Btrfs-progs: fix some build warnings on 32bit platform
authorWang Shilong <wangshilong1991@gmail.com>
Sat, 26 Jul 2014 16:49:55 +0000 (00:49 +0800)
committerDavid Sterba <dsterba@suse.cz>
Fri, 22 Aug 2014 13:07:03 +0000 (15:07 +0200)
Fix following build warnings on 32bit platform:

...
utils.c:1708:3: warning: left shift count >= width of
type [enabled by default]
   if (x << i & (1UL << 63))
   ^
qgroup-verify.c:393:9: warning: cast to pointer from integer
of different size [-Wint-to-pointer-cast]
  return (struct tree_block *)unode->aux;
         ^
qgroup-verify.c:407:38: warning: cast from pointer to integer
of different size [-Wpointer-to-int-cast]
   if (ulist_add(tree_blocks, bytenr, (unsigned long long)block, 0) >= 0)
                                      ^
cmds-restore.c:120:4: warning: format %lu expects argument of type
long unsigned int, but argument 3 has type size_t [-Wformat=]
    fprintf(stderr, "bad compress length %lu\n", in_len);
...

BTW, this patch also switches other castings with new helpers.

Signed-off-by: Wang Shilong <wangshilong1991@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
cmds-inspect.c
cmds-restore.c
extent-tree.c
kerncompat.h
qgroup-verify.c
utils.c

index cd9d2c6..c6c17a5 100644 (file)
@@ -49,7 +49,7 @@ static int __ino_to_path_fd(u64 inum, int fd, int verbose, const char *prepend)
        memset(fspath, 0, sizeof(*fspath));
        ipa.inum = inum;
        ipa.size = 4096;
-       ipa.fspath = (uintptr_t)fspath;
+       ipa.fspath = ptr_to_u64(fspath);
 
        ret = ioctl(fd, BTRFS_IOC_INO_PATHS, &ipa);
        if (ret) {
@@ -185,7 +185,7 @@ static int cmd_logical_resolve(int argc, char **argv)
        memset(inodes, 0, sizeof(*inodes));
        loi.logical = arg_strtou64(argv[optind]);
        loi.size = size;
-       loi.inodes = (uintptr_t)inodes;
+       loi.inodes = ptr_to_u64(inodes);
 
        fd = open_file_or_dir(argv[optind+1], &dirstream);
        if (fd < 0) {
index 8e8afc5..33c0ba5 100644 (file)
@@ -117,7 +117,8 @@ static int decompress_lzo(unsigned char *inbuf, char *outbuf, u64 compress_len,
                in_len = read_compress_length(inbuf);
 
                if ((tot_in + LZO_LEN + in_len) > tot_len) {
-                       fprintf(stderr, "bad compress length %lu\n", in_len);
+                       fprintf(stderr, "bad compress length %lu\n",
+                               (unsigned long)in_len);
                        return -1;
                }
 
index 7979457..c46c92b 100644 (file)
@@ -3090,8 +3090,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
                        break;
                ret = get_state_private(&info->block_group_cache, start, &ptr);
                if (!ret) {
-                       cache = (struct btrfs_block_group_cache *)
-                                       (uintptr_t)ptr;
+                       cache = u64_to_ptr(ptr);
                        if (cache->free_space_ctl) {
                                btrfs_remove_free_space_cache(cache);
                                kfree(cache->free_space_ctl);
index 652275e..bb03194 100644 (file)
 #include <assert.h>
 #include <stddef.h>
 #include <linux/types.h>
+#include <stdint.h>
+
+#define ptr_to_u64(x)  ((u64)(uintptr_t)x)
+#define u64_to_ptr(x)  ((void *)(uintptr_t)x)
 
 #ifndef READ
 #define READ 0
index 2e1716d..a5bd4f8 100644 (file)
@@ -390,7 +390,7 @@ static u64 resolve_one_root(u64 bytenr)
 
 static inline struct tree_block *unode_tree_block(struct ulist_node *unode)
 {
-       return (struct tree_block *)unode->aux;
+       return u64_to_ptr(unode->aux);
 }
 static inline u64 unode_bytenr(struct ulist_node *unode)
 {
@@ -404,7 +404,7 @@ static int alloc_tree_block(u64 bytenr, u64 num_bytes, int level)
        if (block) {
                block->num_bytes = num_bytes;
                block->level = level;
-               if (ulist_add(tree_blocks, bytenr, (unsigned long long)block, 0) >= 0)
+               if (ulist_add(tree_blocks, bytenr, ptr_to_u64(block), 0) >= 0)
                        return 0;
                free(block);
        }
diff --git a/utils.c b/utils.c
index 73fcd15..481e061 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -1673,7 +1673,7 @@ static int fls64(u64 x)
        int i;
 
        for (i = 0; i <64; i++)
-               if (x << i & (1UL << 63))
+               if (x << i & (1ULL << 63))
                        return 64 - i;
        return 64 - i;
 }