kernel:fs:update inode size when do lseek
authorwangwang <wangwang1@lenovo.com>
Thu, 28 Mar 2019 03:27:36 +0000 (11:27 +0800)
committerlingsen1 <lingsen1@lenovo.com>
Sun, 7 Feb 2021 09:37:00 +0000 (17:37 +0800)
sdcardfs file node info was not updated when lowlevel file was updated
force to update the inode size when do lseek systemcall

Change-Id: I34802cc33f5cddd9dd8d304c5803cd0886805faf
Signed-off-by: wangwang <wangwang1@mt.com>
Reviewed-on: https://gerrit.mot.com/1328861
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Xiangpo Zhao <zhaoxp3@motorola.com>
Submit-Approved: Jira Key

fs/sdcardfs/file.c

index 271c4c4cb760f829af12cd810943e9580e4a2177..1ec39fd02bf04983f1de510bfd9c6546929e82c7 100644 (file)
@@ -372,6 +372,29 @@ out:
        return err;
 }
 
+static loff_t sdcardfs_wrapper_file_llseek(struct file *file, loff_t offset, int whence)
+{
+       loff_t pos;
+       struct dentry *dentry = file->f_path.dentry;
+       struct inode *inode = d_inode(dentry);
+       struct file *lower_file;
+
+       lower_file = sdcardfs_lower_file(file);
+
+       if (lower_file) {
+               if (sizeof(loff_t) > sizeof(long))
+                       inode_lock(inode);
+               fsstack_copy_inode_size(inode, file_inode(lower_file));
+               fsstack_copy_attr_times(inode, file_inode(lower_file));
+               if (sizeof(loff_t) > sizeof(long))
+                       inode_unlock(inode);
+       }
+       pos = generic_file_llseek(file, offset, whence);
+//     printk(KERN_ERR "sdcardfs file llseek %s, whence: %lld, returns:%lld\n", dentry->d_name.name, whence, pos);
+
+       return pos;
+}
+
 /*
  * Sdcardfs read_iter, redirect modified iocb to lower read_iter
  */
@@ -433,7 +456,7 @@ out:
 }
 
 const struct file_operations sdcardfs_main_fops = {
-       .llseek         = generic_file_llseek,
+       .llseek         = sdcardfs_wrapper_file_llseek,
        .read           = sdcardfs_read,
        .write          = sdcardfs_write,
        .unlocked_ioctl = sdcardfs_unlocked_ioctl,