blob: a1509207bfa63a92a9e735437d675672139a82d1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/cifs/xattr.c
3 *
Steve French79a58d12007-07-06 22:44:50 +00004 * Copyright (c) International Business Machines Corp., 2003, 2007
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * 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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include "cifsfs.h"
26#include "cifspdu.h"
27#include "cifsglob.h"
28#include "cifsproto.h"
29#include "cifs_debug.h"
30
31#define MAX_EA_VALUE_SIZE 65535
32#define CIFS_XATTR_DOS_ATTRIB "user.DosAttrib"
33#define CIFS_XATTR_USER_PREFIX "user."
34#define CIFS_XATTR_SYSTEM_PREFIX "system."
35#define CIFS_XATTR_OS2_PREFIX "os2."
36#define CIFS_XATTR_SECURITY_PREFIX ".security"
37#define CIFS_XATTR_TRUSTED_PREFIX "trusted."
38#define XATTR_TRUSTED_PREFIX_LEN 8
39#define XATTR_SECURITY_PREFIX_LEN 9
40/* BB need to add server (Samba e.g) support for security and trusted prefix */
Steve French50c2f752007-07-13 00:33:32 +000041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43
Steve French79a58d12007-07-06 22:44:50 +000044int cifs_removexattr(struct dentry *direntry, const char *ea_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
46 int rc = -EOPNOTSUPP;
47#ifdef CONFIG_CIFS_XATTR
48 int xid;
49 struct cifs_sb_info *cifs_sb;
50 struct cifsTconInfo *pTcon;
Steve French79a58d12007-07-06 22:44:50 +000051 struct super_block *sb;
52 char *full_path;
53
54 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +000056 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 return -EIO;
58 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +000059 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 return -EIO;
61 xid = GetXid();
Steve French79a58d12007-07-06 22:44:50 +000062
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 cifs_sb = CIFS_SB(sb);
64 pTcon = cifs_sb->tcon;
Steve French79a58d12007-07-06 22:44:50 +000065
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +000067 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +053068 rc = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 FreeXid(xid);
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +053070 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 }
Steve French79a58d12007-07-06 22:44:50 +000072 if (ea_name == NULL) {
Joe Perchesb6b38f72010-04-21 03:50:45 +000073 cFYI(1, "Null xattr names not supported");
Steve French79a58d12007-07-06 22:44:50 +000074 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5)
75 && (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4))) {
76 cFYI(1,
Joe Perchesb6b38f72010-04-21 03:50:45 +000077 "illegal xattr request %s (only user namespace supported)",
78 ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 /* BB what if no namespace prefix? */
80 /* Should we just pass them to server, except for
81 system and perhaps security prefixes? */
82 } else {
Steve French79a58d12007-07-06 22:44:50 +000083 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 goto remove_ea_exit;
85
Steve French79a58d12007-07-06 22:44:50 +000086 ea_name += 5; /* skip past user. prefix */
87 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, NULL,
Steve French737b7582005-04-28 22:41:06 -070088 (__u16)0, cifs_sb->local_nls,
89 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 }
91remove_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -080092 kfree(full_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 FreeXid(xid);
94#endif
95 return rc;
96}
97
Steve French79a58d12007-07-06 22:44:50 +000098int cifs_setxattr(struct dentry *direntry, const char *ea_name,
99 const void *ea_value, size_t value_size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
101 int rc = -EOPNOTSUPP;
102#ifdef CONFIG_CIFS_XATTR
103 int xid;
104 struct cifs_sb_info *cifs_sb;
105 struct cifsTconInfo *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000106 struct super_block *sb;
107 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Steve French79a58d12007-07-06 22:44:50 +0000109 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000111 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 return -EIO;
113 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000114 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 return -EIO;
116 xid = GetXid();
117
118 cifs_sb = CIFS_SB(sb);
119 pTcon = cifs_sb->tcon;
120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000122 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530123 rc = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 FreeXid(xid);
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530125 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 }
127 /* return dos attributes as pseudo xattr */
128 /* return alt name if available as pseudo attr */
129
130 /* if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000131 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 returns as xattrs */
Steve French79a58d12007-07-06 22:44:50 +0000133 if (value_size > MAX_EA_VALUE_SIZE) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000134 cFYI(1, "size of EA value too large");
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800135 kfree(full_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 FreeXid(xid);
137 return -EOPNOTSUPP;
138 }
139
Steve French79a58d12007-07-06 22:44:50 +0000140 if (ea_name == NULL) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000141 cFYI(1, "Null xattr names not supported");
Steve French79a58d12007-07-06 22:44:50 +0000142 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) {
143 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 goto set_ea_exit;
Steve Frenchad7a2922008-02-07 23:25:02 +0000145 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0)
Joe Perchesb6b38f72010-04-21 03:50:45 +0000146 cFYI(1, "attempt to set cifs inode metadata");
Steve Frenchad7a2922008-02-07 23:25:02 +0000147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 ea_name += 5; /* skip past user. prefix */
Steve French79a58d12007-07-06 22:44:50 +0000149 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700150 (__u16)value_size, cifs_sb->local_nls,
151 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000152 } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
153 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 goto set_ea_exit;
155
156 ea_name += 4; /* skip past os2. prefix */
Steve French79a58d12007-07-06 22:44:50 +0000157 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700158 (__u16)value_size, cifs_sb->local_nls,
159 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 } else {
Steve French79a58d12007-07-06 22:44:50 +0000161 int temp;
162 temp = strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 strlen(POSIX_ACL_XATTR_ACCESS));
164 if (temp == 0) {
165#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000166 if (sb->s_flags & MS_POSIXACL)
167 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
168 ea_value, (const int)value_size,
169 ACL_TYPE_ACCESS, cifs_sb->local_nls,
170 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700171 CIFS_MOUNT_MAP_SPECIAL_CHR);
Joe Perchesb6b38f72010-04-21 03:50:45 +0000172 cFYI(1, "set POSIX ACL rc %d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173#else
Joe Perchesb6b38f72010-04-21 03:50:45 +0000174 cFYI(1, "set POSIX ACL not supported");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175#endif
Steve French79a58d12007-07-06 22:44:50 +0000176 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
177 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000179 if (sb->s_flags & MS_POSIXACL)
180 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
181 ea_value, (const int)value_size,
Steve French737b7582005-04-28 22:41:06 -0700182 ACL_TYPE_DEFAULT, cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000183 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700184 CIFS_MOUNT_MAP_SPECIAL_CHR);
Joe Perchesb6b38f72010-04-21 03:50:45 +0000185 cFYI(1, "set POSIX default ACL rc %d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186#else
Joe Perchesb6b38f72010-04-21 03:50:45 +0000187 cFYI(1, "set default POSIX ACL not supported");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188#endif
189 } else {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000190 cFYI(1, "illegal xattr request %s (only user namespace"
191 " supported)", ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 /* BB what if no namespace prefix? */
Steve French79a58d12007-07-06 22:44:50 +0000193 /* Should we just pass them to server, except for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 system and perhaps security prefixes? */
195 }
196 }
197
198set_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800199 kfree(full_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 FreeXid(xid);
201#endif
202 return rc;
203}
204
Steve French79a58d12007-07-06 22:44:50 +0000205ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
206 void *ea_value, size_t buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207{
208 ssize_t rc = -EOPNOTSUPP;
209#ifdef CONFIG_CIFS_XATTR
210 int xid;
211 struct cifs_sb_info *cifs_sb;
212 struct cifsTconInfo *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000213 struct super_block *sb;
214 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Steve French79a58d12007-07-06 22:44:50 +0000216 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000218 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 return -EIO;
220 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000221 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 return -EIO;
223
224 xid = GetXid();
225
226 cifs_sb = CIFS_SB(sb);
227 pTcon = cifs_sb->tcon;
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000230 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530231 rc = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 FreeXid(xid);
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530233 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 }
235 /* return dos attributes as pseudo xattr */
236 /* return alt name if available as pseudo attr */
Steve French79a58d12007-07-06 22:44:50 +0000237 if (ea_name == NULL) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000238 cFYI(1, "Null xattr names not supported");
Steve French79a58d12007-07-06 22:44:50 +0000239 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) {
240 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 goto get_ea_exit;
242
Steve French79a58d12007-07-06 22:44:50 +0000243 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000244 cFYI(1, "attempt to query cifs inode metadata");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 /* revalidate/getattr then populate from inode */
246 } /* BB add else when above is implemented */
247 ea_name += 5; /* skip past user. prefix */
Jeff Layton31c05192010-02-10 16:18:26 -0500248 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700249 buf_size, cifs_sb->local_nls,
250 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000251 } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
252 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 goto get_ea_exit;
254
255 ea_name += 4; /* skip past os2. prefix */
Jeff Layton31c05192010-02-10 16:18:26 -0500256 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700257 buf_size, cifs_sb->local_nls,
258 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000259 } else if (strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
Steve French0a4b92c2006-01-12 15:44:21 -0800260 strlen(POSIX_ACL_XATTR_ACCESS)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000262 if (sb->s_flags & MS_POSIXACL)
Steve French1da0c782005-04-28 22:41:04 -0700263 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
Steve French79a58d12007-07-06 22:44:50 +0000264 ea_value, buf_size, ACL_TYPE_ACCESS,
Steve French737b7582005-04-28 22:41:06 -0700265 cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000266 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700267 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve Frenchd12fd122007-10-03 19:43:19 +0000268#ifdef CONFIG_CIFS_EXPERIMENTAL
Steve Frenchad7a2922008-02-07 23:25:02 +0000269 else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
Steve French0a4b92c2006-01-12 15:44:21 -0800270 __u16 fid;
Steve French4b18f2a2008-04-29 00:06:05 +0000271 int oplock = 0;
Steve French630f3f02007-10-25 21:17:17 +0000272 struct cifs_ntsd *pacl = NULL;
273 __u32 buflen = 0;
Steve French63d25832007-11-05 21:46:10 +0000274 if (experimEnabled)
Steve Frenchd12fd122007-10-03 19:43:19 +0000275 rc = CIFSSMBOpen(xid, pTcon, full_path,
276 FILE_OPEN, GENERIC_READ, 0, &fid,
277 &oplock, NULL, cifs_sb->local_nls,
278 cifs_sb->mnt_cifs_flags &
279 CIFS_MOUNT_MAP_SPECIAL_CHR);
280 /* else rc is EOPNOTSUPP from above */
281
Steve French63d25832007-11-05 21:46:10 +0000282 if (rc == 0) {
Steve French630f3f02007-10-25 21:17:17 +0000283 rc = CIFSSMBGetCIFSACL(xid, pTcon, fid, &pacl,
284 &buflen);
Steve French2fe87f02006-09-21 07:02:52 +0000285 CIFSSMBClose(xid, pTcon, fid);
Steve French0a4b92c2006-01-12 15:44:21 -0800286 }
Steve Frenchd12fd122007-10-03 19:43:19 +0000287 }
288#endif /* EXPERIMENTAL */
Steve French79a58d12007-07-06 22:44:50 +0000289#else
Joe Perchesb6b38f72010-04-21 03:50:45 +0000290 cFYI(1, "query POSIX ACL not supported yet");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291#endif /* CONFIG_CIFS_POSIX */
Steve French79a58d12007-07-06 22:44:50 +0000292 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
Steve French0a4b92c2006-01-12 15:44:21 -0800293 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000295 if (sb->s_flags & MS_POSIXACL)
Steve French1da0c782005-04-28 22:41:04 -0700296 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
Steve French79a58d12007-07-06 22:44:50 +0000297 ea_value, buf_size, ACL_TYPE_DEFAULT,
Steve French737b7582005-04-28 22:41:06 -0700298 cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000299 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700300 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000301#else
Joe Perchesb6b38f72010-04-21 03:50:45 +0000302 cFYI(1, "query POSIX default ACL not supported yet");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303#endif
Steve French79a58d12007-07-06 22:44:50 +0000304 } else if (strncmp(ea_name,
305 CIFS_XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000306 cFYI(1, "Trusted xattr namespace not supported yet");
Steve French79a58d12007-07-06 22:44:50 +0000307 } else if (strncmp(ea_name,
308 CIFS_XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000309 cFYI(1, "Security xattr namespace not supported yet");
Steve Frenchad7a2922008-02-07 23:25:02 +0000310 } else
Steve French79a58d12007-07-06 22:44:50 +0000311 cFYI(1,
Joe Perchesb6b38f72010-04-21 03:50:45 +0000312 "illegal xattr request %s (only user namespace supported)",
313 ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Steve French79a58d12007-07-06 22:44:50 +0000315 /* We could add an additional check for streams ie
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000317 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 returns as xattrs */
319
Steve French79a58d12007-07-06 22:44:50 +0000320 if (rc == -EINVAL)
321 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323get_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800324 kfree(full_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 FreeXid(xid);
326#endif
327 return rc;
328}
329
Steve French79a58d12007-07-06 22:44:50 +0000330ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
332 ssize_t rc = -EOPNOTSUPP;
333#ifdef CONFIG_CIFS_XATTR
334 int xid;
335 struct cifs_sb_info *cifs_sb;
336 struct cifsTconInfo *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000337 struct super_block *sb;
338 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Steve French79a58d12007-07-06 22:44:50 +0000340 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000342 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 return -EIO;
344 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000345 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 cifs_sb = CIFS_SB(sb);
349 pTcon = cifs_sb->tcon;
350
Steve French79a58d12007-07-06 22:44:50 +0000351 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Steve Frenchea4c07d2006-08-16 19:44:25 +0000352 return -EOPNOTSUPP;
353
354 xid = GetXid();
355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000357 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530358 rc = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 FreeXid(xid);
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530360 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
362 /* return dos attributes as pseudo xattr */
363 /* return alt name if available as pseudo attr */
364
365 /* if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000366 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 returns as xattrs */
Jeff Layton31c05192010-02-10 16:18:26 -0500368 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, NULL, data,
369 buf_size, cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000370 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700371 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800373 kfree(full_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 FreeXid(xid);
375#endif
376 return rc;
377}