2006-01-12 04:17:46 +08:00
|
|
|
#include <linux/capability.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/posix_acl.h>
|
|
|
|
#include <linux/reiserfs_fs.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/xattr.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-06-23 15:10:19 +08:00
|
|
|
#include <linux/posix_acl_xattr.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/reiserfs_xattr.h>
|
|
|
|
#include <linux/reiserfs_acl.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
2009-03-31 02:02:39 +08:00
|
|
|
static int reiserfs_set_acl(struct reiserfs_transaction_handle *th,
|
|
|
|
struct inode *inode, int type,
|
2005-07-13 11:21:28 +08:00
|
|
|
struct posix_acl *acl);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static int
|
2009-11-13 17:52:56 +08:00
|
|
|
posix_acl_set(struct dentry *dentry, const char *name, const void *value,
|
|
|
|
size_t size, int flags, int type)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-11-13 17:52:56 +08:00
|
|
|
struct inode *inode = dentry->d_inode;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct posix_acl *acl;
|
2009-03-31 02:02:39 +08:00
|
|
|
int error, error2;
|
|
|
|
struct reiserfs_transaction_handle th;
|
|
|
|
size_t jcreate_blocks;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!reiserfs_posixacl(inode->i_sb))
|
|
|
|
return -EOPNOTSUPP;
|
2011-03-24 07:43:26 +08:00
|
|
|
if (!inode_owner_or_capable(inode))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
acl = posix_acl_from_xattr(value, size);
|
|
|
|
if (IS_ERR(acl)) {
|
|
|
|
return PTR_ERR(acl);
|
|
|
|
} else if (acl) {
|
|
|
|
error = posix_acl_valid(acl);
|
|
|
|
if (error)
|
|
|
|
goto release_and_out;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
acl = NULL;
|
|
|
|
|
2009-03-31 02:02:39 +08:00
|
|
|
/* Pessimism: We can't assume that anything from the xattr root up
|
|
|
|
* has been created. */
|
|
|
|
|
|
|
|
jcreate_blocks = reiserfs_xattr_jcreate_nblocks(inode) +
|
|
|
|
reiserfs_xattr_nblocks(inode, size) * 2;
|
|
|
|
|
|
|
|
reiserfs_write_lock(inode->i_sb);
|
|
|
|
error = journal_begin(&th, inode->i_sb, jcreate_blocks);
|
|
|
|
if (error == 0) {
|
|
|
|
error = reiserfs_set_acl(&th, inode, type, acl);
|
|
|
|
error2 = journal_end(&th, inode->i_sb, jcreate_blocks);
|
|
|
|
if (error2)
|
|
|
|
error = error2;
|
|
|
|
}
|
|
|
|
reiserfs_write_unlock(inode->i_sb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-07-13 11:21:28 +08:00
|
|
|
release_and_out:
|
2005-04-17 06:20:36 +08:00
|
|
|
posix_acl_release(acl);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-11-13 17:52:56 +08:00
|
|
|
posix_acl_get(struct dentry *dentry, const char *name, void *buffer,
|
|
|
|
size_t size, int type)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct posix_acl *acl;
|
|
|
|
int error;
|
|
|
|
|
2009-11-13 17:52:56 +08:00
|
|
|
if (!reiserfs_posixacl(dentry->d_sb))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2009-11-13 17:52:56 +08:00
|
|
|
acl = reiserfs_get_acl(dentry->d_inode, type);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (IS_ERR(acl))
|
|
|
|
return PTR_ERR(acl);
|
|
|
|
if (acl == NULL)
|
|
|
|
return -ENODATA;
|
|
|
|
error = posix_acl_to_xattr(acl, buffer, size);
|
|
|
|
posix_acl_release(acl);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert from filesystem to in-memory representation.
|
|
|
|
*/
|
2005-07-13 11:21:28 +08:00
|
|
|
static struct posix_acl *posix_acl_from_disk(const void *value, size_t size)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
const char *end = (char *)value + size;
|
|
|
|
int n, count;
|
|
|
|
struct posix_acl *acl;
|
|
|
|
|
|
|
|
if (!value)
|
|
|
|
return NULL;
|
|
|
|
if (size < sizeof(reiserfs_acl_header))
|
2005-07-13 11:21:28 +08:00
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
if (((reiserfs_acl_header *) value)->a_version !=
|
2005-04-17 06:20:36 +08:00
|
|
|
cpu_to_le32(REISERFS_ACL_VERSION))
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
value = (char *)value + sizeof(reiserfs_acl_header);
|
|
|
|
count = reiserfs_acl_count(size);
|
|
|
|
if (count < 0)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
if (count == 0)
|
|
|
|
return NULL;
|
|
|
|
acl = posix_acl_alloc(count, GFP_NOFS);
|
|
|
|
if (!acl)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2005-07-13 11:21:28 +08:00
|
|
|
for (n = 0; n < count; n++) {
|
|
|
|
reiserfs_acl_entry *entry = (reiserfs_acl_entry *) value;
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((char *)value + sizeof(reiserfs_acl_entry_short) > end)
|
|
|
|
goto fail;
|
2005-07-13 11:21:28 +08:00
|
|
|
acl->a_entries[n].e_tag = le16_to_cpu(entry->e_tag);
|
2005-04-17 06:20:36 +08:00
|
|
|
acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm);
|
2005-07-13 11:21:28 +08:00
|
|
|
switch (acl->a_entries[n].e_tag) {
|
|
|
|
case ACL_USER_OBJ:
|
|
|
|
case ACL_GROUP_OBJ:
|
|
|
|
case ACL_MASK:
|
|
|
|
case ACL_OTHER:
|
|
|
|
value = (char *)value +
|
|
|
|
sizeof(reiserfs_acl_entry_short);
|
|
|
|
acl->a_entries[n].e_id = ACL_UNDEFINED_ID;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACL_USER:
|
|
|
|
case ACL_GROUP:
|
|
|
|
value = (char *)value + sizeof(reiserfs_acl_entry);
|
|
|
|
if ((char *)value > end)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto fail;
|
2005-07-13 11:21:28 +08:00
|
|
|
acl->a_entries[n].e_id = le32_to_cpu(entry->e_id);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto fail;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (value != end)
|
|
|
|
goto fail;
|
|
|
|
return acl;
|
|
|
|
|
2005-07-13 11:21:28 +08:00
|
|
|
fail:
|
2005-04-17 06:20:36 +08:00
|
|
|
posix_acl_release(acl);
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert from in-memory to filesystem representation.
|
|
|
|
*/
|
2005-07-13 11:21:28 +08:00
|
|
|
static void *posix_acl_to_disk(const struct posix_acl *acl, size_t * size)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
reiserfs_acl_header *ext_acl;
|
|
|
|
char *e;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
*size = reiserfs_acl_size(acl->a_count);
|
2006-12-13 16:35:56 +08:00
|
|
|
ext_acl = kmalloc(sizeof(reiserfs_acl_header) +
|
2005-07-13 11:21:28 +08:00
|
|
|
acl->a_count *
|
|
|
|
sizeof(reiserfs_acl_entry),
|
|
|
|
GFP_NOFS);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!ext_acl)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
ext_acl->a_version = cpu_to_le32(REISERFS_ACL_VERSION);
|
|
|
|
e = (char *)ext_acl + sizeof(reiserfs_acl_header);
|
2005-07-13 11:21:28 +08:00
|
|
|
for (n = 0; n < acl->a_count; n++) {
|
|
|
|
reiserfs_acl_entry *entry = (reiserfs_acl_entry *) e;
|
|
|
|
entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag);
|
2005-04-17 06:20:36 +08:00
|
|
|
entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm);
|
2005-07-13 11:21:28 +08:00
|
|
|
switch (acl->a_entries[n].e_tag) {
|
|
|
|
case ACL_USER:
|
|
|
|
case ACL_GROUP:
|
|
|
|
entry->e_id = cpu_to_le32(acl->a_entries[n].e_id);
|
|
|
|
e += sizeof(reiserfs_acl_entry);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACL_USER_OBJ:
|
|
|
|
case ACL_GROUP_OBJ:
|
|
|
|
case ACL_MASK:
|
|
|
|
case ACL_OTHER:
|
|
|
|
e += sizeof(reiserfs_acl_entry_short);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto fail;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (char *)ext_acl;
|
|
|
|
|
2005-07-13 11:21:28 +08:00
|
|
|
fail:
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(ext_acl);
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Inode operation get_posix_acl().
|
|
|
|
*
|
2006-01-10 07:59:24 +08:00
|
|
|
* inode->i_mutex: down
|
2005-04-17 06:20:36 +08:00
|
|
|
* BKL held [before 2.5.x]
|
|
|
|
*/
|
2005-07-13 11:21:28 +08:00
|
|
|
struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
char *name, *value;
|
2009-06-10 00:11:54 +08:00
|
|
|
struct posix_acl *acl;
|
2006-03-25 19:07:50 +08:00
|
|
|
int size;
|
2005-04-17 06:20:36 +08:00
|
|
|
int retval;
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2009-06-10 00:11:54 +08:00
|
|
|
acl = get_cached_acl(inode, type);
|
|
|
|
if (acl != ACL_NOT_CACHED)
|
|
|
|
return acl;
|
|
|
|
|
2005-07-13 11:21:28 +08:00
|
|
|
switch (type) {
|
|
|
|
case ACL_TYPE_ACCESS:
|
|
|
|
name = POSIX_ACL_XATTR_ACCESS;
|
|
|
|
break;
|
|
|
|
case ACL_TYPE_DEFAULT:
|
|
|
|
name = POSIX_ACL_XATTR_DEFAULT;
|
|
|
|
break;
|
|
|
|
default:
|
2009-06-10 00:11:54 +08:00
|
|
|
BUG();
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size = reiserfs_xattr_get(inode, name, NULL, 0);
|
2006-03-25 19:07:50 +08:00
|
|
|
if (size < 0) {
|
2005-07-13 11:21:28 +08:00
|
|
|
if (size == -ENODATA || size == -ENOSYS) {
|
2009-06-10 00:11:54 +08:00
|
|
|
set_cached_acl(inode, type, NULL);
|
2005-07-13 11:21:28 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return ERR_PTR(size);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-07-13 11:21:28 +08:00
|
|
|
value = kmalloc(size, GFP_NOFS);
|
|
|
|
if (!value)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
retval = reiserfs_xattr_get(inode, name, value, size);
|
|
|
|
if (retval == -ENODATA || retval == -ENOSYS) {
|
|
|
|
/* This shouldn't actually happen as it should have
|
|
|
|
been caught above.. but just in case */
|
|
|
|
acl = NULL;
|
2005-07-13 11:21:28 +08:00
|
|
|
} else if (retval < 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
acl = ERR_PTR(retval);
|
|
|
|
} else {
|
|
|
|
acl = posix_acl_from_disk(value, retval);
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
2009-06-10 00:11:54 +08:00
|
|
|
if (!IS_ERR(acl))
|
|
|
|
set_cached_acl(inode, type, acl);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
kfree(value);
|
|
|
|
return acl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Inode operation set_posix_acl().
|
|
|
|
*
|
2006-01-10 07:59:24 +08:00
|
|
|
* inode->i_mutex: down
|
2005-04-17 06:20:36 +08:00
|
|
|
* BKL held [before 2.5.x]
|
|
|
|
*/
|
|
|
|
static int
|
2009-03-31 02:02:39 +08:00
|
|
|
reiserfs_set_acl(struct reiserfs_transaction_handle *th, struct inode *inode,
|
|
|
|
int type, struct posix_acl *acl)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-07-13 11:21:28 +08:00
|
|
|
char *name;
|
2005-04-17 06:20:36 +08:00
|
|
|
void *value = NULL;
|
2009-03-31 02:02:38 +08:00
|
|
|
size_t size = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
int error;
|
|
|
|
|
|
|
|
if (S_ISLNK(inode->i_mode))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2005-07-13 11:21:28 +08:00
|
|
|
switch (type) {
|
|
|
|
case ACL_TYPE_ACCESS:
|
|
|
|
name = POSIX_ACL_XATTR_ACCESS;
|
|
|
|
if (acl) {
|
|
|
|
mode_t mode = inode->i_mode;
|
|
|
|
error = posix_acl_equiv_mode(acl, &mode);
|
|
|
|
if (error < 0)
|
|
|
|
return error;
|
|
|
|
else {
|
|
|
|
inode->i_mode = mode;
|
|
|
|
if (error == 0)
|
|
|
|
acl = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ACL_TYPE_DEFAULT:
|
|
|
|
name = POSIX_ACL_XATTR_DEFAULT;
|
|
|
|
if (!S_ISDIR(inode->i_mode))
|
|
|
|
return acl ? -EACCES : 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (acl) {
|
|
|
|
value = posix_acl_to_disk(acl, &size);
|
|
|
|
if (IS_ERR(value))
|
|
|
|
return (int)PTR_ERR(value);
|
2009-03-31 02:02:38 +08:00
|
|
|
}
|
|
|
|
|
2009-03-31 02:02:39 +08:00
|
|
|
error = reiserfs_xattr_set_handle(th, inode, name, value, size, 0);
|
2009-03-31 02:02:38 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensure that the inode gets dirtied if we're only using
|
|
|
|
* the mode bits and an old ACL didn't exist. We don't need
|
|
|
|
* to check if the inode is hashed here since we won't get
|
|
|
|
* called by reiserfs_inherit_default_acl().
|
|
|
|
*/
|
|
|
|
if (error == -ENODATA) {
|
|
|
|
error = 0;
|
|
|
|
if (type == ACL_TYPE_ACCESS) {
|
|
|
|
inode->i_ctime = CURRENT_TIME_SEC;
|
2005-07-13 11:21:28 +08:00
|
|
|
mark_inode_dirty(inode);
|
|
|
|
}
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-31 07:00:16 +08:00
|
|
|
kfree(value);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-31 02:02:35 +08:00
|
|
|
if (!error)
|
2009-06-10 00:11:54 +08:00
|
|
|
set_cached_acl(inode, type, acl);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2006-01-10 07:59:24 +08:00
|
|
|
/* dir->i_mutex: locked,
|
2005-04-17 06:20:36 +08:00
|
|
|
* inode is new and not released into the wild yet */
|
|
|
|
int
|
2009-03-31 02:02:39 +08:00
|
|
|
reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
|
|
|
|
struct inode *dir, struct dentry *dentry,
|
2005-07-13 11:21:28 +08:00
|
|
|
struct inode *inode)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-07-13 11:21:28 +08:00
|
|
|
struct posix_acl *acl;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
/* ACLs only get applied to files and directories */
|
|
|
|
if (S_ISLNK(inode->i_mode))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* ACLs can only be used on "new" objects, so if it's an old object
|
|
|
|
* there is nothing to inherit from */
|
|
|
|
if (get_inode_sd_version(dir) == STAT_DATA_V1)
|
|
|
|
goto apply_umask;
|
|
|
|
|
|
|
|
/* Don't apply ACLs to objects in the .reiserfs_priv tree.. This
|
|
|
|
* would be useless since permissions are ignored, and a pain because
|
|
|
|
* it introduces locking cycles */
|
2009-03-31 02:02:32 +08:00
|
|
|
if (IS_PRIVATE(dir)) {
|
|
|
|
inode->i_flags |= S_PRIVATE;
|
2005-07-13 11:21:28 +08:00
|
|
|
goto apply_umask;
|
|
|
|
}
|
|
|
|
|
|
|
|
acl = reiserfs_get_acl(dir, ACL_TYPE_DEFAULT);
|
2009-06-09 09:01:13 +08:00
|
|
|
if (IS_ERR(acl))
|
2005-07-13 11:21:28 +08:00
|
|
|
return PTR_ERR(acl);
|
|
|
|
|
|
|
|
if (acl) {
|
|
|
|
struct posix_acl *acl_copy;
|
|
|
|
mode_t mode = inode->i_mode;
|
|
|
|
int need_acl;
|
|
|
|
|
|
|
|
/* Copy the default ACL to the default ACL of a new directory */
|
|
|
|
if (S_ISDIR(inode->i_mode)) {
|
2009-03-31 02:02:39 +08:00
|
|
|
err = reiserfs_set_acl(th, inode, ACL_TYPE_DEFAULT,
|
|
|
|
acl);
|
2005-07-13 11:21:28 +08:00
|
|
|
if (err)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now we reconcile the new ACL and the mode,
|
|
|
|
potentially modifying both */
|
|
|
|
acl_copy = posix_acl_clone(acl, GFP_NOFS);
|
|
|
|
if (!acl_copy) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
need_acl = posix_acl_create_masq(acl_copy, &mode);
|
|
|
|
if (need_acl >= 0) {
|
|
|
|
if (mode != inode->i_mode) {
|
|
|
|
inode->i_mode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we need an ACL.. */
|
|
|
|
if (need_acl > 0) {
|
2009-03-31 02:02:39 +08:00
|
|
|
err = reiserfs_set_acl(th, inode,
|
|
|
|
ACL_TYPE_ACCESS,
|
|
|
|
acl_copy);
|
2005-07-13 11:21:28 +08:00
|
|
|
if (err)
|
|
|
|
goto cleanup_copy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cleanup_copy:
|
|
|
|
posix_acl_release(acl_copy);
|
|
|
|
cleanup:
|
|
|
|
posix_acl_release(acl);
|
|
|
|
} else {
|
|
|
|
apply_umask:
|
|
|
|
/* no ACL, apply umask */
|
2009-03-30 07:08:22 +08:00
|
|
|
inode->i_mode &= ~current_umask();
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-03-31 02:02:39 +08:00
|
|
|
/* This is used to cache the default acl before a new object is created.
|
|
|
|
* The biggest reason for this is to get an idea of how many blocks will
|
|
|
|
* actually be required for the create operation if we must inherit an ACL.
|
|
|
|
* An ACL write can add up to 3 object creations and an additional file write
|
|
|
|
* so we'd prefer not to reserve that many blocks in the journal if we can.
|
|
|
|
* It also has the advantage of not loading the ACL with a transaction open,
|
|
|
|
* this may seem silly, but if the owner of the directory is doing the
|
|
|
|
* creation, the ACL may not be loaded since the permissions wouldn't require
|
|
|
|
* it.
|
|
|
|
* We return the number of blocks required for the transaction.
|
|
|
|
*/
|
2005-07-13 11:21:28 +08:00
|
|
|
int reiserfs_cache_default_acl(struct inode *inode)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-03-31 02:02:39 +08:00
|
|
|
struct posix_acl *acl;
|
|
|
|
int nblocks = 0;
|
|
|
|
|
|
|
|
if (IS_PRIVATE(inode))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
acl = reiserfs_get_acl(inode, ACL_TYPE_DEFAULT);
|
|
|
|
|
|
|
|
if (acl && !IS_ERR(acl)) {
|
|
|
|
int size = reiserfs_acl_size(acl->a_count);
|
|
|
|
|
|
|
|
/* Other xattrs can be created during inode creation. We don't
|
|
|
|
* want to claim too many blocks, so we check to see if we
|
|
|
|
* we need to create the tree to the xattrs, and then we
|
|
|
|
* just want two files. */
|
|
|
|
nblocks = reiserfs_xattr_jcreate_nblocks(inode);
|
|
|
|
nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
|
|
|
|
|
|
|
|
REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
|
|
|
|
|
|
|
|
/* We need to account for writes + bitmaps for two files */
|
|
|
|
nblocks += reiserfs_xattr_nblocks(inode, size) * 4;
|
|
|
|
posix_acl_release(acl);
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
|
|
|
|
2009-03-31 02:02:39 +08:00
|
|
|
return nblocks;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-07-13 11:21:28 +08:00
|
|
|
int reiserfs_acl_chmod(struct inode *inode)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-07-13 11:21:28 +08:00
|
|
|
struct posix_acl *acl, *clone;
|
|
|
|
int error;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-07-13 11:21:28 +08:00
|
|
|
if (S_ISLNK(inode->i_mode))
|
|
|
|
return -EOPNOTSUPP;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-07-13 11:21:28 +08:00
|
|
|
if (get_inode_sd_version(inode) == STAT_DATA_V1 ||
|
|
|
|
!reiserfs_posixacl(inode->i_sb)) {
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-01-07 19:57:47 +08:00
|
|
|
reiserfs_write_unlock(inode->i_sb);
|
2005-07-13 11:21:28 +08:00
|
|
|
acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
|
2010-01-07 19:57:47 +08:00
|
|
|
reiserfs_write_lock(inode->i_sb);
|
2005-07-13 11:21:28 +08:00
|
|
|
if (!acl)
|
|
|
|
return 0;
|
|
|
|
if (IS_ERR(acl))
|
|
|
|
return PTR_ERR(acl);
|
|
|
|
clone = posix_acl_clone(acl, GFP_NOFS);
|
|
|
|
posix_acl_release(acl);
|
|
|
|
if (!clone)
|
|
|
|
return -ENOMEM;
|
|
|
|
error = posix_acl_chmod_masq(clone, inode->i_mode);
|
2009-03-31 02:02:39 +08:00
|
|
|
if (!error) {
|
|
|
|
struct reiserfs_transaction_handle th;
|
|
|
|
size_t size = reiserfs_xattr_nblocks(inode,
|
|
|
|
reiserfs_acl_size(clone->a_count));
|
2010-12-03 06:31:16 +08:00
|
|
|
int depth;
|
|
|
|
|
|
|
|
depth = reiserfs_write_lock_once(inode->i_sb);
|
2009-03-31 02:02:39 +08:00
|
|
|
error = journal_begin(&th, inode->i_sb, size * 2);
|
|
|
|
if (!error) {
|
|
|
|
int error2;
|
|
|
|
error = reiserfs_set_acl(&th, inode, ACL_TYPE_ACCESS,
|
|
|
|
clone);
|
|
|
|
error2 = journal_end(&th, inode->i_sb, size * 2);
|
|
|
|
if (error2)
|
|
|
|
error = error2;
|
|
|
|
}
|
2010-12-03 06:31:16 +08:00
|
|
|
reiserfs_write_unlock_once(inode->i_sb, depth);
|
2009-03-31 02:02:39 +08:00
|
|
|
}
|
2005-07-13 11:21:28 +08:00
|
|
|
posix_acl_release(clone);
|
|
|
|
return error;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-11-13 17:52:56 +08:00
|
|
|
static size_t posix_acl_access_list(struct dentry *dentry, char *list,
|
2009-03-31 02:02:38 +08:00
|
|
|
size_t list_size, const char *name,
|
2009-11-13 17:52:56 +08:00
|
|
|
size_t name_len, int type)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-03-31 02:02:38 +08:00
|
|
|
const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS);
|
2009-11-13 17:52:56 +08:00
|
|
|
if (!reiserfs_posixacl(dentry->d_sb))
|
2005-07-13 11:21:28 +08:00
|
|
|
return 0;
|
2009-03-31 02:02:38 +08:00
|
|
|
if (list && size <= list_size)
|
|
|
|
memcpy(list, POSIX_ACL_XATTR_ACCESS, size);
|
|
|
|
return size;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-05-14 08:53:19 +08:00
|
|
|
const struct xattr_handler reiserfs_posix_acl_access_handler = {
|
2005-06-23 15:10:19 +08:00
|
|
|
.prefix = POSIX_ACL_XATTR_ACCESS,
|
2009-11-13 17:52:56 +08:00
|
|
|
.flags = ACL_TYPE_ACCESS,
|
|
|
|
.get = posix_acl_get,
|
|
|
|
.set = posix_acl_set,
|
2005-04-17 06:20:36 +08:00
|
|
|
.list = posix_acl_access_list,
|
|
|
|
};
|
|
|
|
|
2009-11-13 17:52:56 +08:00
|
|
|
static size_t posix_acl_default_list(struct dentry *dentry, char *list,
|
2009-03-31 02:02:38 +08:00
|
|
|
size_t list_size, const char *name,
|
2009-11-13 17:52:56 +08:00
|
|
|
size_t name_len, int type)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-03-31 02:02:38 +08:00
|
|
|
const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT);
|
2009-11-13 17:52:56 +08:00
|
|
|
if (!reiserfs_posixacl(dentry->d_sb))
|
2005-07-13 11:21:28 +08:00
|
|
|
return 0;
|
2009-03-31 02:02:38 +08:00
|
|
|
if (list && size <= list_size)
|
|
|
|
memcpy(list, POSIX_ACL_XATTR_DEFAULT, size);
|
|
|
|
return size;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-05-14 08:53:19 +08:00
|
|
|
const struct xattr_handler reiserfs_posix_acl_default_handler = {
|
2005-06-23 15:10:19 +08:00
|
|
|
.prefix = POSIX_ACL_XATTR_DEFAULT,
|
2009-11-13 17:52:56 +08:00
|
|
|
.flags = ACL_TYPE_DEFAULT,
|
|
|
|
.get = posix_acl_get,
|
|
|
|
.set = posix_acl_set,
|
2005-04-17 06:20:36 +08:00
|
|
|
.list = posix_acl_default_list,
|
|
|
|
};
|