Skip to contentSkip to conversation

debugfs: byteswap dirsearch dirent buf on big endian systems

PATCH Applied Brian Foster 3 participants 4 messages Jan 23, 2025 – May 21, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 debugfs: byteswap dirsearch dirent buf on big endian systems

fstests test ext4/048 fails on big endian systems due to broken debugfs dirsearch functionality. On an s390x system and 4k block size, the dirsearch command seems to hang indefinitely. On the same system with a 1k block size, the command fails to locate an existing entry and causes the test to fail due to unexpected results.

The cause of the dirsearch failure is lack of byte swapping of the on-disk (little endian) dirent buffer before attempting to iterate entries in the given block. This leads to garbage record and name length values, for example. To resolve this problem, byte swap the directory buffer on big endian systems.

---

Hi all,

I'm not terribly familiar with this code, but this fixes the test and doesn't show any regressions from fstests runs on big or little endian systems. Thanks.

Brian

 debugfs/htree.c | 6 ++++++
 1 file changed, 6 insertions(+)
debugfs/htree.c +6 -0
index a1008150..4ea8f30b 100644
@@ -482,6 +482,12 @@ static int search_dir_block(ext2_filsys fs, blk64_t *blocknr,
 		return BLOCK_ABORT;
 	}
 
+#ifdef WORDS_BIGENDIAN
+	errcode = ext2fs_dirent_swab_in(fs, p->buf, 0);
+	if (errcode)
+		return BLOCK_ABORT;
+#endif
+
 	while (offset < fs->blocksize) {
 		dirent = (struct ext2_dir_entry *) (p->buf + offset);
 		errcode = ext2fs_get_rec_len(fs, dirent, &rec_len);
Signature · 1 line
2.47.1
#1 lore raw
Quoted 12 lines · Brian Foster

fstests test ext4/048 fails on big endian systems due to broken debugfs dirsearch functionality. On an s390x system and 4k block size, the dirsearch command seems to hang indefinitely. On the same system with a 1k block size, the command fails to locate an existing entry and causes the test to fail due to unexpected results.

The cause of the dirsearch failure is lack of byte swapping of the on-disk (little endian) dirent buffer before attempting to iterate entries in the given block. This leads to garbage record and name length values, for example. To resolve this problem, byte swap the directory buffer on big endian systems.

Quoted 9 lines

---

Hi all,

I'm not terribly familiar with this code, but this fixes the test and doesn't show any regressions from fstests runs on big or little endian systems. Thanks.

Ping... curious if anybody has thoughts on this for dirsearch on big endian? Thanks!

Brian

Quoted 26 lines

Brian

 debugfs/htree.c | 6 ++++++
 1 file changed, 6 insertions(+)
debugfs/htree.c +6 -0
index a1008150..4ea8f30b 100644
@@ -482,6 +482,12 @@ static int search_dir_block(ext2_filsys fs, blk64_t *blocknr,
 		return BLOCK_ABORT;
 	}
 
+#ifdef WORDS_BIGENDIAN
+	errcode = ext2fs_dirent_swab_in(fs, p->buf, 0);
+	if (errcode)
+		return BLOCK_ABORT;
+#endif
+
 	while (offset < fs->blocksize) {
 		dirent = (struct ext2_dir_entry *) (p->buf + offset);
 		errcode = ext2fs_get_rec_len(fs, dirent, &rec_len);
Signature · 1 line
2.47.1
Reviewed-by
#2 lore raw
Quoted 18 lines · Brian Foster
Quoted 17 lines · Brian Foster

fstests test ext4/048 fails on big endian systems due to broken debugfs dirsearch functionality. On an s390x system and 4k block size, the dirsearch command seems to hang indefinitely. On the same system with a 1k block size, the command fails to locate an existing entry and causes the test to fail due to unexpected results.

The cause of the dirsearch failure is lack of byte swapping of the on-disk (little endian) dirent buffer before attempting to iterate entries in the given block. This leads to garbage record and name length values, for example. To resolve this problem, byte swap the directory buffer on big endian systems.

---

Hi all,

Quoted 7 lines
Quoted 4 lines

I'm not terribly familiar with this code, but this fixes the test and doesn't show any regressions from fstests runs on big or little endian systems. Thanks.

Ping... curious if anybody has thoughts on this for dirsearch on big endian? Thanks!

It looks correct to /me/... horrors of debugfs, etc. :(

--D

Quoted 31 lines

Brian

Quoted 26 lines

Brian

 debugfs/htree.c | 6 ++++++
 1 file changed, 6 insertions(+)
debugfs/htree.c +6 -0
index a1008150..4ea8f30b 100644
@@ -482,6 +482,12 @@ static int search_dir_block(ext2_filsys fs, blk64_t *blocknr,
 		return BLOCK_ABORT;
 	}
 
+#ifdef WORDS_BIGENDIAN
+	errcode = ext2fs_dirent_swab_in(fs, p->buf, 0);
+	if (errcode)
+		return BLOCK_ABORT;
+#endif
+
 	while (offset < fs->blocksize) {
 		dirent = (struct ext2_dir_entry *) (p->buf + offset);
 		errcode = ext2fs_get_rec_len(fs, dirent, &rec_len);
Signature · 1 line
2.47.1
#3 lore raw
In reply to Brian Foster
Quoted 6 lines · Brian Foster

fstests test ext4/048 fails on big endian systems due to broken debugfs dirsearch functionality. On an s390x system and 4k block size, the dirsearch command seems to hang indefinitely. On the same system with a 1k block size, the command fails to locate an existing entry and causes the test to fail due to unexpected results.

Quoted 7 lines

The cause of the dirsearch failure is lack of byte swapping of the on-disk (little endian) dirent buffer before attempting to iterate entries in the given block. This leads to garbage record and name length values, for example. To resolve this problem, byte swap the directory buffer on big endian systems.

[...]

Applied, thanks!

[1/1] debugfs: byteswap dirsearch dirent buf on big endian systems

      commit: 4be42019388d76c933e3b2ea80284aaf5b8eaecb

Best regards,

Signature · 1 line
Theodore Ts'o <[email protected]>