Re: splice vs O_APPEND

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linus Torvalds
Date: Thursday, October 9, 2008 - 9:17 am

On Thu, 9 Oct 2008, Miklos Szeredi wrote:

You're right. We can (and should) just check O_APPEND, because it must be 
set if IS_APPEND() is set on the inode.

And yeah, IS_IMMUTABLE is checked at open too. So no worries.

And it turns out that handling O_APPEND is actually pretty easy, so 
instead of doing -EINVAL, we can just implement it. Something like this 
(untested, of course).

Does this look better?

		Linus

---
 fs/splice.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/fs/splice.c b/fs/splice.c
index 1bbc6f4..8aca87b 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1120,11 +1120,17 @@ static long do_splice(struct file *in, loff_t __user *off_in,
 		if (off_in)
 			return -ESPIPE;
 		if (off_out) {
+			if (out->f_flags & O_APPEND)
+				return -EINVAL;
 			if (out->f_op->llseek == no_llseek)
 				return -EINVAL;
 			if (copy_from_user(&offset, off_out, sizeof(loff_t)))
 				return -EFAULT;
 			off = &offset;
+		} else if (out->f_flags & O_APPEND) {
+			struct inode *inode = out->f_dentry->d_inode;
+			offset = i_size_read(inode);
+			off = &offset;
 		} else
 			off = &out->f_pos;
 
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
splice vs O_APPEND, Miklos Szeredi, (Thu Oct 9, 8:02 am)
Re: splice vs O_APPEND, Linus Torvalds, (Thu Oct 9, 8:37 am)
Re: splice vs O_APPEND, Miklos Szeredi, (Thu Oct 9, 9:04 am)
Re: splice vs O_APPEND, Linus Torvalds, (Thu Oct 9, 9:17 am)
Re: splice vs O_APPEND, Andreas Schwab, (Thu Oct 9, 9:30 am)
Re: splice vs O_APPEND, Miklos Szeredi, (Thu Oct 9, 9:30 am)
Re: splice vs O_APPEND, Miklos Szeredi, (Thu Oct 9, 9:43 am)
Re: splice vs O_APPEND, Andreas Schwab, (Thu Oct 9, 10:03 am)
Re: splice vs O_APPEND, Linus Torvalds, (Thu Oct 9, 12:22 pm)
Re: splice vs O_APPEND, Miklos Szeredi, (Thu Oct 9, 12:51 pm)
Re: splice vs O_APPEND, Linus Torvalds, (Thu Oct 9, 2:14 pm)
Re: splice vs O_APPEND, Jens Axboe, (Thu Oct 9, 2:20 pm)
Re: splice vs O_APPEND, Linus Torvalds, (Thu Oct 9, 2:27 pm)
Re: splice vs O_APPEND, Miklos Szeredi, (Fri Oct 10, 2:46 am)
Re: splice vs O_APPEND, Jens Axboe, (Fri Oct 10, 3:06 am)
Re: splice vs O_APPEND, Michael Kerrisk, (Fri Oct 10, 3:23 am)
Re: [stable] splice vs O_APPEND, Greg KH, (Fri Oct 10, 8:49 am)
Re: [stable] splice vs O_APPEND, Miklos Szeredi, (Fri Oct 10, 9:05 am)
Re: [stable] splice vs O_APPEND, Greg KH, (Fri Oct 10, 9:20 am)