Skip to content

Commit

Permalink
ext4: return non-zero st_blocks for inline data
Browse files Browse the repository at this point in the history
Return a non-zero st_blocks to userspace for statfs() and friends.
Some versions of tar will assume that files with st_blocks == 0
do not contain any data and will skip reading them entirely.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
  • Loading branch information
Andreas Dilger authored and Theodore Ts'o committed Nov 12, 2013
1 parent dd1f723 commit 9206c56
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions fs/ext4/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -4693,6 +4693,15 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
inode = dentry->d_inode;
generic_fillattr(inode, stat);

/*
* If there is inline data in the inode, the inode will normally not
* have data blocks allocated (it may have an external xattr block).
* Report at least one sector for such files, so tools like tar, rsync,
* others doen't incorrectly think the file is completely sparse.
*/
if (unlikely(ext4_has_inline_data(inode)))
stat->blocks += (stat->size + 511) >> 9;

/*
* We can't update i_blocks if the block allocation is delayed
* otherwise in the case of system crash before the real block
Expand All @@ -4704,9 +4713,8 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
* blocks for this file.
*/
delalloc_blocks = EXT4_C2B(EXT4_SB(inode->i_sb),
EXT4_I(inode)->i_reserved_data_blocks);

stat->blocks += delalloc_blocks << (inode->i_sb->s_blocksize_bits-9);
EXT4_I(inode)->i_reserved_data_blocks);
stat->blocks += delalloc_blocks << (inode->i_sb->s_blocksize_bits - 9);
return 0;
}

Expand Down

0 comments on commit 9206c56

Please sign in to comment.