From 8e8e019e910f20947fea7eff5da40753639d8870 Mon Sep 17 00:00:00 2001 From: Wang Shilong Date: Fri, 28 Sep 2012 01:25:00 +0800 Subject: Btrfs-progs: introduces '-a' option into subvolume list command We list the subvolumes under current directory according to the input subvolume. However, if we still want to list all the subvolumes in the tree, we can use '-a' option to help us. There may be two kinds of path: absolute path , relative path . The absolute path is beginning with "" The relative path is under current path that you input. Signed-off-by: Wang Shilong --- btrfs-list.c | 12 ++++++++++-- cmds-subvolume.c | 16 +++++++++++----- man/btrfs.8.in | 6 ++++-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/btrfs-list.c b/btrfs-list.c index f079d998..e5f0f969 100644 --- a/btrfs-list.c +++ b/btrfs-list.c @@ -627,8 +627,16 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri, break; } - /* if the ref_tree refers to ourselves, we're at the top */ - if (next == found->root_id) { + if (next == BTRFS_FS_TREE_OBJECTID) { + char p[] = ""; + add_len = strlen(p); + len = strlen(full_path); + tmp = malloc(len + add_len + 2); + memcpy(tmp + add_len + 1, full_path, len); + tmp[add_len] = '/'; + memcpy(tmp, p, add_len); + free(full_path); + full_path = tmp; ri->top_id = next; break; } diff --git a/cmds-subvolume.c b/cmds-subvolume.c index b96af3eb..3b4edb63 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -260,11 +260,12 @@ static int cmd_subvol_delete(int argc, char **argv) } static const char * const cmd_subvol_list_usage[] = { - "btrfs subvolume list [-purt] [-s 0|1] [-g [+|-]value] [-c [+|-]value] " + "btrfs subvolume list [-apurt] [-s 0|1] [-g [+|-]value] [-c [+|-]value] " "[--sort=gen,ogen,rootid,path] ", "List subvolumes (and snapshots)", "", "-p print parent ID", + "-a print all the subvolumes in the filesystem.", "-u print the uuid of subvolumes (and snapshots)", "-t print the result as a table", "-s value list snapshots with generation in ascending/descending order", @@ -295,6 +296,7 @@ static int cmd_subvol_list(int argc, char **argv) int c; char *subvol; int is_tab_result = 0; + int is_list_all = 0; struct option long_options[] = { {"sort", 1, NULL, 'S'}, {0, 0, 0, 0} @@ -306,7 +308,7 @@ static int cmd_subvol_list(int argc, char **argv) optind = 1; while(1) { c = getopt_long(argc, argv, - "ps:urg:c:t", long_options, NULL); + "aps:urg:c:t", long_options, NULL); if (c < 0) break; @@ -314,6 +316,9 @@ static int cmd_subvol_list(int argc, char **argv) case 'p': btrfs_list_setup_print_column(BTRFS_LIST_PARENT); break; + case 'a': + is_list_all = 1; + break; case 't': is_tab_result = 1; break; @@ -389,9 +394,10 @@ static int cmd_subvol_list(int argc, char **argv) } top_id = btrfs_list_get_path_rootid(fd); - btrfs_list_setup_filter(&filter_set, - BTRFS_LIST_FILTER_TOPID_EQUAL, - top_id); + if (!is_list_all) + btrfs_list_setup_filter(&filter_set, + BTRFS_LIST_FILTER_TOPID_EQUAL, + top_id); ret = btrfs_list_subvols(fd, filter_set, comparer_set, is_tab_result); diff --git a/man/btrfs.8.in b/man/btrfs.8.in index 3f7765d6..632802a2 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -11,7 +11,7 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBsubvolume create\fP\fI [/]\fP .PP -\fBbtrfs\fP \fBsubvolume list\fP\fI [-pr] [-s 0|1] [-g [+|-]value] [-c [+|-]value] [--rootid=rootid,gen,ogen,path] \fP +\fBbtrfs\fP \fBsubvolume list\fP\fI [-aprt] [-s 0|1] [-g [+|-]value] [-c [+|-]value] [--rootid=rootid,gen,ogen,path] \fP .PP \fBbtrfs\fP \fBsubvolume set-default\fP\fI \fP .PP @@ -108,7 +108,7 @@ Create a subvolume in \fI\fR (or in the current directory if \fI\fR is omitted). .TP -\fBsubvolume list\fR\fI [-pr][-s 0|1] [-g [+|-]value] [-c [+|-]value] [--sort=gen,ogen,rootid,path] \fR +\fBsubvolume list\fR\fI [-aprt][-s 0|1] [-g [+|-]value] [-c [+|-]value] [--sort=gen,ogen,rootid,path] \fR .RS List the subvolumes present in the filesystem \fI\fR. For every subvolume the following information is shown by default. @@ -124,6 +124,8 @@ and top level. The parent's ID may be used at mount time via the \fB-t\fP print the result as a table. +\fB-a\fP print all the subvolumes in the filesystem. + \fB-r\fP only readonly subvolumes in the filesystem wille be listed. \fB-s\fP only snapshot subvolumes in the filesystem will be listed. -- cgit v1.2.3