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
26 #include "cifsproto.h"
27 #include "cifs_debug.h"
29 #define MAX_EA_VALUE_SIZE 65535
30 #define CIFS_XATTR_DOS_ATTRIB "user.DOSATTRIB"
31 #define CIFS_XATTR_USER_PREFIX "user."
32 #define CIFS_XATTR_SYSTEM_PREFIX "system."
33 #define CIFS_XATTR_OS2_PREFIX "OS2." /* BB should check for this someday */
34 /* also note could add check for security prefix XATTR_SECURITY_PREFIX */
37 int cifs_removexattr(struct dentry * direntry, const char * ea_name)
40 #ifdef CONFIG_CIFS_XATTR
42 struct cifs_sb_info *cifs_sb;
43 struct cifsTconInfo *pTcon;
44 struct super_block * sb;
49 if(direntry->d_inode == NULL)
51 sb = direntry->d_inode->i_sb;
56 cifs_sb = CIFS_SB(sb);
57 pTcon = cifs_sb->tcon;
59 down(&sb->s_vfs_rename_sem);
60 full_path = build_path_from_dentry(direntry);
61 up(&sb->s_vfs_rename_sem);
62 if(full_path == NULL) {
67 cFYI(1,("Null xattr names not supported"));
68 } else if(strncmp(ea_name,CIFS_XATTR_USER_PREFIX,5)) {
69 cFYI(1,("illegal xattr namespace %s (only user namespace supported)",ea_name));
70 /* BB what if no namespace prefix? */
71 /* Should we just pass them to server, except for
72 system and perhaps security prefixes? */
74 ea_name+=5; /* skip past user. prefix */
75 rc = CIFSSMBSetEA(xid,pTcon,full_path,ea_name,NULL,
76 (__u16)0, cifs_sb->local_nls);
85 int cifs_setxattr(struct dentry * direntry, const char * ea_name,
86 const void * ea_value, size_t value_size, int flags)
89 #ifdef CONFIG_CIFS_XATTR
91 struct cifs_sb_info *cifs_sb;
92 struct cifsTconInfo *pTcon;
93 struct super_block * sb;
98 if(direntry->d_inode == NULL)
100 sb = direntry->d_inode->i_sb;
105 cifs_sb = CIFS_SB(sb);
106 pTcon = cifs_sb->tcon;
108 down(&sb->s_vfs_rename_sem);
109 full_path = build_path_from_dentry(direntry);
110 up(&sb->s_vfs_rename_sem);
111 if(full_path == NULL) {
115 /* return dos attributes as pseudo xattr */
116 /* return alt name if available as pseudo attr */
118 /* if proc/fs/cifs/streamstoxattr is set then
119 search server for EAs or streams to
121 if(value_size > MAX_EA_VALUE_SIZE) {
122 cFYI(1,("size of EA value too large"));
129 if(ea_name == NULL) {
130 cFYI(1,("Null xattr names not supported"));
131 } else if(strncmp(ea_name,CIFS_XATTR_USER_PREFIX,5)) {
132 cFYI(1,("illegal xattr namespace %s (only user namespace supported)",ea_name));
133 /* BB what if no namespace prefix? */
134 /* Should we just pass them to server, except for
135 system and perhaps security prefixes? */
137 ea_name+=5; /* skip past user. prefix */
138 rc = CIFSSMBSetEA(xid,pTcon,full_path,ea_name,ea_value,
139 (__u16)value_size, cifs_sb->local_nls);
148 ssize_t cifs_getxattr(struct dentry * direntry, const char * ea_name,
149 void * ea_value, size_t buf_size)
151 ssize_t rc = -EOPNOTSUPP;
152 #ifdef CONFIG_CIFS_XATTR
154 struct cifs_sb_info *cifs_sb;
155 struct cifsTconInfo *pTcon;
156 struct super_block * sb;
161 if(direntry->d_inode == NULL)
163 sb = direntry->d_inode->i_sb;
168 cifs_sb = CIFS_SB(sb);
169 pTcon = cifs_sb->tcon;
171 down(&sb->s_vfs_rename_sem);
172 full_path = build_path_from_dentry(direntry);
173 up(&sb->s_vfs_rename_sem);
174 if(full_path == NULL) {
178 /* return dos attributes as pseudo xattr */
179 /* return alt name if available as pseudo attr */
180 if(strncmp(ea_name,CIFS_XATTR_USER_PREFIX,5)) {
181 cFYI(1,("illegal xattr namespace %s (only user namespace supported)",ea_name));
182 /* BB what if no namespace prefix? */
183 /* Should we just pass them to server, except for system? */
185 /* We could add a check here
186 if proc/fs/cifs/streamstoxattr is set then
187 search server for EAs or streams to
189 ea_name+=5; /* skip past user. */
190 rc = CIFSSMBQueryEA(xid,pTcon,full_path,ea_name,ea_value,
191 buf_size, cifs_sb->local_nls);
200 ssize_t cifs_listxattr(struct dentry * direntry, char * data, size_t buf_size)
202 ssize_t rc = -EOPNOTSUPP;
203 #ifdef CONFIG_CIFS_XATTR
205 struct cifs_sb_info *cifs_sb;
206 struct cifsTconInfo *pTcon;
207 struct super_block * sb;
212 if(direntry->d_inode == NULL)
214 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 */
232 /* if proc/fs/cifs/streamstoxattr is set then
233 search server for EAs or streams to
235 rc = CIFSSMBQAllEAs(xid,pTcon,full_path,data,buf_size,