From patchwork Tue Oct 29 16:34:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 3109371 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 53D76BF924 for ; Tue, 29 Oct 2013 16:26:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3E525200FF for ; Tue, 29 Oct 2013 16:26:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 06941200D5 for ; Tue, 29 Oct 2013 16:26:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758382Ab3J2Q0h (ORCPT ); Tue, 29 Oct 2013 12:26:37 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:37086 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751723Ab3J2Q0g (ORCPT ); Tue, 29 Oct 2013 12:26:36 -0400 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r9TGQZpG010809 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 29 Oct 2013 16:26:36 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r9TGQYCK022881 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 29 Oct 2013 16:26:35 GMT Received: from abhmt110.oracle.com (abhmt110.oracle.com [141.146.116.62]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r9TGQYm7022877 for ; Tue, 29 Oct 2013 16:26:34 GMT Received: from wish.sg.oracle.com (/10.186.101.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 29 Oct 2013 09:26:34 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH] btrfs-progs: lblkid wouldn't find non mapper path input Date: Wed, 30 Oct 2013 00:34:50 +0800 Message-Id: <1383064490-28875-1-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 1.8.1.164.g2d0029e X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A new test case when disk is unmounted and if the non mapper disk path is given as the argument to the btrfs filesystem show we still need this to work but lblkid will pull only mapper disks, it won't match. So this will normalize the input to find btrfs by fsid and pass it to the search. Signed-off-by: Anand Jain --- cmds-filesystem.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 49 insertions(+), 3 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index fcabdb0..3a494fd 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -37,6 +37,7 @@ #include "version.h" #include "commands.h" #include "list_sort.h" +#include "disk-io.h" static const char * const filesystem_cmd_group_usage[] = { "btrfs filesystem [] []", @@ -414,6 +415,39 @@ static int btrfs_scan_kernel(void *search) return 0; } +static int dev_to_fsid(char *dev, __u8 *fsid) +{ + struct btrfs_super_block *disk_super; + char *buf; + int ret; + int fd; + + buf = malloc(4096); + if (!buf) + return -ENOMEM; + + fd = open(dev, O_RDONLY); + if (fd < 0) { + ret = -errno; + free(buf); + return ret; + } + + disk_super = (struct btrfs_super_block *)buf; + ret = btrfs_read_dev_super(fd, disk_super, + BTRFS_SUPER_INFO_OFFSET); + if (ret) + goto out; + + memcpy(fsid, disk_super->fsid, BTRFS_FSID_SIZE); + ret = 0; + +out: + close(fd); + free(buf); + return ret; +} + static const char * const cmd_show_usage[] = { "btrfs filesystem show [options] [|||label]", "Show the structure of a filesystem", @@ -434,6 +468,8 @@ static int cmd_show(int argc, char **argv) int type = 0; char mp[BTRFS_PATH_NAME_MAX + 1]; char path[PATH_MAX]; + __u8 fsid[BTRFS_FSID_SIZE]; + char uuid_buf[37]; while (1) { int long_index; @@ -480,11 +516,21 @@ static int cmd_show(int argc, char **argv) if (!ret) /* given block dev is mounted*/ search = mp; - else + else { + ret = dev_to_fsid(search, fsid); + if (ret) { + fprintf(stderr, + "ERROR: No btrfs on %s\n", + search); + return 1; + } + uuid_unparse(fsid, uuid_buf); + search = uuid_buf; + type = BTRFS_ARG_UUID; goto devs_only; + } } - } - if (type == BTRFS_ARG_MNTPOINT) { + } else if (type == BTRFS_ARG_MNTPOINT) { char label[BTRFS_LABEL_SIZE]; if (get_label_mounted(search, label)) return 1;