root/fs/ext2/super.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ext2_error
  2. ext2_panic
  3. ext2_warning
  4. ext2_put_super
  5. convert_pre_02b_fs
  6. parse_options
  7. ext2_setup_super
  8. ext2_check_descriptors
  9. ext2_read_super
  10. ext2_commit_super
  11. ext2_write_super
  12. ext2_remount
  13. ext2_statfs

   1 /*
   2  *  linux/fs/ext2/super.c
   3  *
   4  *  Copyright (C) 1992, 1993, 1994  Remy Card (card@masi.ibp.fr)
   5  *                                  Laboratoire MASI - Institut Blaise Pascal
   6  *                                  Universite Pierre et Marie Curie (Paris VI)
   7  *
   8  *  from
   9  *
  10  *  linux/fs/minix/inode.c
  11  *
  12  *  Copyright (C) 1991, 1992  Linus Torvalds
  13  */
  14 
  15 #include <stdarg.h>
  16 
  17 #include <asm/segment.h>
  18 #include <asm/system.h>
  19 
  20 #include <linux/errno.h>
  21 #include <linux/fs.h>
  22 #include <linux/ext2_fs.h>
  23 #include <linux/sched.h>
  24 #include <linux/stat.h>
  25 #include <linux/string.h>
  26 #include <linux/locks.h>
  27 
  28 extern int vsprintf (char *, const char *, va_list);
  29 
  30 void ext2_error (struct super_block * sb, const char * function,
     /* [previous][next][first][last][top][bottom][index][help] */
  31                  const char * fmt, ...)
  32 {
  33         char buf[1024];
  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 |= EXT2_ERROR_FS;
  39                 sb->u.ext2_sb.s_sbh->b_dirt = 1;
  40                 sb->s_dirt = 1;
  41         }
  42         va_start (args, fmt);
  43         vsprintf (buf, fmt, args);
  44         va_end (args);
  45         if (test_opt (sb, ERRORS_PANIC) ||
  46             (sb->u.ext2_sb.s_es->s_errors == EXT2_ERRORS_PANIC &&
  47              !test_opt (sb, ERRORS_CONT) && !test_opt (sb, ERRORS_RO)))
  48                 panic ("EXT2-fs panic (device %d/%d): %s: %s\n",
  49                        MAJOR(sb->s_dev), MINOR(sb->s_dev), function, buf);
  50         printk (KERN_CRIT "EXT2-fs error (device %d/%d): %s: %s\n",
  51                 MAJOR(sb->s_dev), MINOR(sb->s_dev), function, buf);
  52         if (test_opt (sb, ERRORS_RO) ||
  53             (sb->u.ext2_sb.s_es->s_errors == EXT2_ERRORS_RO &&
  54              !test_opt (sb, ERRORS_CONT) && !test_opt (sb, ERRORS_PANIC))) {
  55                 printk ("Remounting filesystem read-only\n");
  56                 sb->s_flags |= MS_RDONLY;
  57         }
  58 }
  59 
  60 NORET_TYPE void ext2_panic (struct super_block * sb, const char * function,
     /* [previous][next][first][last][top][bottom][index][help] */
  61                             const char * fmt, ...)
  62 {
  63         char buf[1024];
  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                 sb->u.ext2_sb.s_sbh->b_dirt = 1;
  70                 sb->s_dirt = 1;
  71         }
  72         va_start (args, fmt);
  73         vsprintf (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, buf);
  77 }
  78 
  79 void ext2_warning (struct super_block * sb, const char * function,
     /* [previous][next][first][last][top][bottom][index][help] */
  80                    const char * fmt, ...)
  81 {
  82         char buf[1024];
  83         va_list args;
  84 
  85         va_start (args, fmt);
  86         vsprintf (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, buf);
  90 }
  91 
  92 void ext2_put_super (struct super_block * sb)
     /* [previous][next][first][last][top][bottom][index][help] */
  93 {
  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                 sb->u.ext2_sb.s_sbh->b_dirt = 1;
 100         }
 101 #ifndef DONT_USE_DCACHE
 102         ext2_dcache_invalidate (sb->s_dev);
 103 #endif
 104         sb->s_dev = 0;
 105         for (i = 0; i < EXT2_MAX_GROUP_DESC; i++)
 106                 if (sb->u.ext2_sb.s_group_desc[i])
 107                         brelse (sb->u.ext2_sb.s_group_desc[i]);
 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,
     /* [previous][next][first][last][top][bottom][index][help] */
 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         bh2->b_dirt = 1;
 163         brelse (bh2);
 164         es->s_magic = EXT2_SUPER_MAGIC;
 165         bh->b_dirt = 1;
 166         sb->s_magic = EXT2_SUPER_MAGIC;
 167         return 1;
 168 }
 169 
 170 #endif
 171 
 172 /*
 173  * This function has been shamelessly adapted from the msdos fs
 174  */
 175 static int parse_options (char * options, unsigned long * sb_block,
     /* [previous][next][first][last][top][bottom][index][help] */
 176                           unsigned long * mount_options)
 177 {
 178         char * this_char;
 179         char * value;
 180 
 181         if (!options)
 182                 return 1;
 183         for (this_char = strtok (options, ",");
 184              this_char != NULL;
 185              this_char = strtok (NULL, ",")) {
 186                 if ((value = strchr (this_char, '=')) != NULL)
 187                         *value++ = 0;
 188                 if (!strcmp (this_char, "check")) {
 189                         if (!value || !*value)
 190                                 set_opt (*mount_options, CHECK_NORMAL);
 191                         else if (!strcmp (value, "none")) {
 192                                 clear_opt (*mount_options, CHECK_NORMAL);
 193                                 clear_opt (*mount_options, CHECK_STRICT);
 194                         }
 195                         else if (strcmp (value, "normal"))
 196                                 set_opt (*mount_options, CHECK_NORMAL);
 197                         else if (strcmp (value, "strict")) {
 198                                 set_opt (*mount_options, CHECK_NORMAL);
 199                                 set_opt (*mount_options, CHECK_STRICT);
 200                         }
 201                         else {
 202                                 printk ("EXT2-fs: Invalid check option: %s\n",
 203                                         value);
 204                                 return 0;
 205                         }
 206                 }
 207                 else if (!strcmp (this_char, "debug"))
 208                         set_opt (*mount_options, DEBUG);
 209                 else if (!strcmp (this_char, "errors")) {
 210                         if (!value || !*value) {
 211                                 printk ("EXT2-fs: the errors option requires "
 212                                         "an argument");
 213                                 return 0;
 214                         }
 215                         if (!strcmp (value, "continue")) {
 216                                 clear_opt (*mount_options, ERRORS_RO);
 217                                 clear_opt (*mount_options, ERRORS_PANIC);
 218                                 set_opt (*mount_options, ERRORS_CONT);
 219                         }
 220                         else if (!strcmp (value, "remount-ro")) {
 221                                 clear_opt (*mount_options, ERRORS_CONT);
 222                                 clear_opt (*mount_options, ERRORS_PANIC);
 223                                 set_opt (*mount_options, ERRORS_RO);
 224                         }
 225                         else if (!strcmp (value, "panic")) {
 226                                 clear_opt (*mount_options, ERRORS_CONT);
 227                                 clear_opt (*mount_options, ERRORS_RO);
 228                                 set_opt (*mount_options, ERRORS_PANIC);
 229                         }
 230                         else {
 231                                 printk ("EXT2-fs: Invalid errors option: %s\n",
 232                                         value);
 233                                 return 0;
 234                         }
 235                 }
 236                 else if (!strcmp (this_char, "grpid") ||
 237                          !strcmp (this_char, "bsdgroups"))
 238                         set_opt (*mount_options, GRPID);
 239                 else if (!strcmp (this_char, "nocheck")) {
 240                         clear_opt (*mount_options, CHECK_NORMAL);
 241                         clear_opt (*mount_options, CHECK_STRICT);
 242                 }
 243                 else if (!strcmp (this_char, "nogrpid") ||
 244                          !strcmp (this_char, "sysvgroups"))
 245                         clear_opt (*mount_options, GRPID);
 246                 else if (!strcmp (this_char, "sb")) {
 247                         if (!value || !*value) {
 248                                 printk ("EXT2-fs: the sb option requires "
 249                                         "an argument");
 250                                 return 0;
 251                         }
 252                         *sb_block = simple_strtoul (value, &value, 0);
 253                         if (*value) {
 254                                 printk ("EXT2-fs: Invalid sb option: %s\n",
 255                                         value);
 256                                 return 0;
 257                         }
 258                 }
 259                 else {
 260                         printk ("EXT2-fs: Unrecognized mount option %s\n", this_char);
 261                         return 0;
 262                 }
 263         }
 264         return 1;
 265 }
 266 
 267 static void ext2_setup_super (struct super_block * sb,
     /* [previous][next][first][last][top][bottom][index][help] */
 268                               struct ext2_super_block * es)
 269 {
 270         if (!(sb->u.ext2_sb.s_mount_state & EXT2_VALID_FS))
 271                 printk ("EXT2-fs warning: mounting unchecked fs, "
 272                         "running e2fsck is recommended\n");
 273         else if ((sb->u.ext2_sb.s_mount_state & EXT2_ERROR_FS))
 274                 printk ("EXT2-fs warning: mounting fs with errors, "
 275                         "running e2fsck is recommended\n");
 276         else if (es->s_max_mnt_count >= 0 &&
 277                  es->s_mnt_count >= es->s_max_mnt_count)
 278                 printk ("EXT2-fs warning: maximal mount count reached, "
 279                         "running e2fsck is recommended\n");
 280         if (!(sb->s_flags & MS_RDONLY)) {
 281                 es->s_state &= ~EXT2_VALID_FS;
 282                 if (!es->s_max_mnt_count)
 283                         es->s_max_mnt_count = EXT2_DFL_MAX_MNT_COUNT;
 284                 es->s_mnt_count++;
 285                 es->s_mtime = CURRENT_TIME;
 286                 sb->u.ext2_sb.s_sbh->b_dirt = 1;
 287                 sb->s_dirt = 1;
 288                 if (test_opt (sb, DEBUG))
 289                         printk ("[EXT II FS %s, %s, bs=%lu, fs=%lu, gc=%lu, "
 290                                 "bpg=%lu, ipg=%lu, mo=%04lx]\n",
 291                                 EXT2FS_VERSION, EXT2FS_DATE, sb->s_blocksize,
 292                                 sb->u.ext2_sb.s_frag_size,
 293                                 sb->u.ext2_sb.s_groups_count,
 294                                 EXT2_BLOCKS_PER_GROUP(sb),
 295                                 EXT2_INODES_PER_GROUP(sb),
 296                                 sb->u.ext2_sb.s_mount_opt);
 297                 if (test_opt (sb, CHECK)) {
 298                         ext2_check_blocks_bitmap (sb);
 299                         ext2_check_inodes_bitmap (sb);
 300                 }
 301         }
 302 }
 303 
 304 static int ext2_check_descriptors (struct super_block * sb)
     /* [previous][next][first][last][top][bottom][index][help] */
 305 {
 306         int i;
 307         int desc_block = 0;
 308         unsigned long block = sb->u.ext2_sb.s_es->s_first_data_block;
 309         struct ext2_group_desc * gdp = NULL;
 310 
 311         ext2_debug ("Checking group descriptors");
 312 
 313         for (i = 0; i < sb->u.ext2_sb.s_groups_count; i++)
 314         {
 315                 if ((i % EXT2_DESC_PER_BLOCK(sb)) == 0)
 316                         gdp = (struct ext2_group_desc *) sb->u.ext2_sb.s_group_desc[desc_block++]->b_data;
 317                 if (gdp->bg_block_bitmap < block ||
 318                     gdp->bg_block_bitmap >= block + EXT2_BLOCKS_PER_GROUP(sb))
 319                 {
 320                         ext2_error (sb, "ext2_check_desciptors",
 321                                     "Block bitmap for group %d"
 322                                     " not in group (block %lu)!",
 323                                     i, gdp->bg_block_bitmap);
 324                         return 0;
 325                 }
 326                 if (gdp->bg_inode_bitmap < block ||
 327                     gdp->bg_inode_bitmap >= block + EXT2_BLOCKS_PER_GROUP(sb))
 328                 {
 329                         ext2_error (sb, "ext2_check_desciptors",
 330                                     "Inode bitmap for group %d"
 331                                     " not in group (block %lu)!",
 332                                     i, gdp->bg_inode_bitmap);
 333                         return 0;
 334                 }
 335                 if (gdp->bg_inode_table < block ||
 336                     gdp->bg_inode_table + sb->u.ext2_sb.s_itb_per_group >=
 337                     block + EXT2_BLOCKS_PER_GROUP(sb))
 338                 {
 339                         ext2_error (sb, "ext2_check_desciptors",
 340                                     "Inode table for group %d"
 341                                     " not in group (block %lu)!",
 342                                     i, gdp->bg_inode_table);
 343                         return 0;
 344                 }
 345                 block += EXT2_BLOCKS_PER_GROUP(sb);
 346                 gdp++;
 347         }
 348         return 1;
 349 }
 350 
 351 struct super_block * ext2_read_super (struct super_block * sb, void * data,
     /* [previous][next][first][last][top][bottom][index][help] */
 352                                       int silent)
 353 {
 354         struct buffer_head * bh;
 355         struct ext2_super_block * es;
 356         unsigned long sb_block = 1;
 357         unsigned long logic_sb_block = 1;
 358         int dev = sb->s_dev;
 359         int bh_count;
 360         int i, j;
 361 #ifdef EXT2FS_PRE_02B_COMPAT
 362         int fs_converted = 0;
 363 #endif
 364 
 365         set_opt (sb->u.ext2_sb.s_mount_opt, CHECK_NORMAL);
 366         if (!parse_options ((char *) data, &sb_block,
 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          * Note: s_es must be initialized s_es as soon as possible because
 382          * some ext2 macro-instructions depend on its value
 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 #ifdef EXT2FS_PRE_02B_COMPAT
 389            && sb->s_magic != EXT2_PRE_02B_MAGIC
 390 #endif
 391            ) {
 392                 sb->s_dev = 0;
 393                 unlock_super (sb);
 394                 brelse (bh);
 395                 if (!silent)
 396                         printk ("VFS: Can't find an ext2 filesystem on dev %d/%d.\n",
 397                                 MAJOR(dev), MINOR(dev));
 398                 return NULL;
 399         }
 400         sb->s_blocksize = EXT2_MIN_BLOCK_SIZE << es->s_log_block_size;
 401         sb->s_blocksize_bits = EXT2_BLOCK_SIZE_BITS(sb);
 402         if (sb->s_blocksize != BLOCK_SIZE && 
 403             (sb->s_blocksize == 1024 || sb->s_blocksize == 2048 ||  
 404              sb->s_blocksize == 4096)) {
 405                 unsigned long offset;
 406 
 407                 brelse (bh);
 408                 set_blocksize (dev, sb->s_blocksize);
 409                 logic_sb_block = sb_block / sb->s_blocksize;
 410                 offset = sb_block % sb->s_blocksize;
 411                 bh = bread (dev, logic_sb_block, sb->s_blocksize);
 412                 if(!bh)
 413                         return NULL;
 414                 es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
 415                 sb->u.ext2_sb.s_es = es;
 416                 if (es->s_magic != EXT2_SUPER_MAGIC) {
 417                         sb->s_dev = 0;
 418                         unlock_super (sb);
 419                         brelse (bh);
 420                         printk ("EXT2-fs: Magic mismatch, very weird !\n");
 421                         return NULL;
 422                 }
 423         }
 424         sb->u.ext2_sb.s_frag_size = EXT2_MIN_FRAG_SIZE <<
 425                                    es->s_log_frag_size;
 426         if (sb->u.ext2_sb.s_frag_size)
 427                 sb->u.ext2_sb.s_frags_per_block = sb->s_blocksize /
 428                                                   sb->u.ext2_sb.s_frag_size;
 429         else
 430                 sb->s_magic = 0;
 431         sb->u.ext2_sb.s_blocks_per_group = es->s_blocks_per_group;
 432         sb->u.ext2_sb.s_frags_per_group = es->s_frags_per_group;
 433         sb->u.ext2_sb.s_inodes_per_group = es->s_inodes_per_group;
 434         sb->u.ext2_sb.s_inodes_per_block = sb->s_blocksize /
 435                                            sizeof (struct ext2_inode);
 436         sb->u.ext2_sb.s_itb_per_group = sb->u.ext2_sb.s_inodes_per_group /
 437                                         sb->u.ext2_sb.s_inodes_per_block;
 438         sb->u.ext2_sb.s_desc_per_block = sb->s_blocksize /
 439                                          sizeof (struct ext2_group_desc);
 440         sb->u.ext2_sb.s_sbh = bh;
 441         sb->u.ext2_sb.s_es = es;
 442         sb->u.ext2_sb.s_mount_state = es->s_state;
 443         sb->u.ext2_sb.s_rename_lock = 0;
 444         sb->u.ext2_sb.s_rename_wait = NULL;
 445 #ifdef EXT2FS_PRE_02B_COMPAT
 446         if (sb->s_magic == EXT2_PRE_02B_MAGIC) {
 447                 if (es->s_blocks_count > 262144) {
 448                         /*
 449                          * fs > 256 MB can't be converted
 450                          */ 
 451                         sb->s_dev = 0;
 452                         unlock_super (sb);
 453                         brelse (bh);
 454                         printk ("EXT2-fs: trying to mount a pre-0.2b file"
 455                                 "system which cannot be converted\n");
 456                         return NULL;
 457                 }
 458                 printk ("EXT2-fs: mounting a pre 0.2b file system, "
 459                         "will try to convert the structure\n");
 460                 if (!(sb->s_flags & MS_RDONLY)) {
 461                         sb->s_dev = 0;
 462                         unlock_super (sb);
 463                         brelse (bh);
 464                         printk ("EXT2-fs: cannot convert a read-only fs\n");
 465                         return NULL;
 466                 }
 467                 if (!convert_pre_02b_fs (sb, bh)) {
 468                         sb->s_dev = 0;
 469                         unlock_super (sb);
 470                         brelse (bh);
 471                         printk ("EXT2-fs: conversion failed !!!\n");
 472                         return NULL;
 473                 }
 474                 printk ("EXT2-fs: conversion succeeded !!!\n");
 475                 fs_converted = 1;
 476         }
 477 #endif
 478         if (sb->s_magic != EXT2_SUPER_MAGIC) {
 479                 sb->s_dev = 0;
 480                 unlock_super (sb);
 481                 brelse (bh);
 482                 if (!silent)
 483                         printk ("VFS: Can't find an ext2 filesystem on dev %d/%d.\n",
 484                                 MAJOR(dev), MINOR(dev));
 485                 return NULL;
 486         }
 487         if (sb->s_blocksize != bh->b_size) {
 488                 sb->s_dev = 0;
 489                 unlock_super (sb);
 490                 brelse (bh);
 491                 if (!silent)
 492                         printk ("VFS: Unsupported blocksize on dev 0x%04x.\n",
 493                                 dev);
 494                 return NULL;
 495         }
 496 
 497         if (sb->s_blocksize != sb->u.ext2_sb.s_frag_size) {
 498                 sb->s_dev = 0;
 499                 unlock_super (sb);
 500                 brelse (bh);
 501                 printk ("EXT2-fs: fragsize %lu != blocksize %lu (not supported yet)\n",
 502                         sb->u.ext2_sb.s_frag_size, sb->s_blocksize);
 503                 return NULL;
 504         }
 505 
 506         sb->u.ext2_sb.s_groups_count = (es->s_blocks_count -
 507                                         es->s_first_data_block +
 508                                        EXT2_BLOCKS_PER_GROUP(sb) - 1) /
 509                                        EXT2_BLOCKS_PER_GROUP(sb);
 510         for (i = 0; i < EXT2_MAX_GROUP_DESC; i++)
 511                 sb->u.ext2_sb.s_group_desc[i] = NULL;
 512         bh_count = (sb->u.ext2_sb.s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
 513                    EXT2_DESC_PER_BLOCK(sb);
 514         if (bh_count > EXT2_MAX_GROUP_DESC) {
 515                 sb->s_dev = 0;
 516                 unlock_super (sb);
 517                 brelse (bh);
 518                 printk ("EXT2-fs: file system is too big\n");
 519                 return NULL;
 520         }
 521         for (i = 0; i < bh_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                         brelse (bh);
 530                         printk ("EXT2-fs: unable to read group descriptors\n");
 531                         return NULL;
 532                 }
 533         }
 534         if (!ext2_check_descriptors (sb)) {
 535                 sb->s_dev = 0;
 536                 unlock_super (sb);
 537                 for (j = 0; j < i; j++)
 538                         brelse (sb->u.ext2_sb.s_group_desc[j]);
 539                 brelse (bh);
 540                 printk ("EXT2-fs: group descriptors corrupted !\n");
 541                 return NULL;
 542         }
 543         for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++) {
 544                 sb->u.ext2_sb.s_inode_bitmap_number[i] = 0;
 545                 sb->u.ext2_sb.s_inode_bitmap[i] = NULL;
 546                 sb->u.ext2_sb.s_block_bitmap_number[i] = 0;
 547                 sb->u.ext2_sb.s_block_bitmap[i] = NULL;
 548         }
 549         sb->u.ext2_sb.s_loaded_inode_bitmaps = 0;
 550         sb->u.ext2_sb.s_loaded_block_bitmaps = 0;
 551         unlock_super (sb);
 552         /*
 553          * set up enough so that it can read an inode
 554          */
 555         sb->s_dev = dev;
 556         sb->s_op = &ext2_sops;
 557         if (!(sb->s_mounted = iget (sb, EXT2_ROOT_INO))) {
 558                 sb->s_dev = 0;
 559                 for (i = 0; i < EXT2_MAX_GROUP_DESC; i++)
 560                         if (sb->u.ext2_sb.s_group_desc[i])
 561                                 brelse (sb->u.ext2_sb.s_group_desc[i]);
 562                 brelse (bh);
 563                 printk ("EXT2-fs: get root inode failed\n");
 564                 return NULL;
 565         }
 566 #ifdef EXT2FS_PRE_02B_COMPAT
 567         if (fs_converted) {
 568                 for (i = 0; i < bh_count; i++)
 569                         sb->u.ext2_sb.s_group_desc[i]->b_dirt = 1;
 570                 sb->s_dirt = 1;
 571         }
 572 #endif
 573         ext2_setup_super (sb, es);
 574         return sb;
 575 }
 576 
 577 static void ext2_commit_super (struct super_block * sb,
     /* [previous][next][first][last][top][bottom][index][help] */
 578                                struct ext2_super_block * es)
 579 {
 580         es->s_wtime = CURRENT_TIME;
 581         sb->u.ext2_sb.s_sbh->b_dirt = 1;
 582         sb->s_dirt = 0;
 583 }
 584 
 585 /*
 586  * In the second extended file system, it is not necessary to
 587  * write the super block since we use a mapping of the
 588  * disk super block in a buffer.
 589  *
 590  * However, this function is still used to set the fs valid
 591  * flags to 0.  We need to set this flag to 0 since the fs
 592  * may have been checked while mounted and e2fsck may have
 593  * set s_state to EXT2_VALID_FS after some corrections.
 594  */
 595 
 596 void ext2_write_super (struct super_block * sb)
     /* [previous][next][first][last][top][bottom][index][help] */
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 615 {
 616         struct ext2_super_block * es;
 617         unsigned long tmp;
 618 
 619         /*
 620          * Allow the "check" option to be passed as a remount option.
 621          */
 622         set_opt (sb->u.ext2_sb.s_mount_opt, CHECK_NORMAL);
 623         parse_options (data, &tmp, &sb->u.ext2_sb.s_mount_opt);
 624 
 625         es = sb->u.ext2_sb.s_es;
 626         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
 627                 return 0;
 628         if (*flags & MS_RDONLY) {
 629                 if (es->s_state & EXT2_VALID_FS ||
 630                     !(sb->u.ext2_sb.s_mount_state & EXT2_VALID_FS))
 631                         return 0;
 632                 /*
 633                  * OK, we are remounting a valid rw partition rdonly, so set
 634                  * the rdonly flag and then mark the partition as valid again.
 635                  */
 636                 es->s_state = sb->u.ext2_sb.s_mount_state;
 637                 es->s_mtime = CURRENT_TIME;
 638                 sb->u.ext2_sb.s_sbh->b_dirt = 1;
 639                 sb->s_dirt = 1;
 640                 ext2_commit_super (sb, es);
 641         }
 642         else {
 643                 /*
 644                  * Mounting a RDONLY partition read-write, so reread and
 645                  * store the current valid flag.  (It may have been changed 
 646                  * by e2fsck since we originally mounted the partition.)
 647                  */
 648                 sb->u.ext2_sb.s_mount_state = es->s_state;
 649                 sb->s_flags &= ~MS_RDONLY;
 650                 ext2_setup_super (sb, es);
 651         }
 652         return 0;
 653 }
 654 
 655 void ext2_statfs (struct super_block * sb, struct statfs * buf)
     /* [previous][next][first][last][top][bottom][index][help] */
 656 {
 657         long tmp;
 658 
 659         put_fs_long (EXT2_SUPER_MAGIC, &buf->f_type);
 660         put_fs_long (sb->s_blocksize, &buf->f_bsize);
 661         put_fs_long (sb->u.ext2_sb.s_es->s_blocks_count, &buf->f_blocks);
 662         tmp = ext2_count_free_blocks (sb);
 663         put_fs_long (tmp, &buf->f_bfree);
 664         if (tmp >= sb->u.ext2_sb.s_es->s_r_blocks_count)
 665                 put_fs_long (tmp - sb->u.ext2_sb.s_es->s_r_blocks_count,
 666                              &buf->f_bavail);
 667         else
 668                 put_fs_long (0, &buf->f_bavail);
 669         put_fs_long (sb->u.ext2_sb.s_es->s_inodes_count, &buf->f_files);
 670         put_fs_long (ext2_count_free_inodes (sb), &buf->f_ffree);
 671         put_fs_long (EXT2_NAME_LEN, &buf->f_namelen);
 672         /* Don't know what value to put in buf->f_fsid */
 673 }

/* [previous][next][first][last][top][bottom][index][help] */