2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public
4 * License v2 as published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 * General Public License for more details.
11 * You should have received a copy of the GNU General Public
12 * License along with this program; if not, write to the
13 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14 * Boston, MA 021110-1307, USA.
22 #include <sys/ioctl.h>
26 #include "kerncompat.h"
31 #include "btrfs_cmds.h"
33 /* FIXME - imported cruft, fix sparse errors and warnings */
35 #define BLKGETSIZE64 0
36 #define BTRFS_IOC_SNAP_CREATE_V2 0
37 #define BTRFS_VOL_NAME_MAX 255
38 struct btrfs_ioctl_vol_args { char name[BTRFS_VOL_NAME_MAX]; };
39 static inline int ioctl(int fd, int define, void *arg) { return 0; }
42 int do_add_volume(int nargs, char **args)
45 char *mntpnt = args[nargs-1];
46 int i, fdmnt, ret=0, e;
49 fdmnt = open_file_or_dir(mntpnt);
51 fprintf(stderr, "ERROR: can't access to '%s'\n", mntpnt);
55 for (i = 1; i < (nargs-1); i++ ){
56 struct btrfs_ioctl_vol_args ioctl_args;
58 u64 dev_block_count = 0;
62 res = check_mounted(args[i]);
64 fprintf(stderr, "error checking %s mount status\n",
70 fprintf(stderr, "%s is mounted\n", args[i]);
75 devfd = open(args[i], O_RDWR);
77 fprintf(stderr, "ERROR: Unable to open device '%s'\n", args[i]);
82 res = fstat(devfd, &st);
84 fprintf(stderr, "ERROR: Unable to stat '%s'\n", args[i]);
89 if (!S_ISBLK(st.st_mode)) {
90 fprintf(stderr, "ERROR: '%s' is not a block device\n", args[i]);
96 res = btrfs_prepare_device(devfd, args[i], 1, &dev_block_count, &mixed);
98 fprintf(stderr, "ERROR: Unable to init '%s'\n", args[i]);
105 strncpy(ioctl_args.name, args[i], BTRFS_PATH_NAME_MAX);
106 res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
109 fprintf(stderr, "ERROR: error adding the device '%s' - %s\n",
110 args[i], strerror(e));
124 int do_remove_volume(int nargs, char **args)
127 char *mntpnt = args[nargs-1];
128 int i, fdmnt, ret=0, e;
130 fdmnt = open_file_or_dir(mntpnt);
132 fprintf(stderr, "ERROR: can't access to '%s'\n", mntpnt);
136 for(i=1 ; i < (nargs-1) ; i++ ){
137 struct btrfs_ioctl_vol_args arg;
140 strncpy(arg.name, args[i], BTRFS_PATH_NAME_MAX);
141 res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
144 fprintf(stderr, "ERROR: error removing the device '%s' - %s\n",
145 args[i], strerror(e));
157 int do_scan(int argc, char **argv)
163 if( argc >= 2 && !strcmp(argv[1],"--all-devices")){
166 fprintf(stderr, "ERROR: too may arguments\n");
178 printf("Scanning for Btrfs filesystems\n");
180 ret = btrfs_scan_block_devices(1);
182 ret = btrfs_scan_one_dir("/dev", 1);
184 fprintf(stderr, "ERROR: error %d while scanning\n", ret);
190 fd = open("/dev/btrfs-control", O_RDWR);
192 perror("failed to open /dev/btrfs-control");
196 for( i = devstart ; i < argc ; i++ ){
197 struct btrfs_ioctl_vol_args args;
200 printf("Scanning for Btrfs filesystems in '%s'\n", argv[i]);
202 strncpy(args.name, argv[i], BTRFS_PATH_NAME_MAX);
204 * FIXME: which are the error code returned by this ioctl ?
205 * it seems that is impossible to understand if there no is
206 * a btrfs filesystem from an I/O error !!!
208 ret = ioctl(fd, BTRFS_IOC_SCAN_DEV, &args);
213 fprintf(stderr, "ERROR: unable to scan the device '%s' - %s\n",
214 argv[i], strerror(e));