Whamcloud - gitweb
Merge branch 'maint'
[tools/e2fsprogs.git] / lib / ext2fs / openfs.c
index d705b1c..a6a8217 100644 (file)
@@ -39,11 +39,10 @@ blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, dgrp_t i)
            (i < fs->super->s_first_meta_bg))
                return (group_block + i + 1);
 
-       bg = (fs->blocksize / sizeof (struct ext2_group_desc)) * i;
+       bg = EXT2_DESC_PER_BLOCK(fs->super) * i;
        if (ext2fs_bg_has_super(fs, bg))
                has_super = 1;
-       ret_blk = (fs->super->s_first_data_block + has_super + 
-                  (bg * fs->super->s_blocks_per_group));
+       ret_blk = ext2fs_group_first_block(fs, bg) + has_super;
        /*
         * If group_block is not the normal value, we're trying to use
         * the backup group descriptors and superblock --- so use the
@@ -178,12 +177,13 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
        if (fs->orig_super)
                memcpy(fs->orig_super, fs->super, SUPERBLOCK_SIZE);
 
-#ifdef EXT2FS_ENABLE_SWAPFS
-       if ((fs->super->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC)) ||
-           (fs->flags & EXT2_FLAG_SWAP_BYTES)) {
-               fs->flags |= EXT2_FLAG_SWAP_BYTES;
-
-               ext2fs_swap_super(fs->super);
+#ifdef WORDS_BIGENDIAN
+       fs->flags |= EXT2_FLAG_SWAP_BYTES;
+       ext2fs_swap_super(fs->super);
+#else
+       if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
+               retval = EXT2_ET_UNIMPLEMENTED;
+               goto cleanup;
        }
 #endif
        
@@ -287,18 +287,16 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
        if (!group_block)
                group_block = fs->super->s_first_data_block;
        dest = (char *) fs->group_desc;
-       groups_per_block = fs->blocksize / sizeof(struct ext2_group_desc);
+       groups_per_block = EXT2_DESC_PER_BLOCK(fs->super);
        for (i=0 ; i < fs->desc_blocks; i++) {
                blk = ext2fs_descriptor_block_loc(fs, group_block, i);
                retval = io_channel_read_blk(fs->io, blk, 1, dest);
                if (retval)
                        goto cleanup;
-#ifdef EXT2FS_ENABLE_SWAPFS
-               if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
-                       gdp = (struct ext2_group_desc *) dest;
-                       for (j=0; j < groups_per_block; j++)
-                               ext2fs_swap_group_desc(gdp++);
-               }
+#ifdef WORDS_BIGENDIAN
+               gdp = (struct ext2_group_desc *) dest;
+               for (j=0; j < groups_per_block; j++)
+                       ext2fs_swap_group_desc(gdp++);
 #endif
                dest += fs->blocksize;
        }