From: Boris Burkov <boris@bur.io>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH v4 1/4] btrfs-corrupt-block: define (u64)-1 as UNSET_U64
Date: Tue, 26 Jul 2022 13:43:22 -0700 [thread overview]
Message-ID: <d2ddc9d1cae29816a103c4c623398bbf4d23e4dc.1658867979.git.boris@bur.io> (raw)
In-Reply-To: <cover.1658867979.git.boris@bur.io>
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 --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)
--
2.37.1
next prev parent reply other threads:[~2022-07-26 20:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-26 20:43 [PATCH v4 0/4] btrfs-progs: support for fs-verity fstests Boris Burkov
2022-07-26 20:43 ` Boris Burkov [this message]
2022-07-26 20:43 ` [PATCH v4 2/4] btrfs-progs: corrupt generic item data with btrfs-corrupt-block Boris Burkov
2022-07-26 20:43 ` [PATCH v4 3/4] btrfs-progs: expand corrupt_file_extent in btrfs-corrupt-block Boris Burkov
2022-07-26 20:43 ` [PATCH v4 4/4] btrfs-progs: add VERITY ro compat flag Boris Burkov
2022-07-27 18:53 ` [PATCH v4 0/4] btrfs-progs: support for fs-verity fstests David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d2ddc9d1cae29816a103c4c623398bbf4d23e4dc.1658867979.git.boris@bur.io \
--to=boris@bur.io \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).