From e7478158e1378325907edfdd960eca98a1be405b Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 29 Jun 2022 15:06:57 +0200 Subject: fs: clear or set FMODE_LSEEK based on llseek function Pipe-like behaviour on llseek(2) (i.e. unconditionally failing with -ESPIPE) can be expresses in 3 ways: 1) ->llseek set to NULL in file_operations 2) ->llseek set to no_llseek in file_operations 3) FMODE_LSEEK *not* set in ->f_mode. Enforce (3) in cases (1) and (2); that will allow to simplify the checks and eventually get rid of no_llseek boilerplate. Signed-off-by: Jason A. Donenfeld Signed-off-by: Al Viro --- fs/open.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'fs/open.c') diff --git a/fs/open.c b/fs/open.c index 1d57fbde2feb..4488bd77c390 100644 --- a/fs/open.c +++ b/fs/open.c @@ -858,6 +858,10 @@ static int do_dentry_open(struct file *f, if ((f->f_mode & FMODE_WRITE) && likely(f->f_op->write || f->f_op->write_iter)) f->f_mode |= FMODE_CAN_WRITE; + if ((f->f_mode & FMODE_LSEEK) && !f->f_op->llseek) + f->f_mode &= ~FMODE_LSEEK; + if ((f->f_mode & FMODE_LSEEK) && f->f_op->llseek == no_llseek) + f->f_mode &= ~FMODE_LSEEK; if (f->f_mapping->a_ops && f->f_mapping->a_ops->direct_IO) f->f_mode |= FMODE_CAN_ODIRECT; -- cgit