dir.c 17 KB

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