]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2fsprogs: fix blk_t <- blk64_t assignment mismatches
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 7 Oct 2013 13:51:48 +0000 (09:51 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 7 Oct 2013 13:51:48 +0000 (09:51 -0400)
Fix all the places where we should be using a blk64_t instead of a
blk_t.  These fixes are more severe because 64bit values could be
truncated silently.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
18 files changed:
debugfs/logdump.c
debugfs/set_fields.c
e2fsck/e2fsck.h
e2fsck/journal.c
e2fsck/message.c
e2fsck/pass1.c
e2fsck/pass3.c
e2fsck/rehash.c
e2fsck/unix.c
e2fsck/util.c
lib/ext2fs/closefs.c
lib/ext2fs/ext2fsP.h
lib/ext2fs/fileio.c
lib/ext2fs/inode.c
lib/ext2fs/punch.c
lib/ext2fs/tst_iscan.c
misc/dumpe2fs.c
misc/tune2fs.c

index 6e39b74cab9a01c9bfc7fd5e2765fc20ea469d5a..a61d5532dd9760d3462c01ed4deab3cea6f9ef7c 100644 (file)
@@ -37,10 +37,10 @@ extern char *optarg;
 
 enum journal_location {JOURNAL_IS_INTERNAL, JOURNAL_IS_EXTERNAL};
 
-#define ANY_BLOCK ((blk_t) -1)
+#define ANY_BLOCK ((blk64_t) -1)
 
 int            dump_all, dump_contents, dump_descriptors;
-blk_t          block_to_dump, bitmap_to_dump, inode_block_to_dump;
+blk64_t                block_to_dump, bitmap_to_dump, inode_block_to_dump;
 unsigned int   group_to_dump, inode_offset_to_dump;
 ext2_ino_t     inode_to_dump;
 
@@ -162,7 +162,7 @@ void do_logdump(int argc, char **argv)
                        (group_offset / inodes_per_block);
                inode_offset_to_dump = ((group_offset % inodes_per_block)
                                        * sizeof(struct ext2_inode));
-               printf("Inode %u is at group %u, block %u, offset %u\n",
+               printf("Inode %u is at group %u, block %llu, offset %u\n",
                       inode_to_dump, inode_group,
                       inode_block_to_dump, inode_offset_to_dump);
        }
@@ -624,7 +624,7 @@ static void dump_metadata_block(FILE *out_file, struct journal_source *source,
                offset = ((block_to_dump - super->s_first_data_block) %
                          super->s_blocks_per_group);
 
-               fprintf(out_file, "    (block bitmap for block %u: "
+               fprintf(out_file, "    (block bitmap for block %llu: "
                        "block is %s)\n",
                        block_to_dump,
                        ext2fs_test_bit(offset, buf) ? "SET" : "CLEAR");
index 5c86d744c4557147507eb666cfa5d0392f6df92b..b09e2f89feccf5c1edc3f650270377845b8276ec 100644 (file)
@@ -529,22 +529,20 @@ static errcode_t parse_hashalg(struct field_set_info *info,
 static errcode_t parse_bmap(struct field_set_info *info,
                            char *field EXT2FS_ATTR((unused)), char *arg)
 {
-       unsigned long   num;
-       blk_t           blk;
+       blk64_t         blk;
        errcode_t       retval;
        char            *tmp;
 
-       num = strtoul(arg, &tmp, 0);
+       blk = strtoull(arg, &tmp, 0);
        if (*tmp) {
                fprintf(stderr, "Couldn't parse '%s' for field %s.\n",
                        arg, info->name);
                return EINVAL;
        }
-       blk = num;
 
-       retval = ext2fs_bmap(current_fs, set_ino,
+       retval = ext2fs_bmap2(current_fs, set_ino,
                             (struct ext2_inode *) &set_inode,
-                            0, BMAP_SET, array_idx, &blk);
+                            NULL, BMAP_SET, array_idx, NULL, &blk);
        if (retval) {
                com_err("set_inode", retval, "while setting block map");
        }
index 420b67f559126436a74e04964c297d27f253b745..e3ad78d66c3db9d20d28e0acdbcc9e84f55f4465 100644 (file)
@@ -119,9 +119,9 @@ struct dx_dir_info {
 
 struct dx_dirblock_info {
        int             type;
-       blk_t           phys;
+       blk64_t         phys;
        int             flags;
-       blk_t           parent;
+       blk64_t         parent;
        ext2_dirhash_t  min_hash;
        ext2_dirhash_t  max_hash;
        ext2_dirhash_t  node_min_hash;
@@ -548,7 +548,7 @@ extern void e2fsck_write_inode_full(e2fsck_t ctx, unsigned long ino,
 #ifdef MTRACE
 extern void mtrace_print(char *mesg);
 #endif
-extern blk_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs,
+extern blk64_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs,
                           const char *name, io_manager manager);
 extern int ext2_file_type(unsigned int mode);
 extern int write_all(int fd, char *buf, size_t count);
index 6908aec77a2cb186a89d5e26081488e71c75e7be..0cbdb7beadf9763ef062125d0604ce51e0a04a01 100644 (file)
@@ -241,6 +241,7 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
        unsigned long long      start = 0;
        int                     ext_journal = 0;
        int                     tried_backup_jnl = 0;
+       blk64_t                 maxlen;
 
        clear_problem_context(&pctx);
 
@@ -424,7 +425,10 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
                        goto errout;
                }
 
-               journal->j_maxlen = ext2fs_blocks_count(&jsuper);
+               maxlen = ext2fs_blocks_count(&jsuper);
+               if (maxlen > 1ULL << 32)
+                       maxlen = (1ULL << 32) - 1;
+               journal->j_maxlen = maxlen;
                start++;
        }
 
index b99473dd6e93d440627dbb86a9e1f302886c225d..80af1afb6660eeaf08808fe2d72d9141608d7246 100644 (file)
@@ -489,7 +489,7 @@ static _INLINE_ void expand_percent_expression(FILE *f, ext2_filsys fs,
 #endif
                break;
        case 'S':
-               fprintf(f, "%u", get_backup_sb(NULL, fs, NULL, NULL));
+               fprintf(f, "%llu", get_backup_sb(NULL, fs, NULL, NULL));
                break;
        case 's':
                fprintf(f, "%*s", width, ctx->str ? ctx->str : "NULL");
index 8279ce52db37d671408da35e9585776b1eacb4fb..311706e3790d4d7369ca71b7e0dbdb9b9e040af7 100644 (file)
@@ -2566,7 +2566,7 @@ static int process_bad_block(ext2_filsys fs,
        return 0;
 }
 
-static void new_table_block(e2fsck_t ctx, blk_t first_block, int group,
+static void new_table_block(e2fsck_t ctx, blk64_t first_block, int group,
                            const char *name, int num, blk64_t *new_block)
 {
        ext2_filsys fs = ctx->fs;
index 565b8e33fe0924fd464bb06dbf8aa3624b2a7b93..e358bb20a13d48316c9c6a57dcc889faae4271ae 100644 (file)
@@ -758,6 +758,7 @@ errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir,
        errcode_t       retval;
        struct expand_dir_struct es;
        struct ext2_inode       inode;
+       blk64_t         sz;
 
        if (!(fs->flags & EXT2_FLAG_RW))
                return EXT2_ET_RO_FILSYS;
@@ -792,7 +793,9 @@ errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir,
        if (retval)
                return retval;
 
-       inode.i_size = (es.last_block + 1) * fs->blocksize;
+       sz = (es.last_block + 1) * fs->blocksize;
+       inode.i_size = sz;
+       inode.i_size_high = sz >> 32;
        ext2fs_iblk_add_blocks(fs, &inode, es.newblocks);
        quota_data_add(ctx->qctx, &inode, dir, es.newblocks * fs->blocksize);
 
index 3d509adbb150700c2cb51fbd3a567490f8ac59f6..9dbdb3bebd4e218292f227dca734959715f24ed7 100644 (file)
@@ -626,7 +626,7 @@ struct write_dir_struct {
        struct out_dir *outdir;
        errcode_t       err;
        e2fsck_t        ctx;
-       int             cleared;
+       blk64_t         cleared;
 };
 
 /*
index 51eeb251b0b51bfd783a3aa4f55e7f65807d0963..1ed8fc575b186ed7f4bbd4eeceea48b3402b23b4 100644 (file)
@@ -1163,7 +1163,7 @@ int main (int argc, char *argv[])
        const char      *lib_ver_date;
        int             my_ver, lib_ver;
        e2fsck_t        ctx;
-       blk_t           orig_superblock;
+       blk64_t         orig_superblock;
        struct problem_context pctx;
        int flags, run_result;
        int journal_size;
index 647e57122e193cea296c09c3b20b27fe1489831d..d361a5176c895e3395d12b258d067eafc3fef2f0 100644 (file)
@@ -501,14 +501,14 @@ void mtrace_print(char *mesg)
 }
 #endif
 
-blk_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs, const char *name,
-                  io_manager manager)
+blk64_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs, const char *name,
+                     io_manager manager)
 {
        struct ext2_super_block *sb;
        io_channel              io = NULL;
        void                    *buf = NULL;
        int                     blocksize;
-       blk_t                   superblock, ret_sb = 8193;
+       blk64_t                 superblock, ret_sb = 8193;
 
        if (fs && fs->super) {
                ret_sb = (fs->super->s_blocks_per_group +
index 3582a0c9bf7ad2484dbe4d541385d09560557a1c..3a804240c0074e40bbc8fda0df4b67088920d30b 100644 (file)
@@ -244,7 +244,7 @@ void ext2fs_update_dynamic_rev(ext2_filsys fs)
 }
 
 static errcode_t write_backup_super(ext2_filsys fs, dgrp_t group,
-                                   blk_t group_block,
+                                   blk64_t group_block,
                                    struct ext2_super_block *super_shadow)
 {
        dgrp_t  sgrp = group;
index 729d5c537ff549fa851679c213ed9b9b7fef2b7a..46a6767d143e988d1df14103ad53e7884002dd74 100644 (file)
@@ -66,7 +66,7 @@ struct dir_context {
  */
 struct ext2_inode_cache {
        void *                          buffer;
-       blk_t                           buffer_blk;
+       blk64_t                         buffer_blk;
        int                             cache_last;
        int                             cache_size;
        int                             refcount;
index ae5cbf17b319fd26e15c386bdeedc786534a0cf4..e6bc60a4a261fb9c319cabfc5031fef9cb340f56 100644 (file)
@@ -158,7 +158,7 @@ errcode_t ext2fs_file_flush(ext2_file_t file)
  */
 static errcode_t sync_buffer_position(ext2_file_t file)
 {
-       blk_t   b;
+       blk64_t b;
        errcode_t       retval;
 
        b = file->pos / file->fs->blocksize;
index fd72d4cd8a8d7d5d756e986cad632fa199c2e17e..573a8fa5e0423a0a21440cbff1e4c2779fdaf2db 100644 (file)
@@ -270,9 +270,9 @@ errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
  * increasing order.
  */
 static errcode_t check_for_inode_bad_blocks(ext2_inode_scan scan,
-                                           blk_t *num_blocks)
+                                           blk64_t *num_blocks)
 {
-       blk_t   blk = scan->current_block;
+       blk64_t blk = scan->current_block;
        badblocks_list  bb = scan->fs->badblocks;
 
        /*
@@ -329,7 +329,7 @@ static errcode_t check_for_inode_bad_blocks(ext2_inode_scan scan,
  */
 static errcode_t get_next_blocks(ext2_inode_scan scan)
 {
-       blk_t           num_blocks;
+       blk64_t         num_blocks;
        errcode_t       retval;
 
        /*
index 092940042c4e6898ee537a995d38b6d6c5c24a04..4471f468de78aa7026ee82b7ad3b35817bf02350 100644 (file)
@@ -281,7 +281,7 @@ static errcode_t ext2fs_punch_extent(ext2_filsys fs, ext2_ino_t ino,
                dbg_printf("Free start %llu, free count = %u\n",
                       free_start, free_count);
                while (free_count-- > 0) {
-                       ext2fs_block_alloc_stats(fs, free_start++, -1);
+                       ext2fs_block_alloc_stats2(fs, free_start++, -1);
                        freed++;
                }
        next_extent:
index 6f783c38fd50e26b5186d446833b1a1effb5410d..a95296c7dad3be3b7de47a2406d876aadef67ec1 100644 (file)
@@ -26,7 +26,7 @@
 #include "ext2_fs.h"
 #include "ext2fs.h"
 
-blk_t test_vec[] = { 8, 12, 24, 34, 43, 44, 100, 0 };
+blk64_t test_vec[] = { 8, 12, 24, 34, 43, 44, 100, 0 };
 
 ext2_filsys    test_fs;
 ext2fs_block_bitmap bad_block_map, touched_map;
index 8be57642d644be8d89c7e249823b5bb630e59371..2ba177146dd52799f5f04efa623fb5caa5c80a24 100644 (file)
@@ -144,7 +144,7 @@ static void print_bg_rel_offset(ext2_filsys fs, blk64_t block, int itable,
                printf(" (+%u)", (unsigned)(block - first_block));
        } else if (fs->super->s_feature_incompat &
                   EXT4_FEATURE_INCOMPAT_FLEX_BG) {
-               dgrp_t flex_grp = ext2fs_group_of_blk(fs, block);
+               dgrp_t flex_grp = ext2fs_group_of_blk2(fs, block);
                printf(" (bg #%u + %u)", flex_grp,
                       (unsigned)(block-ext2fs_group_first_block(fs,flex_grp)));
        }
index b088f17d2754be34e1ba25da6c9931dba7d4a75a..5feb25b275dc843f64bd310ebf2ad5431749763e 100644 (file)
@@ -495,7 +495,7 @@ static int update_feature_set(ext2_filsys fs, char *features)
 
                /* We need to force out the group descriptors as well */
                fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
-               ext2fs_block_alloc_stats(fs, sb->s_mmp_block, -1);
+               ext2fs_block_alloc_stats2(fs, sb->s_mmp_block, -1);
 mmp_error:
                sb->s_mmp_block = 0;
                sb->s_mmp_update_interval = 0;
@@ -1327,10 +1327,10 @@ static int get_move_bitmaps(ext2_filsys fs, int new_ino_blks_per_grp,
        return 0;
 }
 
-static int ext2fs_is_meta_block(ext2_filsys fs, blk_t blk)
+static int ext2fs_is_meta_block(ext2_filsys fs, blk64_t blk)
 {
        dgrp_t group;
-       group = ext2fs_group_of_blk(fs, blk);
+       group = ext2fs_group_of_blk2(fs, blk);
        if (ext2fs_block_bitmap_loc(fs, group) == blk)
                return 1;
        if (ext2fs_inode_bitmap_loc(fs, group) == blk)
@@ -1338,9 +1338,9 @@ static int ext2fs_is_meta_block(ext2_filsys fs, blk_t blk)
        return 0;
 }
 
-static int ext2fs_is_block_in_group(ext2_filsys fs, dgrp_t group, blk_t blk)
+static int ext2fs_is_block_in_group(ext2_filsys fs, dgrp_t group, blk64_t blk)
 {
-       blk_t start_blk, end_blk;
+       blk64_t start_blk, end_blk;
        start_blk = fs->super->s_first_data_block +
                        EXT2_BLOCKS_PER_GROUP(fs->super) * group;
        /*
@@ -1380,7 +1380,7 @@ static int move_block(ext2_filsys fs, ext2fs_block_bitmap bmap)
                         * the respective fs metadata pointers. Otherwise
                         * fail
                         */
-                       group = ext2fs_group_of_blk(fs, blk);
+                       group = ext2fs_group_of_blk2(fs, blk);
                        goal = ext2fs_group_first_block2(fs, group);
                        meta_data = 1;
 
@@ -1541,7 +1541,7 @@ err_out:
 static int group_desc_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap)
 {
        dgrp_t i;
-       blk_t blk, new_blk;
+       blk64_t blk, new_blk;
 
        for (i = 0; i < fs->group_desc_count; i++) {
                blk = ext2fs_block_bitmap_loc(fs, i);