From patchwork Fri Jan 26 18:41:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10186753 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4B0A4603ED for ; Fri, 26 Jan 2018 18:41:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D32729EC8 for ; Fri, 26 Jan 2018 18:41:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3208B29ED0; Fri, 26 Jan 2018 18:41:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 353E329EC8 for ; Fri, 26 Jan 2018 18:41:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752023AbeAZSlp (ORCPT ); Fri, 26 Jan 2018 13:41:45 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:37879 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751613AbeAZSlk (ORCPT ); Fri, 26 Jan 2018 13:41:40 -0500 Received: by mail-pg0-f66.google.com with SMTP id z17so788809pgc.4 for ; Fri, 26 Jan 2018 10:41:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=CbS0F48qgNo49nNTOmmjNNiV9ILGD2yj3Y4giiOVsEs=; b=GgSR5DhK4BQ/o0jhC43Ksn2RCjVQ9wYkjO8nCTQDtlYx5Iu0J2z4aknZx2VUaRCOSE Ex4B7I7GND+4ejc6VXdlhsxela4FvQsFQyPJhOQBUv2yUzVvc6dbxfBbqGEgzjBaOHPY V4h2BYHpo/yzdunvNAXlidvtAc23E7S6rswlKiySz6O5BOGfWrwDK7vfF/vWK32ZQwXD me4UJ+4L5p23J1MiDJ6Rl06cVJnEuTj3pvAPrT+QSaOJtQGJDf9lUwldaapRMVAs6gob xpT6pwYQ+yvg8lQu9HDZgk5+jxQNjit3d55SqdMSux+4JqLGVjOBAPquXlmBL49s9fsr wF7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=CbS0F48qgNo49nNTOmmjNNiV9ILGD2yj3Y4giiOVsEs=; b=D0VmfLBQqW8Tlx1bDqETCZMbaRNYhmyCOgR8p8TGH0PNTS623IT1ChFVDkbRSClb/w ugODYtQXXeSwvxgB4Q4penJKlpl4NFxuLOMFBKsAqaGl+6PiZvOUf0Pipr//S6es8ODX aGVd2KXCZQUuYdqKneq/bZqR0yIagkoXJ+J8F2X77niu4c/ZSkvB+/tjf26xgz4gP1t4 ei7zpXCqvKnsQPdHVXJzngstwhqQKkcbwPSME7MZ1/ApfmvT/1DGeoV9T8aBHOCSZy4L kZRneF9X7avq7nwBuiuuTg/axGfbnewfejMK38T1E2l8D8zj06Rgm7TsjbEc4ZIJMBN/ GSag== X-Gm-Message-State: AKwxytcPmlJb8vwFotvEqNZI61Mq7Q1lUtU2piuHHGpqiVpOEub8TagO N3p9sfgZbzGJ4+ZH5dA39Ok/0KNwEd0= X-Google-Smtp-Source: AH8x225V6VTcFHTrLfHR5YC1Rg8GT8LTIWKXxmwhwWkdFTqiCxSf8hu8M/psJSlUV1RzOCa+D9hl+A== X-Received: by 2002:a17:902:8a97:: with SMTP id p23-v6mr15121999plo.74.1516992099851; Fri, 26 Jan 2018 10:41:39 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:200::6:7f96]) by smtp.gmail.com with ESMTPSA id y29sm19627400pff.24.2018.01.26.10.41.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jan 2018 10:41:39 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH 18/26] btrfs-progs: use libbtrfsutil for get-default Date: Fri, 26 Jan 2018 10:41:06 -0800 Message-Id: <093f03a285d38e6083eb8c047f09adbe21852d99.1516991902.git.osandov@fb.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval 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 --- cmds-subvolume.c | 55 ++++++++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index aaf88af8..557108c1 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -14,6 +14,7 @@ * Boston, MA 021110-1307, USA. */ +#include #include #include #include @@ -788,32 +789,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: %s", - strerror(errno)); - goto out; - } - - ret = 1; - if (default_id == 0) { - error("'default' dir item not found"); + err = btrfs_util_f_get_default_subvolume(fd, &default_id); + if (err) { + error_btrfs_util(err); goto out; } @@ -824,24 +818,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_f_subvolume_info(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_f_subvolume_path(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[] = {