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 void ext2_error (struct super_block * sb, const char * function,
     /* [previous][next][first][last][top][bottom][index][help] */
  29                  const char * fmt, ...)
  30 {
  31         char buf[1024];
  32         va_list args;
  33 
  34         if (!(sb->s_flags & MS_RDONLY)) {
  35                 sb->u.ext2_sb.s_mount_state |= EXT2_ERROR_FS;
  36                 sb->u.ext2_sb.s_es->s_state |= EXT2_ERROR_FS;
  37                 mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
  38                 sb->s_dirt = 1;
  39         }
  40         va_start (args, fmt);
  41         vsprintf (buf, fmt, args);
  42         va_end (args);
  43         if (test_opt (sb, ERRORS_PANIC) ||
  44             (sb->u.ext2_sb.s_es->s_errors == EXT2_ERRORS_PANIC &&
  45              !test_opt (sb, ERRORS_CONT) && !test_opt (sb, ERRORS_RO)))
  46                 panic ("EXT2-fs panic (device %d/%d): %s: %s\n",
  47                        MAJOR(sb->s_dev), MINOR(sb->s_dev), function, buf);
  48         printk (KERN_CRIT "EXT2-fs error (device %d/%d): %s: %s\n",
  49                 MAJOR(sb->s_dev), MINOR(sb->s_dev), function, buf);
  50         if (test_opt (sb, ERRORS_RO) ||
  51             (sb->u.ext2_sb.s_es->s_errors == EXT2_ERRORS_RO &&
  52              !test_opt (sb, ERRORS_CONT) && !test_opt (sb, ERRORS_PANIC))) {
  53                 printk ("Remounting filesystem read-only\n");
  54                 sb->s_flags |= MS_RDONLY;
  55         }
  56 }
  57 
  58 NORET_TYPE void ext2_panic (struct super_block * sb, const char * function,
     /* [previous][next][first][last][top][bottom][index][help] */
  59                             const char * fmt, ...)
  60 {
  61         char buf[1024];
  62         va_list args;
  63 
  64         if (!(sb->s_flags & MS_RDONLY)) {
  65                 sb->u.ext2_sb.s_mount_state |= EXT2_ERROR_FS;
  66                 sb->u.ext2_sb.s_es->s_state |= EXT2_ERROR_FS;
  67                 mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
  68                 sb->s_dirt = 1;
  69         }
  70         va_start (args, fmt);
  71         vsprintf (buf, fmt, args);
  72         va_end (args);
  73         panic ("EXT2-fs panic (device %d/%d): %s: %s\n",
  74                MAJOR(sb->s_dev), MINOR(sb->s_dev), function, buf);
  75 }
  76 
  77 void ext2_warning (struct super_block * sb, const char * function,
     /* [previous][next][first][last][top][bottom][index][help] */
  78                    const char * fmt, ...)
  79 {
  80         char buf[1024];
  81         va_list args;
  82 
  83         va_start (args, fmt);
  84         vsprintf (buf, fmt, args);
  85         va_end (args);
  86         printk (KERN_WARNING "EXT2-fs warning (device %d/%d): %s: %s\n",
  87                 MAJOR(sb->s_dev), MINOR(sb->s_dev), function, buf);
  88 }
  89 
  90 void ext2_put_super (struct super_block * sb)
     /* [previous][next][first][last][top][bottom][index][help] */
  91 {
  92         int i;
  93 
  94         lock_super (sb);
  95         if (!(sb->s_flags & MS_RDONLY)) {
  96                 sb->u.ext2_sb.s_es->s_state = sb->u.ext2_sb.s_mount_state;
  97                 mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
  98         }
  99         sb->s_dev = 0;
 100         for (i = 0; i < EXT2_MAX_GROUP_DESC; i++)
 101                 if (sb->u.ext2_sb.s_group_desc[i])
 102                         brelse (sb->u.ext2_sb.s_group_desc[i]);
 103         for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++)
 104                 if (sb->u.ext2_sb.s_inode_bitmap[i])
 105                         brelse (sb->u.ext2_sb.s_inode_bitmap[i]);
 106         for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++)
 107                 if (sb->u.ext2_sb.s_block_bitmap[i])
 108                         brelse (sb->u.ext2_sb.s_block_bitmap[i]);
 109         brelse (sb->u.ext2_sb.s_sbh);
 110         unlock_super (sb);
 111         return;
 112 }
 113 
 114 static struct super_operations ext2_sops = { 
 115         ext2_read_inode,
 116         NULL,
 117         ext2_write_inode,
 118         ext2_put_inode,
 119         ext2_put_super,
 120         ext2_write_super,
 121         ext2_statfs,
 122         ext2_remount
 123 };
 124 
 125 #ifdef EXT2FS_PRE_02B_COMPAT
 126 
 127 static int convert_pre_02b_fs (struct super_block * sb,
     /* [previous][next][first][last][top][bottom][index][help] */
 128                                struct buffer_head * bh)
 129 {
 130         struct ext2_super_block * es;
 131         struct ext2_old_group_desc old_group_desc [BLOCK_SIZE / sizeof (struct ext2_old_group_desc)];
 132         struct ext2_group_desc * gdp;
 133         struct buffer_head * bh2;
 134         int groups_count;
 135         int i;
 136 
 137         es = (struct ext2_super_block *) bh->b_data;
 138         bh2 = bread (sb->s_dev, 2, BLOCK_SIZE);
 139         if (!bh2) {
 140                 printk ("Cannot read descriptor blocks while converting !\n");
 141                 return 0;
 142         }
 143         memcpy (old_group_desc, bh2->b_data, BLOCK_SIZE);
 144         groups_count = (sb->u.ext2_sb.s_blocks_count - 
 145                         sb->u.ext2_sb.s_first_data_block +
 146                         (EXT2_BLOCK_SIZE(sb) * 8) - 1) /
 147                                 (EXT2_BLOCK_SIZE(sb) * 8);
 148         memset (bh2->b_data, 0, BLOCK_SIZE);
 149         gdp = (struct ext2_group_desc *) bh2->b_data;
 150         for (i = 0; i < groups_count; i++) {
 151                 gdp[i].bg_block_bitmap = old_group_desc[i].bg_block_bitmap;
 152                 gdp[i].bg_inode_bitmap = old_group_desc[i].bg_inode_bitmap;
 153                 gdp[i].bg_inode_table = old_group_desc[i].bg_inode_table;
 154                 gdp[i].bg_free_blocks_count = old_group_desc[i].bg_free_blocks_count;
 155                 gdp[i].bg_free_inodes_count = old_group_desc[i].bg_free_inodes_count;
 156         }
 157         mark_buffer_dirty(bh2, 1);
 158         brelse (bh2);
 159         es->s_magic = EXT2_SUPER_MAGIC;
 160         mark_buffer_dirty(bh, 1);
 161         sb->s_magic = EXT2_SUPER_MAGIC;
 162         return 1;
 163 }
 164 
 165 #endif
 166 
 167 /*
 168  * This function has been shamelessly adapted from the msdos fs
 169  */
 170 static int parse_options (char * options, unsigned long * sb_block,
     /* [previous][next][first][last][top][bottom][index][help] */
 171                           unsigned long * mount_options)
 172 {
 173         char * this_char;
 174         char * value;
 175 
 176         if (!options)
 177                 return 1;
 178         for (this_char = strtok (options, ",");
 179              this_char != NULL;
 180              this_char = strtok (NULL, ",")) {
 181                 if ((value = strchr (this_char, '=')) != NULL)
 182                         *value++ = 0;
 183                 if (!strcmp (this_char, "check")) {
 184                         if (!value || !*value)
 185                                 set_opt (*mount_options, CHECK_NORMAL);
 186                         else if (!strcmp (value, "none")) {
 187                                 clear_opt (*mount_options, CHECK_NORMAL);
 188                                 clear_opt (*mount_options, CHECK_STRICT);
 189                         }
 190                         else if (strcmp (value, "normal"))
 191                                 set_opt (*mount_options, CHECK_NORMAL);
 192                         else if (strcmp (value, "strict")) {
 193                                 set_opt (*mount_options, CHECK_NORMAL);
 194                                 set_opt (*mount_options, CHECK_STRICT);
 195                         }
 196                         else {
 197                                 printk ("EXT2-fs: Invalid check option: %s\n",
 198                                         value);
 199                                 return 0;
 200                         }
 201                 }
 202                 else if (!strcmp (this_char, "debug"))
 203                         set_opt (*mount_options, DEBUG);
 204                 else if (!strcmp (this_char, "errors")) {
 205                         if (!value || !*value) {
 206                                 printk ("EXT2-fs: the errors option requires "
 207                                         "an argument");
 208                                 return 0;
 209                         }
 210                         if (!strcmp (value, "continue")) {
 211                                 clear_opt (*mount_options, ERRORS_RO);
 212                                 clear_opt (*mount_options, ERRORS_PANIC);
 213                                 set_opt (*mount_options, ERRORS_CONT);
 214                         }
 215                         else if (!strcmp (value, "remount-ro")) {
 216                                 clear_opt (*mount_options, ERRORS_CONT);
 217                                 clear_opt (*mount_options, ERRORS_PANIC);
 218                                 set_opt (*mount_options, ERRORS_RO);
 219                         }
 220                         else if (!strcmp (value, "panic")) {
 221                                 clear_opt (*mount_options, ERRORS_CONT);
 222                                 clear_opt (*mount_options, ERRORS_RO);
 223                                 set_opt (*mount_options, ERRORS_PANIC);
 224                         }
 225                         else {
 226                                 printk ("EXT2-fs: Invalid errors option: %s\n",
 227                                         value);
 228                                 return 0;
 229                         }
 230                 }
 231                 else if (!strcmp (this_char, "grpid") ||
 232                          !strcmp (this_char, "bsdgroups"))
 233                         set_opt (*mount_options, GRPID);
 234                 else if (!strcmp (this_char, "nocheck")) {
 235                         clear_opt (*mount_options, CHECK_NORMAL);
 236                         clear_opt (*mount_options, CHECK_STRICT);
 237                 }
 238                 else if (!strcmp (this_char, "nogrpid") ||
 239                          !strcmp (this_char, "sysvgroups"))
 240                         clear_opt (*mount_options, GRPID);
 241                 else if (!strcmp (this_char, "sb")) {
 242                         if (!value || !*value) {
 243                                 printk ("EXT2-fs: the sb option requires "
 244                                         "an argument");
 245                                 return 0;
 246                         }
 247                         *sb_block = simple_strtoul (value, &value, 0);
 248                         if (*value) {
 249                                 printk ("EXT2-fs: Invalid sb option: %s\n",
 250                                         value);
 251                                 return 0;
 252                         }
 253                 }
 254                 else {
 255                         printk ("EXT2-fs: Unrecognized mount option %s\n", this_char);
 256                         return 0;
 257                 }
 258         }
 259         return 1;
 260 }
 261 
 262 static void ext2_setup_super (struct super_block * sb,
     /* [previous][next][first][last][top][bottom][index][help] */
 263                               struct ext2_super_block * es)
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 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_desciptors",
 320                                     "Block bitmap for group %d"
 321                                     " not in group (block %lu)!",
 322                                     i, 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_desciptors",
 329                                     "Inode bitmap for group %d"
 330                                     " not in group (block %lu)!",
 331                                     i, 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_desciptors",
 339                                     "Inode table for group %d"
 340                                     " not in group (block %lu)!",
 341                                     i, gdp->bg_inode_table);
 342                         return 0;
 343                 }
 344                 block += EXT2_BLOCKS_PER_GROUP(sb);
 345                 gdp++;
 346         }
 347         return 1;
 348 }
 349 
 350 struct super_block * ext2_read_super (struct super_block * sb, void * data,
     /* [previous][next][first][last][top][bottom][index][help] */
 351                                       int silent)
 352 {
 353         struct buffer_head * bh;
 354         struct ext2_super_block * es;
 355         unsigned long sb_block = 1;
 356         unsigned long logic_sb_block = 1;
 357         int dev = sb->s_dev;
 358         int bh_count;
 359         int i, j;
 360 #ifdef EXT2FS_PRE_02B_COMPAT
 361         int fs_converted = 0;
 362 #endif
 363 
 364         set_opt (sb->u.ext2_sb.s_mount_opt, CHECK_NORMAL);
 365         if (!parse_options ((char *) data, &sb_block,
 366             &sb->u.ext2_sb.s_mount_opt)) {
 367                 sb->s_dev = 0;
 368                 return NULL;
 369         }
 370 
 371         lock_super (sb);
 372         set_blocksize (dev, BLOCK_SIZE);
 373         if (!(bh = bread (dev, sb_block, BLOCK_SIZE))) {
 374                 sb->s_dev = 0;
 375                 unlock_super (sb);
 376                 printk ("EXT2-fs: unable to read superblock\n");
 377                 return NULL;
 378         }
 379         /*
 380          * Note: s_es must be initialized s_es as soon as possible because
 381          * some ext2 macro-instructions depend on its value
 382          */
 383         es = (struct ext2_super_block *) bh->b_data;
 384         sb->u.ext2_sb.s_es = es;
 385         sb->s_magic = es->s_magic;
 386         if (sb->s_magic != EXT2_SUPER_MAGIC
 387 #ifdef EXT2FS_PRE_02B_COMPAT
 388            && sb->s_magic != EXT2_PRE_02B_MAGIC
 389 #endif
 390            ) {
 391                 sb->s_dev = 0;
 392                 unlock_super (sb);
 393                 brelse (bh);
 394                 if (!silent)
 395                         printk ("VFS: Can't find an ext2 filesystem on dev %d/%d.\n",
 396                                 MAJOR(dev), MINOR(dev));
 397                 return NULL;
 398         }
 399         sb->s_blocksize = EXT2_MIN_BLOCK_SIZE << es->s_log_block_size;
 400         sb->s_blocksize_bits = EXT2_BLOCK_SIZE_BITS(sb);
 401         if (sb->s_blocksize != BLOCK_SIZE && 
 402             (sb->s_blocksize == 1024 || sb->s_blocksize == 2048 ||  
 403              sb->s_blocksize == 4096)) {
 404                 unsigned long offset;
 405 
 406                 brelse (bh);
 407                 set_blocksize (dev, sb->s_blocksize);
 408                 logic_sb_block = (sb_block*BLOCK_SIZE) / sb->s_blocksize;
 409                 offset = (sb_block*BLOCK_SIZE) % sb->s_blocksize;
 410                 bh = bread (dev, logic_sb_block, sb->s_blocksize);
 411                 if(!bh)
 412                         return NULL;
 413                 es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
 414                 sb->u.ext2_sb.s_es = es;
 415                 if (es->s_magic != EXT2_SUPER_MAGIC) {
 416                         sb->s_dev = 0;
 417                         unlock_super (sb);
 418                         brelse (bh);
 419                         printk ("EXT2-fs: Magic mismatch, very weird !\n");
 420                         return NULL;
 421                 }
 422         }
 423         sb->u.ext2_sb.s_frag_size = EXT2_MIN_FRAG_SIZE <<
 424                                    es->s_log_frag_size;
 425         if (sb->u.ext2_sb.s_frag_size)
 426                 sb->u.ext2_sb.s_frags_per_block = sb->s_blocksize /
 427                                                   sb->u.ext2_sb.s_frag_size;
 428         else
 429                 sb->s_magic = 0;
 430         sb->u.ext2_sb.s_blocks_per_group = es->s_blocks_per_group;
 431         sb->u.ext2_sb.s_frags_per_group = es->s_frags_per_group;
 432         sb->u.ext2_sb.s_inodes_per_group = es->s_inodes_per_group;
 433         sb->u.ext2_sb.s_inodes_per_block = sb->s_blocksize /
 434                                            sizeof (struct ext2_inode);
 435         sb->u.ext2_sb.s_itb_per_group = sb->u.ext2_sb.s_inodes_per_group /
 436                                         sb->u.ext2_sb.s_inodes_per_block;
 437         sb->u.ext2_sb.s_desc_per_block = sb->s_blocksize /
 438                                          sizeof (struct ext2_group_desc);
 439         sb->u.ext2_sb.s_sbh = bh;
 440         sb->u.ext2_sb.s_es = es;
 441         sb->u.ext2_sb.s_mount_state = es->s_state;
 442         sb->u.ext2_sb.s_rename_lock = 0;
 443         sb->u.ext2_sb.s_rename_wait = NULL;
 444 #ifdef EXT2FS_PRE_02B_COMPAT
 445         if (sb->s_magic == EXT2_PRE_02B_MAGIC) {
 446                 if (es->s_blocks_count > 262144) {
 447                         /*
 448                          * fs > 256 MB can't be converted
 449                          */ 
 450                         sb->s_dev = 0;
 451                         unlock_super (sb);
 452                         brelse (bh);
 453                         printk ("EXT2-fs: trying to mount a pre-0.2b file"
 454                                 "system which cannot be converted\n");
 455                         return NULL;
 456                 }
 457                 printk ("EXT2-fs: mounting a pre 0.2b file system, "
 458                         "will try to convert the structure\n");
 459                 if (!(sb->s_flags & MS_RDONLY)) {
 460                         sb->s_dev = 0;
 461                         unlock_super (sb);
 462                         brelse (bh);
 463                         printk ("EXT2-fs: cannot convert a read-only fs\n");
 464                         return NULL;
 465                 }
 466                 if (!convert_pre_02b_fs (sb, bh)) {
 467                         sb->s_dev = 0;
 468                         unlock_super (sb);
 469                         brelse (bh);
 470                         printk ("EXT2-fs: conversion failed !!!\n");
 471                         return NULL;
 472                 }
 473                 printk ("EXT2-fs: conversion succeeded !!!\n");
 474                 fs_converted = 1;
 475         }
 476 #endif
 477         if (sb->s_magic != EXT2_SUPER_MAGIC) {
 478                 sb->s_dev = 0;
 479                 unlock_super (sb);
 480                 brelse (bh);
 481                 if (!silent)
 482                         printk ("VFS: Can't find an ext2 filesystem on dev %d/%d.\n",
 483                                 MAJOR(dev), MINOR(dev));
 484                 return NULL;
 485         }
 486         if (sb->s_blocksize != bh->b_size) {
 487                 sb->s_dev = 0;
 488                 unlock_super (sb);
 489                 brelse (bh);
 490                 if (!silent)
 491                         printk ("VFS: Unsupported blocksize on dev 0x%04x.\n",
 492                                 dev);
 493                 return NULL;
 494         }
 495 
 496         if (sb->s_blocksize != sb->u.ext2_sb.s_frag_size) {
 497                 sb->s_dev = 0;
 498                 unlock_super (sb);
 499                 brelse (bh);
 500                 printk ("EXT2-fs: fragsize %lu != blocksize %lu (not supported yet)\n",
 501                         sb->u.ext2_sb.s_frag_size, sb->s_blocksize);
 502                 return NULL;
 503         }
 504 
 505         sb->u.ext2_sb.s_groups_count = (es->s_blocks_count -
 506                                         es->s_first_data_block +
 507                                        EXT2_BLOCKS_PER_GROUP(sb) - 1) /
 508                                        EXT2_BLOCKS_PER_GROUP(sb);
 509         for (i = 0; i < EXT2_MAX_GROUP_DESC; i++)
 510                 sb->u.ext2_sb.s_group_desc[i] = NULL;
 511         bh_count = (sb->u.ext2_sb.s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
 512                    EXT2_DESC_PER_BLOCK(sb);
 513         if (bh_count > EXT2_MAX_GROUP_DESC) {
 514                 sb->s_dev = 0;
 515                 unlock_super (sb);
 516                 brelse (bh);
 517                 printk ("EXT2-fs: file system is too big\n");
 518                 return NULL;
 519         }
 520         for (i = 0; i < bh_count; i++) {
 521                 sb->u.ext2_sb.s_group_desc[i] = bread (dev, logic_sb_block + i + 1,
 522                                                        sb->s_blocksize);
 523                 if (!sb->u.ext2_sb.s_group_desc[i]) {
 524                         sb->s_dev = 0;
 525                         unlock_super (sb);
 526                         for (j = 0; j < i; j++)
 527                                 brelse (sb->u.ext2_sb.s_group_desc[j]);
 528                         brelse (bh);
 529                         printk ("EXT2-fs: unable to read group descriptors\n");
 530                         return NULL;
 531                 }
 532         }
 533         if (!ext2_check_descriptors (sb)) {
 534                 sb->s_dev = 0;
 535                 unlock_super (sb);
 536                 for (j = 0; j < i; j++)
 537                         brelse (sb->u.ext2_sb.s_group_desc[j]);
 538                 brelse (bh);
 539                 printk ("EXT2-fs: group descriptors corrupted !\n");
 540                 return NULL;
 541         }
 542         for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++) {
 543                 sb->u.ext2_sb.s_inode_bitmap_number[i] = 0;
 544                 sb->u.ext2_sb.s_inode_bitmap[i] = NULL;
 545                 sb->u.ext2_sb.s_block_bitmap_number[i] = 0;
 546                 sb->u.ext2_sb.s_block_bitmap[i] = NULL;
 547         }
 548         sb->u.ext2_sb.s_loaded_inode_bitmaps = 0;
 549         sb->u.ext2_sb.s_loaded_block_bitmaps = 0;
 550         unlock_super (sb);
 551         /*
 552          * set up enough so that it can read an inode
 553          */
 554         sb->s_dev = dev;
 555         sb->s_op = &ext2_sops;
 556         if (!(sb->s_mounted = iget (sb, EXT2_ROOT_INO))) {
 557                 sb->s_dev = 0;
 558                 for (i = 0; i < EXT2_MAX_GROUP_DESC; i++)
 559                         if (sb->u.ext2_sb.s_group_desc[i])
 560                                 brelse (sb->u.ext2_sb.s_group_desc[i]);
 561                 brelse (bh);
 562                 printk ("EXT2-fs: get root inode failed\n");
 563                 return NULL;
 564         }
 565 #ifdef EXT2FS_PRE_02B_COMPAT
 566         if (fs_converted) {
 567                 for (i = 0; i < bh_count; i++)
 568                         mark_buffer_dirty(sb->u.ext2_sb.s_group_desc[i], 1);
 569                 sb->s_dirt = 1;
 570         }
 571 #endif
 572         ext2_setup_super (sb, es);
 573         return sb;
 574 }
 575 
 576 static void ext2_commit_super (struct super_block * sb,
     /* [previous][next][first][last][top][bottom][index][help] */
 577                                struct ext2_super_block * es)
 578 {
 579         es->s_wtime = CURRENT_TIME;
 580         mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
 581         sb->s_dirt = 0;
 582 }
 583 
 584 /*
 585  * In the second extended file system, it is not necessary to
 586  * write the super block since we use a mapping of the
 587  * disk super block in a buffer.
 588  *
 589  * However, this function is still used to set the fs valid
 590  * flags to 0.  We need to set this flag to 0 since the fs
 591  * may have been checked while mounted and e2fsck may have
 592  * set s_state to EXT2_VALID_FS after some corrections.
 593  */
 594 
 595 void ext2_write_super (struct super_block * sb)
     /* [previous][next][first][last][top][bottom][index][help] */
 596 {
 597         struct ext2_super_block * es;
 598 
 599         if (!(sb->s_flags & MS_RDONLY)) {
 600                 es = sb->u.ext2_sb.s_es;
 601 
 602                 ext2_debug ("setting valid to 0\n");
 603 
 604                 if (es->s_state & EXT2_VALID_FS) {
 605                         es->s_state &= ~EXT2_VALID_FS;
 606                         es->s_mtime = CURRENT_TIME;
 607                 }
 608                 ext2_commit_super (sb, es);
 609         }
 610         sb->s_dirt = 0;
 611 }
 612 
 613 int ext2_remount (struct super_block * sb, int * flags, char * data)
     /* [previous][next][first][last][top][bottom][index][help] */
 614 {
 615         struct ext2_super_block * es;
 616         unsigned long tmp;
 617 
 618         /*
 619          * Allow the "check" option to be passed as a remount option.
 620          */
 621         set_opt (sb->u.ext2_sb.s_mount_opt, CHECK_NORMAL);
 622         parse_options (data, &tmp, &sb->u.ext2_sb.s_mount_opt);
 623 
 624         es = sb->u.ext2_sb.s_es;
 625         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
 626                 return 0;
 627         if (*flags & MS_RDONLY) {
 628                 if (es->s_state & EXT2_VALID_FS ||
 629                     !(sb->u.ext2_sb.s_mount_state & EXT2_VALID_FS))
 630                         return 0;
 631                 /*
 632                  * OK, we are remounting a valid rw partition rdonly, so set
 633                  * the rdonly flag and then mark the partition as valid again.
 634                  */
 635                 es->s_state = sb->u.ext2_sb.s_mount_state;
 636                 es->s_mtime = CURRENT_TIME;
 637                 mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
 638                 sb->s_dirt = 1;
 639                 ext2_commit_super (sb, es);
 640         }
 641         else {
 642                 /*
 643                  * Mounting a RDONLY partition read-write, so reread and
 644                  * store the current valid flag.  (It may have been changed 
 645                  * by e2fsck since we originally mounted the partition.)
 646                  */
 647                 sb->u.ext2_sb.s_mount_state = es->s_state;
 648                 sb->s_flags &= ~MS_RDONLY;
 649                 ext2_setup_super (sb, es);
 650         }
 651         return 0;
 652 }
 653 
 654 void ext2_statfs (struct super_block * sb, struct statfs * buf)
     /* [previous][next][first][last][top][bottom][index][help] */
 655 {
 656         long tmp;
 657 
 658         put_fs_long (EXT2_SUPER_MAGIC, &buf->f_type);
 659         put_fs_long (sb->s_blocksize, &buf->f_bsize);
 660         put_fs_long (sb->u.ext2_sb.s_es->s_blocks_count, &buf->f_blocks);
 661         tmp = ext2_count_free_blocks (sb);
 662         put_fs_long (tmp, &buf->f_bfree);
 663         if (tmp >= sb->u.ext2_sb.s_es->s_r_blocks_count)
 664                 put_fs_long (tmp - sb->u.ext2_sb.s_es->s_r_blocks_count,
 665                              &buf->f_bavail);
 666         else
 667                 put_fs_long (0, &buf->f_bavail);
 668         put_fs_long (sb->u.ext2_sb.s_es->s_inodes_count, &buf->f_files);
 669         put_fs_long (ext2_count_free_inodes (sb), &buf->f_ffree);
 670         put_fs_long (EXT2_NAME_LEN, &buf->f_namelen);
 671         /* Don't know what value to put in buf->f_fsid */
 672 }

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