]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/os/linux/kernel/linux/xattr_compat.h
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / include / os / linux / kernel / 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 typedef const struct xattr_handler      xattr_handler_t;
39
40 /*
41  * 4.5 API change,
42  */
43 #if defined(HAVE_XATTR_LIST_SIMPLE)
44 #define ZPL_XATTR_LIST_WRAPPER(fn)                                      \
45 static bool                                                             \
46 fn(struct dentry *dentry)                                               \
47 {                                                                       \
48         return (!!__ ## fn(dentry->d_inode, NULL, 0, NULL, 0));         \
49 }
50 /*
51  * 4.4 API change,
52  */
53 #elif defined(HAVE_XATTR_LIST_DENTRY)
54 #define ZPL_XATTR_LIST_WRAPPER(fn)                                      \
55 static size_t                                                           \
56 fn(struct dentry *dentry, char *list, size_t list_size,                 \
57     const char *name, size_t name_len, int type)                        \
58 {                                                                       \
59         return (__ ## fn(dentry->d_inode,                               \
60             list, list_size, name, name_len));                          \
61 }
62 /*
63  * 2.6.33 API change,
64  */
65 #elif defined(HAVE_XATTR_LIST_HANDLER)
66 #define ZPL_XATTR_LIST_WRAPPER(fn)                                      \
67 static size_t                                                           \
68 fn(const struct xattr_handler *handler, struct dentry *dentry,          \
69     char *list, size_t list_size, const char *name, size_t name_len)    \
70 {                                                                       \
71         return (__ ## fn(dentry->d_inode,                               \
72             list, list_size, name, name_len));                          \
73 }
74 #else
75 #error "Unsupported kernel"
76 #endif
77
78 /*
79  * 4.7 API change,
80  * The xattr_handler->get() callback was changed to take a both dentry and
81  * inode, because the dentry might not be attached to an inode yet.
82  */
83 #if defined(HAVE_XATTR_GET_DENTRY_INODE)
84 #define ZPL_XATTR_GET_WRAPPER(fn)                                       \
85 static int                                                              \
86 fn(const struct xattr_handler *handler, struct dentry *dentry,          \
87     struct inode *inode, const char *name, void *buffer, size_t size)   \
88 {                                                                       \
89         return (__ ## fn(inode, name, buffer, size));                   \
90 }
91 /*
92  * 4.4 API change,
93  * The xattr_handler->get() callback was changed to take a xattr_handler,
94  * and handler_flags argument was removed and should be accessed by
95  * handler->flags.
96  */
97 #elif defined(HAVE_XATTR_GET_HANDLER)
98 #define ZPL_XATTR_GET_WRAPPER(fn)                                       \
99 static int                                                              \
100 fn(const struct xattr_handler *handler, struct dentry *dentry,          \
101     const char *name, void *buffer, size_t size)                        \
102 {                                                                       \
103         return (__ ## fn(dentry->d_inode, name, buffer, size));         \
104 }
105 /*
106  * 2.6.33 API change,
107  * The xattr_handler->get() callback was changed to take a dentry
108  * instead of an inode, and a handler_flags argument was added.
109  */
110 #elif defined(HAVE_XATTR_GET_DENTRY)
111 #define ZPL_XATTR_GET_WRAPPER(fn)                                       \
112 static int                                                              \
113 fn(struct dentry *dentry, const char *name, void *buffer, size_t size,  \
114     int unused_handler_flags)                                           \
115 {                                                                       \
116         return (__ ## fn(dentry->d_inode, name, buffer, size));         \
117 }
118 #else
119 #error "Unsupported kernel"
120 #endif
121
122 /*
123  * 4.7 API change,
124  * The xattr_handler->set() callback was changed to take a both dentry and
125  * inode, because the dentry might not be attached to an inode yet.
126  */
127 #if defined(HAVE_XATTR_SET_DENTRY_INODE)
128 #define ZPL_XATTR_SET_WRAPPER(fn)                                       \
129 static int                                                              \
130 fn(const struct xattr_handler *handler, struct dentry *dentry,          \
131     struct inode *inode, const char *name, const void *buffer,          \
132     size_t size, int flags)                                             \
133 {                                                                       \
134         return (__ ## fn(inode, name, buffer, size, flags));            \
135 }
136 /*
137  * 4.4 API change,
138  * The xattr_handler->set() callback was changed to take a xattr_handler,
139  * and handler_flags argument was removed and should be accessed by
140  * handler->flags.
141  */
142 #elif defined(HAVE_XATTR_SET_HANDLER)
143 #define ZPL_XATTR_SET_WRAPPER(fn)                                       \
144 static int                                                              \
145 fn(const struct xattr_handler *handler, struct dentry *dentry,          \
146     const char *name, const void *buffer, size_t size, int flags)       \
147 {                                                                       \
148         return (__ ## fn(dentry->d_inode, name, buffer, size, flags));  \
149 }
150 /*
151  * 2.6.33 API change,
152  * The xattr_handler->set() callback was changed to take a dentry
153  * instead of an inode, and a handler_flags argument was added.
154  */
155 #elif defined(HAVE_XATTR_SET_DENTRY)
156 #define ZPL_XATTR_SET_WRAPPER(fn)                                       \
157 static int                                                              \
158 fn(struct dentry *dentry, const char *name, const void *buffer,         \
159     size_t size, int flags, int unused_handler_flags)                   \
160 {                                                                       \
161         return (__ ## fn(dentry->d_inode, name, buffer, size, flags));  \
162 }
163 #else
164 #error "Unsupported kernel"
165 #endif
166
167 /*
168  * Linux 3.7 API change. posix_acl_{from,to}_xattr gained the user_ns
169  * parameter.  All callers are expected to pass the &init_user_ns which
170  * is available through the init credential (kcred).
171  */
172 static inline struct posix_acl *
173 zpl_acl_from_xattr(const void *value, int size)
174 {
175         return (posix_acl_from_xattr(kcred->user_ns, value, size));
176 }
177
178 static inline int
179 zpl_acl_to_xattr(struct posix_acl *acl, void *value, int size)
180 {
181         return (posix_acl_to_xattr(kcred->user_ns, acl, value, size));
182 }
183
184 #endif /* _ZFS_XATTR_H */