linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* ext2: Fix support for empty directory blocks in 64k blocksize filesystems
@ 2009-02-10  8:39 Wei Yongjun
  0 siblings, 0 replies; only message in thread
From: Wei Yongjun @ 2009-02-10  8:39 UTC (permalink / raw)
  To: linux-ext4, Andrew Morton

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.ext2 -b $(( 64 * 1024 )) /dev/sdc1
  - mount /dev/sda1 /mnt
  - cd /mnt/lost+found
  - ll
  - tail /var/log/messages
  EXT2-fs error (device sdc1): ext2_check_page: bad entry in \
  directory #11: : rec_len is smaller than minimal - offset=65536, \
  inode=0, rec_len=0, name_len=0
  EXT2-fs error (device sdc1): ext2_readdir: bad page in #11

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

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
---
 fs/ext2/dir.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c
index 2999d72..d10907d 100644
--- a/fs/ext2/dir.c
+++ b/fs/ext2/dir.c
@@ -32,7 +32,7 @@ static inline unsigned ext2_rec_len_from_disk(__le16 dlen)
 {
 	unsigned len = le16_to_cpu(dlen);
 
-	if (len == EXT2_MAX_REC_LEN)
+	if (len == EXT2_MAX_REC_LEN || len == 0)
 		return 1 << 16;
 	return len;
 }
@@ -40,7 +40,7 @@ static inline unsigned ext2_rec_len_from_disk(__le16 dlen)
 static inline __le16 ext2_rec_len_to_disk(unsigned len)
 {
 	if (len == (1 << 16))
-		return cpu_to_le16(EXT2_MAX_REC_LEN);
+		return cpu_to_le16(0);
 	else
 		BUG_ON(len > (1 << 16));
 	return cpu_to_le16(len);
-- 
1.5.3.8




^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2009-02-10  8:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-10  8:39 ext2: Fix support for empty directory blocks in 64k blocksize filesystems Wei Yongjun

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).