int do_not_background = 0;
int mixed = 0;
DIR *dirstream = NULL;
- char estr[100]; /* check test_dev_for_mkfs() for error string size*/
while ((c = getopt(argc, argv, "Brf")) != -1) {
switch (c) {
start_args.start.srcdevid = 0;
}
- ret = test_dev_for_mkfs(dstdev, force_using_targetdev, estr);
- if (ret) {
- fprintf(stderr, "%s", estr);
+ ret = test_dev_for_mkfs(dstdev, force_using_targetdev);
+ if (ret)
goto leave_with_error;
- }
+
fddstdev = open(dstdev, O_RDWR);
if (fddstdev < 0) {
fprintf(stderr, "Unable to open %s\n", dstdev);
}
}
-/* Check if disk is suitable for btrfs
+/*
+ * Check if a device is suitable for btrfs
* returns:
- * 1: something is wrong, estr provides the error
+ * 1: something is wrong, an error is printed
* 0: all is fine
*/
-int test_dev_for_mkfs(char *file, int force_overwrite, char *estr)
+int test_dev_for_mkfs(char *file, int force_overwrite)
{
int ret, fd;
- size_t sz = 100;
struct stat st;
ret = is_swap_device(file);
if (ret < 0) {
- snprintf(estr, sz, "error checking %s status: %s\n", file,
+ fprintf(stderr, "ERROR: checking status of %s: %s\n", file,
strerror(-ret));
return 1;
}
if (ret == 1) {
- snprintf(estr, sz, "%s is a swap device\n", file);
+ fprintf(stderr, "ERROR: %s is a swap device\n", file);
return 1;
}
if (!force_overwrite) {
if (check_overwrite(file)) {
- snprintf(estr, sz, "Use the -f option to force overwrite.\n");
+ fprintf(stderr, "Use the -f option to force overwrite.\n");
return 1;
}
}
ret = check_mounted(file);
if (ret < 0) {
- snprintf(estr, sz, "error checking %s mount status\n",
- file);
+ fprintf(stderr, "ERROR: checking mount status of %s: %s\n",
+ file, strerror(-ret));
return 1;
}
if (ret == 1) {
- snprintf(estr, sz, "%s is mounted\n", file);
+ fprintf(stderr, "ERROR: %s is mounted\n", file);
return 1;
}
/* check if the device is busy */
fd = open(file, O_RDWR|O_EXCL);
if (fd < 0) {
- snprintf(estr, sz, "unable to open %s: %s\n", file,
+ fprintf(stderr, "ERROR: unable to open %s: %s\n", file,
strerror(errno));
return 1;
}
if (fstat(fd, &st)) {
- snprintf(estr, sz, "unable to stat %s: %s\n", file,
+ fprintf(stderr, "ERROR: unable to stat %s: %s\n", file,
strerror(errno));
close(fd);
return 1;
}
if (!S_ISBLK(st.st_mode)) {
- fprintf(stderr, "'%s' is not a block device\n", file);
+ fprintf(stderr, "ERROR: %s is not a block device\n", file);
close(fd);
return 1;
}
u64 btrfs_device_size(int fd, struct stat *st);
/* Helper to always get proper size of the destination string */
#define strncpy_null(dest, src) __strncpy__null(dest, src, sizeof(dest))
-int test_dev_for_mkfs(char *file, int force_overwrite, char *estr);
+int test_dev_for_mkfs(char *file, int force_overwrite);
int get_label_mounted(const char *mount_path, char *labelp);
int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
u64 dev_cnt, int mixed, char *estr);