4 * Copyright (c) International Business Machines Corp., 2003
5 * Author(s): Steve French (sfrench@us.ibm.com)
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.
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.
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
23 #include <linux/posix_acl_xattr.h>
27 #include "cifsproto.h"
28 #include "cifs_debug.h"
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 */
43 int cifs_removexattr(struct dentry * direntry, const char * ea_name)
46 #ifdef CONFIG_CIFS_XATTR
48 struct cifs_sb_info *cifs_sb;
49 struct cifsTconInfo *pTcon;
50 struct super_block * sb;
55 if(direntry->d_inode == NULL)
57 sb = direntry->d_inode->i_sb;
62 cifs_sb = CIFS_SB(sb);
63 pTcon = cifs_sb->tcon;
65 down(&sb->s_vfs_rename_sem);
66 full_path = build_path_from_dentry(direntry);
67 up(&sb->s_vfs_rename_sem);
68 if(full_path == NULL) {
73 cFYI(1,("Null xattr names not supported"));
74 } else if(strncmp(ea_name,CIFS_XATTR_USER_PREFIX,5)
75 && (strncmp(ea_name,CIFS_XATTR_OS2_PREFIX,4))) {
76 cFYI(1,("illegal xattr namespace %s (only user namespace supported)",ea_name));
77 /* BB what if no namespace prefix? */
78 /* Should we just pass them to server, except for
79 system and perhaps security prefixes? */
81 if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
84 ea_name+=5; /* skip past user. prefix */
85 rc = CIFSSMBSetEA(xid,pTcon,full_path,ea_name,NULL,
86 (__u16)0, cifs_sb->local_nls);
96 int cifs_setxattr(struct dentry * direntry, const char * ea_name,
97 const void * ea_value, size_t value_size, int flags)
100 #ifdef CONFIG_CIFS_XATTR
102 struct cifs_sb_info *cifs_sb;
103 struct cifsTconInfo *pTcon;
104 struct super_block * sb;
109 if(direntry->d_inode == NULL)
111 sb = direntry->d_inode->i_sb;
116 cifs_sb = CIFS_SB(sb);
117 pTcon = cifs_sb->tcon;
119 down(&sb->s_vfs_rename_sem);
120 full_path = build_path_from_dentry(direntry);
121 up(&sb->s_vfs_rename_sem);
122 if(full_path == NULL) {
126 /* return dos attributes as pseudo xattr */
127 /* return alt name if available as pseudo attr */
129 /* if proc/fs/cifs/streamstoxattr is set then
130 search server for EAs or streams to
132 if(value_size > MAX_EA_VALUE_SIZE) {
133 cFYI(1,("size of EA value too large"));
140 if(ea_name == NULL) {
141 cFYI(1,("Null xattr names not supported"));
142 } else if(strncmp(ea_name,CIFS_XATTR_USER_PREFIX,5) == 0) {
143 if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
145 if(strncmp(ea_name,CIFS_XATTR_DOS_ATTRIB,14) == 0) {
146 cFYI(1,("attempt to set cifs inode metadata"));
148 ea_name += 5; /* skip past user. prefix */
149 rc = CIFSSMBSetEA(xid,pTcon,full_path,ea_name,ea_value,
150 (__u16)value_size, cifs_sb->local_nls);
151 } else if(strncmp(ea_name, CIFS_XATTR_OS2_PREFIX,4) == 0) {
152 if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
155 ea_name += 4; /* skip past os2. prefix */
156 rc = CIFSSMBSetEA(xid,pTcon,full_path,ea_name,ea_value,
157 (__u16)value_size, cifs_sb->local_nls);
160 temp = strncmp(ea_name,POSIX_ACL_XATTR_ACCESS,
161 strlen(POSIX_ACL_XATTR_ACCESS));
163 #ifdef CONFIG_CIFS_POSIX
164 if(sb->s_flags & MS_POSIXACL)
165 rc = CIFSSMBSetPosixACL(xid, pTcon,full_path,
166 ea_value, (const int)value_size,
167 ACL_TYPE_ACCESS,cifs_sb->local_nls);
168 cFYI(1,("set POSIX ACL rc %d",rc));
170 cFYI(1,("set POSIX ACL not supported"));
172 } else if(strncmp(ea_name,POSIX_ACL_XATTR_DEFAULT,strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
173 #ifdef CONFIG_CIFS_POSIX
174 if(sb->s_flags & MS_POSIXACL)
175 rc = CIFSSMBSetPosixACL(xid, pTcon,full_path,
176 ea_value, (const int)value_size,
177 ACL_TYPE_DEFAULT, cifs_sb->local_nls);
178 cFYI(1,("set POSIX default ACL rc %d",rc));
180 cFYI(1,("set default POSIX ACL not supported"));
183 cFYI(1,("illegal xattr request %s (only user namespace supported)",ea_name));
184 /* BB what if no namespace prefix? */
185 /* Should we just pass them to server, except for
186 system and perhaps security prefixes? */
198 ssize_t cifs_getxattr(struct dentry * direntry, const char * ea_name,
199 void * ea_value, size_t buf_size)
201 ssize_t rc = -EOPNOTSUPP;
202 #ifdef CONFIG_CIFS_XATTR
204 struct cifs_sb_info *cifs_sb;
205 struct cifsTconInfo *pTcon;
206 struct super_block * sb;
211 if(direntry->d_inode == NULL)
213 sb = direntry->d_inode->i_sb;
219 cifs_sb = CIFS_SB(sb);
220 pTcon = cifs_sb->tcon;
222 down(&sb->s_vfs_rename_sem);
223 full_path = build_path_from_dentry(direntry);
224 up(&sb->s_vfs_rename_sem);
225 if(full_path == NULL) {
229 /* return dos attributes as pseudo xattr */
230 /* return alt name if available as pseudo attr */
231 if(ea_name == NULL) {
232 cFYI(1,("Null xattr names not supported"));
233 } else if(strncmp(ea_name,CIFS_XATTR_USER_PREFIX,5) == 0) {
234 if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
237 if(strncmp(ea_name,CIFS_XATTR_DOS_ATTRIB,14) == 0) {
238 cFYI(1,("attempt to query cifs inode metadata"));
239 /* revalidate/getattr then populate from inode */
240 } /* BB add else when above is implemented */
241 ea_name += 5; /* skip past user. prefix */
242 rc = CIFSSMBQueryEA(xid,pTcon,full_path,ea_name,ea_value,
243 buf_size, cifs_sb->local_nls);
244 } else if(strncmp(ea_name, CIFS_XATTR_OS2_PREFIX,4) == 0) {
245 if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
248 ea_name += 4; /* skip past os2. prefix */
249 rc = CIFSSMBQueryEA(xid,pTcon,full_path,ea_name,ea_value,
250 buf_size, cifs_sb->local_nls);
251 } else if(strncmp(ea_name,POSIX_ACL_XATTR_ACCESS,strlen(POSIX_ACL_XATTR_ACCESS)) == 0) {
252 #ifdef CONFIG_CIFS_POSIX
253 if(sb->s_flags & MS_POSIXACL)
254 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
255 ea_value, buf_size, ACL_TYPE_ACCESS,
258 cFYI(1,("query POSIX ACL not supported yet"));
259 #endif /* CONFIG_CIFS_POSIX */
260 } else if(strncmp(ea_name,POSIX_ACL_XATTR_DEFAULT,strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
261 #ifdef CONFIG_CIFS_POSIX
262 if(sb->s_flags & MS_POSIXACL)
263 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
264 ea_value, buf_size, ACL_TYPE_DEFAULT,
267 cFYI(1,("query POSIX default ACL not supported yet"));
269 } else if(strncmp(ea_name,
270 CIFS_XATTR_TRUSTED_PREFIX,XATTR_TRUSTED_PREFIX_LEN) == 0) {
271 cFYI(1,("Trusted xattr namespace not supported yet"));
272 } else if(strncmp(ea_name,
273 CIFS_XATTR_SECURITY_PREFIX,XATTR_SECURITY_PREFIX_LEN) == 0) {
274 cFYI(1,("Security xattr namespace not supported yet"));
276 cFYI(1,("illegal xattr name request %s (only user namespace supported)",ea_name));
279 /* We could add an additional check for streams ie
280 if proc/fs/cifs/streamstoxattr is set then
281 search server for EAs or streams to
295 ssize_t cifs_listxattr(struct dentry * direntry, char * data, size_t buf_size)
297 ssize_t rc = -EOPNOTSUPP;
298 #ifdef CONFIG_CIFS_XATTR
300 struct cifs_sb_info *cifs_sb;
301 struct cifsTconInfo *pTcon;
302 struct super_block * sb;
307 if(direntry->d_inode == NULL)
309 sb = direntry->d_inode->i_sb;
314 cifs_sb = CIFS_SB(sb);
315 pTcon = cifs_sb->tcon;
317 down(&sb->s_vfs_rename_sem);
318 full_path = build_path_from_dentry(direntry);
319 up(&sb->s_vfs_rename_sem);
320 if(full_path == NULL) {
324 /* return dos attributes as pseudo xattr */
325 /* return alt name if available as pseudo attr */
327 /* if proc/fs/cifs/streamstoxattr is set then
328 search server for EAs or streams to
330 rc = CIFSSMBQAllEAs(xid,pTcon,full_path,data,buf_size,