btrfs-progs: add btrfs_clear_free_space_tree() from the kernel
[platform/upstream/btrfs-progs.git] / cmds-inspect.c
index 25e8c01..5e58a28 100644 (file)
@@ -96,7 +96,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 +146,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)
@@ -209,7 +207,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 +233,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;
@@ -321,9 +326,9 @@ static int cmd_inspect_rootid(int argc, char **argv)
                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 +420,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).
         */