Linux-2.6.12-rc2
[safe/jmp/linux-2.6] / fs / xfs / xfs_acl.h
1 /*
2  * Copyright (c) 2001-2004 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 CONFIG_XFS_POSIX_ACL
65
66 struct vattr;
67 struct vnode;
68 struct xfs_inode;
69
70 extern struct kmem_zone *xfs_acl_zone;
71 #define xfs_acl_zone_init(zone, name)   \
72                 (zone) = kmem_zone_init(sizeof(xfs_acl_t), name)
73 #define xfs_acl_zone_destroy(zone)      kmem_cache_destroy(zone)
74
75 extern int xfs_acl_inherit(struct vnode *, struct vattr *, xfs_acl_t *);
76 extern int xfs_acl_iaccess(struct xfs_inode *, mode_t, cred_t *);
77 extern int xfs_acl_vtoacl(struct vnode *, xfs_acl_t *, xfs_acl_t *);
78 extern int xfs_acl_vhasacl_access(struct vnode *);
79 extern int xfs_acl_vhasacl_default(struct vnode *);
80 extern int xfs_acl_vset(struct vnode *, void *, size_t, int);
81 extern int xfs_acl_vget(struct vnode *, void *, size_t, int);
82 extern int xfs_acl_vremove(struct vnode *vp, int);
83
84 #define _ACL_TYPE_ACCESS        1
85 #define _ACL_TYPE_DEFAULT       2
86 #define _ACL_PERM_INVALID(perm) ((perm) & ~(ACL_READ|ACL_WRITE|ACL_EXECUTE))
87
88 #define _ACL_INHERIT(c,v,d)     (xfs_acl_inherit(c,v,d))
89 #define _ACL_GET_ACCESS(pv,pa)  (xfs_acl_vtoacl(pv,pa,NULL) == 0)
90 #define _ACL_GET_DEFAULT(pv,pd) (xfs_acl_vtoacl(pv,NULL,pd) == 0)
91 #define _ACL_ACCESS_EXISTS      xfs_acl_vhasacl_access
92 #define _ACL_DEFAULT_EXISTS     xfs_acl_vhasacl_default
93 #define _ACL_XFS_IACCESS(i,m,c) (XFS_IFORK_Q(i) ? xfs_acl_iaccess(i,m,c) : -1)
94
95 #define _ACL_ALLOC(a)           ((a) = kmem_zone_alloc(xfs_acl_zone, KM_SLEEP))
96 #define _ACL_FREE(a)            ((a)? kmem_zone_free(xfs_acl_zone, (a)):(void)0)
97
98 #else
99 #define xfs_acl_zone_init(zone,name)
100 #define xfs_acl_zone_destroy(zone)
101 #define xfs_acl_vset(v,p,sz,t)  (-EOPNOTSUPP)
102 #define xfs_acl_vget(v,p,sz,t)  (-EOPNOTSUPP)
103 #define xfs_acl_vremove(v,t)    (-EOPNOTSUPP)
104 #define xfs_acl_vhasacl_access(v)       (0)
105 #define xfs_acl_vhasacl_default(v)      (0)
106 #define _ACL_ALLOC(a)           (1)     /* successfully allocate nothing */
107 #define _ACL_FREE(a)            ((void)0)
108 #define _ACL_INHERIT(c,v,d)     (0)
109 #define _ACL_GET_ACCESS(pv,pa)  (0)
110 #define _ACL_GET_DEFAULT(pv,pd) (0)
111 #define _ACL_ACCESS_EXISTS      (NULL)
112 #define _ACL_DEFAULT_EXISTS     (NULL)
113 #define _ACL_XFS_IACCESS(i,m,c) (-1)
114 #endif
115
116 #endif  /* __XFS_ACL_H__ */