From: Filipe David Borba Manana <fdmanana@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Filipe David Borba Manana <fdmanana@gmail.com>
Subject: [PATCH 3/5] Btrfs-progs: fix detection of root objects in cmds-property.c
Date: Tue, 12 Nov 2013 13:41:44 +0000 [thread overview]
Message-ID: <1384263706-25549-4-git-send-email-fdmanana@gmail.com> (raw)
In-Reply-To: <1384263706-25549-1-git-send-email-fdmanana@gmail.com>
Several fixes:
1) The function check_is_root() returns 0 if the object is root;
2) Don't treat any error from get fsid ioctl as meaning the target
is root. Only -ENOTTY means it's a root (parent directory is
not a btrfs fs) and a -ENOTDIR means our target object is not a
directory, therefore it can be the root;
3) Fix the comparison of the target and target's parent fs ids. If
they are different, it means the target is a mount point in a
btrfs fs, therefore it's a root, otherwise it isn't.
Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
---
cmds-property.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/cmds-property.c b/cmds-property.c
index 6699e61..3d1f18c 100644
--- a/cmds-property.c
+++ b/cmds-property.c
@@ -75,7 +75,7 @@ static int parse_prop(const char *arg, const struct prop_handler *props,
return -1;
}
-static int get_fsid(const char *path, u8 *fsid)
+static int get_fsid(const char *path, u8 *fsid, int silent)
{
int ret;
int fd;
@@ -84,7 +84,8 @@ static int get_fsid(const char *path, u8 *fsid)
fd = open(path, O_RDONLY);
if (fd < 0) {
ret = -errno;
- fprintf(stderr, "ERROR: open %s failed. %s\n", path,
+ if (!silent)
+ fprintf(stderr, "ERROR: open %s failed. %s\n", path,
strerror(-ret));
goto out;
}
@@ -109,7 +110,7 @@ static int check_btrfs_object(const char *object)
int ret;
u8 fsid[BTRFS_FSID_SIZE];
- ret = get_fsid(object, fsid);
+ ret = get_fsid(object, fsid, 0);
if (ret < 0)
ret = 0;
else
@@ -134,20 +135,27 @@ static int check_is_root(const char *object)
strcat(tmp, "/");
strcat(tmp, "..");
- ret = get_fsid(object, fsid);
+ ret = get_fsid(object, fsid, 0);
if (ret < 0) {
fprintf(stderr, "ERROR: get_fsid for %s failed. %s\n", object,
strerror(-ret));
goto out;
}
- ret = get_fsid(tmp, fsid2);
- if (ret < 0) {
+ ret = get_fsid(tmp, fsid2, 1);
+ if (ret == -ENOTTY) {
ret = 0;
goto out;
+ } else if (ret == -ENOTDIR) {
+ ret = 1;
+ goto out;
+ } else if (ret < 0) {
+ fprintf(stderr, "ERROR: get_fsid for %s failed. %s\n", tmp,
+ strerror(-ret));
+ goto out;
}
- if (!memcmp(fsid, fsid2, BTRFS_FSID_SIZE)) {
+ if (memcmp(fsid, fsid2, BTRFS_FSID_SIZE)) {
ret = 0;
goto out;
}
@@ -195,7 +203,7 @@ static int autodetect_object_types(const char *object, int *types_out)
ret = check_is_root(object);
if (ret < 0)
goto out;
- if (ret)
+ if (!ret)
types |= prop_object_root;
}
--
1.7.9.5
next prev parent reply other threads:[~2013-11-12 13:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-12 13:41 [PATCH 0/5] Add support for object properties Filipe David Borba Manana
2013-11-12 13:41 ` [PATCH 1/5] Btrfs-progs: let get_label return the label instead of printing it Filipe David Borba Manana
2013-11-13 15:43 ` David Sterba
2013-11-12 13:41 ` [PATCH 2/5] Btrfs-progs: introduce btrfs property subgroup Filipe David Borba Manana
2013-11-12 13:41 ` Filipe David Borba Manana [this message]
2013-11-12 13:41 ` [PATCH 4/5] Btrfs-progs: add type root to label property Filipe David Borba Manana
2013-11-12 13:41 ` [PATCH 5/5] Btrfs-progs: add support for the compression property Filipe David Borba Manana
2013-11-13 1:22 ` [PATCH 5/5 V2] " Filipe David Borba Manana
2013-11-13 16:15 ` [PATCH 0/5] Add support for object properties David Sterba
2013-11-23 0:52 ` David Sterba
2013-11-23 10:45 ` Goffredo Baroncelli
2014-01-07 11:51 ` Filipe David Manana
2014-01-23 17:47 ` David Sterba
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=1384263706-25549-4-git-send-email-fdmanana@gmail.com \
--to=fdmanana@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).