diff mbox series

[v4,1/4] btrfs-corrupt-block: define (u64)-1 as UNSET_U64

Message ID d2ddc9d1cae29816a103c4c623398bbf4d23e4dc.1658867979.git.boris@bur.io (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: support for fs-verity fstests | expand

Commit Message

Boris Burkov July 26, 2022, 8:43 p.m. UTC
we use this placeholder for many inputs in this script, so give it a
name for clarity.

Signed-off-by: Boris Burkov <boris@bur.io>
Reviewed-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
---
 btrfs-corrupt-block.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index e961255d5..b826c9c2e 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -35,6 +35,7 @@ 
 #include "common/help.h"
 
 #define FIELD_BUF_LEN 80
+#define UNSET_U64 ((u64)-1)
 
 static int debug_corrupt_block(struct extent_buffer *eb,
 		struct btrfs_root *root, u64 bytenr, u32 blocksize, u64 copy)
@@ -180,7 +181,7 @@  static int corrupt_extent(struct btrfs_trans_handle *trans,
 
 	key.objectid = bytenr;
 	key.type = (u8)-1;
-	key.offset = (u64)-1;
+	key.offset = UNSET_U64;
 
 	extent_root = btrfs_extent_root(trans->fs_info, bytenr);
 	while(1) {
@@ -664,7 +665,7 @@  static int corrupt_inode(struct btrfs_trans_handle *trans,
 
 	key.objectid = inode;
 	key.type = BTRFS_INODE_ITEM_KEY;
-	key.offset = (u64)-1;
+	key.offset = UNSET_U64;
 
 	path = btrfs_alloc_path();
 	if (!path)
@@ -880,7 +881,7 @@  static int corrupt_metadata_block(struct btrfs_fs_info *fs_info, u64 block,
 
 		root_key.objectid = root_objectid;
 		root_key.type = BTRFS_ROOT_ITEM_KEY;
-		root_key.offset = (u64)-1;
+		root_key.offset = UNSET_U64;
 
 		root = btrfs_read_fs_root(fs_info, &root_key);
 		if (IS_ERR(root)) {
@@ -1084,8 +1085,8 @@  static int corrupt_chunk_tree(struct btrfs_trans_handle *trans,
 	if (!path)
 		return -ENOMEM;
 
-	key.objectid = (u64)-1;
-	key.offset = (u64)-1;
+	key.objectid = UNSET_U64;
+	key.offset = UNSET_U64;
 	key.type = (u8)-1;
 
 	/* Here, cow and ins_len must equals 0 for the following reasons:
@@ -1193,7 +1194,7 @@  static struct btrfs_root *open_root(struct btrfs_fs_info *fs_info,
 
 	root_key.objectid = root_objectid;
 	root_key.type = BTRFS_ROOT_ITEM_KEY;
-	root_key.offset = (u64)-1;
+	root_key.offset = UNSET_U64;
 
 	root = btrfs_read_fs_root(fs_info, &root_key);
 	if (IS_ERR(root)) {
@@ -1209,8 +1210,8 @@  int main(int argc, char **argv)
 	struct btrfs_key key;
 	struct btrfs_root *root, *target_root;
 	char *dev;
-	/* chunk offset can be 0,so change to (u64)-1 */
-	u64 logical = (u64)-1;
+	/* chunk offset can be 0,so change to UNSET_U64 */
+	u64 logical = UNSET_U64;
 	int ret = 0;
 	u64 copy = 0;
 	u64 bytes = 4096;
@@ -1225,7 +1226,7 @@  int main(int argc, char **argv)
 	int should_corrupt_key = 0;
 	u64 metadata_block = 0;
 	u64 inode = 0;
-	u64 file_extent = (u64)-1;
+	u64 file_extent = UNSET_U64;
 	u64 root_objectid = 0;
 	u64 csum_bytenr = 0;
 	u64 block_group = 0;
@@ -1353,7 +1354,7 @@  int main(int argc, char **argv)
 	if (extent_rec) {
 		struct btrfs_trans_handle *trans;
 
-		if (logical == (u64)-1)
+		if (logical == UNSET_U64)
 			print_usage(1);
 		trans = btrfs_start_transaction(root, 1);
 		BUG_ON(IS_ERR(trans));
@@ -1378,7 +1379,7 @@  int main(int argc, char **argv)
 		struct btrfs_path *path;
 		int del;
 
-		if (logical == (u64)-1)
+		if (logical == UNSET_U64)
 			print_usage(1);
 		del = rand_range(3);
 		path = btrfs_alloc_path();
@@ -1420,7 +1421,7 @@  int main(int argc, char **argv)
 
 		trans = btrfs_start_transaction(root, 1);
 		BUG_ON(IS_ERR(trans));
-		if (file_extent == (u64)-1) {
+		if (file_extent == UNSET_U64) {
 			printf("corrupting inode\n");
 			ret = corrupt_inode(trans, root, inode, field);
 		} else {
@@ -1481,10 +1482,10 @@  int main(int argc, char **argv)
 	 * If we made it here and we have extent set then we didn't specify
 	 * inode and we're screwed.
 	 */
-	if (file_extent != (u64)-1)
+	if (file_extent != UNSET_U64)
 		print_usage(1);
 
-	if (logical == (u64)-1)
+	if (logical == UNSET_U64)
 		print_usage(1);
 
 	if (bytes == 0)