aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cifs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/cifs/inode.c')
-rw-r--r--fs/cifs/inode.c503
1 files changed, 258 insertions, 245 deletions
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index fcbdbb6ad7bf..00ced97bd53a 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -161,118 +161,115 @@ static void cifs_unix_info_to_inode(struct inode *inode,
161 spin_unlock(&inode->i_lock); 161 spin_unlock(&inode->i_lock);
162} 162}
163 163
164static const unsigned char *cifs_get_search_path(struct cifs_sb_info *cifs_sb,
165 const char *search_path)
166{
167 int tree_len;
168 int path_len;
169 int i;
170 char *tmp_path;
171 struct cifsTconInfo *pTcon = cifs_sb->tcon;
172
173 if (!(pTcon->Flags & SMB_SHARE_IS_IN_DFS))
174 return search_path;
175 164
176 /* use full path name for working with DFS */ 165/*
177 tree_len = strnlen(pTcon->treeName, MAX_TREE_SIZE + 1); 166 * Needed to setup inode data for the directory which is the
178 path_len = strnlen(search_path, MAX_PATHCONF); 167 * junction to the new submount (ie to setup the fake directory
179 168 * which represents a DFS referral)
180 tmp_path = kmalloc(tree_len+path_len+1, GFP_KERNEL); 169 */
181 if (tmp_path == NULL) 170static void fill_fake_finddataunix(FILE_UNIX_BASIC_INFO *pfnd_dat,
182 return search_path; 171 struct super_block *sb)
172{
173 struct inode *pinode = NULL;
174
175 memset(pfnd_dat, sizeof(FILE_UNIX_BASIC_INFO), 0);
176
177/* __le64 pfnd_dat->EndOfFile = cpu_to_le64(0);
178 __le64 pfnd_dat->NumOfBytes = cpu_to_le64(0);
179 __u64 UniqueId = 0; */
180 pfnd_dat->LastStatusChange =
181 cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME));
182 pfnd_dat->LastAccessTime =
183 cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME));
184 pfnd_dat->LastModificationTime =
185 cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME));
186 pfnd_dat->Type = cpu_to_le32(UNIX_DIR);
187 pfnd_dat->Permissions = cpu_to_le64(S_IXUGO | S_IRWXU);
188 pfnd_dat->Nlinks = cpu_to_le64(2);
189 if (sb->s_root)
190 pinode = sb->s_root->d_inode;
191 if (pinode == NULL)
192 return;
183 193
184 strncpy(tmp_path, pTcon->treeName, tree_len); 194 /* fill in default values for the remaining based on root
185 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) 195 inode since we can not query the server for this inode info */
186 for (i = 0; i < tree_len; i++) { 196 pfnd_dat->DevMajor = cpu_to_le64(MAJOR(pinode->i_rdev));
187 if (tmp_path[i] == '\\') 197 pfnd_dat->DevMinor = cpu_to_le64(MINOR(pinode->i_rdev));
188 tmp_path[i] = '/'; 198 pfnd_dat->Uid = cpu_to_le64(pinode->i_uid);
189 } 199 pfnd_dat->Gid = cpu_to_le64(pinode->i_gid);
190 strncpy(tmp_path+tree_len, search_path, path_len);
191 tmp_path[tree_len+path_len] = 0;
192 return tmp_path;
193} 200}
194 201
195int cifs_get_inode_info_unix(struct inode **pinode, 202int cifs_get_inode_info_unix(struct inode **pinode,
196 const unsigned char *search_path, struct super_block *sb, int xid) 203 const unsigned char *full_path, struct super_block *sb, int xid)
197{ 204{
198 int rc = 0; 205 int rc = 0;
199 FILE_UNIX_BASIC_INFO findData; 206 FILE_UNIX_BASIC_INFO find_data;
200 struct cifsTconInfo *pTcon; 207 struct cifsTconInfo *pTcon;
201 struct inode *inode; 208 struct inode *inode;
202 struct cifs_sb_info *cifs_sb = CIFS_SB(sb); 209 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
203 const unsigned char *full_path;
204 bool is_dfs_referral = false; 210 bool is_dfs_referral = false;
211 struct cifsInodeInfo *cifsInfo;
212 __u64 num_of_bytes;
213 __u64 end_of_file;
205 214
206 pTcon = cifs_sb->tcon; 215 pTcon = cifs_sb->tcon;
207 cFYI(1, ("Getting info on %s", search_path)); 216 cFYI(1, ("Getting info on %s", full_path));
208 217
209 full_path = cifs_get_search_path(cifs_sb, search_path);
210
211try_again_CIFSSMBUnixQPathInfo:
212 /* could have done a find first instead but this returns more info */ 218 /* could have done a find first instead but this returns more info */
213 rc = CIFSSMBUnixQPathInfo(xid, pTcon, full_path, &findData, 219 rc = CIFSSMBUnixQPathInfo(xid, pTcon, full_path, &find_data,
214 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & 220 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
215 CIFS_MOUNT_MAP_SPECIAL_CHR); 221 CIFS_MOUNT_MAP_SPECIAL_CHR);
216/* dump_mem("\nUnixQPathInfo return data", &findData,
217 sizeof(findData)); */
218 if (rc) { 222 if (rc) {
219 if (rc == -EREMOTE && !is_dfs_referral) { 223 if (rc == -EREMOTE && !is_dfs_referral) {
220 is_dfs_referral = true; 224 is_dfs_referral = true;
221 if (full_path != search_path) { 225 cFYI(DBG2, ("DFS ref"));
222 kfree(full_path); 226 /* for DFS, server does not give us real inode data */
223 full_path = search_path; 227 fill_fake_finddataunix(&find_data, sb);
224 } 228 rc = 0;
225 goto try_again_CIFSSMBUnixQPathInfo;
226 } 229 }
227 goto cgiiu_exit; 230 }
228 } else { 231 num_of_bytes = le64_to_cpu(find_data.NumOfBytes);
229 struct cifsInodeInfo *cifsInfo; 232 end_of_file = le64_to_cpu(find_data.EndOfFile);
230 __u64 num_of_bytes = le64_to_cpu(findData.NumOfBytes);
231 __u64 end_of_file = le64_to_cpu(findData.EndOfFile);
232 233
233 /* get new inode */ 234 /* get new inode */
235 if (*pinode == NULL) {
236 *pinode = new_inode(sb);
234 if (*pinode == NULL) { 237 if (*pinode == NULL) {
235 *pinode = new_inode(sb); 238 rc = -ENOMEM;
236 if (*pinode == NULL) { 239 goto cgiiu_exit;
237 rc = -ENOMEM;
238 goto cgiiu_exit;
239 }
240 /* Is an i_ino of zero legal? */
241 /* Are there sanity checks we can use to ensure that
242 the server is really filling in that field? */
243 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
244 (*pinode)->i_ino =
245 (unsigned long)findData.UniqueId;
246 } /* note ino incremented to unique num in new_inode */
247 if (sb->s_flags & MS_NOATIME)
248 (*pinode)->i_flags |= S_NOATIME | S_NOCMTIME;
249
250 insert_inode_hash(*pinode);
251 } 240 }
241 /* Is an i_ino of zero legal? */
242 /* note ino incremented to unique num in new_inode */
243 /* Are there sanity checks we can use to ensure that
244 the server is really filling in that field? */
245 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
246 (*pinode)->i_ino = (unsigned long)find_data.UniqueId;
252 247
253 inode = *pinode; 248 if (sb->s_flags & MS_NOATIME)
254 cifsInfo = CIFS_I(inode); 249 (*pinode)->i_flags |= S_NOATIME | S_NOCMTIME;
255 250
256 cFYI(1, ("Old time %ld", cifsInfo->time)); 251 insert_inode_hash(*pinode);
257 cifsInfo->time = jiffies; 252 }
258 cFYI(1, ("New time %ld", cifsInfo->time));
259 /* this is ok to set on every inode revalidate */
260 atomic_set(&cifsInfo->inUse, 1);
261 253
262 cifs_unix_info_to_inode(inode, &findData, 0); 254 inode = *pinode;
255 cifsInfo = CIFS_I(inode);
263 256
257 cFYI(1, ("Old time %ld", cifsInfo->time));
258 cifsInfo->time = jiffies;
259 cFYI(1, ("New time %ld", cifsInfo->time));
260 /* this is ok to set on every inode revalidate */
261 atomic_set(&cifsInfo->inUse, 1);
264 262
265 if (num_of_bytes < end_of_file) 263 cifs_unix_info_to_inode(inode, &find_data, 0);
266 cFYI(1, ("allocation size less than end of file"));
267 cFYI(1, ("Size %ld and blocks %llu",
268 (unsigned long) inode->i_size,
269 (unsigned long long)inode->i_blocks));
270 264
271 cifs_set_ops(inode, is_dfs_referral); 265 if (num_of_bytes < end_of_file)
272 } 266 cFYI(1, ("allocation size less than end of file"));
267 cFYI(1, ("Size %ld and blocks %llu",
268 (unsigned long) inode->i_size,
269 (unsigned long long)inode->i_blocks));
270
271 cifs_set_ops(inode, is_dfs_referral);
273cgiiu_exit: 272cgiiu_exit:
274 if (full_path != search_path)
275 kfree(full_path);
276 return rc; 273 return rc;
277} 274}
278 275
@@ -379,21 +376,51 @@ static int get_sfu_mode(struct inode *inode,
379#endif 376#endif
380} 377}
381 378
379/*
380 * Needed to setup inode data for the directory which is the
381 * junction to the new submount (ie to setup the fake directory
382 * which represents a DFS referral)
383 */
384static void fill_fake_finddata(FILE_ALL_INFO *pfnd_dat,
385 struct super_block *sb)
386{
387 memset(pfnd_dat, sizeof(FILE_ALL_INFO), 0);
388
389/* __le64 pfnd_dat->AllocationSize = cpu_to_le64(0);
390 __le64 pfnd_dat->EndOfFile = cpu_to_le64(0);
391 __u8 pfnd_dat->DeletePending = 0;
392 __u8 pfnd_data->Directory = 0;
393 __le32 pfnd_dat->EASize = 0;
394 __u64 pfnd_dat->IndexNumber = 0;
395 __u64 pfnd_dat->IndexNumber1 = 0; */
396 pfnd_dat->CreationTime =
397 cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME));
398 pfnd_dat->LastAccessTime =
399 cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME));
400 pfnd_dat->LastWriteTime =
401 cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME));
402 pfnd_dat->ChangeTime =
403 cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME));
404 pfnd_dat->Attributes = cpu_to_le32(ATTR_DIRECTORY);
405 pfnd_dat->NumberOfLinks = cpu_to_le32(2);
406}
407
382int cifs_get_inode_info(struct inode **pinode, 408int cifs_get_inode_info(struct inode **pinode,
383 const unsigned char *search_path, FILE_ALL_INFO *pfindData, 409 const unsigned char *full_path, FILE_ALL_INFO *pfindData,
384 struct super_block *sb, int xid, const __u16 *pfid) 410 struct super_block *sb, int xid, const __u16 *pfid)
385{ 411{
386 int rc = 0; 412 int rc = 0;
413 __u32 attr;
414 struct cifsInodeInfo *cifsInfo;
387 struct cifsTconInfo *pTcon; 415 struct cifsTconInfo *pTcon;
388 struct inode *inode; 416 struct inode *inode;
389 struct cifs_sb_info *cifs_sb = CIFS_SB(sb); 417 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
390 const unsigned char *full_path = NULL;
391 char *buf = NULL; 418 char *buf = NULL;
392 bool adjustTZ = false; 419 bool adjustTZ = false;
393 bool is_dfs_referral = false; 420 bool is_dfs_referral = false;
394 421
395 pTcon = cifs_sb->tcon; 422 pTcon = cifs_sb->tcon;
396 cFYI(1, ("Getting info on %s", search_path)); 423 cFYI(1, ("Getting info on %s", full_path));
397 424
398 if ((pfindData == NULL) && (*pinode != NULL)) { 425 if ((pfindData == NULL) && (*pinode != NULL)) {
399 if (CIFS_I(*pinode)->clientCanCacheRead) { 426 if (CIFS_I(*pinode)->clientCanCacheRead) {
@@ -409,9 +436,6 @@ int cifs_get_inode_info(struct inode **pinode,
409 return -ENOMEM; 436 return -ENOMEM;
410 pfindData = (FILE_ALL_INFO *)buf; 437 pfindData = (FILE_ALL_INFO *)buf;
411 438
412 full_path = cifs_get_search_path(cifs_sb, search_path);
413
414try_again_CIFSSMBQPathInfo:
415 /* could do find first instead but this returns more info */ 439 /* could do find first instead but this returns more info */
416 rc = CIFSSMBQPathInfo(xid, pTcon, full_path, pfindData, 440 rc = CIFSSMBQPathInfo(xid, pTcon, full_path, pfindData,
417 0 /* not legacy */, 441 0 /* not legacy */,
@@ -429,178 +453,168 @@ try_again_CIFSSMBQPathInfo:
429 } 453 }
430 } 454 }
431 /* dump_mem("\nQPathInfo return data",&findData, sizeof(findData)); */ 455 /* dump_mem("\nQPathInfo return data",&findData, sizeof(findData)); */
432 if (rc) { 456 if (rc == -EREMOTE) {
433 if (rc == -EREMOTE && !is_dfs_referral) { 457 is_dfs_referral = true;
434 is_dfs_referral = true; 458 fill_fake_finddata(pfindData, sb);
435 if (full_path != search_path) { 459 rc = 0;
436 kfree(full_path); 460 } else if (rc)
437 full_path = search_path;
438 }
439 goto try_again_CIFSSMBQPathInfo;
440 }
441 goto cgii_exit; 461 goto cgii_exit;
442 } else {
443 struct cifsInodeInfo *cifsInfo;
444 __u32 attr = le32_to_cpu(pfindData->Attributes);
445 462
446 /* get new inode */ 463 attr = le32_to_cpu(pfindData->Attributes);
447 if (*pinode == NULL) {
448 *pinode = new_inode(sb);
449 if (*pinode == NULL) {
450 rc = -ENOMEM;
451 goto cgii_exit;
452 }
453 /* Is an i_ino of zero legal? Can we use that to check
454 if the server supports returning inode numbers? Are
455 there other sanity checks we can use to ensure that
456 the server is really filling in that field? */
457 464
458 /* We can not use the IndexNumber field by default from 465 /* get new inode */
459 Windows or Samba (in ALL_INFO buf) but we can request 466 if (*pinode == NULL) {
460 it explicitly. It may not be unique presumably if 467 *pinode = new_inode(sb);
461 the server has multiple devices mounted under one 468 if (*pinode == NULL) {
462 share */ 469 rc = -ENOMEM;
463 470 goto cgii_exit;
464 /* There may be higher info levels that work but are 471 }
465 there Windows server or network appliances for which 472 /* Is an i_ino of zero legal? Can we use that to check
466 IndexNumber field is not guaranteed unique? */ 473 if the server supports returning inode numbers? Are
467 474 there other sanity checks we can use to ensure that
468 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { 475 the server is really filling in that field? */
469 int rc1 = 0; 476
470 __u64 inode_num; 477 /* We can not use the IndexNumber field by default from
471 478 Windows or Samba (in ALL_INFO buf) but we can request
472 rc1 = CIFSGetSrvInodeNumber(xid, pTcon, 479 it explicitly. It may not be unique presumably if
473 search_path, &inode_num, 480 the server has multiple devices mounted under one share */
481
482 /* There may be higher info levels that work but are
483 there Windows server or network appliances for which
484 IndexNumber field is not guaranteed unique? */
485
486 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
487 int rc1 = 0;
488 __u64 inode_num;
489
490 rc1 = CIFSGetSrvInodeNumber(xid, pTcon,
491 full_path, &inode_num,
474 cifs_sb->local_nls, 492 cifs_sb->local_nls,
475 cifs_sb->mnt_cifs_flags & 493 cifs_sb->mnt_cifs_flags &
476 CIFS_MOUNT_MAP_SPECIAL_CHR); 494 CIFS_MOUNT_MAP_SPECIAL_CHR);
477 if (rc1) { 495 if (rc1) {
478 cFYI(1, ("GetSrvInodeNum rc %d", rc1)); 496 cFYI(1, ("GetSrvInodeNum rc %d", rc1));
479 /* BB EOPNOSUPP disable SERVER_INUM? */ 497 /* BB EOPNOSUPP disable SERVER_INUM? */
480 } else /* do we need cast or hash to ino? */ 498 } else /* do we need cast or hash to ino? */
481 (*pinode)->i_ino = inode_num; 499 (*pinode)->i_ino = inode_num;
482 } /* else ino incremented to unique num in new_inode*/ 500 } /* else ino incremented to unique num in new_inode*/
483 if (sb->s_flags & MS_NOATIME) 501 if (sb->s_flags & MS_NOATIME)
484 (*pinode)->i_flags |= S_NOATIME | S_NOCMTIME; 502 (*pinode)->i_flags |= S_NOATIME | S_NOCMTIME;
485 insert_inode_hash(*pinode); 503 insert_inode_hash(*pinode);
486 } 504 }
487 inode = *pinode; 505 inode = *pinode;
488 cifsInfo = CIFS_I(inode); 506 cifsInfo = CIFS_I(inode);
489 cifsInfo->cifsAttrs = attr; 507 cifsInfo->cifsAttrs = attr;
490 cFYI(1, ("Old time %ld", cifsInfo->time)); 508 cFYI(1, ("Old time %ld", cifsInfo->time));
491 cifsInfo->time = jiffies; 509 cifsInfo->time = jiffies;
492 cFYI(1, ("New time %ld", cifsInfo->time)); 510 cFYI(1, ("New time %ld", cifsInfo->time));
493 511
494 /* blksize needs to be multiple of two. So safer to default to 512 /* blksize needs to be multiple of two. So safer to default to
495 blksize and blkbits set in superblock so 2**blkbits and blksize 513 blksize and blkbits set in superblock so 2**blkbits and blksize
496 will match rather than setting to: 514 will match rather than setting to:
497 (pTcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFE00;*/ 515 (pTcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFE00;*/
498 516
499 /* Linux can not store file creation time so ignore it */ 517 /* Linux can not store file creation time so ignore it */
500 if (pfindData->LastAccessTime) 518 if (pfindData->LastAccessTime)
501 inode->i_atime = cifs_NTtimeToUnix 519 inode->i_atime = cifs_NTtimeToUnix
502 (le64_to_cpu(pfindData->LastAccessTime)); 520 (le64_to_cpu(pfindData->LastAccessTime));
503 else /* do not need to use current_fs_time - time not stored */ 521 else /* do not need to use current_fs_time - time not stored */
504 inode->i_atime = CURRENT_TIME; 522 inode->i_atime = CURRENT_TIME;
505 inode->i_mtime = 523 inode->i_mtime =
506 cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastWriteTime)); 524 cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastWriteTime));
507 inode->i_ctime = 525 inode->i_ctime =
508 cifs_NTtimeToUnix(le64_to_cpu(pfindData->ChangeTime)); 526 cifs_NTtimeToUnix(le64_to_cpu(pfindData->ChangeTime));
509 cFYI(0, ("Attributes came in as 0x%x", attr)); 527 cFYI(DBG2, ("Attributes came in as 0x%x", attr));
510 if (adjustTZ && (pTcon->ses) && (pTcon->ses->server)) { 528 if (adjustTZ && (pTcon->ses) && (pTcon->ses->server)) {
511 inode->i_ctime.tv_sec += pTcon->ses->server->timeAdj; 529 inode->i_ctime.tv_sec += pTcon->ses->server->timeAdj;
512 inode->i_mtime.tv_sec += pTcon->ses->server->timeAdj; 530 inode->i_mtime.tv_sec += pTcon->ses->server->timeAdj;
513 } 531 }
514 532
515 /* set default mode. will override for dirs below */ 533 /* set default mode. will override for dirs below */
516 if (atomic_read(&cifsInfo->inUse) == 0) 534 if (atomic_read(&cifsInfo->inUse) == 0)
517 /* new inode, can safely set these fields */ 535 /* new inode, can safely set these fields */
518 inode->i_mode = cifs_sb->mnt_file_mode; 536 inode->i_mode = cifs_sb->mnt_file_mode;
519 else /* since we set the inode type below we need to mask off 537 else /* since we set the inode type below we need to mask off
520 to avoid strange results if type changes and both 538 to avoid strange results if type changes and both
521 get orred in */ 539 get orred in */
522 inode->i_mode &= ~S_IFMT; 540 inode->i_mode &= ~S_IFMT;
523/* if (attr & ATTR_REPARSE) */ 541/* if (attr & ATTR_REPARSE) */
524 /* We no longer handle these as symlinks because we could not 542 /* We no longer handle these as symlinks because we could not
525 follow them due to the absolute path with drive letter */ 543 follow them due to the absolute path with drive letter */
526 if (attr & ATTR_DIRECTORY) { 544 if (attr & ATTR_DIRECTORY) {
527 /* override default perms since we do not do byte range locking 545 /* override default perms since we do not do byte range locking
528 on dirs */ 546 on dirs */
529 inode->i_mode = cifs_sb->mnt_dir_mode; 547 inode->i_mode = cifs_sb->mnt_dir_mode;
530 inode->i_mode |= S_IFDIR; 548 inode->i_mode |= S_IFDIR;
531 } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) && 549 } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) &&
532 (cifsInfo->cifsAttrs & ATTR_SYSTEM) && 550 (cifsInfo->cifsAttrs & ATTR_SYSTEM) &&
533 /* No need to le64 convert size of zero */ 551 /* No need to le64 convert size of zero */
534 (pfindData->EndOfFile == 0)) { 552 (pfindData->EndOfFile == 0)) {
535 inode->i_mode = cifs_sb->mnt_file_mode; 553 inode->i_mode = cifs_sb->mnt_file_mode;
536 inode->i_mode |= S_IFIFO; 554 inode->i_mode |= S_IFIFO;
537/* BB Finish for SFU style symlinks and devices */ 555/* BB Finish for SFU style symlinks and devices */
538 } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) && 556 } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) &&
539 (cifsInfo->cifsAttrs & ATTR_SYSTEM)) { 557 (cifsInfo->cifsAttrs & ATTR_SYSTEM)) {
540 if (decode_sfu_inode(inode, 558 if (decode_sfu_inode(inode, le64_to_cpu(pfindData->EndOfFile),
541 le64_to_cpu(pfindData->EndOfFile), 559 full_path, cifs_sb, xid))
542 search_path, 560 cFYI(1, ("Unrecognized sfu inode type"));
543 cifs_sb, xid))
544 cFYI(1, ("Unrecognized sfu inode type"));
545
546 cFYI(1, ("sfu mode 0%o", inode->i_mode));
547 } else {
548 inode->i_mode |= S_IFREG;
549 /* treat the dos attribute of read-only as read-only
550 mode e.g. 555 */
551 if (cifsInfo->cifsAttrs & ATTR_READONLY)
552 inode->i_mode &= ~(S_IWUGO);
553 else if ((inode->i_mode & S_IWUGO) == 0)
554 /* the ATTR_READONLY flag may have been */
555 /* changed on server -- set any w bits */
556 /* allowed by mnt_file_mode */
557 inode->i_mode |= (S_IWUGO &
558 cifs_sb->mnt_file_mode);
559 /* BB add code here -
560 validate if device or weird share or device type? */
561 }
562 561
563 spin_lock(&inode->i_lock); 562 cFYI(1, ("sfu mode 0%o", inode->i_mode));
564 if (is_size_safe_to_change(cifsInfo, 563 } else {
565 le64_to_cpu(pfindData->EndOfFile))) { 564 inode->i_mode |= S_IFREG;
566 /* can not safely shrink the file size here if the 565 /* treat dos attribute of read-only as read-only mode eg 555 */
567 client is writing to it due to potential races */ 566 if (cifsInfo->cifsAttrs & ATTR_READONLY)
568 i_size_write(inode, le64_to_cpu(pfindData->EndOfFile)); 567 inode->i_mode &= ~(S_IWUGO);
569 568 else if ((inode->i_mode & S_IWUGO) == 0)
570 /* 512 bytes (2**9) is the fake blocksize that must be 569 /* the ATTR_READONLY flag may have been */
571 used for this calculation */ 570 /* changed on server -- set any w bits */
572 inode->i_blocks = (512 - 1 + le64_to_cpu( 571 /* allowed by mnt_file_mode */
573 pfindData->AllocationSize)) >> 9; 572 inode->i_mode |= (S_IWUGO & cifs_sb->mnt_file_mode);
574 } 573 /* BB add code to validate if device or weird share or device type? */
575 spin_unlock(&inode->i_lock); 574 }
575
576 spin_lock(&inode->i_lock);
577 if (is_size_safe_to_change(cifsInfo,
578 le64_to_cpu(pfindData->EndOfFile))) {
579 /* can not safely shrink the file size here if the
580 client is writing to it due to potential races */
581 i_size_write(inode, le64_to_cpu(pfindData->EndOfFile));
582
583 /* 512 bytes (2**9) is the fake blocksize that must be
584 used for this calculation */
585 inode->i_blocks = (512 - 1 + le64_to_cpu(
586 pfindData->AllocationSize)) >> 9;
587 }
588 spin_unlock(&inode->i_lock);
576 589
577 inode->i_nlink = le32_to_cpu(pfindData->NumberOfLinks); 590 inode->i_nlink = le32_to_cpu(pfindData->NumberOfLinks);
578 591
579 /* BB fill in uid and gid here? with help from winbind? 592 /* BB fill in uid and gid here? with help from winbind?
580 or retrieve from NTFS stream extended attribute */ 593 or retrieve from NTFS stream extended attribute */
581#ifdef CONFIG_CIFS_EXPERIMENTAL 594#ifdef CONFIG_CIFS_EXPERIMENTAL
582 /* fill in 0777 bits from ACL */ 595 /* fill in 0777 bits from ACL */
583 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) { 596 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
584 cFYI(1, ("Getting mode bits from ACL")); 597 cFYI(1, ("Getting mode bits from ACL"));
585 acl_to_uid_mode(inode, search_path, pfid); 598 acl_to_uid_mode(inode, full_path, pfid);
586 } 599 }
587#endif 600#endif
588 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) { 601 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
589 /* fill in remaining high mode bits e.g. SUID, VTX */ 602 /* fill in remaining high mode bits e.g. SUID, VTX */
590 get_sfu_mode(inode, search_path, cifs_sb, xid); 603 get_sfu_mode(inode, full_path, cifs_sb, xid);
591 } else if (atomic_read(&cifsInfo->inUse) == 0) { 604 } else if (atomic_read(&cifsInfo->inUse) == 0) {
592 inode->i_uid = cifs_sb->mnt_uid; 605 inode->i_uid = cifs_sb->mnt_uid;
593 inode->i_gid = cifs_sb->mnt_gid; 606 inode->i_gid = cifs_sb->mnt_gid;
594 /* set so we do not keep refreshing these fields with 607 /* set so we do not keep refreshing these fields with
595 bad data after user has changed them in memory */ 608 bad data after user has changed them in memory */
596 atomic_set(&cifsInfo->inUse, 1); 609 atomic_set(&cifsInfo->inUse, 1);
597 }
598
599 cifs_set_ops(inode, is_dfs_referral);
600 } 610 }
611
612 cifs_set_ops(inode, is_dfs_referral);
613
614
615
616
601cgii_exit: 617cgii_exit:
602 if (full_path != search_path)
603 kfree(full_path);
604 kfree(buf); 618 kfree(buf);
605 return rc; 619 return rc;
606} 620}
@@ -1502,8 +1516,7 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
1502 int oplock = 0; 1516 int oplock = 0;
1503 1517
1504 rc = SMBLegacyOpen(xid, pTcon, full_path, 1518 rc = SMBLegacyOpen(xid, pTcon, full_path,
1505 FILE_OPEN, 1519 FILE_OPEN, GENERIC_WRITE,
1506 SYNCHRONIZE | FILE_WRITE_ATTRIBUTES,
1507 CREATE_NOT_DIR, &netfid, &oplock, 1520 CREATE_NOT_DIR, &netfid, &oplock,
1508 NULL, cifs_sb->local_nls, 1521 NULL, cifs_sb->local_nls,
1509 cifs_sb->mnt_cifs_flags & 1522 cifs_sb->mnt_cifs_flags &