Whamcloud - gitweb
Fix bug where mke2fs was incorrectly checking
[tools/e2fsprogs.git] / misc / mke2fs.c
index 3b44015..f0183ed 100644 (file)
@@ -166,7 +166,8 @@ static void set_fs_defaults(const char *fs_type,
                    (megs > p->size))
                        continue;
                if (ratio == 0)
-                       *inode_ratio = p->inode_ratio;
+                       *inode_ratio = p->inode_ratio < blocksize ?
+                               blocksize : p->inode_ratio;
                if (blocksize == 0) {
                        if (p->blocksize == DEF_MAX_BLOCKSIZE)
                                p->blocksize = sys_page_size;
@@ -403,10 +404,9 @@ static errcode_t zero_blocks(ext2_filsys fs, blk_t blk, int num,
        if (next_update_incr < 1)
                next_update_incr = 1;
        for (j=0; j < num; j += STRIDE_LENGTH, blk += STRIDE_LENGTH) {
-               if (num-j > STRIDE_LENGTH)
+               count = num - j;
+               if (count > STRIDE_LENGTH)
                        count = STRIDE_LENGTH;
-               else
-                       count = num - j;
                retval = io_channel_write_blk(fs->io, blk, count, buf);
                if (retval) {
                        if (ret_count)
@@ -570,7 +570,6 @@ static void zap_sector(ext2_filsys fs, int sect, int nsect)
                       sect, sect + nsect - 1);
                exit(1);
        }
-       memset(buf, 0, 512*nsect);
 
        if (sect == 0) {
                /* Check for a BSD disklabel, and don't erase it if so */
@@ -587,6 +586,7 @@ static void zap_sector(ext2_filsys fs, int sect, int nsect)
                }
        }
 
+       memset(buf, 0, 512*nsect);
        io_channel_set_blksize(fs->io, 512);
        retval = io_channel_write_blk(fs->io, sect, -512*nsect, buf);
        io_channel_set_blksize(fs->io, fs->blocksize);
@@ -777,9 +777,11 @@ static void parse_raid_opts(const char *opts)
 }      
 
 static __u32 ok_features[3] = {
-       EXT3_FEATURE_COMPAT_HAS_JOURNAL,        /* Compat */
+       EXT3_FEATURE_COMPAT_HAS_JOURNAL |
+               EXT2_FEATURE_COMPAT_DIR_INDEX,  /* Compat */
        EXT2_FEATURE_INCOMPAT_FILETYPE|         /* Incompat */
-               EXT3_FEATURE_INCOMPAT_JOURNAL_DEV,
+               EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|
+               EXT2_FEATURE_INCOMPAT_META_BG,
        EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER     /* R/O compat */
 };
 
@@ -789,7 +791,6 @@ static void PRS(int argc, char *argv[])
        int             c;
        int             size;
        char *          tmp;
-       blk_t           group_blk_max = 8192;
        int             blocksize = 0;
        int             inode_ratio = 0;
        int             inode_size = 0;
@@ -829,7 +830,7 @@ static void PRS(int argc, char *argv[])
 #endif
 #ifdef _SC_PAGESIZE
        sysval = sysconf(_SC_PAGESIZE);
-       if (sysconf > 0)
+       if (sysval > 0)
                sys_page_size = sysval;
 #endif /* _SC_PAGESIZE */
 #endif /* HAVE_SYSCONF */
@@ -841,7 +842,10 @@ static void PRS(int argc, char *argv[])
        param.s_rev_level = 1;  /* Create revision 1 filesystems now */
        param.s_feature_incompat |= EXT2_FEATURE_INCOMPAT_FILETYPE;
        param.s_feature_ro_compat |= EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
-               
+#if 0
+       param.s_feature_compat |= EXT2_FEATURE_COMPAT_DIR_INDEX;
+#endif
+
 #ifdef __linux__
        if (uname(&ut)) {
                perror("uname");
@@ -884,7 +888,6 @@ static void PRS(int argc, char *argv[])
                                        blocksize);
                        param.s_log_block_size =
                                int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
-                       group_blk_max = blocksize * 8;
                        break;
                case 'c':       /* Check for bad blocks */
                case 't':       /* deprecated */
@@ -1162,11 +1165,17 @@ static void PRS(int argc, char *argv[])
            !journal_size)
                journal_size = -1;
 
+       /* Set first meta blockgroup via an environment variable */
+       /* (this is mostly for debugging purposes) */
+       if ((param.s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) &&
+           ((tmp = getenv("MKE2FS_FIRST_META_BG"))))
+               param.s_first_meta_bg = atoi(tmp);
+
        set_fs_defaults(fs_type, &param, blocksize, &inode_ratio);
 
        if (param.s_blocks_per_group) {
                if (param.s_blocks_per_group < 256 ||
-                   param.s_blocks_per_group > group_blk_max || *tmp) {
+                   param.s_blocks_per_group > 8 * EXT2_BLOCK_SIZE(&param)) {
                        com_err(program_name, 0,
                                _("blocks per group count out of range"));
                        exit(1);
@@ -1242,6 +1251,12 @@ int main (int argc, char *argv[])
        uuid_generate(fs->super->s_uuid);
 
        /*
+        * Initialize the directory index variables
+        */
+       fs->super->s_def_hash_version = EXT2_HASH_TEA;
+       uuid_generate((unsigned char *) fs->super->s_hash_seed);
+
+       /*
         * Add "jitter" to the superblock's check interval so that we
         * don't check all the filesystems at the same time.  We use a
         * kludgy hack of using the UUID to derive a random jitter value.
@@ -1339,9 +1354,8 @@ int main (int argc, char *argv[])
 
                if (retval) {
                        com_err(program_name, retval,
-                               _("zeroing block %u at end of filesystem"),
+                               _("while zeroing block %u at end of filesystem"),
                                ret_blk);
-                       exit(1);
                }
                write_inode_tables(fs);
                create_root_dir(fs);