blob: fe6d21f99964428ce9a55a1c768d8a60b68197f5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/cifs/inode.c
3 *
4 * Copyright (C) International Business Machines Corp., 2002,2005
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#include <linux/fs.h>
22#include <linux/buffer_head.h>
23#include <linux/stat.h>
24#include <linux/pagemap.h>
25#include <asm/div64.h>
26#include "cifsfs.h"
27#include "cifspdu.h"
28#include "cifsglob.h"
29#include "cifsproto.h"
30#include "cifs_debug.h"
31#include "cifs_fs_sb.h"
32
33int cifs_get_inode_info_unix(struct inode **pinode,
34 const unsigned char *search_path, struct super_block *sb, int xid)
35{
36 int rc = 0;
37 FILE_UNIX_BASIC_INFO findData;
38 struct cifsTconInfo *pTcon;
39 struct inode *inode;
40 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
41 char *tmp_path;
42
43 pTcon = cifs_sb->tcon;
Steve French26a21b92006-05-31 18:05:34 +000044 cFYI(1, ("Getting info on %s", search_path));
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 /* could have done a find first instead but this returns more info */
46 rc = CIFSSMBUnixQPathInfo(xid, pTcon, search_path, &findData,
Steve French737b7582005-04-28 22:41:06 -070047 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
48 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049/* dump_mem("\nUnixQPathInfo return data", &findData,
50 sizeof(findData)); */
51 if (rc) {
52 if (rc == -EREMOTE) {
53 tmp_path =
54 kmalloc(strnlen(pTcon->treeName,
55 MAX_TREE_SIZE + 1) +
56 strnlen(search_path, MAX_PATHCONF) + 1,
57 GFP_KERNEL);
58 if (tmp_path == NULL) {
59 return -ENOMEM;
60 }
61 /* have to skip first of the double backslash of
62 UNC name */
63 strncpy(tmp_path, pTcon->treeName, MAX_TREE_SIZE);
64 strncat(tmp_path, search_path, MAX_PATHCONF);
65 rc = connect_to_dfs_path(xid, pTcon->ses,
66 /* treename + */ tmp_path,
Steve French737b7582005-04-28 22:41:06 -070067 cifs_sb->local_nls,
68 cifs_sb->mnt_cifs_flags &
69 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 kfree(tmp_path);
71
72 /* BB fix up inode etc. */
73 } else if (rc) {
74 return rc;
75 }
76 } else {
77 struct cifsInodeInfo *cifsInfo;
78 __u32 type = le32_to_cpu(findData.Type);
79 __u64 num_of_bytes = le64_to_cpu(findData.NumOfBytes);
80 __u64 end_of_file = le64_to_cpu(findData.EndOfFile);
81
82 /* get new inode */
83 if (*pinode == NULL) {
84 *pinode = new_inode(sb);
Steve Frenchd0d2f2d2005-06-02 15:12:36 -070085 if (*pinode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 return -ENOMEM;
87 /* Is an i_ino of zero legal? */
88 /* Are there sanity checks we can use to ensure that
89 the server is really filling in that field? */
Steve Frenchd0d2f2d2005-06-02 15:12:36 -070090 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 (*pinode)->i_ino =
92 (unsigned long)findData.UniqueId;
93 } /* note ino incremented to unique num in new_inode */
94 insert_inode_hash(*pinode);
95 }
96
97 inode = *pinode;
98 cifsInfo = CIFS_I(inode);
99
Steve French26a21b92006-05-31 18:05:34 +0000100 cFYI(1, ("Old time %ld", cifsInfo->time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 cifsInfo->time = jiffies;
Steve French26a21b92006-05-31 18:05:34 +0000102 cFYI(1, ("New time %ld", cifsInfo->time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 /* this is ok to set on every inode revalidate */
104 atomic_set(&cifsInfo->inUse,1);
105
106 inode->i_atime =
107 cifs_NTtimeToUnix(le64_to_cpu(findData.LastAccessTime));
108 inode->i_mtime =
109 cifs_NTtimeToUnix(le64_to_cpu
110 (findData.LastModificationTime));
111 inode->i_ctime =
112 cifs_NTtimeToUnix(le64_to_cpu(findData.LastStatusChange));
113 inode->i_mode = le64_to_cpu(findData.Permissions);
Steve French3020a1f2005-11-18 11:31:10 -0800114 /* since we set the inode type below we need to mask off
115 to avoid strange results if bits set above */
116 inode->i_mode &= ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 if (type == UNIX_FILE) {
118 inode->i_mode |= S_IFREG;
119 } else if (type == UNIX_SYMLINK) {
120 inode->i_mode |= S_IFLNK;
121 } else if (type == UNIX_DIR) {
122 inode->i_mode |= S_IFDIR;
123 } else if (type == UNIX_CHARDEV) {
124 inode->i_mode |= S_IFCHR;
125 inode->i_rdev = MKDEV(le64_to_cpu(findData.DevMajor),
126 le64_to_cpu(findData.DevMinor) & MINORMASK);
127 } else if (type == UNIX_BLOCKDEV) {
128 inode->i_mode |= S_IFBLK;
129 inode->i_rdev = MKDEV(le64_to_cpu(findData.DevMajor),
130 le64_to_cpu(findData.DevMinor) & MINORMASK);
131 } else if (type == UNIX_FIFO) {
132 inode->i_mode |= S_IFIFO;
133 } else if (type == UNIX_SOCKET) {
134 inode->i_mode |= S_IFSOCK;
Steve French3020a1f2005-11-18 11:31:10 -0800135 } else {
136 /* safest to call it a file if we do not know */
137 inode->i_mode |= S_IFREG;
138 cFYI(1,("unknown type %d",type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 }
140 inode->i_uid = le64_to_cpu(findData.Uid);
141 inode->i_gid = le64_to_cpu(findData.Gid);
142 inode->i_nlink = le64_to_cpu(findData.Nlinks);
143
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700144 if (is_size_safe_to_change(cifsInfo)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 /* can not safely change the file size here if the
146 client is writing to it due to potential races */
147
148 i_size_write(inode, end_of_file);
149
150 /* blksize needs to be multiple of two. So safer to default to
151 blksize and blkbits set in superblock so 2**blkbits and blksize
152 will match rather than setting to:
153 (pTcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFE00;*/
154
155 /* This seems incredibly stupid but it turns out that i_blocks
156 is not related to (i_size / i_blksize), instead 512 byte size
157 is required for calculating num blocks */
158
159 /* 512 bytes (2**9) is the fake blocksize that must be used */
160 /* for this calculation */
161 inode->i_blocks = (512 - 1 + num_of_bytes) >> 9;
162 }
163
164 if (num_of_bytes < end_of_file)
Steve French8b94bcb2005-11-11 11:41:00 -0800165 cFYI(1, ("allocation size less than end of file"));
Andrew Morton5515eff2006-03-26 01:37:53 -0800166 cFYI(1, ("Size %ld and blocks %llu",
167 (unsigned long) inode->i_size,
168 (unsigned long long)inode->i_blocks));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 if (S_ISREG(inode->i_mode)) {
Steve French8b94bcb2005-11-11 11:41:00 -0800170 cFYI(1, ("File inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 inode->i_op = &cifs_file_inode_ops;
Steve French8b94bcb2005-11-11 11:41:00 -0800172 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
173 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
174 inode->i_fop =
175 &cifs_file_direct_nobrl_ops;
176 else
177 inode->i_fop = &cifs_file_direct_ops;
178 } else if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
179 inode->i_fop = &cifs_file_nobrl_ops;
180 else /* not direct, send byte range locks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 inode->i_fop = &cifs_file_ops;
Steve French8b94bcb2005-11-11 11:41:00 -0800182
Steve Frenchbfa0d752005-08-31 21:50:37 -0700183 /* check if server can support readpages */
184 if(pTcon->ses->server->maxBuf <
Dave Kleikamp273d81d2006-06-01 19:41:23 +0000185 PAGE_CACHE_SIZE + MAX_CIFS_HDR_SIZE)
186 inode->i_data.a_ops = &cifs_addr_ops_smallbuf;
187 else
188 inode->i_data.a_ops = &cifs_addr_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 } else if (S_ISDIR(inode->i_mode)) {
Steve French8b94bcb2005-11-11 11:41:00 -0800190 cFYI(1, ("Directory inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 inode->i_op = &cifs_dir_inode_ops;
192 inode->i_fop = &cifs_dir_ops;
193 } else if (S_ISLNK(inode->i_mode)) {
Steve French8b94bcb2005-11-11 11:41:00 -0800194 cFYI(1, ("Symbolic Link inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 inode->i_op = &cifs_symlink_inode_ops;
196 /* tmp_inode->i_fop = */ /* do not need to set to anything */
197 } else {
Steve French8b94bcb2005-11-11 11:41:00 -0800198 cFYI(1, ("Init special inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 init_special_inode(inode, inode->i_mode,
200 inode->i_rdev);
201 }
202 }
203 return rc;
204}
205
Steve Frenchd6e2f2a2005-11-15 16:43:39 -0800206static int decode_sfu_inode(struct inode * inode, __u64 size,
207 const unsigned char *path,
208 struct cifs_sb_info *cifs_sb, int xid)
209{
210 int rc;
211 int oplock = FALSE;
212 __u16 netfid;
213 struct cifsTconInfo *pTcon = cifs_sb->tcon;
Steve French86c96b42005-11-18 20:25:31 -0800214 char buf[24];
Steve Frenchd6e2f2a2005-11-15 16:43:39 -0800215 unsigned int bytes_read;
216 char * pbuf;
217
218 pbuf = buf;
219
220 if(size == 0) {
221 inode->i_mode |= S_IFIFO;
222 return 0;
223 } else if (size < 8) {
224 return -EINVAL; /* EOPNOTSUPP? */
225 }
226
227 rc = CIFSSMBOpen(xid, pTcon, path, FILE_OPEN, GENERIC_READ,
228 CREATE_NOT_DIR, &netfid, &oplock, NULL,
229 cifs_sb->local_nls,
230 cifs_sb->mnt_cifs_flags &
231 CIFS_MOUNT_MAP_SPECIAL_CHR);
232 if (rc==0) {
Steve Frenchec637e32005-12-12 20:53:18 -0800233 int buf_type = CIFS_NO_BUFFER;
Steve Frenchd6e2f2a2005-11-15 16:43:39 -0800234 /* Read header */
235 rc = CIFSSMBRead(xid, pTcon,
236 netfid,
Steve French86c96b42005-11-18 20:25:31 -0800237 24 /* length */, 0 /* offset */,
Steve Frenchec637e32005-12-12 20:53:18 -0800238 &bytes_read, &pbuf, &buf_type);
Steve French86c96b42005-11-18 20:25:31 -0800239 if((rc == 0) && (bytes_read >= 8)) {
Steve French9e294f12005-11-17 16:59:21 -0800240 if(memcmp("IntxBLK", pbuf, 8) == 0) {
241 cFYI(1,("Block device"));
Steve French3020a1f2005-11-18 11:31:10 -0800242 inode->i_mode |= S_IFBLK;
Steve French86c96b42005-11-18 20:25:31 -0800243 if(bytes_read == 24) {
244 /* we have enough to decode dev num */
245 __u64 mjr; /* major */
246 __u64 mnr; /* minor */
247 mjr = le64_to_cpu(*(__le64 *)(pbuf+8));
248 mnr = le64_to_cpu(*(__le64 *)(pbuf+16));
249 inode->i_rdev = MKDEV(mjr, mnr);
250 }
Steve French9e294f12005-11-17 16:59:21 -0800251 } else if(memcmp("IntxCHR", pbuf, 8) == 0) {
252 cFYI(1,("Char device"));
Steve French3020a1f2005-11-18 11:31:10 -0800253 inode->i_mode |= S_IFCHR;
Steve French86c96b42005-11-18 20:25:31 -0800254 if(bytes_read == 24) {
255 /* we have enough to decode dev num */
256 __u64 mjr; /* major */
257 __u64 mnr; /* minor */
258 mjr = le64_to_cpu(*(__le64 *)(pbuf+8));
259 mnr = le64_to_cpu(*(__le64 *)(pbuf+16));
260 inode->i_rdev = MKDEV(mjr, mnr);
261 }
Steve French9e294f12005-11-17 16:59:21 -0800262 } else if(memcmp("IntxLNK", pbuf, 7) == 0) {
263 cFYI(1,("Symlink"));
Steve French3020a1f2005-11-18 11:31:10 -0800264 inode->i_mode |= S_IFLNK;
Steve French86c96b42005-11-18 20:25:31 -0800265 } else {
266 inode->i_mode |= S_IFREG; /* file? */
267 rc = -EOPNOTSUPP;
268 }
Steve French3020a1f2005-11-18 11:31:10 -0800269 } else {
270 inode->i_mode |= S_IFREG; /* then it is a file */
271 rc = -EOPNOTSUPP; /* or some unknown SFU type */
Steve Frenchec637e32005-12-12 20:53:18 -0800272 }
Steve Frenchd6e2f2a2005-11-15 16:43:39 -0800273 CIFSSMBClose(xid, pTcon, netfid);
Steve Frenchd6e2f2a2005-11-15 16:43:39 -0800274 }
275 return rc;
276
277}
278
Steve French9e294f12005-11-17 16:59:21 -0800279#define SFBITS_MASK (S_ISVTX | S_ISGID | S_ISUID) /* SETFILEBITS valid bits */
280
281static int get_sfu_uid_mode(struct inode * inode,
282 const unsigned char *path,
283 struct cifs_sb_info *cifs_sb, int xid)
284{
Steve French3020a1f2005-11-18 11:31:10 -0800285#ifdef CONFIG_CIFS_XATTR
Steve French9e294f12005-11-17 16:59:21 -0800286 ssize_t rc;
287 char ea_value[4];
288 __u32 mode;
289
290 rc = CIFSSMBQueryEA(xid, cifs_sb->tcon, path, "SETFILEBITS",
291 ea_value, 4 /* size of buf */, cifs_sb->local_nls,
292 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
293 if(rc < 0)
294 return (int)rc;
295 else if (rc > 3) {
296 mode = le32_to_cpu(*((__le32 *)ea_value));
Steve Frenchc119b872005-11-18 12:27:27 -0800297 inode->i_mode &= ~SFBITS_MASK;
Steve French3020a1f2005-11-18 11:31:10 -0800298 cFYI(1,("special bits 0%o org mode 0%o", mode, inode->i_mode));
Steve French9e294f12005-11-17 16:59:21 -0800299 inode->i_mode = (mode & SFBITS_MASK) | inode->i_mode;
300 cFYI(1,("special mode bits 0%o", mode));
301 return 0;
302 } else {
303 return 0;
304 }
Steve French3020a1f2005-11-18 11:31:10 -0800305#else
306 return -EOPNOTSUPP;
307#endif
308
Steve French9e294f12005-11-17 16:59:21 -0800309
310}
311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312int cifs_get_inode_info(struct inode **pinode,
313 const unsigned char *search_path, FILE_ALL_INFO *pfindData,
314 struct super_block *sb, int xid)
315{
316 int rc = 0;
317 struct cifsTconInfo *pTcon;
318 struct inode *inode;
319 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
320 char *tmp_path;
321 char *buf = NULL;
322
323 pTcon = cifs_sb->tcon;
Steve Frenchd6e2f2a2005-11-15 16:43:39 -0800324 cFYI(1,("Getting info on %s", search_path));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700326 if ((pfindData == NULL) && (*pinode != NULL)) {
327 if (CIFS_I(*pinode)->clientCanCacheRead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 cFYI(1,("No need to revalidate cached inode sizes"));
329 return rc;
330 }
331 }
332
333 /* if file info not passed in then get it from server */
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700334 if (pfindData == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700336 if (buf == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 return -ENOMEM;
338 pfindData = (FILE_ALL_INFO *)buf;
339 /* could do find first instead but this returns more info */
340 rc = CIFSSMBQPathInfo(xid, pTcon, search_path, pfindData,
Steve Frenchacf1a1b2006-10-12 03:28:28 +0000341 0 /* not legacy */,
Steve French6b8edfe2005-08-23 20:26:03 -0700342 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700343 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French6b8edfe2005-08-23 20:26:03 -0700344 /* BB optimize code so we do not make the above call
345 when server claims no NT SMB support and the above call
346 failed at least once - set flag in tcon or mount */
347 if((rc == -EOPNOTSUPP) || (rc == -EINVAL)) {
348 rc = SMBQueryInformation(xid, pTcon, search_path,
349 pfindData, cifs_sb->local_nls,
350 cifs_sb->mnt_cifs_flags &
351 CIFS_MOUNT_MAP_SPECIAL_CHR);
352 }
353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 }
355 /* dump_mem("\nQPathInfo return data",&findData, sizeof(findData)); */
356 if (rc) {
357 if (rc == -EREMOTE) {
358 tmp_path =
359 kmalloc(strnlen
360 (pTcon->treeName,
361 MAX_TREE_SIZE + 1) +
362 strnlen(search_path, MAX_PATHCONF) + 1,
363 GFP_KERNEL);
364 if (tmp_path == NULL) {
365 kfree(buf);
366 return -ENOMEM;
367 }
368
369 strncpy(tmp_path, pTcon->treeName, MAX_TREE_SIZE);
370 strncat(tmp_path, search_path, MAX_PATHCONF);
371 rc = connect_to_dfs_path(xid, pTcon->ses,
372 /* treename + */ tmp_path,
Steve French737b7582005-04-28 22:41:06 -0700373 cifs_sb->local_nls,
374 cifs_sb->mnt_cifs_flags &
375 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 kfree(tmp_path);
377 /* BB fix up inode etc. */
378 } else if (rc) {
379 kfree(buf);
380 return rc;
381 }
382 } else {
383 struct cifsInodeInfo *cifsInfo;
384 __u32 attr = le32_to_cpu(pfindData->Attributes);
385
386 /* get new inode */
387 if (*pinode == NULL) {
388 *pinode = new_inode(sb);
Steve Frenchacf1a1b2006-10-12 03:28:28 +0000389 if (*pinode == NULL) {
390 kfree(buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 return -ENOMEM;
Steve Frenchacf1a1b2006-10-12 03:28:28 +0000392 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 /* Is an i_ino of zero legal? Can we use that to check
394 if the server supports returning inode numbers? Are
395 there other sanity checks we can use to ensure that
396 the server is really filling in that field? */
397
398 /* We can not use the IndexNumber field by default from
399 Windows or Samba (in ALL_INFO buf) but we can request
400 it explicitly. It may not be unique presumably if
401 the server has multiple devices mounted under one
402 share */
403
404 /* There may be higher info levels that work but are
405 there Windows server or network appliances for which
406 IndexNumber field is not guaranteed unique? */
407
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700408 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 int rc1 = 0;
410 __u64 inode_num;
411
412 rc1 = CIFSGetSrvInodeNumber(xid, pTcon,
413 search_path, &inode_num,
Steve French737b7582005-04-28 22:41:06 -0700414 cifs_sb->local_nls,
415 cifs_sb->mnt_cifs_flags &
416 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700417 if (rc1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 cFYI(1,("GetSrvInodeNum rc %d", rc1));
419 /* BB EOPNOSUPP disable SERVER_INUM? */
420 } else /* do we need cast or hash to ino? */
421 (*pinode)->i_ino = inode_num;
422 } /* else ino incremented to unique num in new_inode*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 insert_inode_hash(*pinode);
424 }
425 inode = *pinode;
426 cifsInfo = CIFS_I(inode);
427 cifsInfo->cifsAttrs = attr;
Steve French26a21b92006-05-31 18:05:34 +0000428 cFYI(1, ("Old time %ld", cifsInfo->time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 cifsInfo->time = jiffies;
Steve French26a21b92006-05-31 18:05:34 +0000430 cFYI(1, ("New time %ld", cifsInfo->time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432 /* blksize needs to be multiple of two. So safer to default to
433 blksize and blkbits set in superblock so 2**blkbits and blksize
434 will match rather than setting to:
435 (pTcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFE00;*/
436
Steve French26a21b92006-05-31 18:05:34 +0000437 /* Linux can not store file creation time so ignore it */
Steve French1bd5bbc2006-09-28 03:35:57 +0000438 if(pfindData->LastAccessTime)
439 inode->i_atime = cifs_NTtimeToUnix
440 (le64_to_cpu(pfindData->LastAccessTime));
441 else /* do not need to use current_fs_time - time not stored */
442 inode->i_atime = CURRENT_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 inode->i_mtime =
444 cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastWriteTime));
445 inode->i_ctime =
446 cifs_NTtimeToUnix(le64_to_cpu(pfindData->ChangeTime));
Steve French26a21b92006-05-31 18:05:34 +0000447 cFYI(0, ("Attributes came in as 0x%x", attr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 /* set default mode. will override for dirs below */
450 if (atomic_read(&cifsInfo->inUse) == 0)
451 /* new inode, can safely set these fields */
452 inode->i_mode = cifs_sb->mnt_file_mode;
Steve French3020a1f2005-11-18 11:31:10 -0800453 else /* since we set the inode type below we need to mask off
454 to avoid strange results if type changes and both get orred in */
455 inode->i_mode &= ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456/* if (attr & ATTR_REPARSE) */
457 /* We no longer handle these as symlinks because we could not
458 follow them due to the absolute path with drive letter */
459 if (attr & ATTR_DIRECTORY) {
460 /* override default perms since we do not do byte range locking
461 on dirs */
462 inode->i_mode = cifs_sb->mnt_dir_mode;
463 inode->i_mode |= S_IFDIR;
Steve Frencheda3c022005-07-21 15:20:28 -0700464 } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) &&
465 (cifsInfo->cifsAttrs & ATTR_SYSTEM) &&
466 /* No need to le64 convert size of zero */
467 (pfindData->EndOfFile == 0)) {
468 inode->i_mode = cifs_sb->mnt_file_mode;
469 inode->i_mode |= S_IFIFO;
Steve Frenchd6e2f2a2005-11-15 16:43:39 -0800470/* BB Finish for SFU style symlinks and devices */
471 } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) &&
472 (cifsInfo->cifsAttrs & ATTR_SYSTEM)) {
473 if (decode_sfu_inode(inode,
474 le64_to_cpu(pfindData->EndOfFile),
475 search_path,
476 cifs_sb, xid)) {
477 cFYI(1,("Unrecognized sfu inode type"));
478 }
Steve French3020a1f2005-11-18 11:31:10 -0800479 cFYI(1,("sfu mode 0%o",inode->i_mode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 } else {
481 inode->i_mode |= S_IFREG;
482 /* treat the dos attribute of read-only as read-only
483 mode e.g. 555 */
484 if (cifsInfo->cifsAttrs & ATTR_READONLY)
485 inode->i_mode &= ~(S_IWUGO);
486 /* BB add code here -
487 validate if device or weird share or device type? */
488 }
489 if (is_size_safe_to_change(cifsInfo)) {
490 /* can not safely change the file size here if the
491 client is writing to it due to potential races */
492 i_size_write(inode,le64_to_cpu(pfindData->EndOfFile));
493
494 /* 512 bytes (2**9) is the fake blocksize that must be
495 used for this calculation */
496 inode->i_blocks = (512 - 1 + le64_to_cpu(
497 pfindData->AllocationSize)) >> 9;
498 }
499
500 inode->i_nlink = le32_to_cpu(pfindData->NumberOfLinks);
501
502 /* BB fill in uid and gid here? with help from winbind?
503 or retrieve from NTFS stream extended attribute */
Steve French9e294f12005-11-17 16:59:21 -0800504 if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
505 /* fill in uid, gid, mode from server ACL */
506 get_sfu_uid_mode(inode, search_path, cifs_sb, xid);
507 } else if (atomic_read(&cifsInfo->inUse) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 inode->i_uid = cifs_sb->mnt_uid;
509 inode->i_gid = cifs_sb->mnt_gid;
510 /* set so we do not keep refreshing these fields with
511 bad data after user has changed them in memory */
512 atomic_set(&cifsInfo->inUse,1);
513 }
514
515 if (S_ISREG(inode->i_mode)) {
Steve Frenchd6e2f2a2005-11-15 16:43:39 -0800516 cFYI(1, ("File inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 inode->i_op = &cifs_file_inode_ops;
Steve French8b94bcb2005-11-11 11:41:00 -0800518 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
519 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
520 inode->i_fop =
521 &cifs_file_direct_nobrl_ops;
522 else
523 inode->i_fop = &cifs_file_direct_ops;
524 } else if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
525 inode->i_fop = &cifs_file_nobrl_ops;
526 else /* not direct, send byte range locks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 inode->i_fop = &cifs_file_ops;
Steve French8b94bcb2005-11-11 11:41:00 -0800528
Steve Frenchbfa0d752005-08-31 21:50:37 -0700529 if(pTcon->ses->server->maxBuf <
Dave Kleikamp273d81d2006-06-01 19:41:23 +0000530 PAGE_CACHE_SIZE + MAX_CIFS_HDR_SIZE)
531 inode->i_data.a_ops = &cifs_addr_ops_smallbuf;
532 else
533 inode->i_data.a_ops = &cifs_addr_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 } else if (S_ISDIR(inode->i_mode)) {
Steve Frenchd6e2f2a2005-11-15 16:43:39 -0800535 cFYI(1, ("Directory inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 inode->i_op = &cifs_dir_inode_ops;
537 inode->i_fop = &cifs_dir_ops;
538 } else if (S_ISLNK(inode->i_mode)) {
Steve Frenchd6e2f2a2005-11-15 16:43:39 -0800539 cFYI(1, ("Symbolic Link inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 inode->i_op = &cifs_symlink_inode_ops;
541 } else {
542 init_special_inode(inode, inode->i_mode,
543 inode->i_rdev);
544 }
545 }
546 kfree(buf);
547 return rc;
548}
549
550/* gets root inode */
551void cifs_read_inode(struct inode *inode)
552{
553 int xid;
554 struct cifs_sb_info *cifs_sb;
555
556 cifs_sb = CIFS_SB(inode->i_sb);
557 xid = GetXid();
558 if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
559 cifs_get_inode_info_unix(&inode, "", inode->i_sb,xid);
560 else
561 cifs_get_inode_info(&inode, "", NULL, inode->i_sb,xid);
562 /* can not call macro FreeXid here since in a void func */
563 _FreeXid(xid);
564}
565
566int cifs_unlink(struct inode *inode, struct dentry *direntry)
567{
568 int rc = 0;
569 int xid;
570 struct cifs_sb_info *cifs_sb;
571 struct cifsTconInfo *pTcon;
572 char *full_path = NULL;
573 struct cifsInodeInfo *cifsInode;
574 FILE_BASIC_INFO *pinfo_buf;
575
Steve French06bcfed2006-03-31 22:43:50 +0000576 cFYI(1, ("cifs_unlink, inode = 0x%p", inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 xid = GetXid();
579
Steve French6910ab32006-03-31 03:37:08 +0000580 if(inode)
581 cifs_sb = CIFS_SB(inode->i_sb);
582 else
Steve French06bcfed2006-03-31 22:43:50 +0000583 cifs_sb = CIFS_SB(direntry->d_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 pTcon = cifs_sb->tcon;
585
586 /* Unlink can be called from rename so we can not grab the sem here
587 since we deadlock otherwise */
Arjan van de Vena11f3a02006-03-23 03:00:33 -0800588/* mutex_lock(&direntry->d_sb->s_vfs_rename_mutex);*/
Steve French7f573562005-08-30 11:32:14 -0700589 full_path = build_path_from_dentry(direntry);
Arjan van de Vena11f3a02006-03-23 03:00:33 -0800590/* mutex_unlock(&direntry->d_sb->s_vfs_rename_mutex);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 if (full_path == NULL) {
592 FreeXid(xid);
593 return -ENOMEM;
594 }
Steve French737b7582005-04-28 22:41:06 -0700595 rc = CIFSSMBDelFile(xid, pTcon, full_path, cifs_sb->local_nls,
596 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598 if (!rc) {
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700599 if (direntry->d_inode)
Steve Frenchb2aeb9d2005-05-17 13:16:18 -0500600 direntry->d_inode->i_nlink--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 } else if (rc == -ENOENT) {
602 d_drop(direntry);
603 } else if (rc == -ETXTBSY) {
604 int oplock = FALSE;
605 __u16 netfid;
606
607 rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN, DELETE,
608 CREATE_NOT_DIR | CREATE_DELETE_ON_CLOSE,
Steve French737b7582005-04-28 22:41:06 -0700609 &netfid, &oplock, NULL, cifs_sb->local_nls,
610 cifs_sb->mnt_cifs_flags &
611 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 if (rc==0) {
613 CIFSSMBRenameOpenFile(xid, pTcon, netfid, NULL,
Steve French737b7582005-04-28 22:41:06 -0700614 cifs_sb->local_nls,
615 cifs_sb->mnt_cifs_flags &
616 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 CIFSSMBClose(xid, pTcon, netfid);
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700618 if (direntry->d_inode)
Steve Frenchb2aeb9d2005-05-17 13:16:18 -0500619 direntry->d_inode->i_nlink--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 }
621 } else if (rc == -EACCES) {
622 /* try only if r/o attribute set in local lookup data? */
Eric Sesterhenna048d7a2006-02-21 22:33:09 +0000623 pinfo_buf = kzalloc(sizeof(FILE_BASIC_INFO), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 if (pinfo_buf) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 /* ATTRS set to normal clears r/o bit */
626 pinfo_buf->Attributes = cpu_to_le32(ATTR_NORMAL);
627 if (!(pTcon->ses->flags & CIFS_SES_NT4))
628 rc = CIFSSMBSetTimes(xid, pTcon, full_path,
629 pinfo_buf,
Steve French737b7582005-04-28 22:41:06 -0700630 cifs_sb->local_nls,
631 cifs_sb->mnt_cifs_flags &
632 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 else
634 rc = -EOPNOTSUPP;
635
636 if (rc == -EOPNOTSUPP) {
637 int oplock = FALSE;
638 __u16 netfid;
639 /* rc = CIFSSMBSetAttrLegacy(xid, pTcon,
640 full_path,
641 (__u16)ATTR_NORMAL,
642 cifs_sb->local_nls);
643 For some strange reason it seems that NT4 eats the
644 old setattr call without actually setting the
645 attributes so on to the third attempted workaround
646 */
647
648 /* BB could scan to see if we already have it open
649 and pass in pid of opener to function */
650 rc = CIFSSMBOpen(xid, pTcon, full_path,
651 FILE_OPEN, SYNCHRONIZE |
652 FILE_WRITE_ATTRIBUTES, 0,
653 &netfid, &oplock, NULL,
Steve French737b7582005-04-28 22:41:06 -0700654 cifs_sb->local_nls,
655 cifs_sb->mnt_cifs_flags &
656 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 if (rc==0) {
658 rc = CIFSSMBSetFileTimes(xid, pTcon,
659 pinfo_buf,
660 netfid);
661 CIFSSMBClose(xid, pTcon, netfid);
662 }
663 }
664 kfree(pinfo_buf);
665 }
666 if (rc==0) {
Steve French737b7582005-04-28 22:41:06 -0700667 rc = CIFSSMBDelFile(xid, pTcon, full_path,
668 cifs_sb->local_nls,
669 cifs_sb->mnt_cifs_flags &
670 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 if (!rc) {
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700672 if (direntry->d_inode)
Steve Frenchb2aeb9d2005-05-17 13:16:18 -0500673 direntry->d_inode->i_nlink--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 } else if (rc == -ETXTBSY) {
675 int oplock = FALSE;
676 __u16 netfid;
677
678 rc = CIFSSMBOpen(xid, pTcon, full_path,
679 FILE_OPEN, DELETE,
680 CREATE_NOT_DIR |
681 CREATE_DELETE_ON_CLOSE,
682 &netfid, &oplock, NULL,
Steve French737b7582005-04-28 22:41:06 -0700683 cifs_sb->local_nls,
684 cifs_sb->mnt_cifs_flags &
685 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 if (rc==0) {
687 CIFSSMBRenameOpenFile(xid, pTcon,
688 netfid, NULL,
Steve French737b7582005-04-28 22:41:06 -0700689 cifs_sb->local_nls,
690 cifs_sb->mnt_cifs_flags &
691 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 CIFSSMBClose(xid, pTcon, netfid);
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700693 if (direntry->d_inode)
Steve Frenchb2aeb9d2005-05-17 13:16:18 -0500694 direntry->d_inode->i_nlink--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 }
696 /* BB if rc = -ETXTBUSY goto the rename logic BB */
697 }
698 }
699 }
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700700 if (direntry->d_inode) {
Steve Frenchb2aeb9d2005-05-17 13:16:18 -0500701 cifsInode = CIFS_I(direntry->d_inode);
702 cifsInode->time = 0; /* will force revalidate to get info
703 when needed */
704 direntry->d_inode->i_ctime = current_fs_time(inode->i_sb);
705 }
Steve French06bcfed2006-03-31 22:43:50 +0000706 if(inode) {
707 inode->i_ctime = inode->i_mtime = current_fs_time(inode->i_sb);
708 cifsInode = CIFS_I(inode);
709 cifsInode->time = 0; /* force revalidate of dir as well */
710 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
712 kfree(full_path);
713 FreeXid(xid);
714 return rc;
715}
716
717int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
718{
719 int rc = 0;
720 int xid;
721 struct cifs_sb_info *cifs_sb;
722 struct cifsTconInfo *pTcon;
723 char *full_path = NULL;
724 struct inode *newinode = NULL;
725
Steve French6473a552005-11-29 20:20:10 -0800726 cFYI(1, ("In cifs_mkdir, mode = 0x%x inode = 0x%p", mode, inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728 xid = GetXid();
729
730 cifs_sb = CIFS_SB(inode->i_sb);
731 pTcon = cifs_sb->tcon;
732
Steve French7f573562005-08-30 11:32:14 -0700733 full_path = build_path_from_dentry(direntry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 if (full_path == NULL) {
735 FreeXid(xid);
736 return -ENOMEM;
737 }
738 /* BB add setting the equivalent of mode via CreateX w/ACLs */
Steve French737b7582005-04-28 22:41:06 -0700739 rc = CIFSSMBMkDir(xid, pTcon, full_path, cifs_sb->local_nls,
740 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 if (rc) {
Steve French26a21b92006-05-31 18:05:34 +0000742 cFYI(1, ("cifs_mkdir returned 0x%x", rc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 d_drop(direntry);
744 } else {
745 inode->i_nlink++;
746 if (pTcon->ses->capabilities & CAP_UNIX)
747 rc = cifs_get_inode_info_unix(&newinode, full_path,
748 inode->i_sb,xid);
749 else
750 rc = cifs_get_inode_info(&newinode, full_path, NULL,
751 inode->i_sb,xid);
752
Steve Frenchb92327f2005-08-22 20:09:43 -0700753 if (pTcon->nocase)
754 direntry->d_op = &cifs_ci_dentry_ops;
755 else
756 direntry->d_op = &cifs_dentry_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 d_instantiate(direntry, newinode);
758 if (direntry->d_inode)
759 direntry->d_inode->i_nlink = 2;
760 if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700761 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 CIFSSMBUnixSetPerms(xid, pTcon, full_path,
763 mode,
Steve French83451872005-12-01 17:12:59 -0800764 (__u64)current->fsuid,
765 (__u64)current->fsgid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 0 /* dev_t */,
Steve French737b7582005-04-28 22:41:06 -0700767 cifs_sb->local_nls,
768 cifs_sb->mnt_cifs_flags &
769 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 } else {
771 CIFSSMBUnixSetPerms(xid, pTcon, full_path,
772 mode, (__u64)-1,
773 (__u64)-1, 0 /* dev_t */,
Steve French737b7582005-04-28 22:41:06 -0700774 cifs_sb->local_nls,
775 cifs_sb->mnt_cifs_flags &
776 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 }
778 else {
779 /* BB to be implemented via Windows secrty descriptors
780 eg CIFSSMBWinSetPerms(xid, pTcon, full_path, mode,
781 -1, -1, local_nls); */
Steve French6473a552005-11-29 20:20:10 -0800782 if(direntry->d_inode) {
783 direntry->d_inode->i_mode = mode;
Steve French25741b32005-11-29 22:38:43 -0800784 direntry->d_inode->i_mode |= S_IFDIR;
Steve French6473a552005-11-29 20:20:10 -0800785 if(cifs_sb->mnt_cifs_flags &
786 CIFS_MOUNT_SET_UID) {
787 direntry->d_inode->i_uid =
788 current->fsuid;
789 direntry->d_inode->i_gid =
790 current->fsgid;
791 }
792 }
Steve French2a138ebb2005-11-29 21:22:19 -0800793 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 }
795 kfree(full_path);
796 FreeXid(xid);
797 return rc;
798}
799
800int cifs_rmdir(struct inode *inode, struct dentry *direntry)
801{
802 int rc = 0;
803 int xid;
804 struct cifs_sb_info *cifs_sb;
805 struct cifsTconInfo *pTcon;
806 char *full_path = NULL;
807 struct cifsInodeInfo *cifsInode;
808
Steve French26a21b92006-05-31 18:05:34 +0000809 cFYI(1, ("cifs_rmdir, inode = 0x%p", inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
811 xid = GetXid();
812
813 cifs_sb = CIFS_SB(inode->i_sb);
814 pTcon = cifs_sb->tcon;
815
Steve French7f573562005-08-30 11:32:14 -0700816 full_path = build_path_from_dentry(direntry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 if (full_path == NULL) {
818 FreeXid(xid);
819 return -ENOMEM;
820 }
821
Steve French737b7582005-04-28 22:41:06 -0700822 rc = CIFSSMBRmDir(xid, pTcon, full_path, cifs_sb->local_nls,
823 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825 if (!rc) {
826 inode->i_nlink--;
827 i_size_write(direntry->d_inode,0);
828 direntry->d_inode->i_nlink = 0;
829 }
830
831 cifsInode = CIFS_I(direntry->d_inode);
832 cifsInode->time = 0; /* force revalidate to go get info when
833 needed */
834 direntry->d_inode->i_ctime = inode->i_ctime = inode->i_mtime =
835 current_fs_time(inode->i_sb);
836
837 kfree(full_path);
838 FreeXid(xid);
839 return rc;
840}
841
842int cifs_rename(struct inode *source_inode, struct dentry *source_direntry,
843 struct inode *target_inode, struct dentry *target_direntry)
844{
845 char *fromName;
846 char *toName;
847 struct cifs_sb_info *cifs_sb_source;
848 struct cifs_sb_info *cifs_sb_target;
849 struct cifsTconInfo *pTcon;
850 int xid;
851 int rc = 0;
852
853 xid = GetXid();
854
855 cifs_sb_target = CIFS_SB(target_inode->i_sb);
856 cifs_sb_source = CIFS_SB(source_inode->i_sb);
857 pTcon = cifs_sb_source->tcon;
858
859 if (pTcon != cifs_sb_target->tcon) {
860 FreeXid(xid);
861 return -EXDEV; /* BB actually could be allowed if same server,
862 but different share.
863 Might eventually add support for this */
864 }
865
866 /* we already have the rename sem so we do not need to grab it again
867 here to protect the path integrity */
Steve French7f573562005-08-30 11:32:14 -0700868 fromName = build_path_from_dentry(source_direntry);
869 toName = build_path_from_dentry(target_direntry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 if ((fromName == NULL) || (toName == NULL)) {
871 rc = -ENOMEM;
872 goto cifs_rename_exit;
873 }
874
875 rc = CIFSSMBRename(xid, pTcon, fromName, toName,
Steve French737b7582005-04-28 22:41:06 -0700876 cifs_sb_source->local_nls,
877 cifs_sb_source->mnt_cifs_flags &
878 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 if (rc == -EEXIST) {
880 /* check if they are the same file because rename of hardlinked
881 files is a noop */
882 FILE_UNIX_BASIC_INFO *info_buf_source;
883 FILE_UNIX_BASIC_INFO *info_buf_target;
884
885 info_buf_source =
886 kmalloc(2 * sizeof(FILE_UNIX_BASIC_INFO), GFP_KERNEL);
887 if (info_buf_source != NULL) {
888 info_buf_target = info_buf_source + 1;
889 rc = CIFSSMBUnixQPathInfo(xid, pTcon, fromName,
Steve French737b7582005-04-28 22:41:06 -0700890 info_buf_source, cifs_sb_source->local_nls,
891 cifs_sb_source->mnt_cifs_flags &
892 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 if (rc == 0) {
894 rc = CIFSSMBUnixQPathInfo(xid, pTcon, toName,
895 info_buf_target,
Steve French737b7582005-04-28 22:41:06 -0700896 cifs_sb_target->local_nls,
897 /* remap based on source sb */
898 cifs_sb_source->mnt_cifs_flags &
899 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 }
901 if ((rc == 0) &&
902 (info_buf_source->UniqueId ==
903 info_buf_target->UniqueId)) {
904 /* do not rename since the files are hardlinked which
905 is a noop */
906 } else {
907 /* we either can not tell the files are hardlinked
908 (as with Windows servers) or files are not
909 hardlinked so delete the target manually before
910 renaming to follow POSIX rather than Windows
911 semantics */
912 cifs_unlink(target_inode, target_direntry);
913 rc = CIFSSMBRename(xid, pTcon, fromName,
914 toName,
Steve French737b7582005-04-28 22:41:06 -0700915 cifs_sb_source->local_nls,
916 cifs_sb_source->mnt_cifs_flags
917 & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 }
919 kfree(info_buf_source);
920 } /* if we can not get memory just leave rc as EEXIST */
921 }
922
923 if (rc) {
924 cFYI(1, ("rename rc %d", rc));
925 }
926
927 if ((rc == -EIO) || (rc == -EEXIST)) {
928 int oplock = FALSE;
929 __u16 netfid;
930
931 /* BB FIXME Is Generic Read correct for rename? */
932 /* if renaming directory - we should not say CREATE_NOT_DIR,
933 need to test renaming open directory, also GENERIC_READ
934 might not right be right access to request */
935 rc = CIFSSMBOpen(xid, pTcon, fromName, FILE_OPEN, GENERIC_READ,
936 CREATE_NOT_DIR, &netfid, &oplock, NULL,
Steve French737b7582005-04-28 22:41:06 -0700937 cifs_sb_source->local_nls,
938 cifs_sb_source->mnt_cifs_flags &
939 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 if (rc==0) {
941 CIFSSMBRenameOpenFile(xid, pTcon, netfid, toName,
Steve French737b7582005-04-28 22:41:06 -0700942 cifs_sb_source->local_nls,
943 cifs_sb_source->mnt_cifs_flags &
944 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 CIFSSMBClose(xid, pTcon, netfid);
946 }
947 }
948
949cifs_rename_exit:
950 kfree(fromName);
951 kfree(toName);
952 FreeXid(xid);
953 return rc;
954}
955
956int cifs_revalidate(struct dentry *direntry)
957{
958 int xid;
959 int rc = 0;
960 char *full_path;
961 struct cifs_sb_info *cifs_sb;
962 struct cifsInodeInfo *cifsInode;
963 loff_t local_size;
964 struct timespec local_mtime;
965 int invalidate_inode = FALSE;
966
967 if (direntry->d_inode == NULL)
968 return -ENOENT;
969
970 cifsInode = CIFS_I(direntry->d_inode);
971
972 if (cifsInode == NULL)
973 return -ENOENT;
974
975 /* no sense revalidating inode info on file that no one can write */
976 if (CIFS_I(direntry->d_inode)->clientCanCacheRead)
977 return rc;
978
979 xid = GetXid();
980
981 cifs_sb = CIFS_SB(direntry->d_sb);
982
983 /* can not safely grab the rename sem here if rename calls revalidate
984 since that would deadlock */
Steve French7f573562005-08-30 11:32:14 -0700985 full_path = build_path_from_dentry(direntry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 if (full_path == NULL) {
987 FreeXid(xid);
988 return -ENOMEM;
989 }
990 cFYI(1, ("Revalidate: %s inode 0x%p count %d dentry: 0x%p d_time %ld "
991 "jiffies %ld", full_path, direntry->d_inode,
992 direntry->d_inode->i_count.counter, direntry,
993 direntry->d_time, jiffies));
994
995 if (cifsInode->time == 0) {
996 /* was set to zero previously to force revalidate */
997 } else if (time_before(jiffies, cifsInode->time + HZ) &&
998 lookupCacheEnabled) {
999 if ((S_ISREG(direntry->d_inode->i_mode) == 0) ||
1000 (direntry->d_inode->i_nlink == 1)) {
1001 kfree(full_path);
1002 FreeXid(xid);
1003 return rc;
1004 } else {
1005 cFYI(1, ("Have to revalidate file due to hardlinks"));
1006 }
1007 }
1008
1009 /* save mtime and size */
1010 local_mtime = direntry->d_inode->i_mtime;
1011 local_size = direntry->d_inode->i_size;
1012
1013 if (cifs_sb->tcon->ses->capabilities & CAP_UNIX) {
1014 rc = cifs_get_inode_info_unix(&direntry->d_inode, full_path,
1015 direntry->d_sb,xid);
1016 if (rc) {
1017 cFYI(1, ("error on getting revalidate info %d", rc));
1018/* if (rc != -ENOENT)
1019 rc = 0; */ /* BB should we cache info on
1020 certain errors? */
1021 }
1022 } else {
1023 rc = cifs_get_inode_info(&direntry->d_inode, full_path, NULL,
1024 direntry->d_sb,xid);
1025 if (rc) {
1026 cFYI(1, ("error on getting revalidate info %d", rc));
1027/* if (rc != -ENOENT)
1028 rc = 0; */ /* BB should we cache info on
1029 certain errors? */
1030 }
1031 }
1032 /* should we remap certain errors, access denied?, to zero */
1033
1034 /* if not oplocked, we invalidate inode pages if mtime or file size
1035 had changed on server */
1036
1037 if (timespec_equal(&local_mtime,&direntry->d_inode->i_mtime) &&
1038 (local_size == direntry->d_inode->i_size)) {
1039 cFYI(1, ("cifs_revalidate - inode unchanged"));
1040 } else {
1041 /* file may have changed on server */
1042 if (cifsInode->clientCanCacheRead) {
1043 /* no need to invalidate inode pages since we were the
1044 only ones who could have modified the file and the
1045 server copy is staler than ours */
1046 } else {
1047 invalidate_inode = TRUE;
1048 }
1049 }
1050
1051 /* can not grab this sem since kernel filesys locking documentation
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08001052 indicates i_mutex may be taken by the kernel on lookup and rename
1053 which could deadlock if we grab the i_mutex here as well */
1054/* mutex_lock(&direntry->d_inode->i_mutex);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 /* need to write out dirty pages here */
1056 if (direntry->d_inode->i_mapping) {
1057 /* do we need to lock inode until after invalidate completes
1058 below? */
1059 filemap_fdatawrite(direntry->d_inode->i_mapping);
1060 }
1061 if (invalidate_inode) {
Steve French3abb9272005-11-28 08:16:13 -08001062 /* shrink_dcache not necessary now that cifs dentry ops
1063 are exported for negative dentries */
1064/* if(S_ISDIR(direntry->d_inode->i_mode))
1065 shrink_dcache_parent(direntry); */
1066 if (S_ISREG(direntry->d_inode->i_mode)) {
1067 if (direntry->d_inode->i_mapping)
1068 filemap_fdatawait(direntry->d_inode->i_mapping);
1069 /* may eventually have to do this for open files too */
1070 if (list_empty(&(cifsInode->openFileList))) {
1071 /* changed on server - flush read ahead pages */
1072 cFYI(1, ("Invalidating read ahead data on "
1073 "closed file"));
1074 invalidate_remote_inode(direntry->d_inode);
1075 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 }
1077 }
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08001078/* mutex_unlock(&direntry->d_inode->i_mutex); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
1080 kfree(full_path);
1081 FreeXid(xid);
1082 return rc;
1083}
1084
1085int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1086 struct kstat *stat)
1087{
1088 int err = cifs_revalidate(dentry);
1089 if (!err)
1090 generic_fillattr(dentry->d_inode, stat);
1091 return err;
1092}
1093
1094static int cifs_truncate_page(struct address_space *mapping, loff_t from)
1095{
1096 pgoff_t index = from >> PAGE_CACHE_SHIFT;
1097 unsigned offset = from & (PAGE_CACHE_SIZE - 1);
1098 struct page *page;
1099 char *kaddr;
1100 int rc = 0;
1101
1102 page = grab_cache_page(mapping, index);
1103 if (!page)
1104 return -ENOMEM;
1105
1106 kaddr = kmap_atomic(page, KM_USER0);
1107 memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset);
1108 flush_dcache_page(page);
1109 kunmap_atomic(kaddr, KM_USER0);
1110 unlock_page(page);
1111 page_cache_release(page);
1112 return rc;
1113}
1114
1115int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
1116{
1117 int xid;
1118 struct cifs_sb_info *cifs_sb;
1119 struct cifsTconInfo *pTcon;
1120 char *full_path = NULL;
1121 int rc = -EACCES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 struct cifsFileInfo *open_file = NULL;
1123 FILE_BASIC_INFO time_buf;
1124 int set_time = FALSE;
1125 __u64 mode = 0xFFFFFFFFFFFFFFFFULL;
1126 __u64 uid = 0xFFFFFFFFFFFFFFFFULL;
1127 __u64 gid = 0xFFFFFFFFFFFFFFFFULL;
1128 struct cifsInodeInfo *cifsInode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
1130 xid = GetXid();
1131
Steve French39798772006-05-31 22:40:51 +00001132 cFYI(1, ("setattr on file %s attrs->iavalid 0x%x",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 direntry->d_name.name, attrs->ia_valid));
Steve French6473a552005-11-29 20:20:10 -08001134
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 cifs_sb = CIFS_SB(direntry->d_inode->i_sb);
1136 pTcon = cifs_sb->tcon;
1137
Steve French2a138ebb2005-11-29 21:22:19 -08001138 if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) == 0) {
Steve French6473a552005-11-29 20:20:10 -08001139 /* check if we have permission to change attrs */
1140 rc = inode_change_ok(direntry->d_inode, attrs);
1141 if(rc < 0) {
1142 FreeXid(xid);
1143 return rc;
1144 } else
1145 rc = 0;
1146 }
1147
Steve French7f573562005-08-30 11:32:14 -07001148 full_path = build_path_from_dentry(direntry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 if (full_path == NULL) {
1150 FreeXid(xid);
1151 return -ENOMEM;
1152 }
1153 cifsInode = CIFS_I(direntry->d_inode);
1154
1155 /* BB check if we need to refresh inode from server now ? BB */
1156
1157 /* need to flush data before changing file size on server */
OGAWA Hirofumi28fd1292006-01-08 01:02:14 -08001158 filemap_write_and_wait(direntry->d_inode->i_mapping);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
1160 if (attrs->ia_valid & ATTR_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 /* To avoid spurious oplock breaks from server, in the case of
1162 inodes that we already have open, avoid doing path based
1163 setting of file size if we can do it by handle.
1164 This keeps our caching token (oplock) and avoids timeouts
1165 when the local oplock break takes longer to flush
1166 writebehind data than the SMB timeout for the SetPathInfo
1167 request would allow */
Steve French39798772006-05-31 22:40:51 +00001168
Steve French6148a742005-10-05 12:23:19 -07001169 open_file = find_writable_file(cifsInode);
1170 if (open_file) {
1171 __u16 nfid = open_file->netfid;
1172 __u32 npid = open_file->pid;
1173 rc = CIFSSMBSetFileSize(xid, pTcon, attrs->ia_size,
1174 nfid, npid, FALSE);
Steve French23e7dd72005-10-20 13:44:56 -07001175 atomic_dec(&open_file->wrtPending);
Steve French6148a742005-10-05 12:23:19 -07001176 cFYI(1,("SetFSize for attrs rc = %d", rc));
Steve French083d3a22006-03-03 09:53:36 +00001177 if((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
Steve French6148a742005-10-05 12:23:19 -07001178 int bytes_written;
1179 rc = CIFSSMBWrite(xid, pTcon,
1180 nfid, 0, attrs->ia_size,
1181 &bytes_written, NULL, NULL,
1182 1 /* 45 seconds */);
1183 cFYI(1,("Wrt seteof rc %d", rc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 }
Steve French6473a552005-11-29 20:20:10 -08001185 } else
1186 rc = -EINVAL;
1187
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 if (rc != 0) {
1189 /* Set file size by pathname rather than by handle
1190 either because no valid, writeable file handle for
1191 it was found or because there was an error setting
1192 it by handle */
1193 rc = CIFSSMBSetEOF(xid, pTcon, full_path,
1194 attrs->ia_size, FALSE,
Steve French737b7582005-04-28 22:41:06 -07001195 cifs_sb->local_nls,
1196 cifs_sb->mnt_cifs_flags &
1197 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve Frenche30dcf32005-09-20 20:49:16 -07001198 cFYI(1, ("SetEOF by path (setattrs) rc = %d", rc));
Steve French083d3a22006-03-03 09:53:36 +00001199 if((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
Steve Frenche30dcf32005-09-20 20:49:16 -07001200 __u16 netfid;
1201 int oplock = FALSE;
1202
1203 rc = SMBLegacyOpen(xid, pTcon, full_path,
1204 FILE_OPEN,
1205 SYNCHRONIZE | FILE_WRITE_ATTRIBUTES,
1206 CREATE_NOT_DIR, &netfid, &oplock,
1207 NULL, cifs_sb->local_nls,
1208 cifs_sb->mnt_cifs_flags &
1209 CIFS_MOUNT_MAP_SPECIAL_CHR);
1210 if (rc==0) {
1211 int bytes_written;
1212 rc = CIFSSMBWrite(xid, pTcon,
1213 netfid, 0,
1214 attrs->ia_size,
1215 &bytes_written, NULL,
1216 NULL, 1 /* 45 sec */);
1217 cFYI(1,("wrt seteof rc %d",rc));
1218 CIFSSMBClose(xid, pTcon, netfid);
1219 }
1220
1221 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 }
1223
1224 /* Server is ok setting allocation size implicitly - no need
1225 to call:
1226 CIFSSMBSetEOF(xid, pTcon, full_path, attrs->ia_size, TRUE,
1227 cifs_sb->local_nls);
1228 */
1229
1230 if (rc == 0) {
1231 rc = vmtruncate(direntry->d_inode, attrs->ia_size);
1232 cifs_truncate_page(direntry->d_inode->i_mapping,
1233 direntry->d_inode->i_size);
Steve Frenche30dcf32005-09-20 20:49:16 -07001234 } else
1235 goto cifs_setattr_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 }
1237 if (attrs->ia_valid & ATTR_UID) {
Steve Frenche30dcf32005-09-20 20:49:16 -07001238 cFYI(1, ("UID changed to %d", attrs->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 uid = attrs->ia_uid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 }
1241 if (attrs->ia_valid & ATTR_GID) {
Steve Frenche30dcf32005-09-20 20:49:16 -07001242 cFYI(1, ("GID changed to %d", attrs->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 gid = attrs->ia_gid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 }
1245
1246 time_buf.Attributes = 0;
1247 if (attrs->ia_valid & ATTR_MODE) {
Steve Frenche30dcf32005-09-20 20:49:16 -07001248 cFYI(1, ("Mode changed to 0x%x", attrs->ia_mode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 mode = attrs->ia_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 }
1251
1252 if ((cifs_sb->tcon->ses->capabilities & CAP_UNIX)
1253 && (attrs->ia_valid & (ATTR_MODE | ATTR_GID | ATTR_UID)))
1254 rc = CIFSSMBUnixSetPerms(xid, pTcon, full_path, mode, uid, gid,
Steve French737b7582005-04-28 22:41:06 -07001255 0 /* dev_t */, cifs_sb->local_nls,
1256 cifs_sb->mnt_cifs_flags &
1257 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 else if (attrs->ia_valid & ATTR_MODE) {
Steve Frenchcdbce9c2005-11-19 21:04:52 -08001259 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 if ((mode & S_IWUGO) == 0) /* not writeable */ {
1261 if ((cifsInode->cifsAttrs & ATTR_READONLY) == 0)
1262 time_buf.Attributes =
1263 cpu_to_le32(cifsInode->cifsAttrs |
1264 ATTR_READONLY);
1265 } else if ((mode & S_IWUGO) == S_IWUGO) {
1266 if (cifsInode->cifsAttrs & ATTR_READONLY)
1267 time_buf.Attributes =
1268 cpu_to_le32(cifsInode->cifsAttrs &
1269 (~ATTR_READONLY));
1270 }
1271 /* BB to be implemented -
1272 via Windows security descriptors or streams */
1273 /* CIFSSMBWinSetPerms(xid, pTcon, full_path, mode, uid, gid,
1274 cifs_sb->local_nls); */
1275 }
1276
1277 if (attrs->ia_valid & ATTR_ATIME) {
1278 set_time = TRUE;
1279 time_buf.LastAccessTime =
1280 cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_atime));
1281 } else
1282 time_buf.LastAccessTime = 0;
1283
1284 if (attrs->ia_valid & ATTR_MTIME) {
1285 set_time = TRUE;
1286 time_buf.LastWriteTime =
1287 cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_mtime));
1288 } else
1289 time_buf.LastWriteTime = 0;
Steve Frenche30dcf32005-09-20 20:49:16 -07001290 /* Do not set ctime explicitly unless other time
1291 stamps are changed explicitly (i.e. by utime()
1292 since we would then have a mix of client and
1293 server times */
1294
1295 if (set_time && (attrs->ia_valid & ATTR_CTIME)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 set_time = TRUE;
Steve Frenche30dcf32005-09-20 20:49:16 -07001297 /* Although Samba throws this field away
1298 it may be useful to Windows - but we do
1299 not want to set ctime unless some other
1300 timestamp is changing */
Steve French26a21b92006-05-31 18:05:34 +00001301 cFYI(1, ("CIFS - CTIME changed"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 time_buf.ChangeTime =
1303 cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_ctime));
1304 } else
1305 time_buf.ChangeTime = 0;
1306
1307 if (set_time || time_buf.Attributes) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 time_buf.CreationTime = 0; /* do not change */
1309 /* In the future we should experiment - try setting timestamps
1310 via Handle (SetFileInfo) instead of by path */
1311 if (!(pTcon->ses->flags & CIFS_SES_NT4))
1312 rc = CIFSSMBSetTimes(xid, pTcon, full_path, &time_buf,
Steve French737b7582005-04-28 22:41:06 -07001313 cifs_sb->local_nls,
1314 cifs_sb->mnt_cifs_flags &
1315 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 else
1317 rc = -EOPNOTSUPP;
1318
1319 if (rc == -EOPNOTSUPP) {
1320 int oplock = FALSE;
1321 __u16 netfid;
1322
1323 cFYI(1, ("calling SetFileInfo since SetPathInfo for "
1324 "times not supported by this server"));
1325 /* BB we could scan to see if we already have it open
1326 and pass in pid of opener to function */
1327 rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN,
1328 SYNCHRONIZE | FILE_WRITE_ATTRIBUTES,
1329 CREATE_NOT_DIR, &netfid, &oplock,
Steve French737b7582005-04-28 22:41:06 -07001330 NULL, cifs_sb->local_nls,
1331 cifs_sb->mnt_cifs_flags &
1332 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 if (rc==0) {
1334 rc = CIFSSMBSetFileTimes(xid, pTcon, &time_buf,
1335 netfid);
1336 CIFSSMBClose(xid, pTcon, netfid);
1337 } else {
1338 /* BB For even older servers we could convert time_buf
1339 into old DOS style which uses two second
1340 granularity */
1341
1342 /* rc = CIFSSMBSetTimesLegacy(xid, pTcon, full_path,
1343 &time_buf, cifs_sb->local_nls); */
1344 }
1345 }
Steve Frenche30dcf32005-09-20 20:49:16 -07001346 /* Even if error on time set, no sense failing the call if
1347 the server would set the time to a reasonable value anyway,
1348 and this check ensures that we are not being called from
1349 sys_utimes in which case we ought to fail the call back to
1350 the user when the server rejects the call */
1351 if((rc) && (attrs->ia_valid &&
1352 (ATTR_MODE | ATTR_GID | ATTR_UID | ATTR_SIZE)))
1353 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 }
1355
1356 /* do not need local check to inode_check_ok since the server does
1357 that */
1358 if (!rc)
1359 rc = inode_setattr(direntry->d_inode, attrs);
Steve Frenche30dcf32005-09-20 20:49:16 -07001360cifs_setattr_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 kfree(full_path);
1362 FreeXid(xid);
1363 return rc;
1364}
1365
1366void cifs_delete_inode(struct inode *inode)
1367{
Steve French26a21b92006-05-31 18:05:34 +00001368 cFYI(1, ("In cifs_delete_inode, inode = 0x%p", inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 /* may have to add back in if and when safe distributed caching of
1370 directories added e.g. via FindNotify */
1371}