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