dir.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /*
  2. * fs/cifs/dir.c
  3. *
  4. * vfs operations that deal with dentries
  5. *
  6. * Copyright (C) International Business Machines Corp., 2002,2008
  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 "cifsfs.h"
  28. #include "cifspdu.h"
  29. #include "cifsglob.h"
  30. #include "cifsproto.h"
  31. #include "cifs_debug.h"
  32. #include "cifs_fs_sb.h"
  33. static void
  34. renew_parental_timestamps(struct dentry *direntry)
  35. {
  36. /* BB check if there is a way to get the kernel to do this or if we
  37. really need this */
  38. do {
  39. direntry->d_time = jiffies;
  40. direntry = direntry->d_parent;
  41. } while (!IS_ROOT(direntry));
  42. }
  43. /* Note: caller must free return buffer */
  44. char *
  45. build_path_from_dentry(struct dentry *direntry)
  46. {
  47. struct dentry *temp;
  48. int namelen;
  49. int pplen;
  50. int dfsplen;
  51. char *full_path;
  52. char dirsep;
  53. struct cifs_sb_info *cifs_sb;
  54. if (direntry == NULL)
  55. return NULL; /* not much we can do if dentry is freed and
  56. we need to reopen the file after it was closed implicitly
  57. when the server crashed */
  58. cifs_sb = CIFS_SB(direntry->d_sb);
  59. dirsep = CIFS_DIR_SEP(cifs_sb);
  60. pplen = cifs_sb->prepathlen;
  61. if (cifs_sb->tcon && (cifs_sb->tcon->Flags & SMB_SHARE_IS_IN_DFS))
  62. dfsplen = strnlen(cifs_sb->tcon->treeName, MAX_TREE_SIZE + 1);
  63. else
  64. dfsplen = 0;
  65. cifs_bp_rename_retry:
  66. namelen = pplen + dfsplen;
  67. for (temp = direntry; !IS_ROOT(temp);) {
  68. namelen += (1 + temp->d_name.len);
  69. temp = temp->d_parent;
  70. if (temp == NULL) {
  71. cERROR(1, ("corrupt dentry"));
  72. return NULL;
  73. }
  74. }
  75. full_path = kmalloc(namelen+1, GFP_KERNEL);
  76. if (full_path == NULL)
  77. return full_path;
  78. full_path[namelen] = 0; /* trailing null */
  79. for (temp = direntry; !IS_ROOT(temp);) {
  80. namelen -= 1 + temp->d_name.len;
  81. if (namelen < 0) {
  82. break;
  83. } else {
  84. full_path[namelen] = dirsep;
  85. strncpy(full_path + namelen + 1, temp->d_name.name,
  86. temp->d_name.len);
  87. cFYI(0, ("name: %s", full_path + namelen));
  88. }
  89. temp = temp->d_parent;
  90. if (temp == NULL) {
  91. cERROR(1, ("corrupt dentry"));
  92. kfree(full_path);
  93. return NULL;
  94. }
  95. }
  96. if (namelen != pplen + dfsplen) {
  97. cERROR(1,
  98. ("did not end path lookup where expected namelen is %d",
  99. namelen));
  100. /* presumably this is only possible if racing with a rename
  101. of one of the parent directories (we can not lock the dentries
  102. above us to prevent this, but retrying should be harmless) */
  103. kfree(full_path);
  104. goto cifs_bp_rename_retry;
  105. }
  106. /* DIR_SEP already set for byte 0 / vs \ but not for
  107. subsequent slashes in prepath which currently must
  108. be entered the right way - not sure if there is an alternative
  109. since the '\' is a valid posix character so we can not switch
  110. those safely to '/' if any are found in the middle of the prepath */
  111. /* BB test paths to Windows with '/' in the midst of prepath */
  112. if (dfsplen) {
  113. strncpy(full_path, cifs_sb->tcon->treeName, dfsplen);
  114. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) {
  115. int i;
  116. for (i = 0; i < dfsplen; i++) {
  117. if (full_path[i] == '\\')
  118. full_path[i] = '/';
  119. }
  120. }
  121. }
  122. strncpy(full_path + dfsplen, CIFS_SB(direntry->d_sb)->prepath, pplen);
  123. return full_path;
  124. }
  125. /* Inode operations in similar order to how they appear in Linux file fs.h */
  126. int
  127. cifs_create(struct inode *inode, struct dentry *direntry, int mode,
  128. struct nameidata *nd)
  129. {
  130. int rc = -ENOENT;
  131. int xid;
  132. int create_options = CREATE_NOT_DIR;
  133. int oplock = 0;
  134. int desiredAccess = GENERIC_READ | GENERIC_WRITE;
  135. __u16 fileHandle;
  136. struct cifs_sb_info *cifs_sb;
  137. struct cifsTconInfo *pTcon;
  138. char *full_path = NULL;
  139. FILE_ALL_INFO *buf = NULL;
  140. struct inode *newinode = NULL;
  141. struct cifsFileInfo *pCifsFile = NULL;
  142. struct cifsInodeInfo *pCifsInode;
  143. int disposition = FILE_OVERWRITE_IF;
  144. bool write_only = false;
  145. xid = GetXid();
  146. cifs_sb = CIFS_SB(inode->i_sb);
  147. pTcon = cifs_sb->tcon;
  148. full_path = build_path_from_dentry(direntry);
  149. if (full_path == NULL) {
  150. FreeXid(xid);
  151. return -ENOMEM;
  152. }
  153. if (nd && (nd->flags & LOOKUP_OPEN)) {
  154. int oflags = nd->intent.open.flags;
  155. desiredAccess = 0;
  156. if (oflags & FMODE_READ)
  157. desiredAccess |= GENERIC_READ;
  158. if (oflags & FMODE_WRITE) {
  159. desiredAccess |= GENERIC_WRITE;
  160. if (!(oflags & FMODE_READ))
  161. write_only = true;
  162. }
  163. if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
  164. disposition = FILE_CREATE;
  165. else if ((oflags & (O_CREAT | O_TRUNC)) == (O_CREAT | O_TRUNC))
  166. disposition = FILE_OVERWRITE_IF;
  167. else if ((oflags & O_CREAT) == O_CREAT)
  168. disposition = FILE_OPEN_IF;
  169. else
  170. cFYI(1, ("Create flag not set in create function"));
  171. }
  172. /* BB add processing to set equivalent of mode - e.g. via CreateX with
  173. ACLs */
  174. if (oplockEnabled)
  175. oplock = REQ_OPLOCK;
  176. buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
  177. if (buf == NULL) {
  178. kfree(full_path);
  179. FreeXid(xid);
  180. return -ENOMEM;
  181. }
  182. mode &= ~current->fs->umask;
  183. /*
  184. * if we're not using unix extensions, see if we need to set
  185. * ATTR_READONLY on the create call
  186. */
  187. if (!pTcon->unix_ext && (mode & S_IWUGO) == 0)
  188. create_options |= CREATE_OPTION_READONLY;
  189. if (cifs_sb->tcon->ses->capabilities & CAP_NT_SMBS)
  190. rc = CIFSSMBOpen(xid, pTcon, full_path, disposition,
  191. desiredAccess, create_options,
  192. &fileHandle, &oplock, buf, cifs_sb->local_nls,
  193. cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
  194. else
  195. rc = -EIO; /* no NT SMB support fall into legacy open below */
  196. if (rc == -EIO) {
  197. /* old server, retry the open legacy style */
  198. rc = SMBLegacyOpen(xid, pTcon, full_path, disposition,
  199. desiredAccess, create_options,
  200. &fileHandle, &oplock, buf, cifs_sb->local_nls,
  201. cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
  202. }
  203. if (rc) {
  204. cFYI(1, ("cifs_create returned 0x%x", rc));
  205. } else {
  206. /* If Open reported that we actually created a file
  207. then we now have to set the mode if possible */
  208. if ((pTcon->unix_ext) && (oplock & CIFS_CREATE_ACTION)) {
  209. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
  210. CIFSSMBUnixSetPerms(xid, pTcon, full_path, mode,
  211. (__u64)current->fsuid,
  212. (__u64)current->fsgid,
  213. 0 /* dev */,
  214. cifs_sb->local_nls,
  215. cifs_sb->mnt_cifs_flags &
  216. CIFS_MOUNT_MAP_SPECIAL_CHR);
  217. } else {
  218. CIFSSMBUnixSetPerms(xid, pTcon, full_path, mode,
  219. (__u64)-1,
  220. (__u64)-1,
  221. 0 /* dev */,
  222. cifs_sb->local_nls,
  223. cifs_sb->mnt_cifs_flags &
  224. CIFS_MOUNT_MAP_SPECIAL_CHR);
  225. }
  226. } else {
  227. /* BB implement mode setting via Windows security
  228. descriptors e.g. */
  229. /* CIFSSMBWinSetPerms(xid,pTcon,path,mode,-1,-1,nls);*/
  230. /* Could set r/o dos attribute if mode & 0222 == 0 */
  231. }
  232. /* server might mask mode so we have to query for it */
  233. if (pTcon->unix_ext)
  234. rc = cifs_get_inode_info_unix(&newinode, full_path,
  235. inode->i_sb, xid);
  236. else {
  237. rc = cifs_get_inode_info(&newinode, full_path,
  238. buf, inode->i_sb, xid,
  239. &fileHandle);
  240. if (newinode) {
  241. if (cifs_sb->mnt_cifs_flags &
  242. CIFS_MOUNT_DYNPERM)
  243. newinode->i_mode = mode;
  244. if ((oplock & CIFS_CREATE_ACTION) &&
  245. (cifs_sb->mnt_cifs_flags &
  246. CIFS_MOUNT_SET_UID)) {
  247. newinode->i_uid = current->fsuid;
  248. newinode->i_gid = current->fsgid;
  249. }
  250. }
  251. }
  252. if (rc != 0) {
  253. cFYI(1,
  254. ("Create worked but get_inode_info failed rc = %d",
  255. rc));
  256. } else {
  257. if (pTcon->nocase)
  258. direntry->d_op = &cifs_ci_dentry_ops;
  259. else
  260. direntry->d_op = &cifs_dentry_ops;
  261. d_instantiate(direntry, newinode);
  262. }
  263. if ((nd == NULL /* nfsd case - nfs srv does not set nd */) ||
  264. (!(nd->flags & LOOKUP_OPEN))) {
  265. /* mknod case - do not leave file open */
  266. CIFSSMBClose(xid, pTcon, fileHandle);
  267. } else if (newinode) {
  268. pCifsFile =
  269. kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL);
  270. if (pCifsFile == NULL)
  271. goto cifs_create_out;
  272. pCifsFile->netfid = fileHandle;
  273. pCifsFile->pid = current->tgid;
  274. pCifsFile->pInode = newinode;
  275. pCifsFile->invalidHandle = false;
  276. pCifsFile->closePend = false;
  277. init_MUTEX(&pCifsFile->fh_sem);
  278. mutex_init(&pCifsFile->lock_mutex);
  279. INIT_LIST_HEAD(&pCifsFile->llist);
  280. atomic_set(&pCifsFile->wrtPending, 0);
  281. /* set the following in open now
  282. pCifsFile->pfile = file; */
  283. write_lock(&GlobalSMBSeslock);
  284. list_add(&pCifsFile->tlist, &pTcon->openFileList);
  285. pCifsInode = CIFS_I(newinode);
  286. if (pCifsInode) {
  287. /* if readable file instance put first in list*/
  288. if (write_only) {
  289. list_add_tail(&pCifsFile->flist,
  290. &pCifsInode->openFileList);
  291. } else {
  292. list_add(&pCifsFile->flist,
  293. &pCifsInode->openFileList);
  294. }
  295. if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) {
  296. pCifsInode->clientCanCacheAll = true;
  297. pCifsInode->clientCanCacheRead = true;
  298. cFYI(1, ("Exclusive Oplock inode %p",
  299. newinode));
  300. } else if ((oplock & 0xF) == OPLOCK_READ)
  301. pCifsInode->clientCanCacheRead = true;
  302. }
  303. write_unlock(&GlobalSMBSeslock);
  304. }
  305. }
  306. cifs_create_out:
  307. kfree(buf);
  308. kfree(full_path);
  309. FreeXid(xid);
  310. return rc;
  311. }
  312. int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode,
  313. dev_t device_number)
  314. {
  315. int rc = -EPERM;
  316. int xid;
  317. struct cifs_sb_info *cifs_sb;
  318. struct cifsTconInfo *pTcon;
  319. char *full_path = NULL;
  320. struct inode *newinode = NULL;
  321. if (!old_valid_dev(device_number))
  322. return -EINVAL;
  323. xid = GetXid();
  324. cifs_sb = CIFS_SB(inode->i_sb);
  325. pTcon = cifs_sb->tcon;
  326. full_path = build_path_from_dentry(direntry);
  327. if (full_path == NULL)
  328. rc = -ENOMEM;
  329. else if (pTcon->unix_ext) {
  330. mode &= ~current->fs->umask;
  331. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
  332. rc = CIFSSMBUnixSetPerms(xid, pTcon, full_path,
  333. mode, (__u64)current->fsuid,
  334. (__u64)current->fsgid,
  335. device_number, cifs_sb->local_nls,
  336. cifs_sb->mnt_cifs_flags &
  337. CIFS_MOUNT_MAP_SPECIAL_CHR);
  338. } else {
  339. rc = CIFSSMBUnixSetPerms(xid, pTcon,
  340. full_path, mode, (__u64)-1, (__u64)-1,
  341. device_number, cifs_sb->local_nls,
  342. cifs_sb->mnt_cifs_flags &
  343. CIFS_MOUNT_MAP_SPECIAL_CHR);
  344. }
  345. if (!rc) {
  346. rc = cifs_get_inode_info_unix(&newinode, full_path,
  347. inode->i_sb, xid);
  348. if (pTcon->nocase)
  349. direntry->d_op = &cifs_ci_dentry_ops;
  350. else
  351. direntry->d_op = &cifs_dentry_ops;
  352. if (rc == 0)
  353. d_instantiate(direntry, newinode);
  354. }
  355. } else {
  356. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
  357. int oplock = 0;
  358. u16 fileHandle;
  359. FILE_ALL_INFO *buf;
  360. cFYI(1, ("sfu compat create special file"));
  361. buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
  362. if (buf == NULL) {
  363. kfree(full_path);
  364. FreeXid(xid);
  365. return -ENOMEM;
  366. }
  367. rc = CIFSSMBOpen(xid, pTcon, full_path,
  368. FILE_CREATE, /* fail if exists */
  369. GENERIC_WRITE /* BB would
  370. WRITE_OWNER | WRITE_DAC be better? */,
  371. /* Create a file and set the
  372. file attribute to SYSTEM */
  373. CREATE_NOT_DIR | CREATE_OPTION_SPECIAL,
  374. &fileHandle, &oplock, buf,
  375. cifs_sb->local_nls,
  376. cifs_sb->mnt_cifs_flags &
  377. CIFS_MOUNT_MAP_SPECIAL_CHR);
  378. /* BB FIXME - add handling for backlevel servers
  379. which need legacy open and check for all
  380. calls to SMBOpen for fallback to SMBLeagcyOpen */
  381. if (!rc) {
  382. /* BB Do not bother to decode buf since no
  383. local inode yet to put timestamps in,
  384. but we can reuse it safely */
  385. unsigned int bytes_written;
  386. struct win_dev *pdev;
  387. pdev = (struct win_dev *)buf;
  388. if (S_ISCHR(mode)) {
  389. memcpy(pdev->type, "IntxCHR", 8);
  390. pdev->major =
  391. cpu_to_le64(MAJOR(device_number));
  392. pdev->minor =
  393. cpu_to_le64(MINOR(device_number));
  394. rc = CIFSSMBWrite(xid, pTcon,
  395. fileHandle,
  396. sizeof(struct win_dev),
  397. 0, &bytes_written, (char *)pdev,
  398. NULL, 0);
  399. } else if (S_ISBLK(mode)) {
  400. memcpy(pdev->type, "IntxBLK", 8);
  401. pdev->major =
  402. cpu_to_le64(MAJOR(device_number));
  403. pdev->minor =
  404. cpu_to_le64(MINOR(device_number));
  405. rc = CIFSSMBWrite(xid, pTcon,
  406. fileHandle,
  407. sizeof(struct win_dev),
  408. 0, &bytes_written, (char *)pdev,
  409. NULL, 0);
  410. } /* else if(S_ISFIFO */
  411. CIFSSMBClose(xid, pTcon, fileHandle);
  412. d_drop(direntry);
  413. }
  414. kfree(buf);
  415. /* add code here to set EAs */
  416. }
  417. }
  418. kfree(full_path);
  419. FreeXid(xid);
  420. return rc;
  421. }
  422. struct dentry *
  423. cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
  424. struct nameidata *nd)
  425. {
  426. int xid;
  427. int rc = 0; /* to get around spurious gcc warning, set to zero here */
  428. struct cifs_sb_info *cifs_sb;
  429. struct cifsTconInfo *pTcon;
  430. struct inode *newInode = NULL;
  431. char *full_path = NULL;
  432. xid = GetXid();
  433. cFYI(1, (" parent inode = 0x%p name is: %s and dentry = 0x%p",
  434. parent_dir_inode, direntry->d_name.name, direntry));
  435. /* check whether path exists */
  436. cifs_sb = CIFS_SB(parent_dir_inode->i_sb);
  437. pTcon = cifs_sb->tcon;
  438. /*
  439. * Don't allow the separator character in a path component.
  440. * The VFS will not allow "/", but "\" is allowed by posix.
  441. */
  442. if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)) {
  443. int i;
  444. for (i = 0; i < direntry->d_name.len; i++)
  445. if (direntry->d_name.name[i] == '\\') {
  446. cFYI(1, ("Invalid file name"));
  447. FreeXid(xid);
  448. return ERR_PTR(-EINVAL);
  449. }
  450. }
  451. /* can not grab the rename sem here since it would
  452. deadlock in the cases (beginning of sys_rename itself)
  453. in which we already have the sb rename sem */
  454. full_path = build_path_from_dentry(direntry);
  455. if (full_path == NULL) {
  456. FreeXid(xid);
  457. return ERR_PTR(-ENOMEM);
  458. }
  459. if (direntry->d_inode != NULL) {
  460. cFYI(1, (" non-NULL inode in lookup"));
  461. } else {
  462. cFYI(1, (" NULL inode in lookup"));
  463. }
  464. cFYI(1,
  465. (" Full path: %s inode = 0x%p", full_path, direntry->d_inode));
  466. if (pTcon->unix_ext)
  467. rc = cifs_get_inode_info_unix(&newInode, full_path,
  468. parent_dir_inode->i_sb, xid);
  469. else
  470. rc = cifs_get_inode_info(&newInode, full_path, NULL,
  471. parent_dir_inode->i_sb, xid, NULL);
  472. if ((rc == 0) && (newInode != NULL)) {
  473. if (pTcon->nocase)
  474. direntry->d_op = &cifs_ci_dentry_ops;
  475. else
  476. direntry->d_op = &cifs_dentry_ops;
  477. d_add(direntry, newInode);
  478. /* since paths are not looked up by component - the parent
  479. directories are presumed to be good here */
  480. renew_parental_timestamps(direntry);
  481. } else if (rc == -ENOENT) {
  482. rc = 0;
  483. direntry->d_time = jiffies;
  484. if (pTcon->nocase)
  485. direntry->d_op = &cifs_ci_dentry_ops;
  486. else
  487. direntry->d_op = &cifs_dentry_ops;
  488. d_add(direntry, NULL);
  489. /* if it was once a directory (but how can we tell?) we could do
  490. shrink_dcache_parent(direntry); */
  491. } else if (rc != -EACCES) {
  492. cERROR(1, ("Unexpected lookup error %d", rc));
  493. /* We special case check for Access Denied - since that
  494. is a common return code */
  495. }
  496. kfree(full_path);
  497. FreeXid(xid);
  498. return ERR_PTR(rc);
  499. }
  500. static int
  501. cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd)
  502. {
  503. int isValid = 1;
  504. if (direntry->d_inode) {
  505. if (cifs_revalidate(direntry))
  506. return 0;
  507. } else {
  508. cFYI(1, ("neg dentry 0x%p name = %s",
  509. direntry, direntry->d_name.name));
  510. if (time_after(jiffies, direntry->d_time + HZ) ||
  511. !lookupCacheEnabled) {
  512. d_drop(direntry);
  513. isValid = 0;
  514. }
  515. }
  516. return isValid;
  517. }
  518. /* static int cifs_d_delete(struct dentry *direntry)
  519. {
  520. int rc = 0;
  521. cFYI(1, ("In cifs d_delete, name = %s", direntry->d_name.name));
  522. return rc;
  523. } */
  524. struct dentry_operations cifs_dentry_ops = {
  525. .d_revalidate = cifs_d_revalidate,
  526. /* d_delete: cifs_d_delete, */ /* not needed except for debugging */
  527. };
  528. static int cifs_ci_hash(struct dentry *dentry, struct qstr *q)
  529. {
  530. struct nls_table *codepage = CIFS_SB(dentry->d_inode->i_sb)->local_nls;
  531. unsigned long hash;
  532. int i;
  533. hash = init_name_hash();
  534. for (i = 0; i < q->len; i++)
  535. hash = partial_name_hash(nls_tolower(codepage, q->name[i]),
  536. hash);
  537. q->hash = end_name_hash(hash);
  538. return 0;
  539. }
  540. static int cifs_ci_compare(struct dentry *dentry, struct qstr *a,
  541. struct qstr *b)
  542. {
  543. struct nls_table *codepage = CIFS_SB(dentry->d_inode->i_sb)->local_nls;
  544. if ((a->len == b->len) &&
  545. (nls_strnicmp(codepage, a->name, b->name, a->len) == 0)) {
  546. /*
  547. * To preserve case, don't let an existing negative dentry's
  548. * case take precedence. If a is not a negative dentry, this
  549. * should have no side effects
  550. */
  551. memcpy((void *)a->name, b->name, a->len);
  552. return 0;
  553. }
  554. return 1;
  555. }
  556. struct dentry_operations cifs_ci_dentry_ops = {
  557. .d_revalidate = cifs_d_revalidate,
  558. .d_hash = cifs_ci_hash,
  559. .d_compare = cifs_ci_compare,
  560. };