Skip to content

Commit f8f484d

Browse files
author
Tyler Hicks
committed
eCryptfs: Add getattr function
The i_blocks field of an eCryptfs inode cannot be trusted, but generic_fillattr() uses it to instantiate the blocks field of a stat() syscall when a filesystem doesn't implement its own getattr(). Users have noticed that the output of du is incorrect on newly created files. This patch creates ecryptfs_getattr() which calls into the lower filesystem's getattr() so that eCryptfs can use its kstat.blocks value after calling generic_fillattr(). It is important to note that the block count includes the eCryptfs metadata stored in the beginning of the lower file plus any padding used to fill an extent before encryption. https://bugs.launchpad.net/ecryptfs/+bug/390833 Reported-by: Dominic Sacré <dominic.sacre@gmx.de> Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com>
1 parent 5f3ef64 commit f8f484d

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎fs/ecryptfs/inode.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,21 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)
10061006
return rc;
10071007
}
10081008

1009+
int ecryptfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1010+
struct kstat *stat)
1011+
{
1012+
struct kstat lower_stat;
1013+
int rc;
1014+
1015+
rc = vfs_getattr(ecryptfs_dentry_to_lower_mnt(dentry),
1016+
ecryptfs_dentry_to_lower(dentry), &lower_stat);
1017+
if (!rc) {
1018+
generic_fillattr(dentry->d_inode, stat);
1019+
stat->blocks = lower_stat.blocks;
1020+
}
1021+
return rc;
1022+
}
1023+
10091024
int
10101025
ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value,
10111026
size_t size, int flags)
@@ -1135,6 +1150,7 @@ const struct inode_operations ecryptfs_dir_iops = {
11351150
const struct inode_operations ecryptfs_main_iops = {
11361151
.permission = ecryptfs_permission,
11371152
.setattr = ecryptfs_setattr,
1153+
.getattr = ecryptfs_getattr,
11381154
.setxattr = ecryptfs_setxattr,
11391155
.getxattr = ecryptfs_getxattr,
11401156
.listxattr = ecryptfs_listxattr,

0 commit comments

Comments
 (0)