mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-06 05:13:18 +00:00
fs: add vfs_setpos_cookie()
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>
This commit is contained in:
parent
1c5a54af47
commit
d095a5be75
@ -39,6 +39,34 @@ static inline bool unsigned_offsets(struct file *file)
|
|||||||
return file->f_mode & FMODE_UNSIGNED_OFFSET;
|
return file->f_mode & FMODE_UNSIGNED_OFFSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
if (offset > maxsize)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (offset != file->f_pos) {
|
||||||
|
file->f_pos = offset;
|
||||||
|
*cookie = 0;
|
||||||
|
}
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* vfs_setpos - update the file offset for lseek
|
* vfs_setpos - update the file offset for lseek
|
||||||
* @file: file structure in question
|
* @file: file structure in question
|
||||||
@ -53,16 +81,7 @@ static inline bool unsigned_offsets(struct file *file)
|
|||||||
*/
|
*/
|
||||||
loff_t vfs_setpos(struct file *file, loff_t offset, loff_t maxsize)
|
loff_t vfs_setpos(struct file *file, loff_t offset, loff_t maxsize)
|
||||||
{
|
{
|
||||||
if (offset < 0 && !unsigned_offsets(file))
|
return vfs_setpos_cookie(file, offset, maxsize, &file->f_version);
|
||||||
return -EINVAL;
|
|
||||||
if (offset > maxsize)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
if (offset != file->f_pos) {
|
|
||||||
file->f_pos = offset;
|
|
||||||
file->f_version = 0;
|
|
||||||
}
|
|
||||||
return offset;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(vfs_setpos);
|
EXPORT_SYMBOL(vfs_setpos);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user