Skip to content

Commit

Permalink
Fix clang warnings on architectures with a 64-bit long
Browse files Browse the repository at this point in the history
On most systems where we compile e2fsprogs, the u64 type is an
unsigned long long.  However, there are platforms (such as the
PowerPC) where a long 64-bits and so u64 is typedef'ed to be unsigned
long instead of a unsigned long long.  Fix this by using explicit
casts in printf statements.  For scanf calls, we need to receive the
value into a unsigned long long, and then assign it to a u64, after
doing range checks.

Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
tytso committed Feb 11, 2021
1 parent fb874e6 commit 33b9a60
Show file tree
Hide file tree
Showing 44 changed files with 399 additions and 266 deletions.
74 changes: 41 additions & 33 deletions debugfs/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,12 @@ void do_show_super_stats(int argc, char *argv[],
"inode table at %llu\n"
" %u free %s%s, "
"%u free %s, "
"%u used %s%s",
i, ext2fs_block_bitmap_loc(current_fs, i),
ext2fs_inode_bitmap_loc(current_fs, i),
ext2fs_inode_table_loc(current_fs, i),
ext2fs_bg_free_blocks_count(current_fs, i), units,
"%u used %s%s", i,
(unsigned long long) ext2fs_block_bitmap_loc(current_fs, i),
(unsigned long long) ext2fs_inode_bitmap_loc(current_fs, i),
(unsigned long long) ext2fs_inode_table_loc(current_fs, i),
ext2fs_bg_free_blocks_count(current_fs, i),
units,
ext2fs_bg_free_blocks_count(current_fs, i) != 1 ?
"s" : "",
ext2fs_bg_free_inodes_count(current_fs, i),
Expand Down Expand Up @@ -567,11 +568,13 @@ static void finish_range(struct list_blocks_struct *lb)
fprintf(lb->f, ", ");
if (lb->first_block == lb->last_block)
fprintf(lb->f, "(%lld):%llu",
(long long)lb->first_bcnt, lb->first_block);
(long long)lb->first_bcnt,
(unsigned long long) lb->first_block);
else
fprintf(lb->f, "(%lld-%lld):%llu-%llu",
(long long)lb->first_bcnt, (long long)lb->last_bcnt,
lb->first_block, lb->last_block);
(unsigned long long) lb->first_block,
(unsigned long long) lb->last_block);
lb->first_block = 0;
}

Expand Down Expand Up @@ -721,18 +724,18 @@ static void dump_extents(FILE *f, const char *prefix, ext2_ino_t ino,
info.curr_level, info.max_depth,
info.curr_entry, info.num_entries,
logical_width,
extent.e_lblk,
(unsigned long long) extent.e_lblk,
logical_width,
extent.e_lblk + (extent.e_len - 1),
(unsigned long long) extent.e_lblk + (extent.e_len - 1),
physical_width,
extent.e_pblk,
(unsigned long long) extent.e_pblk,
physical_width+3, "", extent.e_len);
continue;
}

