mirror of
https://github.com/kdave/btrfs-progs
synced 2025-05-02 07:57:58 +00:00
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>
This commit is contained in:
parent
6dfe365b4b
commit
d1ec1fe602
@ -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)
|
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 found_key;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
btrfs_init_path(&path);
|
||||||
key.objectid = 0;
|
key.objectid = 0;
|
||||||
key.type = BTRFS_DIR_INDEX_KEY;
|
key.type = BTRFS_DIR_INDEX_KEY;
|
||||||
key.offset = 0;
|
key.offset = 0;
|
||||||
|
ret = btrfs_search_slot(NULL, root, &key, &path, 0, 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);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "Error searching %d\n", ret);
|
fprintf(stderr, "Error searching %d\n", ret);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!path->nodes[0]) {
|
if (!path.nodes[0]) {
|
||||||
fprintf(stderr, "No leaf!\n");
|
fprintf(stderr, "No leaf!\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
again:
|
again:
|
||||||
for (i = path->slots[0];
|
for (i = path.slots[0];
|
||||||
i < btrfs_header_nritems(path->nodes[0]); i++) {
|
i < btrfs_header_nritems(path.nodes[0]); i++) {
|
||||||
btrfs_item_key_to_cpu(path->nodes[0], &found_key, i);
|
btrfs_item_key_to_cpu(path.nodes[0], &found_key, i);
|
||||||
if (found_key.type != key.type)
|
if (found_key.type != key.type)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -1328,7 +1322,7 @@ again:
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
ret = next_leaf(root, path);
|
ret = next_leaf(root, &path);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "Error getting next leaf %d\n",
|
fprintf(stderr, "Error getting next leaf %d\n",
|
||||||
ret);
|
ret);
|
||||||
@ -1337,12 +1331,12 @@ again:
|
|||||||
fprintf(stderr, "No more leaves\n");
|
fprintf(stderr, "No more leaves\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} while (!path->nodes[0]);
|
} while (!path.nodes[0]);
|
||||||
if (path->nodes[0])
|
if (path.nodes[0])
|
||||||
goto again;
|
goto again;
|
||||||
printf("Couldn't find a dir index item\n");
|
printf("Couldn't find a dir index item\n");
|
||||||
out:
|
out:
|
||||||
btrfs_free_path(path);
|
btrfs_release_path(&path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user