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,
87 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
97 int cifs_setxattr(struct dentry * direntry, const char * ea_name,
98 const void * ea_value, size_t value_size, int flags)
100 int rc = -EOPNOTSUPP;
101 #ifdef CONFIG_CIFS_XATTR
103 struct cifs_sb_info *cifs_sb;
104 struct cifsTconInfo *pTcon;
105 struct super_block * sb;
110 if(direntry->d_inode == NULL)
112 sb = direntry->d_inode->i_sb;
117 cifs_sb = CIFS_SB(sb);
118 pTcon = cifs_sb->tcon;
120 down(&sb->s_vfs_rename_sem);
121 full_path = build_path_from_dentry(direntry);
122 up(&sb->s_vfs_rename_sem);
123 if(full_path == NULL) {
127 /* return dos attributes as pseudo xattr */
128 /* return alt name if available as pseudo attr */
130 /* if proc/fs/cifs/streamstoxattr is set then
131 search server for EAs or streams to
133 if(value_size > MAX_EA_VALUE_SIZE) {
134 cFYI(1,("size of EA value too large"));
141 if(ea_name == NULL) {
142 cFYI(1,("Null xattr names not supported"));
143 } else if(strncmp(ea_name,CIFS_XATTR_USER_PREFIX,5) == 0) {
144 if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
146 if(strncmp(ea_name,CIFS_XATTR_DOS_ATTRIB,14) == 0) {
147 cFYI(1,("attempt to set cifs inode metadata"));
149 ea_name += 5; /* skip past user. prefix */
150 rc = CIFSSMBSetEA(xid,pTcon,full_path,ea_name,ea_value,
151 (__u16)value_size, cifs_sb->local_nls,
152 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
153 } else if(strncmp(ea_name, CIFS_XATTR_OS2_PREFIX,4) == 0) {
154 if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
157 ea_name += 4; /* skip past os2. prefix */
158 rc = CIFSSMBSetEA(xid,pTcon,full_path,ea_name,ea_value,
159 (__u16)value_size, cifs_sb->local_nls,
160 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
163 temp = strncmp(ea_name,POSIX_ACL_XATTR_ACCESS,
164 strlen(POSIX_ACL_XATTR_ACCESS));
166 #ifdef CONFIG_CIFS_POSIX
167 if(sb->s_flags & MS_POSIXACL)
168 rc = CIFSSMBSetPosixACL(xid, pTcon,full_path,
169 ea_value, (const int)value_size,
170 ACL_TYPE_ACCESS,cifs_sb->local_nls,
171 cifs_sb->mnt_cifs_flags &
172 CIFS_MOUNT_MAP_SPECIAL_CHR);
173 cFYI(1,("set POSIX ACL rc %d",rc));
175 cFYI(1,("set POSIX ACL not supported"));
177 } else if(strncmp(ea_name,POSIX_ACL_XATTR_DEFAULT,strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
178 #ifdef CONFIG_CIFS_POSIX
179 if(sb->s_flags & MS_POSIXACL)
180 rc = CIFSSMBSetPosixACL(xid, pTcon,full_path,
181 ea_value, (const int)value_size,
182 ACL_TYPE_DEFAULT, cifs_sb->local_nls,
183 cifs_sb->mnt_cifs_flags &
184 CIFS_MOUNT_MAP_SPECIAL_CHR);
185 cFYI(1,("set POSIX default ACL rc %d",rc));
187 cFYI(1,("set default POSIX ACL not supported"));
190 cFYI(1,("illegal xattr request %s (only user namespace supported)",ea_name));
191 /* BB what if no namespace prefix? */
192 /* Should we just pass them to server, except for
193 system and perhaps security prefixes? */
205 ssize_t cifs_getxattr(struct dentry * direntry, const char * ea_name,
206 void * ea_value, size_t buf_size)
208 ssize_t rc = -EOPNOTSUPP;
209 #ifdef CONFIG_CIFS_XATTR
211 struct cifs_sb_info *cifs_sb;
212 struct cifsTconInfo *pTcon;
213 struct super_block * sb;
218 if(direntry->d_inode == NULL)
220 sb = direntry->d_inode->i_sb;
226 cifs_sb = CIFS_SB(sb);
227 pTcon = cifs_sb->tcon;
229 down(&sb->s_vfs_rename_sem);
230 full_path = build_path_from_dentry(direntry);
231 up(&sb->s_vfs_rename_sem);
232 if(full_path == NULL) {
236 /* return dos attributes as pseudo xattr */
237 /* return alt name if available as pseudo attr */
238 if(ea_name == NULL) {
239 cFYI(1,("Null xattr names not supported"));
240 } else if(strncmp(ea_name,CIFS_XATTR_USER_PREFIX,5) == 0) {
241 if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
244 if(strncmp(ea_name,CIFS_XATTR_DOS_ATTRIB,14) == 0) {
245 cFYI(1,("attempt to query cifs inode metadata"));
246 /* revalidate/getattr then populate from inode */
247 } /* BB add else when above is implemented */
248 ea_name += 5; /* skip past user. prefix */
249 rc = CIFSSMBQueryEA(xid,pTcon,full_path,ea_name,ea_value,
250 buf_size, cifs_sb->local_nls,
251 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
252 } else if(strncmp(ea_name, CIFS_XATTR_OS2_PREFIX,4) == 0) {
253 if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
256 ea_name += 4; /* skip past os2. prefix */
257 rc = CIFSSMBQueryEA(xid,pTcon,full_path,ea_name,ea_value,
258 buf_size, cifs_sb->local_nls,
259 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
260 } else if(strncmp(ea_name,POSIX_ACL_XATTR_ACCESS,strlen(POSIX_ACL_XATTR_ACCESS)) == 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_ACCESS,
266 cifs_sb->mnt_cifs_flags &
267 CIFS_MOUNT_MAP_SPECIAL_CHR);
269 cFYI(1,("query POSIX ACL not supported yet"));
270 #endif /* CONFIG_CIFS_POSIX */
271 } else if(strncmp(ea_name,POSIX_ACL_XATTR_DEFAULT,strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
272 #ifdef CONFIG_CIFS_POSIX
273 if(sb->s_flags & MS_POSIXACL)
274 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
275 ea_value, buf_size, ACL_TYPE_DEFAULT,
277 cifs_sb->mnt_cifs_flags &
278 CIFS_MOUNT_MAP_SPECIAL_CHR);
280 cFYI(1,("query POSIX default ACL not supported yet"));
282 } else if(strncmp(ea_name,
283 CIFS_XATTR_TRUSTED_PREFIX,XATTR_TRUSTED_PREFIX_LEN) == 0) {
284 cFYI(1,("Trusted xattr namespace not supported yet"));
285 } else if(strncmp(ea_name,
286 CIFS_XATTR_SECURITY_PREFIX,XATTR_SECURITY_PREFIX_LEN) == 0) {
287 cFYI(1,("Security xattr namespace not supported yet"));
289 cFYI(1,("illegal xattr name request %s (only user namespace supported)",ea_name));
292 /* We could add an additional check for streams ie
293 if proc/fs/cifs/streamstoxattr is set then
294 search server for EAs or streams to
308 ssize_t cifs_listxattr(struct dentry * direntry, char * data, size_t buf_size)
310 ssize_t rc = -EOPNOTSUPP;
311 #ifdef CONFIG_CIFS_XATTR
313 struct cifs_sb_info *cifs_sb;
314 struct cifsTconInfo *pTcon;
315 struct super_block * sb;
320 if(direntry->d_inode == NULL)
322 sb = direntry->d_inode->i_sb;
327 cifs_sb = CIFS_SB(sb);
328 pTcon = cifs_sb->tcon;
330 down(&sb->s_vfs_rename_sem);
331 full_path = build_path_from_dentry(direntry);
332 up(&sb->s_vfs_rename_sem);
333 if(full_path == NULL) {
337 /* return dos attributes as pseudo xattr */
338 /* return alt name if available as pseudo attr */
340 /* if proc/fs/cifs/streamstoxattr is set then
341 search server for EAs or streams to
343 rc = CIFSSMBQAllEAs(xid,pTcon,full_path,data,buf_size,
345 cifs_sb->mnt_cifs_flags &
346 CIFS_MOUNT_MAP_SPECIAL_CHR);