From: Jose Lopes <jabolopes@gmail.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Jose Lopes <jabolopes@gmail.com>,
linux-fsdevel@vger.kernel.org, fuse-devel@lists.sourceforge.net
Subject: [PATCH] Make file struct available to fchmod FS handlers.
Date: Wed, 2 Nov 2016 23:53:40 +0100 [thread overview]
Message-ID: <20161102225340.11613-1-jabolopes@gmail.com> (raw)
Syscall 'ftruncate' makes the 'file' struct available to filesystem
handlers. This makes it possible, e.g., for filesystems, such as,
FUSE, to access the file handle associated with the file descriptor
that was passed to 'ftruncate'. In the specific case of FUSE, this
also makes it possible for (userspace) FUSE-based filesystems to
distinguish between calls to 'truncate' and 'ftruncate'.
>From an implementation point of view, this is possible because the
'ftruncate' syscall passes the 'file' struct to the underlying
filesystem handlers via the 'ia_file' field and the 'ia_valid' field
mask.
Similarly to 'ftruncate', pass the 'file' struct to 'fchmod', which
allows filesystem handlers to get the file handle associated with the
file descriptor passed to 'fchmod' and allows FUSE-based filesystems
to distinguish between calls to 'chmod' and 'fchmod'.
In a future patch, make a similar change to the 'fchown' and
'futimens' syscalls.
Signed-off-by: Jose Lopes <jabolopes@gmail.com>
---
fs/open.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/fs/open.c b/fs/open.c
index d3ed817..00214c5 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -516,7 +516,8 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
return error;
}
-static int chmod_common(const struct path *path, umode_t mode)
+static int chmod_common(const struct path *path, umode_t mode,
+ struct file *filp)
{
struct inode *inode = path->dentry->d_inode;
struct inode *delegated_inode = NULL;
@@ -533,6 +534,10 @@ static int chmod_common(const struct path *path, umode_t mode)
goto out_unlock;
newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
+ if (filp) {
+ newattrs.ia_file = filp;
+ newattrs.ia_valid |= ATTR_FILE;
+ }
error = notify_change(path->dentry, &newattrs, &delegated_inode);
out_unlock:
inode_unlock(inode);
@@ -552,7 +557,7 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
if (f.file) {
audit_file(f.file);
- err = chmod_common(&f.file->f_path, mode);
+ err = chmod_common(&f.file->f_path, mode, f.file);
fdput(f);
}
return err;
@@ -566,7 +571,7 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, umode_t, mode
retry:
error = user_path_at(dfd, filename, lookup_flags, &path);
if (!error) {
- error = chmod_common(&path, mode);
+ error = chmod_common(&path, mode, NULL);
path_put(&path);
if (retry_estale(error, lookup_flags)) {
lookup_flags |= LOOKUP_REVAL;
--
2.9.0
next reply other threads:[~2016-11-02 22:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-02 22:53 Jose Lopes [this message]
2016-11-03 0:59 ` [PATCH] Make file struct available to fchmod FS handlers Al Viro
2016-11-03 8:22 ` [fuse-devel] " Jean-Pierre André
[not found] ` <581AF3CB.3090001-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>
2016-11-03 10:26 ` Jose Lopes
2016-11-17 17:44 ` [fuse-devel] " Eric W. Biederman
2016-11-17 18:39 ` Nikolaus Rath
2016-11-17 19:20 ` Eric W. Biederman
2016-11-17 23:03 ` Stef Bon
2016-11-03 15:22 ` Nikolaus Rath
2016-11-07 4:51 ` Nikolaus Rath
2016-11-09 17:54 ` Jose Lopes
2016-11-07 5:25 ` Nikolaus Rath
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=20161102225340.11613-1-jabolopes@gmail.com \
--to=jabolopes@gmail.com \
--cc=fuse-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.