]> git.proxmox.com Git - mirror_zfs-debian.git/blob - include/linux/xattr_compat.h
Imported Upstream version 0.6.5.8
[mirror_zfs-debian.git] / include / linux / xattr_compat.h
1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (C) 2011 Lawrence Livermore National Security, LLC.
24 */
25
26 #ifndef _ZFS_XATTR_H
27 #define _ZFS_XATTR_H
28
29 #include <linux/posix_acl_xattr.h>
30
31 /*
32 * 2.6.35 API change,
33 * The const keyword was added to the 'struct xattr_handler' in the
34 * generic Linux super_block structure. To handle this we define an
35 * appropriate xattr_handler_t typedef which can be used. This was
36 * the preferred solution because it keeps the code clean and readable.
37 */
38 #ifdef HAVE_CONST_XATTR_HANDLER
39 typedef const struct xattr_handler xattr_handler_t;
40 #else
41 typedef struct xattr_handler xattr_handler_t;
42 #endif
43
44 /*
45 * 3.7 API change,
46 * Preferred XATTR_NAME_* definitions introduced, these are mapped to
47 * the previous definitions for older kernels.
48 */
49 #ifndef XATTR_NAME_POSIX_ACL_DEFAULT
50 #define XATTR_NAME_POSIX_ACL_DEFAULT POSIX_ACL_XATTR_DEFAULT
51 #endif
52
53 #ifndef XATTR_NAME_POSIX_ACL_ACCESS
54 #define XATTR_NAME_POSIX_ACL_ACCESS POSIX_ACL_XATTR_ACCESS
55 #endif
56
57 /*
58 * 4.5 API change,
59 */
60 #if defined(HAVE_XATTR_LIST_SIMPLE)
61 #define ZPL_XATTR_LIST_WRAPPER(fn) \
62 static bool \
63 fn(struct dentry *dentry) \
64 { \
65 return (!!__ ## fn(dentry->d_inode, NULL, 0, NULL, 0)); \
66 }
67 /*
68 * 4.4 API change,
69 */
70 #elif defined(HAVE_XATTR_LIST_DENTRY)
71 #define ZPL_XATTR_LIST_WRAPPER(fn) \
72 static size_t \
73 fn(struct dentry *dentry, char *list, size_t list_size, \
74 const char *name, size_t name_len, int type) \
75 { \
76 return (__ ## fn(dentry->d_inode, \
77 list, list_size, name, name_len)); \
78 }
79 /*
80 * 2.6.33 API change,
81 */
82 #elif defined(HAVE_XATTR_LIST_HANDLER)
83 #define ZPL_XATTR_LIST_WRAPPER(fn) \
84 static size_t \
85 fn(const struct xattr_handler *handler, struct dentry *dentry, \
86 char *list, size_t list_size, const char *name, size_t name_len) \
87 { \
88 return (__ ## fn(dentry->d_inode, \
89 list, list_size, name, name_len)); \
90 }
91 /*
92 * 2.6.32 API
93 */
94 #elif defined(HAVE_XATTR_LIST_INODE)
95 #define ZPL_XATTR_LIST_WRAPPER(fn) \
96 static size_t \
97 fn(struct inode *ip, char *list, size_t list_size, \
98 const char *name, size_t name_len) \
99 { \
100 return (__ ## fn(ip, list, list_size, name, name_len)); \
101 }
102 #endif
103
104 /*
105 * 4.7 API change,
106 * The xattr_handler->get() callback was changed to take a both dentry and
107 * inode, because the dentry might not be attached to an inode yet.
108 */
109 #if defined(HAVE_XATTR_GET_DENTRY_INODE)
110 #define ZPL_XATTR_GET_WRAPPER(fn) \
111 static int \
112 fn(const struct xattr_handler *handler, struct dentry *dentry, \
113 struct inode *inode, const char *name, void *buffer, size_t size) \
114 { \
115 return (__ ## fn(inode, name, buffer, size)); \
116 }
117 /*
118 * 4.4 API change,
119 * The xattr_handler->get() callback was changed to take a xattr_handler,
120 * and handler_flags argument was removed and should be accessed by
121 * handler->flags.
122 */
123 #elif defined(HAVE_XATTR_GET_HANDLER)
124 #define ZPL_XATTR_GET_WRAPPER(fn) \
125 static int \
126 fn(const struct xattr_handler *handler, struct dentry *dentry, \
127 const char *name, void *buffer, size_t size) \
128 { \
129 return (__ ## fn(dentry->d_inode, name, buffer, size)); \
130 }
131 /*
132 * 2.6.33 API change,
133 * The xattr_handler->get() callback was changed to take a dentry
134 * instead of an inode, and a handler_flags argument was added.
135 */
136 #elif defined(HAVE_XATTR_GET_DENTRY)
137 #define ZPL_XATTR_GET_WRAPPER(fn) \
138 static int \
139 fn(struct dentry *dentry, const char *name, void *buffer, size_t size, \
140 int unused_handler_flags) \
141 { \
142 return (__ ## fn(dentry->d_inode, name, buffer, size)); \
143 }
144 /*
145 * 2.6.32 API
146 */
147 #elif defined(HAVE_XATTR_GET_INODE)
148 #define ZPL_XATTR_GET_WRAPPER(fn) \
149 static int \
150 fn(struct inode *ip, const char *name, void *buffer, size_t size) \
151 { \
152 return (__ ## fn(ip, name, buffer, size)); \
153 }
154 #endif
155
156 /*
157 * 4.7 API change,
158 * The xattr_handler->set() callback was changed to take a both dentry and
159 * inode, because the dentry might not be attached to an inode yet.
160 */
161 #if defined(HAVE_XATTR_SET_DENTRY_INODE)
162 #define ZPL_XATTR_SET_WRAPPER(fn) \
163 static int \
164 fn(const struct xattr_handler *handler, struct dentry *dentry, \
165 struct inode *inode, const char *name, const void *buffer, \
166 size_t size, int flags) \
167 { \
168 return (__ ## fn(inode, name, buffer, size, flags)); \
169 }
170 /*
171 * 4.4 API change,
172 * The xattr_handler->set() callback was changed to take a xattr_handler,
173 * and handler_flags argument was removed and should be accessed by
174 * handler->flags.
175 */
176 #elif defined(HAVE_XATTR_SET_HANDLER)
177 #define ZPL_XATTR_SET_WRAPPER(fn) \
178 static int \
179 fn(const struct xattr_handler *handler, struct dentry *dentry, \
180 const char *name, const void *buffer, size_t size, int flags) \
181 { \
182 return (__ ## fn(dentry->d_inode, name, buffer, size, flags)); \
183 }
184 /*
185 * 2.6.33 API change,
186 * The xattr_handler->set() callback was changed to take a dentry
187 * instead of an inode, and a handler_flags argument was added.
188 */
189 #elif defined(HAVE_XATTR_SET_DENTRY)
190 #define ZPL_XATTR_SET_WRAPPER(fn) \
191 static int \
192 fn(struct dentry *dentry, const char *name, const void *buffer, \
193 size_t size, int flags, int unused_handler_flags) \
194 { \
195 return (__ ## fn(dentry->d_inode, name, buffer, size, flags)); \
196 }
197 /*
198 * 2.6.32 API
199 */
200 #elif defined(HAVE_XATTR_SET_INODE)
201 #define ZPL_XATTR_SET_WRAPPER(fn) \
202 static int \
203 fn(struct inode *ip, const char *name, const void *buffer, \
204 size_t size, int flags) \
205 { \
206 return (__ ## fn(ip, name, buffer, size, flags)); \
207 }
208 #endif
209
210 #ifdef HAVE_6ARGS_SECURITY_INODE_INIT_SECURITY
211 #define zpl_security_inode_init_security(ip, dip, qstr, nm, val, len) \
212 security_inode_init_security(ip, dip, qstr, nm, val, len)
213 #else
214 #define zpl_security_inode_init_security(ip, dip, qstr, nm, val, len) \
215 security_inode_init_security(ip, dip, nm, val, len)
216 #endif /* HAVE_6ARGS_SECURITY_INODE_INIT_SECURITY */
217
218 /*
219 * Linux 3.7 API change. posix_acl_{from,to}_xattr gained the user_ns
220 * parameter. All callers are expected to pass the &init_user_ns which
221 * is available through the init credential (kcred).
222 */
223 #ifdef HAVE_POSIX_ACL_FROM_XATTR_USERNS
224 static inline struct posix_acl *
225 zpl_acl_from_xattr(const void *value, int size)
226 {
227 return (posix_acl_from_xattr(kcred->user_ns, value, size));
228 }
229
230 static inline int
231 zpl_acl_to_xattr(struct posix_acl *acl, void *value, int size)
232 {
233 return (posix_acl_to_xattr(kcred->user_ns, acl, value, size));
234 }
235
236 #else
237
238 static inline struct posix_acl *
239 zpl_acl_from_xattr(const void *value, int size)
240 {
241 return (posix_acl_from_xattr(value, size));
242 }
243
244 static inline int
245 zpl_acl_to_xattr(struct posix_acl *acl, void *value, int size)
246 {
247 return (posix_acl_to_xattr(acl, value, size));
248 }
249 #endif /* HAVE_POSIX_ACL_FROM_XATTR_USERNS */
250
251 #endif /* _ZFS_XATTR_H */