fprintf(f, "%s(ETB%d):%llu",
printed ? ", " : "", info.curr_level,
extent.e_pblk);
(unsigned long long) extent.e_pblk);
printed = 1;
continue;
}
Expand All @@ -743,13 +746,13 @@ static void dump_extents(FILE *f, const char *prefix, ext2_ino_t ino,
info.curr_level, info.max_depth,
info.curr_entry, info.num_entries,
logical_width,
extent.e_lblk,
(unsigned long long) extent.e_lblk,
logical_width,
extent.e_lblk + (extent.e_len - 1),
(unsigned long long) extent.e_lblk + (extent.e_len - 1),
physical_width,
extent.e_pblk,
(unsigned long long) extent.e_pblk,
physical_width,
extent.e_pblk + (extent.e_len - 1),
(unsigned long long) extent.e_pblk + (extent.e_len - 1),
extent.e_len,
extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT ?
"Uninit" : "");
Expand All @@ -762,20 +765,20 @@ static void dump_extents(FILE *f, const char *prefix, ext2_ino_t ino,
fprintf(f,
"%s(%lld%s):%lld",
printed ? ", " : "",
extent.e_lblk,
(unsigned long long) extent.e_lblk,
extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT ?
"[u]" : "",
extent.e_pblk);
(unsigned long long) extent.e_pblk);
else
fprintf(f,
"%s(%lld-%lld%s):%lld-%lld",
printed ? ", " : "",
extent.e_lblk,
extent.e_lblk + (extent.e_len - 1),
(unsigned long long) extent.e_lblk,
(unsigned long long) extent.e_lblk + (extent.e_len - 1),
extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT ?
"[u]" : "",
extent.e_pblk,
extent.e_pblk + (extent.e_len - 1));
(unsigned long long) extent.e_pblk,
(unsigned long long) extent.e_pblk + (extent.e_len - 1));
printed = 1;
}
if (printed)
Expand Down Expand Up @@ -861,7 +864,7 @@ void internal_dump_inode(FILE *out, const char *prefix,
fprintf(out, " Project: %5d", large_inode->i_projid);
fputs(" Size: ", out);
if (LINUX_S_ISREG(inode->i_mode) || LINUX_S_ISDIR(inode->i_mode))
fprintf(out, "%llu\n", EXT2_I_SIZE(inode));
fprintf(out, "%llu\n", (unsigned long long) EXT2_I_SIZE(inode));
else
fprintf(out, "%u\n", inode->i_size);
if (os == EXT2_OS_HURD)
Expand Down Expand Up @@ -1085,7 +1088,7 @@ static int print_blocks_proc(ext2_filsys fs EXT2FS_ATTR((unused)),
int ref_offset EXT2FS_ATTR((unused)),
void *private EXT2FS_ATTR((unused)))
{
printf("%llu ", *blocknr);
printf("%llu ", (unsigned long long) *blocknr);
return 0;
}

Expand Down Expand Up @@ -1232,7 +1235,7 @@ void do_freeb(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
while (count-- > 0) {
if (!ext2fs_test_block_bitmap2(current_fs->block_map,block))
com_err(argv[0], 0, "Warning: block %llu already clear",
block);
(unsigned long long) block);
ext2fs_unmark_block_bitmap2(current_fs->block_map,block);
block++;
}
Expand All @@ -1252,7 +1255,7 @@ void do_setb(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
while (count-- > 0) {
if (ext2fs_test_block_bitmap2(current_fs->block_map,block))
com_err(argv[0], 0, "Warning: block %llu already set",
block);
(unsigned long long) block);
ext2fs_mark_block_bitmap2(current_fs->block_map,block);
block++;
}
Expand All @@ -1270,9 +1273,11 @@ void do_testb(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
return;
while (count-- > 0) {
if (ext2fs_test_block_bitmap2(current_fs->block_map,block))
printf("Block %llu marked in use\n", block);
printf("Block %llu marked in use\n",
(unsigned long long) block);
else
printf("Block %llu not in use\n", block);
printf("Block %llu not in use\n",
(unsigned long long) block);
block++;
}
}
Expand Down Expand Up @@ -1708,7 +1713,7 @@ void do_find_free_block(int argc, char *argv[],
com_err("ext2fs_new_block", retval, 0);
return;
} else
printf("%llu ", free_blk);
printf("%llu ", (unsigned long long) free_blk);
}
printf("\n");
}
Expand Down Expand Up @@ -2110,10 +2115,11 @@ void do_bmap(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
&ret_flags, &pblk);
if (errcode) {
com_err(argv[0], errcode,
"while mapping logical block %llu\n", blk);
"while mapping logical block %llu\n",
(unsigned long long) blk);
return;
}
printf("%llu", pblk);
printf("%llu", (unsigned long long) pblk);
if (ret_flags & BMAP_RET_UNINIT)
fputs(" (uninit)", stdout);
fputc('\n', stdout);
Expand Down Expand Up @@ -2447,17 +2453,19 @@ void do_dump_mmp(int argc EXT2FS_ATTR((unused)), char *argv[],
retval = ext2fs_mmp_read(current_fs, mmp_block, current_fs->mmp_buf);
if (retval) {
com_err(argv[0], retval, "reading MMP block %llu.\n",
mmp_block);
(unsigned long long) mmp_block);
return;
}

