Skip to content

Commit 9e73a41

Browse files
osandovkdave
authored andcommitted
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 <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 2116398 commit 9e73a41

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

cmds-subvolume.c

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* Boston, MA 021110-1307, USA.
1515
*/
1616

17+
#include <inttypes.h>
1718
#include <stdio.h>
1819
#include <stdlib.h>
1920
#include <string.h>
@@ -806,31 +807,25 @@ static const char * const cmd_subvol_get_default_usage[] = {
806807
static int cmd_subvol_get_default(int argc, char **argv)
807808
{
808809
int fd = -1;
809-
int ret;
810-
char *subvol;
811-
struct btrfs_list_filter_set *filter_set;
812-
u64 default_id;
810+
int ret = 1;
811+
uint64_t default_id;
813812
DIR *dirstream = NULL;
813+
enum btrfs_util_error err;
814+
struct btrfs_util_subvolume_info subvol;
815+
char *path;
814816

815817
clean_args_no_options(argc, argv, cmd_subvol_get_default_usage);
816818

817819
if (check_argc_exact(argc - optind, 1))
818820
usage(cmd_subvol_get_default_usage);
819821

820-
subvol = argv[1];
821-
fd = btrfs_open_dir(subvol, &dirstream, 1);
822+
fd = btrfs_open_dir(argv[1], &dirstream, 1);
822823
if (fd < 0)
823824
return 1;
824825

825-
ret = btrfs_list_get_default_subvolume(fd, &default_id);
826-
if (ret) {
827-
error("failed to look up default subvolume: %m");
828-
goto out;
829-
}
830-
831-
ret = 1;
832-
if (default_id == 0) {
833-
error("'default' dir item not found");
826+
err = btrfs_util_get_default_subvolume_fd(fd, &default_id);
827+
if (err) {
828+
error_btrfs_util(err);
834829
goto out;
835830
}
836831

@@ -841,24 +836,27 @@ static int cmd_subvol_get_default(int argc, char **argv)
841836
goto out;
842837
}
843838

844-
filter_set = btrfs_list_alloc_filter_set();
845-
btrfs_list_setup_filter(&filter_set, BTRFS_LIST_FILTER_ROOTID,
846-
default_id);
839+
err = btrfs_util_subvolume_info_fd(fd, default_id, &subvol);
840+
if (err) {
841+
error_btrfs_util(err);
842+
goto out;
843+
}
847844

848-
/* by default we shall print the following columns*/
849-
btrfs_list_setup_print_column(BTRFS_LIST_OBJECTID);
850-
btrfs_list_setup_print_column(BTRFS_LIST_GENERATION);
851-
btrfs_list_setup_print_column(BTRFS_LIST_TOP_LEVEL);
852-
btrfs_list_setup_print_column(BTRFS_LIST_PATH);
845+
err = btrfs_util_subvolume_path_fd(fd, default_id, &path);
846+
if (err) {
847+
error_btrfs_util(err);
848+
goto out;
849+
}
853850

854-
ret = btrfs_list_subvols_print(fd, filter_set, NULL,
855-
BTRFS_LIST_LAYOUT_DEFAULT, 1, NULL);
851+
printf("ID %" PRIu64 " gen %" PRIu64 " top level %" PRIu64 " path %s\n",
852+
subvol.id, subvol.generation, subvol.parent_id, path);
856853

857-
if (filter_set)
858-
free(filter_set);
854+
free(path);
855+
856+
ret = 0;
859857
out:
860858
close_file_or_dir(fd, dirstream);
861-
return !!ret;
859+
return ret;
862860
}
863861

864862
static const char * const cmd_subvol_set_default_usage[] = {

0 commit comments

Comments
 (0)