On Fri, Apr 05, 2013 at 01:54:57PM +0800, Anand Jain wrote: > In the cases where one of the disk is not suitable for > btrfs, then we would fail the mkfs, however we determine > that after we have written btrfs to the preceding disks. > At this time if user changes mind for not to use btrfs > will left with no choice. > > So this patch will check if all the provided disks are > suitable for the btrfs at once before proceeding to > create btrfs on a disk.
Good fix and cleanup. > +void __test_dev_for_mkfs(char *file, int force_overwrite) > +{ > + int ret, fd; > + > + ret = is_swap_device(file); > + if (ret < 0) { > + fprintf(stderr, "error checking %s status: %s\n", file, > + strerror(-ret)); > + exit(1); The exit()s were ok when this code was in main(), but should be converted to return for a helper function. > + } > int main(int ac, char **av) > { > char *file; > @@ -1378,6 +1418,8 @@ int main(int ac, char **av) > char *pretty_buf; > struct btrfs_super_block *super; > u64 flags; > + int dev_cnt=0; int dev_cnt = 0; > + int saved_optind; > > while(1) { > int c; > + dev_cnt = ac - optind; > + if (dev_cnt == 0) > print_usage(); > > + if (source_dir_set && dev_cnt > 1) { > + fprintf(stderr, > + "The -r option is limited to a single device\n"); > + exit(1); > + } > + while (dev_cnt-- > 0) { > + file = av[optind++]; > + /* following func would exit on error */ > + if (is_block_device(file)) > + __test_dev_for_mkfs(file, force_overwrite); Catch errors here and exit() eventually. > + } > + -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html