mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git
synced 2024-11-15 08:14:21 +08:00
btrfs-progs: Fix printf formats
Discovered with cppcheck. Fix signed/unsigned int mismatches, sizeof and long formats. Pull-request: #197 Signed-off-by: Rosen Penev <rosenp@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
e2da195a3c
commit
5d72055066
@ -52,7 +52,7 @@ int main(int argc, char **argv)
|
|||||||
length = atol(optarg);
|
length = atol(optarg);
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
sscanf(optarg, "%li", &checksum);
|
sscanf(optarg, "%lu", &checksum);
|
||||||
loop = 1;
|
loop = 1;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
|
@ -84,7 +84,7 @@ print_bg(FILE *html, char *name, u64 start, u64 len, u64 used, u64 flags,
|
|||||||
{
|
{
|
||||||
double frag = (double)areas / (len / 4096) * 2;
|
double frag = (double)areas / (len / 4096) * 2;
|
||||||
|
|
||||||
fprintf(html, "<p>%s chunk starts at %lld, size is %s, %.2f%% used, "
|
fprintf(html, "<p>%s chunk starts at %llu, size is %s, %.2f%% used, "
|
||||||
"%.2f%% fragmented</p>\n", chunk_type(flags), start,
|
"%.2f%% fragmented</p>\n", chunk_type(flags), start,
|
||||||
pretty_size(len), 100.0 * used / len, 100.0 * frag);
|
pretty_size(len), 100.0 * used / len, 100.0 * frag);
|
||||||
fprintf(html, "<img src=\"%s\" border=\"1\" />\n", name);
|
fprintf(html, "<img src=\"%s\" border=\"1\" />\n", name);
|
||||||
@ -264,8 +264,8 @@ list_fragments(int fd, u64 flags, char *dir)
|
|||||||
bgflags = btrfs_block_group_flags(bg);
|
bgflags = btrfs_block_group_flags(bg);
|
||||||
bgused = btrfs_block_group_used(bg);
|
bgused = btrfs_block_group_used(bg);
|
||||||
|
|
||||||
printf("found block group %lld len %lld "
|
printf("found block group %llu len %llu "
|
||||||
"flags %lld\n",
|
"flags %llu\n",
|
||||||
btrfs_search_header_objectid(sh),
|
btrfs_search_header_objectid(sh),
|
||||||
btrfs_search_header_offset(sh),
|
btrfs_search_header_offset(sh),
|
||||||
bgflags);
|
bgflags);
|
||||||
@ -322,7 +322,7 @@ list_fragments(int fd, u64 flags, char *dir)
|
|||||||
else
|
else
|
||||||
c = black;
|
c = black;
|
||||||
if (btrfs_search_header_objectid(sh) > bgend) {
|
if (btrfs_search_header_objectid(sh) > bgend) {
|
||||||
printf("WARN: extent %lld is without "
|
printf("WARN: extent %llu is without "
|
||||||
"block group\n",
|
"block group\n",
|
||||||
btrfs_search_header_objectid(sh));
|
btrfs_search_header_objectid(sh));
|
||||||
goto skip;
|
goto skip;
|
||||||
|
@ -5280,7 +5280,7 @@ static int process_extent_item(struct btrfs_root *root,
|
|||||||
}
|
}
|
||||||
if (item_size < sizeof(*ei)) {
|
if (item_size < sizeof(*ei)) {
|
||||||
error(
|
error(
|
||||||
"corrupted or unsupported extent item found, item size=%u expect minimal size=%lu",
|
"corrupted or unsupported extent item found, item size=%u expect minimal size=%zu",
|
||||||
item_size, sizeof(*ei));
|
item_size, sizeof(*ei));
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@ -389,7 +389,7 @@ int pretty_size_snprintf(u64 size, char *str, size_t str_size, unsigned unit_mod
|
|||||||
|
|
||||||
/* Unknown mode */
|
/* Unknown mode */
|
||||||
if (!base) {
|
if (!base) {
|
||||||
fprintf(stderr, "INTERNAL ERROR: unknown unit base, mode %d\n",
|
fprintf(stderr, "INTERNAL ERROR: unknown unit base, mode %u\n",
|
||||||
unit_mode);
|
unit_mode);
|
||||||
assert(0);
|
assert(0);
|
||||||
return -1;
|
return -1;
|
||||||
|
4
ctree.c
4
ctree.c
@ -2569,7 +2569,7 @@ int btrfs_extend_item(struct btrfs_root *root, struct btrfs_path *path,
|
|||||||
BUG_ON(slot < 0);
|
BUG_ON(slot < 0);
|
||||||
if (slot >= nritems) {
|
if (slot >= nritems) {
|
||||||
btrfs_print_leaf(leaf);
|
btrfs_print_leaf(leaf);
|
||||||
printk("slot %d too large, nritems %d\n", slot, nritems);
|
printk("slot %d too large, nritems %u\n", slot, nritems);
|
||||||
BUG_ON(1);
|
BUG_ON(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2660,7 +2660,7 @@ int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
|
|||||||
|
|
||||||
if (old_data < data_end) {
|
if (old_data < data_end) {
|
||||||
btrfs_print_leaf(leaf);
|
btrfs_print_leaf(leaf);
|
||||||
printk("slot %d old_data %d data_end %d\n",
|
printk("slot %d old_data %u data_end %u\n",
|
||||||
slot, old_data, data_end);
|
slot, old_data, data_end);
|
||||||
BUG_ON(1);
|
BUG_ON(1);
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ static void print_tree_block_error(struct btrfs_fs_info *fs_info,
|
|||||||
eb->start, btrfs_header_bytenr(eb));
|
eb->start, btrfs_header_bytenr(eb));
|
||||||
break;
|
break;
|
||||||
case BTRFS_BAD_LEVEL:
|
case BTRFS_BAD_LEVEL:
|
||||||
fprintf(stderr, "bad level, %u > %u\n",
|
fprintf(stderr, "bad level, %u > %d\n",
|
||||||
btrfs_header_level(eb), BTRFS_MAX_LEVEL);
|
btrfs_header_level(eb), BTRFS_MAX_LEVEL);
|
||||||
break;
|
break;
|
||||||
case BTRFS_BAD_NRITEMS:
|
case BTRFS_BAD_NRITEMS:
|
||||||
@ -826,7 +826,7 @@ int btrfs_check_fs_compatibility(struct btrfs_super_block *sb,
|
|||||||
~BTRFS_FEATURE_INCOMPAT_SUPP;
|
~BTRFS_FEATURE_INCOMPAT_SUPP;
|
||||||
if (features) {
|
if (features) {
|
||||||
printk("couldn't open because of unsupported "
|
printk("couldn't open because of unsupported "
|
||||||
"option features (%Lx).\n",
|
"option features (%llx).\n",
|
||||||
(unsigned long long)features);
|
(unsigned long long)features);
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
@ -848,7 +848,7 @@ int btrfs_check_fs_compatibility(struct btrfs_super_block *sb,
|
|||||||
}
|
}
|
||||||
if (features & ~BTRFS_FEATURE_COMPAT_RO_SUPP) {
|
if (features & ~BTRFS_FEATURE_COMPAT_RO_SUPP) {
|
||||||
printk("couldn't open RDWR because of unsupported "
|
printk("couldn't open RDWR because of unsupported "
|
||||||
"option features (%Lx).\n",
|
"option features (0x%llx)\n",
|
||||||
(unsigned long long)features);
|
(unsigned long long)features);
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
@ -1422,7 +1422,7 @@ again:
|
|||||||
item_size = btrfs_item_size_nr(l, path->slots[0]);
|
item_size = btrfs_item_size_nr(l, path->slots[0]);
|
||||||
if (item_size < sizeof(*item)) {
|
if (item_size < sizeof(*item)) {
|
||||||
error(
|
error(
|
||||||
"unsupported or corrupted extent item, item size=%u expect minimal size=%lu",
|
"unsupported or corrupted extent item, item size=%u expect minimal size=%zu",
|
||||||
item_size, sizeof(*item));
|
item_size, sizeof(*item));
|
||||||
ret = -EUCLEAN;
|
ret = -EUCLEAN;
|
||||||
goto out;
|
goto out;
|
||||||
@ -2027,7 +2027,7 @@ static int __free_extent(struct btrfs_trans_handle *trans,
|
|||||||
(unsigned long long)root_objectid,
|
(unsigned long long)root_objectid,
|
||||||
(unsigned long long)owner_objectid,
|
(unsigned long long)owner_objectid,
|
||||||
(unsigned long long)owner_offset);
|
(unsigned long long)owner_offset);
|
||||||
printf("path->slots[0]: %u path->nodes[0]:\n", path->slots[0]);
|
printf("path->slots[0]: %d path->nodes[0]:\n", path->slots[0]);
|
||||||
btrfs_print_leaf(path->nodes[0]);
|
btrfs_print_leaf(path->nodes[0]);
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -2037,7 +2037,7 @@ static int __free_extent(struct btrfs_trans_handle *trans,
|
|||||||
item_size = btrfs_item_size_nr(leaf, extent_slot);
|
item_size = btrfs_item_size_nr(leaf, extent_slot);
|
||||||
if (item_size < sizeof(*ei)) {
|
if (item_size < sizeof(*ei)) {
|
||||||
error(
|
error(
|
||||||
"unsupported or corrupted extent item, item size=%u expect minimal size=%lu",
|
"unsupported or corrupted extent item, item size=%u expect minimal size=%zu",
|
||||||
item_size, sizeof(*ei));
|
item_size, sizeof(*ei));
|
||||||
ret = -EUCLEAN;
|
ret = -EUCLEAN;
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -3766,7 +3766,7 @@ static int run_delayed_tree_ref(struct btrfs_trans_handle *trans,
|
|||||||
ref_root = ref->root;
|
ref_root = ref->root;
|
||||||
|
|
||||||
if (node->ref_mod != 1) {
|
if (node->ref_mod != 1) {
|
||||||
printf("btree block(%llu) has %d references rather than 1: action %d ref_root %llu parent %llu",
|
printf("btree block(%llu) has %d references rather than 1: action %u ref_root %llu parent %llu",
|
||||||
node->bytenr, node->ref_mod, node->action, ref_root,
|
node->bytenr, node->ref_mod, node->action, ref_root,
|
||||||
parent);
|
parent);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
@ -102,7 +102,7 @@ static inline void warning_trace(const char *assertion, const char *filename,
|
|||||||
if (!val)
|
if (!val)
|
||||||
return;
|
return;
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%s:%d: %s: Warning: assertion `%s` failed, value %ld\n",
|
"%s:%u: %s: Warning: assertion `%s` failed, value %ld\n",
|
||||||
filename, line, func, assertion, val);
|
filename, line, func, assertion, val);
|
||||||
#ifndef BTRFS_DISABLE_BACKTRACE
|
#ifndef BTRFS_DISABLE_BACKTRACE
|
||||||
print_trace();
|
print_trace();
|
||||||
@ -115,7 +115,7 @@ static inline void bugon_trace(const char *assertion, const char *filename,
|
|||||||
if (!val)
|
if (!val)
|
||||||
return;
|
return;
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%s:%d: %s: BUG_ON `%s` triggered, value %ld\n",
|
"%s:%u: %s: BUG_ON `%s` triggered, value %ld\n",
|
||||||
filename, line, func, assertion, val);
|
filename, line, func, assertion, val);
|
||||||
#ifndef BTRFS_DISABLE_BACKTRACE
|
#ifndef BTRFS_DISABLE_BACKTRACE
|
||||||
print_trace();
|
print_trace();
|
||||||
|
16
print-tree.c
16
print-tree.c
@ -472,7 +472,7 @@ void print_extent_item(struct extent_buffer *eb, int slot, int metadata)
|
|||||||
printf("\t\textent data backref root ");
|
printf("\t\textent data backref root ");
|
||||||
print_objectid(stdout,
|
print_objectid(stdout,
|
||||||
(unsigned long long)btrfs_extent_data_ref_root(eb, dref), 0);
|
(unsigned long long)btrfs_extent_data_ref_root(eb, dref), 0);
|
||||||
printf(" objectid %llu offset %lld count %u\n",
|
printf(" objectid %llu offset %llu count %u\n",
|
||||||
(unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
|
(unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
|
||||||
btrfs_extent_data_ref_offset(eb, dref),
|
btrfs_extent_data_ref_offset(eb, dref),
|
||||||
btrfs_extent_data_ref_count(eb, dref));
|
btrfs_extent_data_ref_count(eb, dref));
|
||||||
@ -830,7 +830,7 @@ void btrfs_print_key(struct btrfs_disk_key *disk_key)
|
|||||||
if (objectid == BTRFS_TREE_RELOC_OBJECTID)
|
if (objectid == BTRFS_TREE_RELOC_OBJECTID)
|
||||||
print_objectid(stdout, offset, type);
|
print_objectid(stdout, offset, type);
|
||||||
else
|
else
|
||||||
printf("%lld", offset);
|
printf("%llu", offset);
|
||||||
printf(")");
|
printf(")");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -977,7 +977,7 @@ static void print_dev_stats(struct extent_buffer *eb,
|
|||||||
if (known < size) {
|
if (known < size) {
|
||||||
printf("\t\tunknown stats item bytes %u", size - known);
|
printf("\t\tunknown stats item bytes %u", size - known);
|
||||||
for (i = BTRFS_DEV_STAT_VALUES_MAX; i * sizeof(__le64) < size; i++) {
|
for (i = BTRFS_DEV_STAT_VALUES_MAX; i * sizeof(__le64) < size; i++) {
|
||||||
printf("\t\tunknown item %u offset %zu value %llu\n",
|
printf("\t\tunknown item %d offset %zu value %llu\n",
|
||||||
i, i * sizeof(__le64),
|
i, i * sizeof(__le64),
|
||||||
btrfs_dev_stats_value(eb, stats, i));
|
btrfs_dev_stats_value(eb, stats, i));
|
||||||
}
|
}
|
||||||
@ -1063,7 +1063,7 @@ static void print_qgroup_status(struct extent_buffer *eb, int slot)
|
|||||||
memset(flags_str, 0, sizeof(flags_str));
|
memset(flags_str, 0, sizeof(flags_str));
|
||||||
qgroup_flags_to_str(btrfs_qgroup_status_flags(eb, qg_status),
|
qgroup_flags_to_str(btrfs_qgroup_status_flags(eb, qg_status),
|
||||||
flags_str);
|
flags_str);
|
||||||
printf("\t\tversion %llu generation %llu flags %s scan %lld\n",
|
printf("\t\tversion %llu generation %llu flags %s scan %llu\n",
|
||||||
(unsigned long long)btrfs_qgroup_status_version(eb, qg_status),
|
(unsigned long long)btrfs_qgroup_status_version(eb, qg_status),
|
||||||
(unsigned long long)btrfs_qgroup_status_generation(eb, qg_status),
|
(unsigned long long)btrfs_qgroup_status_generation(eb, qg_status),
|
||||||
flags_str,
|
flags_str,
|
||||||
@ -1185,7 +1185,7 @@ void btrfs_print_leaf(struct extent_buffer *eb)
|
|||||||
header_flags_to_str(flags, flags_str);
|
header_flags_to_str(flags, flags_str);
|
||||||
nr = btrfs_header_nritems(eb);
|
nr = btrfs_header_nritems(eb);
|
||||||
|
|
||||||
printf("leaf %llu items %d free space %d generation %llu owner ",
|
printf("leaf %llu items %u free space %d generation %llu owner ",
|
||||||
(unsigned long long)btrfs_header_bytenr(eb), nr,
|
(unsigned long long)btrfs_header_bytenr(eb), nr,
|
||||||
btrfs_leaf_free_space(eb),
|
btrfs_leaf_free_space(eb),
|
||||||
(unsigned long long)btrfs_header_generation(eb));
|
(unsigned long long)btrfs_header_generation(eb));
|
||||||
@ -1230,9 +1230,9 @@ void btrfs_print_leaf(struct extent_buffer *eb)
|
|||||||
type = btrfs_disk_key_type(&disk_key);
|
type = btrfs_disk_key_type(&disk_key);
|
||||||
offset = btrfs_disk_key_offset(&disk_key);
|
offset = btrfs_disk_key_offset(&disk_key);
|
||||||
|
|
||||||
printf("\titem %d ", i);
|
printf("\titem %u ", i);
|
||||||
btrfs_print_key(&disk_key);
|
btrfs_print_key(&disk_key);
|
||||||
printf(" itemoff %d itemsize %d\n",
|
printf(" itemoff %u itemsize %u\n",
|
||||||
btrfs_item_offset(eb, item),
|
btrfs_item_offset(eb, item),
|
||||||
btrfs_item_size(eb, item));
|
btrfs_item_size(eb, item));
|
||||||
|
|
||||||
@ -1489,7 +1489,7 @@ void btrfs_print_tree(struct extent_buffer *eb, bool follow, int traverse)
|
|||||||
warning(
|
warning(
|
||||||
"node nr_items corrupted, has %u limit %u, continue anyway",
|
"node nr_items corrupted, has %u limit %u, continue anyway",
|
||||||
nr, BTRFS_NODEPTRS_PER_EXTENT_BUFFER(eb));
|
nr, BTRFS_NODEPTRS_PER_EXTENT_BUFFER(eb));
|
||||||
printf("node %llu level %d items %d free %u generation %llu owner ",
|
printf("node %llu level %d items %u free %u generation %llu owner ",
|
||||||
(unsigned long long)eb->start,
|
(unsigned long long)eb->start,
|
||||||
btrfs_header_level(eb), nr,
|
btrfs_header_level(eb), nr,
|
||||||
(u32)BTRFS_NODEPTRS_PER_EXTENT_BUFFER(eb) - nr,
|
(u32)BTRFS_NODEPTRS_PER_EXTENT_BUFFER(eb) - nr,
|
||||||
|
@ -107,7 +107,7 @@ int main(int ac, char **av) {
|
|||||||
fprintf(stderr, "Open ctree failed\n");
|
fprintf(stderr, "Open ctree failed\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
printf("node %p level %d total ptrs %d free spc %lu\n", root->node,
|
printf("node %p level %d total ptrs %u free spc %lu\n", root->node,
|
||||||
btrfs_header_level(root->node),
|
btrfs_header_level(root->node),
|
||||||
btrfs_header_nritems(root->node),
|
btrfs_header_nritems(root->node),
|
||||||
(unsigned long)BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) -
|
(unsigned long)BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) -
|
||||||
|
@ -398,7 +398,7 @@ int main(int ac, char **av)
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
if (i && i % 5000 == 0) {
|
if (i && i % 5000 == 0) {
|
||||||
printf("open & close, root level %d nritems %d\n",
|
printf("open & close, root level %d nritems %u\n",
|
||||||
btrfs_header_level(&root->node->node.header),
|
btrfs_header_level(&root->node->node.header),
|
||||||
btrfs_header_nritems(&root->node->node.header));
|
btrfs_header_nritems(&root->node->node.header));
|
||||||
close_ctree(root, &super);
|
close_ctree(root, &super);
|
||||||
|
@ -272,7 +272,7 @@ sum_file_data_permissive(int fd, sum_t *dst)
|
|||||||
for (old = i; buf[i] != 0 && i < ret; ++i)
|
for (old = i; buf[i] != 0 && i < ret; ++i)
|
||||||
;
|
;
|
||||||
if (verbose >= 2)
|
if (verbose >= 2)
|
||||||
fprintf(stderr, "adding %u non-zeros to sum\n",
|
fprintf(stderr, "adding %d non-zeros to sum\n",
|
||||||
i - (int)old);
|
i - (int)old);
|
||||||
sum_add(dst, buf + old, i - old);
|
sum_add(dst, buf + old, i - old);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user