summaryrefslogtreecommitdiff
path: root/cmds-inspect.c
diff options
context:
space:
mode:
authorStefan Behrens <sbehrens@giantdisaster.de>2013-04-23 12:18:55 +0200
committerDavid Sterba <dsterba@suse.cz>2013-04-23 19:16:25 +0200
commit6d26357f8e7d73d802e8025407fe17542a18164b (patch)
treeabef033343ba9e957b2264dad8d3046310c07c9b /cmds-inspect.c
parent6b76570652e2f5a1f776848f330ca01e418a186c (diff)
Btrfs-progs: add function to map subvol ID to path
Several tools like btrfs-send and btrfs-receive need to map a subvolume ID to a filesystem path. The so far existing methods in btrfs-list.c cause a horrible effort when performing this operation (and the effort is dependent on the number of existing subvolumes with quadratic effort). This commit adds a function that is able to map a subvolume ID to a filesystem path with an effort that is independent of the number of existing subvolumes. In addition to this function, a command line frontend is added as well: btrfs inspect-internal subvolid-resolve <subvolid> <path> Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Diffstat (limited to 'cmds-inspect.c')
-rw-r--r--cmds-inspect.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/cmds-inspect.c b/cmds-inspect.c
index 7761759..30b41fc 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -24,6 +24,8 @@
#include "kerncompat.h"
#include "ioctl.h"
#include "utils.h"
+#include "ctree.h"
+#include "send-utils.h"
#include "commands.h"
#include "btrfs-list.h"
@@ -253,12 +255,56 @@ out:
return ret;
}
+static const char * const cmd_subvolid_resolve_usage[] = {
+ "btrfs inspect-internal subvolid-resolve <subvolid> <path>",
+ "Get file system paths for the given subvolume ID.",
+ NULL
+};
+
+static int cmd_subvolid_resolve(int argc, char **argv)
+{
+ int ret;
+ int fd = -1;
+ u64 subvol_id;
+ char path[BTRFS_PATH_NAME_MAX + 1];
+
+ if (check_argc_exact(argc, 3))
+ usage(cmd_subvolid_resolve_usage);
+
+ fd = open_file_or_dir(argv[2]);
+ if (fd < 0) {
+ fprintf(stderr, "ERROR: can't access '%s'\n", argv[2]);
+ ret = -ENOENT;
+ goto out;
+ }
+
+ subvol_id = atoll(argv[1]);
+ ret = btrfs_subvolid_resolve(fd, path, sizeof(path), subvol_id);
+
+ if (ret) {
+ fprintf(stderr,
+ "%s: btrfs_subvolid_resolve(subvol_id %llu) failed with ret=%d\n",
+ argv[0], (unsigned long long)subvol_id, ret);
+ goto out;
+ }
+
+ path[BTRFS_PATH_NAME_MAX] = '\0';
+ printf("%s\n", path);
+
+out:
+ if (fd >= 0)
+ close(fd);
+ return ret ? 1 : 0;
+}
+
const struct cmd_group inspect_cmd_group = {
inspect_cmd_group_usage, NULL, {
{ "inode-resolve", cmd_inode_resolve, cmd_inode_resolve_usage,
NULL, 0 },
{ "logical-resolve", cmd_logical_resolve,
cmd_logical_resolve_usage, NULL, 0 },
+ { "subvolid-resolve", cmd_subvolid_resolve,
+ cmd_subvolid_resolve_usage, NULL, 0 },
{ 0, 0, 0, 0, 0 }
}
};