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                         set_opt (*mount_options, GRPID);
 238                 else if (!strcmp (this_char, "nocheck")) {
 239                         clear_opt (*mount_options, CHECK_NORMAL);
 240                         clear_opt (*mount_options, CHECK_STRICT);
 241                 }
 242                 else if (!strcmp (this_char, "nogrpid"))
 243                         clear_opt (*mount_options, GRPID);
 244                 else if (!strcmp (this_char, "sb")) {
 245                         if (!value || !*value) {
 246                                 printk ("EXT2-fs: the sb option requires "
 247                                         "an argument");
 248                                 return 0;
 249                         }
 250                         *sb_block = simple_strtoul (value, &value, 0);
 251                         if (*value) {
 252                                 printk ("EXT2-fs: Invalid sb option: %s\n",
 253                                         value);
 254                                 return 0;
 255                         }
 256                 }
 257                 else {
 258                         printk ("EXT2-fs: Unrecognized mount option %s\n", this_char);
 259                         return 0;
 260                 }
 261         }
 262         return 1;
 263 }
 264 
 265 static void ext2_setup_super (struct super_block * sb,
     /* [previous][next][first][last][top][bottom][index][help] */
 266                               struct ext2_super_block * es)
 267 {
 268         if (!(sb->u.ext2_sb.s_mount_state & EXT2_VALID_FS))
 269                 printk ("EXT2-fs warning: mounting unchecked fs, "
 270                         "running e2fsck is recommended\n");
 271         else if ((sb->u.ext2_sb.s_mount_state & EXT2_ERROR_FS))
 272                 printk ("EXT2-fs warning: mounting fs with errors, "
 273                         "running e2fsck is recommended\n");
 274         else if (es->s_mnt_count >= es->s_max_mnt_count)
 275                 printk ("EXT2-fs warning: maximal mount count reached, "
 276                         "running e2fsck is recommended\n");
 277         if (!(sb->s_flags & MS_RDONLY)) {
 278                 es->s_state &= ~EXT2_VALID_FS;
 279                 if (!es->s_max_mnt_count)
 280                         es->s_max_mnt_count = EXT2_DFL_MAX_MNT_COUNT;
 281                 es->s_mnt_count++;
 282                 es->s_mtime = CURRENT_TIME;
 283                 sb->u.ext2_sb.s_sbh->b_dirt = 1;
 284                 sb->s_dirt = 1;
 285                 if (test_opt (sb, DEBUG))
 286                         printk ("[EXT II FS %s, %s, bs=%lu, fs=%lu, gc=%lu, "
 287                                 "bpg=%lu, ipg=%lu, mo=%04lx]\n",
 288                                 EXT2FS_VERSION, EXT2FS_DATE, sb->s_blocksize,
 289                                 sb->u.ext2_sb.s_frag_size,
 290                                 sb->u.ext2_sb.s_groups_count,
 291                                 EXT2_BLOCKS_PER_GROUP(sb),
 292                                 EXT2_INODES_PER_GROUP(sb),
 293                                 sb->u.ext2_sb.s_mount_opt);
 294                 if (test_opt (sb, CHECK)) {
 295                         ext2_check_blocks_bitmap (sb);
 296                         ext2_check_inodes_bitmap (sb);
 297                 }
 298         }
 299 }
 300 
 301 static int ext2_check_descriptors (struct super_block * sb)
     /* [previous][next][first][last][top][bottom][index][help] */
 302 {
 303         int i;
 304         int desc_block = 0;
 305         unsigned long block = sb->u.ext2_sb.s_es->s_first_data_block;
 306         struct ext2_group_desc * gdp = NULL;
 307 
 308         ext2_debug ("Checking group descriptors");
 309 
 310         for (i = 0; i < sb->u.ext2_sb.s_groups_count; i++)
 311         {
 312                 if ((i % EXT2_DESC_PER_BLOCK(sb)) == 0)
 313                         gdp = (struct ext2_group_desc *) sb->u.ext2_sb.s_group_desc[desc_block++]->b_data;
 314                 if (gdp->bg_block_bitmap < block ||
 315                     gdp->bg_block_bitmap >= block + EXT2_BLOCKS_PER_GROUP(sb))
 316                 {
 317                         ext2_error (sb, "ext2_check_desciptors",
 318                                     "Block bitmap for group %d"
 319                                     " not in group (block %lu)!",
 320                                     i, gdp->bg_block_bitmap);
 321                         return 0;
 322                 }
 323                 if (gdp->bg_inode_bitmap < block ||
 324                     gdp->bg_inode_bitmap >= block + EXT2_BLOCKS_PER_GROUP(sb))
 325                 {
 326                         ext2_error (sb, "ext2_check_desciptors",
 327                                     "Inode bitmap for group %d"
 328                                     " not in group (block %lu)!",
 329                                     i, gdp->bg_inode_bitmap);
 330                         return 0;
 331                 }
 332                 if (gdp->bg_inode_table < block ||
 333                     gdp->bg_inode_table + sb->u.ext2_sb.s_itb_per_group >=
 334                     block + EXT2_BLOCKS_PER_GROUP(sb))
 335                 {
 336                         ext2_error (sb, "ext2_check_desciptors",
 337                                     "Inode table for group %d"
 338                                     " not in group (block %lu)!",
 339                                     i, gdp->bg_inode_table);
 340                         return 0;
 341                 }
 342                 block += EXT2_BLOCKS_PER_GROUP(sb);
 343                 gdp++;
 344         }
 345         return 1;
 346 }
 347 
 348 struct super_block * ext2_read_super (struct super_block * sb, void * data,
     /* [previous][next][first][last][top][bottom][index][help] */
 349                                       int silent)
 350 {
 351         struct buffer_head * bh;
 352         struct ext2_super_block * es;
 353         unsigned long sb_block = 1;
 354         unsigned long logic_sb_block = 1;
 355         int dev = sb->s_dev;
 356         int bh_count;
 357         int i, j;
 358 #ifdef EXT2FS_PRE_02B_COMPAT
 359         int fs_converted = 0;
 360 #endif
 361 
 362         set_opt (sb->u.ext2_sb.s_mount_opt, CHECK_NORMAL);
 363         if (!parse_options ((char *) data, &sb_block,
 364             &sb->u.ext2_sb.s_mount_opt)) {
 365                 sb->s_dev = 0;
 366                 return NULL;
 367         }
 368 
 369         lock_super (sb);
 370         set_blocksize (dev, BLOCK_SIZE);
 371         if (!(bh = bread (dev, sb_block, BLOCK_SIZE))) {
 372                 sb->s_dev = 0;
 373                 unlock_super (sb);
 374                 printk ("EXT2-fs: unable to read superblock\n");
 375                 return NULL;
 376         }
 377         /*
 378          * Note: s_es must be initialized s_es as soon as possible because
 379          * some ext2 macro-instructions depend on its value
 380          */
 381         es = (struct ext2_super_block *) bh->b_data;
 382         sb->u.ext2_sb.s_es = es;
 383         sb->s_magic = es->s_magic;
 384         if (sb->s_magic != EXT2_SUPER_MAGIC
 385 #ifdef EXT2FS_PRE_02B_COMPAT
 386            && sb->s_magic != EXT2_PRE_02B_MAGIC
 387 #endif
 388            ) {
 389                 sb->s_dev = 0;
 390                 unlock_super (sb);
 391                 brelse (bh);
 392                 if (!silent)
 393                         printk ("VFS: Can't find an ext2 filesystem on dev 0x%04x.\n",
 394                                 dev);
 395                 return NULL;
 396         }
 397         sb->s_blocksize = EXT2_MIN_BLOCK_SIZE << es->s_log_block_size;
 398         sb->s_blocksize_bits = EXT2_BLOCK_SIZE_BITS(sb);
 399         if (sb->s_blocksize != BLOCK_SIZE && 
 400             (sb->s_blocksize == 1024 || sb->s_blocksize == 2048 ||  
 401              sb->s_blocksize == 4096)) {
 402                 unsigned long offset;
 403 
 404                 brelse (bh);
 405                 set_blocksize (dev, sb->s_blocksize);
 406                 logic_sb_block = sb_block / sb->s_blocksize;
 407                 offset = sb_block % sb->s_blocksize;
 408                 bh = bread (dev, logic_sb_block, sb->s_blocksize);
 409                 if(!bh)
 410                         return NULL;
 411                 es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
 412                 sb->u.ext2_sb.s_es = es;
 413                 if (es->s_magic != EXT2_SUPER_MAGIC) {
 414                         sb->s_dev = 0;
 415                         unlock_super (sb);
 416                         brelse (bh);
 417                         printk ("EXT2-fs: Magic mismatch, very weird !\n");
 418                         return NULL;
 419                 }
 420         }
 421         sb->u.ext2_sb.s_frag_size = EXT2_MIN_FRAG_SIZE <<
 422                                    es->s_log_frag_size;
 423         if (sb->u.ext2_sb.s_frag_size)
 424                 sb->u.ext2_sb.s_frags_per_block = sb->s_blocksize /
 425                                                   sb->u.ext2_sb.s_frag_size;
 426         else
 427                 sb->s_magic = 0;
 428         sb->u.ext2_sb.s_blocks_per_group = es->s_blocks_per_group;
 429         sb->u.ext2_sb.s_frags_per_group = es->s_frags_per_group;
 430         sb->u.ext2_sb.s_inodes_per_group = es->s_inodes_per_group;
 431         sb->u.ext2_sb.s_inodes_per_block = sb->s_blocksize /
 432                                            sizeof (struct ext2_inode);
 433         sb->u.ext2_sb.s_itb_per_group = sb->u.ext2_sb.s_inodes_per_group /
 434                                         sb->u.ext2_sb.s_inodes_per_block;
 435         sb->u.ext2_sb.s_desc_per_block = sb->s_blocksize /
 436                                          sizeof (struct ext2_group_desc);
 437         sb->u.ext2_sb.s_sbh = bh;
 438         sb->u.ext2_sb.s_es = es;
 439         sb->u.ext2_sb.s_mount_state = es->s_state;
 440         sb->u.ext2_sb.s_rename_lock = 0;
 441         sb->u.ext2_sb.s_rename_wait = NULL;
 442 #ifdef EXT2FS_PRE_02B_COMPAT
 443         if (sb->s_magic == EXT2_PRE_02B_MAGIC) {
 444                 if (es->s_blocks_count > 262144) {
 445                         /*
 446                          * fs > 256 MB can't be converted
 447                          */ 
 448                         sb->s_dev = 0;
 449                         unlock_super (sb);
 450                         brelse (bh);
 451                         printk ("EXT2-fs: trying to mount a pre-0.2b file"
 452                                 "system which cannot be converted\n");
 453                         return NULL;
 454                 }
 455                 printk ("EXT2-fs: mounting a pre 0.2b file system, "
 456                         "will try to convert the structure\n");
 457                 if (!(sb->s_flags & MS_RDONLY)) {
 458                         sb->s_dev = 0;
 459                         unlock_super (sb);
 460                         brelse (bh);
 461                         printk ("EXT2-fs: cannot convert a read-only fs\n");
 462                         return NULL;
 463                 }
 464                 if (!convert_pre_02b_fs (sb, bh)) {
 465                         sb->s_dev = 0;
 466                         unlock_super (sb);
 467                         brelse (bh);
 468                         printk ("EXT2-fs: conversion failed !!!\n");
 469                         return NULL;
 470                 }
 471                 printk ("EXT2-fs: conversion succeeded !!!\n");
 472                 fs_converted = 1;
 473         }
 474 #endif
 475         if (sb->s_magic != EXT2_SUPER_MAGIC) {
 476                 sb->s_dev = 0;
 477                 unlock_super (sb);
 478                 brelse (bh);
 479                 if (!silent)
 480                         printk ("VFS: Can't find an ext2 filesystem on dev 0x%04x.\n",
 481                                 dev);
 482                 return NULL;
 483         }
 484         if (sb->s_blocksize != bh->b_size) {
 485                 sb->s_dev = 0;
 486                 unlock_super (sb);
 487                 brelse (bh);
 488                 if (!silent)
 489                         printk ("VFS: Unsupported blocksize on dev 0x%04x.\n",
 490                                 dev);
 491                 return NULL;
 492         }
 493 
 494         if (sb->s_blocksize != sb->u.ext2_sb.s_frag_size) {
 495                 sb->s_dev = 0;
 496                 unlock_super (sb);
 497                 brelse (bh);
 498                 printk ("EXT2-fs: fragsize %lu != blocksize %lu (not supported yet)\n",
 499                         sb->u.ext2_sb.s_frag_size, sb->s_blocksize);
 500                 return NULL;
 501         }
 502 
 503         sb->u.ext2_sb.s_groups_count = (es->s_blocks_count -
 504                                         es->s_first_data_block +
 505                                        EXT2_BLOCKS_PER_GROUP(sb) - 1) /
 506                                        EXT2_BLOCKS_PER_GROUP(sb);
 507         for (i = 0; i < EXT2_MAX_GROUP_DESC; i++)
 508                 sb->u.ext2_sb.s_group_desc[i] = NULL;
 509         bh_count = (sb->u.ext2_sb.s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
 510                    EXT2_DESC_PER_BLOCK(sb);
 511         if (bh_count > EXT2_MAX_GROUP_DESC) {
 512                 sb->s_dev = 0;
 513                 unlock_super (sb);
 514                 brelse (bh);
 515                 printk ("EXT2-fs: file system is too big\n");
 516                 return NULL;
 517         }
 518         for (i = 0; i < bh_count; i++) {
 519                 sb->u.ext2_sb.s_group_desc[i] = bread (dev, logic_sb_block + i + 1,
 520                                                        sb->s_blocksize);
 521                 if (!sb->u.ext2_sb.s_group_desc[i]) {
 522                         sb->s_dev = 0;
 523                         unlock_super (sb);
 524                         for (j = 0; j < i; j++)
 525                                 brelse (sb->u.ext2_sb.s_group_desc[i]);
 526                         brelse (bh);
 527                         printk ("EXT2-fs: unable to read group descriptors\n");
 528                         return NULL;
 529                 }
 530         }
 531         if (!ext2_check_descriptors (sb)) {
 532                 sb->s_dev = 0;
 533                 unlock_super (sb);
 534                 for (j = 0; j < i; j++)
 535                         brelse (sb->u.ext2_sb.s_group_desc[i]);
 536                 brelse (bh);
 537                 printk ("EXT2-fs: group descriptors corrupted !\n");
 538                 return NULL;
 539         }
 540         for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++) {
 541                 sb->u.ext2_sb.s_inode_bitmap_number[i] = 0;
 542                 sb->u.ext2_sb.s_inode_bitmap[i] = NULL;
 543                 sb->u.ext2_sb.s_block_bitmap_number[i] = 0;
 544                 sb->u.ext2_sb.s_block_bitmap[i] = NULL;
 545         }
 546         sb->u.ext2_sb.s_loaded_inode_bitmaps = 0;
 547         sb->u.ext2_sb.s_loaded_block_bitmaps = 0;
 548         unlock_super (sb);
 549         /*
 550          * set up enough so that it can read an inode
 551          */
 552         sb->s_dev = dev;
 553         sb->s_op = &ext2_sops;
 554         if (!(sb->s_mounted = iget (sb, EXT2_ROOT_INO))) {
 555                 sb->s_dev = 0;
 556                 for (i = 0; i < EXT2_MAX_GROUP_DESC; i++)
 557                         if (sb->u.ext2_sb.s_group_desc[i])
 558                                 brelse (sb->u.ext2_sb.s_group_desc[i]);
 559                 brelse (bh);
 560                 printk ("EXT2-fs: get root inode failed\n");
 561                 return NULL;
 562         }
 563 #ifdef EXT2FS_PRE_02B_COMPAT
 564         if (fs_converted) {
 565                 for (i = 0; i < bh_count; i++)
 566                         sb->u.ext2_sb.s_group_desc[i]->b_dirt = 1;
 567                 sb->s_dirt = 1;
 568         }
 569 #endif
 570         ext2_setup_super (sb, es);
 571         return sb;
 572 }
 573 
 574 static void ext2_commit_super (struct super_block * sb,
     /* [previous][next][first][last][top][bottom][index][help] */
 575                                struct ext2_super_block * es)
 576 {
 577         es->s_wtime = CURRENT_TIME;
 578         sb->u.ext2_sb.s_sbh->b_dirt = 1;
 579         sb->s_dirt = 0;
 580 }
 581 
 582 /*
 583  * In the second extended file system, it is not necessary to
 584  * write the super block since we use a mapping of the
 585  * disk super block in a buffer.
 586  *
 587  * However, this function is still used to set the fs valid
 588  * flags to 0.  We need to set this flag to 0 since the fs
 589  * may have been checked while mounted and e2fsck may have
 590  * set s_state to EXT2_VALID_FS after some corrections.
 591  */
 592 
 593 void ext2_write_super (struct super_block * sb)
     /* [previous][next][first][last][top][bottom][index][help] */
 594 {
 595         struct ext2_super_block * es;
 596 
 597         if (!(sb->s_flags & MS_RDONLY)) {
 598                 es = sb->u.ext2_sb.s_es;
 599 
 600                 ext2_debug ("setting valid to 0\n");
 601 
 602                 if (es->s_state & EXT2_VALID_FS) {
 603                         es->s_state &= ~EXT2_VALID_FS;
 604                         es->s_mtime = CURRENT_TIME;
 605                 }
 606                 ext2_commit_super (sb, es);
 607         }
 608         sb->s_dirt = 0;
 609 }
 610 
 611 int ext2_remount (struct super_block * sb, int * flags, char * data)
     /* [previous][next][first][last][top][bottom][index][help] */
 612 {
 613         struct ext2_super_block * es;
 614         unsigned long tmp;
 615 
 616         /*
 617          * Allow the "check" option to be passed as a remount option.
 618          */
 619         set_opt (sb->u.ext2_sb.s_mount_opt, CHECK_NORMAL);
 620         parse_options (data, &tmp, &sb->u.ext2_sb.s_mount_opt);
 621 
 622         es = sb->u.ext2_sb.s_es;
 623         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
 624                 return 0;
 625         if (*flags & MS_RDONLY) {
 626                 if (es->s_state & EXT2_VALID_FS ||
 627                     !(sb->u.ext2_sb.s_mount_state & EXT2_VALID_FS))
 628                         return 0;
 629                 /*
 630                  * OK, we are remounting a valid rw partition rdonly, so set
 631                  * the rdonly flag and then mark the partition as valid again.
 632                  */
 633                 es->s_state = sb->u.ext2_sb.s_mount_state;
 634                 es->s_mtime = CURRENT_TIME;
 635                 sb->u.ext2_sb.s_sbh->b_dirt = 1;
 636                 sb->s_dirt = 1;
 637                 ext2_commit_super (sb, es);
 638         }
 639         else {
 640                 /*
 641                  * Mounting a RDONLY partition read-write, so reread and
 642                  * store the current valid flag.  (It may have been changed 
 643                  * by e2fsck since we originally mounted the partition.)
 644                  */
 645                 sb->u.ext2_sb.s_mount_state = es->s_state;
 646                 sb->s_flags &= ~MS_RDONLY;
 647                 ext2_setup_super (sb, es);
 648         }
 649         return 0;
 650 }
 651 
 652 void ext2_statfs (struct super_block * sb, struct statfs * buf)
     /* [previous][next][first][last][top][bottom][index][help] */
 653 {
 654         long tmp;
 655 
 656         put_fs_long (EXT2_SUPER_MAGIC, &buf->f_type);
 657         put_fs_long (sb->s_blocksize, &buf->f_bsize);
 658         put_fs_long (sb->u.ext2_sb.s_es->s_blocks_count, &buf->f_blocks);
 659         tmp = ext2_count_free_blocks (sb);
 660         put_fs_long (tmp, &buf->f_bfree);
 661         if (tmp >= sb->u.ext2_sb.s_es->s_r_blocks_count)
 662                 put_fs_long (tmp - sb->u.ext2_sb.s_es->s_r_blocks_count,
 663                              &buf->f_bavail);
 664         else
 665                 put_fs_long (0, &buf->f_bavail);
 666         put_fs_long (sb->u.ext2_sb.s_es->s_inodes_count, &buf->f_files);
 667         put_fs_long (ext2_count_free_inodes (sb), &buf->f_ffree);
 668         put_fs_long (EXT2_NAME_LEN, &buf->f_namelen);
 669         /* Don't know what value to put in buf->f_fsid */
 670 }

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