return 0;
if (len > (path_max - pathp)) {
- fprintf(stderr, "ERROR: Path max exceeded: %s %s\n", path,
- filename);
+ error("path too long: %s %s", path, filename);
return ENAMETOOLONG;
}
int cmd_filesystem_du(int argc, char **argv)
{
- int ret = 0, error = 0;
+ int ret = 0, err = 0;
int i;
unit_mode = get_unit_mode_from_arg(&argc, argv, 1);
for (i = optind; i < argc; i++) {
ret = du_add_file(argv[i], AT_FDCWD, NULL, NULL, NULL, 1);
if (ret) {
- fprintf(stderr, "ERROR: can't check space of '%s': %s\n",
- argv[i], strerror(ret));
- error = 1;
+ error("cannot check space of '%s': %s", argv[i],
+ strerror(ret));
+ err = 1;
}
/* reset hard-link detection for each argument */
clear_seen_inodes();
}
- return error;
+ return err;
}
buf = malloc(sizeof(*buf) + sizeof(*sb));
if (!buf) {
- fprintf(stderr, "%s\n", strerror(ENOMEM));
+ error("not enough memory");
goto out;
}
write_extent_buffer(buf, sb, 0, sizeof(*sb));
if (ret == 0 && errno == 0)
return 0;
- fprintf(stderr,
- "ERROR: Failed to read the superblock on %s at %llu\n",
- filename, (unsigned long long)sb_bytenr);
- fprintf(stderr,
- "ERROR: error = '%s', errno = %d\n", strerror(errno), errno);
+ error("failed to read the superblock on %s at %llu",
+ filename, (unsigned long long)sb_bytenr);
+ error("error = '%s', errno = %d", strerror(errno), errno);
return 1;
}
printf("superblock: bytenr=%llu, device=%s\n", sb_bytenr, filename);
printf("---------------------------------------------------------\n");
if (btrfs_super_magic(sb) != BTRFS_MAGIC && !force) {
- fprintf(stderr,
- "ERROR: bad magic on superblock on %s at %llu\n",
- filename, (unsigned long long)sb_bytenr);
+ error("bad magic on superblock on %s at %llu",
+ filename, (unsigned long long)sb_bytenr);
} else {
dump_superblock(sb, full);
}
case 'i':
arg = arg_strtou64(optarg);
if (arg >= BTRFS_SUPER_MIRROR_MAX) {
- fprintf(stderr,
- "Illegal super_mirror %llu\n",
- arg);
+ error("super mirror too big: %llu >= %d",
+ arg, BTRFS_SUPER_MIRROR_MAX);
usage(cmd_inspect_dump_super_usage);
}
sb_bytenr = btrfs_sb_offset(arg);
filename = argv[i];
fd = open(filename, O_RDONLY, 0666);
if (fd < 0) {
- fprintf(stderr, "Could not open %s\n", filename);
+ error("cannot open %s: %s", filename, strerror(errno));
ret = 1;
goto out;
}
ret = check_arg_type(argv[optind]);
if (ret != BTRFS_ARG_BLKDEV && ret != BTRFS_ARG_REG) {
- fprintf(stderr, "'%s' is not a block device or regular file\n",
- argv[optind]);
+ error("not a block device or regular file: %s", argv[optind]);
goto out;
}
info = open_ctree_fs_info(argv[optind], 0, 0, OPEN_CTREE_PARTIAL);
if (!info) {
- fprintf(stderr, "unable to open %s\n", argv[optind]);
+ error("unable to open %s", argv[optind]);
goto out;
}
root = info->fs_root;
if (!root) {
- fprintf(stderr, "unable to open %s\n", argv[optind]);
+ error("unable to open %s", argv[optind]);
goto out;
}
root->nodesize, 0);
}
if (!extent_buffer_uptodate(leaf)) {
- fprintf(stderr, "failed to read %llu\n",
+ error("failed to read %llu",
(unsigned long long)block_only);
goto close_root;
}
ret = ioctl(fd, BTRFS_IOC_INO_PATHS, &ipa);
if (ret < 0) {
- printf("ioctl ret=%d, error: %s\n", ret, strerror(errno));
+ error("ino paths ioctl: %s", strerror(errno));
goto out;
}
ret = ioctl(fd, BTRFS_IOC_LOGICAL_INO, &loi);
if (ret < 0) {
- printf("ioctl ret=%d, error: %s\n", ret, strerror(errno));
+ error("logical ino ioctl: %s", strerror(errno));
goto out;
}
ret = btrfs_subvolid_resolve(fd, path, sizeof(path), subvol_id);
if (ret) {
- fprintf(stderr,
- "btrfs_subvolid_resolve(subvol_id %llu) failed with ret=%d\n",
+ error("resolving subvolid %llu error %d",
(unsigned long long)subvol_id, ret);
goto out;
}
ret = lookup_ino_rootid(fd, &rootid);
if (ret) {
- fprintf(stderr, "rootid failed with ret=%d\n", ret);
+ error("rootid failed with ret=%d", ret);
goto out;
}
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
if (ret < 0) {
- fprintf(stderr,
- "Error invoking tree search ioctl: %s\n",
- strerror(errno));
+ error("tree search ioctl: %s", strerror(errno));
ret = 1;
goto out;
}
ret = add_dev_extent(&holes, last_pos,
sh->offset - 1, 1);
if (ret) {
- fprintf(stderr, "Error: %s\n", strerror(-ret));
+ error("add device extent: %s", strerror(-ret));
ret = 1;
goto out;
}