summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosef Bacik <josef@redhat.com>2009-12-11 21:12:07 +0000
committerChris Mason <chris.mason@oracle.com>2010-02-28 19:24:25 -0500
commit7b14bc0f4ffaf64be53b2ee531bb1774502d6a8f (patch)
tree1fb2c7e27b7aa3131e2af698318b6abab6b4a3af
parent4ff9e2af1721559ec6a8026f5d52a6c9dea805bf (diff)
Btrfs-progs: add command to set default subvol
This introduces a new btrfsctl option, -m, to allow you to set the default'ly mounted subvolume. You can do btrfsctl -m /your/subvolume and that will make that subvolume the subvolume that is mounted by default, or you can do btrfsctl -m <treeid> /any/subvolume and this will make the subvolume with tree id <treeid> the default'ly mounted subvolume. You can get the treeid by using the listing option. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
-rw-r--r--btrfsctl.c17
-rw-r--r--ioctl.h1
2 files changed, 18 insertions, 0 deletions
diff --git a/btrfsctl.c b/btrfsctl.c
index 66c4e89f..be6bf250 100644
--- a/btrfsctl.c
+++ b/btrfsctl.c
@@ -29,6 +29,7 @@
#include <unistd.h>
#include <dirent.h>
#include <libgen.h>
+#include <stdlib.h>
#include "kerncompat.h"
#include "ctree.h"
#include "transaction.h"
@@ -56,6 +57,8 @@ static void print_usage(void)
printf("\t-a: scans all devices for Btrfs filesystems\n");
printf("\t-c: forces a single FS sync\n");
printf("\t-D: delete snapshot\n");
+ printf("\t-m [tree id] directory: set the default mounted subvolume"
+ " to the [tree id] or the directory\n");
printf("%s\n", BTRFS_BUILD_VERSION);
exit(1);
}
@@ -101,6 +104,7 @@ int main(int ac, char **av)
unsigned long command = 0;
int len;
char *fullpath;
+ u64 objectid = 0;
if (ac == 2 && strcmp(av[1], "-a") == 0) {
fprintf(stderr, "Scanning for Btrfs filesystems\n");
@@ -191,6 +195,16 @@ int main(int ac, char **av)
command = BTRFS_IOC_RESIZE;
} else if (strcmp(av[i], "-c") == 0) {
command = BTRFS_IOC_SYNC;
+ } else if (strcmp(av[i], "-m") == 0) {
+ command = BTRFS_IOC_DEFAULT_SUBVOL;
+ if (i == ac - 3) {
+ objectid = (unsigned long long)
+ strtoll(av[i + 1], NULL, 0);
+ if (errno == ERANGE) {
+ fprintf(stderr, "invalid tree id\n");
+ exit(1);
+ }
+ }
}
}
if (command == 0) {
@@ -219,6 +233,9 @@ int main(int ac, char **av)
if (command == BTRFS_IOC_SNAP_CREATE) {
args.fd = fd;
ret = ioctl(snap_fd, command, &args);
+ } else if (command == BTRFS_IOC_DEFAULT_SUBVOL) {
+ printf("objectid is %llu\n", objectid);
+ ret = ioctl(fd, command, &objectid);
} else
ret = ioctl(fd, command, &args);
if (ret < 0) {
diff --git a/ioctl.h b/ioctl.h
index b0e5c0db..6a4a2d14 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -126,4 +126,5 @@ struct btrfs_ioctl_ino_lookup_args {
struct btrfs_ioctl_search_args)
#define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \
struct btrfs_ioctl_ino_lookup_args)
+#define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64)
#endif