t = mmp_s->mmp_time;
fprintf(stdout, "block_number: %llu\n", current_fs->super->s_mmp_block);
fprintf(stdout, "block_number: %llu\n",
(unsigned long long) current_fs->super->s_mmp_block);
fprintf(stdout, "update_interval: %d\n",
current_fs->super->s_mmp_update_interval);
fprintf(stdout, "check_interval: %d\n", mmp_s->mmp_check_interval);
fprintf(stdout, "sequence: %08x\n", mmp_s->mmp_seq);
fprintf(stdout, "time: %lld -- %s", mmp_s->mmp_time, ctime(&t));
fprintf(stdout, "time: %llu -- %s",
(unsigned long long) mmp_s->mmp_time, ctime(&t));
fprintf(stdout, "node_name: %.*s\n",
EXT2_LEN_STR(mmp_s->mmp_nodename));
fprintf(stdout, "device_name: %.*s\n",
Expand Down
10 changes: 6 additions & 4 deletions debugfs/extent_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ static void dbg_print_extent(char *desc, struct ext2fs_extent *extent)
if (desc)
printf("%s: ", desc);
printf("extent: lblk %llu--%llu, len %u, pblk %llu, flags: ",
extent->e_lblk, extent->e_lblk + extent->e_len - 1,
extent->e_len, extent->e_pblk);
(unsigned long long) extent->e_lblk,
(unsigned long long) extent->e_lblk + extent->e_len - 1,
extent->e_len, (unsigned long long) extent->e_pblk);
if (extent->e_flags & EXT2_EXTENT_FLAGS_LEAF)
fputs("LEAF ", stdout);
if (extent->e_flags & EXT2_EXTENT_FLAGS_UNINIT)
Expand Down Expand Up @@ -527,8 +528,9 @@ void do_info(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
printf("Current handle location: %d/%d (max: %d, bytes %d), level %d/%d\n",
info.curr_entry, info.num_entries, info.max_entries,
info.bytes_avail, info.curr_level, info.max_depth);
printf("\tmax lblk: %llu, max pblk: %llu\n", info.max_lblk,
info.max_pblk);
printf("\tmax lblk: %llu, max pblk: %llu\n",
(unsigned long long) info.max_lblk,
(unsigned long long) info.max_pblk);
printf("\tmax_len: %u, max_uninit_len: %u\n", info.max_len,
info.max_uninit_len);
}
Expand Down
12 changes: 8 additions & 4 deletions debugfs/filefrag.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ static void report_filefrag(struct filefrag_struct *fs)
fprintf(fs->f, "%4d %*lu %*llu %*llu %*lu\n", fs->ext,
fs->logical_width,
(unsigned long) fs->logical_start,
fs->physical_width, fs->physical_start,
fs->physical_width, fs->expected,
fs->physical_width,
(unsigned long long) fs->physical_start,
fs->physical_width,
(unsigned long long) fs->expected,
fs->logical_width, (unsigned long) fs->num);
else
fprintf(fs->f, "%4d %*lu %*llu %*s %*lu\n", fs->ext,
fs->logical_width,
(unsigned long) fs->logical_start,
fs->physical_width, fs->physical_start,
fs->physical_width,
(unsigned long long) fs->physical_start,
fs->physical_width, "",
fs->logical_width, (unsigned long) fs->num);
}
Expand Down Expand Up @@ -150,7 +153,8 @@ static void filefrag(ext2_ino_t ino, struct ext2_inode *inode,
num_blocks /= current_fs->blocksize / 512;

fprintf(fs->f, "\n%s has %llu block(s), i_size is %llu\n",
fs->name, num_blocks, EXT2_I_SIZE(inode));
fs->name, (unsigned long long) num_blocks,
(unsigned long long) EXT2_I_SIZE(inode));
}
print_header(fs);
if (ext2fs_inode_has_valid_blocks2(current_fs, inode)) {
Expand Down
18 changes: 11 additions & 7 deletions debugfs/htree.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,18 @@ static void htree_dump_leaf_node(ext2_filsys fs, ext2_ino_t ino,
errcode = ext2fs_bmap2(fs, ino, inode, buf, 0, blk, 0, &pblk);
if (errcode) {
com_err("htree_dump_leaf_node", errcode,
"while mapping logical block %llu\n", blk);
"while mapping logical block %llu\n",
(unsigned long long) blk);
return;
}

fprintf(pager, "Reading directory block %llu, phys %llu\n", blk, pblk);
fprintf(pager, "Reading directory block %llu, phys %llu\n",
(unsigned long long) blk, (unsigned long long) pblk);
errcode = ext2fs_read_dir_block4(current_fs, pblk, buf, 0, ino);
if (errcode) {
com_err("htree_dump_leaf_node", errcode,
"while reading block %llu (%llu)\n",
blk, pblk);
(unsigned long long) blk, (unsigned long long) pblk);
return;
}
hash_alg = rootnode->hash_version;
Expand All @@ -85,7 +87,7 @@ static void htree_dump_leaf_node(ext2_filsys fs, ext2_ino_t ino,
((rec_len % 4) != 0) ||
((unsigned) thislen + 8 > rec_len)) {
fprintf(pager, "Corrupted directory block (%llu)!\n",
blk);
(unsigned long long) blk);
break;
}
strncpy(name, dirent->name, thislen);
Expand Down Expand Up @@ -213,14 +215,16 @@ static void htree_dump_int_block(ext2_filsys fs, ext2_ino_t ino,
errcode = ext2fs_bmap2(fs, ino, inode, buf, 0, blk, 0, &pblk);
if (errcode) {
com_err("htree_dump_int_block", errcode,
"while mapping logical block %llu\n", blk);
"while mapping logical block %llu\n",
(unsigned long long) blk);
goto errout;
}

errcode = io_channel_read_blk64(current_fs->io, pblk, 1, buf);
if (errcode) {
com_err("htree_dump_int_block", errcode,
"while reading block %llu\n", blk);
"while reading block %llu\n",
(unsigned long long) blk);
goto errout;
}

