diff options
author | Miklos Szeredi <mszeredi@suse.cz> | 2009-06-30 14:12:23 -0400 |
---|---|---|
committer | Miklos Szeredi <mszeredi@suse.cz> | 2009-06-30 14:12:23 -0400 |
commit | e0a43ddcc08c34dbd666d93600fd23914505f4aa (patch) | |
tree | 103449845b1ffaf8f32ed98a1a543276227ec087 | |
parent | 201fa69a2849536ef2912e8e971ec0b01c04eff4 (diff) |
fuse: allow umask processing in userspace
This patch lets filesystems handle masking the file mode on creation.
This is needed if filesystem is using ACLs.
- The CREATE, MKDIR and MKNOD requests are extended with a "umask"
parameter.
- A new FUSE_DONT_MASK flag is added to the INIT request/reply. With
this the filesystem may request that the create mode is not masked.
CC: Jean-Pierre André <jean-pierre.andre@wanadoo.fr>
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
-rw-r--r-- | fs/fuse/dir.c | 20 | ||||
-rw-r--r-- | fs/fuse/fuse_i.h | 3 | ||||
-rw-r--r-- | fs/fuse/inode.c | 9 | ||||
-rw-r--r-- | include/linux/fuse.h | 20 |
4 files changed, 46 insertions, 6 deletions
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index b3089a083d30..6b700734e519 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c | |||
@@ -375,7 +375,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode, | |||
375 | struct fuse_conn *fc = get_fuse_conn(dir); | 375 | struct fuse_conn *fc = get_fuse_conn(dir); |
376 | struct fuse_req *req; | 376 | struct fuse_req *req; |
377 | struct fuse_req *forget_req; | 377 | struct fuse_req *forget_req; |
378 | struct fuse_open_in inarg; | 378 | struct fuse_create_in inarg; |
379 | struct fuse_open_out outopen; | 379 | struct fuse_open_out outopen; |
380 | struct fuse_entry_out outentry; | 380 | struct fuse_entry_out outentry; |
381 | struct fuse_file *ff; | 381 | struct fuse_file *ff; |
@@ -399,15 +399,20 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode, | |||
399 | if (!ff) | 399 | if (!ff) |
400 | goto out_put_request; | 400 | goto out_put_request; |
401 | 401 | ||
402 | if (!fc->dont_mask) | ||
403 | mode &= ~current_umask(); | ||
404 | |||
402 | flags &= ~O_NOCTTY; | 405 | flags &= ~O_NOCTTY; |
403 | memset(&inarg, 0, sizeof(inarg)); | 406 | memset(&inarg, 0, sizeof(inarg)); |
404 | memset(&outentry, 0, sizeof(outentry)); | 407 | memset(&outentry, 0, sizeof(outentry)); |
405 | inarg.flags = flags; | 408 | inarg.flags = flags; |
406 | inarg.mode = mode; | 409 | inarg.mode = mode; |
410 | inarg.umask = current_umask(); | ||
407 | req->in.h.opcode = FUSE_CREATE; | 411 | req->in.h.opcode = FUSE_CREATE; |
408 | req->in.h.nodeid = get_node_id(dir); | 412 | req->in.h.nodeid = get_node_id(dir); |
409 | req->in.numargs = 2; | 413 | req->in.numargs = 2; |
410 | req->in.args[0].size = sizeof(inarg); | 414 | req->in.args[0].size = fc->minor < 12 ? sizeof(struct fuse_open_in) : |
415 | sizeof(inarg); | ||
411 | req->in.args[0].value = &inarg; | 416 | req->in.args[0].value = &inarg; |
412 | req->in.args[1].size = entry->d_name.len + 1; | 417 | req->in.args[1].size = entry->d_name.len + 1; |
413 | req->in.args[1].value = entry->d_name.name; | 418 | req->in.args[1].value = entry->d_name.name; |
@@ -546,12 +551,17 @@ static int fuse_mknod(struct inode *dir, struct dentry *entry, int mode, | |||
546 | if (IS_ERR(req)) | 551 | if (IS_ERR(req)) |
547 | return PTR_ERR(req); | 552 | return PTR_ERR(req); |
548 | 553 | ||
554 | if (!fc->dont_mask) | ||
555 | mode &= ~current_umask(); | ||
556 | |||
549 | memset(&inarg, 0, sizeof(inarg)); | 557 | memset(&inarg, 0, sizeof(inarg)); |
550 | inarg.mode = mode; | 558 | inarg.mode = mode; |
551 | inarg.rdev = new_encode_dev(rdev); | 559 | inarg.rdev = new_encode_dev(rdev); |
560 | inarg.umask = current_umask(); | ||
552 | req->in.h.opcode = FUSE_MKNOD; | 561 | req->in.h.opcode = FUSE_MKNOD; |
553 | req->in.numargs = 2; | 562 | req->in.numargs = 2; |
554 | req->in.args[0].size = sizeof(inarg); | 563 | req->in.args[0].size = fc->minor < 12 ? FUSE_COMPAT_MKNOD_IN_SIZE : |
564 | sizeof(inarg); | ||
555 | req->in.args[0].value = &inarg; | 565 | req->in.args[0].value = &inarg; |
556 | req->in.args[1].size = entry->d_name.len + 1; | 566 | req->in.args[1].size = entry->d_name.len + 1; |
557 | req->in.args[1].value = entry->d_name.name; | 567 | req->in.args[1].value = entry->d_name.name; |
@@ -578,8 +588,12 @@ static int fuse_mkdir(struct inode *dir, struct dentry *entry, int mode) | |||
578 | if (IS_ERR(req)) | 588 | if (IS_ERR(req)) |
579 | return PTR_ERR(req); | 589 | return PTR_ERR(req); |
580 | 590 | ||
591 | if (!fc->dont_mask) | ||
592 | mode &= ~current_umask(); | ||
593 | |||
581 | memset(&inarg, 0, sizeof(inarg)); | 594 | memset(&inarg, 0, sizeof(inarg)); |
582 | inarg.mode = mode; | 595 | inarg.mode = mode; |
596 | inarg.umask = current_umask(); | ||
583 | req->in.h.opcode = FUSE_MKDIR; | 597 | req->in.h.opcode = FUSE_MKDIR; |
584 | req->in.numargs = 2; | 598 | req->in.numargs = 2; |
585 | req->in.args[0].size = sizeof(inarg); | 599 | req->in.args[0].size = sizeof(inarg); |
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index aaf2f9ff970e..ede4f77b2d6c 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h | |||
@@ -446,6 +446,9 @@ struct fuse_conn { | |||
446 | /** Do multi-page cached writes */ | 446 | /** Do multi-page cached writes */ |
447 | unsigned big_writes:1; | 447 | unsigned big_writes:1; |
448 | 448 | ||
449 | /** Don't apply umask to creation modes */ | ||
450 | unsigned dont_mask:1; | ||
451 | |||
449 | /** The number of requests waiting for completion */ | 452 | /** The number of requests waiting for completion */ |
450 | atomic_t num_waiting; | 453 | atomic_t num_waiting; |
451 | 454 | ||
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index d8673ccf90b7..6cc501bd0187 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c | |||
@@ -725,6 +725,8 @@ static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req) | |||
725 | } | 725 | } |
726 | if (arg->flags & FUSE_BIG_WRITES) | 726 | if (arg->flags & FUSE_BIG_WRITES) |
727 | fc->big_writes = 1; | 727 | fc->big_writes = 1; |
728 | if (arg->flags & FUSE_DONT_MASK) | ||
729 | fc->dont_mask = 1; | ||
728 | } else { | 730 | } else { |
729 | ra_pages = fc->max_read / PAGE_CACHE_SIZE; | 731 | ra_pages = fc->max_read / PAGE_CACHE_SIZE; |
730 | fc->no_lock = 1; | 732 | fc->no_lock = 1; |
@@ -748,7 +750,7 @@ static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req) | |||
748 | arg->minor = FUSE_KERNEL_MINOR_VERSION; | 750 | arg->minor = FUSE_KERNEL_MINOR_VERSION; |
749 | arg->max_readahead = fc->bdi.ra_pages * PAGE_CACHE_SIZE; | 751 | arg->max_readahead = fc->bdi.ra_pages * PAGE_CACHE_SIZE; |
750 | arg->flags |= FUSE_ASYNC_READ | FUSE_POSIX_LOCKS | FUSE_ATOMIC_O_TRUNC | | 752 | arg->flags |= FUSE_ASYNC_READ | FUSE_POSIX_LOCKS | FUSE_ATOMIC_O_TRUNC | |
751 | FUSE_EXPORT_SUPPORT | FUSE_BIG_WRITES; | 753 | FUSE_EXPORT_SUPPORT | FUSE_BIG_WRITES | FUSE_DONT_MASK; |
752 | req->in.h.opcode = FUSE_INIT; | 754 | req->in.h.opcode = FUSE_INIT; |
753 | req->in.numargs = 1; | 755 | req->in.numargs = 1; |
754 | req->in.args[0].size = sizeof(*arg); | 756 | req->in.args[0].size = sizeof(*arg); |
@@ -864,6 +866,11 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent) | |||
864 | if (err) | 866 | if (err) |
865 | goto err_put_conn; | 867 | goto err_put_conn; |
866 | 868 | ||
869 | /* Handle umasking inside the fuse code */ | ||
870 | if (sb->s_flags & MS_POSIXACL) | ||
871 | fc->dont_mask = 1; | ||
872 | sb->s_flags |= MS_POSIXACL; | ||
873 | |||
867 | fc->release = fuse_free_conn; | 874 | fc->release = fuse_free_conn; |
868 | fc->flags = d.flags; | 875 | fc->flags = d.flags; |
869 | fc->user_id = d.user_id; | 876 | fc->user_id = d.user_id; |
diff --git a/include/linux/fuse.h b/include/linux/fuse.h index d41ed593f79f..e2b816a62488 100644 --- a/include/linux/fuse.h +++ b/include/linux/fuse.h | |||
@@ -25,6 +25,9 @@ | |||
25 | * - add IOCTL message | 25 | * - add IOCTL message |
26 | * - add unsolicited notification support | 26 | * - add unsolicited notification support |
27 | * - add POLL message and NOTIFY_POLL notification | 27 | * - add POLL message and NOTIFY_POLL notification |
28 | * | ||
29 | * 7.12 | ||
30 | * - add umask flag to input argument of open, mknod and mkdir | ||
28 | */ | 31 | */ |
29 | 32 | ||
30 | #ifndef _LINUX_FUSE_H | 33 | #ifndef _LINUX_FUSE_H |
@@ -36,7 +39,7 @@ | |||
36 | #define FUSE_KERNEL_VERSION 7 | 39 | #define FUSE_KERNEL_VERSION 7 |
37 | 40 | ||
38 | /** Minor version number of this interface */ | 41 | /** Minor version number of this interface */ |
39 | #define FUSE_KERNEL_MINOR_VERSION 11 | 42 | #define FUSE_KERNEL_MINOR_VERSION 12 |
40 | 43 | ||
41 | /** The node ID of the root inode */ | 44 | /** The node ID of the root inode */ |
42 | #define FUSE_ROOT_ID 1 | 45 | #define FUSE_ROOT_ID 1 |
@@ -112,6 +115,7 @@ struct fuse_file_lock { | |||
112 | * INIT request/reply flags | 115 | * INIT request/reply flags |
113 | * | 116 | * |
114 | * FUSE_EXPORT_SUPPORT: filesystem handles lookups of "." and ".." | 117 | * FUSE_EXPORT_SUPPORT: filesystem handles lookups of "." and ".." |
118 | * FUSE_DONT_MASK: don't apply umask to file mode on create operations | ||
115 | */ | 119 | */ |
116 | #define FUSE_ASYNC_READ (1 << 0) | 120 | #define FUSE_ASYNC_READ (1 << 0) |
117 | #define FUSE_POSIX_LOCKS (1 << 1) | 121 | #define FUSE_POSIX_LOCKS (1 << 1) |
@@ -119,6 +123,7 @@ struct fuse_file_lock { | |||
119 | #define FUSE_ATOMIC_O_TRUNC (1 << 3) | 123 | #define FUSE_ATOMIC_O_TRUNC (1 << 3) |
120 | #define FUSE_EXPORT_SUPPORT (1 << 4) | 124 | #define FUSE_EXPORT_SUPPORT (1 << 4) |
121 | #define FUSE_BIG_WRITES (1 << 5) | 125 | #define FUSE_BIG_WRITES (1 << 5) |
126 | #define FUSE_DONT_MASK (1 << 6) | ||
122 | 127 | ||
123 | /** | 128 | /** |
124 | * CUSE INIT request/reply flags | 129 | * CUSE INIT request/reply flags |
@@ -262,14 +267,18 @@ struct fuse_attr_out { | |||
262 | struct fuse_attr attr; | 267 | struct fuse_attr attr; |
263 | }; | 268 | }; |
264 | 269 | ||
270 | #define FUSE_COMPAT_MKNOD_IN_SIZE 8 | ||
271 | |||
265 | struct fuse_mknod_in { | 272 | struct fuse_mknod_in { |
266 | __u32 mode; | 273 | __u32 mode; |
267 | __u32 rdev; | 274 | __u32 rdev; |
275 | __u32 umask; | ||
276 | __u32 padding; | ||
268 | }; | 277 | }; |
269 | 278 | ||
270 | struct fuse_mkdir_in { | 279 | struct fuse_mkdir_in { |
271 | __u32 mode; | 280 | __u32 mode; |
272 | __u32 padding; | 281 | __u32 umask; |
273 | }; | 282 | }; |
274 | 283 | ||
275 | struct fuse_rename_in { | 284 | struct fuse_rename_in { |
@@ -301,7 +310,14 @@ struct fuse_setattr_in { | |||
301 | 310 | ||
302 | struct fuse_open_in { | 311 | struct fuse_open_in { |
303 | __u32 flags; | 312 | __u32 flags; |
313 | __u32 unused; | ||
314 | }; | ||
315 | |||
316 | struct fuse_create_in { | ||
317 | __u32 flags; | ||
304 | __u32 mode; | 318 | __u32 mode; |
319 | __u32 umask; | ||
320 | __u32 padding; | ||
305 | }; | 321 | }; |
306 | 322 | ||
307 | struct fuse_open_out { | 323 | struct fuse_open_out { |