From: Theodore Ts'o Date: Mon, 17 Dec 2001 04:23:37 +0000 (-0500) Subject: Fix various gcc -Wall nits. Fixed a bug in mke2fs where a bogus X-Git-Tag: E2FSPROGS-1_26-WIP-1224~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4ea7bd04390935e1f8b473c8b857e518df2e226b;p=thirdparty%2Fe2fsprogs.git Fix various gcc -Wall nits. Fixed a bug in mke2fs where a bogus error message could be printed on an malloc() failure, and e2image was optimized to avoid needless system calls by using the stashed inode functions. --- diff --git a/debugfs/ChangeLog b/debugfs/ChangeLog index 831e1fa38..9f510cfc4 100644 --- a/debugfs/ChangeLog +++ b/debugfs/ChangeLog @@ -1,5 +1,8 @@ 2001-12-16 Theodore Tso + * setsuper.c (print_possible_fields), + logdump.c (dump_journal): Fix gcc -Wall nits + * Makefile.in, jfs_user.h: linux/jfs.h has been renamed to linux/jbd.h diff --git a/debugfs/logdump.c b/debugfs/logdump.c index 0102c2484..34552d01b 100644 --- a/debugfs/logdump.c +++ b/debugfs/logdump.c @@ -34,6 +34,7 @@ extern int optreset; /* defined by BSD, but not others */ #include "debugfs.h" #include "jfs_user.h" +#include enum journal_location {JOURNAL_IS_INTERNAL, JOURNAL_IS_EXTERNAL}; @@ -342,13 +343,13 @@ static void dump_journal(char *cmdname, FILE *out_file, (sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) { blocksize = EXT2_BLOCK_SIZE(sb); blocknr = (blocksize == 1024) ? 2 : 1; - uuid_unparse(&sb->s_uuid, jsb_buffer); + uuid_unparse(sb->s_uuid, jsb_buffer); fprintf(out_file, "Ext2 superblock header found.\n"); if (dump_all) { fprintf(out_file, "\tuuid=%s\n", jsb_buffer); fprintf(out_file, "\tblocksize=%d\n", blocksize); fprintf(out_file, "\tjournal data size %ld\n", - sb->s_blocks_count); + (long) sb->s_blocks_count); } } diff --git a/debugfs/setsuper.c b/debugfs/setsuper.c index b9b2136fc..d48bd0487 100644 --- a/debugfs/setsuper.c +++ b/debugfs/setsuper.c @@ -172,7 +172,7 @@ static errcode_t parse_string(struct super_set_info *info, char *arg) static void print_possible_fields() { struct super_set_info *ss; - char *type; + const char *type; printf("Superblock fields supported by the set_super_value command:\n"); for (ss = super_fields ; ss->name ; ss++) { diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index d42ff8fc1..cc55532ff 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,5 +1,9 @@ 2001-12-16 Theodore Tso + * e2fsck.h (ext2fs_get_refcount_size), unix.c (check_mount, PRS), + pass1.c (adjust_extattr_refcount), + ea_refcount.c (ea_refcount_create): Fix gcc -Wall nits. + * recovery.c, revoke.c: Update to versions from 2.4.17-pre8. * journal.c, jfs_user.h: Update support code for new version of diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h index 35de50b54..489847163 100644 --- a/e2fsck/e2fsck.h +++ b/e2fsck/e2fsck.h @@ -304,6 +304,7 @@ extern errcode_t ea_refcount_decrement(ext2_refcount_t refcount, blk_t blk, int *ret); extern errcode_t ea_refcount_store(ext2_refcount_t refcount, blk_t blk, int count); +extern blk_t ext2fs_get_refcount_size(ext2_refcount_t refcount); extern void ea_refcount_intr_begin(ext2_refcount_t refcount); extern blk_t ea_refcount_intr_next(ext2_refcount_t refcount, int *ret); diff --git a/e2fsck/ea_refcount.c b/e2fsck/ea_refcount.c index 9a3f652b1..04ba47c5e 100644 --- a/e2fsck/ea_refcount.c +++ b/e2fsck/ea_refcount.c @@ -47,7 +47,6 @@ errcode_t ea_refcount_create(int size, ext2_refcount_t *ret) ext2_refcount_t refcount; errcode_t retval; size_t bytes; - int i; retval = ext2fs_get_mem(sizeof(struct ea_refcount), (void **) &refcount); diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index b51f5521c..6a5202477 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -933,7 +933,6 @@ static void adjust_extattr_refcount(e2fsck_t ctx, ext2_refcount_t refcount, struct ext2_ext_attr_header *header; struct problem_context pctx; ext2_filsys fs = ctx->fs; - errcode_t retval; blk_t blk; __u32 should_be; int count; diff --git a/e2fsck/unix.c b/e2fsck/unix.c index fb48f2bde..61f737729 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -204,7 +204,7 @@ static void show_stats(e2fsck_t ctx) static void check_mount(e2fsck_t ctx) { errcode_t retval; - int mount_flags, cont, fd; + int mount_flags, cont; retval = ext2fs_check_if_mounted(ctx->filesystem_name, &mount_flags); if (retval) { @@ -592,8 +592,7 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx) ctx->options |= E2F_OPT_READONLY; ctx->filesystem_name = argv[optind]; if (flush) { - int fd = open(ctx->filesystem_name, O_RDONLY, 0); - + fd = open(ctx->filesystem_name, O_RDONLY, 0); if (fd < 0) { com_err("open", errno, _("while opening %s for flushing"), diff --git a/lib/e2p/ChangeLog b/lib/e2p/ChangeLog index 5b4012550..1b2f51456 100644 --- a/lib/e2p/ChangeLog +++ b/lib/e2p/ChangeLog @@ -1,3 +1,7 @@ +2001-12-16 Theodore Tso + + * pf.c: Add const to struct flags_name to avoid -Wall complaints. + 2001-11-05 Theodore Tso * pf.c: Add a new file attribute, EXT2_NOTAIL_FL diff --git a/lib/e2p/pf.c b/lib/e2p/pf.c index 45c7b3686..d9aab2904 100644 --- a/lib/e2p/pf.c +++ b/lib/e2p/pf.c @@ -20,8 +20,8 @@ struct flags_name { unsigned long flag; - char *short_name; - char *long_name; + const char *short_name; + const char *long_name; }; static struct flags_name flags_array[] = { diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index a98001089..a8a4274f1 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,5 +1,9 @@ 2001-12-16 Theodore Tso + * bitops.h (ext2fs_mark_generic_bitmap, ext2fs_unmark_generic_bitmap), + ext_attr.c (ext2fs_read_ext_attr, ext2fs_write_ext_attr), + fileio.c (ext2fs_file_write): Fix gcc -Wall nits + * Makefile.in, jfs_user.h: linux/jfs.h has been renamed to linux/jbd.h diff --git a/lib/ext2fs/bitops.h b/lib/ext2fs/bitops.h index 7872b3672..cb04453cc 100644 --- a/lib/ext2fs/bitops.h +++ b/lib/ext2fs/bitops.h @@ -77,6 +77,11 @@ extern int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap, blk_t block, int num); extern void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map); +/* These two routines moved to gen_bitmap.c */ +extern int ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap, + __u32 bitno); +extern int ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap, + blk_t bitno); /* * The inline routines themselves... * @@ -456,11 +461,6 @@ _INLINE_ int ext2fs_find_next_bit_set (void * addr, int size, int offset) } #endif -/* These two routines moved to gen_bitmap.c */ -extern int ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap, - __u32 bitno); -extern int ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap, - blk_t bitno); _INLINE_ int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap, blk_t bitno); diff --git a/lib/ext2fs/ext_attr.c b/lib/ext2fs/ext_attr.c index 3a281e8d3..b5404390c 100644 --- a/lib/ext2fs/ext_attr.c +++ b/lib/ext2fs/ext_attr.c @@ -60,7 +60,6 @@ void ext2fs_swap_ext_attr(ext2_filsys fs, char *to, char *from) errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf) { errcode_t retval; - struct ext2_ext_attr_entry *entry; retval = io_channel_read_blk(fs->io, block, 1, buf); if (retval) @@ -76,9 +75,8 @@ errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf) errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block, void *inbuf) { errcode_t retval; - char *p, *end, *write_buf; + char *write_buf; char *buf = NULL; - struct ext2_dir_entry *dirent; #ifdef EXT2FS_ENABLE_SWAPFS if ((fs->flags & EXT2_FLAG_SWAP_BYTES) || diff --git a/lib/ext2fs/fileio.c b/lib/ext2fs/fileio.c index 80e503218..e2f479514 100644 --- a/lib/ext2fs/fileio.c +++ b/lib/ext2fs/fileio.c @@ -239,11 +239,9 @@ errcode_t ext2fs_file_write(ext2_file_t file, void *buf, unsigned int nbytes, unsigned int *written) { ext2_filsys fs; - blk_t pb; errcode_t retval = 0; unsigned int start, c, count = 0; char *ptr = (char *) buf; - int dontfill; EXT2_CHECK_MAGIC(file, EXT2_ET_MAGIC_EXT2_FILE); fs = file->fs; diff --git a/misc/ChangeLog b/misc/ChangeLog index 2ac28654d..385fabda5 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,5 +1,14 @@ 2001-12-16 Theodore Tso + * dumpe2fs.c (list_desc), fsck.c (fs_match), + get_device_by_label.c (get_label_uuid), + mke2fs.c (set_fs_defaults, zap_sector, PRS), + tune2fs.c (remove_journal_device, update_feature_set), + util.c (figure_journal_size), util.h: Fix gcc -Wall nits. + + * e2image.c (write_raw_image_file): Fix gcc -Wall nits, and use + the stashed inode functions to optimize away system calls. + * Makefile.in, jfs_user.h: linux/jfs.h has been renamed to linux/jbd.h diff --git a/misc/dumpe2fs.c b/misc/dumpe2fs.c index 87e563f8e..b86bf4ec4 100644 --- a/misc/dumpe2fs.c +++ b/misc/dumpe2fs.c @@ -37,6 +37,7 @@ extern int optind; #include "ext2fs/ext2fs.h" #include "e2p/e2p.h" #include "jfs_user.h" +#include #include "../version.h" #include "nls-enable.h" @@ -45,7 +46,7 @@ extern int optind; const char * program_name = "dumpe2fs"; char * device_name = NULL; -char *num_format = "%lu"; +const char *num_format = "%lu"; static void usage(void) { @@ -125,12 +126,12 @@ static void list_desc (ext2_filsys fs) printf(num_format, fs->group_desc[i].bg_block_bitmap); diff = fs->group_desc[i].bg_block_bitmap - group_blk; if (diff >= 0) - printf(" (+%d)", diff); + printf(" (+%ld)", diff); fputs(_(", Inode bitmap at "), stdout); printf(num_format, fs->group_desc[i].bg_inode_bitmap); diff = fs->group_desc[i].bg_inode_bitmap - group_blk; if (diff >= 0) - printf(" (+%d)", diff); + printf(" (+%ld)", diff); fputs(_("\n Inode table at "), stdout); printf(num_format, fs->group_desc[i].bg_inode_table); fputc('-', stdout); @@ -138,7 +139,7 @@ static void list_desc (ext2_filsys fs) inode_blocks_per_group - 1); diff = fs->group_desc[i].bg_inode_table - group_blk; if (diff > 0) - printf(" (+%d)", diff); + printf(" (+%ld)", diff); printf (_("\n %d free blocks, %d free inodes, " "%d directories\n Free blocks: "), fs->group_desc[i].bg_free_blocks_count, diff --git a/misc/e2image.c b/misc/e2image.c index ccabb197f..d8d43f9e3 100644 --- a/misc/e2image.c +++ b/misc/e2image.c @@ -173,6 +173,16 @@ static errcode_t meta_get_blocks(ext2_filsys fs, ext2_ino_t ino, return 0; } +static errcode_t meta_check_directory(ext2_filsys fs, ext2_ino_t ino) +{ + if ((ino != stashed_ino) || !stashed_inode) + return EXT2_ET_CALLBACK_NOTHANDLED; + + if (!LINUX_S_ISDIR(stashed_inode->i_mode)) + return EXT2_ET_NO_DIRECTORY; + return 0; +} + static errcode_t meta_read_inode(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode) { @@ -182,6 +192,20 @@ static errcode_t meta_read_inode(ext2_filsys fs, ext2_ino_t ino, return 0; } +static void use_inode_shortcuts(ext2_filsys fs, int bool) +{ + if (bool) { + fs->get_blocks = meta_get_blocks; + fs->check_directory = meta_check_directory; + fs->read_inode = meta_read_inode; + stashed_ino = 0; + } else { + fs->get_blocks = 0; + fs->check_directory = 0; + fs->read_inode = 0; + } +} + static int process_dir_block(ext2_filsys fs, blk_t *block_nr, e2_blkcnt_t blockcnt, blk_t ref_block, int ref_offset, void *priv_data) @@ -293,7 +317,7 @@ static void write_block(int fd, char *buf, int sparse_offset, } } -static output_meta_data_blocks(ext2_filsys fs, int fd) +static void output_meta_data_blocks(ext2_filsys fs, int fd) { errcode_t retval; blk_t blk; @@ -360,6 +384,7 @@ static void write_raw_image_file(ext2_filsys fs, int fd) exit(1); } + use_inode_shortcuts(fs, 1); stashed_inode = &inode; while (1) { retval = ext2fs_get_next_inode(scan, &ino, &inode); @@ -404,7 +429,7 @@ static void write_raw_image_file(ext2_filsys fs, int fd) } } } - + use_inode_shortcuts(fs, 0); output_meta_data_blocks(fs, fd); } diff --git a/misc/fsck.c b/misc/fsck.c index c958bafc1..83751bd8a 100644 --- a/misc/fsck.c +++ b/misc/fsck.c @@ -736,7 +736,7 @@ static int fs_match(struct fs_info *fs, struct fs_type_compile *cmp) if (cmp->list == 0 || cmp->list[0] == 0) return 1; - for (n=0; cp = cmp->list[n]; n++) { + for (n=0; (cp = cmp->list[n]); n++) { switch (cmp->type[n]) { case FS_TYPE_NORMAL: checked_type++; diff --git a/misc/fstype.c b/misc/fstype.c index 31f302739..8f127386e 100644 --- a/misc/fstype.c +++ b/misc/fstype.c @@ -16,11 +16,13 @@ #include #include +#include "fsck.h" + struct fs_magic { - const char *fs_name; - int offset; - int len; - char *magic; + const char *fs_name; + int offset; + int len; + const char *magic; }; struct fs_magic type_array[] = { diff --git a/misc/get_device_by_label.c b/misc/get_device_by_label.c index 69750d4f3..2bebcded1 100644 --- a/misc/get_device_by_label.c +++ b/misc/get_device_by_label.c @@ -82,7 +82,7 @@ get_label_uuid(const char *device, char **label, char *uuid) { /* should merge these later */ int fd; size_t label_size; - char *sb_uuid = 0, *sb_label = 0; + unsigned char *sb_uuid = 0, *sb_label = 0; struct ext2_super_block e2sb; struct xfs_super_block xfsb; diff --git a/misc/mke2fs.c b/misc/mke2fs.c index f7e48321c..d60e28e36 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -142,7 +142,8 @@ struct mke2fs_defaults { { 0, 0, 0, 0}, }; -static void set_fs_defaults(char *fs_type, struct ext2_super_block *super, +static void set_fs_defaults(const char *fs_type, + struct ext2_super_block *super, int blocksize, int *inode_ratio) { int megs; @@ -317,7 +318,7 @@ struct progress_struct { }; static void progress_init(struct progress_struct *progress, - char *label,__u32 max) + const char *label,__u32 max) { int i; @@ -555,8 +556,8 @@ static void zap_sector(ext2_filsys fs, int sect, int nsect) buf = malloc(512*nsect); if (!buf) { - printf(_("Warning: out of memory erasing sectors %d-%d: %s\n"), - sect, sect + nsect - 1, error_message(retval)); + printf(_("Out of memory erasing sectors %d-%d\n"), + sect, sect + nsect - 1); exit(1); } memset(buf, 0, 512*nsect); @@ -771,7 +772,7 @@ static void PRS(int argc, char *argv[]) errcode_t retval; char * oldpath = getenv("PATH"); char * raid_opts = 0; - char * fs_type = 0; + const char * fs_type = 0; int default_features = 1; blk_t dev_size; #ifdef linux diff --git a/misc/tune2fs.c b/misc/tune2fs.c index 028c25cd7..794f35b1c 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -95,7 +95,7 @@ static __u32 ok_features[3] = { */ static void remove_journal_device(ext2_filsys fs) { - char *journal_device; + char *journal_path; ext2_filsys jfs; char buf[1024]; journal_superblock_t *jsb; @@ -107,16 +107,16 @@ static void remove_journal_device(ext2_filsys fs) commit_remove_journal = 1; /* force removal even if error */ uuid_unparse(fs->super->s_journal_uuid, buf); - journal_device = get_spec_by_uuid(buf); + journal_path = get_spec_by_uuid(buf); - if (!journal_device) { - journal_device = + if (!journal_path) { + journal_path = ext2fs_find_block_device(fs->super->s_journal_dev); - if (!journal_device) + if (!journal_path) return; } - retval = ext2fs_open(journal_device, EXT2_FLAG_RW| + retval = ext2fs_open(journal_path, EXT2_FLAG_RW| EXT2_FLAG_JOURNAL_DEV_OK, 0, fs->blocksize, unix_io_manager, &jfs); if (retval) { @@ -126,7 +126,7 @@ static void remove_journal_device(ext2_filsys fs) } if (!(jfs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) { fprintf(stderr, _("%s is not a journal device.\n"), - journal_device); + journal_path); goto no_valid_journal; } @@ -181,7 +181,7 @@ no_valid_journal: sizeof(fs->super->s_journal_uuid)); ext2fs_mark_super_dirty(fs); printf(_("Journal removed\n")); - free(journal_device); + free(journal_path); } /* Helper function for remove_journal_inode */ @@ -250,9 +250,7 @@ static void update_feature_set(ext2_filsys fs, char *features) { int sparse, old_sparse, filetype, old_filetype; int journal, old_journal; - struct ext2_inode inode; struct ext2_super_block *sb= fs->super; - errcode_t retval; old_sparse = sb->s_feature_ro_compat & EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; diff --git a/misc/util.c b/misc/util.c index 1160e6b8a..4bffb43a5 100644 --- a/misc/util.c +++ b/misc/util.c @@ -206,7 +206,7 @@ void parse_journal_opts(const char *opts) * in the filesystem. For very small filesystems, it is not reasonable to * have a journal that fills more than half of the filesystem. */ -int figure_journal_size(int journal_size, ext2_filsys fs) +int figure_journal_size(int size, ext2_filsys fs) { blk_t j_blocks; @@ -215,9 +215,8 @@ int figure_journal_size(int journal_size, ext2_filsys fs) return 0; } - if (journal_size >= 0) { - j_blocks = journal_size * 1024 / - (fs->blocksize / 1024); + if (size >= 0) { + j_blocks = size * 1024 / (fs->blocksize / 1024); if (j_blocks < 1024 || j_blocks > 102400) { fprintf(stderr, _("\nThe requested journal " "size is %d blocks; it must be\n" diff --git a/misc/util.h b/misc/util.h index d4ef8f964..d3cc9e66b 100644 --- a/misc/util.h +++ b/misc/util.h @@ -21,5 +21,5 @@ extern void proceed_question(void); extern void check_plausibility(const char *device); extern void parse_journal_opts(const char *opts); extern void check_mount(const char *device, int force, const char *type); -extern int figure_journal_size(int journal_size, ext2_filsys fs); +extern int figure_journal_size(int size, ext2_filsys fs); extern void print_check_message(ext2_filsys fs);