btrfs-debug-tree: add -d option to print only the device mapping
[btrfs-progs-unstable.git] / btrfs_cmds.c
blob8031c589d6bf1465958eaae39cf22d5fe1c1cb92
1 /*
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.
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <sys/ioctl.h>
22 #include <sys/types.h>
23 #include <dirent.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <libgen.h>
28 #include <limits.h>
29 #include <uuid/uuid.h>
30 #include <ctype.h>
32 #undef ULONG_MAX
34 #include "kerncompat.h"
35 #include "ctree.h"
36 #include "transaction.h"
37 #include "utils.h"
38 #include "version.h"
39 #include "ioctl.h"
40 #include "volumes.h"
42 #include "btrfs_cmds.h"
44 #ifdef __CHECKER__
45 #define BLKGETSIZE64 0
46 #define BTRFS_IOC_SNAP_CREATE 0
47 #define BTRFS_VOL_NAME_MAX 255
48 struct btrfs_ioctl_vol_args { char name[BTRFS_VOL_NAME_MAX]; };
49 static inline int ioctl(int fd, int define, void *arg) { return 0; }
50 #endif
53 * test if path is a subvolume:
54 * this function return
55 * 0-> path exists but it is not a subvolume
56 * 1-> path exists and it is a subvolume
57 * -1 -> path is unaccessible
59 static int test_issubvolume(char *path)
62 struct stat st;
63 int res;
65 res = stat(path, &st);
66 if(res < 0 )
67 return -1;
69 return (st.st_ino == 256) && S_ISDIR(st.st_mode);
74 * test if path is a directory
75 * this function return
76 * 0-> path exists but it is not a directory
77 * 1-> path exists and it is a directory
78 * -1 -> path is unaccessible
80 static int test_isdir(char *path)
82 struct stat st;
83 int res;
85 res = stat(path, &st);
86 if(res < 0 )
87 return -1;
89 return S_ISDIR(st.st_mode);
93 static int open_file_or_dir(const char *fname)
95 int ret;
96 struct stat st;
97 DIR *dirstream;
98 int fd;
100 ret = stat(fname, &st);
101 if (ret < 0) {
102 return -1;
104 if (S_ISDIR(st.st_mode)) {
105 dirstream = opendir(fname);
106 if (!dirstream) {
107 return -2;
109 fd = dirfd(dirstream);
110 } else {
111 fd = open(fname, O_RDWR);
113 if (fd < 0) {
114 return -3;
116 return fd;
119 static u64 parse_size(char *s)
121 int len = strlen(s);
122 char c;
123 u64 mult = 1;
125 if (!isdigit(s[len - 1])) {
126 c = tolower(s[len - 1]);
127 switch (c) {
128 case 'g':
129 mult *= 1024;
130 case 'm':
131 mult *= 1024;
132 case 'k':
133 mult *= 1024;
134 case 'b':
135 break;
136 default:
137 fprintf(stderr, "Unknown size descriptor %c\n", c);
138 exit(1);
140 s[len - 1] = '\0';
142 return atoll(s) * mult;
145 int do_defrag(int ac, char **av)
147 int fd;
148 int compress = 0;
149 int flush = 0;
150 u64 start = 0;
151 u64 len = (u64)-1;
152 u32 thresh = 0;
153 int i;
154 int errors = 0;
155 int ret = 0;
156 int verbose = 0;
157 int fancy_ioctl = 0;
158 struct btrfs_ioctl_defrag_range_args range;
160 optind = 1;
161 while(1) {
162 int c = getopt(ac, av, "vcfs:l:t:");
163 if (c < 0)
164 break;
165 switch(c) {
166 case 'c':
167 compress = 1;
168 fancy_ioctl = 1;
169 break;
170 case 'f':
171 flush = 1;
172 fancy_ioctl = 1;
173 break;
174 case 'v':
175 verbose = 1;
176 break;
177 case 's':
178 start = parse_size(optarg);
179 fancy_ioctl = 1;
180 break;
181 case 'l':
182 len = parse_size(optarg);
183 fancy_ioctl = 1;
184 break;
185 case 't':
186 thresh = parse_size(optarg);
187 fancy_ioctl = 1;
188 break;
189 default:
190 fprintf(stderr, "Invalid arguments for defragment\n");
191 free(av);
192 return 1;
195 if (ac - optind == 0) {
196 fprintf(stderr, "Invalid arguments for defragment\n");
197 free(av);
198 return 1;
201 memset(&range, 0, sizeof(range));
202 range.start = start;
203 range.len = len;
204 range.extent_thresh = thresh;
205 if (compress)
206 range.flags |= BTRFS_DEFRAG_RANGE_COMPRESS;
207 if (flush)
208 range.flags |= BTRFS_DEFRAG_RANGE_START_IO;
210 for (i = optind; i < ac; i++) {
211 if (verbose)
212 printf("%s\n", av[i]);
213 fd = open_file_or_dir(av[i]);
214 if (fd < 0) {
215 fprintf(stderr, "failed to open %s\n", av[i]);
216 perror("open:");
217 errors++;
218 continue;
220 if (!fancy_ioctl) {
221 ret = ioctl(fd, BTRFS_IOC_DEFRAG, NULL);
222 } else {
223 ret = ioctl(fd, BTRFS_IOC_DEFRAG_RANGE, &range);
224 if (ret && errno == ENOTTY) {
225 fprintf(stderr, "defrag range ioctl not "
226 "supported in this kernel, please try "
227 "without any options.\n");
228 errors++;
229 break;
232 if (ret) {
233 fprintf(stderr, "ioctl failed on %s ret %d errno %d\n",
234 av[i], ret, errno);
235 errors++;
237 close(fd);
239 if (verbose)
240 printf("%s\n", BTRFS_BUILD_VERSION);
241 if (errors) {
242 fprintf(stderr, "total %d failures\n", errors);
243 exit(1);
246 free(av);
247 return errors + 20;
250 int do_find_newer(int argc, char **argv)
252 int fd;
253 int ret;
254 char *subvol;
255 u64 last_gen;
257 subvol = argv[1];
258 last_gen = atoll(argv[2]);
260 ret = test_issubvolume(subvol);
261 if (ret < 0) {
262 fprintf(stderr, "ERROR: error accessing '%s'\n", subvol);
263 return 12;
265 if (!ret) {
266 fprintf(stderr, "ERROR: '%s' is not a subvolume\n", subvol);
267 return 13;
270 fd = open_file_or_dir(subvol);
271 if (fd < 0) {
272 fprintf(stderr, "ERROR: can't access '%s'\n", subvol);
273 return 12;
275 ret = find_updated_files(fd, 0, last_gen);
276 if (ret)
277 return 19;
278 return 0;
281 int do_subvol_list(int argc, char **argv)
283 int fd;
284 int ret;
285 char *subvol;
287 subvol = argv[1];
289 ret = test_issubvolume(subvol);
290 if (ret < 0) {
291 fprintf(stderr, "ERROR: error accessing '%s'\n", subvol);
292 return 12;
294 if (!ret) {
295 fprintf(stderr, "ERROR: '%s' is not a subvolume\n", subvol);
296 return 13;
299 fd = open_file_or_dir(subvol);
300 if (fd < 0) {
301 fprintf(stderr, "ERROR: can't access '%s'\n", subvol);
302 return 12;
304 ret = list_subvols(fd);
305 if (ret)
306 return 19;
307 return 0;
310 int do_clone(int argc, char **argv)
312 char *subvol, *dst;
313 int res, fd, fddst, len;
314 char *newname;
315 char *dstdir;
317 subvol = argv[1];
318 dst = argv[2];
319 struct btrfs_ioctl_vol_args args;
321 res = test_issubvolume(subvol);
322 if(res<0){
323 fprintf(stderr, "ERROR: error accessing '%s'\n", subvol);
324 return 12;
326 if(!res){
327 fprintf(stderr, "ERROR: '%s' is not a subvolume\n", subvol);
328 return 13;
331 res = test_isdir(dst);
332 if(res == 0 ){
333 fprintf(stderr, "ERROR: '%s' exists and it is not a directory\n", dst);
334 return 12;
337 if(res>0){
338 newname = strdup(subvol);
339 newname = basename(newname);
340 dstdir = dst;
341 }else{
342 newname = strdup(dst);
343 newname = basename(newname);
344 dstdir = strdup(dst);
345 dstdir = dirname(dstdir);
348 if( !strcmp(newname,".") || !strcmp(newname,"..") ||
349 strchr(newname, '/') ){
350 fprintf(stderr, "ERROR: incorrect snapshot name ('%s')\n",
351 newname);
352 return 14;
355 len = strlen(newname);
356 if (len == 0 || len >= BTRFS_VOL_NAME_MAX) {
357 fprintf(stderr, "ERROR: snapshot name too long ('%s)\n",
358 newname);
359 return 14;
362 fddst = open_file_or_dir(dstdir);
363 if (fddst < 0) {
364 fprintf(stderr, "ERROR: can't access to '%s'\n", dstdir);
365 return 12;
368 fd = open_file_or_dir(subvol);
369 if (fd < 0) {
370 close(fddst);
371 fprintf(stderr, "ERROR: can't access to '%s'\n", dstdir);
372 return 12;
375 printf("Create a snapshot of '%s' in '%s/%s'\n",
376 subvol, dstdir, newname);
377 args.fd = fd;
378 strcpy(args.name, newname);
379 res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE, &args);
381 close(fd);
382 close(fddst);
384 if(res < 0 ){
385 fprintf( stderr, "ERROR: cannot snapshot '%s'\n",subvol);
386 return 11;
389 return 0;
393 int do_delete_subvolume(int argc, char **argv)
395 int res, fd, len;
396 struct btrfs_ioctl_vol_args args;
397 char *dname, *vname, *cpath;
398 char *path = argv[1];
400 res = test_issubvolume(path);
401 if(res<0){
402 fprintf(stderr, "ERROR: error accessing '%s'\n", path);
403 return 12;
405 if(!res){
406 fprintf(stderr, "ERROR: '%s' is not a subvolume\n", path);
407 return 13;
410 cpath = realpath(path, 0);
411 dname = strdup(cpath);
412 dname = dirname(dname);
413 vname = strdup(cpath);
414 vname = basename(vname);
415 free(cpath);
417 if( !strcmp(vname,".") || !strcmp(vname,"..") ||
418 strchr(vname, '/') ){
419 fprintf(stderr, "ERROR: incorrect subvolume name ('%s')\n",
420 vname);
421 return 14;
424 len = strlen(vname);
425 if (len == 0 || len >= BTRFS_VOL_NAME_MAX) {
426 fprintf(stderr, "ERROR: snapshot name too long ('%s)\n",
427 vname);
428 return 14;
431 fd = open_file_or_dir(dname);
432 if (fd < 0) {
433 close(fd);
434 fprintf(stderr, "ERROR: can't access to '%s'\n", dname);
435 return 12;
438 printf("Delete subvolume '%s/%s'\n", dname, vname);
439 strcpy(args.name, vname);
440 res = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &args);
442 close(fd);
444 if(res < 0 ){
445 fprintf( stderr, "ERROR: cannot delete '%s/%s'\n",dname, vname);
446 return 11;
449 return 0;
453 int do_create_subvol(int argc, char **argv)
455 int res, fddst, len;
456 char *newname;
457 char *dstdir;
458 struct btrfs_ioctl_vol_args args;
459 char *dst = argv[1];
461 res = test_isdir(dst);
462 if(res >= 0 ){
463 fprintf(stderr, "ERROR: '%s' exists\n", dst);
464 return 12;
467 newname = strdup(dst);
468 newname = basename(newname);
469 dstdir = strdup(dst);
470 dstdir = dirname(dstdir);
472 if( !strcmp(newname,".") || !strcmp(newname,"..") ||
473 strchr(newname, '/') ){
474 fprintf(stderr, "ERROR: uncorrect subvolume name ('%s')\n",
475 newname);
476 return 14;
479 len = strlen(newname);
480 if (len == 0 || len >= BTRFS_VOL_NAME_MAX) {
481 fprintf(stderr, "ERROR: subvolume name too long ('%s)\n",
482 newname);
483 return 14;
486 fddst = open_file_or_dir(dstdir);
487 if (fddst < 0) {
488 fprintf(stderr, "ERROR: can't access to '%s'\n", dstdir);
489 return 12;
492 printf("Create subvolume '%s/%s'\n", dstdir, newname);
493 strcpy(args.name, newname);
494 res = ioctl(fddst, BTRFS_IOC_SUBVOL_CREATE, &args);
496 close(fddst);
498 if(res < 0 ){
499 fprintf( stderr, "ERROR: cannot create subvolume\n");
500 return 11;
503 return 0;
507 int do_fssync(int argc, char **argv)
509 int fd, res;
510 char *path = argv[1];
512 fd = open_file_or_dir(path);
513 if (fd < 0) {
514 fprintf(stderr, "ERROR: can't access to '%s'\n", path);
515 return 12;
518 printf("FSSync '%s'\n", path);
519 res = ioctl(fd, BTRFS_IOC_SYNC);
520 close(fd);
521 if( res < 0 ){
522 fprintf(stderr, "ERROR: unable to fs-syncing '%s'\n", path);
523 return 16;
526 return 0;
529 int do_scan(int argc, char **argv)
531 int i, fd;
532 if(argc<=1){
533 int ret;
535 printf("Scanning for Btrfs filesystems\n");
536 ret = btrfs_scan_one_dir("/dev", 1);
537 if (ret){
538 fprintf(stderr, "ERROR: error %d while scanning\n", ret);
539 return 18;
541 return 0;
544 fd = open("/dev/btrfs-control", O_RDWR);
545 if (fd < 0) {
546 perror("failed to open /dev/btrfs-control");
547 return 10;
550 for( i = 1 ; i < argc ; i++ ){
551 struct btrfs_ioctl_vol_args args;
552 int ret;
554 printf("Scanning for Btrfs filesystems in '%s'\n", argv[i]);
556 strcpy(args.name, argv[i]);
558 * FIXME: which are the error code returned by this ioctl ?
559 * it seems that is impossible to understand if there no is
560 * a btrfs filesystem from an I/O error !!!
562 ret = ioctl(fd, BTRFS_IOC_SCAN_DEV, &args);
564 if( ret < 0 ){
565 close(fd);
566 fprintf(stderr, "ERROR: unable to scan the device '%s'\n", argv[i]);
567 return 11;
571 close(fd);
572 return 0;
576 int do_resize(int argc, char **argv)
579 struct btrfs_ioctl_vol_args args;
580 int fd, res, len;
581 char *amount=argv[1], *path=argv[2];
583 fd = open_file_or_dir(path);
584 if (fd < 0) {
585 fprintf(stderr, "ERROR: can't access to '%s'\n", path);
586 return 12;
588 len = strlen(amount);
589 if (len == 0 || len >= BTRFS_VOL_NAME_MAX) {
590 fprintf(stderr, "ERROR: size value too long ('%s)\n",
591 amount);
592 return 14;
595 printf("Resize '%s' of '%s'\n", path, amount);
596 strcpy(args.name, amount);
597 res = ioctl(fd, BTRFS_IOC_RESIZE, &args);
598 close(fd);
599 if( res < 0 ){
600 fprintf(stderr, "ERROR: unable to resize '%s'\n", path);
601 return 30;
603 return 0;
606 static int uuid_search(struct btrfs_fs_devices *fs_devices, char *search)
608 struct list_head *cur;
609 struct btrfs_device *device;
611 list_for_each(cur, &fs_devices->devices) {
612 device = list_entry(cur, struct btrfs_device, dev_list);
613 if ((device->label && strcmp(device->label, search) == 0) ||
614 strcmp(device->name, search) == 0)
615 return 1;
617 return 0;
620 static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
622 char uuidbuf[37];
623 struct list_head *cur;
624 struct btrfs_device *device;
625 char *super_bytes_used;
626 u64 devs_found = 0;
627 u64 total;
629 uuid_unparse(fs_devices->fsid, uuidbuf);
630 device = list_entry(fs_devices->devices.next, struct btrfs_device,
631 dev_list);
632 if (device->label && device->label[0])
633 printf("Label: '%s' ", device->label);
634 else
635 printf("Label: none ");
637 super_bytes_used = pretty_sizes(device->super_bytes_used);
639 total = device->total_devs;
640 printf(" uuid: %s\n\tTotal devices %llu FS bytes used %s\n", uuidbuf,
641 (unsigned long long)total, super_bytes_used);
643 free(super_bytes_used);
645 list_for_each(cur, &fs_devices->devices) {
646 char *total_bytes;
647 char *bytes_used;
648 device = list_entry(cur, struct btrfs_device, dev_list);
649 total_bytes = pretty_sizes(device->total_bytes);
650 bytes_used = pretty_sizes(device->bytes_used);
651 printf("\tdevid %4llu size %s used %s path %s\n",
652 (unsigned long long)device->devid,
653 total_bytes, bytes_used, device->name);
654 free(total_bytes);
655 free(bytes_used);
656 devs_found++;
658 if (devs_found < total) {
659 printf("\t*** Some devices missing\n");
661 printf("\n");
664 int do_show_filesystem(int argc, char **argv)
666 struct list_head *all_uuids;
667 struct btrfs_fs_devices *fs_devices;
668 struct list_head *cur_uuid;
669 char *search = argv[1];
670 int ret;
672 ret = btrfs_scan_one_dir("/dev", 0);
673 if (ret){
674 fprintf(stderr, "ERROR: error %d while scanning\n", ret);
675 return 18;
678 all_uuids = btrfs_scanned_uuids();
679 list_for_each(cur_uuid, all_uuids) {
680 fs_devices = list_entry(cur_uuid, struct btrfs_fs_devices,
681 list);
682 if (search && uuid_search(fs_devices, search) == 0)
683 continue;
684 print_one_uuid(fs_devices);
686 printf("%s\n", BTRFS_BUILD_VERSION);
687 return 0;
690 int do_add_volume(int nargs, char **args)
693 char *mntpnt = args[nargs-1];
694 int i, fdmnt, ret=0;
697 fdmnt = open_file_or_dir(mntpnt);
698 if (fdmnt < 0) {
699 fprintf(stderr, "ERROR: can't access to '%s'\n", mntpnt);
700 return 12;
703 for(i=1 ; i < (nargs-1) ; i++ ){
704 struct btrfs_ioctl_vol_args ioctl_args;
705 int devfd, res;
706 u64 dev_block_count = 0;
707 struct stat st;
709 devfd = open(args[i], O_RDWR);
710 if (!devfd) {
711 fprintf(stderr, "ERROR: Unable to open device '%s'\n", args[i]);
712 close(devfd);
713 ret++;
714 continue;
716 ret = fstat(devfd, &st);
717 if (ret) {
718 fprintf(stderr, "ERROR: Unable to stat '%s'\n", args[i]);
719 close(devfd);
720 ret++;
721 continue;
723 if (!S_ISBLK(st.st_mode)) {
724 fprintf(stderr, "ERROR: '%s' is not a block device\n", args[i]);
725 close(devfd);
726 ret++;
727 continue;
730 res = btrfs_prepare_device(devfd, args[i], 1, &dev_block_count);
731 if (res) {
732 fprintf(stderr, "ERROR: Unable to init '%s'\n", args[i]);
733 close(devfd);
734 ret++;
735 continue;
737 close(devfd);
739 strcpy(ioctl_args.name, args[i]);
740 res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
741 if(res<0){
742 fprintf(stderr, "ERROR: error adding the device '%s'\n", args[i]);
743 ret++;
748 close(fdmnt);
749 if( ret)
750 return ret+20;
751 else
752 return 0;
756 int do_balance(int argc, char **argv)
759 int fdmnt, ret=0;
760 struct btrfs_ioctl_vol_args args;
761 char *path = argv[1];
763 fdmnt = open_file_or_dir(path);
764 if (fdmnt < 0) {
765 fprintf(stderr, "ERROR: can't access to '%s'\n", path);
766 return 12;
769 memset(&args, 0, sizeof(args));
770 ret = ioctl(fdmnt, BTRFS_IOC_BALANCE, &args);
771 close(fdmnt);
772 if(ret<0){
773 fprintf(stderr, "ERROR: balancing '%s'\n", path);
775 return 19;
777 return 0;
779 int do_remove_volume(int nargs, char **args)
782 char *mntpnt = args[nargs-1];
783 int i, fdmnt, ret=0;
785 fdmnt = open_file_or_dir(mntpnt);
786 if (fdmnt < 0) {
787 fprintf(stderr, "ERROR: can't access to '%s'\n", mntpnt);
788 return 12;
791 for(i=1 ; i < (nargs-1) ; i++ ){
792 struct btrfs_ioctl_vol_args arg;
793 int res;
795 strcpy(arg.name, args[i]);
796 res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
797 if(res<0){
798 fprintf(stderr, "ERROR: error removing the device '%s'\n", args[i]);
799 ret++;
803 close(fdmnt);
804 if( ret)
805 return ret+20;
806 else
807 return 0;
810 int do_set_default_subvol(int nargs, char **argv)
812 int ret=0, fd;
813 u64 objectid;
814 char *path = argv[2];
815 char *subvolid = argv[1];
817 fd = open_file_or_dir(path);
818 if (fd < 0) {
819 fprintf(stderr, "ERROR: can't access to '%s'\n", path);
820 return 12;
823 objectid = (unsigned long long)strtoll(subvolid, NULL, 0);
824 if (errno == ERANGE) {
825 fprintf(stderr, "ERROR: invalid tree id (%s)\n",subvolid);
826 return 30;
828 ret = ioctl(fd, BTRFS_IOC_DEFAULT_SUBVOL, &objectid);
829 close(fd);
830 if( ret < 0 ){
831 fprintf(stderr, "ERROR: unable to set a new default subvolume\n");
832 return 30;
834 return 0;
837 int do_df_filesystem(int nargs, char **argv)
839 struct btrfs_ioctl_space_args *sargs;
840 u64 count = 0, i;
841 int ret;
842 int fd;
843 char *path = argv[1];
845 fd = open_file_or_dir(path);
846 if (fd < 0) {
847 fprintf(stderr, "ERROR: can't access to '%s'\n", path);
848 return 12;
851 sargs = malloc(sizeof(struct btrfs_ioctl_space_args));
852 if (!sargs)
853 return -ENOMEM;
855 sargs->space_slots = 0;
856 sargs->total_spaces = 0;
858 ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
859 if (ret) {
860 free(sargs);
861 return ret;
863 if (!sargs->total_spaces)
864 return 0;
866 count = sargs->total_spaces;
868 sargs = realloc(sargs, sizeof(struct btrfs_ioctl_space_args) +
869 (count * sizeof(struct btrfs_ioctl_space_info)));
870 if (!sargs)
871 return -ENOMEM;
873 sargs->space_slots = count;
874 sargs->total_spaces = 0;
876 ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
877 if (ret) {
878 free(sargs);
879 return ret;
882 for (i = 0; i < sargs->total_spaces; i++) {
883 char description[80];
884 char *total_bytes;
885 char *used_bytes;
886 int written = 0;
887 u64 flags = sargs->spaces[i].flags;
889 memset(description, 0, 80);
891 if (flags & BTRFS_BLOCK_GROUP_DATA) {
892 snprintf(description, 5, "%s", "Data");
893 written += 4;
894 } else if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
895 snprintf(description, 7, "%s", "System");
896 written += 6;
897 } else if (flags & BTRFS_BLOCK_GROUP_METADATA) {
898 snprintf(description, 9, "%s", "Metadata");
899 written += 8;
902 if (flags & BTRFS_BLOCK_GROUP_RAID0) {
903 snprintf(description+written, 8, "%s", ", RAID0");
904 written += 7;
905 } else if (flags & BTRFS_BLOCK_GROUP_RAID1) {
906 snprintf(description+written, 8, "%s", ", RAID1");
907 written += 7;
908 } else if (flags & BTRFS_BLOCK_GROUP_DUP) {
909 snprintf(description+written, 6, "%s", ", DUP");
910 written += 5;
911 } else if (flags & BTRFS_BLOCK_GROUP_RAID10) {
912 snprintf(description+written, 9, "%s", ", RAID10");
913 written += 8;
916 total_bytes = pretty_sizes(sargs->spaces[i].total_bytes);
917 used_bytes = pretty_sizes(sargs->spaces[i].used_bytes);
918 printf("%s: total=%s, used=%s\n", description, total_bytes,
919 used_bytes);
921 free(sargs);
923 return 0;