PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/fs/cifs/dir.c

https://github.com/mstsirkin/linux
C | 719 lines | 520 code | 76 blank | 123 comment | 149 complexity | d5332bc16d6e2ec572774a62ee34338e MD5 | raw file
  1. /*
  2. * fs/cifs/dir.c
  3. *
  4. * vfs operations that deal with dentries
  5. *
  6. * Copyright (C) International Business Machines Corp., 2002,2009
  7. * Author(s): Steve French (sfrench@us.ibm.com)
  8. *
  9. * This library is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU Lesser General Public License as published
  11. * by the Free Software Foundation; either version 2.1 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  17. * the GNU Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <linux/fs.h>
  24. #include <linux/stat.h>
  25. #include <linux/slab.h>
  26. #include <linux/namei.h>
  27. #include <linux/mount.h>
  28. #include <linux/file.h>
  29. #include "cifsfs.h"
  30. #include "cifspdu.h"
  31. #include "cifsglob.h"
  32. #include "cifsproto.h"
  33. #include "cifs_debug.h"
  34. #include "cifs_fs_sb.h"
  35. static void
  36. renew_parental_timestamps(struct dentry *direntry)
  37. {
  38. /* BB check if there is a way to get the kernel to do this or if we
  39. really need this */
  40. do {
  41. direntry->d_time = jiffies;
  42. direntry = direntry->d_parent;
  43. } while (!IS_ROOT(direntry));
  44. }
  45. /* Note: caller must free return buffer */
  46. char *
  47. build_path_from_dentry(struct dentry *direntry)
  48. {
  49. struct dentry *temp;
  50. int namelen;
  51. int dfsplen;
  52. char *full_path;
  53. char dirsep;
  54. struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
  55. struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
  56. unsigned seq;
  57. dirsep = CIFS_DIR_SEP(cifs_sb);
  58. if (tcon->Flags & SMB_SHARE_IS_IN_DFS)
  59. dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
  60. else
  61. dfsplen = 0;
  62. cifs_bp_rename_retry:
  63. namelen = dfsplen;
  64. seq = read_seqbegin(&rename_lock);
  65. rcu_read_lock();
  66. for (temp = direntry; !IS_ROOT(temp);) {
  67. namelen += (1 + temp->d_name.len);
  68. temp = temp->d_parent;
  69. if (temp == NULL) {
  70. cERROR(1, "corrupt dentry");
  71. rcu_read_unlock();
  72. return NULL;
  73. }
  74. }
  75. rcu_read_unlock();
  76. full_path = kmalloc(namelen+1, GFP_KERNEL);
  77. if (full_path == NULL)
  78. return full_path;
  79. full_path[namelen] = 0; /* trailing null */
  80. rcu_read_lock();
  81. for (temp = direntry; !IS_ROOT(temp);) {
  82. spin_lock(&temp->d_lock);
  83. namelen -= 1 + temp->d_name.len;
  84. if (namelen < 0) {
  85. spin_unlock(&temp->d_lock);
  86. break;
  87. } else {
  88. full_path[namelen] = dirsep;
  89. strncpy(full_path + namelen + 1, temp->d_name.name,
  90. temp->d_name.len);
  91. cFYI(0, "name: %s", full_path + namelen);
  92. }
  93. spin_unlock(&temp->d_lock);
  94. temp = temp->d_parent;
  95. if (temp == NULL) {
  96. cERROR(1, "corrupt dentry");
  97. rcu_read_unlock();
  98. kfree(full_path);
  99. return NULL;
  100. }
  101. }
  102. rcu_read_unlock();
  103. if (namelen != dfsplen || read_seqretry(&rename_lock, seq)) {
  104. cFYI(1, "did not end path lookup where expected. namelen=%d "
  105. "dfsplen=%d", namelen, dfsplen);
  106. /* presumably this is only possible if racing with a rename
  107. of one of the parent directories (we can not lock the dentries
  108. above us to prevent this, but retrying should be harmless) */
  109. kfree(full_path);
  110. goto cifs_bp_rename_retry;
  111. }
  112. /* DIR_SEP already set for byte 0 / vs \ but not for
  113. subsequent slashes in prepath which currently must
  114. be entered the right way - not sure if there is an alternative
  115. since the '\' is a valid posix character so we can not switch
  116. those safely to '/' if any are found in the middle of the prepath */
  117. /* BB test paths to Windows with '/' in the midst of prepath */
  118. if (dfsplen) {
  119. strncpy(full_path, tcon->treeName, dfsplen);
  120. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) {
  121. int i;
  122. for (i = 0; i < dfsplen; i++) {
  123. if (full_path[i] == '\\')
  124. full_path[i] = '/';
  125. }
  126. }
  127. }
  128. return full_path;
  129. }
  130. /* Inode operations in similar order to how they appear in Linux file fs.h */
  131. int
  132. cifs_create(struct inode *inode, struct dentry *direntry, int mode,
  133. struct nameidata *nd)
  134. {
  135. int rc = -ENOENT;
  136. int xid;
  137. int create_options = CREATE_NOT_DIR;
  138. __u32 oplock = 0;
  139. int oflags;
  140. /*
  141. * BB below access is probably too much for mknod to request
  142. * but we have to do query and setpathinfo so requesting
  143. * less could fail (unless we want to request getatr and setatr
  144. * permissions (only). At least for POSIX we do not have to
  145. * request so much.
  146. */
  147. int desiredAccess = GENERIC_READ | GENERIC_WRITE;
  148. __u16 fileHandle;
  149. struct cifs_sb_info *cifs_sb;
  150. struct tcon_link *tlink;
  151. struct cifs_tcon *tcon;
  152. char *full_path = NULL;
  153. FILE_ALL_INFO *buf = NULL;
  154. struct inode *newinode = NULL;
  155. int disposition = FILE_OVERWRITE_IF;
  156. xid = GetXid();
  157. cifs_sb = CIFS_SB(inode->i_sb);
  158. tlink = cifs_sb_tlink(cifs_sb);
  159. if (IS_ERR(tlink)) {
  160. FreeXid(xid);
  161. return PTR_ERR(tlink);
  162. }
  163. tcon = tlink_tcon(tlink);
  164. if (oplockEnabled)
  165. oplock = REQ_OPLOCK;
  166. if (nd)
  167. oflags = nd->intent.open.file->f_flags;
  168. else
  169. oflags = O_RDONLY | O_CREAT;
  170. full_path = build_path_from_dentry(direntry);
  171. if (full_path == NULL) {
  172. rc = -ENOMEM;
  173. goto cifs_create_out;
  174. }
  175. if (tcon->unix_ext && (tcon->ses->capabilities & CAP_UNIX) &&
  176. (CIFS_UNIX_POSIX_PATH_OPS_CAP &
  177. le64_to_cpu(tcon->fsUnixInfo.Capability))) {
  178. rc = cifs_posix_open(full_path, &newinode,
  179. inode->i_sb, mode, oflags, &oplock, &fileHandle, xid);
  180. /* EIO could indicate that (posix open) operation is not
  181. supported, despite what server claimed in capability
  182. negotiation. EREMOTE indicates DFS junction, which is not
  183. handled in posix open */
  184. if (rc == 0) {
  185. if (newinode == NULL) /* query inode info */
  186. goto cifs_create_get_file_info;
  187. else /* success, no need to query */
  188. goto cifs_create_set_dentry;
  189. } else if ((rc != -EIO) && (rc != -EREMOTE) &&
  190. (rc != -EOPNOTSUPP) && (rc != -EINVAL))
  191. goto cifs_create_out;
  192. /* else fallthrough to retry, using older open call, this is
  193. case where server does not support this SMB level, and
  194. falsely claims capability (also get here for DFS case
  195. which should be rare for path not covered on files) */
  196. }
  197. if (nd) {
  198. /* if the file is going to stay open, then we
  199. need to set the desired access properly */
  200. desiredAccess = 0;
  201. if (OPEN_FMODE(oflags) & FMODE_READ)
  202. desiredAccess |= GENERIC_READ; /* is this too little? */
  203. if (OPEN_FMODE(oflags) & FMODE_WRITE)
  204. desiredAccess |= GENERIC_WRITE;
  205. if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
  206. disposition = FILE_CREATE;
  207. else if ((oflags & (O_CREAT | O_TRUNC)) == (O_CREAT | O_TRUNC))
  208. disposition = FILE_OVERWRITE_IF;
  209. else if ((oflags & O_CREAT) == O_CREAT)
  210. disposition = FILE_OPEN_IF;
  211. else
  212. cFYI(1, "Create flag not set in create function");
  213. }
  214. /* BB add processing to set equivalent of mode - e.g. via CreateX with
  215. ACLs */
  216. buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
  217. if (buf == NULL) {
  218. rc = -ENOMEM;
  219. goto cifs_create_out;
  220. }
  221. /*
  222. * if we're not using unix extensions, see if we need to set
  223. * ATTR_READONLY on the create call
  224. */
  225. if (!tcon->unix_ext && (mode & S_IWUGO) == 0)
  226. create_options |= CREATE_OPTION_READONLY;
  227. if (tcon->ses->capabilities & CAP_NT_SMBS)
  228. rc = CIFSSMBOpen(xid, tcon, full_path, disposition,
  229. desiredAccess, create_options,
  230. &fileHandle, &oplock, buf, cifs_sb->local_nls,
  231. cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
  232. else
  233. rc = -EIO; /* no NT SMB support fall into legacy open below */
  234. if (rc == -EIO) {
  235. /* old server, retry the open legacy style */
  236. rc = SMBLegacyOpen(xid, tcon, full_path, disposition,
  237. desiredAccess, create_options,
  238. &fileHandle, &oplock, buf, cifs_sb->local_nls,
  239. cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
  240. }
  241. if (rc) {
  242. cFYI(1, "cifs_create returned 0x%x", rc);
  243. goto cifs_create_out;
  244. }
  245. /* If Open reported that we actually created a file
  246. then we now have to set the mode if possible */
  247. if ((tcon->unix_ext) && (oplock & CIFS_CREATE_ACTION)) {
  248. struct cifs_unix_set_info_args args = {
  249. .mode = mode,
  250. .ctime = NO_CHANGE_64,
  251. .atime = NO_CHANGE_64,
  252. .mtime = NO_CHANGE_64,
  253. .device = 0,
  254. };
  255. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
  256. args.uid = (__u64) current_fsuid();
  257. if (inode->i_mode & S_ISGID)
  258. args.gid = (__u64) inode->i_gid;
  259. else
  260. args.gid = (__u64) current_fsgid();
  261. } else {
  262. args.uid = NO_CHANGE_64;
  263. args.gid = NO_CHANGE_64;
  264. }
  265. CIFSSMBUnixSetFileInfo(xid, tcon, &args, fileHandle,
  266. current->tgid);
  267. } else {
  268. /* BB implement mode setting via Windows security
  269. descriptors e.g. */
  270. /* CIFSSMBWinSetPerms(xid,tcon,path,mode,-1,-1,nls);*/
  271. /* Could set r/o dos attribute if mode & 0222 == 0 */
  272. }
  273. cifs_create_get_file_info:
  274. /* server might mask mode so we have to query for it */
  275. if (tcon->unix_ext)
  276. rc = cifs_get_inode_info_unix(&newinode, full_path,
  277. inode->i_sb, xid);
  278. else {
  279. rc = cifs_get_inode_info(&newinode, full_path, buf,
  280. inode->i_sb, xid, &fileHandle);
  281. if (newinode) {
  282. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
  283. newinode->i_mode = mode;
  284. if ((oplock & CIFS_CREATE_ACTION) &&
  285. (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)) {
  286. newinode->i_uid = current_fsuid();
  287. if (inode->i_mode & S_ISGID)
  288. newinode->i_gid = inode->i_gid;
  289. else
  290. newinode->i_gid = current_fsgid();
  291. }
  292. }
  293. }
  294. cifs_create_set_dentry:
  295. if (rc == 0)
  296. d_instantiate(direntry, newinode);
  297. else
  298. cFYI(1, "Create worked, get_inode_info failed rc = %d", rc);
  299. if (newinode && nd) {
  300. struct cifsFileInfo *pfile_info;
  301. struct file *filp;
  302. filp = lookup_instantiate_filp(nd, direntry, generic_file_open);
  303. if (IS_ERR(filp)) {
  304. rc = PTR_ERR(filp);
  305. CIFSSMBClose(xid, tcon, fileHandle);
  306. goto cifs_create_out;
  307. }
  308. pfile_info = cifs_new_fileinfo(fileHandle, filp, tlink, oplock);
  309. if (pfile_info == NULL) {
  310. fput(filp);
  311. CIFSSMBClose(xid, tcon, fileHandle);
  312. rc = -ENOMEM;
  313. }
  314. } else {
  315. CIFSSMBClose(xid, tcon, fileHandle);
  316. }
  317. cifs_create_out:
  318. kfree(buf);
  319. kfree(full_path);
  320. cifs_put_tlink(tlink);
  321. FreeXid(xid);
  322. return rc;
  323. }
  324. int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode,
  325. dev_t device_number)
  326. {
  327. int rc = -EPERM;
  328. int xid;
  329. struct cifs_sb_info *cifs_sb;
  330. struct tcon_link *tlink;
  331. struct cifs_tcon *pTcon;
  332. struct cifs_io_parms io_parms;
  333. char *full_path = NULL;
  334. struct inode *newinode = NULL;
  335. int oplock = 0;
  336. u16 fileHandle;
  337. FILE_ALL_INFO *buf = NULL;
  338. unsigned int bytes_written;
  339. struct win_dev *pdev;
  340. if (!old_valid_dev(device_number))
  341. return -EINVAL;
  342. cifs_sb = CIFS_SB(inode->i_sb);
  343. tlink = cifs_sb_tlink(cifs_sb);
  344. if (IS_ERR(tlink))
  345. return PTR_ERR(tlink);
  346. pTcon = tlink_tcon(tlink);
  347. xid = GetXid();
  348. full_path = build_path_from_dentry(direntry);
  349. if (full_path == NULL) {
  350. rc = -ENOMEM;
  351. goto mknod_out;
  352. }
  353. if (pTcon->unix_ext) {
  354. struct cifs_unix_set_info_args args = {
  355. .mode = mode & ~current_umask(),
  356. .ctime = NO_CHANGE_64,
  357. .atime = NO_CHANGE_64,
  358. .mtime = NO_CHANGE_64,
  359. .device = device_number,
  360. };
  361. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
  362. args.uid = (__u64) current_fsuid();
  363. args.gid = (__u64) current_fsgid();
  364. } else {
  365. args.uid = NO_CHANGE_64;
  366. args.gid = NO_CHANGE_64;
  367. }
  368. rc = CIFSSMBUnixSetPathInfo(xid, pTcon, full_path, &args,
  369. cifs_sb->local_nls,
  370. cifs_sb->mnt_cifs_flags &
  371. CIFS_MOUNT_MAP_SPECIAL_CHR);
  372. if (rc)
  373. goto mknod_out;
  374. rc = cifs_get_inode_info_unix(&newinode, full_path,
  375. inode->i_sb, xid);
  376. if (rc == 0)
  377. d_instantiate(direntry, newinode);
  378. goto mknod_out;
  379. }
  380. if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
  381. goto mknod_out;
  382. cFYI(1, "sfu compat create special file");
  383. buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
  384. if (buf == NULL) {
  385. kfree(full_path);
  386. rc = -ENOMEM;
  387. FreeXid(xid);
  388. return rc;
  389. }
  390. /* FIXME: would WRITE_OWNER | WRITE_DAC be better? */
  391. rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_CREATE,
  392. GENERIC_WRITE, CREATE_NOT_DIR | CREATE_OPTION_SPECIAL,
  393. &fileHandle, &oplock, buf, cifs_sb->local_nls,
  394. cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
  395. if (rc)
  396. goto mknod_out;
  397. /* BB Do not bother to decode buf since no local inode yet to put
  398. * timestamps in, but we can reuse it safely */
  399. pdev = (struct win_dev *)buf;
  400. io_parms.netfid = fileHandle;
  401. io_parms.pid = current->tgid;
  402. io_parms.tcon = pTcon;
  403. io_parms.offset = 0;
  404. io_parms.length = sizeof(struct win_dev);
  405. if (S_ISCHR(mode)) {
  406. memcpy(pdev->type, "IntxCHR", 8);
  407. pdev->major =
  408. cpu_to_le64(MAJOR(device_number));
  409. pdev->minor =
  410. cpu_to_le64(MINOR(device_number));
  411. rc = CIFSSMBWrite(xid, &io_parms,
  412. &bytes_written, (char *)pdev,
  413. NULL, 0);
  414. } else if (S_ISBLK(mode)) {
  415. memcpy(pdev->type, "IntxBLK", 8);
  416. pdev->major =
  417. cpu_to_le64(MAJOR(device_number));
  418. pdev->minor =
  419. cpu_to_le64(MINOR(device_number));
  420. rc = CIFSSMBWrite(xid, &io_parms,
  421. &bytes_written, (char *)pdev,
  422. NULL, 0);
  423. } /* else if (S_ISFIFO) */
  424. CIFSSMBClose(xid, pTcon, fileHandle);
  425. d_drop(direntry);
  426. /* FIXME: add code here to set EAs */
  427. mknod_out:
  428. kfree(full_path);
  429. kfree(buf);
  430. FreeXid(xid);
  431. cifs_put_tlink(tlink);
  432. return rc;
  433. }
  434. struct dentry *
  435. cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
  436. struct nameidata *nd)
  437. {
  438. int xid;
  439. int rc = 0; /* to get around spurious gcc warning, set to zero here */
  440. __u32 oplock = 0;
  441. __u16 fileHandle = 0;
  442. bool posix_open = false;
  443. struct cifs_sb_info *cifs_sb;
  444. struct tcon_link *tlink;
  445. struct cifs_tcon *pTcon;
  446. struct cifsFileInfo *cfile;
  447. struct inode *newInode = NULL;
  448. char *full_path = NULL;
  449. struct file *filp;
  450. xid = GetXid();
  451. cFYI(1, "parent inode = 0x%p name is: %s and dentry = 0x%p",
  452. parent_dir_inode, direntry->d_name.name, direntry);
  453. /* check whether path exists */
  454. cifs_sb = CIFS_SB(parent_dir_inode->i_sb);
  455. tlink = cifs_sb_tlink(cifs_sb);
  456. if (IS_ERR(tlink)) {
  457. FreeXid(xid);
  458. return (struct dentry *)tlink;
  459. }
  460. pTcon = tlink_tcon(tlink);
  461. /*
  462. * Don't allow the separator character in a path component.
  463. * The VFS will not allow "/", but "\" is allowed by posix.
  464. */
  465. if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)) {
  466. int i;
  467. for (i = 0; i < direntry->d_name.len; i++)
  468. if (direntry->d_name.name[i] == '\\') {
  469. cFYI(1, "Invalid file name");
  470. rc = -EINVAL;
  471. goto lookup_out;
  472. }
  473. }
  474. /*
  475. * O_EXCL: optimize away the lookup, but don't hash the dentry. Let
  476. * the VFS handle the create.
  477. */
  478. if (nd && (nd->flags & LOOKUP_EXCL)) {
  479. d_instantiate(direntry, NULL);
  480. rc = 0;
  481. goto lookup_out;
  482. }
  483. /* can not grab the rename sem here since it would
  484. deadlock in the cases (beginning of sys_rename itself)
  485. in which we already have the sb rename sem */
  486. full_path = build_path_from_dentry(direntry);
  487. if (full_path == NULL) {
  488. rc = -ENOMEM;
  489. goto lookup_out;
  490. }
  491. if (direntry->d_inode != NULL) {
  492. cFYI(1, "non-NULL inode in lookup");
  493. } else {
  494. cFYI(1, "NULL inode in lookup");
  495. }
  496. cFYI(1, "Full path: %s inode = 0x%p", full_path, direntry->d_inode);
  497. /* Posix open is only called (at lookup time) for file create now.
  498. * For opens (rather than creates), because we do not know if it
  499. * is a file or directory yet, and current Samba no longer allows
  500. * us to do posix open on dirs, we could end up wasting an open call
  501. * on what turns out to be a dir. For file opens, we wait to call posix
  502. * open till cifs_open. It could be added here (lookup) in the future
  503. * but the performance tradeoff of the extra network request when EISDIR
  504. * or EACCES is returned would have to be weighed against the 50%
  505. * reduction in network traffic in the other paths.
  506. */
  507. if (pTcon->unix_ext) {
  508. if (nd && !(nd->flags & LOOKUP_DIRECTORY) &&
  509. (nd->flags & LOOKUP_OPEN) && !pTcon->broken_posix_open &&
  510. (nd->intent.open.file->f_flags & O_CREAT)) {
  511. rc = cifs_posix_open(full_path, &newInode,
  512. parent_dir_inode->i_sb,
  513. nd->intent.open.create_mode,
  514. nd->intent.open.file->f_flags, &oplock,
  515. &fileHandle, xid);
  516. /*
  517. * The check below works around a bug in POSIX
  518. * open in samba versions 3.3.1 and earlier where
  519. * open could incorrectly fail with invalid parameter.
  520. * If either that or op not supported returned, follow
  521. * the normal lookup.
  522. */
  523. if ((rc == 0) || (rc == -ENOENT))
  524. posix_open = true;
  525. else if ((rc == -EINVAL) || (rc != -EOPNOTSUPP))
  526. pTcon->broken_posix_open = true;
  527. }
  528. if (!posix_open)
  529. rc = cifs_get_inode_info_unix(&newInode, full_path,
  530. parent_dir_inode->i_sb, xid);
  531. } else
  532. rc = cifs_get_inode_info(&newInode, full_path, NULL,
  533. parent_dir_inode->i_sb, xid, NULL);
  534. if ((rc == 0) && (newInode != NULL)) {
  535. d_add(direntry, newInode);
  536. if (posix_open) {
  537. filp = lookup_instantiate_filp(nd, direntry,
  538. generic_file_open);
  539. if (IS_ERR(filp)) {
  540. rc = PTR_ERR(filp);
  541. CIFSSMBClose(xid, pTcon, fileHandle);
  542. goto lookup_out;
  543. }
  544. cfile = cifs_new_fileinfo(fileHandle, filp, tlink,
  545. oplock);
  546. if (cfile == NULL) {
  547. fput(filp);
  548. CIFSSMBClose(xid, pTcon, fileHandle);
  549. rc = -ENOMEM;
  550. goto lookup_out;
  551. }
  552. }
  553. /* since paths are not looked up by component - the parent
  554. directories are presumed to be good here */
  555. renew_parental_timestamps(direntry);
  556. } else if (rc == -ENOENT) {
  557. rc = 0;
  558. direntry->d_time = jiffies;
  559. d_add(direntry, NULL);
  560. /* if it was once a directory (but how can we tell?) we could do
  561. shrink_dcache_parent(direntry); */
  562. } else if (rc != -EACCES) {
  563. cERROR(1, "Unexpected lookup error %d", rc);
  564. /* We special case check for Access Denied - since that
  565. is a common return code */
  566. }
  567. lookup_out:
  568. kfree(full_path);
  569. cifs_put_tlink(tlink);
  570. FreeXid(xid);
  571. return ERR_PTR(rc);
  572. }
  573. static int
  574. cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd)
  575. {
  576. if (nd && (nd->flags & LOOKUP_RCU))
  577. return -ECHILD;
  578. if (direntry->d_inode) {
  579. if (cifs_revalidate_dentry(direntry))
  580. return 0;
  581. else
  582. return 1;
  583. }
  584. /*
  585. * This may be nfsd (or something), anyway, we can't see the
  586. * intent of this. So, since this can be for creation, drop it.
  587. */
  588. if (!nd)
  589. return 0;
  590. /*
  591. * Drop the negative dentry, in order to make sure to use the
  592. * case sensitive name which is specified by user if this is
  593. * for creation.
  594. */
  595. if (nd->flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET))
  596. return 0;
  597. if (time_after(jiffies, direntry->d_time + HZ) || !lookupCacheEnabled)
  598. return 0;
  599. return 1;
  600. }
  601. /* static int cifs_d_delete(struct dentry *direntry)
  602. {
  603. int rc = 0;
  604. cFYI(1, "In cifs d_delete, name = %s", direntry->d_name.name);
  605. return rc;
  606. } */
  607. const struct dentry_operations cifs_dentry_ops = {
  608. .d_revalidate = cifs_d_revalidate,
  609. .d_automount = cifs_dfs_d_automount,
  610. /* d_delete: cifs_d_delete, */ /* not needed except for debugging */
  611. };
  612. static int cifs_ci_hash(const struct dentry *dentry, const struct inode *inode,
  613. struct qstr *q)
  614. {
  615. struct nls_table *codepage = CIFS_SB(dentry->d_sb)->local_nls;
  616. unsigned long hash;
  617. int i;
  618. hash = init_name_hash();
  619. for (i = 0; i < q->len; i++)
  620. hash = partial_name_hash(nls_tolower(codepage, q->name[i]),
  621. hash);
  622. q->hash = end_name_hash(hash);
  623. return 0;
  624. }
  625. static int cifs_ci_compare(const struct dentry *parent,
  626. const struct inode *pinode,
  627. const struct dentry *dentry, const struct inode *inode,
  628. unsigned int len, const char *str, const struct qstr *name)
  629. {
  630. struct nls_table *codepage = CIFS_SB(pinode->i_sb)->local_nls;
  631. if ((name->len == len) &&
  632. (nls_strnicmp(codepage, name->name, str, len) == 0))
  633. return 0;
  634. return 1;
  635. }
  636. const struct dentry_operations cifs_ci_dentry_ops = {
  637. .d_revalidate = cifs_d_revalidate,
  638. .d_hash = cifs_ci_hash,
  639. .d_compare = cifs_ci_compare,
  640. .d_automount = cifs_dfs_d_automount,
  641. };