Version:
~ [ 0.6-2.3.46 ] ~
Architecture:
~ [ um ] ~
** Warning: Cannot open xref database.
1 /*
2 * linux/fs/ext2/super.c
3 *
4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
8 *
9 * from
10 *
11 * linux/fs/minix/inode.c
12 *
13 * Copyright (C) 1991, 1992 Linus Torvalds
14 *
15 * Big-endian to little-endian byte-swapping/bitmaps by
16 * David S. Miller (davem@caip.rutgers.edu), 1995
17 */
18
19 #include <linux/module.h>
20 #include <linux/string.h>
21 #include <linux/fs.h>
22 #include <linux/slab.h>
23 #include <linux/init.h>
24 #include <linux/locks.h>
25 #include <asm/uaccess.h>
26
27
28
29 static char error_buf[1024];
30
31 void ext2_error (struct super_block * sb, const char * function,
32 const char * fmt, ...)
33 {
34 va_list args;
35
36 if (!(sb->s_flags & MS_RDONLY)) {
37 sb->u.ext2_sb.s_mount_state |= EXT2_ERROR_FS;
38 sb->u.ext2_sb.s_es->s_state =
39 cpu_to_le16(le16_to_cpu(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 (le16_to_cpu(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 %s): %s: %s\n",
50 bdevname(sb->s_dev), function, error_buf);
51 printk (KERN_CRIT "EXT2-fs error (device %s): %s: %s\n",
52 bdevname(sb->s_dev), function, error_buf);
53 if (test_opt (sb, ERRORS_RO) ||
54 (le16_to_cpu(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 =
69 cpu_to_le16(le16_to_cpu(sb->u.ext2_sb.s_es->s_state) | EXT2_ERROR_FS);
70 mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
71 sb->s_dirt = 1;
72 }
73 va_start (args, fmt);
74 vsprintf (error_buf, fmt, args);
75 va_end (args);
76 /* this is to prevent panic from syncing this filesystem */
77 if (sb->s_lock)
78 sb->s_lock=0;
79 sb->s_flags |= MS_RDONLY;
80 panic ("EXT2-fs panic (device %s): %s: %s\n",
81 bdevname(sb->s_dev), function, error_buf);
82 }
83
84 void ext2_warning (struct super_block * sb, const char * function,
85 const char * fmt, ...)
86 {
87 va_list args;
88
89 va_start (args, fmt);
90 vsprintf (error_buf, fmt, args);
91 va_end (args);
92 printk (KERN_WARNING "EXT2-fs warning (device %s): %s: %s\n",
93 bdevname(sb->s_dev), function, error_buf);
94 }
95
96 void ext2_put_super (struct super_block * sb)
97 {
98 int db_count;
99 int i;
100
101 if (!(sb->s_flags & MS_RDONLY)) {
102 sb->u.ext2_sb.s_es->s_state = le16_to_cpu(sb->u.ext2_sb.s_mount_state);
103 mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
104 }
105 db_count = sb->u.ext2_sb.s_db_per_group;
106 for (i = 0; i < db_count; i++)
107 if (sb->u.ext2_sb.s_group_desc[i])
108 brelse (sb->u.ext2_sb.s_group_desc[i]);
109 kfree_s (sb->u.ext2_sb.s_group_desc,
110 db_count * sizeof (struct buffer_head *));
111 for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++)
112 if (sb->u.ext2_sb.s_inode_bitmap[i])
113 brelse (sb->u.ext2_sb.s_inode_bitmap[i]);
114 for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++)
115 if (sb->u.ext2_sb.s_block_bitmap[i])
116 brelse (sb->u.ext2_sb.s_block_bitmap[i]);
117 brelse (sb->u.ext2_sb.s_sbh);
118
119 MOD_DEC_USE_COUNT;
120 return;
121 }
122
123 static struct super_operations ext2_sops = {
124 ext2_read_inode,
125 ext2_write_inode,
126 ext2_put_inode,
127 ext2_delete_inode,
128 NULL,
129 ext2_put_super,
130 ext2_write_super,
131 ext2_statfs,
132 ext2_remount
133 };
134
135 /*
136 * This function has been shamelessly adapted from the msdos fs
137 */
138 static int parse_options (char * options, unsigned long * sb_block,
139 unsigned short *resuid, unsigned short * resgid,
140 unsigned long * mount_options)
141 {
142 char * this_char;
143 char * value;
144
145 if (!options)
146 return 1;
147 for (this_char = strtok (options, ",");
148 this_char != NULL;
149 this_char = strtok (NULL, ",")) {
150 if ((value = strchr (this_char, '=')) != NULL)
151 *value++ = 0;
152 if (!strcmp (this_char, "bsddf"))
153 clear_opt (*mount_options, MINIX_DF);
154 else if (!strcmp (this_char, "nouid32")) {
155 set_opt (*mount_options, NO_UID32);
156 }
157 else if (!strcmp (this_char, "check")) {
158 if (!value || !*value)
159 set_opt (*mount_options, CHECK_NORMAL);
160 else if (!strcmp (value, "none")) {
161 clear_opt (*mount_options, CHECK_NORMAL);
162 clear_opt (*mount_options, CHECK_STRICT);
163 }
164 else if (!strcmp (value, "normal"))
165 set_opt (*mount_options, CHECK_NORMAL);
166 else if (!strcmp (value, "strict")) {
167 set_opt (*mount_options, CHECK_NORMAL);
168 set_opt (*mount_options, CHECK_STRICT);
169 }
170 else {
171 printk ("EXT2-fs: Invalid check option: %s\n",
172 value);
173 return 0;
174 }
175 }
176 else if (!strcmp (this_char, "debug"))
177 set_opt (*mount_options, DEBUG);
178 else if (!strcmp (this_char, "errors")) {
179 if (!value || !*value) {
180 printk ("EXT2-fs: the errors option requires "
181 "an argument");
182 return 0;
183 }
184 if (!strcmp (value, "continue")) {
185 clear_opt (*mount_options, ERRORS_RO);
186 clear_opt (*mount_options, ERRORS_PANIC);
187 set_opt (*mount_options, ERRORS_CONT);
188 }
189 else if (!strcmp (value, "remount-ro")) {
190 clear_opt (*mount_options, ERRORS_CONT);
191 clear_opt (*mount_options, ERRORS_PANIC);
192 set_opt (*mount_options, ERRORS_RO);
193 }
194 else if (!strcmp (value, "panic")) {
195 clear_opt (*mount_options, ERRORS_CONT);
196 clear_opt (*mount_options, ERRORS_RO);
197 set_opt (*mount_options, ERRORS_PANIC);
198 }
199 else {
200 printk ("EXT2-fs: Invalid errors option: %s\n",
201 value);
202 return 0;
203 }
204 }
205 else if (!strcmp (this_char, "grpid") ||
206 !strcmp (this_char, "bsdgroups"))
207 set_opt (*mount_options, GRPID);
208 else if (!strcmp (this_char, "minixdf"))
209 set_opt (*mount_options, MINIX_DF);
210 else if (!strcmp (this_char, "nocheck")) {
211 clear_opt (*mount_options, CHECK_NORMAL);
212 clear_opt (*mount_options, CHECK_STRICT);
213 }
214 else if (!strcmp (this_char, "nogrpid") ||
215 !strcmp (this_char, "sysvgroups"))
216 clear_opt (*mount_options, GRPID);
217 else if (!strcmp (this_char, "resgid")) {
218 if (!value || !*value) {
219 printk ("EXT2-fs: the resgid option requires "
220 "an argument");
221 return 0;
222 }
223 *resgid = simple_strtoul (value, &value, 0);
224 if (*value) {
225 printk ("EXT2-fs: Invalid resgid option: %s\n",
226 value);
227 return 0;
228 }
229 }
230 else if (!strcmp (this_char, "resuid")) {
231 if (!value || !*value) {
232 printk ("EXT2-fs: the resuid option requires "
233 "an argument");
234 return 0;
235 }
236 *resuid = simple_strtoul (value, &value, 0);
237 if (*value) {
238 printk ("EXT2-fs: Invalid resuid option: %s\n",
239 value);
240 return 0;
241 }
242 }
243 else if (!strcmp (this_char, "sb")) {
244 if (!value || !*value) {
245 printk ("EXT2-fs: the sb option requires "
246 "an argument");
247 return 0;
248 }
249 *sb_block = simple_strtoul (value, &value, 0);
250 if (*value) {
251 printk ("EXT2-fs: Invalid sb option: %s\n",
252 value);
253 return 0;
254 }
255 }
256 /* Silently ignore the quota options */
257 else if (!strcmp (this_char, "grpquota")
258 || !strcmp (this_char, "noquota")
259 || !strcmp (this_char, "quota")
260 || !strcmp (this_char, "usrquota"))
261 /* Don't do anything ;-) */ ;
262 else {
263 printk ("EXT2-fs: Unrecognized mount option %s\n", this_char);
264 return 0;
265 }
266 }
267 return 1;
268 }
269
270 static void ext2_setup_super (struct super_block * sb,
271 struct ext2_super_block * es)
272 {
273 if (le32_to_cpu(es->s_rev_level) > EXT2_MAX_SUPP_REV) {
274 printk ("EXT2-fs warning: revision level too high, "
275 "forcing read/only mode\n");
276 sb->s_flags |= MS_RDONLY;
277 }
278 if (!(sb->s_flags & MS_RDONLY)) {
279 if (!(sb->u.ext2_sb.s_mount_state & EXT2_VALID_FS))
280 printk ("EXT2-fs warning: mounting unchecked fs, "
281 "running e2fsck is recommended\n");
282 else if ((sb->u.ext2_sb.s_mount_state & EXT2_ERROR_FS))
283 printk ("EXT2-fs warning: mounting fs with errors, "
284 "running e2fsck is recommended\n");
285 else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 &&
286 le16_to_cpu(es->s_mnt_count) >=
287 (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count))
288 printk ("EXT2-fs warning: maximal mount count reached, "
289 "running e2fsck is recommended\n");
290 else if (le32_to_cpu(es->s_checkinterval) &&
291 (le32_to_cpu(es->s_lastcheck) + le32_to_cpu(es->s_checkinterval) <= CURRENT_TIME))
292 printk ("EXT2-fs warning: checktime reached, "
293 "running e2fsck is recommended\n");
294 es->s_state = cpu_to_le16(le16_to_cpu(es->s_state) & ~EXT2_VALID_FS);
295 if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
296 es->s_max_mnt_count = (__s16) cpu_to_le16(EXT2_DFL_MAX_MNT_COUNT);
297 es->s_mnt_count=cpu_to_le16(le16_to_cpu(es->s_mnt_count) + 1);
298 es->s_mtime = cpu_to_le32(CURRENT_TIME);
299 mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
300 sb->s_dirt = 1;
301 if (test_opt (sb, DEBUG))
302 printk ("[EXT II FS %s, %s, bs=%lu, fs=%lu, gc=%lu, "
303 "bpg=%lu, ipg=%lu, mo=%04lx]\n",
304 EXT2FS_VERSION, EXT2FS_DATE, sb->s_blocksize,
305 sb->u.ext2_sb.s_frag_size,
306 sb->u.ext2_sb.s_groups_count,
307 EXT2_BLOCKS_PER_GROUP(sb),
308 EXT2_INODES_PER_GROUP(sb),
309 sb->u.ext2_sb.s_mount_opt);
310 if (test_opt (sb, CHECK)) {
311 ext2_check_blocks_bitmap (sb);
312 ext2_check_inodes_bitmap (sb);
313 }
314 }
315 #if 0 /* ibasket's still have unresolved bugs... -DaveM */
316
317 /* [T. Schoebel-Theuer] This limit should be maintained on disk.
318 * This is just provisionary.
319 */
320 sb->s_ibasket_max = 100;
321 #endif
322 }
323
324 static int ext2_check_descriptors (struct super_block * sb)
325 {
326 int i;
327 int desc_block = 0;
328 unsigned long block = le32_to_cpu(sb->u.ext2_sb.s_es->s_first_data_block);
329 struct ext2_group_desc * gdp = NULL;
330
331 ext2_debug ("Checking group descriptors");
332
333 for (i = 0; i < sb->u.ext2_sb.s_groups_count; i++)
334 {
335 if ((i % EXT2_DESC_PER_BLOCK(sb)) == 0)
336 gdp = (struct ext2_group_desc *) sb->u.ext2_sb.s_group_desc[desc_block++]->b_data;
337 if (le32_to_cpu(gdp->bg_block_bitmap) < block ||
338 le32_to_cpu(gdp->bg_block_bitmap) >= block + EXT2_BLOCKS_PER_GROUP(sb))
339 {
340 ext2_error (sb, "ext2_check_descriptors",
341 "Block bitmap for group %d"
342 " not in group (block %lu)!",
343 i, (unsigned long) le32_to_cpu(gdp->bg_block_bitmap));
344 return 0;
345 }
346 if (le32_to_cpu(gdp->bg_inode_bitmap) < block ||
347 le32_to_cpu(gdp->bg_inode_bitmap) >= block + EXT2_BLOCKS_PER_GROUP(sb))
348 {
349 ext2_error (sb, "ext2_check_descriptors",
350 "Inode bitmap for group %d"
351 " not in group (block %lu)!",
352 i, (unsigned long) le32_to_cpu(gdp->bg_inode_bitmap));
353 return 0;
354 }
355 if (le32_to_cpu(gdp->bg_inode_table) < block ||
356 le32_to_cpu(gdp->bg_inode_table) + sb->u.ext2_sb.s_itb_per_group >=
357 block + EXT2_BLOCKS_PER_GROUP(sb))
358 {
359 ext2_error (sb, "ext2_check_descriptors",
360 "Inode table for group %d"
361 " not in group (block %lu)!",
362 i, (unsigned long) le32_to_cpu(gdp->bg_inode_table));
363 return 0;
364 }
365 block += EXT2_BLOCKS_PER_GROUP(sb);
366 gdp++;
367 }
368 return 1;
369 }
370
371 #define log2(n) ffz(~(n))
372
373 struct super_block * ext2_read_super (struct super_block * sb, void * data,
374 int silent)
375 {
376 struct buffer_head * bh;
377 struct ext2_super_block * es;
378 unsigned long sb_block = 1;
379 unsigned short resuid = EXT2_DEF_RESUID;
380 unsigned short resgid = EXT2_DEF_RESGID;
381 unsigned long logic_sb_block = 1;
382 unsigned long offset = 0;
383 kdev_t dev = sb->s_dev;
384 int blocksize = BLOCK_SIZE;
385 int hblock;
386 int db_count;
387 int i, j;
388
389 /*
390 * See what the current blocksize for the device is, and
391 * use that as the blocksize. Otherwise (or if the blocksize
392 * is smaller than the default) use the default.
393 * This is important for devices that have a hardware
394 * sectorsize that is larger than the default.
395 */
396 blocksize = get_hardblocksize(dev);
397 if( blocksize == 0 || blocksize < BLOCK_SIZE )
398 {
399 blocksize = BLOCK_SIZE;
400 }
401
402 sb->u.ext2_sb.s_mount_opt = 0;
403 set_opt (sb->u.ext2_sb.s_mount_opt, CHECK_NORMAL);
404 if (!parse_options ((char *) data, &sb_block, &resuid, &resgid,
405 &sb->u.ext2_sb.s_mount_opt)) {
406 sb->s_dev = 0;
407 return NULL;
408 }
409
410 MOD_INC_USE_COUNT;
411 lock_super (sb);
412 set_blocksize (dev, blocksize);
413
414 /*
415 * If the superblock doesn't start on a sector boundary,
416 * calculate the offset. FIXME(eric) this doesn't make sense
417 * that we would have to do this.
418 */
419 if (blocksize != BLOCK_SIZE) {
420 logic_sb_block = (sb_block*BLOCK_SIZE) / blocksize;
421 offset = (sb_block*BLOCK_SIZE) % blocksize;
422 }
423
424 if (!(bh = bread (dev, logic_sb_block, blocksize))) {
425 sb->s_dev = 0;
426 unlock_super (sb);
427 printk ("EXT2-fs: unable to read superblock\n");
428 MOD_DEC_USE_COUNT;
429 return NULL;
430 }
431 /*
432 * Note: s_es must be initialized s_es as soon as possible because
433 * some ext2 macro-instructions depend on its value
434 */
435 es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
436 sb->u.ext2_sb.s_es = es;
437 sb->s_magic = le16_to_cpu(es->s_magic);
438 if (sb->s_magic != EXT2_SUPER_MAGIC) {
439 if (!silent)
440 printk ("VFS: Can't find an ext2 filesystem on dev "
441 "%s.\n", bdevname(dev));
442 failed_mount:
443 sb->s_dev = 0;
444 unlock_super (sb);
445 if (bh)
446 brelse(bh);
447 MOD_DEC_USE_COUNT;
448 return NULL;
449 }
450 if (le32_to_cpu(es->s_rev_level) > EXT2_GOOD_OLD_REV) {
451 if (le32_to_cpu(es->s_feature_incompat) & ~EXT2_FEATURE_INCOMPAT_SUPP) {
452 printk("EXT2-fs: %s: couldn't mount because of "
453 "unsupported optional features.\n",
454 bdevname(dev));
455 goto failed_mount;
456 }
457 if (!(sb->s_flags & MS_RDONLY) &&
458 (le32_to_cpu(es->s_feature_ro_compat) & ~EXT2_FEATURE_RO_COMPAT_SUPP)) {
459 printk("EXT2-fs: %s: couldn't mount RDWR because of "
460 "unsupported optional features.\n",
461 bdevname(dev));
462 goto failed_mount;
463 }
464 }
465 sb->s_blocksize_bits = le32_to_cpu(sb->u.ext2_sb.s_es->s_log_block_size) + 10;
466 sb->s_blocksize = 1 << sb->s_blocksize_bits;
467 if (sb->s_blocksize != BLOCK_SIZE &&
468 (sb->s_blocksize == 1024 || sb->s_blocksize == 2048 ||
469 sb->s_blocksize == 4096)) {
470 /*
471 * Make sure the blocksize for the filesystem is larger
472 * than the hardware sectorsize for the machine.
473 */
474 hblock = get_hardblocksize(dev);
475 if( (hblock != 0)
476 && (sb->s_blocksize < hblock) )
477 {
478 printk("EXT2-fs: blocksize too small for device.\n");
479 goto failed_mount;
480 }
481
482 brelse (bh);
483 set_blocksize (dev, sb->s_blocksize);
484 logic_sb_block = (sb_block*BLOCK_SIZE) / sb->s_blocksize;
485 offset = (sb_block*BLOCK_SIZE) % sb->s_blocksize;
486 bh = bread (dev, logic_sb_block, sb->s_blocksize);
487 if(!bh) {
488 printk("EXT2-fs: Couldn't read superblock on "
489 "2nd try.\n");
490 goto failed_mount;
491 }
492 es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
493 sb->u.ext2_sb.s_es = es;
494 if (es->s_magic != le16_to_cpu(EXT2_SUPER_MAGIC)) {
495 printk ("EXT2-fs: Magic mismatch, very weird !\n");
496 goto failed_mount;
497 }
498 }
499 if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV) {
500 sb->u.ext2_sb.s_inode_size = EXT2_GOOD_OLD_INODE_SIZE;
501 sb->u.ext2_sb.s_first_ino = EXT2_GOOD_OLD_FIRST_INO;
502 } else {
503 sb->u.ext2_sb.s_inode_size = le16_to_cpu(es->s_inode_size);
504 sb->u.ext2_sb.s_first_ino = le32_to_cpu(es->s_first_ino);
505 if (sb->u.ext2_sb.s_inode_size != EXT2_GOOD_OLD_INODE_SIZE) {
506 printk ("EXT2-fs: unsupported inode size: %d\n",
507 sb->u.ext2_sb.s_inode_size);
508 goto failed_mount;
509 }
510 }
511 sb->u.ext2_sb.s_feature_compat = le32_to_cpu(es->s_feature_compat);
512 sb->u.ext2_sb.s_feature_incompat = le32_to_cpu(es->s_feature_incompat);
513 sb->u.ext2_sb.s_feature_ro_compat = le32_to_cpu(es->s_feature_ro_compat);
514 sb->u.ext2_sb.s_frag_size = EXT2_MIN_FRAG_SIZE <<
515 le32_to_cpu(es->s_log_frag_size);
516 if (sb->u.ext2_sb.s_frag_size)
517 sb->u.ext2_sb.s_frags_per_block = sb->s_blocksize /
518 sb->u.ext2_sb.s_frag_size;
519 else
520 sb->s_magic = 0;
521 sb->u.ext2_sb.s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
522 sb->u.ext2_sb.s_frags_per_group = le32_to_cpu(es->s_frags_per_group);
523 sb->u.ext2_sb.s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
524 sb->u.ext2_sb.s_inodes_per_block = sb->s_blocksize /
525 EXT2_INODE_SIZE(sb);
526 sb->u.ext2_sb.s_itb_per_group = sb->u.ext2_sb.s_inodes_per_group /
527 sb->u.ext2_sb.s_inodes_per_block;
528 sb->u.ext2_sb.s_desc_per_block = sb->s_blocksize /
529 sizeof (struct ext2_group_desc);
530 sb->u.ext2_sb.s_sbh = bh;
531 if (resuid != EXT2_DEF_RESUID)
532 sb->u.ext2_sb.s_resuid = resuid;
533 else
534 sb->u.ext2_sb.s_resuid = le16_to_cpu(es->s_def_resuid);
535 if (resgid != EXT2_DEF_RESGID)
536 sb->u.ext2_sb.s_resgid = resgid;
537 else
538 sb->u.ext2_sb.s_resgid = le16_to_cpu(es->s_def_resgid);
539 sb->u.ext2_sb.s_mount_state = le16_to_cpu(es->s_state);
540 sb->u.ext2_sb.s_addr_per_block_bits =
541 log2 (EXT2_ADDR_PER_BLOCK(sb));
542 sb->u.ext2_sb.s_desc_per_block_bits =
543 log2 (EXT2_DESC_PER_BLOCK(sb));
544 if (sb->s_magic != EXT2_SUPER_MAGIC) {
545 if (!silent)
546 printk ("VFS: Can't find an ext2 filesystem on dev "
547 "%s.\n",
548 bdevname(dev));
549 goto failed_mount;
550 }
551 if (sb->s_blocksize != bh->b_size) {
552 if (!silent)
553 printk ("VFS: Unsupported blocksize on dev "
554 "%s.\n", bdevname(dev));
555 goto failed_mount;
556 }
557
558 if (sb->s_blocksize != sb->u.ext2_sb.s_frag_size) {
559 printk ("EXT2-fs: fragsize %lu != blocksize %lu (not supported yet)\n",
560 sb->u.ext2_sb.s_frag_size, sb->s_blocksize);
561 goto failed_mount;
562 }
563
564 if (sb->u.ext2_sb.s_blocks_per_group > sb->s_blocksize * 8) {
565 printk ("EXT2-fs: #blocks per group too big: %lu\n",
566 sb->u.ext2_sb.s_blocks_per_group);
567 goto failed_mount;
568 }
569 if (sb->u.ext2_sb.s_frags_per_group > sb->s_blocksize * 8) {
570 printk ("EXT2-fs: #fragments per group too big: %lu\n",
571 sb->u.ext2_sb.s_frags_per_group);
572 goto failed_mount;
573 }
574 if (sb->u.ext2_sb.s_inodes_per_group > sb->s_blocksize * 8) {
575 printk ("EXT2-fs: #inodes per group too big: %lu\n",
576 sb->u.ext2_sb.s_inodes_per_group);
577 goto failed_mount;
578 }
579
580 sb->u.ext2_sb.s_groups_count = (le32_to_cpu(es->s_blocks_count) -
581 le32_to_cpu(es->s_first_data_block) +
582 EXT2_BLOCKS_PER_GROUP(sb) - 1) /
583 EXT2_BLOCKS_PER_GROUP(sb);
584 db_count = (sb->u.ext2_sb.s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
585 EXT2_DESC_PER_BLOCK(sb);
586 sb->u.ext2_sb.s_group_desc = kmalloc (db_count * sizeof (struct buffer_head *), GFP_KERNEL);
587 if (sb->u.ext2_sb.s_group_desc == NULL) {
588 printk ("EXT2-fs: not enough memory\n");
589 goto failed_mount;
590 }
591 for (i = 0; i < db_count; i++) {
592 sb->u.ext2_sb.s_group_desc[i] = bread (dev, logic_sb_block + i + 1,
593 sb->s_blocksize);
594 if (!sb->u.ext2_sb.s_group_desc[i]) {
595 for (j = 0; j < i; j++)
596 brelse (sb->u.ext2_sb.s_group_desc[j]);
597 kfree_s (sb->u.ext2_sb.s_group_desc,
598 db_count * sizeof (struct buffer_head *));
599 printk ("EXT2-fs: unable to read group descriptors\n");
600 goto failed_mount;
601 }
602 }
603 if (!ext2_check_descriptors (sb)) {
604 for (j = 0; j < db_count; j++)
605 brelse (sb->u.ext2_sb.s_group_desc[j]);
606 kfree_s (sb->u.ext2_sb.s_group_desc,
607 db_count * sizeof (struct buffer_head *));
608 printk ("EXT2-fs: group descriptors corrupted !\n");
609 goto failed_mount;
610 }
611 for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++) {
612 sb->u.ext2_sb.s_inode_bitmap_number[i] = 0;
613 sb->u.ext2_sb.s_inode_bitmap[i] = NULL;
614 sb->u.ext2_sb.s_block_bitmap_number[i] = 0;
615 sb->u.ext2_sb.s_block_bitmap[i] = NULL;
616 }
617 sb->u.ext2_sb.s_loaded_inode_bitmaps = 0;
618 sb->u.ext2_sb.s_loaded_block_bitmaps = 0;
619 sb->u.ext2_sb.s_db_per_group = db_count;
620 unlock_super (sb);
621 /*
622 * set up enough so that it can read an inode
623 */
624 sb->s_dev = dev;
625 sb->s_op = &ext2_sops;
626 sb->s_root = d_alloc_root(iget(sb, EXT2_ROOT_INO));
627 if (!sb->s_root) {
628 sb->s_dev = 0;
629 for (i = 0; i < db_count; i++)
630 if (sb->u.ext2_sb.s_group_desc[i])
631 brelse (sb->u.ext2_sb.s_group_desc[i]);
632 kfree_s (sb->u.ext2_sb.s_group_desc,
633 db_count * sizeof (struct buffer_head *));
634 brelse (bh);
635 printk ("EXT2-fs: get root inode failed\n");
636 MOD_DEC_USE_COUNT;
637 return NULL;
638 }
639 ext2_setup_super (sb, es);
640 return sb;
641 }
642
643 static void ext2_commit_super (struct super_block * sb,
644 struct ext2_super_block * es)
645 {
646 es->s_wtime = cpu_to_le32(CURRENT_TIME);
647 mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
648 sb->s_dirt = 0;
649 }
650
651 /*
652 * In the second extended file system, it is not necessary to
653 * write the super block since we use a mapping of the
654 * disk super block in a buffer.
655 *
656 * However, this function is still used to set the fs valid
657 * flags to 0. We need to set this flag to 0 since the fs
658 * may have been checked while mounted and e2fsck may have
659 * set s_state to EXT2_VALID_FS after some corrections.
660 */
661
662 void ext2_write_super (struct super_block * sb)
663 {
664 struct ext2_super_block * es;
665
666 if (!(sb->s_flags & MS_RDONLY)) {
667 es = sb->u.ext2_sb.s_es;
668
669 ext2_debug ("setting valid to 0\n");
670
671 if (le16_to_cpu(es->s_state) & EXT2_VALID_FS) {
672 es->s_state = cpu_to_le16(le16_to_cpu(es->s_state) & ~EXT2_VALID_FS);
673 es->s_mtime = cpu_to_le32(CURRENT_TIME);
674 }
675 ext2_commit_super (sb, es);
676 }
677 sb->s_dirt = 0;
678 }
679
680 int ext2_remount (struct super_block * sb, int * flags, char * data)
681 {
682 struct ext2_super_block * es;
683 unsigned short resuid = sb->u.ext2_sb.s_resuid;
684 unsigned short resgid = sb->u.ext2_sb.s_resgid;
685 unsigned long new_mount_opt;
686 unsigned long tmp;
687
688 /*
689 * Allow the "check" option to be passed as a remount option.
690 */
691 new_mount_opt = EXT2_MOUNT_CHECK_NORMAL;
692 if (!parse_options (data, &tmp, &resuid, &resgid,
693 &new_mount_opt))
694 return -EINVAL;
695
696 sb->u.ext2_sb.s_mount_opt = new_mount_opt;
697 sb->u.ext2_sb.s_resuid = resuid;
698 sb->u.ext2_sb.s_resgid = resgid;
699 es = sb->u.ext2_sb.s_es;
700 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
701 return 0;
702 if (*flags & MS_RDONLY) {
703 if (le16_to_cpu(es->s_state) & EXT2_VALID_FS ||
704 !(sb->u.ext2_sb.s_mount_state & EXT2_VALID_FS))
705 return 0;
706 /*
707 * OK, we are remounting a valid rw partition rdonly, so set
708 * the rdonly flag and then mark the partition as valid again.
709 */
710 es->s_state = cpu_to_le16(sb->u.ext2_sb.s_mount_state);
711 es->s_mtime = cpu_to_le32(CURRENT_TIME);
712 mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
713 sb->s_dirt = 1;
714 ext2_commit_super (sb, es);
715 }
716 else {
717 /*
718 * Mounting a RDONLY partition read-write, so reread and
719 * store the current valid flag. (It may have been changed
720 * by e2fsck since we originally mounted the partition.)
721 */
722 sb->u.ext2_sb.s_mount_state = le16_to_cpu(es->s_state);
723 sb->s_flags &= ~MS_RDONLY;
724 ext2_setup_super (sb, es);
725 }
726 return 0;
727 }
728
729 int ext2_statfs (struct super_block * sb, struct statfs * buf, int bufsiz)
730 {
731 unsigned long overhead;
732 struct statfs tmp;
733 int ngroups, i;
734
735 if (test_opt (sb, MINIX_DF))
736 overhead = 0;
737 else {
738 /*
739 * Compute the overhead (FS structures)
740 */
741
742 /*
743 * All of the blocks before first_data_block are
744 * overhead
745 */
746 overhead = le32_to_cpu(sb->u.ext2_sb.s_es->s_first_data_block);
747
748 /*
749 * Add the overhead attributed to the superblock and
750 * block group descriptors. If this is sparse
751 * superblocks is turned on, then not all groups have
752 * this.
753 */
754 if (sb->u.ext2_sb.s_feature_ro_compat &
755 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) {
756 ngroups = 0;
757 for (i=0 ; i < sb->u.ext2_sb.s_groups_count; i++)
758 if (ext2_group_sparse(i))
759 ngroups++;
760 } else
761 ngroups = sb->u.ext2_sb.s_groups_count;
762 overhead += ngroups * (1 + sb->u.ext2_sb.s_db_per_group);
763
764 /*
765 * Every block group has an inode bitmap, a block
766 * bitmap, and an inode table.
767 */
768 overhead += (sb->u.ext2_sb.s_groups_count *
769 (2 + sb->u.ext2_sb.s_itb_per_group));
770 }
771
772 tmp.f_type = EXT2_SUPER_MAGIC;
773 tmp.f_bsize = sb->s_blocksize;
774 tmp.f_blocks = le32_to_cpu(sb->u.ext2_sb.s_es->s_blocks_count) - overhead;
775 tmp.f_bfree = ext2_count_free_blocks (sb);
776 tmp.f_bavail = tmp.f_bfree - le32_to_cpu(sb->u.ext2_sb.s_es->s_r_blocks_count);
777 if (tmp.f_bfree < le32_to_cpu(sb->u.ext2_sb.s_es->s_r_blocks_count))
778 tmp.f_bavail = 0;
779 tmp.f_files = le32_to_cpu(sb->u.ext2_sb.s_es->s_inodes_count);
780 tmp.f_ffree = ext2_count_free_inodes (sb);
781 tmp.f_namelen = EXT2_NAME_LEN;
782 return copy_to_user(buf, &tmp, bufsiz) ? -EFAULT : 0;
783 }
784
785 static struct file_system_type ext2_fs_type = {
786 "ext2",
787 FS_REQUIRES_DEV /* | FS_IBASKET */, /* ibaskets have unresolved bugs */
788 ext2_read_super,
789 NULL
790 };
791
792 static int __init init_ext2_fs(void)
793 {
794 return register_filesystem(&ext2_fs_type);
795 }
796
797 module_init(init_ext2_fs)
798
799 #ifdef CONFIG_MODULES
800 static void __exit exit_ext2_fs(void)
801 {
802 unregister_filesystem(&ext2_fs_type);
803 }
804
805 module_exit(exit_ext2_fs)
806 #endif
807
808 EXPORT_NO_SYMBOLS;
809
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.