2006-01-16 17:50:04 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
|
2006-05-18 21:09:15 +02:00
|
|
|
* Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
|
2006-01-16 17:50:04 +01:00
|
|
|
*
|
|
|
|
* This copyrighted material is made available to anyone wishing to use,
|
|
|
|
* modify, copy, or redistribute it subject to the terms and conditions
|
2006-09-01 17:05:15 +02:00
|
|
|
* of the GNU General Public License version 2.
|
2006-01-16 17:50:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/buffer_head.h>
|
2009-10-02 12:50:54 +02:00
|
|
|
#include <linux/xattr.h>
|
2006-01-16 17:50:04 +01:00
|
|
|
#include <linux/posix_acl.h>
|
|
|
|
#include <linux/posix_acl_xattr.h>
|
2006-02-27 23:23:27 +01:00
|
|
|
#include <linux/gfs2_ondisk.h>
|
2006-01-16 17:50:04 +01:00
|
|
|
|
|
|
|
#include "gfs2.h"
|
2006-02-27 23:23:27 +01:00
|
|
|
#include "incore.h"
|
2006-01-16 17:50:04 +01:00
|
|
|
#include "acl.h"
|
2009-08-26 19:51:04 +02:00
|
|
|
#include "xattr.h"
|
2006-01-16 17:50:04 +01:00
|
|
|
#include "glock.h"
|
|
|
|
#include "inode.h"
|
|
|
|
#include "meta_io.h"
|
|
|
|
#include "trans.h"
|
2006-02-27 23:23:27 +01:00
|
|
|
#include "util.h"
|
2006-01-16 17:50:04 +01:00
|
|
|
|
2009-10-02 13:00:00 +02:00
|
|
|
static const char *gfs2_acl_name(int type)
|
2006-01-16 17:50:04 +01:00
|
|
|
{
|
2009-10-02 13:00:00 +02:00
|
|
|
switch (type) {
|
|
|
|
case ACL_TYPE_ACCESS:
|
|
|
|
return GFS2_POSIX_ACL_ACCESS;
|
|
|
|
case ACL_TYPE_DEFAULT:
|
|
|
|
return GFS2_POSIX_ACL_DEFAULT;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-01-16 17:50:04 +01:00
|
|
|
|
2011-11-23 14:31:51 +01:00
|
|
|
struct posix_acl *gfs2_get_acl(struct inode *inode, int type)
|
2009-10-02 13:00:00 +02:00
|
|
|
{
|
2011-11-23 14:31:51 +01:00
|
|
|
struct gfs2_inode *ip = GFS2_I(inode);
|
2009-10-02 13:00:00 +02:00
|
|
|
struct posix_acl *acl;
|
|
|
|
const char *name;
|
|
|
|
char *data;
|
|
|
|
int len;
|
2009-08-26 19:41:32 +02:00
|
|
|
|
2008-11-03 15:28:42 +01:00
|
|
|
if (!ip->i_eattr)
|
2009-10-02 13:00:00 +02:00
|
|
|
return NULL;
|
2006-01-16 17:50:04 +01:00
|
|
|
|
2009-10-02 13:00:00 +02:00
|
|
|
name = gfs2_acl_name(type);
|
|
|
|
if (name == NULL)
|
|
|
|
return ERR_PTR(-EINVAL);
|
2006-01-16 17:50:04 +01:00
|
|
|
|
2009-10-02 13:00:00 +02:00
|
|
|
len = gfs2_xattr_acl_get(ip, name, &data);
|
|
|
|
if (len < 0)
|
|
|
|
return ERR_PTR(len);
|
|
|
|
if (len == 0)
|
|
|
|
return NULL;
|
2006-01-16 17:50:04 +01:00
|
|
|
|
2012-09-11 05:17:44 +02:00
|
|
|
acl = posix_acl_from_xattr(&init_user_ns, data, len);
|
2009-10-02 13:00:00 +02:00
|
|
|
kfree(data);
|
|
|
|
return acl;
|
2006-01-16 17:50:04 +01:00
|
|
|
}
|
|
|
|
|
2013-12-20 14:16:52 +01:00
|
|
|
int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
|
2006-01-16 17:50:04 +01:00
|
|
|
{
|
|
|
|
int error;
|
2009-10-02 13:00:00 +02:00
|
|
|
int len;
|
|
|
|
char *data;
|
|
|
|
const char *name = gfs2_acl_name(type);
|
|
|
|
|
|
|
|
BUG_ON(name == NULL);
|
2011-07-23 09:10:32 +02:00
|
|
|
|
2015-02-09 18:53:04 +01:00
|
|
|
if (acl && acl->a_count > GFS2_ACL_MAX_ENTRIES(GFS2_SB(inode)))
|
2014-03-04 04:28:39 +01:00
|
|
|
return -E2BIG;
|
2009-10-02 12:50:54 +02:00
|
|
|
|
|
|
|
if (type == ACL_TYPE_ACCESS) {
|
2011-07-24 00:56:36 +02:00
|
|
|
umode_t mode = inode->i_mode;
|
2013-12-20 14:16:52 +01:00
|
|
|
|
2009-10-02 12:50:54 +02:00
|
|
|
error = posix_acl_equiv_mode(acl, &mode);
|
2013-12-20 14:16:52 +01:00
|
|
|
if (error < 0)
|
|
|
|
return error;
|
2009-10-02 12:50:54 +02:00
|
|
|
|
2013-12-20 14:16:52 +01:00
|
|
|
if (error == 0)
|
2009-10-02 12:50:54 +02:00
|
|
|
acl = NULL;
|
|
|
|
|
2014-03-19 16:51:28 +01:00
|
|
|
if (mode != inode->i_mode) {
|
|
|
|
inode->i_mode = mode;
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
}
|
2009-10-02 12:50:54 +02:00
|
|
|
}
|
|
|
|
|
2013-12-20 14:16:52 +01:00
|
|
|
if (acl) {
|
|
|
|
len = posix_acl_to_xattr(&init_user_ns, acl, NULL, 0);
|
|
|
|
if (len == 0)
|
|
|
|
return 0;
|
|
|
|
data = kmalloc(len, GFP_NOFS);
|
|
|
|
if (data == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
error = posix_acl_to_xattr(&init_user_ns, acl, data, len);
|
|
|
|
if (error < 0)
|
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
data = NULL;
|
|
|
|
len = 0;
|
2009-09-29 17:26:23 +02:00
|
|
|
}
|
2013-12-20 14:16:52 +01:00
|
|
|
|
|
|
|
error = __gfs2_xattr_set(inode, name, data, len, 0, GFS2_EATYPE_SYS);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (acl)
|
|
|
|
set_cached_acl(inode, type, acl);
|
|
|
|
else
|
|
|
|
forget_cached_acl(inode, type);
|
2009-10-02 12:50:54 +02:00
|
|
|
out:
|
2013-12-20 14:16:52 +01:00
|
|
|
kfree(data);
|
2009-10-02 12:50:54 +02:00
|
|
|
return error;
|
|
|
|
}
|