X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=cmds-inspect.c;h=885f3abe5b0bfe72156cd2e9eec09fa2c067f0e6;hb=faaf70f1cc7ade1d6d5a41a900a3b58cc4bd5f58;hp=25e8c016136f7b0d8051c4d3b8c159e6f5331592;hpb=1e4abbdf96cae7cbf17a3bf1376d7a56e78153fa;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/cmds-inspect.c b/cmds-inspect.c index 25e8c01..885f3ab 100644 --- a/cmds-inspect.c +++ b/cmds-inspect.c @@ -31,9 +31,7 @@ #include "disk-io.h" #include "commands.h" #include "btrfs-list.h" -#include "cmds-inspect-dump-tree.h" -#include "cmds-inspect-dump-super.h" -#include "cmds-inspect-tree-stats.h" +#include "help.h" static const char * const inspect_cmd_group_usage[] = { "btrfs inspect-internal ", @@ -96,7 +94,6 @@ static int cmd_inspect_inode_resolve(int argc, char **argv) int ret; DIR *dirstream = NULL; - optind = 1; while (1) { int c = getopt(argc, argv, "v"); if (c < 0) @@ -147,11 +144,10 @@ static int cmd_inspect_logical_resolve(int argc, char **argv) struct btrfs_ioctl_logical_ino_args loi; struct btrfs_data_container *inodes; u64 size = 4096; - char full_path[4096]; + char full_path[PATH_MAX]; char *path_ptr; DIR *dirstream = NULL; - optind = 1; while (1) { int c = getopt(argc, argv, "Pvs:"); if (c < 0) @@ -175,7 +171,7 @@ static int cmd_inspect_logical_resolve(int argc, char **argv) if (check_argc_exact(argc - optind, 2)) usage(cmd_inspect_logical_resolve_usage); - size = min(size, (u64)64 * 1024); + size = min(size, (u64)SZ_64K); inodes = malloc(size); if (!inodes) return 1; @@ -209,7 +205,10 @@ static int cmd_inspect_logical_resolve(int argc, char **argv) ret = snprintf(full_path, bytes_left, "%s/", argv[optind+1]); path_ptr = full_path + ret; bytes_left -= ret + 1; - BUG_ON(bytes_left < 0); + if (bytes_left < 0) { + error("path buffer too small: %d bytes", bytes_left); + goto out; + } for (i = 0; i < inodes->elem_cnt; i += 3) { u64 inum = inodes->val[i]; @@ -232,8 +231,12 @@ static int cmd_inspect_logical_resolve(int argc, char **argv) path_ptr[-1] = '/'; ret = snprintf(path_ptr, bytes_left, "%s", name); - BUG_ON(ret >= bytes_left); free(name); + if (ret >= bytes_left) { + error("path buffer too small: %d bytes", + bytes_left - ret); + goto out; + } path_fd = btrfs_open_dir(full_path, &dirs, 1); if (path_fd < 0) { ret = -ENOENT; @@ -315,15 +318,15 @@ static int cmd_inspect_rootid(int argc, char **argv) if (check_argc_exact(argc - optind, 1)) usage(cmd_inspect_rootid_usage); - fd = btrfs_open_dir(argv[optind], &dirstream, 1); + fd = btrfs_open_file_or_dir(argv[optind], &dirstream, 1); if (fd < 0) { ret = -ENOENT; goto out; } - ret = lookup_ino_rootid(fd, &rootid); + ret = lookup_path_rootid(fd, &rootid); if (ret) { - error("rootid failed with ret=%d", ret); + error("failed to lookup root id: %s", strerror(-ret)); goto out; } @@ -415,7 +418,7 @@ static void adjust_dev_min_size(struct list_head *extents, /* * List of device extents is sorted by descending order of the extent's * end offset. If some extent goes beyond the computed minimum size, - * which initially matches the sum of the lenghts of all extents, + * which initially matches the sum of the lengths of all extents, * we need to check if the extent can be relocated to an hole in the * device between [0, *min_size[ (which is what the resize ioctl does). */ @@ -481,7 +484,7 @@ static void adjust_dev_min_size(struct list_head *extents, * chunk tree, so often this can lead to the need of allocating * a new system chunk too, which has a maximum size of 32Mb. */ - *min_size += 32 * 1024 * 1024; + *min_size += SZ_32M; } } @@ -495,7 +498,7 @@ static int print_min_dev_size(int fd, u64 devid) * possibility of deprecating/removing it has been discussed, so we * ignore it here. */ - u64 min_size = 1 * 1024 * 1024ull; + u64 min_size = SZ_1M; struct btrfs_ioctl_search_args args; struct btrfs_ioctl_search_key *sk = &args.key; u64 last_pos = (u64)-1;