Skip to content

Commit 3a8cff4

Browse files
Christoph HellwigAl Viro
authored andcommitted
[PATCH] generic_file_llseek tidyups
Add kerneldoc for generic_file_llseek and generic_file_llseek_unlocked, use sane variable names and unclutter the code. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent a518ab9 commit 3a8cff4

1 file changed

Lines changed: 40 additions & 18 deletions

File tree

‎fs/read_write.c‎

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,61 @@ const struct file_operations generic_ro_fops = {
3131

3232
EXPORT_SYMBOL(generic_ro_fops);
3333

34+
/**
35+
* generic_file_llseek_unlocked - lockless generic llseek implementation
36+
* @file: file structure to seek on
37+
* @offset: file offset to seek to
38+
* @origin: type of seek
39+
*
40+
* Updates the file offset to the value specified by @offset and @origin.
41+
* Locking must be provided by the caller.
42+
*/
3443
loff_t
3544
generic_file_llseek_unlocked(struct file *file, loff_t offset, int origin)
3645
{
37-
loff_t retval;
3846
struct inode *inode = file->f_mapping->host;
3947

4048
switch (origin) {
41-
case SEEK_END:
42-
offset += inode->i_size;
43-
break;
44-
case SEEK_CUR:
45-
offset += file->f_pos;
49+
case SEEK_END:
50+
offset += inode->i_size;
51+
break;
52+
case SEEK_CUR:
53+
offset += file->f_pos;
54+
break;
4655
}
47-
retval = -EINVAL;
48-
if (offset>=0 && offset<=inode->i_sb->s_maxbytes) {
49-
/* Special lock needed here? */
50-
if (offset != file->f_pos) {
51-
file->f_pos = offset;
52-
file->f_version = 0;
53-
}
54-
retval = offset;
56+
57+
if (offset < 0 || offset > inode->i_sb->s_maxbytes)
58+
return -EINVAL;
59+
60+
/* Special lock needed here? */
61+
if (offset != file->f_pos) {
62+
file->f_pos = offset;
63+
file->f_version = 0;
5564
}
56-
return retval;
65+
66+
return offset;
5767
}
5868
EXPORT_SYMBOL(generic_file_llseek_unlocked);
5969

70+
/**
71+
* generic_file_llseek - generic llseek implementation for regular files
72+
* @file: file structure to seek on
73+
* @offset: file offset to seek to
74+
* @origin: type of seek
75+
*
76+
* This is a generic implemenation of ->llseek useable for all normal local
77+
* filesystems. It just updates the file offset to the value specified by
78+
* @offset and @origin under i_mutex.
79+
*/
6080
loff_t generic_file_llseek(struct file *file, loff_t offset, int origin)
6181
{
62-
loff_t n;
82+
loff_t rval;
83+
6384
mutex_lock(&file->f_dentry->d_inode->i_mutex);
64-
n = generic_file_llseek_unlocked(file, offset, origin);
85+
rval = generic_file_llseek_unlocked(file, offset, origin);
6586
mutex_unlock(&file->f_dentry->d_inode->i_mutex);
66-
return n;
87+
88+
return rval;
6789
}
6890
EXPORT_SYMBOL(generic_file_llseek);
6991

0 commit comments

Comments
 (0)