sdcardfs: don't depend on reserved_mb to check free space
Even if reserving nothing in sdcardfs, lower fs statfs info is still needed to avoid APP overwriting media storage. port (CR) from P. Change-Id: I63e87c3b34c739aeff2dcdd5e6fb3f34c4270cfa Signed-off-by: Shiyong Li <a22381@motorola.com> Reviewed-on: https://gerrit.mot.com/1435235 SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Reviewed-by: Igor Kovalenko <igork@motorola.com> Submit-Approved: Jira Key Reviewed-on: https://gerrit.mot.com/1531815 Reviewed-by: Zonghua Liu <a17671@motorola.com>
This commit is contained in:
parent
e9e73a5fb4
commit
bbc58b13f9
1 changed files with 25 additions and 28 deletions
|
@ -586,37 +586,34 @@ static inline int check_min_free_space(struct dentry *dentry, size_t size, int d
|
|||
u64 avail;
|
||||
struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
|
||||
|
||||
if (sbi->options.reserved_mb) {
|
||||
/* Get fs stat of lower filesystem. */
|
||||
sdcardfs_get_lower_path(dentry, &lower_path);
|
||||
err = vfs_statfs(&lower_path, &statfs);
|
||||
sdcardfs_put_lower_path(dentry, &lower_path);
|
||||
|
||||
if (unlikely(err))
|
||||
return 0;
|
||||
|
||||
/* Invalid statfs informations. */
|
||||
if (unlikely(statfs.f_bsize == 0))
|
||||
return 0;
|
||||
|
||||
/* if you are checking directory, set size to f_bsize. */
|
||||
if (unlikely(dir))
|
||||
size = statfs.f_bsize;
|
||||
|
||||
/* available size */
|
||||
avail = statfs.f_bavail * statfs.f_bsize;
|
||||
|
||||
/* not enough space */
|
||||
if ((u64)size > avail)
|
||||
return 0;
|
||||
|
||||
/* enough space */
|
||||
if ((avail - size) > (sbi->options.reserved_mb * 1024 * 1024))
|
||||
return 1;
|
||||
/* Get fs stat of lower filesystem. */
|
||||
sdcardfs_get_lower_path(dentry, &lower_path);
|
||||
err = vfs_statfs(&lower_path, &statfs);
|
||||
sdcardfs_put_lower_path(dentry, &lower_path);
|
||||
|
||||
if (unlikely(err))
|
||||
return 0;
|
||||
} else
|
||||
|
||||
/* Invalid statfs informations. */
|
||||
if (unlikely(statfs.f_bsize == 0))
|
||||
return 0;
|
||||
|
||||
/* if you are checking directory, set size to f_bsize. */
|
||||
if (unlikely(dir))
|
||||
size = statfs.f_bsize;
|
||||
|
||||
/* available size */
|
||||
avail = statfs.f_bavail * statfs.f_bsize;
|
||||
|
||||
/* not enough space */
|
||||
if ((u64)size > avail)
|
||||
return 0;
|
||||
|
||||
/* enough space */
|
||||
if ((avail - size) > (sbi->options.reserved_mb * 1024 * 1024))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue