forked from Mirrors/btrfs-progs
btrfs-progs: replace test_issubvolume() with btrfs_util_is_subvolume()
This gets the remaining occurrences that weren't covered by previous conversions. Signed-off-by: Omar Sandoval <osandov@fb.com> [ fixup test_issubvolume due to removed dependency patch ] Signed-off-by: David Sterba <dsterba@suse.com>master
parent
bbf7acbef0
commit
f0a376df47
|
@ -427,6 +427,7 @@ static int cmd_qgroup_limit(int argc, char **argv)
|
||||||
int compressed = 0;
|
int compressed = 0;
|
||||||
int exclusive = 0;
|
int exclusive = 0;
|
||||||
DIR *dirstream = NULL;
|
DIR *dirstream = NULL;
|
||||||
|
enum btrfs_util_error err;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int c = getopt(argc, argv, "ce");
|
int c = getopt(argc, argv, "ce");
|
||||||
|
@ -467,13 +468,9 @@ static int cmd_qgroup_limit(int argc, char **argv)
|
||||||
if (argc - optind == 2) {
|
if (argc - optind == 2) {
|
||||||
args.qgroupid = 0;
|
args.qgroupid = 0;
|
||||||
path = argv[optind + 1];
|
path = argv[optind + 1];
|
||||||
ret = test_issubvolume(path);
|
err = btrfs_util_is_subvolume(path);
|
||||||
if (ret < 0) {
|
if (err) {
|
||||||
error("cannot access '%s': %s", path, strerror(-ret));
|
error_btrfs_util(err);
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (!ret) {
|
|
||||||
error("'%s' is not a subvolume", path);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -630,6 +630,7 @@ static int cmd_subvol_snapshot(int argc, char **argv)
|
||||||
char *dupdir = NULL;
|
char *dupdir = NULL;
|
||||||
char *newname;
|
char *newname;
|
||||||
char *dstdir;
|
char *dstdir;
|
||||||
|
enum btrfs_util_error err;
|
||||||
struct btrfs_ioctl_vol_args_v2 args;
|
struct btrfs_ioctl_vol_args_v2 args;
|
||||||
struct btrfs_qgroup_inherit *inherit = NULL;
|
struct btrfs_qgroup_inherit *inherit = NULL;
|
||||||
DIR *dirstream1 = NULL, *dirstream2 = NULL;
|
DIR *dirstream1 = NULL, *dirstream2 = NULL;
|
||||||
|
@ -677,13 +678,9 @@ static int cmd_subvol_snapshot(int argc, char **argv)
|
||||||
dst = argv[optind + 1];
|
dst = argv[optind + 1];
|
||||||
|
|
||||||
retval = 1; /* failure */
|
retval = 1; /* failure */
|
||||||
res = test_issubvolume(subvol);
|
err = btrfs_util_is_subvolume(subvol);
|
||||||
if (res < 0) {
|
if (err) {
|
||||||
error("cannot access subvolume %s: %s", subvol, strerror(-res));
|
error_btrfs_util(err);
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
if (!res) {
|
|
||||||
error("not a subvolume: %s", subvol);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -886,13 +883,9 @@ static int cmd_subvol_find_new(int argc, char **argv)
|
||||||
subvol = argv[optind];
|
subvol = argv[optind];
|
||||||
last_gen = arg_strtou64(argv[optind + 1]);
|
last_gen = arg_strtou64(argv[optind + 1]);
|
||||||
|
|
||||||
ret = test_issubvolume(subvol);
|
err = btrfs_util_is_subvolume(subvol);
|
||||||
if (ret < 0) {
|
if (err) {
|
||||||
error("cannot access subvolume %s: %s", subvol, strerror(-ret));
|
error_btrfs_util(err);
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (!ret) {
|
|
||||||
error("not a subvolume: %s", subvol);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
34
utils.c
34
utils.c
|
@ -40,6 +40,8 @@
|
||||||
#include <linux/magic.h>
|
#include <linux/magic.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
|
#include <btrfsutil.h>
|
||||||
|
|
||||||
#include "kerncompat.h"
|
#include "kerncompat.h"
|
||||||
#include "radix-tree.h"
|
#include "radix-tree.h"
|
||||||
#include "ctree.h"
|
#include "ctree.h"
|
||||||
|
@ -1453,6 +1455,7 @@ u64 parse_qgroupid(const char *p)
|
||||||
char *s = strchr(p, '/');
|
char *s = strchr(p, '/');
|
||||||
const char *ptr_src_end = p + strlen(p);
|
const char *ptr_src_end = p + strlen(p);
|
||||||
char *ptr_parse_end = NULL;
|
char *ptr_parse_end = NULL;
|
||||||
|
enum btrfs_util_error err;
|
||||||
u64 level;
|
u64 level;
|
||||||
u64 id;
|
u64 id;
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -1480,8 +1483,8 @@ u64 parse_qgroupid(const char *p)
|
||||||
|
|
||||||
path:
|
path:
|
||||||
/* Path format like subv at 'my_subvol' is the fallback case */
|
/* Path format like subv at 'my_subvol' is the fallback case */
|
||||||
ret = test_issubvolume(p);
|
err = btrfs_util_is_subvolume(p);
|
||||||
if (ret < 0 || !ret)
|
if (err)
|
||||||
goto err;
|
goto err;
|
||||||
fd = open(p, O_RDONLY);
|
fd = open(p, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
@ -2451,33 +2454,6 @@ int test_issubvolname(const char *name)
|
||||||
strcmp(name, ".") && strcmp(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *subvol_strip_mountpoint(const char *mnt, const char *full_path)
|
const char *subvol_strip_mountpoint(const char *mnt, const char *full_path)
|
||||||
{
|
{
|
||||||
int len = strlen(mnt);
|
int len = strlen(mnt);
|
||||||
|
|
1
utils.h
1
utils.h
|
@ -149,7 +149,6 @@ u64 disk_size(const char *path);
|
||||||
u64 get_partition_size(const char *dev);
|
u64 get_partition_size(const char *dev);
|
||||||
|
|
||||||
int test_issubvolname(const char *name);
|
int test_issubvolname(const char *name);
|
||||||
int test_issubvolume(const char *path);
|
|
||||||
int test_isdir(const char *path);
|
int test_isdir(const char *path);
|
||||||
|
|
||||||
const char *subvol_strip_mountpoint(const char *mnt, const char *full_path);
|
const char *subvol_strip_mountpoint(const char *mnt, const char *full_path);
|
||||||
|
|
Loading…
Reference in New Issue