This source file includes following definitions.
- ext2_error
- ext2_panic
- ext2_warning
- ext2_put_super
- convert_pre_02b_fs
- parse_options
- ext2_setup_super
- ext2_check_descriptors
- ext2_read_super
- ext2_commit_super
- ext2_write_super
- ext2_remount
- ext2_statfs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 #include <stdarg.h>
17
18 #include <asm/segment.h>
19 #include <asm/system.h>
20
21 #include <linux/errno.h>
22 #include <linux/fs.h>
23 #include <linux/ext2_fs.h>
24 #include <linux/malloc.h>
25 #include <linux/sched.h>
26 #include <linux/stat.h>
27 #include <linux/string.h>
28 #include <linux/locks.h>
29
30 static char error_buf[1024];
31
32 void ext2_error (struct super_block * sb, const char * function,
33 const char * fmt, ...)
34 {
35 va_list args;
36
37 if (!(sb->s_flags & MS_RDONLY)) {
38 sb->u.ext2_sb.s_mount_state |= EXT2_ERROR_FS;
39 sb->u.ext2_sb.s_es->s_state |= EXT2_ERROR_FS;
40 mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
41 sb->s_dirt = 1;
42 }
43 va_start (args, fmt);
44 vsprintf (error_buf, fmt, args);
45 va_end (args);
46 if (test_opt (sb, ERRORS_PANIC) ||
47 (sb->u.ext2_sb.s_es->s_errors == EXT2_ERRORS_PANIC &&
48 !test_opt (sb, ERRORS_CONT) && !test_opt (sb, ERRORS_RO)))
49 panic ("EXT2-fs panic (device %d/%d): %s: %s\n",
50 MAJOR(sb->s_dev), MINOR(sb->s_dev), function, error_buf);
51 printk (KERN_CRIT "EXT2-fs error (device %d/%d): %s: %s\n",
52 MAJOR(sb->s_dev), MINOR(sb->s_dev), function, error_buf);
53 if (test_opt (sb, ERRORS_RO) ||
54 (sb->u.ext2_sb.s_es->s_errors == EXT2_ERRORS_RO &&
55 !test_opt (sb, ERRORS_CONT) && !test_opt (sb, ERRORS_PANIC))) {
56 printk ("Remounting filesystem read-only\n");
57 sb->s_flags |= MS_RDONLY;
58 }
59 }
60
61 NORET_TYPE void ext2_panic (struct super_block * sb, const char * function,
62 const char * fmt, ...)
63 {
64 va_list args;
65
66 if (!(sb->s_flags & MS_RDONLY)) {
67 sb->u.ext2_sb.s_mount_state |= EXT2_ERROR_FS;
68 sb->u.ext2_sb.s_es->s_state |= EXT2_ERROR_FS;
69 mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
70 sb->s_dirt = 1;
71 }
72 va_start (args, fmt);
73 vsprintf (error_buf, fmt, args);
74 va_end (args);
75 panic ("EXT2-fs panic (device %d/%d): %s: %s\n",
76 MAJOR(sb->s_dev), MINOR(sb->s_dev), function, error_buf);
77 }
78
79 void ext2_warning (struct super_block * sb, const char * function,
80 const char * fmt, ...)
81 {
82 va_list args;
83
84 va_start (args, fmt);
85 vsprintf (error_buf, fmt, args);
86 va_end (args);
87 printk (KERN_WARNING "EXT2-fs warning (device %d/%d): %s: %s\n",
88 MAJOR(sb->s_dev), MINOR(sb->s_dev), function, error_buf);
89 }
90
91 void ext2_put_super (struct super_block * sb)
92 {
93 int db_count;
94 int i;
95
96 lock_super (sb);
97 if (!(sb->s_flags & MS_RDONLY)) {
98 sb->u.ext2_sb.s_es->s_state = sb->u.ext2_sb.s_mount_state;
99 mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
100 }
101 sb->s_dev = 0;
102 db_count = sb->u.ext2_sb.s_db_per_group;
103 for (i = 0; i < db_count; i++)
104 if (sb->u.ext2_sb.s_group_desc[i])
105 brelse (sb->u.ext2_sb.s_group_desc[i]);
106 kfree_s (sb->u.ext2_sb.s_group_desc,
107 db_count * sizeof (struct buffer_head *));
108 for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++)
109 if (sb->u.ext2_sb.s_inode_bitmap[i])
110 brelse (sb->u.ext2_sb.s_inode_bitmap[i]);
111 for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++)
112 if (sb->u.ext2_sb.s_block_bitmap[i])
113 brelse (sb->u.ext2_sb.s_block_bitmap[i]);
114 brelse (sb->u.ext2_sb.s_sbh);
115 unlock_super (sb);
116 return;
117 }
118
119 static struct super_operations ext2_sops = {
120 ext2_read_inode,
121 NULL,
122 ext2_write_inode,
123 ext2_put_inode,
124 ext2_put_super,
125 ext2_write_super,
126 ext2_statfs,
127 ext2_remount
128 };
129
130 #ifdef EXT2FS_PRE_02B_COMPAT
131
132 static int convert_pre_02b_fs (struct super_block * sb,
133 struct buffer_head * bh)
134 {
135 struct ext2_super_block * es;
136 struct ext2_old_group_desc old_group_desc [BLOCK_SIZE / sizeof (struct ext2_old_group_desc)];
137 struct ext2_group_desc * gdp;
138 struct buffer_head * bh2;
139 int groups_count;
140 int i;
141
142 es = (struct ext2_super_block *) bh->b_data;
143 bh2 = bread (sb->s_dev, 2, BLOCK_SIZE);
144 if (!bh2) {
145 printk ("Cannot read descriptor blocks while converting !\n");
146 return 0;
147 }
148 memcpy (old_group_desc, bh2->b_data, BLOCK_SIZE);
149 groups_count = (sb->u.ext2_sb.s_blocks_count -
150 sb->u.ext2_sb.s_first_data_block +
151 (EXT2_BLOCK_SIZE(sb) * 8) - 1) /
152 (EXT2_BLOCK_SIZE(sb) * 8);
153 memset (bh2->b_data, 0, BLOCK_SIZE);
154 gdp = (struct ext2_group_desc *) bh2->b_data;
155 for (i = 0; i < groups_count; i++) {
156 gdp[i].bg_block_bitmap = old_group_desc[i].bg_block_bitmap;
157 gdp[i].bg_inode_bitmap = old_group_desc[i].bg_inode_bitmap;
158 gdp[i].bg_inode_table = old_group_desc[i].bg_inode_table;
159 gdp[i].bg_free_blocks_count = old_group_desc[i].bg_free_blocks_count;
160 gdp[i].bg_free_inodes_count = old_group_desc[i].bg_free_inodes_count;
161 }
162 mark_buffer_dirty(bh2, 1);
163 brelse (bh2);
164 es->s_magic = EXT2_SUPER_MAGIC;
165 mark_buffer_dirty(bh, 1);
166 sb->s_magic = EXT2_SUPER_MAGIC;
167 return 1;
168 }
169
170 #endif
171
172
173
174
175 static int parse_options (char * options, unsigned long * sb_block,
176 unsigned short *resuid, unsigned short * resgid,
177 unsigned long * mount_options)
178 {
179 char * this_char;
180 char * value;
181
182 if (!options)
183 return 1;
184 for (this_char = strtok (options, ",");
185 this_char != NULL;
186 this_char = strtok (NULL, ",")) {
187 if ((value = strchr (this_char, '=')) != NULL)
188 *value++ = 0;
189 if (!strcmp (this_char, "bsddf"))
190 clear_opt (*mount_options, MINIX_DF);
191 else if (!strcmp (this_char, "check")) {
192 if (!value || !*value)
193 set_opt (*mount_options, CHECK_NORMAL);
194 else if (!strcmp (value, "none")) {
195 clear_opt (*mount_options, CHECK_NORMAL);
196 clear_opt (*mount_options, CHECK_STRICT);
197 }
198 else if (strcmp (value, "normal"))
199 set_opt (*mount_options, CHECK_NORMAL);
200 else if (strcmp (value, "strict")) {
201 set_opt (*mount_options, CHECK_NORMAL);
202 set_opt (*mount_options, CHECK_STRICT);
203 }
204 else {
205 printk ("EXT2-fs: Invalid check option: %s\n",
206 value);
207 return 0;
208 }
209 }
210 else if (!strcmp (this_char, "debug"))
211 set_opt (*mount_options, DEBUG);
212 else if (!strcmp (this_char, "errors")) {
213 if (!value || !*value) {
214 printk ("EXT2-fs: the errors option requires "
215 "an argument");
216 return 0;
217 }
218 if (!strcmp (value, "continue")) {
219 clear_opt (*mount_options, ERRORS_RO);
220 clear_opt (*mount_options, ERRORS_PANIC);
221 set_opt (*mount_options, ERRORS_CONT);
222 }
223 else if (!strcmp (value, "remount-ro")) {
224 clear_opt (*mount_options, ERRORS_CONT);
225 clear_opt (*mount_options, ERRORS_PANIC);
226 set_opt (*mount_options, ERRORS_RO);
227 }
228 else if (!strcmp (value, "panic")) {
229 clear_opt (*mount_options, ERRORS_CONT);
230 clear_opt (*mount_options, ERRORS_RO);
231 set_opt (*mount_options, ERRORS_PANIC);
232 }
233 else {
234 printk ("EXT2-fs: Invalid errors option: %s\n",
235 value);
236 return 0;
237 }
238 }
239 else if (!strcmp (this_char, "grpid") ||
240 !strcmp (this_char, "bsdgroups"))
241 set_opt (*mount_options, GRPID);
242 else if (!strcmp (this_char, "minixdf"))
243 set_opt (*mount_options, MINIX_DF);
244 else if (!strcmp (this_char, "nocheck")) {
245 clear_opt (*mount_options, CHECK_NORMAL);
246 clear_opt (*mount_options, CHECK_STRICT);
247 }
248 else if (!strcmp (this_char, "nogrpid") ||
249 !strcmp (this_char, "sysvgroups"))
250 clear_opt (*mount_options, GRPID);
251 else if (!strcmp (this_char, "resgid")) {
252 if (!value || !*value) {
253 printk ("EXT2-fs: the resgid option requires "
254 "an argument");
255 return 0;
256 }
257 *resgid = simple_strtoul (value, &value, 0);
258 if (*value) {
259 printk ("EXT2-fs: Invalid resgid option: %s\n",
260 value);
261 return 0;
262 }
263 }
264 else if (!strcmp (this_char, "resuid")) {
265 if (!value || !*value) {
266 printk ("EXT2-fs: the resuid option requires "
267 "an argument");
268 return 0;
269 }
270 *resuid = simple_strtoul (value, &value, 0);
271 if (*value) {
272 printk ("EXT2-fs: Invalid resuid option: %s\n",
273 value);
274 return 0;
275 }
276 }
277 else if (!strcmp (this_char, "sb")) {
278 if (!value || !*value) {
279 printk ("EXT2-fs: the sb option requires "
280 "an argument");
281 return 0;
282 }
283 *sb_block = simple_strtoul (value, &value, 0);
284 if (*value) {
285 printk ("EXT2-fs: Invalid sb option: %s\n",
286 value);
287 return 0;
288 }
289 }
290 else {
291 printk ("EXT2-fs: Unrecognized mount option %s\n", this_char);
292 return 0;
293 }
294 }
295 return 1;
296 }
297
298 static void ext2_setup_super (struct super_block * sb,
299 struct ext2_super_block * es)
300 {
301 if (es->s_rev_level > EXT2_CURRENT_REV) {
302 printk ("EXT2-fs warning: revision level too high, "
303 "forcing read/only mode\n");
304 sb->s_flags |= MS_RDONLY;
305 }
306 if (!(sb->s_flags & MS_RDONLY)) {
307 if (!(sb->u.ext2_sb.s_mount_state & EXT2_VALID_FS))
308 printk ("EXT2-fs warning: mounting unchecked fs, "
309 "running e2fsck is recommended\n");
310 else if ((sb->u.ext2_sb.s_mount_state & EXT2_ERROR_FS))
311 printk ("EXT2-fs warning: mounting fs with errors, "
312 "running e2fsck is recommended\n");
313 else if (es->s_max_mnt_count >= 0 &&
314 es->s_mnt_count >= (unsigned short) es->s_max_mnt_count)
315 printk ("EXT2-fs warning: maximal mount count reached, "
316 "running e2fsck is recommended\n");
317 else if (es->s_checkinterval &&
318 (es->s_lastcheck + es->s_checkinterval <= CURRENT_TIME))
319 printk ("EXT2-fs warning: checktime reached, "
320 "running e2fsck is recommended\n");
321 es->s_state &= ~EXT2_VALID_FS;
322 if (!es->s_max_mnt_count)
323 es->s_max_mnt_count = EXT2_DFL_MAX_MNT_COUNT;
324 es->s_mnt_count++;
325 es->s_mtime = CURRENT_TIME;
326 mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
327 sb->s_dirt = 1;
328 if (test_opt (sb, DEBUG))
329 printk ("[EXT II FS %s, %s, bs=%lu, fs=%lu, gc=%lu, "
330 "bpg=%lu, ipg=%lu, mo=%04lx]\n",
331 EXT2FS_VERSION, EXT2FS_DATE, sb->s_blocksize,
332 sb->u.ext2_sb.s_frag_size,
333 sb->u.ext2_sb.s_groups_count,
334 EXT2_BLOCKS_PER_GROUP(sb),
335 EXT2_INODES_PER_GROUP(sb),
336 sb->u.ext2_sb.s_mount_opt);
337 if (test_opt (sb, CHECK)) {
338 ext2_check_blocks_bitmap (sb);
339 ext2_check_inodes_bitmap (sb);
340 }
341 }
342 }
343
344 static int ext2_check_descriptors (struct super_block * sb)
345 {
346 int i;
347 int desc_block = 0;
348 unsigned long block = sb->u.ext2_sb.s_es->s_first_data_block;
349 struct ext2_group_desc * gdp = NULL;
350
351 ext2_debug ("Checking group descriptors");
352
353 for (i = 0; i < sb->u.ext2_sb.s_groups_count; i++)
354 {
355 if ((i % EXT2_DESC_PER_BLOCK(sb)) == 0)
356 gdp = (struct ext2_group_desc *) sb->u.ext2_sb.s_group_desc[desc_block++]->b_data;
357 if (gdp->bg_block_bitmap < block ||
358 gdp->bg_block_bitmap >= block + EXT2_BLOCKS_PER_GROUP(sb))
359 {
360 ext2_error (sb, "ext2_check_descriptors",
361 "Block bitmap for group %d"
362 " not in group (block %lu)!",
363 i, (unsigned long) gdp->bg_block_bitmap);
364 return 0;
365 }
366 if (gdp->bg_inode_bitmap < block ||
367 gdp->bg_inode_bitmap >= block + EXT2_BLOCKS_PER_GROUP(sb))
368 {
369 ext2_error (sb, "ext2_check_descriptors",
370 "Inode bitmap for group %d"
371 " not in group (block %lu)!",
372 i, (unsigned long) gdp->bg_inode_bitmap);
373 return 0;
374 }
375 if (gdp->bg_inode_table < block ||
376 gdp->bg_inode_table + sb->u.ext2_sb.s_itb_per_group >=
377 block + EXT2_BLOCKS_PER_GROUP(sb))
378 {
379 ext2_error (sb, "ext2_check_descriptors",
380 "Inode table for group %d"
381 " not in group (block %lu)!",
382 i, (unsigned long) gdp->bg_inode_table);
383 return 0;
384 }
385 block += EXT2_BLOCKS_PER_GROUP(sb);
386 gdp++;
387 }
388 return 1;
389 }
390
391 struct super_block * ext2_read_super (struct super_block * sb, void * data,
392 int silent)
393 {
394 struct buffer_head * bh;
395 struct ext2_super_block * es;
396 unsigned long sb_block = 1;
397 unsigned short resuid = EXT2_DEF_RESUID;
398 unsigned short resgid = EXT2_DEF_RESGID;
399 unsigned long logic_sb_block = 1;
400 int dev = sb->s_dev;
401 int db_count;
402 int i, j;
403 #ifdef EXT2FS_PRE_02B_COMPAT
404 int fs_converted = 0;
405 #endif
406
407 set_opt (sb->u.ext2_sb.s_mount_opt, CHECK_NORMAL);
408 if (!parse_options ((char *) data, &sb_block, &resuid, &resgid,
409 &sb->u.ext2_sb.s_mount_opt)) {
410 sb->s_dev = 0;
411 return NULL;
412 }
413
414 lock_super (sb);
415 set_blocksize (dev, BLOCK_SIZE);
416 if (!(bh = bread (dev, sb_block, BLOCK_SIZE))) {
417 sb->s_dev = 0;
418 unlock_super (sb);
419 printk ("EXT2-fs: unable to read superblock\n");
420 return NULL;
421 }
422
423
424
425
426 es = (struct ext2_super_block *) bh->b_data;
427 sb->u.ext2_sb.s_es = es;
428 sb->s_magic = es->s_magic;
429 if (sb->s_magic != EXT2_SUPER_MAGIC
430 #ifdef EXT2FS_PRE_02B_COMPAT
431 && sb->s_magic != EXT2_PRE_02B_MAGIC
432 #endif
433 ) {
434 sb->s_dev = 0;
435 unlock_super (sb);
436 brelse (bh);
437 if (!silent)
438 printk ("VFS: Can't find an ext2 filesystem on dev %d/%d.\n",
439 MAJOR(dev), MINOR(dev));
440 return NULL;
441 }
442 sb->s_blocksize = EXT2_MIN_BLOCK_SIZE << es->s_log_block_size;
443 sb->s_blocksize_bits = EXT2_BLOCK_SIZE_BITS(sb);
444 if (sb->s_blocksize != BLOCK_SIZE &&
445 (sb->s_blocksize == 1024 || sb->s_blocksize == 2048 ||
446 sb->s_blocksize == 4096)) {
447 unsigned long offset;
448
449 brelse (bh);
450 set_blocksize (dev, sb->s_blocksize);
451 logic_sb_block = (sb_block*BLOCK_SIZE) / sb->s_blocksize;
452 offset = (sb_block*BLOCK_SIZE) % sb->s_blocksize;
453 bh = bread (dev, logic_sb_block, sb->s_blocksize);
454 if(!bh)
455 return NULL;
456 es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
457 sb->u.ext2_sb.s_es = es;
458 if (es->s_magic != EXT2_SUPER_MAGIC) {
459 sb->s_dev = 0;
460 unlock_super (sb);
461 brelse (bh);
462 printk ("EXT2-fs: Magic mismatch, very weird !\n");
463 return NULL;
464 }
465 }
466 sb->u.ext2_sb.s_frag_size = EXT2_MIN_FRAG_SIZE <<
467 es->s_log_frag_size;
468 if (sb->u.ext2_sb.s_frag_size)
469 sb->u.ext2_sb.s_frags_per_block = sb->s_blocksize /
470 sb->u.ext2_sb.s_frag_size;
471 else
472 sb->s_magic = 0;
473 sb->u.ext2_sb.s_blocks_per_group = es->s_blocks_per_group;
474 sb->u.ext2_sb.s_frags_per_group = es->s_frags_per_group;
475 sb->u.ext2_sb.s_inodes_per_group = es->s_inodes_per_group;
476 sb->u.ext2_sb.s_inodes_per_block = sb->s_blocksize /
477 sizeof (struct ext2_inode);
478 sb->u.ext2_sb.s_itb_per_group = sb->u.ext2_sb.s_inodes_per_group /
479 sb->u.ext2_sb.s_inodes_per_block;
480 sb->u.ext2_sb.s_desc_per_block = sb->s_blocksize /
481 sizeof (struct ext2_group_desc);
482 sb->u.ext2_sb.s_sbh = bh;
483 sb->u.ext2_sb.s_es = es;
484 if (resuid != EXT2_DEF_RESUID)
485 sb->u.ext2_sb.s_resuid = resuid;
486 else
487 sb->u.ext2_sb.s_resuid = es->s_def_resuid;
488 if (resgid != EXT2_DEF_RESGID)
489 sb->u.ext2_sb.s_resgid = resgid;
490 else
491 sb->u.ext2_sb.s_resgid = es->s_def_resgid;
492 sb->u.ext2_sb.s_mount_state = es->s_state;
493 sb->u.ext2_sb.s_rename_lock = 0;
494 sb->u.ext2_sb.s_rename_wait = NULL;
495 #ifdef EXT2FS_PRE_02B_COMPAT
496 if (sb->s_magic == EXT2_PRE_02B_MAGIC) {
497 if (es->s_blocks_count > 262144) {
498
499
500
501 sb->s_dev = 0;
502 unlock_super (sb);
503 brelse (bh);
504 printk ("EXT2-fs: trying to mount a pre-0.2b file"
505 "system which cannot be converted\n");
506 return NULL;
507 }
508 printk ("EXT2-fs: mounting a pre 0.2b file system, "
509 "will try to convert the structure\n");
510 if (!(sb->s_flags & MS_RDONLY)) {
511 sb->s_dev = 0;
512 unlock_super (sb);
513 brelse (bh);
514 printk ("EXT2-fs: cannot convert a read-only fs\n");
515 return NULL;
516 }
517 if (!convert_pre_02b_fs (sb, bh)) {
518 sb->s_dev = 0;
519 unlock_super (sb);
520 brelse (bh);
521 printk ("EXT2-fs: conversion failed !!!\n");
522 return NULL;
523 }
524 printk ("EXT2-fs: conversion succeeded !!!\n");
525 fs_converted = 1;
526 }
527 #endif
528 if (sb->s_magic != EXT2_SUPER_MAGIC) {
529 sb->s_dev = 0;
530 unlock_super (sb);
531 brelse (bh);
532 if (!silent)
533 printk ("VFS: Can't find an ext2 filesystem on dev %d/%d.\n",
534 MAJOR(dev), MINOR(dev));
535 return NULL;
536 }
537 if (sb->s_blocksize != bh->b_size) {
538 sb->s_dev = 0;
539 unlock_super (sb);
540 brelse (bh);
541 if (!silent)
542 printk ("VFS: Unsupported blocksize on dev 0x%04x.\n",
543 dev);
544 return NULL;
545 }
546
547 if (sb->s_blocksize != sb->u.ext2_sb.s_frag_size) {
548 sb->s_dev = 0;
549 unlock_super (sb);
550 brelse (bh);
551 printk ("EXT2-fs: fragsize %lu != blocksize %lu (not supported yet)\n",
552 sb->u.ext2_sb.s_frag_size, sb->s_blocksize);
553 return NULL;
554 }
555
556 if (sb->u.ext2_sb.s_blocks_per_group > sb->s_blocksize * 8) {
557 sb->s_dev = 0;
558 unlock_super (sb);
559 brelse (bh);
560 printk ("EXT2-fs: #blocks per group too big: %lu\n",
561 sb->u.ext2_sb.s_blocks_per_group);
562 return NULL;
563 }
564 if (sb->u.ext2_sb.s_frags_per_group > sb->s_blocksize * 8) {
565 sb->s_dev = 0;
566 unlock_super (sb);
567 brelse (bh);
568 printk ("EXT2-fs: #fragments per group too big: %lu\n",
569 sb->u.ext2_sb.s_frags_per_group);
570 return NULL;
571 }
572 if (sb->u.ext2_sb.s_inodes_per_group > sb->s_blocksize * 8) {
573 sb->s_dev = 0;
574 unlock_super (sb);
575 brelse (bh);
576 printk ("EXT2-fs: #inodes per group too big: %lu\n",
577 sb->u.ext2_sb.s_inodes_per_group);
578 return NULL;
579 }
580
581 sb->u.ext2_sb.s_groups_count = (es->s_blocks_count -
582 es->s_first_data_block +
583 EXT2_BLOCKS_PER_GROUP(sb) - 1) /
584 EXT2_BLOCKS_PER_GROUP(sb);
585 db_count = (sb->u.ext2_sb.s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
586 EXT2_DESC_PER_BLOCK(sb);
587 sb->u.ext2_sb.s_group_desc = kmalloc (db_count * sizeof (struct buffer_head *), GFP_KERNEL);
588 if (sb->u.ext2_sb.s_group_desc == NULL) {
589 sb->s_dev = 0;
590 unlock_super (sb);
591 brelse (bh);
592 printk ("EXT2-fs: not enough memory\n");
593 return NULL;
594 }
595 for (i = 0; i < db_count; i++) {
596 sb->u.ext2_sb.s_group_desc[i] = bread (dev, logic_sb_block + i + 1,
597 sb->s_blocksize);
598 if (!sb->u.ext2_sb.s_group_desc[i]) {
599 sb->s_dev = 0;
600 unlock_super (sb);
601 for (j = 0; j < i; j++)
602 brelse (sb->u.ext2_sb.s_group_desc[j]);
603 kfree_s (sb->u.ext2_sb.s_group_desc,
604 db_count * sizeof (struct buffer_head *));
605 brelse (bh);
606 printk ("EXT2-fs: unable to read group descriptors\n");
607 return NULL;
608 }
609 }
610 if (!ext2_check_descriptors (sb)) {
611 sb->s_dev = 0;
612 unlock_super (sb);
613 for (j = 0; j < db_count; j++)
614 brelse (sb->u.ext2_sb.s_group_desc[j]);
615 kfree_s (sb->u.ext2_sb.s_group_desc,
616 db_count * sizeof (struct buffer_head *));
617 brelse (bh);
618 printk ("EXT2-fs: group descriptors corrupted !\n");
619 return NULL;
620 }
621 for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++) {
622 sb->u.ext2_sb.s_inode_bitmap_number[i] = 0;
623 sb->u.ext2_sb.s_inode_bitmap[i] = NULL;
624 sb->u.ext2_sb.s_block_bitmap_number[i] = 0;
625 sb->u.ext2_sb.s_block_bitmap[i] = NULL;
626 }
627 sb->u.ext2_sb.s_loaded_inode_bitmaps = 0;
628 sb->u.ext2_sb.s_loaded_block_bitmaps = 0;
629 sb->u.ext2_sb.s_db_per_group = db_count;
630 unlock_super (sb);
631
632
633
634 sb->s_dev = dev;
635 sb->s_op = &ext2_sops;
636 if (!(sb->s_mounted = iget (sb, EXT2_ROOT_INO))) {
637 sb->s_dev = 0;
638 for (i = 0; i < db_count; i++)
639 if (sb->u.ext2_sb.s_group_desc[i])
640 brelse (sb->u.ext2_sb.s_group_desc[i]);
641 kfree_s (sb->u.ext2_sb.s_group_desc,
642 db_count * sizeof (struct buffer_head *));
643 brelse (bh);
644 printk ("EXT2-fs: get root inode failed\n");
645 return NULL;
646 }
647 #ifdef EXT2FS_PRE_02B_COMPAT
648 if (fs_converted) {
649 for (i = 0; i < db_count; i++)
650 mark_buffer_dirty(sb->u.ext2_sb.s_group_desc[i], 1);
651 sb->s_dirt = 1;
652 }
653 #endif
654 ext2_setup_super (sb, es);
655 return sb;
656 }
657
658 static void ext2_commit_super (struct super_block * sb,
659 struct ext2_super_block * es)
660 {
661 es->s_wtime = CURRENT_TIME;
662 mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
663 sb->s_dirt = 0;
664 }
665
666
667
668
669
670
671
672
673
674
675
676
677 void ext2_write_super (struct super_block * sb)
678 {
679 struct ext2_super_block * es;
680
681 if (!(sb->s_flags & MS_RDONLY)) {
682 es = sb->u.ext2_sb.s_es;
683
684 ext2_debug ("setting valid to 0\n");
685
686 if (es->s_state & EXT2_VALID_FS) {
687 es->s_state &= ~EXT2_VALID_FS;
688 es->s_mtime = CURRENT_TIME;
689 }
690 ext2_commit_super (sb, es);
691 }
692 sb->s_dirt = 0;
693 }
694
695 int ext2_remount (struct super_block * sb, int * flags, char * data)
696 {
697 struct ext2_super_block * es;
698 unsigned short resuid = sb->u.ext2_sb.s_resuid;
699 unsigned short resgid = sb->u.ext2_sb.s_resgid;
700 unsigned long new_mount_opt;
701 unsigned long tmp;
702
703
704
705
706 set_opt (sb->u.ext2_sb.s_mount_opt, CHECK_NORMAL);
707 if (!parse_options (data, &tmp, &resuid, &resgid,
708 &new_mount_opt))
709 return -EINVAL;
710
711 sb->u.ext2_sb.s_mount_opt = new_mount_opt;
712 sb->u.ext2_sb.s_resuid = resuid;
713 sb->u.ext2_sb.s_resgid = resgid;
714 es = sb->u.ext2_sb.s_es;
715 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
716 return 0;
717 if (*flags & MS_RDONLY) {
718 if (es->s_state & EXT2_VALID_FS ||
719 !(sb->u.ext2_sb.s_mount_state & EXT2_VALID_FS))
720 return 0;
721
722
723
724
725 es->s_state = sb->u.ext2_sb.s_mount_state;
726 es->s_mtime = CURRENT_TIME;
727 mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
728 sb->s_dirt = 1;
729 ext2_commit_super (sb, es);
730 }
731 else {
732
733
734
735
736
737 sb->u.ext2_sb.s_mount_state = es->s_state;
738 sb->s_flags &= ~MS_RDONLY;
739 ext2_setup_super (sb, es);
740 }
741 return 0;
742 }
743
744 void ext2_statfs (struct super_block * sb, struct statfs * buf)
745 {
746 long tmp;
747 unsigned long overhead;
748 unsigned long overhead_per_group;
749
750 if (test_opt (sb, MINIX_DF))
751 overhead = 0;
752 else {
753
754
755
756 overhead_per_group = 1 +
757 sb->u.ext2_sb.s_db_per_group +
758 1 +
759 1 +
760 sb->u.ext2_sb.s_itb_per_group ;
761 overhead = sb->u.ext2_sb.s_es->s_first_data_block +
762 sb->u.ext2_sb.s_groups_count * overhead_per_group;
763 }
764
765 put_fs_long (EXT2_SUPER_MAGIC, &buf->f_type);
766 put_fs_long (sb->s_blocksize, &buf->f_bsize);
767 put_fs_long (sb->u.ext2_sb.s_es->s_blocks_count - overhead,
768 &buf->f_blocks);
769 tmp = ext2_count_free_blocks (sb);
770 put_fs_long (tmp, &buf->f_bfree);
771 if (tmp >= sb->u.ext2_sb.s_es->s_r_blocks_count)
772 put_fs_long (tmp - sb->u.ext2_sb.s_es->s_r_blocks_count,
773 &buf->f_bavail);
774 else
775 put_fs_long (0, &buf->f_bavail);
776 put_fs_long (sb->u.ext2_sb.s_es->s_inodes_count, &buf->f_files);
777 put_fs_long (ext2_count_free_inodes (sb), &buf->f_ffree);
778 put_fs_long (EXT2_NAME_LEN, &buf->f_namelen);
779
780 }