diff --git a/e2fsck/unix.c b/e2fsck/unix.c index 63487775..48db71ab 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -1173,7 +1173,7 @@ int main (int argc, char *argv[]) int old_bitmaps; __u32 features[3]; char *cp; - int qtype; /* quota type */ + int qtype = -99; /* quota type */ clear_problem_context(&pctx); sigcatcher_setup(); diff --git a/e2fsck/util.c b/e2fsck/util.c index 7c4caab0..f3ba6453 100644 --- a/e2fsck/util.c +++ b/e2fsck/util.c @@ -795,7 +795,6 @@ void e2fsck_set_bitmap_type(ext2_filsys fs, unsigned int default_type, const char *profile_name, unsigned int *old_type) { unsigned type; - errcode_t retval; if (old_type) *old_type = fs->default_bitmap_type; diff --git a/lib/ext2fs/blkmap64_rb.c b/lib/ext2fs/blkmap64_rb.c index 7196e906..6007238c 100644 --- a/lib/ext2fs/blkmap64_rb.c +++ b/lib/ext2fs/blkmap64_rb.c @@ -70,7 +70,7 @@ static void print_tree(struct rb_root *root) printf("\t\t\t=================================\n"); } -static int check_tree(struct rb_root *root, const char *msg) +static void check_tree(struct rb_root *root, const char *msg) { struct rb_node *new_node, *node, *next; struct bmap_rb_extent *ext, *old = NULL; @@ -115,7 +115,7 @@ static int check_tree(struct rb_root *root, const char *msg) } old = ext; } - return 0; + return; err_out: printf("%s\n", msg); @@ -123,8 +123,8 @@ err_out: exit(1); } #else -#define check_tree(root, msg) 0 -#define print_tree(root, msg) 0 +#define check_tree(root, msg) do {} while (0) +#define print_tree(root, msg) do {} while (0) #endif static void rb_get_new_extent(struct bmap_rb_extent **ext, __u64 start, diff --git a/lib/ext2fs/bmap.c b/lib/ext2fs/bmap.c index 16d51e0b..aadd22ed 100644 --- a/lib/ext2fs/bmap.c +++ b/lib/ext2fs/bmap.c @@ -95,7 +95,7 @@ static _BMAP_INLINE_ errcode_t block_dind_bmap(ext2_filsys fs, int flags, int *blocks_alloc, blk_t nr, blk_t *ret_blk) { - blk_t b; + blk_t b = 0; errcode_t retval; blk_t addr_per_block; @@ -115,7 +115,7 @@ static _BMAP_INLINE_ errcode_t block_tind_bmap(ext2_filsys fs, int flags, int *blocks_alloc, blk_t nr, blk_t *ret_blk) { - blk_t b; + blk_t b = 0; errcode_t retval; blk_t addr_per_block; diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c index bf532ae0..6a223df5 100644 --- a/lib/ext2fs/ismounted.c +++ b/lib/ext2fs/ismounted.c @@ -302,9 +302,7 @@ leave: errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags, char *mtpt, int mtlen) { - struct stat st_buf; errcode_t retval = 0; - int fd; if (is_swap_device(device)) { *mount_flags = EXT2_MF_MOUNTED | EXT2_MF_SWAP; @@ -327,15 +325,18 @@ errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags, return retval; #ifdef __linux__ /* This only works on Linux 2.6+ systems */ - if ((stat(device, &st_buf) != 0) || - !S_ISBLK(st_buf.st_mode)) - return 0; - fd = open(device, O_RDONLY | O_EXCL); - if (fd < 0) { - if (errno == EBUSY) - *mount_flags |= EXT2_MF_BUSY; - } else - close(fd); + { + struct stat st_buf; + + if (stat(device, &st_buf) == 0 && S_ISBLK(st_buf.st_mode)) { + int fd = open(device, O_RDONLY | O_EXCL); + + if (fd >= 0) + close(fd); + else if (errno == EBUSY) + *mount_flags |= EXT2_MF_BUSY; + } + } #endif return 0; diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c index 30ccdd20..c154d916 100644 --- a/lib/ext2fs/mkjournal.c +++ b/lib/ext2fs/mkjournal.c @@ -496,7 +496,7 @@ errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks, int flags) ext2_ino_t journal_ino; struct stat st; char jfile[1024]; - int mount_flags, f; + int mount_flags; int fd = -1; if (flags & EXT2_MKJOURNAL_NO_MNT_CHECK) @@ -507,6 +507,9 @@ errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks, int flags) return retval; if (mount_flags & EXT2_MF_MOUNTED) { +#if HAVE_EXT2_IOCTLS + int f = 0; +#endif strcat(jfile, "/.journal"); /* @@ -519,7 +522,6 @@ errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks, int flags) #if HAVE_EXT2_IOCTLS fd = open(jfile, O_RDONLY); if (fd >= 0) { - f = 0; ioctl(fd, EXT2_IOC_SETFLAGS, &f); close(fd); } diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c index 53f6ec48..3f3ed651 100644 --- a/lib/ext2fs/rw_bitmaps.c +++ b/lib/ext2fs/rw_bitmaps.c @@ -154,7 +154,6 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) int block_nbytes = EXT2_CLUSTERS_PER_GROUP(fs->super) / 8; int inode_nbytes = EXT2_INODES_PER_GROUP(fs->super) / 8; int csum_flag = 0; - int do_image = fs->flags & EXT2_FLAG_IMAGE_FILE; unsigned int cnt; blk64_t blk; blk64_t blk_itr = EXT2FS_B2C(fs, fs->super->s_first_data_block); diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c index 73716546..19be6308 100644 --- a/lib/ext2fs/unix_io.c +++ b/lib/ext2fs/unix_io.c @@ -472,7 +472,7 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel) io_channel io = NULL; struct unix_private_data *data = NULL; errcode_t retval; - int open_flags, zeroes = 0; + int open_flags; int f_nocache = 0; ext2fs_struct_stat st; #ifdef __linux__ @@ -550,9 +550,12 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel) } #ifdef BLKDISCARDZEROES - ioctl(data->dev, BLKDISCARDZEROES, &zeroes); - if (zeroes) - io->flags |= CHANNEL_FLAGS_DISCARD_ZEROES; + { + int zeroes = 0; + if (ioctl(data->dev, BLKDISCARDZEROES, &zeroes) == 0 && + zeroes) + io->flags |= CHANNEL_FLAGS_DISCARD_ZEROES; + } #endif #if defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) @@ -920,7 +923,6 @@ static errcode_t unix_discard(io_channel channel, unsigned long long block, unsigned long long count) { struct unix_private_data *data; - __uint64_t range[2]; int ret; EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); @@ -929,6 +931,8 @@ static errcode_t unix_discard(io_channel channel, unsigned long long block, if (channel->flags & CHANNEL_FLAGS_BLOCK_DEVICE) { #ifdef BLKDISCARD + __uint64_t range[2]; + range[0] = (__uint64_t)(block) * channel->block_size; range[1] = (__uint64_t)(count) * channel->block_size; diff --git a/lib/quota/quotaio.c b/lib/quota/quotaio.c index 7cdd6530..ac34a80d 100644 --- a/lib/quota/quotaio.c +++ b/lib/quota/quotaio.c @@ -117,7 +117,6 @@ static int compute_num_blocks_proc(ext2_filsys fs, blk64_t *blocknr, int ref_offset EXT2FS_ATTR((unused)), void *private) { - blk64_t block; blk64_t *num_blocks = private; *num_blocks += 1; @@ -128,7 +127,6 @@ errcode_t quota_inode_truncate(ext2_filsys fs, ext2_ino_t ino) { struct ext2_inode inode; errcode_t err; - int i; if ((err = ext2fs_read_inode(fs, ino, &inode))) return err; diff --git a/lib/uuid/gen_uuid.c b/lib/uuid/gen_uuid.c index 42d7563d..efa4e3d3 100644 --- a/lib/uuid/gen_uuid.c +++ b/lib/uuid/gen_uuid.c @@ -176,8 +176,7 @@ static void get_random_bytes(void *buf, int nbytes) { int i, n = nbytes, fd = get_random_fd(); int lose_counter = 0; - unsigned char *cp = (unsigned char *) buf; - unsigned short tmp_seed[3]; + unsigned char *cp = buf; if (fd >= 0) { while (n > 0) { @@ -200,12 +199,16 @@ static void get_random_bytes(void *buf, int nbytes) for (cp = buf, i = 0; i < nbytes; i++) *cp++ ^= (rand() >> 7) & 0xFF; #ifdef DO_JRAND_MIX - memcpy(tmp_seed, jrand_seed, sizeof(tmp_seed)); - jrand_seed[2] = jrand_seed[2] ^ syscall(__NR_gettid); - for (cp = buf, i = 0; i < nbytes; i++) - *cp++ ^= (jrand48(tmp_seed) >> 7) & 0xFF; - memcpy(jrand_seed, tmp_seed, - sizeof(jrand_seed)-sizeof(unsigned short)); + { + unsigned short tmp_seed[3]; + + memcpy(tmp_seed, jrand_seed, sizeof(tmp_seed)); + jrand_seed[2] = jrand_seed[2] ^ syscall(__NR_gettid); + for (cp = buf, i = 0; i < nbytes; i++) + *cp++ ^= (jrand48(tmp_seed) >> 7) & 0xFF; + memcpy(jrand_seed, tmp_seed, + sizeof(jrand_seed) - sizeof(unsigned short)); + } #endif return; diff --git a/misc/badblocks.c b/misc/badblocks.c index 890d5107..f37cf269 100644 --- a/misc/badblocks.c +++ b/misc/badblocks.c @@ -68,19 +68,18 @@ extern int optind; const char * program_name = "badblocks"; const char * done_string = N_("done \n"); -static int v_flag = 0; /* verbose */ -static int w_flag = 0; /* do r/w test: 0=no, 1=yes, +static int v_flag; /* verbose */ +static int w_flag; /* do r/w test: 0=no, 1=yes, * 2=non-destructive */ -static int s_flag = 0; /* show progress of test */ -static int force = 0; /* force check of mounted device */ -static int t_flag = 0; /* number of test patterns */ -static int t_max = 0; /* allocated test patterns */ -static unsigned int *t_patts = NULL; /* test patterns */ -static int current_O_DIRECT = 0; /* Current status of O_DIRECT flag */ -static int use_buffered_io = 0; -static int exclusive_ok = 0; -static unsigned int max_bb = 0; /* Abort test if more than this number of bad blocks has been encountered */ -static unsigned int d_flag = 0; /* delay factor between reads */ +static int s_flag; /* show progress of test */ +static int force; /* force check of mounted device */ +static int t_flag; /* number of test patterns */ +static int t_max; /* allocated test patterns */ +static unsigned int *t_patts; /* test patterns */ +static int use_buffered_io; +static int exclusive_ok; +static unsigned int max_bb; /* Abort test if more than this number of bad blocks has been encountered */ +static unsigned int d_flag; /* delay factor between reads */ static struct timeval time_start; #define T_INC 32 @@ -286,6 +285,7 @@ static void set_o_direct(int dev, unsigned char *buffer, size_t size, ext2_loff_t offset) { #ifdef O_DIRECT + static int current_O_DIRECT; /* Current status of O_DIRECT flag */ int new_flag = O_DIRECT; int flag; diff --git a/misc/ismounted.c b/misc/ismounted.c index 4671af8e..6aa0e04d 100644 --- a/misc/ismounted.c +++ b/misc/ismounted.c @@ -40,6 +40,7 @@ #include "et/com_err.h" +#ifdef HAVE_SETMNTENT static char *skip_over_blank(char *cp) { while (*cp && isspace(*cp)) @@ -69,6 +70,7 @@ static char *parse_word(char **buf) *buf = next; return word; } +#endif /* * Helper function which checks a file in /etc/mtab format to see if a diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 0f9a299f..df9c1c14 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -146,6 +146,7 @@ static int int_log10(unsigned long long arg) return l; } +#ifdef __linux__ static int parse_version_number(const char *s) { int major, minor, rev; @@ -167,6 +168,7 @@ static int parse_version_number(const char *s) return 0; return ((((major * 256) + minor) * 256) + rev); } +#endif /* * Helper function for read_bb_file and test_disk