writeback: split writeback_inodes_wb
[linux-2.6/next.git] / include / linux / posix_acl.h
blob67608161df6b574eb5e382678d58e9683e30a6a6
1 /*
2 File: linux/posix_acl.h
4 (C) 2002 Andreas Gruenbacher, <a.gruenbacher@computer.org>
5 */
8 #ifndef __LINUX_POSIX_ACL_H
9 #define __LINUX_POSIX_ACL_H
11 #include <linux/slab.h>
13 #define ACL_UNDEFINED_ID (-1)
15 /* a_type field in acl_user_posix_entry_t */
16 #define ACL_TYPE_ACCESS (0x8000)
17 #define ACL_TYPE_DEFAULT (0x4000)
19 /* e_tag entry in struct posix_acl_entry */
20 #define ACL_USER_OBJ (0x01)
21 #define ACL_USER (0x02)
22 #define ACL_GROUP_OBJ (0x04)
23 #define ACL_GROUP (0x08)
24 #define ACL_MASK (0x10)
25 #define ACL_OTHER (0x20)
27 /* permissions in the e_perm field */
28 #define ACL_READ (0x04)
29 #define ACL_WRITE (0x02)
30 #define ACL_EXECUTE (0x01)
31 //#define ACL_ADD (0x08)
32 //#define ACL_DELETE (0x10)
34 struct posix_acl_entry {
35 short e_tag;
36 unsigned short e_perm;
37 unsigned int e_id;
40 struct posix_acl {
41 atomic_t a_refcount;
42 unsigned int a_count;
43 struct posix_acl_entry a_entries[0];
46 #define FOREACH_ACL_ENTRY(pa, acl, pe) \
47 for(pa=(acl)->a_entries, pe=pa+(acl)->a_count; pa<pe; pa++)
51 * Duplicate an ACL handle.
53 static inline struct posix_acl *
54 posix_acl_dup(struct posix_acl *acl)
56 if (acl)
57 atomic_inc(&acl->a_refcount);
58 return acl;
62 * Free an ACL handle.
64 static inline void
65 posix_acl_release(struct posix_acl *acl)
67 if (acl && atomic_dec_and_test(&acl->a_refcount))
68 kfree(acl);
72 /* posix_acl.c */
74 extern struct posix_acl *posix_acl_alloc(int, gfp_t);
75 extern struct posix_acl *posix_acl_clone(const struct posix_acl *, gfp_t);
76 extern int posix_acl_valid(const struct posix_acl *);
77 extern int posix_acl_permission(struct inode *, const struct posix_acl *, int);
78 extern struct posix_acl *posix_acl_from_mode(mode_t, gfp_t);
79 extern int posix_acl_equiv_mode(const struct posix_acl *, mode_t *);
80 extern int posix_acl_create_masq(struct posix_acl *, mode_t *);
81 extern int posix_acl_chmod_masq(struct posix_acl *, mode_t);
83 extern struct posix_acl *get_posix_acl(struct inode *, int);
84 extern int set_posix_acl(struct inode *, int, struct posix_acl *);
86 #ifdef CONFIG_FS_POSIX_ACL
87 static inline struct posix_acl *get_cached_acl(struct inode *inode, int type)
89 struct posix_acl **p, *acl;
90 switch (type) {
91 case ACL_TYPE_ACCESS:
92 p = &inode->i_acl;
93 break;
94 case ACL_TYPE_DEFAULT:
95 p = &inode->i_default_acl;
96 break;
97 default:
98 return ERR_PTR(-EINVAL);
100 acl = ACCESS_ONCE(*p);
101 if (acl) {
102 spin_lock(&inode->i_lock);
103 acl = *p;
104 if (acl != ACL_NOT_CACHED)
105 acl = posix_acl_dup(acl);
106 spin_unlock(&inode->i_lock);
108 return acl;
111 static inline void set_cached_acl(struct inode *inode,
112 int type,
113 struct posix_acl *acl)
115 struct posix_acl *old = NULL;
116 spin_lock(&inode->i_lock);
117 switch (type) {
118 case ACL_TYPE_ACCESS:
119 old = inode->i_acl;
120 inode->i_acl = posix_acl_dup(acl);
121 break;
122 case ACL_TYPE_DEFAULT:
123 old = inode->i_default_acl;
124 inode->i_default_acl = posix_acl_dup(acl);
125 break;
127 spin_unlock(&inode->i_lock);
128 if (old != ACL_NOT_CACHED)
129 posix_acl_release(old);
132 static inline void forget_cached_acl(struct inode *inode, int type)
134 struct posix_acl *old = NULL;
135 spin_lock(&inode->i_lock);
136 switch (type) {
137 case ACL_TYPE_ACCESS:
138 old = inode->i_acl;
139 inode->i_acl = ACL_NOT_CACHED;
140 break;
141 case ACL_TYPE_DEFAULT:
142 old = inode->i_default_acl;
143 inode->i_default_acl = ACL_NOT_CACHED;
144 break;
146 spin_unlock(&inode->i_lock);
147 if (old != ACL_NOT_CACHED)
148 posix_acl_release(old);
151 static inline void forget_all_cached_acls(struct inode *inode)
153 struct posix_acl *old_access, *old_default;
154 spin_lock(&inode->i_lock);
155 old_access = inode->i_acl;
156 old_default = inode->i_default_acl;
157 inode->i_acl = inode->i_default_acl = ACL_NOT_CACHED;
158 spin_unlock(&inode->i_lock);
159 if (old_access != ACL_NOT_CACHED)
160 posix_acl_release(old_access);
161 if (old_default != ACL_NOT_CACHED)
162 posix_acl_release(old_default);
164 #endif
166 static inline void cache_no_acl(struct inode *inode)
168 #ifdef CONFIG_FS_POSIX_ACL
169 inode->i_acl = NULL;
170 inode->i_default_acl = NULL;
171 #endif
174 #endif /* __LINUX_POSIX_ACL_H */