2 * Copyright (C) 2007 Oracle. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
21 #include <sys/ioctl.h>
22 #include <sys/mount.h>
28 #include <sys/types.h>
33 #include <uuid/uuid.h>
34 #include "kerncompat.h"
36 #include "transaction.h"
41 #define BLKGETSIZE64 0
42 #define BTRFS_IOC_SNAP_CREATE 0
43 #define BTRFS_IOC_ADD_DEV 0
44 #define BTRFS_IOC_RM_DEV 0
45 #define BTRFS_VOL_NAME_MAX 255
46 struct btrfs_ioctl_vol_args { char name[BTRFS_VOL_NAME_MAX]; };
47 static inline int ioctl(int fd, int define, void *arg) { return 0; }
50 static void print_usage(void)
52 fprintf(stderr, "usage: btrfs-vol [options] mount_point\n");
53 fprintf(stderr, "\t-a device add one device\n");
54 fprintf(stderr, "\t-b balance chunks across all devices\n");
55 fprintf(stderr, "\t-r device remove one device\n");
59 static struct option long_options[] = {
60 /* { "byte-count", 1, NULL, 'b' }, */
61 { "add", 1, NULL, 'a' },
62 { "balance", 0, NULL, 'b' },
63 { "remove", 1, NULL, 'r' },
67 int main(int ac, char **av)
78 struct btrfs_ioctl_vol_args args;
79 u64 dev_block_count = 0;
83 c = getopt_long(ac, av, "a:br:", long_options,
89 device = strdup(optarg);
90 cmd = BTRFS_IOC_ADD_DEV;
93 cmd = BTRFS_IOC_BALANCE;
96 device = strdup(optarg);
97 cmd = BTRFS_IOC_RM_DEV;
108 if (device && strcmp(device, "missing") == 0 &&
109 cmd == BTRFS_IOC_RM_DEV) {
110 fprintf(stderr, "removing missing devices from %s\n", mnt);
111 } else if (cmd != BTRFS_IOC_BALANCE) {
112 if (cmd == BTRFS_IOC_ADD_DEV) {
113 ret = check_mounted(device);
116 "error checking %s mount status\n",
121 fprintf(stderr, "%s is mounted\n", device);
125 devfd = open(device, O_RDWR);
127 fprintf(stderr, "Unable to open device %s\n", device);
130 ret = fstat(devfd, &st);
132 fprintf(stderr, "Unable to stat %s\n", device);
135 if (!S_ISBLK(st.st_mode)) {
136 fprintf(stderr, "%s is not a block device\n", device);
140 dirstream = opendir(mnt);
142 fprintf(stderr, "Unable to open directory %s\n", mnt);
145 if (cmd == BTRFS_IOC_ADD_DEV) {
146 ret = btrfs_prepare_device(devfd, device, 1, &dev_block_count);
148 fprintf(stderr, "Unable to init %s\n", device);
152 fd = dirfd(dirstream);
154 strcpy(args.name, device);
158 ret = ioctl(fd, cmd, &args);
159 printf("ioctl returns %d\n", ret);