4 * (C) 2005 Andreas Gruenbacher <agruen@suse.de>
6 * This file is released under the GPL.
10 #include <linux/shmem_fs.h>
11 #include <linux/xattr.h>
12 #include <linux/generic_acl.h>
15 * shmem_get_acl - generic_acl_operations->getacl() operation
17 static struct posix_acl
*
18 shmem_get_acl(struct inode
*inode
, int type
)
20 struct posix_acl
*acl
= NULL
;
22 spin_lock(&inode
->i_lock
);
25 acl
= posix_acl_dup(SHMEM_I(inode
)->i_acl
);
28 case ACL_TYPE_DEFAULT
:
29 acl
= posix_acl_dup(SHMEM_I(inode
)->i_default_acl
);
32 spin_unlock(&inode
->i_lock
);
38 * shmem_get_acl - generic_acl_operations->setacl() operation
41 shmem_set_acl(struct inode
*inode
, int type
, struct posix_acl
*acl
)
43 struct posix_acl
*free
= NULL
;
45 spin_lock(&inode
->i_lock
);
48 free
= SHMEM_I(inode
)->i_acl
;
49 SHMEM_I(inode
)->i_acl
= posix_acl_dup(acl
);
52 case ACL_TYPE_DEFAULT
:
53 free
= SHMEM_I(inode
)->i_default_acl
;
54 SHMEM_I(inode
)->i_default_acl
= posix_acl_dup(acl
);
57 spin_unlock(&inode
->i_lock
);
58 posix_acl_release(free
);
61 struct generic_acl_operations shmem_acl_ops
= {
62 .getacl
= shmem_get_acl
,
63 .setacl
= shmem_set_acl
,
67 * shmem_list_acl_access, shmem_get_acl_access, shmem_set_acl_access,
68 * shmem_xattr_acl_access_handler - plumbing code to implement the
69 * system.posix_acl_access xattr using the generic acl functions.
73 shmem_list_acl_access(struct inode
*inode
, char *list
, size_t list_size
,
74 const char *name
, size_t name_len
)
76 return generic_acl_list(inode
, &shmem_acl_ops
, ACL_TYPE_ACCESS
,
81 shmem_get_acl_access(struct inode
*inode
, const char *name
, void *buffer
,
84 if (strcmp(name
, "") != 0)
86 return generic_acl_get(inode
, &shmem_acl_ops
, ACL_TYPE_ACCESS
, buffer
,
91 shmem_set_acl_access(struct inode
*inode
, const char *name
, const void *value
,
92 size_t size
, int flags
)
94 if (strcmp(name
, "") != 0)
96 return generic_acl_set(inode
, &shmem_acl_ops
, ACL_TYPE_ACCESS
, value
,
100 struct xattr_handler shmem_xattr_acl_access_handler
= {
101 .prefix
= POSIX_ACL_XATTR_ACCESS
,
102 .list
= shmem_list_acl_access
,
103 .get
= shmem_get_acl_access
,
104 .set
= shmem_set_acl_access
,
108 * shmem_list_acl_default, shmem_get_acl_default, shmem_set_acl_default,
109 * shmem_xattr_acl_default_handler - plumbing code to implement the
110 * system.posix_acl_default xattr using the generic acl functions.
114 shmem_list_acl_default(struct inode
*inode
, char *list
, size_t list_size
,
115 const char *name
, size_t name_len
)
117 return generic_acl_list(inode
, &shmem_acl_ops
, ACL_TYPE_DEFAULT
,
122 shmem_get_acl_default(struct inode
*inode
, const char *name
, void *buffer
,
125 if (strcmp(name
, "") != 0)
127 return generic_acl_get(inode
, &shmem_acl_ops
, ACL_TYPE_DEFAULT
, buffer
,
132 shmem_set_acl_default(struct inode
*inode
, const char *name
, const void *value
,
133 size_t size
, int flags
)
135 if (strcmp(name
, "") != 0)
137 return generic_acl_set(inode
, &shmem_acl_ops
, ACL_TYPE_DEFAULT
, value
,
141 struct xattr_handler shmem_xattr_acl_default_handler
= {
142 .prefix
= POSIX_ACL_XATTR_DEFAULT
,
143 .list
= shmem_list_acl_default
,
144 .get
= shmem_get_acl_default
,
145 .set
= shmem_set_acl_default
,
149 * shmem_acl_init - Inizialize the acl(s) of a new inode
152 shmem_acl_init(struct inode
*inode
, struct inode
*dir
)
154 return generic_acl_init(inode
, dir
, &shmem_acl_ops
);
158 * shmem_acl_destroy_inode - destroy acls hanging off the in-memory inode
160 * This is done before destroying the actual inode.
164 shmem_acl_destroy_inode(struct inode
*inode
)
166 if (SHMEM_I(inode
)->i_acl
)
167 posix_acl_release(SHMEM_I(inode
)->i_acl
);
168 SHMEM_I(inode
)->i_acl
= NULL
;
169 if (SHMEM_I(inode
)->i_default_acl
)
170 posix_acl_release(SHMEM_I(inode
)->i_default_acl
);
171 SHMEM_I(inode
)->i_default_acl
= NULL
;
175 * shmem_check_acl - check_acl() callback for generic_permission()
178 shmem_check_acl(struct inode
*inode
, int mask
)
180 struct posix_acl
*acl
= shmem_get_acl(inode
, ACL_TYPE_ACCESS
);
183 int error
= posix_acl_permission(inode
, acl
, mask
);
184 posix_acl_release(acl
);
191 * shmem_permission - permission() inode operation
194 shmem_permission(struct inode
*inode
, int mask
, struct nameidata
*nd
)
196 return generic_permission(inode
, mask
, shmem_check_acl
);