From a5dbd2064ef8a9b78eb0c2819b4d432623e1917d Mon Sep 17 00:00:00 2001 From: Anand Jain Date: Mon, 21 Mar 2016 15:21:01 +0800 Subject: btrfs-progs: move test_issubvolume() to utils.c Signed-off-by: Anand Jain Signed-off-by: David Sterba --- utils.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'utils.c') diff --git a/utils.c b/utils.c index 09962f8e..6dea54f2 100644 --- a/utils.c +++ b/utils.c @@ -3151,3 +3151,30 @@ int test_issubvolname(const char *name) return name[0] != '\0' && !strchr(name, '/') && strcmp(name, ".") && strcmp(name, ".."); } + +/* + * Test if path is a subvolume + * Returns: + * 0 - path exists but it is not a subvolume + * 1 - path exists and it is a subvolume + * < 0 - error + */ +int test_issubvolume(const char *path) +{ + struct stat st; + struct statfs stfs; + int res; + + res = stat(path, &st); + if (res < 0) + return -errno; + + 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; +} -- cgit v1.2.3