blob: c4fa91b8b62fb042c73df37f3a21ceadc3e840f9 [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 */
93 insert_inode_hash(*pinode);
94 }
95
96 inode = *pinode;
97 cifsInfo = CIFS_I(inode);
98
Steve French26a21b92006-05-31 18:05:34 +000099 cFYI(1, ("Old time %ld", cifsInfo->time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 cifsInfo->time = jiffies;
Steve French26a21b92006-05-31 18:05:34 +0000101 cFYI(1, ("New time %ld", cifsInfo->time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 /* this is ok to set on every inode revalidate */
103 atomic_set(&cifsInfo->inUse,1);
104
105 inode->i_atime =
106 cifs_NTtimeToUnix(le64_to_cpu(findData.LastAccessTime));
107 inode->i_mtime =
108 cifs_NTtimeToUnix(le64_to_cpu
109 (findData.LastModificationTime));
110 inode->i_ctime =
111 cifs_NTtimeToUnix(le64_to_cpu(findData.LastStatusChange));
112 inode->i_mode = le64_to_cpu(findData.Permissions);
Steve French3020a1f2005-11-18 11:31:10 -0800113 /* since we set the inode type below we need to mask off
114 to avoid strange results if bits set above */
115 inode->i_mode &= ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 if (type == UNIX_FILE) {
117 inode->i_mode |= S_IFREG;
118 } else if (type == UNIX_SYMLINK) {
119 inode->i_mode |= S_IFLNK;
120 } else if (type == UNIX_DIR) {
121 inode->i_mode |= S_IFDIR;
122 } else if (type == UNIX_CHARDEV) {
123 inode->i_mode |= S_IFCHR;
124 inode->i_rdev = MKDEV(le64_to_cpu(findData.DevMajor),
125 le64_to_cpu(findData.DevMinor) & MINORMASK);
126 } else if (type == UNIX_BLOCKDEV) {
127 inode->i_mode |= S_IFBLK;
128 inode->i_rdev = MKDEV(le64_to_cpu(findData.DevMajor),
129 le64_to_cpu(findData.DevMinor) & MINORMASK);
130 } else if (type == UNIX_FIFO) {
131 inode->i_mode |= S_IFIFO;
132 } else if (type == UNIX_SOCKET) {
133 inode->i_mode |= S_IFSOCK;
Steve French3020a1f2005-11-18 11:31:10 -0800134 } else {
135 /* safest to call it a file if we do not know */
136 inode->i_mode |= S_IFREG;
137 cFYI(1,("unknown type %d",type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 }
139 inode->i_uid = le64_to_cpu(findData.Uid);
140 inode->i_gid = le64_to_cpu(findData.Gid);
141 inode->i_nlink = le64_to_cpu(findData.Nlinks);
142
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700143 if (is_size_safe_to_change(cifsInfo)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 /* can not safely change the file size here if the
145 client is writing to it due to potential races */
146
147 i_size_write(inode, end_of_file);
148
149 /* blksize needs to be multiple of two. So safer to default to
150 blksize and blkbits set in superblock so 2**blkbits and blksize
151 will match rather than setting to:
152 (pTcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFE00;*/
153
154 /* This seems incredibly stupid but it turns out that i_blocks
155 is not related to (i_size / i_blksize), instead 512 byte size
156 is required for calculating num blocks */
157
158 /* 512 bytes (2**9) is the fake blocksize that must be used */
159 /* for this calculation */
160 inode->i_blocks = (512 - 1 + num_of_bytes) >> 9;
161 }
162
163 if (num_of_bytes < end_of_file)
Steve French8b94bcb2005-11-11 11:41:00 -0800164 cFYI(1, ("allocation size less than end of file"));
Andrew Morton5515eff2006-03-26 01:37:53 -0800165 cFYI(1, ("Size %ld and blocks %llu",
166 (unsigned long) inode->i_size,
167 (unsigned long long)inode->i_blocks));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 if (S_ISREG(inode->i_mode)) {
Steve French8b94bcb2005-11-11 11:41:00 -0800169 cFYI(1, ("File inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 inode->i_op = &cifs_file_inode_ops;
Steve French8b94bcb2005-11-11 11:41:00 -0800171 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
172 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
173 inode->i_fop =
174 &cifs_file_direct_nobrl_ops;
175 else
176 inode->i_fop = &cifs_file_direct_ops;
177 } else if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
178 inode->i_fop = &cifs_file_nobrl_ops;
179 else /* not direct, send byte range locks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 inode->i_fop = &cifs_file_ops;
Steve French8b94bcb2005-11-11 11:41:00 -0800181
Steve Frenchbfa0d752005-08-31 21:50:37 -0700182 /* check if server can support readpages */
183 if(pTcon->ses->server->maxBuf <
Dave Kleikamp273d81d2006-06-01 19:41:23 +0000184 PAGE_CACHE_SIZE + MAX_CIFS_HDR_SIZE)
185 inode->i_data.a_ops = &cifs_addr_ops_smallbuf;
186 else
187 inode->i_data.a_ops = &cifs_addr_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 } else if (S_ISDIR(inode->i_mode)) {
Steve French8b94bcb2005-11-11 11:41:00 -0800189 cFYI(1, ("Directory inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 inode->i_op = &cifs_dir_inode_ops;
191 inode->i_fop = &cifs_dir_ops;
192 } else if (S_ISLNK(inode->i_mode)) {
Steve French8b94bcb2005-11-11 11:41:00 -0800193 cFYI(1, ("Symbolic Link inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 inode->i_op = &cifs_symlink_inode_ops;
195 /* tmp_inode->i_fop = */ /* do not need to set to anything */
196 } else {
Steve French8b94bcb2005-11-11 11:41:00 -0800197 cFYI(1, ("Init special inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 init_special_inode(inode, inode->i_mode,
199 inode->i_rdev);
200 }
201 }
202 return rc;
203}
204
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800205static int decode_sfu_inode(struct inode * inode, __u64 size,
206 const unsigned char *path,
207 struct cifs_sb_info *cifs_sb, int xid)
208{
209 int rc;
210 int oplock = FALSE;
211 __u16 netfid;
212 struct cifsTconInfo *pTcon = cifs_sb->tcon;
Steve French86c96b42005-11-18 20:25:31 -0800213 char buf[24];
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800214 unsigned int bytes_read;
215 char * pbuf;
216
217 pbuf = buf;
218
219 if(size == 0) {
220 inode->i_mode |= S_IFIFO;
221 return 0;
222 } else if (size < 8) {
223 return -EINVAL; /* EOPNOTSUPP? */
224 }
225
226 rc = CIFSSMBOpen(xid, pTcon, path, FILE_OPEN, GENERIC_READ,
227 CREATE_NOT_DIR, &netfid, &oplock, NULL,
228 cifs_sb->local_nls,
229 cifs_sb->mnt_cifs_flags &
230 CIFS_MOUNT_MAP_SPECIAL_CHR);
231 if (rc==0) {
Steve Frenchec637e32005-12-12 20:53:18 -0800232 int buf_type = CIFS_NO_BUFFER;
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800233 /* Read header */
234 rc = CIFSSMBRead(xid, pTcon,
235 netfid,
Steve French86c96b42005-11-18 20:25:31 -0800236 24 /* length */, 0 /* offset */,
Steve Frenchec637e32005-12-12 20:53:18 -0800237 &bytes_read, &pbuf, &buf_type);
Steve French86c96b42005-11-18 20:25:31 -0800238 if((rc == 0) && (bytes_read >= 8)) {
Steve French9e294f12005-11-17 16:59:21 -0800239 if(memcmp("IntxBLK", pbuf, 8) == 0) {
240 cFYI(1,("Block device"));
Steve French3020a1f2005-11-18 11:31:10 -0800241 inode->i_mode |= S_IFBLK;
Steve French86c96b42005-11-18 20:25:31 -0800242 if(bytes_read == 24) {
243 /* we have enough to decode dev num */
244 __u64 mjr; /* major */
245 __u64 mnr; /* minor */
246 mjr = le64_to_cpu(*(__le64 *)(pbuf+8));
247 mnr = le64_to_cpu(*(__le64 *)(pbuf+16));
248 inode->i_rdev = MKDEV(mjr, mnr);
249 }
Steve French9e294f12005-11-17 16:59:21 -0800250 } else if(memcmp("IntxCHR", pbuf, 8) == 0) {
251 cFYI(1,("Char device"));
Steve French3020a1f2005-11-18 11:31:10 -0800252 inode->i_mode |= S_IFCHR;
Steve French86c96b42005-11-18 20:25:31 -0800253 if(bytes_read == 24) {
254 /* we have enough to decode dev num */
255 __u64 mjr; /* major */
256 __u64 mnr; /* minor */
257 mjr = le64_to_cpu(*(__le64 *)(pbuf+8));
258 mnr = le64_to_cpu(*(__le64 *)(pbuf+16));
259 inode->i_rdev = MKDEV(mjr, mnr);
260 }
Steve French9e294f12005-11-17 16:59:21 -0800261 } else if(memcmp("IntxLNK", pbuf, 7) == 0) {
262 cFYI(1,("Symlink"));
Steve French3020a1f2005-11-18 11:31:10 -0800263 inode->i_mode |= S_IFLNK;
Steve French86c96b42005-11-18 20:25:31 -0800264 } else {
265 inode->i_mode |= S_IFREG; /* file? */
266 rc = -EOPNOTSUPP;
267 }
Steve French3020a1f2005-11-18 11:31:10 -0800268 } else {
269 inode->i_mode |= S_IFREG; /* then it is a file */
270 rc = -EOPNOTSUPP; /* or some unknown SFU type */
Steve Frenchec637e32005-12-12 20:53:18 -0800271 }
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800272 CIFSSMBClose(xid, pTcon, netfid);
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800273 }
274 return rc;
275
276}
277
Steve French9e294f12005-11-17 16:59:21 -0800278#define SFBITS_MASK (S_ISVTX | S_ISGID | S_ISUID) /* SETFILEBITS valid bits */
279
280static int get_sfu_uid_mode(struct inode * inode,
281 const unsigned char *path,
282 struct cifs_sb_info *cifs_sb, int xid)
283{
Steve French3020a1f2005-11-18 11:31:10 -0800284#ifdef CONFIG_CIFS_XATTR
Steve French9e294f12005-11-17 16:59:21 -0800285 ssize_t rc;
286 char ea_value[4];
287 __u32 mode;
288
289 rc = CIFSSMBQueryEA(xid, cifs_sb->tcon, path, "SETFILEBITS",
290 ea_value, 4 /* size of buf */, cifs_sb->local_nls,
291 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
292 if(rc < 0)
293 return (int)rc;
294 else if (rc > 3) {
295 mode = le32_to_cpu(*((__le32 *)ea_value));
Steve Frenchc119b872005-11-18 12:27:27 -0800296 inode->i_mode &= ~SFBITS_MASK;
Steve French3020a1f2005-11-18 11:31:10 -0800297 cFYI(1,("special bits 0%o org mode 0%o", mode, inode->i_mode));
Steve French9e294f12005-11-17 16:59:21 -0800298 inode->i_mode = (mode & SFBITS_MASK) | inode->i_mode;
299 cFYI(1,("special mode bits 0%o", mode));
300 return 0;
301 } else {
302 return 0;
303 }
Steve French3020a1f2005-11-18 11:31:10 -0800304#else
305 return -EOPNOTSUPP;
306#endif
307
Steve French9e294f12005-11-17 16:59:21 -0800308
309}
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311int cifs_get_inode_info(struct inode **pinode,
312 const unsigned char *search_path, FILE_ALL_INFO *pfindData,
313 struct super_block *sb, int xid)
314{
315 int rc = 0;
316 struct cifsTconInfo *pTcon;
317 struct inode *inode;
318 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
319 char *tmp_path;
320 char *buf = NULL;
Steve French8d6286f2006-11-16 22:48:25 +0000321 int adjustTZ = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323 pTcon = cifs_sb->tcon;
Steve Frenchd6e2f2a42005-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);
Steve French8d6286f2006-11-16 22:48:25 +0000352 adjustTZ = TRUE;
Steve French6b8edfe2005-08-23 20:26:03 -0700353 }
354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 }
356 /* dump_mem("\nQPathInfo return data",&findData, sizeof(findData)); */
357 if (rc) {
358 if (rc == -EREMOTE) {
359 tmp_path =
360 kmalloc(strnlen
361 (pTcon->treeName,
362 MAX_TREE_SIZE + 1) +
363 strnlen(search_path, MAX_PATHCONF) + 1,
364 GFP_KERNEL);
365 if (tmp_path == NULL) {
366 kfree(buf);
367 return -ENOMEM;
368 }
369
370 strncpy(tmp_path, pTcon->treeName, MAX_TREE_SIZE);
371 strncat(tmp_path, search_path, MAX_PATHCONF);
372 rc = connect_to_dfs_path(xid, pTcon->ses,
373 /* treename + */ tmp_path,
Steve French737b7582005-04-28 22:41:06 -0700374 cifs_sb->local_nls,
375 cifs_sb->mnt_cifs_flags &
376 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 kfree(tmp_path);
378 /* BB fix up inode etc. */
379 } else if (rc) {
380 kfree(buf);
381 return rc;
382 }
383 } else {
384 struct cifsInodeInfo *cifsInfo;
385 __u32 attr = le32_to_cpu(pfindData->Attributes);
386
387 /* get new inode */
388 if (*pinode == NULL) {
389 *pinode = new_inode(sb);
Steve Frenchacf1a1b2006-10-12 03:28:28 +0000390 if (*pinode == NULL) {
391 kfree(buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 return -ENOMEM;
Steve Frenchacf1a1b2006-10-12 03:28:28 +0000393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 /* Is an i_ino of zero legal? Can we use that to check
395 if the server supports returning inode numbers? Are
396 there other sanity checks we can use to ensure that
397 the server is really filling in that field? */
398
399 /* We can not use the IndexNumber field by default from
400 Windows or Samba (in ALL_INFO buf) but we can request
401 it explicitly. It may not be unique presumably if
402 the server has multiple devices mounted under one
403 share */
404
405 /* There may be higher info levels that work but are
406 there Windows server or network appliances for which
407 IndexNumber field is not guaranteed unique? */
408
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700409 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 int rc1 = 0;
411 __u64 inode_num;
412
413 rc1 = CIFSGetSrvInodeNumber(xid, pTcon,
414 search_path, &inode_num,
Steve French737b7582005-04-28 22:41:06 -0700415 cifs_sb->local_nls,
416 cifs_sb->mnt_cifs_flags &
417 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700418 if (rc1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 cFYI(1,("GetSrvInodeNum rc %d", rc1));
420 /* BB EOPNOSUPP disable SERVER_INUM? */
421 } else /* do we need cast or hash to ino? */
422 (*pinode)->i_ino = inode_num;
423 } /* else ino incremented to unique num in new_inode*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 insert_inode_hash(*pinode);
425 }
426 inode = *pinode;
427 cifsInfo = CIFS_I(inode);
428 cifsInfo->cifsAttrs = attr;
Steve French26a21b92006-05-31 18:05:34 +0000429 cFYI(1, ("Old time %ld", cifsInfo->time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 cifsInfo->time = jiffies;
Steve French26a21b92006-05-31 18:05:34 +0000431 cFYI(1, ("New time %ld", cifsInfo->time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433 /* blksize needs to be multiple of two. So safer to default to
434 blksize and blkbits set in superblock so 2**blkbits and blksize
435 will match rather than setting to:
436 (pTcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFE00;*/
437
Steve French26a21b92006-05-31 18:05:34 +0000438 /* Linux can not store file creation time so ignore it */
Steve French1bd5bbc2006-09-28 03:35:57 +0000439 if(pfindData->LastAccessTime)
440 inode->i_atime = cifs_NTtimeToUnix
441 (le64_to_cpu(pfindData->LastAccessTime));
442 else /* do not need to use current_fs_time - time not stored */
443 inode->i_atime = CURRENT_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 inode->i_mtime =
445 cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastWriteTime));
446 inode->i_ctime =
447 cifs_NTtimeToUnix(le64_to_cpu(pfindData->ChangeTime));
Steve French26a21b92006-05-31 18:05:34 +0000448 cFYI(0, ("Attributes came in as 0x%x", attr));
Steve French8d6286f2006-11-16 22:48:25 +0000449 if(adjustTZ && (pTcon->ses) && (pTcon->ses->server)) {
450 inode->i_ctime.tv_sec += pTcon->ses->server->timeAdj;
451 inode->i_mtime.tv_sec += pTcon->ses->server->timeAdj;
452 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
454 /* set default mode. will override for dirs below */
455 if (atomic_read(&cifsInfo->inUse) == 0)
456 /* new inode, can safely set these fields */
457 inode->i_mode = cifs_sb->mnt_file_mode;
Steve French3020a1f2005-11-18 11:31:10 -0800458 else /* since we set the inode type below we need to mask off
459 to avoid strange results if type changes and both get orred in */
460 inode->i_mode &= ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461/* if (attr & ATTR_REPARSE) */
462 /* We no longer handle these as symlinks because we could not
463 follow them due to the absolute path with drive letter */
464 if (attr & ATTR_DIRECTORY) {
465 /* override default perms since we do not do byte range locking
466 on dirs */
467 inode->i_mode = cifs_sb->mnt_dir_mode;
468 inode->i_mode |= S_IFDIR;
Steve Frencheda3c0292005-07-21 15:20:28 -0700469 } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) &&
470 (cifsInfo->cifsAttrs & ATTR_SYSTEM) &&
471 /* No need to le64 convert size of zero */
472 (pfindData->EndOfFile == 0)) {
473 inode->i_mode = cifs_sb->mnt_file_mode;
474 inode->i_mode |= S_IFIFO;
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800475/* BB Finish for SFU style symlinks and devices */
476 } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) &&
477 (cifsInfo->cifsAttrs & ATTR_SYSTEM)) {
478 if (decode_sfu_inode(inode,
479 le64_to_cpu(pfindData->EndOfFile),
480 search_path,
481 cifs_sb, xid)) {
482 cFYI(1,("Unrecognized sfu inode type"));
483 }
Steve French3020a1f2005-11-18 11:31:10 -0800484 cFYI(1,("sfu mode 0%o",inode->i_mode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 } else {
486 inode->i_mode |= S_IFREG;
487 /* treat the dos attribute of read-only as read-only
488 mode e.g. 555 */
489 if (cifsInfo->cifsAttrs & ATTR_READONLY)
490 inode->i_mode &= ~(S_IWUGO);
491 /* BB add code here -
492 validate if device or weird share or device type? */
493 }
494 if (is_size_safe_to_change(cifsInfo)) {
495 /* can not safely change the file size here if the
496 client is writing to it due to potential races */
497 i_size_write(inode,le64_to_cpu(pfindData->EndOfFile));
498
499 /* 512 bytes (2**9) is the fake blocksize that must be
500 used for this calculation */
501 inode->i_blocks = (512 - 1 + le64_to_cpu(
502 pfindData->AllocationSize)) >> 9;
503 }
504
505 inode->i_nlink = le32_to_cpu(pfindData->NumberOfLinks);
506
507 /* BB fill in uid and gid here? with help from winbind?
508 or retrieve from NTFS stream extended attribute */
Steve French9e294f12005-11-17 16:59:21 -0800509 if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
510 /* fill in uid, gid, mode from server ACL */
511 get_sfu_uid_mode(inode, search_path, cifs_sb, xid);
512 } else if (atomic_read(&cifsInfo->inUse) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 inode->i_uid = cifs_sb->mnt_uid;
514 inode->i_gid = cifs_sb->mnt_gid;
515 /* set so we do not keep refreshing these fields with
516 bad data after user has changed them in memory */
517 atomic_set(&cifsInfo->inUse,1);
518 }
519
520 if (S_ISREG(inode->i_mode)) {
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800521 cFYI(1, ("File inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 inode->i_op = &cifs_file_inode_ops;
Steve French8b94bcb2005-11-11 11:41:00 -0800523 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
524 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
525 inode->i_fop =
526 &cifs_file_direct_nobrl_ops;
527 else
528 inode->i_fop = &cifs_file_direct_ops;
529 } else if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
530 inode->i_fop = &cifs_file_nobrl_ops;
531 else /* not direct, send byte range locks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 inode->i_fop = &cifs_file_ops;
Steve French8b94bcb2005-11-11 11:41:00 -0800533
Steve Frenchbfa0d752005-08-31 21:50:37 -0700534 if(pTcon->ses->server->maxBuf <
Dave Kleikamp273d81d2006-06-01 19:41:23 +0000535 PAGE_CACHE_SIZE + MAX_CIFS_HDR_SIZE)
536 inode->i_data.a_ops = &cifs_addr_ops_smallbuf;
537 else
538 inode->i_data.a_ops = &cifs_addr_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 } else if (S_ISDIR(inode->i_mode)) {
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800540 cFYI(1, ("Directory inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 inode->i_op = &cifs_dir_inode_ops;
542 inode->i_fop = &cifs_dir_ops;
543 } else if (S_ISLNK(inode->i_mode)) {
Steve Frenchd6e2f2a42005-11-15 16:43:39 -0800544 cFYI(1, ("Symbolic Link inode"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 inode->i_op = &cifs_symlink_inode_ops;
546 } else {
547 init_special_inode(inode, inode->i_mode,
548 inode->i_rdev);
549 }
550 }
551 kfree(buf);
552 return rc;
553}
554
555/* gets root inode */
556void cifs_read_inode(struct inode *inode)
557{
558 int xid;
559 struct cifs_sb_info *cifs_sb;
560
561 cifs_sb = CIFS_SB(inode->i_sb);
562 xid = GetXid();
563 if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
564 cifs_get_inode_info_unix(&inode, "", inode->i_sb,xid);
565 else
566 cifs_get_inode_info(&inode, "", NULL, inode->i_sb,xid);
567 /* can not call macro FreeXid here since in a void func */
568 _FreeXid(xid);
569}
570
571int cifs_unlink(struct inode *inode, struct dentry *direntry)
572{
573 int rc = 0;
574 int xid;
575 struct cifs_sb_info *cifs_sb;
576 struct cifsTconInfo *pTcon;
577 char *full_path = NULL;
578 struct cifsInodeInfo *cifsInode;
579 FILE_BASIC_INFO *pinfo_buf;
580
Steve French06bcfed2006-03-31 22:43:50 +0000581 cFYI(1, ("cifs_unlink, inode = 0x%p", inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583 xid = GetXid();
584
Steve French6910ab32006-03-31 03:37:08 +0000585 if(inode)
586 cifs_sb = CIFS_SB(inode->i_sb);
587 else
Steve French06bcfed2006-03-31 22:43:50 +0000588 cifs_sb = CIFS_SB(direntry->d_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 pTcon = cifs_sb->tcon;
590
591 /* Unlink can be called from rename so we can not grab the sem here
592 since we deadlock otherwise */
Arjan van de Vena11f3a02006-03-23 03:00:33 -0800593/* mutex_lock(&direntry->d_sb->s_vfs_rename_mutex);*/
Steve French7f573562005-08-30 11:32:14 -0700594 full_path = build_path_from_dentry(direntry);
Arjan van de Vena11f3a02006-03-23 03:00:33 -0800595/* mutex_unlock(&direntry->d_sb->s_vfs_rename_mutex);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 if (full_path == NULL) {
597 FreeXid(xid);
598 return -ENOMEM;
599 }
Steve French737b7582005-04-28 22:41:06 -0700600 rc = CIFSSMBDelFile(xid, pTcon, full_path, cifs_sb->local_nls,
601 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
603 if (!rc) {
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700604 if (direntry->d_inode)
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700605 drop_nlink(direntry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 } else if (rc == -ENOENT) {
607 d_drop(direntry);
608 } else if (rc == -ETXTBSY) {
609 int oplock = FALSE;
610 __u16 netfid;
611
612 rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN, DELETE,
613 CREATE_NOT_DIR | CREATE_DELETE_ON_CLOSE,
Steve French737b7582005-04-28 22:41:06 -0700614 &netfid, &oplock, NULL, cifs_sb->local_nls,
615 cifs_sb->mnt_cifs_flags &
616 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 if (rc==0) {
618 CIFSSMBRenameOpenFile(xid, pTcon, netfid, NULL,
Steve French737b7582005-04-28 22:41:06 -0700619 cifs_sb->local_nls,
620 cifs_sb->mnt_cifs_flags &
621 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 CIFSSMBClose(xid, pTcon, netfid);
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700623 if (direntry->d_inode)
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700624 drop_nlink(direntry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 }
626 } else if (rc == -EACCES) {
627 /* try only if r/o attribute set in local lookup data? */
Eric Sesterhenna048d7a2006-02-21 22:33:09 +0000628 pinfo_buf = kzalloc(sizeof(FILE_BASIC_INFO), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 if (pinfo_buf) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 /* ATTRS set to normal clears r/o bit */
631 pinfo_buf->Attributes = cpu_to_le32(ATTR_NORMAL);
632 if (!(pTcon->ses->flags & CIFS_SES_NT4))
633 rc = CIFSSMBSetTimes(xid, pTcon, full_path,
634 pinfo_buf,
Steve French737b7582005-04-28 22:41:06 -0700635 cifs_sb->local_nls,
636 cifs_sb->mnt_cifs_flags &
637 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 else
639 rc = -EOPNOTSUPP;
640
641 if (rc == -EOPNOTSUPP) {
642 int oplock = FALSE;
643 __u16 netfid;
644 /* rc = CIFSSMBSetAttrLegacy(xid, pTcon,
645 full_path,
646 (__u16)ATTR_NORMAL,
647 cifs_sb->local_nls);
648 For some strange reason it seems that NT4 eats the
649 old setattr call without actually setting the
650 attributes so on to the third attempted workaround
651 */
652
653 /* BB could scan to see if we already have it open
654 and pass in pid of opener to function */
655 rc = CIFSSMBOpen(xid, pTcon, full_path,
656 FILE_OPEN, SYNCHRONIZE |
657 FILE_WRITE_ATTRIBUTES, 0,
658 &netfid, &oplock, NULL,
Steve French737b7582005-04-28 22:41:06 -0700659 cifs_sb->local_nls,
660 cifs_sb->mnt_cifs_flags &
661 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 if (rc==0) {
663 rc = CIFSSMBSetFileTimes(xid, pTcon,
664 pinfo_buf,
665 netfid);
666 CIFSSMBClose(xid, pTcon, netfid);
667 }
668 }
669 kfree(pinfo_buf);
670 }
671 if (rc==0) {
Steve French737b7582005-04-28 22:41:06 -0700672 rc = CIFSSMBDelFile(xid, pTcon, full_path,
673 cifs_sb->local_nls,
674 cifs_sb->mnt_cifs_flags &
675 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 if (!rc) {
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700677 if (direntry->d_inode)
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700678 drop_nlink(direntry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 } else if (rc == -ETXTBSY) {
680 int oplock = FALSE;
681 __u16 netfid;
682
683 rc = CIFSSMBOpen(xid, pTcon, full_path,
684 FILE_OPEN, DELETE,
685 CREATE_NOT_DIR |
686 CREATE_DELETE_ON_CLOSE,
687 &netfid, &oplock, NULL,
Steve French737b7582005-04-28 22:41:06 -0700688 cifs_sb->local_nls,
689 cifs_sb->mnt_cifs_flags &
690 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 if (rc==0) {
692 CIFSSMBRenameOpenFile(xid, pTcon,
693 netfid, NULL,
Steve French737b7582005-04-28 22:41:06 -0700694 cifs_sb->local_nls,
695 cifs_sb->mnt_cifs_flags &
696 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 CIFSSMBClose(xid, pTcon, netfid);
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700698 if (direntry->d_inode)
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700699 drop_nlink(direntry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
701 /* BB if rc = -ETXTBUSY goto the rename logic BB */
702 }
703 }
704 }
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700705 if (direntry->d_inode) {
Steve Frenchb2aeb9d2005-05-17 13:16:18 -0500706 cifsInode = CIFS_I(direntry->d_inode);
707 cifsInode->time = 0; /* will force revalidate to get info
708 when needed */
709 direntry->d_inode->i_ctime = current_fs_time(inode->i_sb);
710 }
Steve French06bcfed2006-03-31 22:43:50 +0000711 if(inode) {
712 inode->i_ctime = inode->i_mtime = current_fs_time(inode->i_sb);
713 cifsInode = CIFS_I(inode);
714 cifsInode->time = 0; /* force revalidate of dir as well */
715 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717 kfree(full_path);
718 FreeXid(xid);
719 return rc;
720}
721
722int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
723{
724 int rc = 0;
725 int xid;
726 struct cifs_sb_info *cifs_sb;
727 struct cifsTconInfo *pTcon;
728 char *full_path = NULL;
729 struct inode *newinode = NULL;
730
Steve French6473a552005-11-29 20:20:10 -0800731 cFYI(1, ("In cifs_mkdir, mode = 0x%x inode = 0x%p", mode, inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733 xid = GetXid();
734
735 cifs_sb = CIFS_SB(inode->i_sb);
736 pTcon = cifs_sb->tcon;
737
Steve French7f573562005-08-30 11:32:14 -0700738 full_path = build_path_from_dentry(direntry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 if (full_path == NULL) {
740 FreeXid(xid);
741 return -ENOMEM;
742 }
743 /* BB add setting the equivalent of mode via CreateX w/ACLs */
Steve French737b7582005-04-28 22:41:06 -0700744 rc = CIFSSMBMkDir(xid, pTcon, full_path, cifs_sb->local_nls,
745 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 if (rc) {
Steve French26a21b92006-05-31 18:05:34 +0000747 cFYI(1, ("cifs_mkdir returned 0x%x", rc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 d_drop(direntry);
749 } else {
Dave Hansend8c76e62006-09-30 23:29:04 -0700750 inc_nlink(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 if (pTcon->ses->capabilities & CAP_UNIX)
752 rc = cifs_get_inode_info_unix(&newinode, full_path,
753 inode->i_sb,xid);
754 else
755 rc = cifs_get_inode_info(&newinode, full_path, NULL,
756 inode->i_sb,xid);
757
Steve Frenchb92327f2005-08-22 20:09:43 -0700758 if (pTcon->nocase)
759 direntry->d_op = &cifs_ci_dentry_ops;
760 else
761 direntry->d_op = &cifs_dentry_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 d_instantiate(direntry, newinode);
763 if (direntry->d_inode)
764 direntry->d_inode->i_nlink = 2;
765 if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
Steve Frenchd0d2f2d2005-06-02 15:12:36 -0700766 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 CIFSSMBUnixSetPerms(xid, pTcon, full_path,
768 mode,
Steve French83451872005-12-01 17:12:59 -0800769 (__u64)current->fsuid,
770 (__u64)current->fsgid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 0 /* dev_t */,
Steve French737b7582005-04-28 22:41:06 -0700772 cifs_sb->local_nls,
773 cifs_sb->mnt_cifs_flags &
774 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 } else {
776 CIFSSMBUnixSetPerms(xid, pTcon, full_path,
777 mode, (__u64)-1,
778 (__u64)-1, 0 /* dev_t */,
Steve French737b7582005-04-28 22:41:06 -0700779 cifs_sb->local_nls,
780 cifs_sb->mnt_cifs_flags &
781 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 }
783 else {
784 /* BB to be implemented via Windows secrty descriptors
785 eg CIFSSMBWinSetPerms(xid, pTcon, full_path, mode,
786 -1, -1, local_nls); */
Steve French6473a552005-11-29 20:20:10 -0800787 if(direntry->d_inode) {
788 direntry->d_inode->i_mode = mode;
Steve French25741b32005-11-29 22:38:43 -0800789 direntry->d_inode->i_mode |= S_IFDIR;
Steve French6473a552005-11-29 20:20:10 -0800790 if(cifs_sb->mnt_cifs_flags &
791 CIFS_MOUNT_SET_UID) {
792 direntry->d_inode->i_uid =
793 current->fsuid;
794 direntry->d_inode->i_gid =
795 current->fsgid;
796 }
797 }
Steve French2a138ebb2005-11-29 21:22:19 -0800798 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 }
800 kfree(full_path);
801 FreeXid(xid);
802 return rc;
803}
804
805int cifs_rmdir(struct inode *inode, struct dentry *direntry)
806{
807 int rc = 0;
808 int xid;
809 struct cifs_sb_info *cifs_sb;
810 struct cifsTconInfo *pTcon;
811 char *full_path = NULL;
812 struct cifsInodeInfo *cifsInode;
813
Steve French26a21b92006-05-31 18:05:34 +0000814 cFYI(1, ("cifs_rmdir, inode = 0x%p", inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
816 xid = GetXid();
817
818 cifs_sb = CIFS_SB(inode->i_sb);
819 pTcon = cifs_sb->tcon;
820
Steve French7f573562005-08-30 11:32:14 -0700821 full_path = build_path_from_dentry(direntry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 if (full_path == NULL) {
823 FreeXid(xid);
824 return -ENOMEM;
825 }
826
Steve French737b7582005-04-28 22:41:06 -0700827 rc = CIFSSMBRmDir(xid, pTcon, full_path, cifs_sb->local_nls,
828 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 if (!rc) {
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700831 drop_nlink(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 i_size_write(direntry->d_inode,0);
Dave Hansence71ec32006-09-30 23:29:06 -0700833 clear_nlink(direntry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 }
835
836 cifsInode = CIFS_I(direntry->d_inode);
837 cifsInode->time = 0; /* force revalidate to go get info when
838 needed */
839 direntry->d_inode->i_ctime = inode->i_ctime = inode->i_mtime =
840 current_fs_time(inode->i_sb);
841
842 kfree(full_path);
843 FreeXid(xid);
844 return rc;
845}
846
847int cifs_rename(struct inode *source_inode, struct dentry *source_direntry,
848 struct inode *target_inode, struct dentry *target_direntry)
849{
850 char *fromName;
851 char *toName;
852 struct cifs_sb_info *cifs_sb_source;
853 struct cifs_sb_info *cifs_sb_target;
854 struct cifsTconInfo *pTcon;
855 int xid;
856 int rc = 0;
857
858 xid = GetXid();
859
860 cifs_sb_target = CIFS_SB(target_inode->i_sb);
861 cifs_sb_source = CIFS_SB(source_inode->i_sb);
862 pTcon = cifs_sb_source->tcon;
863
864 if (pTcon != cifs_sb_target->tcon) {
865 FreeXid(xid);
866 return -EXDEV; /* BB actually could be allowed if same server,
867 but different share.
868 Might eventually add support for this */
869 }
870
871 /* we already have the rename sem so we do not need to grab it again
872 here to protect the path integrity */
Steve French7f573562005-08-30 11:32:14 -0700873 fromName = build_path_from_dentry(source_direntry);
874 toName = build_path_from_dentry(target_direntry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 if ((fromName == NULL) || (toName == NULL)) {
876 rc = -ENOMEM;
877 goto cifs_rename_exit;
878 }
879
880 rc = CIFSSMBRename(xid, pTcon, fromName, toName,
Steve French737b7582005-04-28 22:41:06 -0700881 cifs_sb_source->local_nls,
882 cifs_sb_source->mnt_cifs_flags &
883 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 if (rc == -EEXIST) {
885 /* check if they are the same file because rename of hardlinked
886 files is a noop */
887 FILE_UNIX_BASIC_INFO *info_buf_source;
888 FILE_UNIX_BASIC_INFO *info_buf_target;
889
890 info_buf_source =
891 kmalloc(2 * sizeof(FILE_UNIX_BASIC_INFO), GFP_KERNEL);
892 if (info_buf_source != NULL) {
893 info_buf_target = info_buf_source + 1;
Steve French8e87d4d2006-11-02 03:45:24 +0000894 if (pTcon->ses->capabilities & CAP_UNIX)
895 rc = CIFSSMBUnixQPathInfo(xid, pTcon, fromName,
896 info_buf_source,
897 cifs_sb_source->local_nls,
898 cifs_sb_source->mnt_cifs_flags &
899 CIFS_MOUNT_MAP_SPECIAL_CHR);
900 /* else rc is still EEXIST so will fall through to
901 unlink the target and retry rename */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 if (rc == 0) {
903 rc = CIFSSMBUnixQPathInfo(xid, pTcon, toName,
904 info_buf_target,
Steve French737b7582005-04-28 22:41:06 -0700905 cifs_sb_target->local_nls,
906 /* remap based on source sb */
907 cifs_sb_source->mnt_cifs_flags &
908 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 }
910 if ((rc == 0) &&
911 (info_buf_source->UniqueId ==
912 info_buf_target->UniqueId)) {
913 /* do not rename since the files are hardlinked which
914 is a noop */
915 } else {
916 /* we either can not tell the files are hardlinked
917 (as with Windows servers) or files are not
918 hardlinked so delete the target manually before
919 renaming to follow POSIX rather than Windows
920 semantics */
921 cifs_unlink(target_inode, target_direntry);
922 rc = CIFSSMBRename(xid, pTcon, fromName,
923 toName,
Steve French737b7582005-04-28 22:41:06 -0700924 cifs_sb_source->local_nls,
925 cifs_sb_source->mnt_cifs_flags
926 & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 }
928 kfree(info_buf_source);
929 } /* if we can not get memory just leave rc as EEXIST */
930 }
931
932 if (rc) {
933 cFYI(1, ("rename rc %d", rc));
934 }
935
936 if ((rc == -EIO) || (rc == -EEXIST)) {
937 int oplock = FALSE;
938 __u16 netfid;
939
940 /* BB FIXME Is Generic Read correct for rename? */
941 /* if renaming directory - we should not say CREATE_NOT_DIR,
942 need to test renaming open directory, also GENERIC_READ
943 might not right be right access to request */
944 rc = CIFSSMBOpen(xid, pTcon, fromName, FILE_OPEN, GENERIC_READ,
945 CREATE_NOT_DIR, &netfid, &oplock, NULL,
Steve French737b7582005-04-28 22:41:06 -0700946 cifs_sb_source->local_nls,
947 cifs_sb_source->mnt_cifs_flags &
948 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 if (rc==0) {
Steve French8e87d4d2006-11-02 03:45:24 +0000950 rc = CIFSSMBRenameOpenFile(xid, pTcon, netfid, toName,
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 CIFSSMBClose(xid, pTcon, netfid);
955 }
956 }
957
958cifs_rename_exit:
959 kfree(fromName);
960 kfree(toName);
961 FreeXid(xid);
962 return rc;
963}
964
965int cifs_revalidate(struct dentry *direntry)
966{
967 int xid;
968 int rc = 0;
969 char *full_path;
970 struct cifs_sb_info *cifs_sb;
971 struct cifsInodeInfo *cifsInode;
972 loff_t local_size;
973 struct timespec local_mtime;
974 int invalidate_inode = FALSE;
975
976 if (direntry->d_inode == NULL)
977 return -ENOENT;
978
979 cifsInode = CIFS_I(direntry->d_inode);
980
981 if (cifsInode == NULL)
982 return -ENOENT;
983
984 /* no sense revalidating inode info on file that no one can write */
985 if (CIFS_I(direntry->d_inode)->clientCanCacheRead)
986 return rc;
987
988 xid = GetXid();
989
990 cifs_sb = CIFS_SB(direntry->d_sb);
991
992 /* can not safely grab the rename sem here if rename calls revalidate
993 since that would deadlock */
Steve French7f573562005-08-30 11:32:14 -0700994 full_path = build_path_from_dentry(direntry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 if (full_path == NULL) {
996 FreeXid(xid);
997 return -ENOMEM;
998 }
999 cFYI(1, ("Revalidate: %s inode 0x%p count %d dentry: 0x%p d_time %ld "
1000 "jiffies %ld", full_path, direntry->d_inode,
1001 direntry->d_inode->i_count.counter, direntry,
1002 direntry->d_time, jiffies));
1003
1004 if (cifsInode->time == 0) {
1005 /* was set to zero previously to force revalidate */
1006 } else if (time_before(jiffies, cifsInode->time + HZ) &&
1007 lookupCacheEnabled) {
1008 if ((S_ISREG(direntry->d_inode->i_mode) == 0) ||
1009 (direntry->d_inode->i_nlink == 1)) {
1010 kfree(full_path);
1011 FreeXid(xid);
1012 return rc;
1013 } else {
1014 cFYI(1, ("Have to revalidate file due to hardlinks"));
1015 }
1016 }
1017
1018 /* save mtime and size */
1019 local_mtime = direntry->d_inode->i_mtime;
1020 local_size = direntry->d_inode->i_size;
1021
1022 if (cifs_sb->tcon->ses->capabilities & CAP_UNIX) {
1023 rc = cifs_get_inode_info_unix(&direntry->d_inode, full_path,
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 } else {
1032 rc = cifs_get_inode_info(&direntry->d_inode, full_path, NULL,
1033 direntry->d_sb,xid);
1034 if (rc) {
1035 cFYI(1, ("error on getting revalidate info %d", rc));
1036/* if (rc != -ENOENT)
1037 rc = 0; */ /* BB should we cache info on
1038 certain errors? */
1039 }
1040 }
1041 /* should we remap certain errors, access denied?, to zero */
1042
1043 /* if not oplocked, we invalidate inode pages if mtime or file size
1044 had changed on server */
1045
1046 if (timespec_equal(&local_mtime,&direntry->d_inode->i_mtime) &&
1047 (local_size == direntry->d_inode->i_size)) {
1048 cFYI(1, ("cifs_revalidate - inode unchanged"));
1049 } else {
1050 /* file may have changed on server */
1051 if (cifsInode->clientCanCacheRead) {
1052 /* no need to invalidate inode pages since we were the
1053 only ones who could have modified the file and the
1054 server copy is staler than ours */
1055 } else {
1056 invalidate_inode = TRUE;
1057 }
1058 }
1059
1060 /* can not grab this sem since kernel filesys locking documentation
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08001061 indicates i_mutex may be taken by the kernel on lookup and rename
1062 which could deadlock if we grab the i_mutex here as well */
1063/* mutex_lock(&direntry->d_inode->i_mutex);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 /* need to write out dirty pages here */
1065 if (direntry->d_inode->i_mapping) {
1066 /* do we need to lock inode until after invalidate completes
1067 below? */
1068 filemap_fdatawrite(direntry->d_inode->i_mapping);
1069 }
1070 if (invalidate_inode) {
Steve French3abb9272005-11-28 08:16:13 -08001071 /* shrink_dcache not necessary now that cifs dentry ops
1072 are exported for negative dentries */
1073/* if(S_ISDIR(direntry->d_inode->i_mode))
1074 shrink_dcache_parent(direntry); */
1075 if (S_ISREG(direntry->d_inode->i_mode)) {
1076 if (direntry->d_inode->i_mapping)
1077 filemap_fdatawait(direntry->d_inode->i_mapping);
1078 /* may eventually have to do this for open files too */
1079 if (list_empty(&(cifsInode->openFileList))) {
1080 /* changed on server - flush read ahead pages */
1081 cFYI(1, ("Invalidating read ahead data on "
1082 "closed file"));
1083 invalidate_remote_inode(direntry->d_inode);
1084 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 }
1086 }
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08001087/* mutex_unlock(&direntry->d_inode->i_mutex); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
1089 kfree(full_path);
1090 FreeXid(xid);
1091 return rc;
1092}
1093
1094int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1095 struct kstat *stat)
1096{
1097 int err = cifs_revalidate(dentry);
Steve French5fe14c82006-11-07 19:26:33 +00001098 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 generic_fillattr(dentry->d_inode, stat);
Steve French5fe14c82006-11-07 19:26:33 +00001100 stat->blksize = CIFS_MAX_MSGSIZE;
1101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 return err;
1103}
1104
1105static int cifs_truncate_page(struct address_space *mapping, loff_t from)
1106{
1107 pgoff_t index = from >> PAGE_CACHE_SHIFT;
1108 unsigned offset = from & (PAGE_CACHE_SIZE - 1);
1109 struct page *page;
1110 char *kaddr;
1111 int rc = 0;
1112
1113 page = grab_cache_page(mapping, index);
1114 if (!page)
1115 return -ENOMEM;
1116
1117 kaddr = kmap_atomic(page, KM_USER0);
1118 memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset);
1119 flush_dcache_page(page);
1120 kunmap_atomic(kaddr, KM_USER0);
1121 unlock_page(page);
1122 page_cache_release(page);
1123 return rc;
1124}
1125
1126int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
1127{
1128 int xid;
1129 struct cifs_sb_info *cifs_sb;
1130 struct cifsTconInfo *pTcon;
1131 char *full_path = NULL;
1132 int rc = -EACCES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 struct cifsFileInfo *open_file = NULL;
1134 FILE_BASIC_INFO time_buf;
1135 int set_time = FALSE;
1136 __u64 mode = 0xFFFFFFFFFFFFFFFFULL;
1137 __u64 uid = 0xFFFFFFFFFFFFFFFFULL;
1138 __u64 gid = 0xFFFFFFFFFFFFFFFFULL;
1139 struct cifsInodeInfo *cifsInode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
1141 xid = GetXid();
1142
Steve French39798772006-05-31 22:40:51 +00001143 cFYI(1, ("setattr on file %s attrs->iavalid 0x%x",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 direntry->d_name.name, attrs->ia_valid));
Steve French6473a552005-11-29 20:20:10 -08001145
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 cifs_sb = CIFS_SB(direntry->d_inode->i_sb);
1147 pTcon = cifs_sb->tcon;
1148
Steve French2a138ebb2005-11-29 21:22:19 -08001149 if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) == 0) {
Steve French6473a552005-11-29 20:20:10 -08001150 /* check if we have permission to change attrs */
1151 rc = inode_change_ok(direntry->d_inode, attrs);
1152 if(rc < 0) {
1153 FreeXid(xid);
1154 return rc;
1155 } else
1156 rc = 0;
1157 }
1158
Steve French7f573562005-08-30 11:32:14 -07001159 full_path = build_path_from_dentry(direntry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 if (full_path == NULL) {
1161 FreeXid(xid);
1162 return -ENOMEM;
1163 }
1164 cifsInode = CIFS_I(direntry->d_inode);
1165
1166 /* BB check if we need to refresh inode from server now ? BB */
1167
1168 /* need to flush data before changing file size on server */
OGAWA Hirofumi28fd1292006-01-08 01:02:14 -08001169 filemap_write_and_wait(direntry->d_inode->i_mapping);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
1171 if (attrs->ia_valid & ATTR_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 /* To avoid spurious oplock breaks from server, in the case of
1173 inodes that we already have open, avoid doing path based
1174 setting of file size if we can do it by handle.
1175 This keeps our caching token (oplock) and avoids timeouts
1176 when the local oplock break takes longer to flush
1177 writebehind data than the SMB timeout for the SetPathInfo
1178 request would allow */
Steve French39798772006-05-31 22:40:51 +00001179
Steve French6148a742005-10-05 12:23:19 -07001180 open_file = find_writable_file(cifsInode);
1181 if (open_file) {
1182 __u16 nfid = open_file->netfid;
1183 __u32 npid = open_file->pid;
1184 rc = CIFSSMBSetFileSize(xid, pTcon, attrs->ia_size,
1185 nfid, npid, FALSE);
Steve French23e7dd72005-10-20 13:44:56 -07001186 atomic_dec(&open_file->wrtPending);
Steve French6148a742005-10-05 12:23:19 -07001187 cFYI(1,("SetFSize for attrs rc = %d", rc));
Steve French083d3a22006-03-03 09:53:36 +00001188 if((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
Steve French6148a742005-10-05 12:23:19 -07001189 int bytes_written;
1190 rc = CIFSSMBWrite(xid, pTcon,
1191 nfid, 0, attrs->ia_size,
1192 &bytes_written, NULL, NULL,
1193 1 /* 45 seconds */);
1194 cFYI(1,("Wrt seteof rc %d", rc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 }
Steve French6473a552005-11-29 20:20:10 -08001196 } else
1197 rc = -EINVAL;
1198
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 if (rc != 0) {
1200 /* Set file size by pathname rather than by handle
1201 either because no valid, writeable file handle for
1202 it was found or because there was an error setting
1203 it by handle */
1204 rc = CIFSSMBSetEOF(xid, pTcon, full_path,
1205 attrs->ia_size, FALSE,
Steve French737b7582005-04-28 22:41:06 -07001206 cifs_sb->local_nls,
1207 cifs_sb->mnt_cifs_flags &
1208 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve Frenche30dcf32005-09-20 20:49:16 -07001209 cFYI(1, ("SetEOF by path (setattrs) rc = %d", rc));
Steve French083d3a22006-03-03 09:53:36 +00001210 if((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
Steve Frenche30dcf32005-09-20 20:49:16 -07001211 __u16 netfid;
1212 int oplock = FALSE;
1213
1214 rc = SMBLegacyOpen(xid, pTcon, full_path,
1215 FILE_OPEN,
1216 SYNCHRONIZE | FILE_WRITE_ATTRIBUTES,
1217 CREATE_NOT_DIR, &netfid, &oplock,
1218 NULL, cifs_sb->local_nls,
1219 cifs_sb->mnt_cifs_flags &
1220 CIFS_MOUNT_MAP_SPECIAL_CHR);
1221 if (rc==0) {
1222 int bytes_written;
1223 rc = CIFSSMBWrite(xid, pTcon,
1224 netfid, 0,
1225 attrs->ia_size,
1226 &bytes_written, NULL,
1227 NULL, 1 /* 45 sec */);
1228 cFYI(1,("wrt seteof rc %d",rc));
1229 CIFSSMBClose(xid, pTcon, netfid);
1230 }
1231
1232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 }
1234
1235 /* Server is ok setting allocation size implicitly - no need
1236 to call:
1237 CIFSSMBSetEOF(xid, pTcon, full_path, attrs->ia_size, TRUE,
1238 cifs_sb->local_nls);
1239 */
1240
1241 if (rc == 0) {
1242 rc = vmtruncate(direntry->d_inode, attrs->ia_size);
1243 cifs_truncate_page(direntry->d_inode->i_mapping,
1244 direntry->d_inode->i_size);
Steve Frenche30dcf32005-09-20 20:49:16 -07001245 } else
1246 goto cifs_setattr_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 }
1248 if (attrs->ia_valid & ATTR_UID) {
Steve Frenche30dcf32005-09-20 20:49:16 -07001249 cFYI(1, ("UID changed to %d", attrs->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 uid = attrs->ia_uid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 }
1252 if (attrs->ia_valid & ATTR_GID) {
Steve Frenche30dcf32005-09-20 20:49:16 -07001253 cFYI(1, ("GID changed to %d", attrs->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 gid = attrs->ia_gid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 }
1256
1257 time_buf.Attributes = 0;
1258 if (attrs->ia_valid & ATTR_MODE) {
Steve Frenche30dcf32005-09-20 20:49:16 -07001259 cFYI(1, ("Mode changed to 0x%x", attrs->ia_mode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 mode = attrs->ia_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 }
1262
1263 if ((cifs_sb->tcon->ses->capabilities & CAP_UNIX)
1264 && (attrs->ia_valid & (ATTR_MODE | ATTR_GID | ATTR_UID)))
1265 rc = CIFSSMBUnixSetPerms(xid, pTcon, full_path, mode, uid, gid,
Steve French737b7582005-04-28 22:41:06 -07001266 0 /* dev_t */, cifs_sb->local_nls,
1267 cifs_sb->mnt_cifs_flags &
1268 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 else if (attrs->ia_valid & ATTR_MODE) {
Steve Frenchcdbce9c2005-11-19 21:04:52 -08001270 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 if ((mode & S_IWUGO) == 0) /* not writeable */ {
1272 if ((cifsInode->cifsAttrs & ATTR_READONLY) == 0)
1273 time_buf.Attributes =
1274 cpu_to_le32(cifsInode->cifsAttrs |
1275 ATTR_READONLY);
1276 } else if ((mode & S_IWUGO) == S_IWUGO) {
1277 if (cifsInode->cifsAttrs & ATTR_READONLY)
1278 time_buf.Attributes =
1279 cpu_to_le32(cifsInode->cifsAttrs &
1280 (~ATTR_READONLY));
1281 }
1282 /* BB to be implemented -
1283 via Windows security descriptors or streams */
1284 /* CIFSSMBWinSetPerms(xid, pTcon, full_path, mode, uid, gid,
1285 cifs_sb->local_nls); */
1286 }
1287
1288 if (attrs->ia_valid & ATTR_ATIME) {
1289 set_time = TRUE;
1290 time_buf.LastAccessTime =
1291 cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_atime));
1292 } else
1293 time_buf.LastAccessTime = 0;
1294
1295 if (attrs->ia_valid & ATTR_MTIME) {
1296 set_time = TRUE;
1297 time_buf.LastWriteTime =
1298 cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_mtime));
1299 } else
1300 time_buf.LastWriteTime = 0;
Steve Frenche30dcf32005-09-20 20:49:16 -07001301 /* Do not set ctime explicitly unless other time
1302 stamps are changed explicitly (i.e. by utime()
1303 since we would then have a mix of client and
1304 server times */
1305
1306 if (set_time && (attrs->ia_valid & ATTR_CTIME)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 set_time = TRUE;
Steve Frenche30dcf32005-09-20 20:49:16 -07001308 /* Although Samba throws this field away
1309 it may be useful to Windows - but we do
1310 not want to set ctime unless some other
1311 timestamp is changing */
Steve French26a21b92006-05-31 18:05:34 +00001312 cFYI(1, ("CIFS - CTIME changed"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 time_buf.ChangeTime =
1314 cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_ctime));
1315 } else
1316 time_buf.ChangeTime = 0;
1317
1318 if (set_time || time_buf.Attributes) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 time_buf.CreationTime = 0; /* do not change */
1320 /* In the future we should experiment - try setting timestamps
1321 via Handle (SetFileInfo) instead of by path */
1322 if (!(pTcon->ses->flags & CIFS_SES_NT4))
1323 rc = CIFSSMBSetTimes(xid, pTcon, full_path, &time_buf,
Steve French737b7582005-04-28 22:41:06 -07001324 cifs_sb->local_nls,
1325 cifs_sb->mnt_cifs_flags &
1326 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 else
1328 rc = -EOPNOTSUPP;
1329
1330 if (rc == -EOPNOTSUPP) {
1331 int oplock = FALSE;
1332 __u16 netfid;
1333
1334 cFYI(1, ("calling SetFileInfo since SetPathInfo for "
1335 "times not supported by this server"));
1336 /* BB we could scan to see if we already have it open
1337 and pass in pid of opener to function */
1338 rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN,
1339 SYNCHRONIZE | FILE_WRITE_ATTRIBUTES,
1340 CREATE_NOT_DIR, &netfid, &oplock,
Steve French737b7582005-04-28 22:41:06 -07001341 NULL, cifs_sb->local_nls,
1342 cifs_sb->mnt_cifs_flags &
1343 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 if (rc==0) {
1345 rc = CIFSSMBSetFileTimes(xid, pTcon, &time_buf,
1346 netfid);
1347 CIFSSMBClose(xid, pTcon, netfid);
1348 } else {
1349 /* BB For even older servers we could convert time_buf
1350 into old DOS style which uses two second
1351 granularity */
1352
1353 /* rc = CIFSSMBSetTimesLegacy(xid, pTcon, full_path,
1354 &time_buf, cifs_sb->local_nls); */
1355 }
1356 }
Steve Frenche30dcf32005-09-20 20:49:16 -07001357 /* Even if error on time set, no sense failing the call if
1358 the server would set the time to a reasonable value anyway,
1359 and this check ensures that we are not being called from
1360 sys_utimes in which case we ought to fail the call back to
1361 the user when the server rejects the call */
1362 if((rc) && (attrs->ia_valid &&
1363 (ATTR_MODE | ATTR_GID | ATTR_UID | ATTR_SIZE)))
1364 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 }
1366
1367 /* do not need local check to inode_check_ok since the server does
1368 that */
1369 if (!rc)
1370 rc = inode_setattr(direntry->d_inode, attrs);
Steve Frenche30dcf32005-09-20 20:49:16 -07001371cifs_setattr_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 kfree(full_path);
1373 FreeXid(xid);
1374 return rc;
1375}
1376
1377void cifs_delete_inode(struct inode *inode)
1378{
Steve French26a21b92006-05-31 18:05:34 +00001379 cFYI(1, ("In cifs_delete_inode, inode = 0x%p", inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 /* may have to add back in if and when safe distributed caching of
1381 directories added e.g. via FindNotify */
1382}