[PATCHv2] ext4: Fix support for empty directory blocks in 64k blocksize filesystems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The rec_len field in the directory entry is 16 bits, so if the
filesystem is completely empty, rec_len of 0 is used to designate
65536 in e2fsprogs, for the case where the directory entry takes
the entire 64k block.

But if empty directory is read, error message will be output by
current kernel. You can do the following commands to reproduct it.

  - mkfs.ext4 -b $(( 64 * 1024 )) /dev/sdc1
  - mount -t ext4 /dev/sda1 /mnt
  - cd /mnt/lost+found
  - ll
  - tail /var/log/messages
  EXT4-fs error (device sdc1): ext4_readdir: bad entry in \
  directory #11: rec_len is smaller than minimal - offset=0, \
  inode=0, rec_len=0, name_len=0

This patch fix to treat rec_len of 0 as 65536, like what e2fsprogs do.

Signed-off-by: Wei Yongjun <yjwei@xxxxxxxxxxxxxx>
---
 fs/ext4/ext4.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index aafc9eb..c64ab94 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -868,7 +868,7 @@ static inline unsigned ext4_rec_len_from_disk(__le16 dlen)
 {
 	unsigned len = le16_to_cpu(dlen);
 
-	if (len == EXT4_MAX_REC_LEN)
+	if (len == EXT4_MAX_REC_LEN || len == 0)
 		return 1 << 16;
 	return len;
 }
@@ -876,7 +876,7 @@ static inline unsigned ext4_rec_len_from_disk(__le16 dlen)
 static inline __le16 ext4_rec_len_to_disk(unsigned len)
 {
 	if (len == (1 << 16))
-		return cpu_to_le16(EXT4_MAX_REC_LEN);
+		return cpu_to_le16(0);
 	else if (len > (1 << 16))
 		BUG();
 	return cpu_to_le16(len);
-- 
1.5.3.8



--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux