dir.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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. newinode->i_mode = mode;
  242. if ((oplock & CIFS_CREATE_ACTION) &&
  243. (cifs_sb->mnt_cifs_flags &
  244. CIFS_MOUNT_SET_UID)) {
  245. newinode->i_uid = current->fsuid;
  246. newinode->i_gid = current->fsgid;
  247. }
  248. }
  249. }
  250. if (rc != 0) {
  251. cFYI(1,
  252. ("Create worked but get_inode_info failed rc = %d",
  253. rc));
  254. } else {
  255. if (pTcon->nocase)
  256. direntry->d_op = &cifs_ci_dentry_ops;
  257. else
  258. direntry->d_op = &cifs_dentry_ops;
  259. d_instantiate(direntry, newinode);
  260. }
  261. if ((nd == NULL /* nfsd case - nfs srv does not set nd */) ||
  262. (!(nd->flags & LOOKUP_OPEN))) {
  263. /* mknod case - do not leave file open */
  264. CIFSSMBClose(xid, pTcon, fileHandle);
  265. } else if (newinode) {
  266. pCifsFile =
  267. kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL);
  268. if (pCifsFile == NULL)
  269. goto cifs_create_out;
  270. pCifsFile->netfid = fileHandle;
  271. pCifsFile->pid = current->tgid;
  272. pCifsFile->pInode = newinode;
  273. pCifsFile->invalidHandle = false;
  274. pCifsFile->closePend = false;
  275. init_MUTEX(&pCifsFile->fh_sem);
  276. mutex_init(&pCifsFile->lock_mutex);
  277. INIT_LIST_HEAD(&pCifsFile->llist);
  278. atomic_set(&pCifsFile->wrtPending, 0);
  279. /* set the following in open now
  280. pCifsFile->pfile = file; */
  281. write_lock(&GlobalSMBSeslock);
  282. list_add(&pCifsFile->tlist, &pTcon->openFileList);
  283. pCifsInode = CIFS_I(newinode);
  284. if (pCifsInode) {
  285. /* if readable file instance put first in list*/
  286. if (write_only) {
  287. list_add_tail(&pCifsFile->flist,
  288. &pCifsInode->openFileList);
  289. } else {
  290. list_add(&pCifsFile->flist,
  291. &pCifsInode->openFileList);
  292. }
  293. if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) {
  294. pCifsInode->clientCanCacheAll = true;
  295. pCifsInode->clientCanCacheRead = true;
  296. cFYI(1, ("Exclusive Oplock inode %p",
  297. newinode));
  298. } else if ((oplock & 0xF) == OPLOCK_READ)
  299. pCifsInode->clientCanCacheRead = true;
  300. }
  301. write_unlock(&GlobalSMBSeslock);
  302. }
  303. }
  304. cifs_create_out:
  305. kfree(buf);
  306. kfree(full_path);
  307. FreeXid(xid);
  308. return rc;
  309. }
  310. int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode,
  311. dev_t device_number)
  312. {
  313. int rc = -EPERM;
  314. int xid;
  315. struct cifs_sb_info *cifs_sb;
  316. struct cifsTconInfo *pTcon;
  317. char *full_path = NULL;
  318. struct inode *newinode = NULL;
  319. if (!old_valid_dev(device_number))
  320. return -EINVAL;
  321. xid = GetXid();
  322. cifs_sb = CIFS_SB(inode->i_sb);
  323. pTcon = cifs_sb->tcon;
  324. full_path = build_path_from_dentry(direntry);
  325. if (full_path == NULL)
  326. rc = -ENOMEM;
  327. else if (pTcon->unix_ext) {
  328. mode &= ~current->fs->umask;
  329. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
  330. rc = CIFSSMBUnixSetPerms(xid, pTcon, full_path,
  331. mode, (__u64)current->fsuid,
  332. (__u64)current->fsgid,
  333. device_number, cifs_sb->local_nls,
  334. cifs_sb->mnt_cifs_flags &
  335. CIFS_MOUNT_MAP_SPECIAL_CHR);
  336. } else {
  337. rc = CIFSSMBUnixSetPerms(xid, pTcon,
  338. full_path, mode, (__u64)-1, (__u64)-1,
  339. device_number, cifs_sb->local_nls,
  340. cifs_sb->mnt_cifs_flags &
  341. CIFS_MOUNT_MAP_SPECIAL_CHR);
  342. }
  343. if (!rc) {
  344. rc = cifs_get_inode_info_unix(&newinode, full_path,
  345. inode->i_sb, xid);
  346. if (pTcon->nocase)
  347. direntry->d_op = &cifs_ci_dentry_ops;
  348. else
  349. direntry->d_op = &cifs_dentry_ops;
  350. if (rc == 0)
  351. d_instantiate(direntry, newinode);
  352. }
  353. } else {
  354. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
  355. int oplock = 0;
  356. u16 fileHandle;
  357. FILE_ALL_INFO *buf;
  358. cFYI(1, ("sfu compat create special file"));
  359. buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
  360. if (buf == NULL) {
  361. kfree(full_path);
  362. FreeXid(xid);
  363. return -ENOMEM;
  364. }
  365. rc = CIFSSMBOpen(xid, pTcon, full_path,
  366. FILE_CREATE, /* fail if exists */
  367. GENERIC_WRITE /* BB would
  368. WRITE_OWNER | WRITE_DAC be better? */,
  369. /* Create a file and set the
  370. file attribute to SYSTEM */
  371. CREATE_NOT_DIR | CREATE_OPTION_SPECIAL,
  372. &fileHandle, &oplock, buf,
  373. cifs_sb->local_nls,
  374. cifs_sb->mnt_cifs_flags &
  375. CIFS_MOUNT_MAP_SPECIAL_CHR);
  376. /* BB FIXME - add handling for backlevel servers
  377. which need legacy open and check for all
  378. calls to SMBOpen for fallback to SMBLeagcyOpen */
  379. if (!rc) {
  380. /* BB Do not bother to decode buf since no
  381. local inode yet to put timestamps in,
  382. but we can reuse it safely */
  383. unsigned int bytes_written;
  384. struct win_dev *pdev;
  385. pdev = (struct win_dev *)buf;
  386. if (S_ISCHR(mode)) {
  387. memcpy(pdev->type, "IntxCHR", 8);
  388. pdev->major =
  389. cpu_to_le64(MAJOR(device_number));
  390. pdev->minor =
  391. cpu_to_le64(MINOR(device_number));
  392. rc = CIFSSMBWrite(xid, pTcon,
  393. fileHandle,
  394. sizeof(struct win_dev),
  395. 0, &bytes_written, (char *)pdev,
  396. NULL, 0);
  397. } else if (S_ISBLK(mode)) {
  398. memcpy(pdev->type, "IntxBLK", 8);
  399. pdev->major =
  400. cpu_to_le64(MAJOR(device_number));
  401. pdev->minor =
  402. cpu_to_le64(MINOR(device_number));
  403. rc = CIFSSMBWrite(xid, pTcon,
  404. fileHandle,
  405. sizeof(struct win_dev),
  406. 0, &bytes_written, (char *)pdev,
  407. NULL, 0);
  408. } /* else if(S_ISFIFO */
  409. CIFSSMBClose(xid, pTcon, fileHandle);
  410. d_drop(direntry);
  411. }
  412. kfree(buf);
  413. /* add code here to set EAs */
  414. }
  415. }
  416. kfree(full_path);
  417. FreeXid(xid);
  418. return rc;
  419. }
  420. struct dentry *
  421. cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
  422. struct nameidata *nd)
  423. {
  424. int xid;
  425. int rc = 0; /* to get around spurious gcc warning, set to zero here */
  426. struct cifs_sb_info *cifs_sb;
  427. struct cifsTconInfo *pTcon;
  428. struct inode *newInode = NULL;
  429. char *full_path = NULL;
  430. xid = GetXid();
  431. cFYI(1, (" parent inode = 0x%p name is: %s and dentry = 0x%p",
  432. parent_dir_inode, direntry->d_name.name, direntry));
  433. /* check whether path exists */
  434. cifs_sb = CIFS_SB(parent_dir_inode->i_sb);
  435. pTcon = cifs_sb->tcon;
  436. /*
  437. * Don't allow the separator character in a path component.
  438. * The VFS will not allow "/", but "\" is allowed by posix.
  439. */
  440. if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)) {
  441. int i;
  442. for (i = 0; i < direntry->d_name.len; i++)
  443. if (direntry->d_name.name[i] == '\\') {
  444. cFYI(1, ("Invalid file name"));
  445. FreeXid(xid);
  446. return ERR_PTR(-EINVAL);
  447. }
  448. }
  449. /* can not grab the rename sem here since it would
  450. deadlock in the cases (beginning of sys_rename itself)
  451. in which we already have the sb rename sem */
  452. full_path = build_path_from_dentry(direntry);
  453. if (full_path == NULL) {
  454. FreeXid(xid);
  455. return ERR_PTR(-ENOMEM);
  456. }
  457. if (direntry->d_inode != NULL) {
  458. cFYI(1, (" non-NULL inode in lookup"));
  459. } else {
  460. cFYI(1, (" NULL inode in lookup"));
  461. }
  462. cFYI(1,
  463. (" Full path: %s inode = 0x%p", full_path, direntry->d_inode));
  464. if (pTcon->unix_ext)
  465. rc = cifs_get_inode_info_unix(&newInode, full_path,
  466. parent_dir_inode->i_sb, xid);
  467. else
  468. rc = cifs_get_inode_info(&newInode, full_path, NULL,
  469. parent_dir_inode->i_sb, xid, NULL);
  470. if ((rc == 0) && (newInode != NULL)) {
  471. if (pTcon->nocase)
  472. direntry->d_op = &cifs_ci_dentry_ops;
  473. else
  474. direntry->d_op = &cifs_dentry_ops;
  475. d_add(direntry, newInode);
  476. /* since paths are not looked up by component - the parent
  477. directories are presumed to be good here */
  478. renew_parental_timestamps(direntry);
  479. } else if (rc == -ENOENT) {
  480. rc = 0;
  481. direntry->d_time = jiffies;
  482. if (pTcon->nocase)
  483. direntry->d_op = &cifs_ci_dentry_ops;
  484. else
  485. direntry->d_op = &cifs_dentry_ops;
  486. d_add(direntry, NULL);
  487. /* if it was once a directory (but how can we tell?) we could do
  488. shrink_dcache_parent(direntry); */
  489. } else if (rc != -EACCES) {
  490. cERROR(1, ("Unexpected lookup error %d", rc));
  491. /* We special case check for Access Denied - since that
  492. is a common return code */
  493. }
  494. kfree(full_path);
  495. FreeXid(xid);
  496. return ERR_PTR(rc);
  497. }
  498. static int
  499. cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd)
  500. {
  501. int isValid = 1;
  502. if (direntry->d_inode) {
  503. if (cifs_revalidate(direntry))
  504. return 0;
  505. } else {
  506. cFYI(1, ("neg dentry 0x%p name = %s",
  507. direntry, direntry->d_name.name));
  508. if (time_after(jiffies, direntry->d_time + HZ) ||
  509. !lookupCacheEnabled) {
  510. d_drop(direntry);
  511. isValid = 0;
  512. }
  513. }
  514. return isValid;
  515. }
  516. /* static int cifs_d_delete(struct dentry *direntry)
  517. {
  518. int rc = 0;
  519. cFYI(1, ("In cifs d_delete, name = %s", direntry->d_name.name));
  520. return rc;
  521. } */
  522. struct dentry_operations cifs_dentry_ops = {
  523. .d_revalidate = cifs_d_revalidate,
  524. /* d_delete: cifs_d_delete, */ /* not needed except for debugging */
  525. };
  526. static int cifs_ci_hash(struct dentry *dentry, struct qstr *q)
  527. {
  528. struct nls_table *codepage = CIFS_SB(dentry->d_inode->i_sb)->local_nls;
  529. unsigned long hash;
  530. int i;
  531. hash = init_name_hash();
  532. for (i = 0; i < q->len; i++)
  533. hash = partial_name_hash(nls_tolower(codepage, q->name[i]),
  534. hash);
  535. q->hash = end_name_hash(hash);
  536. return 0;
  537. }
  538. static int cifs_ci_compare(struct dentry *dentry, struct qstr *a,
  539. struct qstr *b)
  540. {
  541. struct nls_table *codepage = CIFS_SB(dentry->d_inode->i_sb)->local_nls;
  542. if ((a->len == b->len) &&
  543. (nls_strnicmp(codepage, a->name, b->name, a->len) == 0)) {
  544. /*
  545. * To preserve case, don't let an existing negative dentry's
  546. * case take precedence. If a is not a negative dentry, this
  547. * should have no side effects
  548. */
  549. memcpy((void *)a->name, b->name, a->len);
  550. return 0;
  551. }
  552. return 1;
  553. }
  554. struct dentry_operations cifs_ci_dentry_ops = {
  555. .d_revalidate = cifs_d_revalidate,
  556. .d_hash = cifs_ci_hash,
  557. .d_compare = cifs_ci_compare,
  558. };