dir.c 17 KB

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