summaryrefslogtreecommitdiff
path: root/cmds-subvolume.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2016-01-13 18:44:59 +0100
committerDavid Sterba <dsterba@suse.com>2016-01-14 11:07:10 +0100
commit7faf96e30aacf927ac18c5a1e5c50921f0ae5eee (patch)
tree2e05e66031858733f2ab226ae1155b1161326949 /cmds-subvolume.c
parentdddc3e08cbf87c1ab06f4fa55a108e538db42f8b (diff)
btrfs-progs: also check filesystem type in test_issubvolume
A subvolume is a directory with inode number 256 on a btrfs filesytem. Add the missing check to test_issubvolume for completeness, otherwise we always do that in btrfs_open_dir. Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-subvolume.c')
-rw-r--r--cmds-subvolume.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index d5ec886..95c23d0 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -21,10 +21,12 @@
#include <sys/ioctl.h>
#include <errno.h>
#include <sys/stat.h>
+#include <sys/vfs.h>
#include <libgen.h>
#include <limits.h>
#include <getopt.h>
#include <uuid/uuid.h>
+#include <linux/magic.h>
#include "kerncompat.h"
#include "ioctl.h"
@@ -232,14 +234,21 @@ out:
int test_issubvolume(const char *path)
{
struct stat st;
+ struct statfs stfs;
int res;
res = stat(path, &st);
if (res < 0)
return -errno;
- return (st.st_ino == BTRFS_FIRST_FREE_OBJECTID)
- && S_ISDIR(st.st_mode);
+ if (st.st_ino != BTRFS_FIRST_FREE_OBJECTID || !S_ISDIR(st.st_mode))
+ return 0;
+
+ res = statfs(path, &stfs);
+ if (res < 0)
+ return -errno;
+
+ return (int)stfs.f_type == BTRFS_SUPER_MAGIC;
}
static int wait_for_commit(int fd)