btrfs-progs: also check filesystem type in test_issubvolume
authorDavid Sterba <dsterba@suse.com>
Wed, 13 Jan 2016 17:44:59 +0000 (18:44 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 14 Jan 2016 10:07:10 +0000 (11:07 +0100)
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>
cmds-subvolume.c

index d5ec886..95c23d0 100644 (file)
 #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)