ext2: a zero block number is actually legit
authorH. Peter Anvin <hpa@zytor.com>
Tue, 16 Feb 2010 21:57:30 +0000 (13:57 -0800)
committerH. Peter Anvin <hpa@zytor.com>
Tue, 16 Feb 2010 21:57:30 +0000 (13:57 -0800)
It may not happen in normal operation, but a zero block value is legit
and means an all-zero block.  For anything which uses the cache, we
have dealt with that by always keeping a zero block in the cache.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
core/fs/ext2/ext2.c

index bc75824..5254340 100644 (file)
@@ -184,8 +184,7 @@ ext2_find_entry(struct fs_info *fs, struct inode *inode, const char *dname)
     size_t dname_len = strlen(dname);
 
     while (i < inode->size) {
-       if (!(block = ext2_bmap(inode, index++)))
-           return NULL;
+       block = ext2_bmap(inode, index++);
        data = get_cache(fs->fs_dev, block);
        offset = 0;
        maxoffset =  min(BLOCK_SIZE(fs), i-inode->size);
@@ -323,8 +322,10 @@ static struct dirent * ext2_readdir(struct file *file)
     block_t index = file->offset >> fs->block_shift;
     block_t block;
 
-    if (!(block = ext2_bmap(inode, index)))
-       return NULL;
+    if (file->offset >= inode->size)
+       return NULL;            /* End of file */
+
+    block = ext2_bmap(inode, index);
 
     data = get_cache(fs->fs_dev, block);
     de = (const struct ext2_dir_entry *)