summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2014-07-23 13:47:35 +0800
committerDavid Sterba <dsterba@suse.cz>2014-08-22 15:07:02 +0200
commitde22c28ef31d9721606ba05965a093a8044be0de (patch)
tree2c5e2c942d927463160bf8c2b46e1c76d548d7be
parent10c8f34f519451d763ae6b40bd388d11f4d3d42f (diff)
btrfs-progs: Check fstype in find_mount_root()
When calling find_mount_root(), caller in fact wants to find the mount point of *BTRFS*. So also check ent->fstype in find_mount_root() and do special error string output in caller. This will suppress a lot of "Inapproiate ioctl for device" error message. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
-rw-r--r--cmds-receive.c7
-rw-r--r--cmds-send.c14
-rw-r--r--cmds-subvolume.c7
-rw-r--r--utils.c11
4 files changed, 39 insertions, 0 deletions
diff --git a/cmds-receive.c b/cmds-receive.c
index 20b3db09..03d21e90 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -848,6 +848,13 @@ static int do_receive(struct btrfs_receive *r, const char *tomnt, int r_fd,
ret = -EINVAL;
goto out;
}
+ if (ret > 0) {
+ fprintf(stderr,
+ "ERROR: %s doesn't belong to btrfs mount point\n",
+ dest_dir_full_path);
+ ret = -EINVAL;
+ goto out;
+ }
r->mnt_fd = open(r->root_path, O_RDONLY | O_NOATIME);
if (r->mnt_fd < 0) {
ret = -errno;
diff --git a/cmds-send.c b/cmds-send.c
index 9ec52dcd..7141c073 100644
--- a/cmds-send.c
+++ b/cmds-send.c
@@ -355,6 +355,13 @@ static int init_root_path(struct btrfs_send *s, const char *subvol)
ret = -EINVAL;
goto out;
}
+ if (ret > 0) {
+ fprintf(stderr,
+ "ERROR: %s doesn't belong to btrfs mount point\n",
+ subvol);
+ ret = -EINVAL;
+ goto out;
+ }
s->mnt_fd = open(s->root_path, O_RDONLY | O_NOATIME);
if (s->mnt_fd < 0) {
@@ -587,6 +594,13 @@ int cmd_send(int argc, char **argv)
strerror(-ret));
goto out;
}
+ if (ret > 0) {
+ fprintf(stderr,
+ "ERROR: %s doesn't belong to btrfs mount point\n",
+ subvol);
+ ret = -EINVAL;
+ goto out;
+ }
if (strcmp(send.root_path, mount_root) != 0) {
ret = -EINVAL;
fprintf(stderr, "ERROR: all subvols must be from the "
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index 5e821c71..9ab5287b 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -933,6 +933,13 @@ static int cmd_subvol_show(int argc, char **argv)
"%s\n", fullpath, strerror(-ret));
goto out;
}
+ if (ret > 0) {
+ fprintf(stderr,
+ "ERROR: %s doesn't belong to btrfs mount point\n",
+ fullpath);
+ ret = -EINVAL;
+ goto out;
+ }
ret = 1;
svpath = get_subvol_name(mnt, fullpath);
diff --git a/utils.c b/utils.c
index 3d467c56..73fcd15f 100644
--- a/utils.c
+++ b/utils.c
@@ -2324,6 +2324,11 @@ int lookup_ino_rootid(int fd, u64 *rootid)
return 0;
}
+/*
+ * return 0 if a btrfs mount point is found
+ * return 1 if a mount point is found but not btrfs
+ * return <0 if something goes wrong
+ */
int find_mount_root(const char *path, char **mount_root)
{
FILE *mnttab;
@@ -2331,6 +2336,7 @@ int find_mount_root(const char *path, char **mount_root)
struct mntent *ent;
int len;
int ret;
+ int not_btrfs = 1;
int longest_matchlen = 0;
char *longest_match = NULL;
@@ -2351,6 +2357,7 @@ int find_mount_root(const char *path, char **mount_root)
free(longest_match);
longest_matchlen = len;
longest_match = strdup(ent->mnt_dir);
+ not_btrfs = strcmp(ent->mnt_type, "btrfs");
}
}
}
@@ -2358,6 +2365,10 @@ int find_mount_root(const char *path, char **mount_root)
if (!longest_match)
return -ENOENT;
+ if (not_btrfs) {
+ free(longest_match);
+ return 1;
+ }
ret = 0;
*mount_root = realpath(longest_match, NULL);