ANDROID: sdcardfs: fix ->llseek to update upper and lower offset
authorDaniel Rosenberg <drosen@google.com>
Fri, 10 Mar 2017 05:42:01 +0000 (21:42 -0800)
committerStricted <info@stricted.net>
Thu, 11 Oct 2018 16:03:35 +0000 (18:03 +0200)
Adapted from wrapfs
commit 1d1d23a47baa ("Wrapfs: fix ->llseek to update upper and lower
offsets")

Fixes bug: xfstests generic/257. f_pos consistently is required by and
only by dir_ops->wrapfs_readdir, main_ops is not affected.

Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
Signed-off-by: Mengyang Li <li.mengyang@stonybrook.edu>
Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35766959
Change-Id: I360a1368ac37ea8966910a58972b81504031d437

Conflicts:
fs/sdcardfs/file.c

fs/sdcardfs/file.c

index 3ceac2b4d31c0469f434846bbf8760bc29df41f4..d8fa7476c432a7b563997e74bf194b4028c58d69 100644 (file)
@@ -320,6 +320,28 @@ static struct file *sdcardfs_get_lower_file(struct file *f)
        return sdcardfs_lower_file(f);
 }
 
+/*
+ * Sdcardfs cannot use generic_file_llseek as ->llseek, because it would
+ * only set the offset of the upper file.  So we have to implement our
+ * own method to set both the upper and lower file offsets
+ * consistently.
+ */
+static loff_t sdcardfs_file_llseek(struct file *file, loff_t offset, int whence)
+{
+       int err;
+       struct file *lower_file;
+
+       err = generic_file_llseek(file, offset, whence);
+       if (err < 0)
+               goto out;
+
+       lower_file = sdcardfs_lower_file(file);
+       err = generic_file_llseek(lower_file, offset, whence);
+
+out:
+       return err;
+}
+
 const struct file_operations sdcardfs_main_fops = {
        .llseek         = generic_file_llseek,
        .read           = sdcardfs_read,
@@ -339,7 +361,7 @@ const struct file_operations sdcardfs_main_fops = {
 
 /* trimmed directory options */
 const struct file_operations sdcardfs_dir_fops = {
-       .llseek         = generic_file_llseek,
+       .llseek         = sdcardfs_file_llseek,
        .read           = generic_read_dir,
        .iterate        = sdcardfs_readdir,
        .unlocked_ioctl = sdcardfs_unlocked_ioctl,