[PATCH 3/5] btrfs-progs: corrupt-block: allow corrupting dir item flags

Qu Wenruo <[email protected]>
Newsgroups org.kernel.vger.linux-btrfs
Message-ID <c8166f5de759a95c5426eed13264369bd0617e4b.1787045341.git.wqu@suse.com>
With this feature and the previous inode corruption, we can change the
type in inode item, dir item, dir index to be consistent with each
other.

Assisted-by: LLM (coding)
Signed-off-by: Qu Wenruo <[email protected]>
---
 btrfs-corrupt-block.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index 1e49f6ec50db..83910f1394f1 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -343,6 +343,7 @@ enum btrfs_file_extent_field {
 enum btrfs_dir_item_field {
 	BTRFS_DIR_ITEM_NAME,
 	BTRFS_DIR_ITEM_LOCATION_OBJECTID,
+	BTRFS_DIR_ITEM_FLAGS,
 	BTRFS_DIR_ITEM_BAD,
 };
 
@@ -448,6 +449,8 @@ static enum btrfs_dir_item_field convert_dir_item_field(char *field)
 		return BTRFS_DIR_ITEM_NAME;
 	if (strncmp(field, "location_objectid", FIELD_BUF_LEN) == 0)
 		return BTRFS_DIR_ITEM_LOCATION_OBJECTID;
+	if (strncmp(field, "flags", FIELD_BUF_LEN) == 0)
+		return BTRFS_DIR_ITEM_FLAGS;
 	return BTRFS_DIR_ITEM_BAD;
 }
 
@@ -683,6 +686,12 @@ static int corrupt_dir_item(struct btrfs_root *root, struct btrfs_key *key,
 		btrfs_set_dir_item_key(path->nodes[0], di, &disk_key);
 		btrfs_mark_buffer_dirty(path->nodes[0]);
 		goto out;
+	case BTRFS_DIR_ITEM_FLAGS:
+		if (bogus == (u64)-1)
+			bogus = generate_u8(btrfs_dir_flags(path->nodes[0], di));
+		btrfs_set_dir_flags(path->nodes[0], di, bogus);
+		btrfs_mark_buffer_dirty(path->nodes[0]);
+		goto out;
 	default:
 		ret = -EINVAL;
 		goto out;
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.