blob: 37c6ce87416b3eb540f05e30859e6b262c080dd8 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/stat.h>
23#include <linux/pagemap.h>
24#include <asm/div64.h>
25#include "cifsfs.h"
26#include "cifspdu.h"
27#include "cifsglob.h"
28#include "cifsproto.h"
29#include "cifs_debug.h"
30#include "cifs_fs_sb.h"
31
32int cifs_get_inode_info_unix(struct inode **pinode,
33 const unsigned char *search_path, struct super_block *sb, int xid)
34{
35 int rc = 0;
36 FILE_UNIX_BASIC_INFO findData;
37 struct cifsTconInfo *pTcon;
38 struct inode *inode;
39 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
40 char *tmp_path;
41
42 pTcon = cifs_sb->tcon;
Steve French26a21b92006-05-31 18:05:34 +000043 cFYI(1, ("Getting info on %s", search_path));
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 /* could have done a find first instead but this returns more info */
45 rc = CIFSSMBUnixQPathInfo(xid, pTcon, search_path, &findData,
Steve French737b7582005-04-28 22:41:06 -070046 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
47 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048/* dump_mem("\nUnixQPathInfo return data", &findData,
49 sizeof(findData)); */
50 if (rc) {
51 if (rc == -EREMOTE) {
52 tmp_path =
53 kmalloc(strnlen(pTcon->treeName,
54 MAX_TREE_SIZE + 1) +
55 strnlen(search_path, MAX_PATHCONF) + 1,
56 GFP_KERNEL);
57 if (tmp_path == NULL) {
58 return -ENOMEM;
59 }
60 /* have to skip first of the double backslash of
61 UNC name */
62 strncpy(tmp_path, pTcon->treeName, MAX_TREE_SIZE);
63 strncat(tmp_path, search_path, MAX_PATHCONF);
64 rc = connect_to_dfs_path(xid, pTcon->ses,
65 /* treename + */ tmp_path,
Steve French737b7582005-04-28 22:41:06 -070066 cifs_sb->local_nls,
67 cifs_sb->mnt_cifs_flags &
68 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 kfree(tmp_path);
70
71 /* BB fix up inode etc. */
72 } else if (rc) {
73 return rc;
74 }
75 } else {
76 struct cifsInodeInfo *cifsInfo;
77 __u32 type = le32_to_cpu(findData.Type);
78 __u64 num_of_bytes = le64_to_cpu(findData.NumOfBytes);
79 __u64 end_of_file = le64_to_cpu(findData.EndOfFile);
80
81 /* get new inode */
82 if (*pinode == NULL) {
83 *pinode = new_inode(sb);
Steve Frenchd0d2f2d2005-06-02 15:12:36 -070084 if (*pinode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 return -ENOMEM;
86 /* Is an i_ino of zero legal? */
87 /* Are there sanity checks we can use to ensure that
88 the server is really filling in that field? */
Steve Frenchd0d2f2d2005-06-02 15:12:36 -070089 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 (*pinode)->i_ino =
91 (unsigned long)findData.UniqueId;
92 } /* note ino incremented to unique num in new_inode */
Steve French1b2b2122007-02-17 04:30:54 +000093 if(sb->s_flags & MS_NOATIME)
94 (*pinode)->i_flags |= S_NOATIME | S_NOCMTIME;
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 insert_inode_hash(*pinode);
97 }
98
99 inode = *pinode;
100 cifsInfo = CIFS_I(inode);
101
Steve French26a21b92006-05-31 18:05:34 +0000102 cFYI(1, ("Old time %ld", cifsInfo->time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 cifsInfo->time = jiffies;
Steve French26a21b92006-05-31 18:05:34 +0000104 cFYI(1, ("New time %ld", cifsInfo->time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 /* this is ok to set on every inode revalidate */
106 atomic_set(&cifsInfo->inUse,1);
107
108 inode->i_atime =
109 cifs_NTtimeToUnix(le64_to_cpu(findData.LastAccessTime));
110 inode->i_mtime =
111 cifs_NTtimeToUnix(le64_to_cpu
112 (findData.LastModificationTime));
113 inode->i_ctime =
114 cifs_NTtimeToUnix(le64_to_cpu(findData.LastStatusChange));
115 inode->i_mode = le64_to_cpu(findData.Permissions);
Steve French3020a1f2005-11-18 11:31:10 -0800116 /* since we set the inode type below we need to mask off
117 to avoid strange results if bits set above */
118 inode->i_mode &= ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 if (type == UNIX_FILE) {
120 inode->i_mode |= S_IFREG;
121 } else if (type == UNIX_SYMLINK) {
122 inode->i_mode |= S_IFLNK;
123 } else if (type == UNIX_DIR) {
124 inode->i_mode |= S_IFDIR;
125 } else if (type == UNIX_CHARDEV) {
126 inode->i_mode |= S_IFCHR;
127 inode->i_rdev = MKDEV(le64_to_cpu(findData.DevMajor),
128 le64_to_cpu(findData.DevMinor) & MINORMASK);
129 } else if (type == UNIX_BLOCKDEV) {
130 inode->i_mode |= S_IFBLK;
131 inode->i_rdev = MKDEV(le64_to_cpu(findData.DevMajor),
132 le64_to_cpu(findData.DevMinor) & MINORMASK);
133 } else if (type == UNIX_FIFO) {
134 inode->i_mode |= S_IFIFO;
135 } else if (type == UNIX_SOCKET) {
136 inode->i_mode |= S_IFSOCK;
Steve French3020a1f2005-11-18 11:31:10 -0800137 } else {
138 /* safest to call it a file if we do not know */
139 inode->i_mode |= S_IFREG;
140 cFYI(1,("unknown type %d",type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 }
142 inode->i_uid = le64_to_cpu(findData.Uid);
143 inode->i_gid = le64_to_cpu(findData.Gid);
144 inode->i_nlink = le64_to_cpu(findData.Nlinks);
145
Steve French7ba52632007-02-08 18:14:13 +0000146 if (is_size_safe_to_change(cifsInfo, end_of_file)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 /* can not safely change the file size here if the
148 client is writing to it due to potential races */
149
150 i_size_write(inode, end_of_file);
151
152 /* blksize needs to be multiple of two. So safer to default to
153 blksize and blkbits set in superblock so 2**blkbits and blksize
154 will match rather than setting to:
155 (pTcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFE00;*/
156
157 /* This seems incredibly stupid but it turns out that i_blocks
158 is not related to (i_size / i_blksize), instead 512 byte size
159 is required for calculating num blocks */
160
161 /* 512 bytes (2**9) is the fake blocksize that must be used */
162 /* for this calculation */
163 inode->i_blocks = (512 - 1 + num_of_bytes) >> 9;
164 }
165
166 if (num_of_bytes < end_of_file)
Steve French8b94bcb2005-11-11 11:41:00 -0800167 cFYI(1, ("allocation size less than end of file"));
Andrew Morton5515eff2006-03-26 01:37:53 -0800168 cFYI(1, ("Size %ld and blocks %llu",
169 (unsigned long) inode->i_size,
170 (unsigned long long)inode->i_blocks));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 if (S_ISREG(inode->i_mode)) {
Steve French8b94bcb2005-11-11 11:41:00 -0800172 cFYI(1, ("File inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 inode->i_op = &cifs_file_inode_ops;
Steve French8b94bcb2005-11-11 11:41:00 -0800174 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
175 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
176 inode->i_fop =
177 &cifs_file_direct_nobrl_ops;
178 else
179 inode->i_fop = &cifs_file_direct_ops;
180 } else if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
181 inode->i_fop = &cifs_file_nobrl_ops;
182 else /* not direct, send byte range locks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 inode->i_fop = &cifs_file_ops;
Steve French8b94bcb2005-11-11 11:41:00 -0800184
Steve Frenchbfa0d752005-08-31 21:50:37 -0700185 /* check if server can support readpages */
186 if(pTcon->ses->server->maxBuf <
Dave Kleikamp273d81d2006-06-01 19:41:23 +0000187 PAGE_CACHE_SIZE + MAX_CIFS_HDR_SIZE)
188 inode->i_data.a_ops = &cifs_addr_ops_smallbuf;
189 else
190 inode->i_data.a_ops = &cifs_addr_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 } else if (S_ISDIR(inode->i_mode)) {
Steve French8b94bcb2005-11-11 11:41:00 -0800192 cFYI(1, ("Directory inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 inode->i_op = &cifs_dir_inode_ops;
194 inode->i_fop = &cifs_dir_ops;
195 } else if (S_ISLNK(inode->i_mode)) {
Steve French8b94bcb2005-11-11 11:41:00 -0800196 cFYI(1, ("Symbolic Link inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 inode->i_op = &cifs_symlink_inode_ops;
198 /* tmp_inode->i_fop = */ /* do not need to set to anything */
199 } else {
Steve French8b94bcb2005-11-11 11:41:00 -0800200 cFYI(1, ("Init special inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 init_special_inode(inode, inode->i_mode,
202 inode->i_rdev);
203 }
204 }
205 return rc;
206}
207
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800208static int decode_sfu_inode(struct inode * inode, __u64 size,
209 const unsigned char *path,
210 struct cifs_sb_info *cifs_sb, int xid)
211{
212 int rc;
213 int oplock = FALSE;
214 __u16 netfid;
215 struct cifsTconInfo *pTcon = cifs_sb->tcon;
Steve French86c96b42005-11-18 20:25:31 -0800216 char buf[24];
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800217 unsigned int bytes_read;
218 char * pbuf;
219
220 pbuf = buf;
221
222 if(size == 0) {
223 inode->i_mode |= S_IFIFO;
224 return 0;
225 } else if (size < 8) {
226 return -EINVAL; /* EOPNOTSUPP? */
227 }
228
229 rc = CIFSSMBOpen(xid, pTcon, path, FILE_OPEN, GENERIC_READ,
230 CREATE_NOT_DIR, &netfid, &oplock, NULL,
231 cifs_sb->local_nls,
232 cifs_sb->mnt_cifs_flags &
233 CIFS_MOUNT_MAP_SPECIAL_CHR);
234 if (rc==0) {
Steve Frenchec637e32005-12-12 20:53:18 -0800235 int buf_type = CIFS_NO_BUFFER;
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800236 /* Read header */
237 rc = CIFSSMBRead(xid, pTcon,
238 netfid,
Steve French86c96b42005-11-18 20:25:31 -0800239 24 /* length */, 0 /* offset */,
Steve Frenchec637e32005-12-12 20:53:18 -0800240 &bytes_read, &pbuf, &buf_type);
Steve French86c96b42005-11-18 20:25:31 -0800241 if((rc == 0) && (bytes_read >= 8)) {
Steve French9e294f12005-11-17 16:59:21 -0800242 if(memcmp("IntxBLK", pbuf, 8) == 0) {
243 cFYI(1,("Block device"));
Steve French3020a1f2005-11-18 11:31:10 -0800244 inode->i_mode |= S_IFBLK;
Steve French86c96b42005-11-18 20:25:31 -0800245 if(bytes_read == 24) {
246 /* we have enough to decode dev num */
247 __u64 mjr; /* major */
248 __u64 mnr; /* minor */
249 mjr = le64_to_cpu(*(__le64 *)(pbuf+8));
250 mnr = le64_to_cpu(*(__le64 *)(pbuf+16));
251 inode->i_rdev = MKDEV(mjr, mnr);
252 }
Steve French9e294f12005-11-17 16:59:21 -0800253 } else if(memcmp("IntxCHR", pbuf, 8) == 0) {
254 cFYI(1,("Char device"));
Steve French3020a1f2005-11-18 11:31:10 -0800255 inode->i_mode |= S_IFCHR;
Steve French86c96b42005-11-18 20:25:31 -0800256 if(bytes_read == 24) {
257 /* we have enough to decode dev num */
258 __u64 mjr; /* major */
259 __u64 mnr; /* minor */
260 mjr = le64_to_cpu(*(__le64 *)(pbuf+8));
261 mnr = le64_to_cpu(*(__le64 *)(pbuf+16));
262 inode->i_rdev = MKDEV(mjr, mnr);
263 }
Steve French9e294f12005-11-17 16:59:21 -0800264 } else if(memcmp("IntxLNK", pbuf, 7) == 0) {
265 cFYI(1,("Symlink"));
Steve French3020a1f2005-11-18 11:31:10 -0800266 inode->i_mode |= S_IFLNK;
Steve French86c96b42005-11-18 20:25:31 -0800267 } else {
268 inode->i_mode |= S_IFREG; /* file? */
269 rc = -EOPNOTSUPP;
270 }
Steve French3020a1f2005-11-18 11:31:10 -0800271 } else {
272 inode->i_mode |= S_IFREG; /* then it is a file */
273 rc = -EOPNOTSUPP; /* or some unknown SFU type */
Steve Frenchec637e32005-12-12 20:53:18 -0800274 }
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800275 CIFSSMBClose(xid, pTcon, netfid);
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800276 }
277 return rc;
278
279}
280
Steve French9e294f12005-11-17 16:59:21 -0800281#define SFBITS_MASK (S_ISVTX | S_ISGID | S_ISUID) /* SETFILEBITS valid bits */
282
283static int get_sfu_uid_mode(struct inode * inode,
284 const unsigned char *path,
285 struct cifs_sb_info *cifs_sb, int xid)
286{
Steve French3020a1f2005-11-18 11:31:10 -0800287#ifdef CONFIG_CIFS_XATTR
Steve French9e294f12005-11-17 16:59:21 -0800288 ssize_t rc;
289 char ea_value[4];
290 __u32 mode;
291
292 rc = CIFSSMBQueryEA(xid, cifs_sb->tcon, path, "SETFILEBITS",
293 ea_value, 4 /* size of buf */, cifs_sb->local_nls,
294 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
295 if(rc < 0)
296 return (int)rc;
297 else if (rc > 3) {
298 mode = le32_to_cpu(*((__le32 *)ea_value));
Steve Frenchc119b872005-11-18 12:27:27 -0800299 inode->i_mode &= ~SFBITS_MASK;
Steve French3020a1f2005-11-18 11:31:10 -0800300 cFYI(1,("special bits 0%o org mode 0%o", mode, inode->i_mode));
Steve French9e294f12005-11-17 16:59:21 -0800301 inode->i_mode = (mode & SFBITS_MASK) | inode->i_mode;
302 cFYI(1,("special mode bits 0%o", mode));
303 return 0;
304 } else {
305 return 0;
306 }
Steve French3020a1f2005-11-18 11:31:10 -0800307#else
308 return -EOPNOTSUPP;
309#endif
310
Steve French9e294f12005-11-17 16:59:21 -0800311
312}
313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314int cifs_get_inode_info(struct inode **pinode,
315 const unsigned char *search_path, FILE_ALL_INFO *pfindData,
316 struct super_block *sb, int xid)
317{
318 int rc = 0;
319 struct cifsTconInfo *pTcon;
320 struct inode *inode;
321 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
322 char *tmp_path;
323 char *buf = NULL;
Steve French8d6286f2006-11-16 22:48:25 +0000324 int adjustTZ = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326 pTcon = cifs_sb->tcon;
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800327 cFYI(1,("Getting info on %s", search_path));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700329 if ((pfindData == NULL) && (*pinode != NULL)) {
330 if (CIFS_I(*pinode)->clientCanCacheRead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 cFYI(1,("No need to revalidate cached inode sizes"));
332 return rc;
333 }
334 }
335
336 /* if file info not passed in then get it from server */
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700337 if (pfindData == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700339 if (buf == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 return -ENOMEM;
341 pfindData = (FILE_ALL_INFO *)buf;
342 /* could do find first instead but this returns more info */
343 rc = CIFSSMBQPathInfo(xid, pTcon, search_path, pfindData,
Steve Frenchacf1a1b2006-10-12 03:28:28 +0000344 0 /* not legacy */,
Steve French6b8edfe2005-08-23 20:26:03 -0700345 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700346 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French6b8edfe2005-08-23 20:26:03 -0700347 /* BB optimize code so we do not make the above call
348 when server claims no NT SMB support and the above call
349 failed at least once - set flag in tcon or mount */
350 if((rc == -EOPNOTSUPP) || (rc == -EINVAL)) {
351 rc = SMBQueryInformation(xid, pTcon, search_path,
352 pfindData, cifs_sb->local_nls,
353 cifs_sb->mnt_cifs_flags &
354 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French8d6286f2006-11-16 22:48:25 +0000355 adjustTZ = TRUE;
Steve French6b8edfe2005-08-23 20:26:03 -0700356 }
357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 }
359 /* dump_mem("\nQPathInfo return data",&findData, sizeof(findData)); */
360 if (rc) {
361 if (rc == -EREMOTE) {
362 tmp_path =
363 kmalloc(strnlen
364 (pTcon->treeName,
365 MAX_TREE_SIZE + 1) +
366 strnlen(search_path, MAX_PATHCONF) + 1,
367 GFP_KERNEL);
368 if (tmp_path == NULL) {
369 kfree(buf);
370 return -ENOMEM;
371 }
372
373 strncpy(tmp_path, pTcon->treeName, MAX_TREE_SIZE);
374 strncat(tmp_path, search_path, MAX_PATHCONF);
375 rc = connect_to_dfs_path(xid, pTcon->ses,
376 /* treename + */ tmp_path,
Steve French737b7582005-04-28 22:41:06 -0700377 cifs_sb->local_nls,
378 cifs_sb->mnt_cifs_flags &
379 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 kfree(tmp_path);
381 /* BB fix up inode etc. */
382 } else if (rc) {
383 kfree(buf);
384 return rc;
385 }
386 } else {
387 struct cifsInodeInfo *cifsInfo;
388 __u32 attr = le32_to_cpu(pfindData->Attributes);
389
390 /* get new inode */
391 if (*pinode == NULL) {
392 *pinode = new_inode(sb);
Steve Frenchacf1a1b2006-10-12 03:28:28 +0000393 if (*pinode == NULL) {
394 kfree(buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 return -ENOMEM;
Steve Frenchacf1a1b2006-10-12 03:28:28 +0000396 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 /* Is an i_ino of zero legal? Can we use that to check
398 if the server supports returning inode numbers? Are
399 there other sanity checks we can use to ensure that
400 the server is really filling in that field? */
401
402 /* We can not use the IndexNumber field by default from
403 Windows or Samba (in ALL_INFO buf) but we can request
404 it explicitly. It may not be unique presumably if
405 the server has multiple devices mounted under one
406 share */
407
408 /* There may be higher info levels that work but are
409 there Windows server or network appliances for which
410 IndexNumber field is not guaranteed unique? */
411
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700412 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 int rc1 = 0;
414 __u64 inode_num;
415
416 rc1 = CIFSGetSrvInodeNumber(xid, pTcon,
417 search_path, &inode_num,
Steve French737b7582005-04-28 22:41:06 -0700418 cifs_sb->local_nls,
419 cifs_sb->mnt_cifs_flags &
420 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700421 if (rc1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 cFYI(1,("GetSrvInodeNum rc %d", rc1));
423 /* BB EOPNOSUPP disable SERVER_INUM? */
424 } else /* do we need cast or hash to ino? */
425 (*pinode)->i_ino = inode_num;
426 } /* else ino incremented to unique num in new_inode*/
Steve French1b2b2122007-02-17 04:30:54 +0000427 if(sb->s_flags & MS_NOATIME)
428 (*pinode)->i_flags |= S_NOATIME | S_NOCMTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 insert_inode_hash(*pinode);
430 }
431 inode = *pinode;
432 cifsInfo = CIFS_I(inode);
433 cifsInfo->cifsAttrs = attr;
Steve French26a21b92006-05-31 18:05:34 +0000434 cFYI(1, ("Old time %ld", cifsInfo->time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 cifsInfo->time = jiffies;
Steve French26a21b92006-05-31 18:05:34 +0000436 cFYI(1, ("New time %ld", cifsInfo->time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
438 /* blksize needs to be multiple of two. So safer to default to
439 blksize and blkbits set in superblock so 2**blkbits and blksize
440 will match rather than setting to:
441 (pTcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFE00;*/
442
Steve French26a21b92006-05-31 18:05:34 +0000443 /* Linux can not store file creation time so ignore it */
Steve French1bd5bbc2006-09-28 03:35:57 +0000444 if(pfindData->LastAccessTime)
445 inode->i_atime = cifs_NTtimeToUnix
446 (le64_to_cpu(pfindData->LastAccessTime));
447 else /* do not need to use current_fs_time - time not stored */
448 inode->i_atime = CURRENT_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 inode->i_mtime =
450 cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastWriteTime));
451 inode->i_ctime =
452 cifs_NTtimeToUnix(le64_to_cpu(pfindData->ChangeTime));
Steve French26a21b92006-05-31 18:05:34 +0000453 cFYI(0, ("Attributes came in as 0x%x", attr));
Steve French8d6286f2006-11-16 22:48:25 +0000454 if(adjustTZ && (pTcon->ses) && (pTcon->ses->server)) {
455 inode->i_ctime.tv_sec += pTcon->ses->server->timeAdj;
456 inode->i_mtime.tv_sec += pTcon->ses->server->timeAdj;
457 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
459 /* set default mode. will override for dirs below */
460 if (atomic_read(&cifsInfo->inUse) == 0)
461 /* new inode, can safely set these fields */
462 inode->i_mode = cifs_sb->mnt_file_mode;
Steve French3020a1f2005-11-18 11:31:10 -0800463 else /* since we set the inode type below we need to mask off
464 to avoid strange results if type changes and both get orred in */
465 inode->i_mode &= ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466/* if (attr & ATTR_REPARSE) */
467 /* We no longer handle these as symlinks because we could not
468 follow them due to the absolute path with drive letter */
469 if (attr & ATTR_DIRECTORY) {
470 /* override default perms since we do not do byte range locking
471 on dirs */
472 inode->i_mode = cifs_sb->mnt_dir_mode;
473 inode->i_mode |= S_IFDIR;
Steve Frencheda3c0292005-07-21 15:20:28 -0700474 } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) &&
475 (cifsInfo->cifsAttrs & ATTR_SYSTEM) &&
476 /* No need to le64 convert size of zero */
477 (pfindData->EndOfFile == 0)) {
478 inode->i_mode = cifs_sb->mnt_file_mode;
479 inode->i_mode |= S_IFIFO;
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800480/* BB Finish for SFU style symlinks and devices */
481 } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) &&
482 (cifsInfo->cifsAttrs & ATTR_SYSTEM)) {
483 if (decode_sfu_inode(inode,
484 le64_to_cpu(pfindData->EndOfFile),
485 search_path,
486 cifs_sb, xid)) {
487 cFYI(1,("Unrecognized sfu inode type"));
488 }
Steve French3020a1f2005-11-18 11:31:10 -0800489 cFYI(1,("sfu mode 0%o",inode->i_mode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 } else {
491 inode->i_mode |= S_IFREG;
492 /* treat the dos attribute of read-only as read-only
493 mode e.g. 555 */
494 if (cifsInfo->cifsAttrs & ATTR_READONLY)
495 inode->i_mode &= ~(S_IWUGO);
496 /* BB add code here -
497 validate if device or weird share or device type? */
498 }
Steve French7ba52632007-02-08 18:14:13 +0000499 if (is_size_safe_to_change(cifsInfo, le64_to_cpu(pfindData->EndOfFile))) {
500 /* can not safely shrink the file size here if the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 client is writing to it due to potential races */
502 i_size_write(inode,le64_to_cpu(pfindData->EndOfFile));
503
504 /* 512 bytes (2**9) is the fake blocksize that must be
505 used for this calculation */
506 inode->i_blocks = (512 - 1 + le64_to_cpu(
507 pfindData->AllocationSize)) >> 9;
508 }
509
510 inode->i_nlink = le32_to_cpu(pfindData->NumberOfLinks);
511
512 /* BB fill in uid and gid here? with help from winbind?
513 or retrieve from NTFS stream extended attribute */
Steve French9e294f12005-11-17 16:59:21 -0800514 if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
515 /* fill in uid, gid, mode from server ACL */
516 get_sfu_uid_mode(inode, search_path, cifs_sb, xid);
517 } else if (atomic_read(&cifsInfo->inUse) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 inode->i_uid = cifs_sb->mnt_uid;
519 inode->i_gid = cifs_sb->mnt_gid;
520 /* set so we do not keep refreshing these fields with
521 bad data after user has changed them in memory */
522 atomic_set(&cifsInfo->inUse,1);
523 }
524
525 if (S_ISREG(inode->i_mode)) {
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800526 cFYI(1, ("File inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 inode->i_op = &cifs_file_inode_ops;
Steve French8b94bcb2005-11-11 11:41:00 -0800528 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
529 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
530 inode->i_fop =
531 &cifs_file_direct_nobrl_ops;
532 else
533 inode->i_fop = &cifs_file_direct_ops;
534 } else if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
535 inode->i_fop = &cifs_file_nobrl_ops;
536 else /* not direct, send byte range locks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 inode->i_fop = &cifs_file_ops;
Steve French8b94bcb2005-11-11 11:41:00 -0800538
Steve Frenchbfa0d752005-08-31 21:50:37 -0700539 if(pTcon->ses->server->maxBuf <
Dave Kleikamp273d81d2006-06-01 19:41:23 +0000540 PAGE_CACHE_SIZE + MAX_CIFS_HDR_SIZE)
541 inode->i_data.a_ops = &cifs_addr_ops_smallbuf;
542 else
543 inode->i_data.a_ops = &cifs_addr_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 } else if (S_ISDIR(inode->i_mode)) {
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800545 cFYI(1, ("Directory inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 inode->i_op = &cifs_dir_inode_ops;
547 inode->i_fop = &cifs_dir_ops;
548 } else if (S_ISLNK(inode->i_mode)) {
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800549 cFYI(1, ("Symbolic Link inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 inode->i_op = &cifs_symlink_inode_ops;
551 } else {
552 init_special_inode(inode, inode->i_mode,
553 inode->i_rdev);
554 }
555 }
556 kfree(buf);
557 return rc;
558}
559
560/* gets root inode */
561void cifs_read_inode(struct inode *inode)
562{
563 int xid;
564 struct cifs_sb_info *cifs_sb;
565
566 cifs_sb = CIFS_SB(inode->i_sb);
567 xid = GetXid();
568 if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
569 cifs_get_inode_info_unix(&inode, "", inode->i_sb,xid);
570 else
571 cifs_get_inode_info(&inode, "", NULL, inode->i_sb,xid);
572 /* can not call macro FreeXid here since in a void func */
573 _FreeXid(xid);
574}
575
576int cifs_unlink(struct inode *inode, struct dentry *direntry)
577{
578 int rc = 0;
579 int xid;
580 struct cifs_sb_info *cifs_sb;
581 struct cifsTconInfo *pTcon;
582 char *full_path = NULL;
583 struct cifsInodeInfo *cifsInode;
584 FILE_BASIC_INFO *pinfo_buf;
585
Steve French06bcfed2006-03-31 22:43:50 +0000586 cFYI(1, ("cifs_unlink, inode = 0x%p", inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 xid = GetXid();
589
Steve French6910ab32006-03-31 03:37:08 +0000590 if(inode)
591 cifs_sb = CIFS_SB(inode->i_sb);
592 else
Steve French06bcfed2006-03-31 22:43:50 +0000593 cifs_sb = CIFS_SB(direntry->d_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 pTcon = cifs_sb->tcon;
595
596 /* Unlink can be called from rename so we can not grab the sem here
597 since we deadlock otherwise */
Arjan van de Vena11f3a02006-03-23 03:00:33 -0800598/* mutex_lock(&direntry->d_sb->s_vfs_rename_mutex);*/
Steve French7f573562005-08-30 11:32:14 -0700599 full_path = build_path_from_dentry(direntry);
Arjan van de Vena11f3a02006-03-23 03:00:33 -0800600/* mutex_unlock(&direntry->d_sb->s_vfs_rename_mutex);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 if (full_path == NULL) {
602 FreeXid(xid);
603 return -ENOMEM;
604 }
Steve French737b7582005-04-28 22:41:06 -0700605 rc = CIFSSMBDelFile(xid, pTcon, full_path, cifs_sb->local_nls,
606 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
608 if (!rc) {
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700609 if (direntry->d_inode)
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700610 drop_nlink(direntry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 } else if (rc == -ENOENT) {
612 d_drop(direntry);
613 } else if (rc == -ETXTBSY) {
614 int oplock = FALSE;
615 __u16 netfid;
616
617 rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN, DELETE,
618 CREATE_NOT_DIR | CREATE_DELETE_ON_CLOSE,
Steve French737b7582005-04-28 22:41:06 -0700619 &netfid, &oplock, NULL, cifs_sb->local_nls,
620 cifs_sb->mnt_cifs_flags &
621 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 if (rc==0) {
623 CIFSSMBRenameOpenFile(xid, pTcon, netfid, NULL,
Steve French737b7582005-04-28 22:41:06 -0700624 cifs_sb->local_nls,
625 cifs_sb->mnt_cifs_flags &
626 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 CIFSSMBClose(xid, pTcon, netfid);
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700628 if (direntry->d_inode)
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700629 drop_nlink(direntry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 }
631 } else if (rc == -EACCES) {
632 /* try only if r/o attribute set in local lookup data? */
Eric Sesterhenna048d7a2006-02-21 22:33:09 +0000633 pinfo_buf = kzalloc(sizeof(FILE_BASIC_INFO), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 if (pinfo_buf) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 /* ATTRS set to normal clears r/o bit */
636 pinfo_buf->Attributes = cpu_to_le32(ATTR_NORMAL);
637 if (!(pTcon->ses->flags & CIFS_SES_NT4))
638 rc = CIFSSMBSetTimes(xid, pTcon, full_path,
639 pinfo_buf,
Steve French737b7582005-04-28 22:41:06 -0700640 cifs_sb->local_nls,
641 cifs_sb->mnt_cifs_flags &
642 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 else
644 rc = -EOPNOTSUPP;
645
646 if (rc == -EOPNOTSUPP) {
647 int oplock = FALSE;
648 __u16 netfid;
649 /* rc = CIFSSMBSetAttrLegacy(xid, pTcon,
650 full_path,
651 (__u16)ATTR_NORMAL,
652 cifs_sb->local_nls);
653 For some strange reason it seems that NT4 eats the
654 old setattr call without actually setting the
655 attributes so on to the third attempted workaround
656 */
657
658 /* BB could scan to see if we already have it open
659 and pass in pid of opener to function */
660 rc = CIFSSMBOpen(xid, pTcon, full_path,
661 FILE_OPEN, SYNCHRONIZE |
662 FILE_WRITE_ATTRIBUTES, 0,
663 &netfid, &oplock, NULL,
Steve French737b7582005-04-28 22:41:06 -0700664 cifs_sb->local_nls,
665 cifs_sb->mnt_cifs_flags &
666 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 if (rc==0) {
668 rc = CIFSSMBSetFileTimes(xid, pTcon,
669 pinfo_buf,
670 netfid);
671 CIFSSMBClose(xid, pTcon, netfid);
672 }
673 }
674 kfree(pinfo_buf);
675 }
676 if (rc==0) {
Steve French737b7582005-04-28 22:41:06 -0700677 rc = CIFSSMBDelFile(xid, pTcon, full_path,
678 cifs_sb->local_nls,
679 cifs_sb->mnt_cifs_flags &
680 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 if (!rc) {
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700682 if (direntry->d_inode)
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700683 drop_nlink(direntry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 } else if (rc == -ETXTBSY) {
685 int oplock = FALSE;
686 __u16 netfid;
687
688 rc = CIFSSMBOpen(xid, pTcon, full_path,
689 FILE_OPEN, DELETE,
690 CREATE_NOT_DIR |
691 CREATE_DELETE_ON_CLOSE,
692 &netfid, &oplock, NULL,
Steve French737b7582005-04-28 22:41:06 -0700693 cifs_sb->local_nls,
694 cifs_sb->mnt_cifs_flags &
695 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 if (rc==0) {
697 CIFSSMBRenameOpenFile(xid, pTcon,
698 netfid, NULL,
Steve French737b7582005-04-28 22:41:06 -0700699 cifs_sb->local_nls,
700 cifs_sb->mnt_cifs_flags &
701 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 CIFSSMBClose(xid, pTcon, netfid);
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700703 if (direntry->d_inode)
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700704 drop_nlink(direntry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 }
706 /* BB if rc = -ETXTBUSY goto the rename logic BB */
707 }
708 }
709 }
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700710 if (direntry->d_inode) {
Steve Frenchb2aeb9d2005-05-17 13:16:18 -0500711 cifsInode = CIFS_I(direntry->d_inode);
712 cifsInode->time = 0; /* will force revalidate to get info
713 when needed */
714 direntry->d_inode->i_ctime = current_fs_time(inode->i_sb);
715 }
Steve French06bcfed2006-03-31 22:43:50 +0000716 if(inode) {
717 inode->i_ctime = inode->i_mtime = current_fs_time(inode->i_sb);
718 cifsInode = CIFS_I(inode);
719 cifsInode->time = 0; /* force revalidate of dir as well */
720 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
722 kfree(full_path);
723 FreeXid(xid);
724 return rc;
725}
726
727int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
728{
729 int rc = 0;
730 int xid;
731 struct cifs_sb_info *cifs_sb;
732 struct cifsTconInfo *pTcon;
733 char *full_path = NULL;
734 struct inode *newinode = NULL;
735
Steve French6473a552005-11-29 20:20:10 -0800736 cFYI(1, ("In cifs_mkdir, mode = 0x%x inode = 0x%p", mode, inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 xid = GetXid();
739
740 cifs_sb = CIFS_SB(inode->i_sb);
741 pTcon = cifs_sb->tcon;
742
Steve French7f573562005-08-30 11:32:14 -0700743 full_path = build_path_from_dentry(direntry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 if (full_path == NULL) {
745 FreeXid(xid);
746 return -ENOMEM;
747 }
748 /* BB add setting the equivalent of mode via CreateX w/ACLs */
Steve French737b7582005-04-28 22:41:06 -0700749 rc = CIFSSMBMkDir(xid, pTcon, full_path, cifs_sb->local_nls,
750 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 if (rc) {
Steve French26a21b92006-05-31 18:05:34 +0000752 cFYI(1, ("cifs_mkdir returned 0x%x", rc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 d_drop(direntry);
754 } else {
Dave Hansend8c76e62006-09-30 23:29:04 -0700755 inc_nlink(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 if (pTcon->ses->capabilities & CAP_UNIX)
757 rc = cifs_get_inode_info_unix(&newinode, full_path,
758 inode->i_sb,xid);
759 else
760 rc = cifs_get_inode_info(&newinode, full_path, NULL,
761 inode->i_sb,xid);
762
Steve Frenchb92327f2005-08-22 20:09:43 -0700763 if (pTcon->nocase)
764 direntry->d_op = &cifs_ci_dentry_ops;
765 else
766 direntry->d_op = &cifs_dentry_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 d_instantiate(direntry, newinode);
768 if (direntry->d_inode)
769 direntry->d_inode->i_nlink = 2;
770 if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700771 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 CIFSSMBUnixSetPerms(xid, pTcon, full_path,
773 mode,
Steve French83451872005-12-01 17:12:59 -0800774 (__u64)current->fsuid,
775 (__u64)current->fsgid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 0 /* dev_t */,
Steve French737b7582005-04-28 22:41:06 -0700777 cifs_sb->local_nls,
778 cifs_sb->mnt_cifs_flags &
779 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 } else {
781 CIFSSMBUnixSetPerms(xid, pTcon, full_path,
782 mode, (__u64)-1,
783 (__u64)-1, 0 /* dev_t */,
Steve French737b7582005-04-28 22:41:06 -0700784 cifs_sb->local_nls,
785 cifs_sb->mnt_cifs_flags &
786 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 }
788 else {
789 /* BB to be implemented via Windows secrty descriptors
790 eg CIFSSMBWinSetPerms(xid, pTcon, full_path, mode,
791 -1, -1, local_nls); */
Steve French6473a552005-11-29 20:20:10 -0800792 if(direntry->d_inode) {
793 direntry->d_inode->i_mode = mode;
Steve French25741b32005-11-29 22:38:43 -0800794 direntry->d_inode->i_mode |= S_IFDIR;
Steve French6473a552005-11-29 20:20:10 -0800795 if(cifs_sb->mnt_cifs_flags &
796 CIFS_MOUNT_SET_UID) {
797 direntry->d_inode->i_uid =
798 current->fsuid;
799 direntry->d_inode->i_gid =
800 current->fsgid;
801 }
802 }
Steve French2a138ebb2005-11-29 21:22:19 -0800803 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 }
805 kfree(full_path);
806 FreeXid(xid);
807 return rc;
808}
809
810int cifs_rmdir(struct inode *inode, struct dentry *direntry)
811{
812 int rc = 0;
813 int xid;
814 struct cifs_sb_info *cifs_sb;
815 struct cifsTconInfo *pTcon;
816 char *full_path = NULL;
817 struct cifsInodeInfo *cifsInode;
818
Steve French26a21b92006-05-31 18:05:34 +0000819 cFYI(1, ("cifs_rmdir, inode = 0x%p", inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
821 xid = GetXid();
822
823 cifs_sb = CIFS_SB(inode->i_sb);
824 pTcon = cifs_sb->tcon;
825
Steve French7f573562005-08-30 11:32:14 -0700826 full_path = build_path_from_dentry(direntry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 if (full_path == NULL) {
828 FreeXid(xid);
829 return -ENOMEM;
830 }
831
Steve French737b7582005-04-28 22:41:06 -0700832 rc = CIFSSMBRmDir(xid, pTcon, full_path, cifs_sb->local_nls,
833 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
835 if (!rc) {
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700836 drop_nlink(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 i_size_write(direntry->d_inode,0);
Dave Hansence71ec32006-09-30 23:29:06 -0700838 clear_nlink(direntry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 }
840
841 cifsInode = CIFS_I(direntry->d_inode);
842 cifsInode->time = 0; /* force revalidate to go get info when
843 needed */
844 direntry->d_inode->i_ctime = inode->i_ctime = inode->i_mtime =
845 current_fs_time(inode->i_sb);
846
847 kfree(full_path);
848 FreeXid(xid);
849 return rc;
850}
851
852int cifs_rename(struct inode *source_inode, struct dentry *source_direntry,
853 struct inode *target_inode, struct dentry *target_direntry)
854{
855 char *fromName;
856 char *toName;
857 struct cifs_sb_info *cifs_sb_source;
858 struct cifs_sb_info *cifs_sb_target;
859 struct cifsTconInfo *pTcon;
860 int xid;
861 int rc = 0;
862
863 xid = GetXid();
864
865 cifs_sb_target = CIFS_SB(target_inode->i_sb);
866 cifs_sb_source = CIFS_SB(source_inode->i_sb);
867 pTcon = cifs_sb_source->tcon;
868
869 if (pTcon != cifs_sb_target->tcon) {
870 FreeXid(xid);
871 return -EXDEV; /* BB actually could be allowed if same server,
872 but different share.
873 Might eventually add support for this */
874 }
875
876 /* we already have the rename sem so we do not need to grab it again
877 here to protect the path integrity */
Steve French7f573562005-08-30 11:32:14 -0700878 fromName = build_path_from_dentry(source_direntry);
879 toName = build_path_from_dentry(target_direntry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 if ((fromName == NULL) || (toName == NULL)) {
881 rc = -ENOMEM;
882 goto cifs_rename_exit;
883 }
884
885 rc = CIFSSMBRename(xid, pTcon, fromName, toName,
Steve French737b7582005-04-28 22:41:06 -0700886 cifs_sb_source->local_nls,
887 cifs_sb_source->mnt_cifs_flags &
888 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 if (rc == -EEXIST) {
890 /* check if they are the same file because rename of hardlinked
891 files is a noop */
892 FILE_UNIX_BASIC_INFO *info_buf_source;
893 FILE_UNIX_BASIC_INFO *info_buf_target;
894
895 info_buf_source =
896 kmalloc(2 * sizeof(FILE_UNIX_BASIC_INFO), GFP_KERNEL);
897 if (info_buf_source != NULL) {
898 info_buf_target = info_buf_source + 1;
Steve French8e87d4d2006-11-02 03:45:24 +0000899 if (pTcon->ses->capabilities & CAP_UNIX)
900 rc = CIFSSMBUnixQPathInfo(xid, pTcon, fromName,
901 info_buf_source,
902 cifs_sb_source->local_nls,
903 cifs_sb_source->mnt_cifs_flags &
904 CIFS_MOUNT_MAP_SPECIAL_CHR);
905 /* else rc is still EEXIST so will fall through to
906 unlink the target and retry rename */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 if (rc == 0) {
908 rc = CIFSSMBUnixQPathInfo(xid, pTcon, toName,
909 info_buf_target,
Steve French737b7582005-04-28 22:41:06 -0700910 cifs_sb_target->local_nls,
911 /* remap based on source sb */
912 cifs_sb_source->mnt_cifs_flags &
913 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 }
915 if ((rc == 0) &&
916 (info_buf_source->UniqueId ==
917 info_buf_target->UniqueId)) {
918 /* do not rename since the files are hardlinked which
919 is a noop */
920 } else {
921 /* we either can not tell the files are hardlinked
922 (as with Windows servers) or files are not
923 hardlinked so delete the target manually before
924 renaming to follow POSIX rather than Windows
925 semantics */
926 cifs_unlink(target_inode, target_direntry);
927 rc = CIFSSMBRename(xid, pTcon, fromName,
928 toName,
Steve French737b7582005-04-28 22:41:06 -0700929 cifs_sb_source->local_nls,
930 cifs_sb_source->mnt_cifs_flags
931 & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 }
933 kfree(info_buf_source);
934 } /* if we can not get memory just leave rc as EEXIST */
935 }
936
937 if (rc) {
938 cFYI(1, ("rename rc %d", rc));
939 }
940
941 if ((rc == -EIO) || (rc == -EEXIST)) {
942 int oplock = FALSE;
943 __u16 netfid;
944
945 /* BB FIXME Is Generic Read correct for rename? */
946 /* if renaming directory - we should not say CREATE_NOT_DIR,
947 need to test renaming open directory, also GENERIC_READ
948 might not right be right access to request */
949 rc = CIFSSMBOpen(xid, pTcon, fromName, FILE_OPEN, GENERIC_READ,
950 CREATE_NOT_DIR, &netfid, &oplock, NULL,
Steve French737b7582005-04-28 22:41:06 -0700951 cifs_sb_source->local_nls,
952 cifs_sb_source->mnt_cifs_flags &
953 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 if (rc==0) {
Steve French8e87d4d2006-11-02 03:45:24 +0000955 rc = CIFSSMBRenameOpenFile(xid, pTcon, netfid, toName,
Steve French737b7582005-04-28 22:41:06 -0700956 cifs_sb_source->local_nls,
957 cifs_sb_source->mnt_cifs_flags &
958 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 CIFSSMBClose(xid, pTcon, netfid);
960 }
961 }
962
963cifs_rename_exit:
964 kfree(fromName);
965 kfree(toName);
966 FreeXid(xid);
967 return rc;
968}
969
970int cifs_revalidate(struct dentry *direntry)
971{
972 int xid;
973 int rc = 0;
974 char *full_path;
975 struct cifs_sb_info *cifs_sb;
976 struct cifsInodeInfo *cifsInode;
977 loff_t local_size;
978 struct timespec local_mtime;
979 int invalidate_inode = FALSE;
980
981 if (direntry->d_inode == NULL)
982 return -ENOENT;
983
984 cifsInode = CIFS_I(direntry->d_inode);
985
986 if (cifsInode == NULL)
987 return -ENOENT;
988
989 /* no sense revalidating inode info on file that no one can write */
990 if (CIFS_I(direntry->d_inode)->clientCanCacheRead)
991 return rc;
992
993 xid = GetXid();
994
995 cifs_sb = CIFS_SB(direntry->d_sb);
996
997 /* can not safely grab the rename sem here if rename calls revalidate
998 since that would deadlock */
Steve French7f573562005-08-30 11:32:14 -0700999 full_path = build_path_from_dentry(direntry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 if (full_path == NULL) {
1001 FreeXid(xid);
1002 return -ENOMEM;
1003 }
1004 cFYI(1, ("Revalidate: %s inode 0x%p count %d dentry: 0x%p d_time %ld "
1005 "jiffies %ld", full_path, direntry->d_inode,
1006 direntry->d_inode->i_count.counter, direntry,
1007 direntry->d_time, jiffies));
1008
1009 if (cifsInode->time == 0) {
1010 /* was set to zero previously to force revalidate */
1011 } else if (time_before(jiffies, cifsInode->time + HZ) &&
1012 lookupCacheEnabled) {
1013 if ((S_ISREG(direntry->d_inode->i_mode) == 0) ||
1014 (direntry->d_inode->i_nlink == 1)) {
1015 kfree(full_path);
1016 FreeXid(xid);
1017 return rc;
1018 } else {
1019 cFYI(1, ("Have to revalidate file due to hardlinks"));
1020 }
1021 }
1022
1023 /* save mtime and size */
1024 local_mtime = direntry->d_inode->i_mtime;
1025 local_size = direntry->d_inode->i_size;
1026
1027 if (cifs_sb->tcon->ses->capabilities & CAP_UNIX) {
1028 rc = cifs_get_inode_info_unix(&direntry->d_inode, full_path,
1029 direntry->d_sb,xid);
1030 if (rc) {
1031 cFYI(1, ("error on getting revalidate info %d", rc));
1032/* if (rc != -ENOENT)
1033 rc = 0; */ /* BB should we cache info on
1034 certain errors? */
1035 }
1036 } else {
1037 rc = cifs_get_inode_info(&direntry->d_inode, full_path, NULL,
1038 direntry->d_sb,xid);
1039 if (rc) {
1040 cFYI(1, ("error on getting revalidate info %d", rc));
1041/* if (rc != -ENOENT)
1042 rc = 0; */ /* BB should we cache info on
1043 certain errors? */
1044 }
1045 }
1046 /* should we remap certain errors, access denied?, to zero */
1047
1048 /* if not oplocked, we invalidate inode pages if mtime or file size
1049 had changed on server */
1050
1051 if (timespec_equal(&local_mtime,&direntry->d_inode->i_mtime) &&
1052 (local_size == direntry->d_inode->i_size)) {
1053 cFYI(1, ("cifs_revalidate - inode unchanged"));
1054 } else {
1055 /* file may have changed on server */
1056 if (cifsInode->clientCanCacheRead) {
1057 /* no need to invalidate inode pages since we were the
1058 only ones who could have modified the file and the
1059 server copy is staler than ours */
1060 } else {
1061 invalidate_inode = TRUE;
1062 }
1063 }
1064
1065 /* can not grab this sem since kernel filesys locking documentation
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08001066 indicates i_mutex may be taken by the kernel on lookup and rename
1067 which could deadlock if we grab the i_mutex here as well */
1068/* mutex_lock(&direntry->d_inode->i_mutex);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 /* need to write out dirty pages here */
1070 if (direntry->d_inode->i_mapping) {
1071 /* do we need to lock inode until after invalidate completes
1072 below? */
1073 filemap_fdatawrite(direntry->d_inode->i_mapping);
1074 }
1075 if (invalidate_inode) {
Steve French3abb9272005-11-28 08:16:13 -08001076 /* shrink_dcache not necessary now that cifs dentry ops
1077 are exported for negative dentries */
1078/* if(S_ISDIR(direntry->d_inode->i_mode))
1079 shrink_dcache_parent(direntry); */
1080 if (S_ISREG(direntry->d_inode->i_mode)) {
1081 if (direntry->d_inode->i_mapping)
1082 filemap_fdatawait(direntry->d_inode->i_mapping);
1083 /* may eventually have to do this for open files too */
1084 if (list_empty(&(cifsInode->openFileList))) {
1085 /* changed on server - flush read ahead pages */
1086 cFYI(1, ("Invalidating read ahead data on "
1087 "closed file"));
1088 invalidate_remote_inode(direntry->d_inode);
1089 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 }
1091 }
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08001092/* mutex_unlock(&direntry->d_inode->i_mutex); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
1094 kfree(full_path);
1095 FreeXid(xid);
1096 return rc;
1097}
1098
1099int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1100 struct kstat *stat)
1101{
1102 int err = cifs_revalidate(dentry);
Steve French5fe14c82006-11-07 19:26:33 +00001103 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 generic_fillattr(dentry->d_inode, stat);
Steve French5fe14c82006-11-07 19:26:33 +00001105 stat->blksize = CIFS_MAX_MSGSIZE;
1106 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 return err;
1108}
1109
1110static int cifs_truncate_page(struct address_space *mapping, loff_t from)
1111{
1112 pgoff_t index = from >> PAGE_CACHE_SHIFT;
1113 unsigned offset = from & (PAGE_CACHE_SIZE - 1);
1114 struct page *page;
1115 char *kaddr;
1116 int rc = 0;
1117
1118 page = grab_cache_page(mapping, index);
1119 if (!page)
1120 return -ENOMEM;
1121
1122 kaddr = kmap_atomic(page, KM_USER0);
1123 memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset);
1124 flush_dcache_page(page);
1125 kunmap_atomic(kaddr, KM_USER0);
1126 unlock_page(page);
1127 page_cache_release(page);
1128 return rc;
1129}
1130
1131int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
1132{
1133 int xid;
1134 struct cifs_sb_info *cifs_sb;
1135 struct cifsTconInfo *pTcon;
1136 char *full_path = NULL;
1137 int rc = -EACCES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 struct cifsFileInfo *open_file = NULL;
1139 FILE_BASIC_INFO time_buf;
1140 int set_time = FALSE;
1141 __u64 mode = 0xFFFFFFFFFFFFFFFFULL;
1142 __u64 uid = 0xFFFFFFFFFFFFFFFFULL;
1143 __u64 gid = 0xFFFFFFFFFFFFFFFFULL;
1144 struct cifsInodeInfo *cifsInode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146 xid = GetXid();
1147
Steve French39798772006-05-31 22:40:51 +00001148 cFYI(1, ("setattr on file %s attrs->iavalid 0x%x",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 direntry->d_name.name, attrs->ia_valid));
Steve French6473a552005-11-29 20:20:10 -08001150
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 cifs_sb = CIFS_SB(direntry->d_inode->i_sb);
1152 pTcon = cifs_sb->tcon;
1153
Steve French2a138ebb2005-11-29 21:22:19 -08001154 if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) == 0) {
Steve French6473a552005-11-29 20:20:10 -08001155 /* check if we have permission to change attrs */
1156 rc = inode_change_ok(direntry->d_inode, attrs);
1157 if(rc < 0) {
1158 FreeXid(xid);
1159 return rc;
1160 } else
1161 rc = 0;
1162 }
1163
Steve French7f573562005-08-30 11:32:14 -07001164 full_path = build_path_from_dentry(direntry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 if (full_path == NULL) {
1166 FreeXid(xid);
1167 return -ENOMEM;
1168 }
1169 cifsInode = CIFS_I(direntry->d_inode);
1170
1171 /* BB check if we need to refresh inode from server now ? BB */
1172
1173 /* need to flush data before changing file size on server */
OGAWA Hirofumi28fd1292006-01-08 01:02:14 -08001174 filemap_write_and_wait(direntry->d_inode->i_mapping);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
1176 if (attrs->ia_valid & ATTR_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 /* To avoid spurious oplock breaks from server, in the case of
1178 inodes that we already have open, avoid doing path based
1179 setting of file size if we can do it by handle.
1180 This keeps our caching token (oplock) and avoids timeouts
1181 when the local oplock break takes longer to flush
1182 writebehind data than the SMB timeout for the SetPathInfo
1183 request would allow */
Steve French39798772006-05-31 22:40:51 +00001184
Steve French6148a742005-10-05 12:23:19 -07001185 open_file = find_writable_file(cifsInode);
1186 if (open_file) {
1187 __u16 nfid = open_file->netfid;
1188 __u32 npid = open_file->pid;
1189 rc = CIFSSMBSetFileSize(xid, pTcon, attrs->ia_size,
1190 nfid, npid, FALSE);
Steve French23e7dd72005-10-20 13:44:56 -07001191 atomic_dec(&open_file->wrtPending);
Steve French6148a742005-10-05 12:23:19 -07001192 cFYI(1,("SetFSize for attrs rc = %d", rc));
Steve French083d3a22006-03-03 09:53:36 +00001193 if((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
Steve French6148a742005-10-05 12:23:19 -07001194 int bytes_written;
1195 rc = CIFSSMBWrite(xid, pTcon,
1196 nfid, 0, attrs->ia_size,
1197 &bytes_written, NULL, NULL,
1198 1 /* 45 seconds */);
1199 cFYI(1,("Wrt seteof rc %d", rc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 }
Steve French6473a552005-11-29 20:20:10 -08001201 } else
1202 rc = -EINVAL;
1203
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 if (rc != 0) {
1205 /* Set file size by pathname rather than by handle
1206 either because no valid, writeable file handle for
1207 it was found or because there was an error setting
1208 it by handle */
1209 rc = CIFSSMBSetEOF(xid, pTcon, full_path,
1210 attrs->ia_size, FALSE,
Steve French737b7582005-04-28 22:41:06 -07001211 cifs_sb->local_nls,
1212 cifs_sb->mnt_cifs_flags &
1213 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve Frenche30dcf32005-09-20 20:49:16 -07001214 cFYI(1, ("SetEOF by path (setattrs) rc = %d", rc));
Steve French083d3a22006-03-03 09:53:36 +00001215 if((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
Steve Frenche30dcf32005-09-20 20:49:16 -07001216 __u16 netfid;
1217 int oplock = FALSE;
1218
1219 rc = SMBLegacyOpen(xid, pTcon, full_path,
1220 FILE_OPEN,
1221 SYNCHRONIZE | FILE_WRITE_ATTRIBUTES,
1222 CREATE_NOT_DIR, &netfid, &oplock,
1223 NULL, cifs_sb->local_nls,
1224 cifs_sb->mnt_cifs_flags &
1225 CIFS_MOUNT_MAP_SPECIAL_CHR);
1226 if (rc==0) {
1227 int bytes_written;
1228 rc = CIFSSMBWrite(xid, pTcon,
1229 netfid, 0,
1230 attrs->ia_size,
1231 &bytes_written, NULL,
1232 NULL, 1 /* 45 sec */);
1233 cFYI(1,("wrt seteof rc %d",rc));
1234 CIFSSMBClose(xid, pTcon, netfid);
1235 }
1236
1237 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 }
1239
1240 /* Server is ok setting allocation size implicitly - no need
1241 to call:
1242 CIFSSMBSetEOF(xid, pTcon, full_path, attrs->ia_size, TRUE,
1243 cifs_sb->local_nls);
1244 */
1245
1246 if (rc == 0) {
1247 rc = vmtruncate(direntry->d_inode, attrs->ia_size);
1248 cifs_truncate_page(direntry->d_inode->i_mapping,
1249 direntry->d_inode->i_size);
Steve Frenche30dcf32005-09-20 20:49:16 -07001250 } else
1251 goto cifs_setattr_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 }
1253 if (attrs->ia_valid & ATTR_UID) {
Steve Frenche30dcf32005-09-20 20:49:16 -07001254 cFYI(1, ("UID changed to %d", attrs->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 uid = attrs->ia_uid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 }
1257 if (attrs->ia_valid & ATTR_GID) {
Steve Frenche30dcf32005-09-20 20:49:16 -07001258 cFYI(1, ("GID changed to %d", attrs->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 gid = attrs->ia_gid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 }
1261
1262 time_buf.Attributes = 0;
1263 if (attrs->ia_valid & ATTR_MODE) {
Steve Frenche30dcf32005-09-20 20:49:16 -07001264 cFYI(1, ("Mode changed to 0x%x", attrs->ia_mode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 mode = attrs->ia_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 }
1267
1268 if ((cifs_sb->tcon->ses->capabilities & CAP_UNIX)
1269 && (attrs->ia_valid & (ATTR_MODE | ATTR_GID | ATTR_UID)))
1270 rc = CIFSSMBUnixSetPerms(xid, pTcon, full_path, mode, uid, gid,
Steve French737b7582005-04-28 22:41:06 -07001271 0 /* dev_t */, cifs_sb->local_nls,
1272 cifs_sb->mnt_cifs_flags &
1273 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 else if (attrs->ia_valid & ATTR_MODE) {
Steve Frenchcdbce9c2005-11-19 21:04:52 -08001275 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 if ((mode & S_IWUGO) == 0) /* not writeable */ {
1277 if ((cifsInode->cifsAttrs & ATTR_READONLY) == 0)
1278 time_buf.Attributes =
1279 cpu_to_le32(cifsInode->cifsAttrs |
1280 ATTR_READONLY);
1281 } else if ((mode & S_IWUGO) == S_IWUGO) {
1282 if (cifsInode->cifsAttrs & ATTR_READONLY)
1283 time_buf.Attributes =
1284 cpu_to_le32(cifsInode->cifsAttrs &
1285 (~ATTR_READONLY));
1286 }
1287 /* BB to be implemented -
1288 via Windows security descriptors or streams */
1289 /* CIFSSMBWinSetPerms(xid, pTcon, full_path, mode, uid, gid,
1290 cifs_sb->local_nls); */
1291 }
1292
1293 if (attrs->ia_valid & ATTR_ATIME) {
1294 set_time = TRUE;
1295 time_buf.LastAccessTime =
1296 cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_atime));
1297 } else
1298 time_buf.LastAccessTime = 0;
1299
1300 if (attrs->ia_valid & ATTR_MTIME) {
1301 set_time = TRUE;
1302 time_buf.LastWriteTime =
1303 cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_mtime));
1304 } else
1305 time_buf.LastWriteTime = 0;
Steve Frenche30dcf32005-09-20 20:49:16 -07001306 /* Do not set ctime explicitly unless other time
1307 stamps are changed explicitly (i.e. by utime()
1308 since we would then have a mix of client and
1309 server times */
1310
1311 if (set_time && (attrs->ia_valid & ATTR_CTIME)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 set_time = TRUE;
Steve Frenche30dcf32005-09-20 20:49:16 -07001313 /* Although Samba throws this field away
1314 it may be useful to Windows - but we do
1315 not want to set ctime unless some other
1316 timestamp is changing */
Steve French26a21b92006-05-31 18:05:34 +00001317 cFYI(1, ("CIFS - CTIME changed"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 time_buf.ChangeTime =
1319 cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_ctime));
1320 } else
1321 time_buf.ChangeTime = 0;
1322
1323 if (set_time || time_buf.Attributes) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 time_buf.CreationTime = 0; /* do not change */
1325 /* In the future we should experiment - try setting timestamps
1326 via Handle (SetFileInfo) instead of by path */
1327 if (!(pTcon->ses->flags & CIFS_SES_NT4))
1328 rc = CIFSSMBSetTimes(xid, pTcon, full_path, &time_buf,
Steve French737b7582005-04-28 22:41:06 -07001329 cifs_sb->local_nls,
1330 cifs_sb->mnt_cifs_flags &
1331 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 else
1333 rc = -EOPNOTSUPP;
1334
1335 if (rc == -EOPNOTSUPP) {
1336 int oplock = FALSE;
1337 __u16 netfid;
1338
1339 cFYI(1, ("calling SetFileInfo since SetPathInfo for "
1340 "times not supported by this server"));
1341 /* BB we could scan to see if we already have it open
1342 and pass in pid of opener to function */
1343 rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN,
1344 SYNCHRONIZE | FILE_WRITE_ATTRIBUTES,
1345 CREATE_NOT_DIR, &netfid, &oplock,
Steve French737b7582005-04-28 22:41:06 -07001346 NULL, cifs_sb->local_nls,
1347 cifs_sb->mnt_cifs_flags &
1348 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 if (rc==0) {
1350 rc = CIFSSMBSetFileTimes(xid, pTcon, &time_buf,
1351 netfid);
1352 CIFSSMBClose(xid, pTcon, netfid);
1353 } else {
1354 /* BB For even older servers we could convert time_buf
1355 into old DOS style which uses two second
1356 granularity */
1357
1358 /* rc = CIFSSMBSetTimesLegacy(xid, pTcon, full_path,
1359 &time_buf, cifs_sb->local_nls); */
1360 }
1361 }
Steve Frenche30dcf32005-09-20 20:49:16 -07001362 /* Even if error on time set, no sense failing the call if
1363 the server would set the time to a reasonable value anyway,
1364 and this check ensures that we are not being called from
1365 sys_utimes in which case we ought to fail the call back to
1366 the user when the server rejects the call */
Steve Frenchc14e8942007-02-15 01:33:18 +00001367 if((rc) && (attrs->ia_valid &
Steve Frenche30dcf32005-09-20 20:49:16 -07001368 (ATTR_MODE | ATTR_GID | ATTR_UID | ATTR_SIZE)))
1369 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 }
1371
1372 /* do not need local check to inode_check_ok since the server does
1373 that */
1374 if (!rc)
1375 rc = inode_setattr(direntry->d_inode, attrs);
Steve Frenche30dcf32005-09-20 20:49:16 -07001376cifs_setattr_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 kfree(full_path);
1378 FreeXid(xid);
1379 return rc;
1380}
1381
1382void cifs_delete_inode(struct inode *inode)
1383{
Steve French26a21b92006-05-31 18:05:34 +00001384 cFYI(1, ("In cifs_delete_inode, inode = 0x%p", inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 /* may have to add back in if and when safe distributed caching of
1386 directories added e.g. via FindNotify */
1387}