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 <linux/gfs2_ondisk.h>
17 #include <asm/semaphore.h>
18 #include <asm/uaccess.h>
21 #include "lm_interface.h"
29 * gfs2_ea_name2type - get the type of the ea, and truncate type from the name
30 * @namep: ea name, possibly with type appended
32 * Returns: GFS2_EATYPE_XXX
35 unsigned int gfs2_ea_name2type(const char *name, char **truncated_name)
39 if (strncmp(name, "system.", 7) == 0) {
40 type = GFS2_EATYPE_SYS;
42 *truncated_name = strchr(name, '.') + 1;
43 } else if (strncmp(name, "user.", 5) == 0) {
44 type = GFS2_EATYPE_USR;
46 *truncated_name = strchr(name, '.') + 1;
48 type = GFS2_EATYPE_UNUSED;
50 *truncated_name = NULL;
56 static int user_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
58 struct inode *inode = ip->i_vnode;
59 int error = permission(inode, MAY_READ, NULL);
63 return gfs2_ea_get_i(ip, er);
66 static int user_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
68 struct inode *inode = ip->i_vnode;
70 if (S_ISREG(inode->i_mode) ||
71 (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) {
72 int error = permission(inode, MAY_WRITE, NULL);
78 return gfs2_ea_set_i(ip, er);
81 static int user_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
83 struct inode *inode = ip->i_vnode;
85 if (S_ISREG(inode->i_mode) ||
86 (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) {
87 int error = permission(inode, MAY_WRITE, NULL);
93 return gfs2_ea_remove_i(ip, er);
96 static int system_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
98 if (!GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) &&
99 !GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len) &&
100 !capable(CAP_SYS_ADMIN))
103 if (ip->i_sbd->sd_args.ar_posix_acl == 0 &&
104 (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) ||
105 GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)))
110 return gfs2_ea_get_i(ip, er);
113 static int system_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
118 if (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len)) {
119 if (!(er->er_flags & GFS2_ERF_MODE)) {
120 er->er_mode = ip->i_di.di_mode;
121 er->er_flags |= GFS2_ERF_MODE;
123 error = gfs2_acl_validate_set(ip, 1, er,
124 &remove, &er->er_mode);
127 error = gfs2_ea_set_i(ip, er);
131 gfs2_ea_remove_i(ip, er);
134 } else if (GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)) {
135 error = gfs2_acl_validate_set(ip, 0, er,
140 error = gfs2_ea_set_i(ip, er);
142 error = gfs2_ea_remove_i(ip, er);
143 if (error == -ENODATA)
152 static int system_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
154 if (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len)) {
155 int error = gfs2_acl_validate_remove(ip, 1);
159 } else if (GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)) {
160 int error = gfs2_acl_validate_remove(ip, 0);
167 return gfs2_ea_remove_i(ip, er);
170 struct gfs2_eattr_operations gfs2_user_eaops = {
171 .eo_get = user_eo_get,
172 .eo_set = user_eo_set,
173 .eo_remove = user_eo_remove,
177 struct gfs2_eattr_operations gfs2_system_eaops = {
178 .eo_get = system_eo_get,
179 .eo_set = system_eo_set,
180 .eo_remove = system_eo_remove,
184 struct gfs2_eattr_operations *gfs2_ea_ops[] = {