#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"
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)
u64 default_id;
DIR *dirstream = NULL;
- if (check_argc_exact(argc, 2))
+ clean_args_no_options(argc, argv, cmd_subvol_get_default_usage);
+
+ if (check_argc_exact(argc - optind, 2))
usage(cmd_subvol_get_default_usage);
subvol = argv[1];
char *subvolid;
DIR *dirstream = NULL;
- if (check_argc_exact(argc, 3))
+ clean_args_no_options(argc, argv, cmd_subvol_set_default_usage);
+
+ if (check_argc_exact(argc - optind, 2))
usage(cmd_subvol_set_default_usage);
- subvolid = argv[1];
- path = argv[2];
+ subvolid = argv[optind];
+ path = argv[optind + 1];
objectid = arg_strtou64(subvolid);
u64 last_gen;
DIR *dirstream = NULL;
- if (check_argc_exact(argc, 3))
+ clean_args_no_options(argc, argv, cmd_subvol_find_new_usage);
+
+ if (check_argc_exact(argc - optind, 2))
usage(cmd_subvol_find_new_usage);
- subvol = argv[1];
- last_gen = arg_strtou64(argv[2]);
+ subvol = argv[optind];
+ last_gen = arg_strtou64(argv[optind + 1]);
ret = test_issubvolume(subvol);
if (ret < 0) {
int ret = 1;
DIR *dirstream1 = NULL, *dirstream2 = NULL;
- while (1) {
- static const struct option long_options[] = {
- {NULL, 0, NULL, 0}
- };
- int c = getopt_long(argc, argv, "", long_options, NULL);
-
- if (c < 0)
- break;
-
- switch (c) {
- default:
- usage(cmd_subvol_show_usage);
- }
- }
+ clean_args_no_options(argc, argv, cmd_subvol_show_usage);
if (check_argc_exact(argc - optind, 1))
usage(cmd_subvol_show_usage);