btrfs-progs: printf format fixes for 32bit x86
PATCH 1/1 btrfs-progs: printf format fixes for 32bit x86
When compiling btrfs-progs on 32bit x86 using GCC 11.1.0, there are several warnings:
In file included from ./common/utils.h:30,
from check/main.c:36:
check/main.c: In function 'run_next_block':
./common/messages.h:42:31: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'u32' {aka 'unsigned int'} [-Wformat=]
42 | __btrfs_error((fmt), ##__VA_ARGS__); \
| ^~~~~
check/main.c:6496:33: note: in expansion of macro 'error'
6496 | error(
| ^~~~~ In file included from ./common/utils.h:30,
from kernel-shared/volumes.c:32:
kernel-shared/volumes.c: In function 'btrfs_check_chunk_valid':
./common/messages.h:42:31: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'u32' {aka 'unsigned int'} [-Wformat=]
42 | __btrfs_error((fmt), ##__VA_ARGS__); \
| ^~~~~
kernel-shared/volumes.c:2052:17: note: in expansion of macro 'error'
2052 | error("invalid chunk item size, have %u expect [%zu, %lu)",
| ^~~~~ image/main.c: In function 'search_for_chunk_blocks':
./common/messages.h:42:31: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
42 | __btrfs_error((fmt), ##__VA_ARGS__); \
| ^~~~~
image/main.c:2122:33: note: in expansion of macro 'error'
2122 | error(
| ^~~~~There are two types of problems:
- __BTRFS_LEAF_DATA_SIZE()
This macro has no type definition, making it behaves differently on different arches.
Fix this by following kernel to use inline function to make its return value fixed to u32.
- size_t related output
For x86_64 %lu is OK but not for x86.
Fix this by using %zu.
--- check/main.c | 2 +- image/main.c | 2 +- kernel-shared/ctree.h | 6 +++++- kernel-shared/volumes.c | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-)
check/main.c +1 -1
@@ -6494,7 +6494,7 @@ static int run_next_block(struct btrfs_root *root,if (btrfs_item_size_nr (buf, i) < inline_offset) { ret = -EUCLEAN ;error ( -"invalid file extent item size, have %u expect (%lu, %lu]" , +"invalid file extent item size, have %u expect (%lu, %u]" ,btrfs_item_size_nr (buf, i), inline_offset,BTRFS_LEAF_DATA_SIZE (gfs_info));
image/main.c +1 -1
@@ -2120,7 +2120,7 @@ static int search_for_chunk_blocks(struct mdrestore_struct *mdres) current_cluster);if (ret <0 ) {error ( -"failed to search tree blocks in item bytenr %llu size %lu" , +"failed to search tree blocks in item bytenr %llu size %zu" , item_bytenr, size); goto out; }
kernel-shared/ctree.h +5 -1
@@ -354,7 +354,11 @@ struct btrfs_header {u8 level; } __attribute__ ((__packed__)); -#define __BTRFS_LEAF_DATA_SIZE (bs) ((bs) - sizeof(struct btrfs_header)) +static inline u32 __BTRFS_LEAF_DATA_SIZE (u32 nodesize) +{ +return nodesize -sizeof (struct btrfs_header ); +} +#define BTRFS_LEAF_DATA_SIZE (fs_info) \ (__BTRFS_LEAF_DATA_SIZE(fs_info->nodesize))
kernel-shared/volumes.c +1 -1
@@ -2094,7 +2094,7 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,*/ if (slot >=0 &&btrfs_item_size_nr (leaf, slot) <sizeof (struct btrfs_chunk )) { -error ("invalid chunk item size, have %u expect [%zu, %lu)" , +error ("invalid chunk item size, have %u expect [%zu, %u)" ,btrfs_item_size_nr (leaf, slot),sizeof (struct btrfs_chunk ),BTRFS_LEAF_DATA_SIZE (fs_info));
Signature · 1 line
2.33.1
Quoted 40 lines · Qu Wenruo
When compiling btrfs-progs on 32bit x86 using GCC 11.1.0, there are several warnings:
In file included from
./common/utils.h:30,from check/main.c:36: check/main.c: In function 'run_next_block': ./common/messages.h:42:31: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'u32' {aka 'unsigned int'} [-Wformat=] 42 | __btrfs_error((fmt), ##__VA_ARGS__); \ | ^~~~~ check/main.c:6496:33: note: in expansion of macro 'error' 6496 | error( | ^~~~~In file included from
./common/utils.h:30,
fromkernel-shared/volumes.c:32:
kernel-shared/volumes.c: In function 'btrfs_check_chunk_valid':
./common/messages.h:42:31: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'u32' {aka 'unsigned int'} [-Wformat=]42 | __btrfs_error((fmt), ##__VA_ARGS__); \ | ^~~~~ kernel-shared/volumes.c:2052:17: note: in expansion of macro 'error' 2052 | error("invalid chunk item size, have %u expect [%zu, %lu)", | ^~~~~
image/main.c: In function 'search_for_chunk_blocks':
./common/messages.h:42:31: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'size_t' {aka 'unsigned int'} [-Wformat=]42 | __btrfs_error((fmt), ##__VA_ARGS__); \ | ^~~~~ image/main.c:2122:33: note: in expansion of macro 'error' 2122 | error( | ^~~~~There are two types of problems:
-
__BTRFS_LEAF_DATA_SIZE()
This macro has no type definition, making it behaves differently on different arches.Fix this by following kernel to use inline function to make its return value fixed to u32.
Quoted 6 lines
-
size_trelated output
Forx86_64%lu is OK but not for x86.Fix this by using %zu.
Signed-off-by Qu Wenruo <[email protected]>
Added to devel, thanks.