Skip to content

Commit e8b96eb

Browse files
Eric SandeenAl Viro
authored andcommitted
vfs: allow custom EOF in generic_file_llseek code
For ext3/4 htree directories, using the vfs llseek function with SEEK_END goes to i_size like for any other file, but in reality we want the maximum possible hash value. Recent changes in ext4 have cut & pasted generic_file_llseek() back into fs/ext4/dir.c, but replicating this core code seems like a bad idea, especially since the copy has already diverged from the vfs. This patch updates generic_file_llseek_size to accept both a custom maximum offset, and a custom EOF position. With this in place, ext4_dir_llseek can pass in the appropriate maximum hash position for both maxsize and eof, and get what it wants. As far as I know, this does not fix any bugs - nfs in the kernel doesn't use SEEK_END, and I don't know of any user who does. But some ext4 folks seem keen on doing the right thing here, and I can't really argue. (Patch also fixes up some comments slightly) Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 4ea425b commit e8b96eb

4 files changed

Lines changed: 15 additions & 11 deletions

File tree

‎fs/ext3/dir.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ loff_t ext3_dir_llseek(struct file *file, loff_t offset, int origin)
303303

304304
if (likely(dx_dir))
305305
return generic_file_llseek_size(file, offset, origin,
306-
ext3_get_htree_eof(file));
306+
ext3_get_htree_eof(file),
307+
i_size_read(inode));
307308
else
308309
return generic_file_llseek(file, offset, origin);
309310
}

‎fs/ext4/file.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ loff_t ext4_llseek(struct file *file, loff_t offset, int origin)
225225
else
226226
maxbytes = inode->i_sb->s_maxbytes;
227227

228-
return generic_file_llseek_size(file, offset, origin, maxbytes);
228+
return generic_file_llseek_size(file, offset, origin,
229+
maxbytes, i_size_read(inode));
229230
}
230231

231232
const struct file_operations ext4_file_operations = {

‎fs/read_write.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ static loff_t lseek_execute(struct file *file, struct inode *inode,
5555
* @file: file structure to seek on
5656
* @offset: file offset to seek to
5757
* @origin: type of seek
58-
* @size: max size of file system
58+
* @size: max size of this file in file system
59+
* @eof: offset used for SEEK_END position
5960
*
6061
* This is a variant of generic_file_llseek that allows passing in a custom
61-
* file size.
62+
* maximum file size and a custom EOF position, for e.g. hashed directories
6263
*
6364
* Synchronization:
6465
* SEEK_SET and SEEK_END are unsynchronized (but atomic on 64bit platforms)
@@ -67,13 +68,13 @@ static loff_t lseek_execute(struct file *file, struct inode *inode,
6768
*/
6869
loff_t
6970
generic_file_llseek_size(struct file *file, loff_t offset, int origin,
70-
loff_t maxsize)
71+
loff_t maxsize, loff_t eof)
7172
{
7273
struct inode *inode = file->f_mapping->host;
7374

7475
switch (origin) {
7576
case SEEK_END:
76-
offset += i_size_read(inode);
77+
offset += eof;
7778
break;
7879
case SEEK_CUR:
7980
/*
@@ -99,17 +100,17 @@ generic_file_llseek_size(struct file *file, loff_t offset, int origin,
99100
* In the generic case the entire file is data, so as long as
100101
* offset isn't at the end of the file then the offset is data.
101102
*/
102-
if (offset >= i_size_read(inode))
103+
if (offset >= eof)
103104
return -ENXIO;
104105
break;
105106
case SEEK_HOLE:
106107
/*
107108
* There is a virtual hole at the end of the file, so as long as
108109
* offset isn't i_size or larger, return i_size.
109110
*/
110-
if (offset >= i_size_read(inode))
111+
if (offset >= eof)
111112
return -ENXIO;
112-
offset = i_size_read(inode);
113+
offset = eof;
113114
break;
114115
}
115116

@@ -132,7 +133,8 @@ loff_t generic_file_llseek(struct file *file, loff_t offset, int origin)
132133
struct inode *inode = file->f_mapping->host;
133134

134135
return generic_file_llseek_size(file, offset, origin,
135-
inode->i_sb->s_maxbytes);
136+
inode->i_sb->s_maxbytes,
137+
i_size_read(inode));
136138
}
137139
EXPORT_SYMBOL(generic_file_llseek);
138140

‎include/linux/fs.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2454,7 +2454,7 @@ extern loff_t noop_llseek(struct file *file, loff_t offset, int origin);
24542454
extern loff_t no_llseek(struct file *file, loff_t offset, int origin);
24552455
extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin);
24562456
extern loff_t generic_file_llseek_size(struct file *file, loff_t offset,
2457-
int origin, loff_t maxsize);
2457+
int origin, loff_t maxsize, loff_t eof);
24582458
extern int generic_file_open(struct inode * inode, struct file * filp);
24592459
extern int nonseekable_open(struct inode * inode, struct file * filp);
24602460

0 commit comments

Comments
 (0)