Skip to content

Commit 1a41364

Browse files
Yufen Yutorvalds
authored andcommitted
tmpfs: make lseek(SEEK_DATA/SEK_HOLE) return ENXIO with a negative offset
Other filesystems such as ext4, f2fs and ubifs all return ENXIO when lseek (SEEK_DATA or SEEK_HOLE) requests a negative offset. man 2 lseek says : EINVAL whence is not valid. Or: the resulting file offset would be : negative, or beyond the end of a seekable device. : : ENXIO whence is SEEK_DATA or SEEK_HOLE, and the file offset is beyond : the end of the file. Make tmpfs return ENXIO under these circumstances as well. After this, tmpfs also passes xfstests's generic/448. [akpm@linux-foundation.org: rewrite changelog] Link: http://lkml.kernel.org/r/1540434176-14349-1-git-send-email-yuyufen@huawei.com Signed-off-by: Yufen Yu <yuyufen@huawei.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Hugh Dickins <hughd@google.com> Cc: William Kucharski <william.kucharski@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1c23b41 commit 1a41364

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

mm/shmem.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,9 +2563,7 @@ static loff_t shmem_file_llseek(struct file *file, loff_t offset, int whence)
25632563
inode_lock(inode);
25642564
/* We're holding i_mutex so we can access i_size directly */
25652565

2566-
if (offset < 0)
2567-
offset = -EINVAL;
2568-
else if (offset >= inode->i_size)
2566+
if (offset < 0 || offset >= inode->i_size)
25692567
offset = -ENXIO;
25702568
else {
25712569
start = offset >> PAGE_SHIFT;

0 commit comments

Comments
 (0)