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/uaccess.h>
20 #include "lm_interface.h"
28 * gfs2_ea_name2type - get the type of the ea, and truncate type from the name
29 * @namep: ea name, possibly with type appended
31 * Returns: GFS2_EATYPE_XXX
34 unsigned int gfs2_ea_name2type(const char *name, char **truncated_name)
38 if (strncmp(name, "system.", 7) == 0) {
39 type = GFS2_EATYPE_SYS;
41 *truncated_name = strchr(name, '.') + 1;
42 } else if (strncmp(name, "user.", 5) == 0) {
43 type = GFS2_EATYPE_USR;
45 *truncated_name = strchr(name, '.') + 1;
47 type = GFS2_EATYPE_UNUSED;
49 *truncated_name = NULL;
55 static int user_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
57 struct inode *inode = ip->i_vnode;
58 int error = permission(inode, MAY_READ, NULL);
62 return gfs2_ea_get_i(ip, er);
65 static int user_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
67 struct inode *inode = ip->i_vnode;
69 if (S_ISREG(inode->i_mode) ||
70 (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) {
71 int error = permission(inode, MAY_WRITE, NULL);
77 return gfs2_ea_set_i(ip, er);
80 static int user_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
82 struct inode *inode = ip->i_vnode;
84 if (S_ISREG(inode->i_mode) ||
85 (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) {
86 int error = permission(inode, MAY_WRITE, NULL);
92 return gfs2_ea_remove_i(ip, er);
95 static int system_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
97 if (!GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) &&
98 !GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len) &&
99 !capable(CAP_SYS_ADMIN))
102 if (ip->i_sbd->sd_args.ar_posix_acl == 0 &&
103 (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) ||
104 GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)))
109 return gfs2_ea_get_i(ip, er);
112 static int system_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
117 if (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len)) {
118 if (!(er->er_flags & GFS2_ERF_MODE)) {
119 er->er_mode = ip->i_di.di_mode;
120 er->er_flags |= GFS2_ERF_MODE;
122 error = gfs2_acl_validate_set(ip, 1, er,
123 &remove, &er->er_mode);
126 error = gfs2_ea_set_i(ip, er);
130 gfs2_ea_remove_i(ip, er);
133 } else if (GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)) {
134 error = gfs2_acl_validate_set(ip, 0, er,
139 error = gfs2_ea_set_i(ip, er);
141 error = gfs2_ea_remove_i(ip, er);
142 if (error == -ENODATA)
151 static int system_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
153 if (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len)) {
154 int error = gfs2_acl_validate_remove(ip, 1);
158 } else if (GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)) {
159 int error = gfs2_acl_validate_remove(ip, 0);
166 return gfs2_ea_remove_i(ip, er);
169 static struct gfs2_eattr_operations gfs2_user_eaops = {
170 .eo_get = user_eo_get,
171 .eo_set = user_eo_set,
172 .eo_remove = user_eo_remove,
176 struct gfs2_eattr_operations gfs2_system_eaops = {
177 .eo_get = system_eo_get,
178 .eo_set = system_eo_set,
179 .eo_remove = system_eo_remove,
183 struct gfs2_eattr_operations *gfs2_ea_ops[] = {