summaryrefslogtreecommitdiff
path: root/btrfs-list.c
diff options
context:
space:
mode:
authorAndreas Philipp <philipp.andreas@gmail.com>2011-07-03 00:26:39 +0200
committerChris Mason <chris.mason@oracle.com>2011-10-25 09:18:59 -0400
commit97a3182fbf1b9086a90fcb40d4af197c376e6b5e (patch)
treeaaa4ebf4f08651584c556e4211bb9cf9e0824d47 /btrfs-list.c
parentfd635cdc2d34ed8a1314dc1eef410e0259a796cd (diff)
print parent ID in btrfs suvolume list
There was some discussion on "where" subvolumes live in. Why do we not simply print the parent ID for each subvolume in btrfs subvolume list? This patch adds this functionality when called with parameter "-p". Signed-off-by: Andreas Philipp <philipp.andreas@gmail.com> Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
Diffstat (limited to 'btrfs-list.c')
-rw-r--r--btrfs-list.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/btrfs-list.c b/btrfs-list.c
index f804dfc6..0c3edd11 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -200,9 +200,10 @@ static int add_root(struct root_lookup *root_lookup,
* This can't be called until all the root_info->path fields are filled
* in by lookup_ino_path
*/
-static int resolve_root(struct root_lookup *rl, struct root_info *ri)
+static int resolve_root(struct root_lookup *rl, struct root_info *ri, int print_parent)
{
u64 top_id;
+ u64 parent_id = 0;
char *full_path = NULL;
int len = 0;
struct root_info *found;
@@ -233,6 +234,11 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri)
}
next = found->ref_tree;
+ /* record the first parent */
+ if ( parent_id == 0 ) {
+ parent_id = next;
+ }
+
/* if the ref_tree refers to ourselves, we're at the top */
if (next == found->root_id) {
top_id = next;
@@ -249,9 +255,15 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri)
break;
}
}
- printf("ID %llu top level %llu path %s\n",
- (unsigned long long)ri->root_id, (unsigned long long)top_id,
- full_path);
+ if (print_parent) {
+ printf("ID %llu parent %llu top level %llu path %s\n",
+ (unsigned long long)ri->root_id, (unsigned long long)parent_id, (unsigned long long)top_id,
+ full_path);
+ } else {
+ printf("ID %llu top level %llu path %s\n",
+ (unsigned long long)ri->root_id, (unsigned long long)top_id,
+ full_path);
+ }
free(full_path);
return 0;
}
@@ -549,7 +561,7 @@ build:
return full;
}
-int list_subvols(int fd)
+int list_subvols(int fd, int print_parent)
{
struct root_lookup root_lookup;
struct rb_node *n;
@@ -666,7 +678,7 @@ int list_subvols(int fd)
while (n) {
struct root_info *entry;
entry = rb_entry(n, struct root_info, rb_node);
- resolve_root(&root_lookup, entry);
+ resolve_root(&root_lookup, entry, print_parent);
n = rb_prev(n);
}