ri->ref_tree = 0;
return -ENOENT;
}
- error("failed to lookup path for root %llu: %s",
- (unsigned long long)ri->ref_tree, strerror(errno));
+ error("failed to lookup path for root %llu: %m",
+ (unsigned long long)ri->ref_tree);
return ret;
}
/* this ioctl fills in ino_args->treeid */
ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &ino_args);
if (ret < 0) {
- error("failed to lookup path for dirid %llu: %s",
- (unsigned long long)BTRFS_FIRST_FREE_OBJECTID,
- strerror(errno));
+ error("failed to lookup path for dirid %llu: %m",
+ (unsigned long long)BTRFS_FIRST_FREE_OBJECTID);
return 0;
}
while (1) {
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
if (ret < 0) {
- error("can't perform the search: %s", strerror(errno));
+ error("can't perform the search: %m");
return 0;
}
/* the ioctl returns the number of item it found in nr_items */
ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
if (ret < 0) {
- error("failed to lookup path for dirid %llu: %s",
- (unsigned long long)dirid, strerror(errno));
+ error("failed to lookup path for dirid %llu: %m",
+ (unsigned long long)dirid);
return ERR_PTR(ret);
}
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
if (ret < 0) {
- error("can't perform the search: %s", strerror(errno));
+ error("can't perform the search: %m");
return NULL;
}
/* the ioctl returns the number of item it found in nr_items */
ret = list_subvol_search(fd, root_lookup);
if (ret) {
- error("can't perform the search: %s", strerror(errno));
+ error("can't perform the search: %m");
return ret;
}
while(1) {
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
if (ret < 0) {
- error("can't perform the search: %s", strerror(errno));
+ error("can't perform the search: %m");
break;
}
/* the ioctl returns the number of item it found in nr_items */
ret = lookup_path_rootid(fd, treeid);
if (ret < 0)
- error("cannot resolve rootid for path: %s",
- strerror(errno));
+ error("cannot resolve rootid for path: %m");
return ret;
}
fprintf(stderr, "balance canceled by user\n");
ret = 0;
} else {
- error("error during balancing '%s': %s", path,
- strerror(errno));
+ error("error during balancing '%s': %m", path);
if (errno != EINPROGRESS)
fprintf(stderr,
"There may be more info in syslog - try dmesg | tail\n");
else
ret = 1;
} else {
- error("error during balancing '%s': %s\n"
+ error("error during balancing '%s': %m\n"
"There may be more info in syslog - try dmesg | tail",
- path, strerror(errno));
+ path);
ret = 1;
}
} else {
ret = 0;
goto out;
}
- error("balance status on '%s' failed: %s", path, strerror(errno));
+ error("balance status on '%s' failed: %m", path);
ret = 2;
goto out;
}
path = canonicalize_path(argv[i]);
if (!path) {
- error("could not canonicalize pathname '%s': %s",
- argv[i], strerror(errno));
+ error("could not canonicalize pathname '%s': %m",
+ argv[i]);
ret++;
goto error_out;
}
strncpy_null(ioctl_args.name, path);
res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
if (res < 0) {
- error("error adding device '%s': %s",
- path, strerror(errno));
+ error("error adding device '%s': %m", path);
ret++;
}
free(path);
*/
if (res < 0 && (errno == ENOTTY || errno == EOPNOTSUPP)) {
if (is_devid) {
- error("device delete by id failed: %s",
- strerror(errno));
+ error("device delete by id failed: %m");
ret++;
continue;
}
}
path = canonicalize_path(argv[i]);
if (!path) {
- error("could not canonicalize path '%s': %s",
- argv[i], strerror(errno));
+ error("could not canonicalize path '%s': %m", argv[i]);
ret = 1;
goto out;
}
path = canonicalize_path(argv[optind]);
if (!path) {
- error("could not canonicalize pathname '%s': %s",
- argv[optind], strerror(errno));
+ error("could not canonicalize pathname '%s': %m",
+ argv[optind]);
ret = 1;
goto out;
}
strncpy_null(args.name, path);
ret = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
if (ret < 0) {
- error("unable to determine if device '%s' is ready for mount: %s",
- path, strerror(errno));
+ error("unable to determine if device '%s' is ready for mount: %m",
+ path);
ret = 1;
}
args.flags = flags;
if (ioctl(fdmnt, BTRFS_IOC_GET_DEV_STATS, &args) < 0) {
- error("device stats ioctl failed on %s: %s",
- path, strerror(errno));
+ error("device stats ioctl failed on %s: %m",
+ path);
err |= 1;
} else {
char *canonical_path;
return -e;
if (ret < 0) {
- error("cannot look up chunk tree info: %s",
- strerror(e));
+ error("cannot look up chunk tree info: %m");
return 1;
}
/* the ioctl returns the number of item it found in nr_items */
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
if (ret < 0) {
- error("cannot get space info on '%s': %s", path,
- strerror(errno));
+ error("cannot get space info on '%s': %m", path);
free(sargs);
return NULL;
}
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
if (ret < 0) {
- error("cannot get space info with %u slots: %s",
- count, strerror(errno));
+ error("cannot get space info with %u slots: %m",
+ count);
free(sargs);
return NULL;
}
}
if (r_total_size == 0) {
- error("cannot get space info on '%s': %s",
- path, strerror(errno));
+ error("cannot get space info on '%s': %m", path);
ret = 1;
goto exit;
if (ret < 0) {
if (errno == EPERM)
return -errno;
- error("cannot get filesystem info: %s",
- strerror(errno));
+ error("cannot get filesystem info: %m");
return 1;
}
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
if (ret < 0) {
- error("cannot get space info: %s", strerror(errno));
+ error("cannot get space info: %m");
free(sargs);
return -errno;
}
sargs->total_spaces = 0;
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
if (ret < 0) {
- error("cannot get space info with %llu slots: %s",
- count, strerror(errno));
+ error("cannot get space info with %llu slots: %m",
+ count);
free(sargs);
return -errno;
}
static int cmd_filesystem_sync(int argc, char **argv)
{
- int fd, res, e;
+ int fd, res;
char *path;
DIR *dirstream = NULL;
return 1;
res = ioctl(fd, BTRFS_IOC_SYNC);
- e = errno;
close_file_or_dir(fd, dirstream);
if( res < 0 ){
- error("sync ioctl failed on '%s': %s", path, strerror(e));
+ error("sync ioctl failed on '%s': %m", path);
return 1;
}
int typeflag, struct FTW *ftwbuf)
{
int ret = 0;
- int err = 0;
int fd = 0;
if ((typeflag == FTW_F) && S_ISREG(sb->st_mode)) {
printf("%s\n", fpath);
fd = open(fpath, O_RDWR);
if (fd < 0) {
- err = errno;
goto error;
}
ret = ioctl(fd, BTRFS_IOC_DEFRAG_RANGE, &defrag_global_range);
return ENOTTY;
}
if (ret) {
- err = errno;
goto error;
}
}
return 0;
error:
- error("defrag failed on %s: %s", fpath, strerror(err));
+ error("defrag failed on %s: %m", fpath);
defrag_global_errors++;
return 0;
}
dirstream = NULL;
fd = open_file_or_dir(argv[i], &dirstream);
if (fd < 0) {
- error("cannot open %s: %s", argv[i],
- strerror(errno));
+ error("cannot open %s: %m", argv[i]);
ret = -errno;
goto next;
}
ret = fstat(fd, &st);
if (ret) {
- error("failed to stat %s: %s",
- argv[i], strerror(errno));
+ error("failed to stat %s: %m", argv[i]);
ret = -errno;
goto next;
}
res = stat(path, &st);
if (res < 0) {
- error("resize: cannot stat %s: %s", path, strerror(errno));
+ error("resize: cannot stat %s: %m", path);
return 1;
}
if (!S_ISDIR(st.st_mode)) {
path);
break;
default:
- error("unable to resize '%s': %s", path, strerror(e));
+ error("unable to resize '%s': %m", path);
break;
}
return 1;
error("failed to read the superblock on %s at %llu",
filename, (unsigned long long)sb_bytenr);
- error("error = '%s', errno = %d", strerror(errno), errno);
+ error("error = '%m', errno = %d", errno);
return 1;
}
printf("superblock: bytenr=%llu, device=%s\n", sb_bytenr, filename);
filename = argv[i];
fd = open(filename, O_RDONLY);
if (fd < 0) {
- error("cannot open %s: %s", filename, strerror(errno));
+ error("cannot open %s: %m", filename);
ret = 1;
goto out;
}
stat.max_cluster_size = root->fs_info->nodesize;
path.nodes[level] = root->node;
if (gettimeofday(&start, NULL)) {
- error("cannot get time: %s", strerror(errno));
+ error("cannot get time: %m");
goto out;
}
if (!level) {
if (ret)
goto out;
if (gettimeofday(&end, NULL)) {
- error("cannot get time: %s", strerror(errno));
+ error("cannot get time: %m");
goto out;
}
timeval_subtract(&diff, &end, &start);
ret = ioctl(fd, BTRFS_IOC_INO_PATHS, &ipa);
if (ret < 0) {
- error("ino paths ioctl: %s", strerror(errno));
+ error("ino paths ioctl: %m");
goto out;
}
ret = ioctl(fd, BTRFS_IOC_LOGICAL_INO, &loi);
if (ret < 0) {
- error("logical ino ioctl: %s", strerror(errno));
+ error("logical ino ioctl: %m");
goto out;
}
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
if (ret < 0) {
- error("tree search ioctl: %s", strerror(errno));
+ error("tree search ioctl: %m");
ret = 1;
goto out;
}
ret = ioctl(fd, BTRFS_IOC_QGROUP_ASSIGN, &args);
if (ret < 0) {
- error("unable to assign quota group: %s", strerror(errno));
+ error("unable to assign quota group: %m");
close_file_or_dir(fd, dirstream);
return 1;
}
memset(&qargs, 0, sizeof(qargs));
ret = ioctl(fd, BTRFS_IOC_QUOTA_RESCAN, &qargs);
if (ret < 0)
- error("quota rescan failed: %s",
- strerror(errno));
+ error("quota rescan failed: %m");
} else {
warning("quotas may be inconsistent, rescan needed");
}
{
int ret = 0;
int fd;
- int e;
char *path;
struct btrfs_ioctl_qgroup_create_args args;
DIR *dirstream = NULL;
return 1;
ret = ioctl(fd, BTRFS_IOC_QGROUP_CREATE, &args);
- e = errno;
close_file_or_dir(fd, dirstream);
if (ret < 0) {
- error("unable to %s quota group: %s",
- create ? "create":"destroy", strerror(e));
+ error("unable to %s quota group: %m",
+ create ? "create":"destroy");
return 1;
}
return 0;
if (sync) {
ret = ioctl(fd, BTRFS_IOC_SYNC);
if (ret < 0)
- warning("sync ioctl failed on '%s': %s", path,
- strerror(errno));
+ warning("sync ioctl failed on '%s': %m", path);
}
if (filter_flag) {
{
int ret = 0;
int fd;
- int e;
char *path = NULL;
struct btrfs_ioctl_qgroup_limit_args args;
unsigned long long size;
return 1;
ret = ioctl(fd, BTRFS_IOC_QGROUP_LIMIT, &args);
- e = errno;
close_file_or_dir(fd, dirstream);
if (ret < 0) {
- error("unable to limit requested quota group: %s", strerror(e));
+ error("unable to limit requested quota group: %m");
return 1;
}
return 0;
{
int ret = 0;
int fd;
- int e;
char *path = argv[1];
struct btrfs_ioctl_quota_ctl_args args;
DIR *dirstream = NULL;
return 1;
ret = ioctl(fd, BTRFS_IOC_QUOTA_CTL, &args);
- e = errno;
close_file_or_dir(fd, dirstream);
if (ret < 0) {
- error("quota command failed: %s", strerror(e));
+ error("quota command failed: %m");
return 1;
}
return 0;
if (ioctlnum == BTRFS_IOC_QUOTA_RESCAN_STATUS) {
close_file_or_dir(fd, dirstream);
if (ret < 0) {
- error("could not obtain quota rescan status: %s",
- strerror(e));
+ error("could not obtain quota rescan status: %m");
return 1;
}
if (!args.flags)
printf("quota rescan started\n");
fflush(stdout);
} else if (ret < 0 && (!wait_for_completion || e != EINPROGRESS)) {
- error("quota rescan failed: %s", strerror(e));
+ error("quota rescan failed: %m");
close_file_or_dir(fd, dirstream);
return 1;
}
ret = ioctl(fd, BTRFS_IOC_QUOTA_RESCAN_WAIT, &args);
e = errno;
if (ret < 0) {
- error("quota rescan wait failed: %s",
- strerror(e));
+ error("quota rescan wait failed: %m");
close_file_or_dir(fd, dirstream);
return 1;
}
if (fromfile[0]) {
receive_fd = open(fromfile, O_RDONLY | O_NOATIME);
if (receive_fd < 0) {
- error("cannot open %s: %s", fromfile, strerror(errno));
+ error("cannot open %s: %m", fromfile);
goto out;
}
}
ret = ioctl(fdmnt, BTRFS_IOC_DEV_REPLACE, &status_args);
if (ret < 0) {
fprintf(stderr,
- "ERROR: ioctl(DEV_REPLACE_STATUS) failed on \"%s\": %s",
- path, strerror(errno));
+ "ERROR: ioctl(DEV_REPLACE_STATUS) failed on \"%s\": %m",
+ path);
if (status_args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT)
fprintf(stderr, ", %s\n",
replace_dev_result2string(status_args.result));
srcdev = argv[optind];
dstdev = canonicalize_path(argv[optind + 1]);
if (!dstdev) {
- error("cannot canonicalize path '%s': %s",
- argv[optind + 1], strerror(errno));
+ error("cannot canonicalize path '%s': %m",
+ argv[optind + 1]);
goto leave_with_error;
}
fddstdev = open(dstdev, O_RDWR);
if (fddstdev < 0) {
- error("unable to open %s: %s", dstdev, strerror(errno));
+ error("unable to open %s: %m", dstdev);
goto leave_with_error;
}
strncpy((char *)start_args.start.tgtdev_name, dstdev,
dev_replace_handle_sigint(fdmnt);
if (!do_not_background) {
if (daemon(0, 0) < 0) {
- error("backgrounding failed: %s", strerror(errno));
+ error("backgrounding failed: %m");
goto leave_with_error;
}
}
if (do_not_background) {
if (ret < 0) {
fprintf(stderr,
- "ERROR: ioctl(DEV_REPLACE_START) failed on \"%s\": %s",
- path, strerror(errno));
+ "ERROR: ioctl(DEV_REPLACE_START) failed on \"%s\": %m",
+ path);
if (start_args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT)
fprintf(stderr, ", %s\n",
replace_dev_result2string(start_args.result));
args.result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT;
ret = ioctl(fd, BTRFS_IOC_DEV_REPLACE, &args);
if (ret < 0) {
- fprintf(stderr, "ERROR: ioctl(DEV_REPLACE_STATUS) failed on \"%s\": %s",
- path, strerror(errno));
+ fprintf(stderr, "ERROR: ioctl(DEV_REPLACE_STATUS) failed on \"%s\": %m",
+ path);
if (args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT)
fprintf(stderr, ", %s\n",
replace_dev_result2string(args.result));
int ret;
int c;
int fd;
- int e;
char *path;
DIR *dirstream = NULL;
args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_CANCEL;
args.result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT;
ret = ioctl(fd, BTRFS_IOC_DEV_REPLACE, &args);
- e = errno;
close_file_or_dir(fd, dirstream);
if (ret < 0) {
- fprintf(stderr, "ERROR: ioctl(DEV_REPLACE_CANCEL) failed on \"%s\": %s",
- path, strerror(e));
+ fprintf(stderr, "ERROR: ioctl(DEV_REPLACE_CANCEL) failed on \"%s\": %m",
+ path);
if (args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT)
fprintf(stderr, ", %s\n",
replace_dev_result2string(args.result));
pos+total);
if (done < 0) {
ret = -1;
- error("cannot write data: %d %s", errno, strerror(errno));
+ error("cannot write data: %d %m", errno);
goto out;
}
total += done;
data_len = len;
if (fsetxattr(fd, name, data, data_len, 0))
- error("setting extended attribute %s on file %s: %s",
- name, file_name, strerror(errno));
+ error("setting extended attribute %s on file %s: %m",
+ name, file_name);
len = sizeof(*di) + name_len + data_len;
cur += len;
ret = fchown(fd, btrfs_inode_uid(path.nodes[0], inode_item),
btrfs_inode_gid(path.nodes[0], inode_item));
if (ret) {
- error("failed to change owner: %s", strerror(errno));
+ error("failed to change owner: %m");
goto out;
}
ret = fchmod(fd, btrfs_inode_mode(path.nodes[0], inode_item));
if (ret) {
- error("failed to change mode: %s", strerror(errno));
+ error("failed to change mode: %m");
goto out;
}
ret = futimens(fd, times);
if (ret) {
- error("failed to set times: %s", strerror(errno));
+ error("failed to set times: %m");
goto out;
}
}
if (!dry_run) {
ret = symlink(symlink_target, path_name);
if (ret < 0) {
- fprintf(stderr, "Failed to restore symlink '%s': %s\n",
- path_name, strerror(errno));
+ fprintf(stderr, "Failed to restore symlink '%s': %m\n",
+ path_name);
goto out;
}
}
btrfs_inode_gid(path.nodes[0], inode_item),
AT_SYMLINK_NOFOLLOW);
if (ret) {
- fprintf(stderr, "Failed to change owner: %s\n",
- strerror(errno));
+ fprintf(stderr, "Failed to change owner: %m\n");
goto out;
}
ret = utimensat(-1, file, times, AT_SYMLINK_NOFOLLOW);
if (ret)
- fprintf(stderr, "Failed to set times: %s\n", strerror(errno));
+ fprintf(stderr, "Failed to set times: %m\n");
out:
btrfs_release_path(&path);
return ret;
IOPRIO_PRIO_VALUE(sp->ioprio_class,
sp->ioprio_classdata));
if (ret)
- warning("setting ioprio failed: %s (ignored)",
- strerror(errno));
+ warning("setting ioprio failed: %m (ignored)");
ret = ioctl(sp->fd, BTRFS_IOC_SCRUB, &sp->scrub_args);
gettimeofday(&tv, NULL);
if (mkdir_p(datafile)) {
warning_on(!do_quiet,
- "cannot create scrub data file, mkdir %s failed: %s. Status recording disabled",
- datafile, strerror(errno));
+ "cannot create scrub data file, mkdir %s failed: %m. Status recording disabled",
+ datafile);
do_record = 0;
}
free(datafile);
spc.progress = calloc(fi_args.num_devices * 2, sizeof(*spc.progress));
if (!t_devs || !sp || !spc.progress) {
- error_on(!do_quiet, "scrub failed: %s", strerror(errno));
+ error_on(!do_quiet, "scrub failed: %m");
err = 1;
goto out;
}
ret = listen(prg_fd, 100);
if (ret == -1) {
warning_on(!do_quiet,
- "failed to open the progress status socket at %s: %s. Progress cannot be queried",
+ "failed to open the progress status socket at %s: %m. Progress cannot be queried",
sock_path[0] ? sock_path :
- SCRUB_PROGRESS_SOCKET_PATH, strerror(errno));
+ SCRUB_PROGRESS_SOCKET_PATH);
if (prg_fd != -1) {
close(prg_fd);
prg_fd = -1;
if (do_background) {
pid = fork();
if (pid == -1) {
- error_on(!do_quiet, "cannot scrub, fork failed: %s",
- strerror(errno));
+ error_on(!do_quiet, "cannot scrub, fork failed: %m");
err = 1;
goto out;
}
}
ret = wait(&stat);
if (ret != pid) {
- error_on(!do_quiet, "wait failed (ret=%d): %s",
- ret, strerror(errno));
+ error_on(!do_quiet, "wait failed (ret=%d): %m",
+ ret);
err = 1;
goto out;
}
fdres = socket(AF_UNIX, SOCK_STREAM, 0);
if (fdres == -1) {
- error("failed to create socket to receive progress information: %s",
- strerror(errno));
+ error("failed to create socket to receive progress information: %m");
err = 1;
goto out;
}
}
if (res < 0) {
- error("cannot create subvolume: %s", strerror(errno));
+ error("cannot create subvolume: %m");
goto out;
}
cpath = realpath(path, NULL);
if (!cpath) {
ret = errno;
- error("cannot find real path for '%s': %s",
- path, strerror(errno));
+ error("cannot find real path for '%s': %m", path);
goto out;
}
dupdname = strdup(cpath);
strncpy_null(args.name, vname);
res = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &args);
if(res < 0 ){
- error("cannot delete '%s/%s': %s", dname, vname,
- strerror(errno));
+ error("cannot delete '%s/%s': %m", dname, vname);
ret = 1;
goto out;
}
if (commit_mode == COMMIT_EACH) {
res = wait_for_commit(fd);
if (res < 0) {
- error("unable to wait for commit after '%s': %s",
- path, strerror(errno));
+ error("unable to wait for commit after '%s': %m", path);
ret = 1;
}
} else if (commit_mode == COMMIT_AFTER) {
if (res < 0) {
uuid_unparse(seen->fsid, uuidbuf);
error(
- "unable to do final sync after deletion: %s, fsid: %s",
- strerror(errno), uuidbuf);
+ "unable to do final sync after deletion: %m, fsid: %s",
+ uuidbuf);
ret = 1;
} else if (verbose > 0) {
uuid_unparse(seen->fsid, uuidbuf);
res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE_V2, &args);
if (res < 0) {
- error("cannot snapshot '%s': %s", subvol, strerror(errno));
+ error("cannot snapshot '%s': %m", subvol);
goto out;
}
ret = btrfs_list_get_default_subvolume(fd, &default_id);
if (ret) {
- error("failed to look up default subvolume: %s",
- strerror(errno));
+ error("failed to look up default subvolume: %m");
goto out;
}
static int cmd_subvol_set_default(int argc, char **argv)
{
- int ret=0, fd, e;
+ int ret=0, fd;
u64 objectid;
char *path;
char *subvolid;
}
ret = ioctl(fd, BTRFS_IOC_DEFAULT_SUBVOL, &objectid);
- e = errno;
close_file_or_dir(fd, dirstream);
if (ret < 0) {
- error("unable to set a new default subvolume: %s",
- strerror(e));
+ error("unable to set a new default subvolume: %m");
return 1;
}
return 0;
ret = ioctl(fd, BTRFS_IOC_SYNC);
if (ret < 0) {
- error("sync ioctl failed on '%s': %s",
- subvol, strerror(errno));
+ error("sync ioctl failed on '%s': %m", subvol);
close_file_or_dir(fd, dirstream);
return 1;
}
memset(&get_ri, 0, sizeof(get_ri));
fullpath = realpath(argv[optind], NULL);
if (!fullpath) {
- error("cannot find real path for '%s': %s",
- argv[optind], strerror(errno));
+ error("cannot find real path for '%s': %m", argv[optind]);
goto out;
}
goto fail;
fd = open(devname, O_RDWR);
if (fd < 0) {
- error("unable to open %s: %s", devname, strerror(errno));
+ error("unable to open %s: %m", devname);
goto fail;
}
btrfs_parse_features_to_string(features_buf, features);
}
fd = open(devname, O_RDWR);
if (fd < 0) {
- error("unable to open %s: %s", devname, strerror(errno));
+ error("unable to open %s: %m", devname);
ret = -EIO;
goto free_mem;
}
ret = stat(filename, &st);
if (ret < 0) {
- error("cannot stat '%s': %s", filename, strerror(errno));
+ error("cannot stat '%s': %m", filename);
return NULL;
}
if (!(((st.st_mode & S_IFMT) == S_IFREG) || ((st.st_mode & S_IFMT) == S_IFBLK))) {
fp = open(filename, oflags);
if (fp < 0) {
- error("cannot open '%s': %s", filename, strerror(errno));
+ error("cannot open '%s': %m", filename);
return NULL;
}
info = __open_ctree_fd(fp, filename, sb_bytenr, root_tree_bytenr,
if (ret > 0)
fprintf(stderr, "WARNING: failed to write all sb data\n");
else
- fprintf(stderr, "WARNING: failed to write sb: %s\n",
- strerror(errno));
+ fprintf(stderr, "WARNING: failed to write sb: %m\n");
return ret;
}
ret = fwrite(&md->cluster, BLOCK_SIZE, 1, md->out);
if (ret != 1) {
- error("unable to write out cluster: %s", strerror(errno));
+ error("unable to write out cluster: %m");
return -errno;
}
ret = fwrite(async->buffer, async->bufsize, 1,
md->out);
if (ret != 1) {
- error("unable to write out cluster: %s",
- strerror(errno));
+ error("unable to write out cluster: %m");
err = -errno;
ret = 0;
}
bytenr += size;
ret = write_zero(md->out, size);
if (ret != 1) {
- error("unable to zero out buffer: %s",
- strerror(errno));
+ error("unable to zero out buffer: %m");
err = -errno;
}
}
if (ret < size) {
free(async->buffer);
free(async);
- error("unable to read superblock at %llu: %s",
- (unsigned long long)start,
- strerror(errno));
+ error("unable to read superblock at %llu: %m",
+ (unsigned long long)start);
return -errno;
}
size = 0;
if (fstat(fd, &st)) {
error(
- "cannot stat restore point, won't be able to write backup supers: %s",
- strerror(errno));
+ "cannot stat restore point, won't be able to write backup supers: %m");
return;
}
if (ret < BTRFS_SUPER_INFO_SIZE) {
if (ret < 0)
error(
- "problem writing out backup super block %d: %s",
- i, strerror(errno));
+ "problem writing out backup super block %d: %m", i);
else
error("short write writing out backup super block");
break;
error:
if (ret < 0) {
- error("unable to write to device: %s",
- strerror(errno));
+ error("unable to write to device: %m");
err = errno;
} else {
error("short write");
}
ret = fread(async->buffer, async->bufsize, 1, mdres->in);
if (ret != 1) {
- error("unable to read buffer: %s", strerror(errno));
+ error("unable to read buffer: %m");
free(async->buffer);
free(async);
return -EIO;
bytenr += size;
ret = fread(buffer, size, 1, mdres->in);
if (ret != 1) {
- error("failed to read buffer: %s", strerror(errno));
+ error("failed to read buffer: %m");
return -EIO;
}
}
bytenr = current_cluster;
while (1) {
if (fseek(mdres->in, current_cluster, SEEK_SET)) {
- error("seek failed: %s", strerror(errno));
+ error("seek failed: %m");
ret = -EIO;
break;
}
ret = -EIO;
break;
} else if (ret < 0) {
- error("unable to read image at %llu: %s",
- (unsigned long long)cluster_bytenr,
- strerror(errno));
+ error("unable to read image at %llu: %m",
+ (unsigned long long)cluster_bytenr);
break;
}
ret = 0;
if (mdres->compress_method == COMPRESS_ZLIB) {
ret = fread(tmp, bufsize, 1, mdres->in);
if (ret != 1) {
- error("read error: %s", strerror(errno));
+ error("read error: %m");
ret = -EIO;
break;
}
} else {
ret = fread(buffer, bufsize, 1, mdres->in);
if (ret != 1) {
- error("read error: %s",
- strerror(errno));
+ error("read error: %m");
ret = -EIO;
break;
}
ret = fread(cluster, BLOCK_SIZE, 1, mdres->in);
if (ret <= 0) {
- error("unable to read cluster: %s", strerror(errno));
+ error("unable to read cluster: %m");
return -EIO;
}
ret = 0;
break;
bytenr += le32_to_cpu(item->size);
if (fseek(mdres->in, le32_to_cpu(item->size), SEEK_CUR)) {
- error("seek failed: %s", strerror(errno));
+ error("seek failed: %m");
return -EIO;
}
}
ret = fread(buffer, le32_to_cpu(item->size), 1, mdres->in);
if (ret != 1) {
- error("unable to read buffer: %s", strerror(errno));
+ error("unable to read buffer: %m");
free(buffer);
return -EIO;
}
} else {
in = fopen(input, "r");
if (!in) {
- error("unable to open metadump image: %s",
- strerror(errno));
+ error("unable to open metadump image: %m");
return 1;
}
}
}
if (in != stdin && fseek(in, 0, SEEK_SET)) {
- error("seek failed: %s", strerror(errno));
+ error("seek failed: %m");
goto out;
}
info = root->fs_info;
if (stat(target, &st)) {
- error("stat %s failed: %s", target, strerror(errno));
+ error("stat %s failed: %m", target);
close_ctree(info->chunk_root);
free(cluster);
return 1;
/* update other devices' super block */
fp = open(other_dev, O_CREAT | O_RDWR, 0600);
if (fp < 0) {
- error("could not open %s: %s", other_dev, strerror(errno));
+ error("could not open %s: %m", other_dev);
ret = -EIO;
goto out;
}
0, target, multi_devices);
}
if (ret) {
- error("%s failed: %s", (create) ? "create" : "restore",
- strerror(errno));
+ error("%s failed: %m", (create) ? "create" : "restore");
goto out;
}
unlink_ret = unlink(target);
if (unlink_ret)
- error("unlink output file %s failed: %s",
- target, strerror(errno));
+ error("unlink output file %s failed: %m",
+ target);
}
}
/* check if the device is busy */
fd = open(file, O_RDWR|O_EXCL);
if (fd < 0) {
- error("unable to open %s: %s", file, strerror(errno));
+ error("unable to open %s: %m", file);
return 1;
}
if (fstat(fd, &st)) {
- error("unable to stat %s: %s", file, strerror(errno));
+ error("unable to stat %s: %m", file);
close(fd);
return 1;
}
fd = open(file, oflags, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
S_IROTH);
if (fd < 0) {
- error("unable to open %s: %s", file, strerror(errno));
+ error("unable to open %s: %m", file);
goto error;
}
+
ret = fstat(fd, &statbuf);
if (ret < 0) {
- error("unable to stat %s: %s", file, strerror(errno));
+ error("unable to stat %s: %m", file);
ret = -errno;
goto error;
}
path = argv[i];
ret = test_minimum_size(path, min_dev_size);
if (ret < 0) {
- error("failed to check size for %s: %s",
- path, strerror(-ret));
+ error("failed to check size for %s: %m", path);
goto error;
}
if (ret > 0) {
*/
fd = open(file, O_RDWR);
if (fd < 0) {
- error("unable to open %s: %s", file, strerror(errno));
+ error("unable to open %s: %m", file);
goto error;
}
ret = btrfs_prepare_device(fd, file, &dev_block_count, block_count,
*/
fd = open(file, O_RDWR);
if (fd < 0) {
- error("unable to open %s: %s", file, strerror(errno));
+ error("unable to open %s: %m", file);
goto error;
}
ret = btrfs_device_already_in_root(root, fd,
ret = ioctl(mnt_fd, BTRFS_IOC_TREE_SEARCH, &args);
if (ret < 0) {
fprintf(stderr,
- "ERROR: can't perform the search - %s\n",
- strerror(errno));
+ "ERROR: can't perform the search - %m\n");
return 0;
}
/* the ioctl returns the number of item it found in nr_items */
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &search_arg);
if (ret < 0) {
fprintf(stderr,
- "ioctl(BTRFS_IOC_TREE_SEARCH, subvol_id %llu) ret=%d, error: %s\n",
- (unsigned long long)subvol_id, ret, strerror(errno));
+ "ioctl(BTRFS_IOC_TREE_SEARCH, subvol_id %llu) ret=%d, error: %m\n",
+ (unsigned long long)subvol_id, ret);
return ret;
}
ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &ino_lookup_arg);
if (ret < 0) {
fprintf(stderr,
- "ioctl(BTRFS_IOC_INO_LOOKUP) ret=%d, error: %s\n",
- ret, strerror(errno));
+ "ioctl(BTRFS_IOC_INO_LOOKUP) ret=%d, error: %m\n",
+ ret);
return ret;
}
ret = is_uuid_tree_supported(mnt_fd);
if (ret < 0) {
fprintf(stderr,
- "ERROR: check if we support uuid tree fails - %s\n",
- strerror(errno));
+ "ERROR: check if we support uuid tree fails - %m\n");
return ret;
} else if (ret) {
/* uuid tree is supported */
while (1) {
ret = ioctl(mnt_fd, BTRFS_IOC_TREE_SEARCH, &args);
if (ret < 0) {
- fprintf(stderr, "ERROR: can't perform the search - %s\n",
- strerror(errno));
+ fprintf(stderr, "ERROR: can't perform the search - %m\n");
return ret;
}
if (sk->nr_items == 0)
}
ret = lstat64(namelist[i], &st);
if (ret) {
- fprintf(stderr, "stat failed for %s/%s: %s\n",
- path_prefix, path, strerror(errno));
+ fprintf(stderr, "stat failed for %s/%s: %m\n",
+ path_prefix, path);
exit(-1);
}
sum_add_u64(&meta, level);
if (fd == -1 && flags[FLAG_OPEN_ERROR]) {
sum_add_u64(&meta, errno);
} else if (fd == -1) {
- fprintf(stderr, "open failed for %s/%s: %s\n",
- path_prefix, path, strerror(errno));
+ fprintf(stderr, "open failed for %s/%s: %m\n",
+ path_prefix, path);
exit(-1);
} else {
sum(fd, level + 1, &cs, path_prefix, path);
sum_add_u64(&meta, errno);
} else if (fd == -1) {
fprintf(stderr,
- "open failed for %s/%s: %s\n",
- path_prefix, path,
- strerror(errno));
+ "open failed for %s/%s: %m\n",
+ path_prefix, path);
exit(-1);
}
if (fd != -1) {
if (ret < 0) {
fprintf(stderr,
"read failed for "
- "%s/%s: %s\n",
- path_prefix, path,
- strerror(errno));
+ "%s/%s: %m\n",
+ path_prefix, path);
exit(-1);
}
close(fd);
out_fp = fopen(optarg, "w");
if (!out_fp) {
fprintf(stderr,
- "failed to open output file: %s\n",
- strerror(errno));
+ "failed to open output file: %m\n");
exit(-1);
}
break;
in_fp = fopen(optarg, "r");
if (!in_fp) {
fprintf(stderr,
- "failed to open input file: %s\n",
- strerror(errno));
+ "failed to open input file: %m\n");
exit(-1);
}
break;
fd = open(path, O_RDONLY);
if (fd == -1) {
- fprintf(stderr, "failed to open %s: %s\n", path,
- strerror(errno));
+ fprintf(stderr, "failed to open %s: %m\n", path);
exit(-1);
}
memset(buf, 0, len);
ret = pwrite(fd, buf, len, offset);
if (ret < 0) {
- error("cannot wipe existing superblock: %s", strerror(errno));
+ error("cannot wipe existing superblock: %m");
ret = -1;
} else if (ret != len) {
error("cannot wipe existing superblock: wrote %d of %zd", ret, len);
ret = fstat(fd, &st);
if (ret < 0) {
- error("unable to stat %s: %s", file, strerror(errno));
+ error("unable to stat %s: %m", file);
return 1;
}
fd = open(dev, O_RDONLY);
if (fd < 0) {
ret = -errno;
- error("cannot open %s: %s", dev, strerror(errno));
+ error("cannot open %s: %m", dev);
goto out;
}
return -1;
}
ret = open_file_or_dir(mp, dirstream);
- error_on(verbose && ret < 0, "can't access '%s': %s",
- path, strerror(errno));
+ error_on(verbose && ret < 0, "can't access '%s': %m",
+ path);
} else {
ret = btrfs_open_dir(path, dirstream, 1);
}
int ret;
if (statfs(path, &stfs) != 0) {
- error_on(verbose, "cannot access '%s': %s", path,
- strerror(errno));
+ error_on(verbose, "cannot access '%s': %m", path);
return -1;
}
}
if (stat(path, &st) != 0) {
- error_on(verbose, "cannot access '%s': %s", path,
- strerror(errno));
+ error_on(verbose, "cannot access '%s': %m", path);
return -1;
}
ret = open_file_or_dir(path, dirstream);
if (ret < 0) {
- error_on(verbose, "cannot access '%s': %s", path,
- strerror(errno));
+ error_on(verbose, "cannot access '%s': %m", path);
}
return ret;
fd = open(file, O_RDONLY);
if (fd < 0) {
- error("mount check: cannot open %s: %s", file,
- strerror(errno));
+ error("mount check: cannot open %s: %m", file);
return -errno;
}
fd = open("/dev/btrfs-control", O_RDWR);
if (fd < 0) {
warning(
- "failed to open /dev/btrfs-control, skipping device registration: %s",
- strerror(errno));
+ "failed to open /dev/btrfs-control, skipping device registration: %m");
return -errno;
}
memset(&args, 0, sizeof(args));
strncpy_null(args.name, fname);
ret = ioctl(fd, BTRFS_IOC_SCAN_DEV, &args);
if (ret < 0) {
- error("device scan failed on '%s': %s", fname,
- strerror(errno));
+ error("device scan failed on '%s': %m", fname);
ret = -errno;
}
close(fd);
fd = open(mount_path, O_RDONLY | O_NOATIME);
if (fd < 0) {
- error("unable to access %s: %s", mount_path, strerror(errno));
+ error("unable to access %s: %m", mount_path);
return -1;
}
memset(label, 0, sizeof(label));
__strncpy_null(label, labelp, BTRFS_LABEL_SIZE - 1);
if (ioctl(fd, BTRFS_IOC_SET_FSLABEL, label) < 0) {
- error("unable to set label of %s: %s", mount_path,
- strerror(errno));
+ error("unable to set label of %s: %m", mount_path);
close(fd);
return -1;
}
fd = open(mount_path, O_RDONLY | O_NOATIME);
if (fd < 0) {
- error("unable to access %s: %s", mount_path, strerror(errno));
+ error("unable to access %s: %m", mount_path);
return -1;
}
ret = ioctl(fd, BTRFS_IOC_GET_FSLABEL, label);
if (ret < 0) {
if (errno != ENOTTY)
- error("unable to get label of %s: %s", mount_path,
- strerror(errno));
+ error("unable to get label of %s: %m", mount_path);
ret = -errno;
close(fd);
return ret;
fd = open(path, O_RDONLY);
if (fd < 0) {
ret = -errno;
- error("cannot open %s: %s", path, strerror(errno));
+ error("cannot open %s: %m", path);
goto out;
}
ret = check_mounted_where(fd, path, mp, sizeof(mp),
fd = open(path, O_RDONLY);
if (fd < 0) {
- error("cannot open %s: %s", path, strerror(errno));
+ error("cannot open %s: %m", path);
continue;
}
ret = btrfs_scan_one_device(fd, path, &tmp_devices,
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &search_arg);
if (ret < 0) {
fprintf(stderr,
- "ioctl(BTRFS_IOC_TREE_SEARCH, uuid, key %016llx, UUID_KEY, %016llx) ret=%d, error: %s\n",
+ "ioctl(BTRFS_IOC_TREE_SEARCH, uuid, key %016llx, UUID_KEY, %016llx) ret=%d, error: %m\n",
(unsigned long long)key_objectid,
- (unsigned long long)key_offset, ret, strerror(errno));
+ (unsigned long long)key_offset, ret);
ret = -ENOENT;
goto out;
}
struct btrfs_device, dev_list);
if (device->fd != -1) {
if (fsync(device->fd) == -1) {
- warning("fsync on device %llu failed: %s",
- device->devid, strerror(errno));
+ warning("fsync on device %llu failed: %m",
+ device->devid);
ret = -errno;
}
if (posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED))
fd = open(device->name, flags);
if (fd < 0) {
ret = -errno;
- error("cannot open device '%s': %s", device->name,
- strerror(errno));
+ error("cannot open device '%s': %m", device->name);
goto fail;
}