]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
fs: add vfs_setpos_cookie()
authorChristian Brauner <brauner@kernel.org>
Fri, 30 Aug 2024 13:04:46 +0000 (15:04 +0200)
committerChristian Brauner <brauner@kernel.org>
Mon, 9 Sep 2024 09:58:07 +0000 (11:58 +0200)
Add a new helper and make vfs_setpos() call it. We will use it in
follow-up patches.

Link: https://lore.kernel.org/r/20240830-vfs-file-f_version-v1-5-6d3e4816aa7b@kernel.org
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/read_write.c

index 90e283b31ca18195ff8c6a5cc4becbaa333d9f91..66ff52860496c14cfd38ac6235db26481086d86b 100644 (file)
@@ -40,18 +40,20 @@ static inline bool unsigned_offsets(struct file *file)
 }
 
 /**
- * vfs_setpos - update the file offset for lseek
+ * vfs_setpos_cookie - update the file offset for lseek and reset cookie
  * @file:      file structure in question
  * @offset:    file offset to seek to
  * @maxsize:   maximum file size
+ * @cookie:    cookie to reset
  *
- * This is a low-level filesystem helper for updating the file offset to
- * the value specified by @offset if the given offset is valid and it is
- * not equal to the current file offset.
+ * Update the file offset to the value specified by @offset if the given
+ * offset is valid and it is not equal to the current file offset and
+ * reset the specified cookie to indicate that a seek happened.
  *
  * Return the specified offset on success and -EINVAL on invalid offset.
  */
-loff_t vfs_setpos(struct file *file, loff_t offset, loff_t maxsize)
+static loff_t vfs_setpos_cookie(struct file *file, loff_t offset,
+                               loff_t maxsize, u64 *cookie)
 {
        if (offset < 0 && !unsigned_offsets(file))
                return -EINVAL;
@@ -60,10 +62,27 @@ loff_t vfs_setpos(struct file *file, loff_t offset, loff_t maxsize)
 
        if (offset != file->f_pos) {
                file->f_pos = offset;
-               file->f_version = 0;
+               *cookie = 0;
        }
        return offset;
 }
+
+/**
+ * vfs_setpos - update the file offset for lseek
+ * @file:      file structure in question
+ * @offset:    file offset to seek to
+ * @maxsize:   maximum file size
+ *
+ * This is a low-level filesystem helper for updating the file offset to
+ * the value specified by @offset if the given offset is valid and it is
+ * not equal to the current file offset.
+ *
+ * Return the specified offset on success and -EINVAL on invalid offset.
+ */
+loff_t vfs_setpos(struct file *file, loff_t offset, loff_t maxsize)
+{
+       return vfs_setpos_cookie(file, offset, maxsize, &file->f_version);
+}
 EXPORT_SYMBOL(vfs_setpos);
 
 /**