ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / fs / xfs / xfs_acl.h
1 /*
2  * Copyright (c) 2001-2003 Silicon Graphics, Inc.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it would be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  *
12  * Further, this software is distributed without any warranty that it is
13  * free of the rightful claim of any third person regarding infringement
14  * or the like.  Any license provided herein, whether implied or
15  * otherwise, applies only to this software file.  Patent licenses, if
16  * any, provided herein do not apply to combinations of this program with
17  * other software, or any other product whatsoever.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write the Free Software Foundation, Inc., 59
21  * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22  *
23  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24  * Mountain View, CA  94043, or:
25  *
26  * http://www.sgi.com
27  *
28  * For further information regarding this notice, see:
29  *
30  * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31  */
32 #ifndef __XFS_ACL_H__
33 #define __XFS_ACL_H__
34
35 /*
36  * Access Control Lists
37  */
38 typedef __uint16_t      xfs_acl_perm_t;
39 typedef __int32_t       xfs_acl_type_t;
40 typedef __int32_t       xfs_acl_tag_t;
41 typedef __int32_t       xfs_acl_id_t;
42
43 #define XFS_ACL_MAX_ENTRIES 25
44 #define XFS_ACL_NOT_PRESENT (-1)
45
46 typedef struct xfs_acl_entry {
47         xfs_acl_tag_t   ae_tag;
48         xfs_acl_id_t    ae_id;
49         xfs_acl_perm_t  ae_perm;
50 } xfs_acl_entry_t;
51
52 typedef struct xfs_acl {
53         __int32_t       acl_cnt;
54         xfs_acl_entry_t acl_entry[XFS_ACL_MAX_ENTRIES];
55 } xfs_acl_t;
56
57 /* On-disk XFS extended attribute names */
58 #define SGI_ACL_FILE    "SGI_ACL_FILE"
59 #define SGI_ACL_DEFAULT "SGI_ACL_DEFAULT"
60 #define SGI_ACL_FILE_SIZE       (sizeof(SGI_ACL_FILE)-1)
61 #define SGI_ACL_DEFAULT_SIZE    (sizeof(SGI_ACL_DEFAULT)-1)
62
63
64 #ifdef __KERNEL__
65
66 #ifdef CONFIG_XFS_POSIX_ACL
67
68 struct vattr;
69 struct vnode;
70 struct xfs_inode;
71
72 extern int xfs_acl_inherit(struct vnode *, struct vattr *, xfs_acl_t *);
73 extern int xfs_acl_iaccess(struct xfs_inode *, mode_t, cred_t *);
74 extern int xfs_acl_get(struct vnode *, xfs_acl_t *, xfs_acl_t *);
75 extern int xfs_acl_set(struct vnode *, xfs_acl_t *, xfs_acl_t *);
76 extern int xfs_acl_vtoacl(struct vnode *, xfs_acl_t *, xfs_acl_t *);
77 extern int xfs_acl_vhasacl_access(struct vnode *);
78 extern int xfs_acl_vhasacl_default(struct vnode *);
79 extern int xfs_acl_vset(struct vnode *, void *, size_t, int);
80 extern int xfs_acl_vget(struct vnode *, void *, size_t, int);
81 extern int xfs_acl_vremove(struct vnode *vp, int);
82
83 extern struct kmem_zone *xfs_acl_zone;
84
85 #define _ACL_TYPE_ACCESS        1
86 #define _ACL_TYPE_DEFAULT       2
87 #define _ACL_PERM_INVALID(perm) ((perm) & ~(ACL_READ|ACL_WRITE|ACL_EXECUTE))
88
89 #define _ACL_DECL(a)            xfs_acl_t *(a) = NULL
90 #define _ACL_ALLOC(a)           ((a) = kmem_zone_alloc(xfs_acl_zone, KM_SLEEP))
91 #define _ACL_FREE(a)            ((a)? kmem_zone_free(xfs_acl_zone, (a)) : 0)
92 #define _ACL_ZONE_INIT(z,name)  ((z) = kmem_zone_init(sizeof(xfs_acl_t), name))
93 #define _ACL_ZONE_DESTROY(z)    (kmem_cache_destroy(z))
94 #define _ACL_INHERIT(c,v,d)     (xfs_acl_inherit(c,v,d))
95 #define _ACL_GET_ACCESS(pv,pa)  (xfs_acl_vtoacl(pv,pa,NULL) == 0)
96 #define _ACL_GET_DEFAULT(pv,pd) (xfs_acl_vtoacl(pv,NULL,pd) == 0)
97 #define _ACL_ACCESS_EXISTS      xfs_acl_vhasacl_access
98 #define _ACL_DEFAULT_EXISTS     xfs_acl_vhasacl_default
99 #define _ACL_XFS_IACCESS(i,m,c) (XFS_IFORK_Q(i) ? xfs_acl_iaccess(i,m,c) : -1)
100
101 #else
102 #define xfs_acl_vset(v,p,sz,t)  (-EOPNOTSUPP)
103 #define xfs_acl_vget(v,p,sz,t)  (-EOPNOTSUPP)
104 #define xfs_acl_vremove(v,t)    (-EOPNOTSUPP)
105 #define xfs_acl_vhasacl_access(v)       (0)
106 #define xfs_acl_vhasacl_default(v)      (0)
107 #define _ACL_DECL(a)            ((void)0)
108 #define _ACL_ALLOC(a)           (1)     /* successfully allocate nothing */
109 #define _ACL_FREE(a)            ((void)0)
110 #define _ACL_ZONE_INIT(z,name)  ((void)0)
111 #define _ACL_ZONE_DESTROY(z)    ((void)0)
112 #define _ACL_INHERIT(c,v,d)     (0)
113 #define _ACL_GET_ACCESS(pv,pa)  (0)
114 #define _ACL_GET_DEFAULT(pv,pd) (0)
115 #define _ACL_ACCESS_EXISTS      (NULL)
116 #define _ACL_DEFAULT_EXISTS     (NULL)
117 #define _ACL_XFS_IACCESS(i,m,c) (-1)
118 #endif
119
120 #endif  /* __KERNEL__ */
121
122 #endif  /* __XFS_ACL_H__ */