From: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
To: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Cc: naota <naota@elisp.net>
Subject: [PATCH 2/2] btrfs-progs: fix the file system root is regarded as non-root
Date: Thu, 18 Dec 2014 15:42:45 +0900 [thread overview]
Message-ID: <54927765.6060207@jp.fujitsu.com> (raw)
In-Reply-To: <54926FB4.6050604@jp.fujitsu.com>
From: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
When "/" is Btrfs, "btrfs property <subcommand> /" 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 <takeuchi_satoru@jp.fujitsu.com>
Reported-by: Naohiro Aota <naota@elisp.net>
---
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;
}
--
1.9.3
next prev parent reply other threads:[~2014-12-18 6:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-18 6:09 [PATCH 1/2] Fix wrong memory free on check_is_root Satoru Takeuchi
2014-12-18 6:42 ` Satoru Takeuchi [this message]
2014-12-18 7:09 ` [PATCH 2/2] btrfs-progs: fix the file system root is regarded as non-root Gui Hecheng
2014-12-18 7:19 ` Satoru Takeuchi
2014-12-18 7:03 ` [PATCH 1/2] Fix wrong memory free on check_is_root Gui Hecheng
2014-12-18 7:16 ` Satoru Takeuchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54927765.6060207@jp.fujitsu.com \
--to=takeuchi_satoru@jp.fujitsu.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=naota@elisp.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.