dmar: fix using early fixmap mapping for DMAR table parsing
[deliverable/linux.git] / fs / cifs / xattr.c
CommitLineData
1da177e4
LT
1/*
2 * fs/cifs/xattr.c
3 *
79a58d1f 4 * Copyright (c) International Business Machines Corp., 2003, 2007
1da177e4
LT
5 * Author(s): Steve French (sfrench@us.ibm.com)
6 *
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
15 * the GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <linux/fs.h>
23#include <linux/posix_acl_xattr.h>
24#include "cifsfs.h"
25#include "cifspdu.h"
26#include "cifsglob.h"
27#include "cifsproto.h"
28#include "cifs_debug.h"
29
30#define MAX_EA_VALUE_SIZE 65535
31#define CIFS_XATTR_DOS_ATTRIB "user.DosAttrib"
32#define CIFS_XATTR_USER_PREFIX "user."
33#define CIFS_XATTR_SYSTEM_PREFIX "system."
34#define CIFS_XATTR_OS2_PREFIX "os2."
35#define CIFS_XATTR_SECURITY_PREFIX ".security"
36#define CIFS_XATTR_TRUSTED_PREFIX "trusted."
37#define XATTR_TRUSTED_PREFIX_LEN 8
38#define XATTR_SECURITY_PREFIX_LEN 9
39/* BB need to add server (Samba e.g) support for security and trusted prefix */
50c2f753 40
1da177e4
LT
41
42
79a58d1f 43int cifs_removexattr(struct dentry *direntry, const char *ea_name)
1da177e4
LT
44{
45 int rc = -EOPNOTSUPP;
46#ifdef CONFIG_CIFS_XATTR
47 int xid;
48 struct cifs_sb_info *cifs_sb;
49 struct cifsTconInfo *pTcon;
79a58d1f
SF
50 struct super_block *sb;
51 char *full_path;
52
53 if (direntry == NULL)
1da177e4 54 return -EIO;
79a58d1f 55 if (direntry->d_inode == NULL)
1da177e4
LT
56 return -EIO;
57 sb = direntry->d_inode->i_sb;
79a58d1f 58 if (sb == NULL)
1da177e4
LT
59 return -EIO;
60 xid = GetXid();
79a58d1f 61
1da177e4
LT
62 cifs_sb = CIFS_SB(sb);
63 pTcon = cifs_sb->tcon;
79a58d1f 64
1da177e4 65 full_path = build_path_from_dentry(direntry);
79a58d1f 66 if (full_path == NULL) {
1da177e4
LT
67 FreeXid(xid);
68 return -ENOMEM;
69 }
79a58d1f
SF
70 if (ea_name == NULL) {
71 cFYI(1, ("Null xattr names not supported"));
72 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5)
73 && (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4))) {
74 cFYI(1,
75 ("illegal xattr request %s (only user namespace supported)",
76 ea_name));
1da177e4
LT
77 /* BB what if no namespace prefix? */
78 /* Should we just pass them to server, except for
79 system and perhaps security prefixes? */
80 } else {
79a58d1f 81 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
1da177e4
LT
82 goto remove_ea_exit;
83
79a58d1f
SF
84 ea_name += 5; /* skip past user. prefix */
85 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, NULL,
737b758c
SF
86 (__u16)0, cifs_sb->local_nls,
87 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
1da177e4
LT
88 }
89remove_ea_exit:
f99d49ad 90 kfree(full_path);
1da177e4
LT
91 FreeXid(xid);
92#endif
93 return rc;
94}
95
79a58d1f
SF
96int cifs_setxattr(struct dentry *direntry, const char *ea_name,
97 const void *ea_value, size_t value_size, int flags)
1da177e4
LT
98{
99 int rc = -EOPNOTSUPP;
100#ifdef CONFIG_CIFS_XATTR
101 int xid;
102 struct cifs_sb_info *cifs_sb;
103 struct cifsTconInfo *pTcon;
79a58d1f
SF
104 struct super_block *sb;
105 char *full_path;
1da177e4 106
79a58d1f 107 if (direntry == NULL)
1da177e4 108 return -EIO;
79a58d1f 109 if (direntry->d_inode == NULL)
1da177e4
LT
110 return -EIO;
111 sb = direntry->d_inode->i_sb;
79a58d1f 112 if (sb == NULL)
1da177e4
LT
113 return -EIO;
114 xid = GetXid();
115
116 cifs_sb = CIFS_SB(sb);
117 pTcon = cifs_sb->tcon;
118
1da177e4 119 full_path = build_path_from_dentry(direntry);
79a58d1f 120 if (full_path == NULL) {
1da177e4
LT
121 FreeXid(xid);
122 return -ENOMEM;
123 }
124 /* return dos attributes as pseudo xattr */
125 /* return alt name if available as pseudo attr */
126
127 /* if proc/fs/cifs/streamstoxattr is set then
79a58d1f 128 search server for EAs or streams to
1da177e4 129 returns as xattrs */
79a58d1f
SF
130 if (value_size > MAX_EA_VALUE_SIZE) {
131 cFYI(1, ("size of EA value too large"));
f99d49ad 132 kfree(full_path);
1da177e4
LT
133 FreeXid(xid);
134 return -EOPNOTSUPP;
135 }
136
79a58d1f
SF
137 if (ea_name == NULL) {
138 cFYI(1, ("Null xattr names not supported"));
139 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) {
140 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
1da177e4 141 goto set_ea_exit;
ad7a2926 142 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0)
79a58d1f 143 cFYI(1, ("attempt to set cifs inode metadata"));
ad7a2926 144
1da177e4 145 ea_name += 5; /* skip past user. prefix */
79a58d1f 146 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
737b758c
SF
147 (__u16)value_size, cifs_sb->local_nls,
148 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
79a58d1f
SF
149 } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
150 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
1da177e4
LT
151 goto set_ea_exit;
152
153 ea_name += 4; /* skip past os2. prefix */
79a58d1f 154 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
737b758c
SF
155 (__u16)value_size, cifs_sb->local_nls,
156 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
1da177e4 157 } else {
79a58d1f
SF
158 int temp;
159 temp = strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
1da177e4
LT
160 strlen(POSIX_ACL_XATTR_ACCESS));
161 if (temp == 0) {
162#ifdef CONFIG_CIFS_POSIX
79a58d1f
SF
163 if (sb->s_flags & MS_POSIXACL)
164 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
165 ea_value, (const int)value_size,
166 ACL_TYPE_ACCESS, cifs_sb->local_nls,
167 cifs_sb->mnt_cifs_flags &
737b758c 168 CIFS_MOUNT_MAP_SPECIAL_CHR);
79a58d1f 169 cFYI(1, ("set POSIX ACL rc %d", rc));
1da177e4 170#else
79a58d1f 171 cFYI(1, ("set POSIX ACL not supported"));
1da177e4 172#endif
79a58d1f
SF
173 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
174 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
1da177e4 175#ifdef CONFIG_CIFS_POSIX
79a58d1f
SF
176 if (sb->s_flags & MS_POSIXACL)
177 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
178 ea_value, (const int)value_size,
737b758c 179 ACL_TYPE_DEFAULT, cifs_sb->local_nls,
79a58d1f 180 cifs_sb->mnt_cifs_flags &
737b758c 181 CIFS_MOUNT_MAP_SPECIAL_CHR);
79a58d1f 182 cFYI(1, ("set POSIX default ACL rc %d", rc));
1da177e4 183#else
79a58d1f 184 cFYI(1, ("set default POSIX ACL not supported"));
1da177e4
LT
185#endif
186 } else {
63135e08
SF
187 cFYI(1, ("illegal xattr request %s (only user namespace"
188 " supported)", ea_name));
1da177e4 189 /* BB what if no namespace prefix? */
79a58d1f 190 /* Should we just pass them to server, except for
1da177e4
LT
191 system and perhaps security prefixes? */
192 }
193 }
194
195set_ea_exit:
f99d49ad 196 kfree(full_path);
1da177e4
LT
197 FreeXid(xid);
198#endif
199 return rc;
200}
201
79a58d1f
SF
202ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
203 void *ea_value, size_t buf_size)
1da177e4
LT
204{
205 ssize_t rc = -EOPNOTSUPP;
206#ifdef CONFIG_CIFS_XATTR
207 int xid;
208 struct cifs_sb_info *cifs_sb;
209 struct cifsTconInfo *pTcon;
79a58d1f
SF
210 struct super_block *sb;
211 char *full_path;
1da177e4 212
79a58d1f 213 if (direntry == NULL)
1da177e4 214 return -EIO;
79a58d1f 215 if (direntry->d_inode == NULL)
1da177e4
LT
216 return -EIO;
217 sb = direntry->d_inode->i_sb;
79a58d1f 218 if (sb == NULL)
1da177e4
LT
219 return -EIO;
220
221 xid = GetXid();
222
223 cifs_sb = CIFS_SB(sb);
224 pTcon = cifs_sb->tcon;
225
1da177e4 226 full_path = build_path_from_dentry(direntry);
79a58d1f 227 if (full_path == NULL) {
1da177e4
LT
228 FreeXid(xid);
229 return -ENOMEM;
230 }
231 /* return dos attributes as pseudo xattr */
232 /* return alt name if available as pseudo attr */
79a58d1f
SF
233 if (ea_name == NULL) {
234 cFYI(1, ("Null xattr names not supported"));
235 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) {
236 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
1da177e4
LT
237 goto get_ea_exit;
238
79a58d1f
SF
239 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) {
240 cFYI(1, ("attempt to query cifs inode metadata"));
1da177e4
LT
241 /* revalidate/getattr then populate from inode */
242 } /* BB add else when above is implemented */
243 ea_name += 5; /* skip past user. prefix */
79a58d1f 244 rc = CIFSSMBQueryEA(xid, pTcon, full_path, ea_name, ea_value,
737b758c
SF
245 buf_size, cifs_sb->local_nls,
246 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
79a58d1f
SF
247 } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
248 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
1da177e4
LT
249 goto get_ea_exit;
250
251 ea_name += 4; /* skip past os2. prefix */
79a58d1f 252 rc = CIFSSMBQueryEA(xid, pTcon, full_path, ea_name, ea_value,
737b758c
SF
253 buf_size, cifs_sb->local_nls,
254 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
79a58d1f 255 } else if (strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
0a4b92c0 256 strlen(POSIX_ACL_XATTR_ACCESS)) == 0) {
1da177e4 257#ifdef CONFIG_CIFS_POSIX
79a58d1f 258 if (sb->s_flags & MS_POSIXACL)
1da0c78b 259 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
79a58d1f 260 ea_value, buf_size, ACL_TYPE_ACCESS,
737b758c 261 cifs_sb->local_nls,
79a58d1f 262 cifs_sb->mnt_cifs_flags &
737b758c 263 CIFS_MOUNT_MAP_SPECIAL_CHR);
d12fd121 264#ifdef CONFIG_CIFS_EXPERIMENTAL
ad7a2926 265 else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
0a4b92c0 266 __u16 fid;
4b18f2a9 267 int oplock = 0;
630f3f0c
SF
268 struct cifs_ntsd *pacl = NULL;
269 __u32 buflen = 0;
63d2583f 270 if (experimEnabled)
d12fd121
SF
271 rc = CIFSSMBOpen(xid, pTcon, full_path,
272 FILE_OPEN, GENERIC_READ, 0, &fid,
273 &oplock, NULL, cifs_sb->local_nls,
274 cifs_sb->mnt_cifs_flags &
275 CIFS_MOUNT_MAP_SPECIAL_CHR);
276 /* else rc is EOPNOTSUPP from above */
277
63d2583f 278 if (rc == 0) {
630f3f0c
SF
279 rc = CIFSSMBGetCIFSACL(xid, pTcon, fid, &pacl,
280 &buflen);
2fe87f02 281 CIFSSMBClose(xid, pTcon, fid);
0a4b92c0 282 }
d12fd121
SF
283 }
284#endif /* EXPERIMENTAL */
79a58d1f
SF
285#else
286 cFYI(1, ("query POSIX ACL not supported yet"));
1da177e4 287#endif /* CONFIG_CIFS_POSIX */
79a58d1f 288 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
0a4b92c0 289 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
1da177e4 290#ifdef CONFIG_CIFS_POSIX
79a58d1f 291 if (sb->s_flags & MS_POSIXACL)
1da0c78b 292 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
79a58d1f 293 ea_value, buf_size, ACL_TYPE_DEFAULT,
737b758c 294 cifs_sb->local_nls,
79a58d1f 295 cifs_sb->mnt_cifs_flags &
737b758c 296 CIFS_MOUNT_MAP_SPECIAL_CHR);
79a58d1f
SF
297#else
298 cFYI(1, ("query POSIX default ACL not supported yet"));
1da177e4 299#endif
79a58d1f
SF
300 } else if (strncmp(ea_name,
301 CIFS_XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) {
302 cFYI(1, ("Trusted xattr namespace not supported yet"));
303 } else if (strncmp(ea_name,
304 CIFS_XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) {
305 cFYI(1, ("Security xattr namespace not supported yet"));
ad7a2926 306 } else
79a58d1f
SF
307 cFYI(1,
308 ("illegal xattr request %s (only user namespace supported)",
309 ea_name));
1da177e4 310
79a58d1f 311 /* We could add an additional check for streams ie
1da177e4 312 if proc/fs/cifs/streamstoxattr is set then
79a58d1f 313 search server for EAs or streams to
1da177e4
LT
314 returns as xattrs */
315
79a58d1f
SF
316 if (rc == -EINVAL)
317 rc = -EOPNOTSUPP;
1da177e4
LT
318
319get_ea_exit:
f99d49ad 320 kfree(full_path);
1da177e4
LT
321 FreeXid(xid);
322#endif
323 return rc;
324}
325
79a58d1f 326ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
1da177e4
LT
327{
328 ssize_t rc = -EOPNOTSUPP;
329#ifdef CONFIG_CIFS_XATTR
330 int xid;
331 struct cifs_sb_info *cifs_sb;
332 struct cifsTconInfo *pTcon;
79a58d1f
SF
333 struct super_block *sb;
334 char *full_path;
1da177e4 335
79a58d1f 336 if (direntry == NULL)
1da177e4 337 return -EIO;
79a58d1f 338 if (direntry->d_inode == NULL)
1da177e4
LT
339 return -EIO;
340 sb = direntry->d_inode->i_sb;
79a58d1f 341 if (sb == NULL)
1da177e4 342 return -EIO;
1da177e4
LT
343
344 cifs_sb = CIFS_SB(sb);
345 pTcon = cifs_sb->tcon;
346
79a58d1f 347 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
ea4c07d7
SF
348 return -EOPNOTSUPP;
349
350 xid = GetXid();
351
1da177e4 352 full_path = build_path_from_dentry(direntry);
79a58d1f 353 if (full_path == NULL) {
1da177e4
LT
354 FreeXid(xid);
355 return -ENOMEM;
356 }
357 /* return dos attributes as pseudo xattr */
358 /* return alt name if available as pseudo attr */
359
360 /* if proc/fs/cifs/streamstoxattr is set then
79a58d1f 361 search server for EAs or streams to
1da177e4 362 returns as xattrs */
79a58d1f 363 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, data, buf_size,
737b758c 364 cifs_sb->local_nls,
79a58d1f 365 cifs_sb->mnt_cifs_flags &
737b758c 366 CIFS_MOUNT_MAP_SPECIAL_CHR);
1da177e4 367
f99d49ad 368 kfree(full_path);
1da177e4
LT
369 FreeXid(xid);
370#endif
371 return rc;
372}
This page took 0.279318 seconds and 5 git commands to generate.