diff options
author | David Sterba <dsterba@suse.com> | 2016-11-03 00:37:51 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-11-09 13:47:34 +0100 |
commit | d1ec1fe602512f4e97273ae5ed236ffc5a66f06a (patch) | |
tree | 54dc82bb4814c25d22faa98e4c838aae55d88a55 | |
parent | 6dfe365b4bc52f199c98f676a3184886d1e39f61 (diff) |
btrfs-progs: restore: use on-stack path buffer in find_first_dir
We don't need to conserve stack space too much unlike kernel, also
remove one error condition.
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | cmds-restore.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/cmds-restore.c b/cmds-restore.c index 1b95e7a2..a8c67a51 100644 --- a/cmds-restore.c +++ b/cmds-restore.c @@ -1288,36 +1288,30 @@ static struct btrfs_root *open_fs(const char *dev, u64 root_location, static int find_first_dir(struct btrfs_root *root, u64 *objectid) { - struct btrfs_path *path; + struct btrfs_path path; struct btrfs_key found_key; struct btrfs_key key; int ret = -1; int i; + btrfs_init_path(&path); key.objectid = 0; key.type = BTRFS_DIR_INDEX_KEY; key.offset = 0; - - path = btrfs_alloc_path(); - if (!path) { - fprintf(stderr, "Ran out of memory\n"); - return ret; - } - - ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); + ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0); if (ret < 0) { fprintf(stderr, "Error searching %d\n", ret); goto out; } - if (!path->nodes[0]) { + if (!path.nodes[0]) { fprintf(stderr, "No leaf!\n"); goto out; } again: - for (i = path->slots[0]; - i < btrfs_header_nritems(path->nodes[0]); i++) { - btrfs_item_key_to_cpu(path->nodes[0], &found_key, i); + for (i = path.slots[0]; + i < btrfs_header_nritems(path.nodes[0]); i++) { + btrfs_item_key_to_cpu(path.nodes[0], &found_key, i); if (found_key.type != key.type) continue; @@ -1328,7 +1322,7 @@ again: goto out; } do { - ret = next_leaf(root, path); + ret = next_leaf(root, &path); if (ret < 0) { fprintf(stderr, "Error getting next leaf %d\n", ret); @@ -1337,12 +1331,12 @@ again: fprintf(stderr, "No more leaves\n"); goto out; } - } while (!path->nodes[0]); - if (path->nodes[0]) + } while (!path.nodes[0]); + if (path.nodes[0]) goto again; printf("Couldn't find a dir index item\n"); out: - btrfs_free_path(path); + btrfs_release_path(&path); return ret; } |