diff options
author | wangshilong <wangsl-fnst@cn.fujitsu.com> | 2012-09-19 17:21:51 +0800 |
---|---|---|
committer | root <root@localhost.localdomain> | 2012-10-04 16:26:33 -0400 |
commit | 60d11eca6649700c1e39c19c36c903cad747e775 (patch) | |
tree | 57868509696a0977308585d46ee80870ce7ccc38 /cmds-subvolume.c | |
parent | af3045cb201b5a89397d90409aafe111aa526e8a (diff) |
Btrfs-progs: introduce -g -c --sort options into btrfs subvol list command
This patch introduces '-g' '-c' '--sort' options
The option '-g' can help you filter the subvolumes by the generation, you may
use it just like:
btrfs subvol list -g +/-value <path>
'+' means the generation of the subvolumes should >= the value you specified.
'-' means the generation should <= the value
If you don't input either '+' nor '-', this command will list the subvolumes
that their generation equals to the value.
However if you want to find gengeration between value1 and value2
you may use the above like:
btrfs sub list -g -value1 -g +value2 <path>
The option '-c' can help you filter the subvolumes by the ogeneration, you may
use it just like:
btrfs subvol list -c +/-value <path>
The usage is the same to '-g'
You might want to list subvolumes in order of some items, such as root id, gen
and so on, you can use '--sort'. Now you can sort the subvolumes by root id,
gen, ogen and path.
For example:
If you want to list subvolumes in order of rootid, you can use the option like
that:
btrfs sub list --sort=+/-rooid <path>
Here, '+' means the result is sorted by ascending order. '-' is by descending
order. If you don't specify either '+' nor '-', the result is sorted by
default - ascending order.
If you want to combine sort items, you do it like that:
btrfs sub list --sort=-rootid,+path,ogen,gen <path>
Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Diffstat (limited to 'cmds-subvolume.c')
-rw-r--r-- | cmds-subvolume.c | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/cmds-subvolume.c b/cmds-subvolume.c index f385816f..f5da022f 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -23,6 +23,7 @@ #include <sys/stat.h> #include <libgen.h> #include <limits.h> +#include <getopt.h> #include "kerncompat.h" #include "ioctl.h" @@ -259,7 +260,8 @@ static int cmd_subvol_delete(int argc, char **argv) } static const char * const cmd_subvol_list_usage[] = { - "btrfs subvolume list [-pur] [-s 0|1] <path>", + "btrfs subvolume list [-pur] [-s 0|1] [-g [+|-]value] [-c [+|-]value] " + "[--sort=gen,ogen,rootid,path] <path>", "List subvolumes (and snapshots)", "", "-p print parent ID", @@ -267,7 +269,17 @@ static const char * const cmd_subvol_list_usage[] = { "-s value list snapshots with generation in ascending/descending order", " (1: ascending, 0: descending)", "-r list readonly subvolumes (including snapshots)", - NULL + "-g [+|-]value", + " filter the subvolumes by generation", + " (+value: >= value; -value: <= value; value: = value)", + "-c [+|-]value", + " filter the subvolumes by ogeneration", + " (+value: >= value; -value: <= value; value: = value)", + "--sort=gen,ogen,rootid,path", + " list the subvolume in order of gen, ogen, rootid or path", + " you also can add '+' or '-' in front of each items.", + " (+:ascending, -:descending, ascending default)", + NULL, }; static int cmd_subvol_list(int argc, char **argv) @@ -278,14 +290,20 @@ static int cmd_subvol_list(int argc, char **argv) int fd; int ret; int order; + int c; char *subvol; + struct option long_options[] = { + {"sort", 1, NULL, 'S'}, + {0, 0, 0, 0} + }; filter_set = btrfs_list_alloc_filter_set(); comparer_set = btrfs_list_alloc_comparer_set(); optind = 1; while(1) { - int c = getopt(argc, argv, "ps:ur"); + c = getopt_long(argc, argv, + "ps:urg:c:", long_options, NULL); if (c < 0) break; @@ -303,13 +321,37 @@ static int cmd_subvol_list(int argc, char **argv) !order); btrfs_list_setup_print_column(BTRFS_LIST_OGENERATION); btrfs_list_setup_print_column(BTRFS_LIST_OTIME); - break; + case 'u': btrfs_list_setup_print_column(BTRFS_LIST_UUID); break; case 'r': flags |= BTRFS_ROOT_SUBVOL_RDONLY; break; + case 'g': + btrfs_list_setup_print_column(BTRFS_LIST_GENERATION); + ret = btrfs_list_parse_filter_string(optarg, + &filter_set, + BTRFS_LIST_FILTER_GEN); + if (ret) + usage(cmd_subvol_list_usage); + break; + + case 'c': + btrfs_list_setup_print_column(BTRFS_LIST_OGENERATION); + ret = btrfs_list_parse_filter_string(optarg, + &filter_set, + BTRFS_LIST_FILTER_CGEN); + if (ret) + usage(cmd_subvol_list_usage); + break; + case 'S': + ret = btrfs_list_parse_sort_string(optarg, + &comparer_set); + if (ret) + usage(cmd_subvol_list_usage); + break; + default: usage(cmd_subvol_list_usage); } |