From patchwork Thu Feb 15 19:05:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10223397 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 5A4BD602CB for ; Thu, 15 Feb 2018 19:05:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AB4729406 for ; Thu, 15 Feb 2018 19:05:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F0902948F; Thu, 15 Feb 2018 19:05:55 +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 2668729406 for ; Thu, 15 Feb 2018 19:05:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1167177AbeBOTFw (ORCPT ); Thu, 15 Feb 2018 14:05:52 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:35653 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161145AbeBOTFt (ORCPT ); Thu, 15 Feb 2018 14:05:49 -0500 Received: by mail-pg0-f65.google.com with SMTP id l131so509661pga.2 for ; Thu, 15 Feb 2018 11:05:49 -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=VxIHf5ifl6gGpiVMG5QaH/jqteL8j3K7pwDjae06hzU=; b=wV1WL+G+eMZzF9+zQhtbhxQIaZMUjjtIeCVS4N+S8yAW2sRfMMZoA8o0vHPLl0YnGo Ro1xla+t9INY5OJr/ZFvWM2GaJc3JKCl6JPumfQtytUWuZZY8V1GmP/6/fW41Gh/SVqd 8T0+T0+Kd1haJhhJSGw8UhDu90FSASUUQb2kZQvV3i4x1guHxvBIocu5u7mQaq46LtaD q4efFNzGfhFnBQHvn1o/3N6Gs+2Eak+cNRRV+Esrb3vxqmPM+ok6LmcoSw1ddDkmN7+2 3f1b37VDMXhMgf2X8w65UDJtLuTF1uSK0atzwr6F6Ms7lUNxwFzEZFv95Ao552w8U9Y1 WIYg== 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=VxIHf5ifl6gGpiVMG5QaH/jqteL8j3K7pwDjae06hzU=; b=dYIyEGW3nQ9v1GfvHYPAK+2CTnRitWc1q1mTopVtEYLoxphDd4VMwXe6Jtm/1x8qZI Y2TCZlGyuB9HA30O2vVp6ci+da+FdCkFU+TQn74gDqUxHaSgiYgidCCUxZNiWpAU3MMq d3EHgQXGsRNj/75Q4LTF6S9DGzzaNa48T66QCh6cNk2rejRuZ8aKCn7s2M0OCad+/wEH +P3xRStmHgVydXH86dqD612nwSCyyO2XMMgOQrEQ2Qcrnnv/+liAv9Z9VmD3FpeYPP7Q AHcTvdxSCWgAjStCWDgemSTOlezJn6G3PI7Hfm42yTjotJHOuYEF0DfyIFTaoAxEcEkv 4v7Q== X-Gm-Message-State: APf1xPAKw/Qzv/twjOP92aMT7PmmSaAMCtpF9/PVBEPoWhuK7C8hIaKV rRMf/PfN4HVg6uBE5ICjkI3e/RFHz2I= X-Google-Smtp-Source: AH8x227et4wXtpBElll6IbGP3pOo0eN/sgcOVh3DtamTH4+6RFUxMQ6oEMl4BfWLmuR3p9sBSFrVJw== X-Received: by 10.98.51.70 with SMTP id z67mr3626920pfz.2.1518721548213; Thu, 15 Feb 2018 11:05:48 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:200::6:4a19]) by smtp.gmail.com with ESMTPSA id p1sm40467428pgr.44.2018.02.15.11.05.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Feb 2018 11:05:47 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH v2 19/27] btrfs-progs: use libbtrfsutil for get-default Date: Thu, 15 Feb 2018 11:05:04 -0800 Message-Id: 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 | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index 700e822c..42cc30ce 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -14,6 +14,7 @@ * Boston, MA 021110-1307, USA. */ +#include #include #include #include @@ -785,31 +786,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; } @@ -820,24 +815,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[] = {