static void csum_block(u8 *buf, size_t len)
{
- u8 result[BTRFS_CRC32_SIZE];
+ u8 result[btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32]];
u32 crc = ~(u32)0;
crc = crc32c(crc, buf + BTRFS_CSUM_SIZE, len - BTRFS_CSUM_SIZE);
btrfs_csum_final(crc, result);
- memcpy(buf, result, BTRFS_CRC32_SIZE);
+ memcpy(buf, result, btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32]);
}
static int has_name(struct btrfs_key *key)
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);
}
}