]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: change fs->clustersize to fs->cluster_ratio_bits
authorTheodore Ts'o <tytso@mit.edu>
Sat, 4 Jun 2011 14:20:47 +0000 (10:20 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 4 Jun 2011 21:43:10 +0000 (17:43 -0400)
The log2 of the ratio of cluster size to block size is far more useful
than just storing the cluster size.  So make this change, and then
define basic utility macros: EXT2FS_CLUSTER_RATIO(),
EXT2FS_CLUSTER_MASK(), EXT2FS_B2C(), EXT2FS_C2B(), and
EXT2FS_NUM_B2C().

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/ext2fs.h
lib/ext2fs/initialize.c
lib/ext2fs/openfs.c
misc/mke2fs.c

index 516eb1afc09d3b0f2f00580d736c3052edf6e047..5379422ba44ec2b0c8a62dd06c35a8b76e53e104 100644 (file)
@@ -195,7 +195,7 @@ struct struct_ext2_filsys {
        char *                          device_name;
        struct ext2_super_block *       super;
        unsigned int                    blocksize;
-       int                             clustersize;
+       int                             cluster_ratio_bits;
        dgrp_t                          group_desc_count;
        unsigned long                   desc_blocks;
        struct ext2_group_desc *        group_desc;
@@ -547,6 +547,17 @@ typedef struct ext2_icount *ext2_icount_t;
 #define EXT2_LIB_SOFTSUPP_INCOMPAT     (0)
 #define EXT2_LIB_SOFTSUPP_RO_COMPAT    (EXT4_FEATURE_RO_COMPAT_BIGALLOC)
 
+
+/* Translate a block number to a cluster number */
+#define EXT2FS_CLUSTER_RATIO(fs)       (1 << (fs)->cluster_ratio_bits)
+#define EXT2FS_CLUSTER_MASK(fs)                (EXT2FS_CLUSTER_RATIO(fs) - 1)
+#define EXT2FS_B2C(fs, blk)            ((blk) >> (fs)->cluster_ratio_bits)
+/* Translate a cluster number to a block number */
+#define EXT2FS_C2B(fs, cluster)                ((cluster) << (fs)->cluster_ratio_bits)
+/* Translate # of blks to # of clusters */
+#define EXT2FS_NUM_B2C(fs, blks)       (((blks) + EXT2FS_CLUSTER_MASK(fs)) >> \
+                                        (fs)->cluster_ratio_bits)
+
 /*
  * function prototypes
  */
index c109d08edb9b4099543e355dc0984bbf0f2fce19..b9d45aefcd7219cac281a76faf34c63165ead8ac 100644 (file)
@@ -178,7 +178,8 @@ errcode_t ext2fs_initialize(const char *name, int flags,
        super->s_creator_os = CREATOR_OS;
 
        fs->blocksize = EXT2_BLOCK_SIZE(super);
-       fs->clustersize = EXT2_CLUSTER_SIZE(super);
+       fs->cluster_ratio_bits = super->s_log_cluster_size -
+               super->s_log_block_size;
 
        /* default: (fs->blocksize*8) blocks/group, up to 2^16 (GDT limit) */
        set_field(s_blocks_per_group, fs->blocksize * 8);
index f87c171701b98bfcd87d87268eb89bd2fe3f260d..a598ca04a39921188d476982f37cf2d61f13ca00 100644 (file)
@@ -250,7 +250,13 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
                retval = EXT2_ET_CORRUPT_SUPERBLOCK;
                goto cleanup;
        }
-       fs->clustersize = EXT2_CLUSTER_SIZE(fs->super);
+       fs->cluster_ratio_bits = fs->super->s_log_cluster_size -
+               fs->super->s_log_block_size;
+       if (EXT2_BLOCKS_PER_GROUP(fs->super) !=
+           EXT2_CLUSTERS_PER_GROUP(fs->super) << fs->cluster_ratio_bits) {
+               retval = EXT2_ET_CORRUPT_SUPERBLOCK;
+               goto cleanup;
+       }
        fs->inode_blocks_per_group = ((EXT2_INODES_PER_GROUP(fs->super) *
                                       EXT2_INODE_SIZE(fs->super) +
                                       EXT2_BLOCK_SIZE(fs->super) - 1) /
index 9f28901ad4d9e18991acc074e54b147174b1096b..c46df6cec272c99fb661f28d86cc4c7cc58c794d 100644 (file)
@@ -619,9 +619,10 @@ static void show_stats(ext2_filsys fs)
        if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
                                       EXT4_FEATURE_RO_COMPAT_BIGALLOC))
                printf(_("Cluster size=%u (log=%u)\n"),
-                      fs->clustersize, s->s_log_cluster_size);
+                      fs->blocksize << fs->cluster_ratio_bits,
+                      s->s_log_cluster_size);
        else
-               printf(_("Fragment size=%u (log=%u)\n"), fs->clustersize,
+               printf(_("Fragment size=%u (log=%u)\n"), EXT2_CLUSTER_SIZE(s),
                       s->s_log_cluster_size);
        printf(_("Stride=%u blocks, Stripe width=%u blocks\n"),
               s->s_raid_stride, s->s_raid_stripe_width);