2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License v.2.
10 #include <linux/sched.h>
11 #include <linux/slab.h>
12 #include <linux/spinlock.h>
13 #include <linux/completion.h>
14 #include <linux/buffer_head.h>
15 #include <linux/xattr.h>
16 #include <asm/semaphore.h>
17 #include <asm/uaccess.h>
25 * gfs2_ea_name2type - get the type of the ea, and truncate type from the name
26 * @namep: ea name, possibly with type appended
28 * Returns: GFS2_EATYPE_XXX
31 unsigned int gfs2_ea_name2type(const char *name, char **truncated_name)
35 if (strncmp(name, "system.", 7) == 0) {
36 type = GFS2_EATYPE_SYS;
38 *truncated_name = strchr(name, '.') + 1;
39 } else if (strncmp(name, "user.", 5) == 0) {
40 type = GFS2_EATYPE_USR;
42 *truncated_name = strchr(name, '.') + 1;
44 type = GFS2_EATYPE_UNUSED;
46 *truncated_name = NULL;
52 static int user_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
54 struct inode *inode = ip->i_vnode;
55 int error = permission(inode, MAY_READ, NULL);
59 return gfs2_ea_get_i(ip, er);
62 static int user_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
64 struct inode *inode = ip->i_vnode;
66 if (S_ISREG(inode->i_mode) ||
67 (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) {
68 int error = permission(inode, MAY_WRITE, NULL);
74 return gfs2_ea_set_i(ip, er);
77 static int user_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
79 struct inode *inode = ip->i_vnode;
81 if (S_ISREG(inode->i_mode) ||
82 (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) {
83 int error = permission(inode, MAY_WRITE, NULL);
89 return gfs2_ea_remove_i(ip, er);
92 static int system_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
94 if (!GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) &&
95 !GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len) &&
96 !capable(CAP_SYS_ADMIN))
99 if (ip->i_sbd->sd_args.ar_posix_acl == 0 &&
100 (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) ||
101 GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)))
106 return gfs2_ea_get_i(ip, er);
109 static int system_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
114 if (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len)) {
115 if (!(er->er_flags & GFS2_ERF_MODE)) {
116 er->er_mode = ip->i_di.di_mode;
117 er->er_flags |= GFS2_ERF_MODE;
119 error = gfs2_acl_validate_set(ip, 1, er,
120 &remove, &er->er_mode);
123 error = gfs2_ea_set_i(ip, er);
127 gfs2_ea_remove_i(ip, er);
130 } else if (GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)) {
131 error = gfs2_acl_validate_set(ip, 0, er,
136 error = gfs2_ea_set_i(ip, er);
138 error = gfs2_ea_remove_i(ip, er);
139 if (error == -ENODATA)
148 static int system_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
150 if (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len)) {
151 int error = gfs2_acl_validate_remove(ip, 1);
155 } else if (GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)) {
156 int error = gfs2_acl_validate_remove(ip, 0);
163 return gfs2_ea_remove_i(ip, er);
166 struct gfs2_eattr_operations gfs2_user_eaops = {
167 .eo_get = user_eo_get,
168 .eo_set = user_eo_set,
169 .eo_remove = user_eo_remove,
173 struct gfs2_eattr_operations gfs2_system_eaops = {
174 .eo_get = system_eo_get,
175 .eo_set = system_eo_set,
176 .eo_remove = system_eo_remove,
180 struct gfs2_eattr_operations *gfs2_ea_ops[] = {