From patchwork Thu Dec 18 06:42:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satoru Takeuchi X-Patchwork-Id: 5510841 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 5CE97BEEA8 for ; Thu, 18 Dec 2014 06:43:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7870D209CD for ; Thu, 18 Dec 2014 06:43:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0C76C209C7 for ; Thu, 18 Dec 2014 06:43:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751637AbaLRGnE (ORCPT ); Thu, 18 Dec 2014 01:43:04 -0500 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:35459 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751323AbaLRGnC (ORCPT ); Thu, 18 Dec 2014 01:43:02 -0500 Received: from kw-mxauth.gw.nic.fujitsu.com (unknown [10.0.237.134]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id D866E3EE0AE for ; Thu, 18 Dec 2014 15:43:00 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by kw-mxauth.gw.nic.fujitsu.com (Postfix) with ESMTP id D553BAC07FF for ; Thu, 18 Dec 2014 15:42:59 +0900 (JST) Received: from g01jpfmpwyt02.exch.g01.fujitsu.local (g01jpfmpwyt02.exch.g01.fujitsu.local [10.128.193.56]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id D54BCE08002 for ; Thu, 18 Dec 2014 15:42:58 +0900 (JST) Received: from G01JPEXCHYT15.g01.fujitsu.local (G01JPEXCHYT15.g01.fujitsu.local [10.128.194.54]) by g01jpfmpwyt02.exch.g01.fujitsu.local (Postfix) with ESMTP id D1D0D5842CD; Thu, 18 Dec 2014 15:42:57 +0900 (JST) X-SecurityPolicyCheck: OK by SHieldMailChecker v2.0.1 X-SHieldMailCheckerPolicyVersion: FJ-ISEC-20120718-4 Message-ID: <54927765.6060207@jp.fujitsu.com> Date: Thu, 18 Dec 2014 15:42:45 +0900 From: Satoru Takeuchi User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: "linux-btrfs@vger.kernel.org" CC: naota Subject: [PATCH 2/2] btrfs-progs: fix the file system root is regarded as non-root References: <54926FB4.6050604@jp.fujitsu.com> In-Reply-To: <54926FB4.6050604@jp.fujitsu.com> X-SecurityPolicyCheck-GC: OK by FENCE-Mail Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 From: Satoru Takeuchi When "/" is Btrfs, "btrfs property /" regards it as non-root by mistake. check_is_root() regards @object as a file system root if the following two conditions are satisfied. a) Both @object and its parent directory are Btrfs object (file system root, subvolume, inode, and device used for Btrfs). b) fsid of the above mentioned two objects are different. It doesn't work if @object is "/" because, in this case, fsid of "/" and its parent (it's also "/"), are the same. * Test environment Two Btrfs file system (not subvolume) "/" and "/home/sat/mnt". * How to reproduce Submit "btrfs prop get" against the above mentioned file systems. * Test Result ** Actual result (without my patch) ========================== # btrfs prop get /home/sat/mnt/ ro=false label= # label is displayed because it's a file system root # btrfs prop get / ro=false # label is not displayed even if it's a file system root ========================== ** Expected result (with my patch) ========================== # ./btrfs-new prop get btrfs-auto-test/ # ./btrfs-new prop get /home/sat/mnt/ ro=false label= # ./btrfs-new prop get / ro=false label=foo # label is displayed =========================== Signed-off-by: Satoru Takeuchi Reported-by: Naohiro Aota --- cmds-property.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmds-property.c b/cmds-property.c index a4bc127..640af99 100644 --- a/cmds-property.c +++ b/cmds-property.c @@ -125,11 +125,22 @@ static int check_is_root(const char *object) u8 fsid[BTRFS_FSID_SIZE]; u8 fsid2[BTRFS_FSID_SIZE]; char *tmp; + char *rp; + + rp = realpath(object, NULL); + if (!rp) { + ret = -ENOMEM; + goto out; + } + if (!strcmp(rp, "/")) { + ret = 0; + goto free_rp_out; + } tmp = malloc(strlen(object) + 5); if (!tmp) { ret = -ENOMEM; - goto out; + goto free_rp_out; } strcpy(tmp, object); if (tmp[strlen(tmp) - 1] != '/') @@ -165,6 +176,8 @@ static int check_is_root(const char *object) free_tmp_out: free(tmp); +free_rp_out: + free(rp); out: return ret; }