summaryrefslogtreecommitdiff
path: root/check
diff options
context:
space:
mode:
Diffstat (limited to 'check')
-rw-r--r--check/main.c61
-rw-r--r--check/mode-common.c8
-rw-r--r--check/mode-lowmem.c43
3 files changed, 67 insertions, 45 deletions
diff --git a/check/main.c b/check/main.c
index 79d222d5..5733afb4 100644
--- a/check/main.c
+++ b/check/main.c
@@ -2291,9 +2291,9 @@ static int repair_inode_nlinks(struct btrfs_trans_handle *trans,
ret = reset_nlink(trans, root, path, rec);
if (ret < 0) {
+ errno = -ret;
fprintf(stderr,
- "Failed to reset nlink for inode %llu: %s\n",
- rec->ino, strerror(-ret));
+ "Failed to reset nlink for inode %llu: %m\n", rec->ino);
goto out;
}
@@ -3170,8 +3170,8 @@ static int repair_btree(struct btrfs_root *root,
trans = btrfs_start_transaction(root, 1);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
- fprintf(stderr, "Error starting transaction: %s\n",
- strerror(-ret));
+ errno = -ret;
+ fprintf(stderr, "Error starting transaction: %m\n");
return ret;
}
btrfs_init_path(&path);
@@ -3363,8 +3363,8 @@ skip_walking:
root->root_key.objectid);
ret = repair_btree(root, &corrupt_blocks);
if (ret < 0)
- fprintf(stderr, "Failed to repair btree: %s\n",
- strerror(-ret));
+ errno = -ret;
+ fprintf(stderr, "Failed to repair btree: %m\n");
if (!ret)
printf("Btree for root %llu is fixed\n",
root->root_key.objectid);
@@ -5177,18 +5177,20 @@ static int process_extent_item(struct btrfs_root *root,
case BTRFS_TREE_BLOCK_REF_KEY:
ret = add_tree_backref(extent_cache, key.objectid,
0, offset, 0);
- if (ret < 0)
+ if (ret < 0) {
+ errno = -ret;
error(
- "add_tree_backref failed (extent items tree block): %s",
- strerror(-ret));
+ "add_tree_backref failed (extent items tree block): %m");
+ }
break;
case BTRFS_SHARED_BLOCK_REF_KEY:
ret = add_tree_backref(extent_cache, key.objectid,
offset, 0, 0);
- if (ret < 0)
+ if (ret < 0) {
+ errno = -ret;
error(
- "add_tree_backref failed (extent items shared block): %s",
- strerror(-ret));
+ "add_tree_backref failed (extent items shared block): %m");
+ }
break;
case BTRFS_EXTENT_DATA_REF_KEY:
dref = (struct btrfs_extent_data_ref *)(&iref->offset);
@@ -5420,16 +5422,18 @@ static int check_space_cache(struct btrfs_root *root)
if (btrfs_fs_compat_ro(root->fs_info, FREE_SPACE_TREE)) {
ret = exclude_super_stripes(root, cache);
if (ret) {
- fprintf(stderr, "could not exclude super stripes: %s\n",
- strerror(-ret));
+ errno = -ret;
+ fprintf(stderr,
+ "could not exclude super stripes: %m\n");
error++;
continue;
}
ret = load_free_space_tree(root->fs_info, cache);
free_excluded_extents(root, cache);
if (ret < 0) {
- fprintf(stderr, "could not load free space tree: %s\n",
- strerror(-ret));
+ errno = -ret;
+ fprintf(stderr,
+ "could not load free space tree: %m\n");
error++;
continue;
}
@@ -6122,19 +6126,21 @@ static int run_next_block(struct btrfs_root *root,
if (key.type == BTRFS_TREE_BLOCK_REF_KEY) {
ret = add_tree_backref(extent_cache,
key.objectid, 0, key.offset, 0);
- if (ret < 0)
+ if (ret < 0) {
+ errno = -ret;
error(
- "add_tree_backref failed (leaf tree block): %s",
- strerror(-ret));
+ "add_tree_backref failed (leaf tree block): %m");
+ }
continue;
}
if (key.type == BTRFS_SHARED_BLOCK_REF_KEY) {
ret = add_tree_backref(extent_cache,
key.objectid, key.offset, 0, 0);
- if (ret < 0)
+ if (ret < 0) {
+ errno = -ret;
error(
- "add_tree_backref failed (leaf shared block): %s",
- strerror(-ret));
+ "add_tree_backref failed (leaf shared block): %m");
+ }
continue;
}
if (key.type == BTRFS_EXTENT_DATA_REF_KEY) {
@@ -6236,9 +6242,9 @@ static int run_next_block(struct btrfs_root *root,
ret = add_tree_backref(extent_cache, ptr, parent,
owner, 1);
if (ret < 0) {
+ errno = -ret;
error(
- "add_tree_backref failed (non-leaf block): %s",
- strerror(-ret));
+ "add_tree_backref failed (non-leaf block): %m");
continue;
}
@@ -9678,8 +9684,8 @@ int cmd_check(int argc, char **argv)
ret = check_mounted(argv[optind]);
if (!force) {
if (ret < 0) {
- error("could not check mount status: %s",
- strerror(-ret));
+ errno = -ret;
+ error("could not check mount status: %m");
err |= !!ret;
goto err_out;
} else if (ret) {
@@ -9856,7 +9862,8 @@ int cmd_check(int argc, char **argv)
task_stop(ctx.info);
if (ret < 0) {
err = !!ret;
- error("failed to repair root items: %s", strerror(-ret));
+ errno = -ret;
+ error("failed to repair root items: %m");
goto close_out;
}
if (repair) {
diff --git a/check/mode-common.c b/check/mode-common.c
index 15e2bbd1..005be8a3 100644
--- a/check/mode-common.c
+++ b/check/mode-common.c
@@ -450,7 +450,8 @@ int link_inode_to_lostfound(struct btrfs_trans_handle *trans,
BTRFS_FIRST_FREE_OBJECTID, &lost_found_ino,
mode);
if (ret < 0) {
- error("failed to create '%s' dir: %s", dir_name, strerror(-ret));
+ errno = -ret;
+ error("failed to create '%s' dir: %m", dir_name);
goto out;
}
ret = btrfs_add_link(trans, root, ino, lost_found_ino,
@@ -474,8 +475,9 @@ int link_inode_to_lostfound(struct btrfs_trans_handle *trans,
name_len, filetype, NULL, 1, 0);
}
if (ret < 0) {
- error("failed to link the inode %llu to %s dir: %s",
- ino, dir_name, strerror(-ret));
+ errno = -ret;
+ error("failed to link the inode %llu to %s dir: %m",
+ ino, dir_name);
goto out;
}
diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 427b2fe4..14bbc9ee 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -284,7 +284,8 @@ static int modify_block_groups_cache(struct btrfs_fs_info *fs_info, u64 flags,
btrfs_init_path(&path);
ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
if (ret < 0) {
- error("fail to search block groups due to %s", strerror(-ret));
+ errno = -ret;
+ error("fail to search block groups due to %m");
goto out;
}
@@ -341,19 +342,22 @@ static int create_chunk_and_block_group(struct btrfs_fs_info *fs_info,
trans = btrfs_start_transaction(root, 1);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
- error("error starting transaction %s", strerror(-ret));
+ errno = -ret;
+ error("error starting transaction %m");
return ret;
}
ret = btrfs_alloc_chunk(trans, fs_info, start, nbytes, flags);
if (ret) {
- error("fail to allocate new chunk %s", strerror(-ret));
+ errno = -ret;
+ error("fail to allocate new chunk %m");
goto out;
}
ret = btrfs_make_block_group(trans, fs_info, 0, flags, *start,
*nbytes);
if (ret) {
- error("fail to make block group for chunk %llu %llu %s",
- *start, *nbytes, strerror(-ret));
+ errno = -ret;
+ error("fail to make block group for chunk %llu %llu %m",
+ *start, *nbytes);
goto out;
}
out:
@@ -521,8 +525,10 @@ static int avoid_extents_overwrite(struct btrfs_fs_info *fs_info)
"Try to exclude all metadata blcoks and extents, it may be slow\n");
ret = exclude_metadata_blocks(fs_info);
out:
- if (ret)
- error("failed to avoid extents overwrite %s", strerror(-ret));
+ if (ret) {
+ errno = -ret;
+ error("failed to avoid extents overwrite %m");
+ }
return ret;
}
@@ -552,7 +558,8 @@ static int repair_block_accounting(struct btrfs_fs_info *fs_info)
trans = btrfs_start_transaction(root, 1);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
- error("fail to start transaction %s", strerror(-ret));
+ errno = -ret;
+ error("fail to start transaction: %m");
return ret;
}
@@ -629,7 +636,8 @@ static int repair_tree_block_ref(struct btrfs_root *root,
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
trans = NULL;
- error("fail to start transaction %s", strerror(-ret));
+ errno = -ret;
+ error("fail to start transaction: %m");
goto out;
}
/* insert an extent item */
@@ -701,9 +709,10 @@ out:
btrfs_commit_transaction(trans, extent_root);
btrfs_release_path(&path);
if (ret) {
+ errno = -ret;
error(
- "failed to repair tree block ref start %llu root %llu due to %s",
- bytenr, root->objectid, strerror(-ret));
+ "failed to repair tree block ref start %llu root %llu due to %m",
+ bytenr, root->objectid);
} else {
printf("Added one tree block ref start %llu %s %llu\n",
bytenr, parent ? "parent" : "root",
@@ -3006,7 +3015,8 @@ static int repair_extent_data_item(struct btrfs_root *root,
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
trans = NULL;
- error("fail to start transaction %s", strerror(-ret));
+ errno = -ret;
+ error("fail to start transaction: %m");
goto out;
}
/* insert an extent item */
@@ -3820,7 +3830,8 @@ static int repair_extent_item(struct btrfs_root *root, struct btrfs_path *path,
trans = btrfs_start_transaction(extent_root, 1);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
- error("fail to start transaction %s", strerror(-ret));
+ errno = -ret;
+ error("fail to start transaction: %m");
/* nothing happened */
ret = 0;
goto out;
@@ -4281,7 +4292,8 @@ static int repair_chunk_item(struct btrfs_root *chunk_root,
trans = btrfs_start_transaction(extent_root, 1);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
- error("fail to start transaction %s", strerror(-ret));
+ errno = -ret;
+ error("fail to start transaction: %m");
return ret;
}
@@ -4316,7 +4328,8 @@ static int delete_extent_tree_item(struct btrfs_root *root,
trans = btrfs_start_transaction(root, 1);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
- error("fail to start transaction %s", strerror(-ret));
+ errno = -ret;
+ error("fail to start transaction: %m");
goto out;
}
btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);