summaryrefslogtreecommitdiff
path: root/btrfsctl.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-04-10 09:27:30 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-04-10 09:27:30 -0400
commit43f6ab83bf23a9833355b9970ddc600e445f2805 (patch)
treef3c41a277030912d24e4cbad31e44035af22865c /btrfsctl.c
parent86c2d787286b888a7f45ee522310f773b8466917 (diff)
btrfsctl
Diffstat (limited to 'btrfsctl.c')
-rw-r--r--btrfsctl.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/btrfsctl.c b/btrfsctl.c
new file mode 100644
index 00000000..cab846b0
--- /dev/null
+++ b/btrfsctl.c
@@ -0,0 +1,62 @@
+#ifndef __CHECKER__
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include "ioctl.h"
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include "kerncompat.h"
+
+#ifdef __CHECKER__
+#define BLKGETSIZE64 0
+#define BTRFS_IOC_SNAP_CREATE 0
+#define BTRFS_VOL_NAME_MAX 255
+struct btrfs_ioctl_vol_args { char name[BTRFS_VOL_NAME_MAX]; };
+static inline int ioctl(int fd, int define, void *arg) { return 0; }
+#endif
+
+void print_usage(void)
+{
+ printf("usage: btrfsctl [ -s snapshot_name ] dir\n");
+ exit(1);
+}
+
+int main(int ac, char **av)
+{
+ char *fname;
+ int fd;
+ int ret;
+ struct btrfs_ioctl_vol_args args;
+ char *name;
+ int i;
+
+ for (i = 1; i < ac - 1; i++) {
+ if (strcmp(av[i], "-s") == 0) {
+ if (i + 1 >= ac - 1) {
+ fprintf(stderr, "-s requires an arg");
+ print_usage();
+ }
+ name = av[i + 1];
+ if (strlen(name) >= BTRFS_VOL_NAME_MAX) {
+ fprintf(stderr, "snapshot name is too long\n");
+ exit(1);
+ }
+ }
+ }
+ fname = av[ac - 1];
+printf("fname is %s\n", fname);
+ fd = open(fname, O_RDWR);
+ if (fd < 0) {
+ perror("open");
+ exit(1);
+ }
+ strcpy(args.name, name);
+ ret = ioctl(fd, BTRFS_IOC_SNAP_CREATE, &args);
+ printf("ioctl returns %d\n", ret);
+ return 0;
+}
+