From: William Kucharski <william.kucharski@oracle.com>
To: Yufen Yu <yuyufen@huawei.com>
Cc: viro@zeniv.linux.org.uk, hughd@google.com, linux-mm@kvack.org,
linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org
Subject: Re: [PATCH] tmpfs: let lseek return ENXIO with a negative offset
Date: Thu, 1 Nov 2018 01:13:25 -0600 [thread overview]
Message-ID: <88ED1518-A829-4933-8E1B-0576C79491B3@oracle.com> (raw)
In-Reply-To: <1540434176-14349-1-git-send-email-yuyufen@huawei.com>
> On Oct 24, 2018, at 8:22 PM, Yufen Yu <yuyufen@huawei.com> wrote:
>
> For now, the others filesystems, such as ext4, f2fs, ubifs,
> all of them return ENXIO when lseek with a negative offset.
> It is better to let tmpfs return ENXIO too. After that, tmpfs
> can also pass generic/448.
>
> Signed-off-by: Yufen Yu <yuyufen@huawei.com>
> ---
> mm/shmem.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 0376c124..f37bf06 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -2608,9 +2608,7 @@ static loff_t shmem_file_llseek(struct file *file, loff_t offset, int whence)
> inode_lock(inode);
> /* We're holding i_mutex so we can access i_size directly */
>
> - if (offset < 0)
> - offset = -EINVAL;
> - else if (offset >= inode->i_size)
> + if (offset < 0 || offset >= inode->i_size)
> offset = -ENXIO;
> else {
> start = offset >> PAGE_SHIFT;
> --
It's not at all clear what the proper thing to do is if a negative offset is passed.
The man page for lseek(2) states:
SEEK_DATA
Adjust the file offset to the next location in the file
greater than or equal to offset containing data. If offset
points to data, then the file offset is set to offset.
SEEK_HOLE
Adjust the file offset to the next hole in the file greater
than or equal to offset. If offset points into the middle of
a hole, then the file offset is set to offset. If there is no
hole past offset, then the file offset is adjusted to the end
of the file (i.e., there is an implicit hole at the end of any
file).
This seems to indicate that if passed a negative offset, a whence of either SEEK_DATA
or SEEK_HOLE should operate the same as if passed an offset of 0.
ENXIO just seems to be the wrong error code to return for a passed negative offset in
these cases (also from lseek(2)):
ENXIO whence is SEEK_DATA or SEEK_HOLE, and the file offset is
beyond the end of the file.
but EINVAL isn't technically appropriate either:
EINVAL whence is not valid. Or: the resulting file offset would be
negative, or beyond the end of a seekable device.
At the very least it seems the man page should be updated to reflect that ENXIO may be
returned if whence is SEEK_DATA or SEEK_HOLE and the passed offset is negative.
William Kucharski
next prev parent reply other threads:[~2018-11-01 7:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-25 2:22 [PATCH] tmpfs: let lseek return ENXIO with a negative offset Yufen Yu
2018-11-01 7:13 ` William Kucharski [this message]
2018-11-07 23:19 ` Andrew Morton
2018-11-08 10:46 ` William Kucharski
2018-11-08 23:07 ` Andrew Morton
2018-11-09 3:52 ` William Kucharski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=88ED1518-A829-4933-8E1B-0576C79491B3@oracle.com \
--to=william.kucharski@oracle.com \
--cc=hughd@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=yuyufen@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).