summaryrefslogtreecommitdiff
path: root/cmds-subvolume.c
diff options
context:
space:
mode:
authorOmar Sandoval <osandov@fb.com>2018-01-19 14:52:11 -0800
committerDavid Sterba <dsterba@suse.com>2018-03-06 11:28:37 +0100
commit9e73a416f0acbc6c215532e2441f5be10b9e166a (patch)
treecf0b5b24905ba4b6a242bca4df98a79229aa12d3 /cmds-subvolume.c
parent2116398b1dbe8a4483a64e087c9a4588d8a230d1 (diff)
btrfs-progs: use libbtrfsutil for get-default
The only thing of note here is the "top level" column. This used to mean something else, but for a long time it has been equal to the parent ID. I preserved this for backwards compatability. Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-subvolume.c')
-rw-r--r--cmds-subvolume.c54
1 files changed, 26 insertions, 28 deletions
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index d30435f..149cd3f 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -14,6 +14,7 @@
* Boston, MA 021110-1307, USA.
*/
+#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -806,31 +807,25 @@ static const char * const cmd_subvol_get_default_usage[] = {
static int cmd_subvol_get_default(int argc, char **argv)
{
int fd = -1;
- int ret;
- char *subvol;
- struct btrfs_list_filter_set *filter_set;
- u64 default_id;
+ int ret = 1;
+ uint64_t default_id;
DIR *dirstream = NULL;
+ enum btrfs_util_error err;
+ struct btrfs_util_subvolume_info subvol;
+ char *path;
clean_args_no_options(argc, argv, cmd_subvol_get_default_usage);
if (check_argc_exact(argc - optind, 1))
usage(cmd_subvol_get_default_usage);
- subvol = argv[1];
- fd = btrfs_open_dir(subvol, &dirstream, 1);
+ fd = btrfs_open_dir(argv[1], &dirstream, 1);
if (fd < 0)
return 1;
- ret = btrfs_list_get_default_subvolume(fd, &default_id);
- if (ret) {
- error("failed to look up default subvolume: %m");
- goto out;
- }
-
- ret = 1;
- if (default_id == 0) {
- error("'default' dir item not found");
+ err = btrfs_util_get_default_subvolume_fd(fd, &default_id);
+ if (err) {
+ error_btrfs_util(err);
goto out;
}
@@ -841,24 +836,27 @@ static int cmd_subvol_get_default(int argc, char **argv)
goto out;
}
- filter_set = btrfs_list_alloc_filter_set();
- btrfs_list_setup_filter(&filter_set, BTRFS_LIST_FILTER_ROOTID,
- default_id);
+ err = btrfs_util_subvolume_info_fd(fd, default_id, &subvol);
+ if (err) {
+ error_btrfs_util(err);
+ goto out;
+ }
- /* by default we shall print the following columns*/
- btrfs_list_setup_print_column(BTRFS_LIST_OBJECTID);
- btrfs_list_setup_print_column(BTRFS_LIST_GENERATION);
- btrfs_list_setup_print_column(BTRFS_LIST_TOP_LEVEL);
- btrfs_list_setup_print_column(BTRFS_LIST_PATH);
+ err = btrfs_util_subvolume_path_fd(fd, default_id, &path);
+ if (err) {
+ error_btrfs_util(err);
+ goto out;
+ }
- ret = btrfs_list_subvols_print(fd, filter_set, NULL,
- BTRFS_LIST_LAYOUT_DEFAULT, 1, NULL);
+ printf("ID %" PRIu64 " gen %" PRIu64 " top level %" PRIu64 " path %s\n",
+ subvol.id, subvol.generation, subvol.parent_id, path);
- if (filter_set)
- free(filter_set);
+ free(path);
+
+ ret = 0;
out:
close_file_or_dir(fd, dirstream);
- return !!ret;
+ return ret;
}
static const char * const cmd_subvol_set_default_usage[] = {