Expand Down Expand Up @@ -473,7 +477,7 @@ static int search_dir_block(ext2_filsys fs, blk64_t *blocknr,
p->len) == 0) {
printf("Entry found at logical block %lld, "
"phys %llu, offset %u\n", (long long)blockcnt,
*blocknr, offset);
(unsigned long long) *blocknr, offset);
printf("offset %u\n", offset);
return BLOCK_ABORT;
}
Expand Down
6 changes: 4 additions & 2 deletions debugfs/icheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ void do_icheck(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
printf("Block\tInode number\n");
for (i=0, binfo = bw.barray; i < bw.num_blocks; i++, binfo++) {
if (binfo->ino == 0) {
printf("%llu\t<block not found>\n", binfo->blk);
printf("%llu\t<block not found>\n",
(unsigned long long) binfo->blk);
continue;
}
printf("%llu\t%u\n", binfo->blk, binfo->ino);
printf("%llu\t%u\n", (unsigned long long) binfo->blk,
binfo->ino);
}

error_out:
Expand Down
10 changes: 6 additions & 4 deletions debugfs/logdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ void do_logdump(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
* sizeof(struct ext2_inode));
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);
(unsigned long long) inode_block_to_dump,
inode_offset_to_dump);
}

if (optind == argc) {
Expand Down Expand Up @@ -541,7 +542,7 @@ static void dump_fc_block(FILE *out_file, char *buf, int blocksize,
le32_to_cpu(add_range->fc_ino),
le32_to_cpu(ex->ee_block),
le32_to_cpu(ex->ee_start) +
(((__u64) le16_to_cpu(ex->ee_start_hi)) << 32),
(((unsigned long long) le16_to_cpu(ex->ee_start_hi)) << 32),
le16_to_cpu(ex->ee_len) > EXT_INIT_MAX_LEN ?
le16_to_cpu(ex->ee_len) - EXT_INIT_MAX_LEN :
le16_to_cpu(ex->ee_len));
Expand Down Expand Up @@ -699,7 +700,8 @@ static void dump_revoke_block(FILE *out_file, char *buf,
rblock = ext2fs_be64_to_cpu(*entry);
}
if (dump_all || rblock == block_to_dump) {
fprintf(out_file, " Revoke FS block %llu", rblock);
fprintf(out_file, " Revoke FS block %llu",
(unsigned long long) rblock);
if (dump_all)
fprintf(out_file, "\n");
else
Expand Down Expand Up @@ -783,7 +785,7 @@ static void dump_metadata_block(FILE *out_file, struct journal_source *source,

fprintf(out_file, " (block bitmap for block %llu: "
"block is %s)\n",
block_to_dump,
(unsigned long long) block_to_dump,
ext2fs_test_bit(offset, buf) ? "SET" : "CLEAR");
}

Expand Down
6 changes: 4 additions & 2 deletions debugfs/ls.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ static int list_dir_proc(ext2_ino_t dir EXT2FS_ATTR((unused)),
if (LINUX_S_ISDIR(inode.i_mode))
fprintf(ls->f, "/");
else
fprintf(ls->f, "%lld/", EXT2_I_SIZE(&inode));
fprintf(ls->f, "%llu/",
(unsigned long long) EXT2_I_SIZE(&inode));
fprintf(ls->f, "\n");
} else if (options & LONG_OPT) {
if (ino) {
Expand All @@ -143,7 +144,8 @@ static int list_dir_proc(ext2_ino_t dir EXT2FS_ATTR((unused)),
fprintf(ls->f, "(%d) %5d %5d ",
ext2fs_dirent_file_type(dirent),
inode_uid(inode), inode_gid(inode));
fprintf(ls->f, "%5llu", EXT2_I_SIZE(&inode));
fprintf(ls->f, "%5llu",
(unsigned long long) EXT2_I_SIZE(&inode));
fprintf(ls->f, " %s ", datestr);
print_filename(ls->f, dirent, options);
fputc('\n', ls->f);
Expand Down
6 changes: 4 additions & 2 deletions debugfs/lsdel.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,10 @@ void do_lsdel(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
for (i = 0; i < num_delarray; i++) {
fprintf(out, "%6u %6d %6o %6llu %6lld/%6lld %s",
delarray[i].ino,
delarray[i].uid, delarray[i].mode, delarray[i].size,
delarray[i].free_blocks, delarray[i].num_blocks,
delarray[i].uid, delarray[i].mode,
(unsigned long long) delarray[i].size,
(long long) delarray[i].free_blocks,
(long long) delarray[i].num_blocks,
time_to_string(delarray[i].dtime));
}
fprintf(out, "%d deleted inodes found.\n", num_delarray);
Expand Down
Loading

0 comments on commit 33b9a60

Please sign in to comment.