4 * vfs operations that deal with dentries
6 * Copyright (C) International Business Machines Corp., 2002,2009
7 * Author(s): Steve French (sfrench@us.ibm.com)
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.
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.
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
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>
32 #include "cifsproto.h"
33 #include "cifs_debug.h"
34 #include "cifs_fs_sb.h"
35 #include "cifs_unicode.h"
38 renew_parental_timestamps(struct dentry *direntry)
40 /* BB check if there is a way to get the kernel to do this or if we
43 direntry->d_time = jiffies;
44 direntry = direntry->d_parent;
45 } while (!IS_ROOT(direntry));
49 cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
50 struct cifs_tcon *tcon)
52 int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0;
54 char *full_path = NULL;
56 /* if no prefix path, simply set path to the root of share to "" */
58 full_path = kzalloc(1, GFP_KERNEL);
62 if (tcon->Flags & SMB_SHARE_IS_IN_DFS)
63 dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
67 full_path = kmalloc(dfsplen + pplen + 1, GFP_KERNEL);
68 if (full_path == NULL)
72 strncpy(full_path, tcon->treeName, dfsplen);
73 full_path[dfsplen] = CIFS_DIR_SEP(cifs_sb);
74 strncpy(full_path + dfsplen + 1, vol->prepath, pplen);
75 convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb));
76 full_path[dfsplen + pplen] = 0; /* add trailing null */
80 /* Note: caller must free return buffer */
82 build_path_from_dentry(struct dentry *direntry)
90 struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
91 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
94 dirsep = CIFS_DIR_SEP(cifs_sb);
95 if (tcon->Flags & SMB_SHARE_IS_IN_DFS)
96 dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
100 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH)
101 pplen = cifs_sb->prepath ? strlen(cifs_sb->prepath) + 1 : 0;
103 cifs_bp_rename_retry:
104 namelen = dfsplen + pplen;
105 seq = read_seqbegin(&rename_lock);
107 for (temp = direntry; !IS_ROOT(temp);) {
108 namelen += (1 + temp->d_name.len);
109 temp = temp->d_parent;
111 cifs_dbg(VFS, "corrupt dentry\n");
118 full_path = kmalloc(namelen+1, GFP_KERNEL);
119 if (full_path == NULL)
121 full_path[namelen] = 0; /* trailing null */
123 for (temp = direntry; !IS_ROOT(temp);) {
124 spin_lock(&temp->d_lock);
125 namelen -= 1 + temp->d_name.len;
127 spin_unlock(&temp->d_lock);
130 full_path[namelen] = dirsep;
131 strncpy(full_path + namelen + 1, temp->d_name.name,
133 cifs_dbg(FYI, "name: %s\n", full_path + namelen);
135 spin_unlock(&temp->d_lock);
136 temp = temp->d_parent;
138 cifs_dbg(VFS, "corrupt dentry\n");
145 if (namelen != dfsplen + pplen || read_seqretry(&rename_lock, seq)) {
146 cifs_dbg(FYI, "did not end path lookup where expected. namelen=%ddfsplen=%d\n",
148 /* presumably this is only possible if racing with a rename
149 of one of the parent directories (we can not lock the dentries
150 above us to prevent this, but retrying should be harmless) */
152 goto cifs_bp_rename_retry;
154 /* DIR_SEP already set for byte 0 / vs \ but not for
155 subsequent slashes in prepath which currently must
156 be entered the right way - not sure if there is an alternative
157 since the '\' is a valid posix character so we can not switch
158 those safely to '/' if any are found in the middle of the prepath */
159 /* BB test paths to Windows with '/' in the midst of prepath */
164 cifs_dbg(FYI, "using cifs_sb prepath <%s>\n", cifs_sb->prepath);
165 memcpy(full_path+dfsplen+1, cifs_sb->prepath, pplen-1);
166 full_path[dfsplen] = dirsep;
167 for (i = 0; i < pplen-1; i++)
168 if (full_path[dfsplen+1+i] == '/')
169 full_path[dfsplen+1+i] = CIFS_DIR_SEP(cifs_sb);
173 strncpy(full_path, tcon->treeName, dfsplen);
174 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) {
176 for (i = 0; i < dfsplen; i++) {
177 if (full_path[i] == '\\')
186 * Don't allow path components longer than the server max.
187 * Don't allow the separator character in a path component.
188 * The VFS will not allow "/", but "\" is allowed by posix.
191 check_name(struct dentry *direntry, struct cifs_tcon *tcon)
193 struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
196 if (unlikely(tcon->fsAttrInfo.MaxPathNameComponentLength &&
197 direntry->d_name.len >
198 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength)))
199 return -ENAMETOOLONG;
201 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)) {
202 for (i = 0; i < direntry->d_name.len; i++) {
203 if (direntry->d_name.name[i] == '\\') {
204 cifs_dbg(FYI, "Invalid file name\n");
213 /* Inode operations in similar order to how they appear in Linux file fs.h */
216 cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
217 struct tcon_link *tlink, unsigned oflags, umode_t mode,
218 __u32 *oplock, struct cifs_fid *fid)
221 int create_options = CREATE_NOT_DIR;
223 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
224 struct cifs_tcon *tcon = tlink_tcon(tlink);
225 char *full_path = NULL;
226 FILE_ALL_INFO *buf = NULL;
227 struct inode *newinode = NULL;
229 struct TCP_Server_Info *server = tcon->ses->server;
230 struct cifs_open_parms oparms;
233 if (tcon->ses->server->oplocks)
234 *oplock = REQ_OPLOCK;
236 full_path = build_path_from_dentry(direntry);
237 if (full_path == NULL) {
242 if (tcon->unix_ext && cap_unix(tcon->ses) && !tcon->broken_posix_open &&
243 (CIFS_UNIX_POSIX_PATH_OPS_CAP &
244 le64_to_cpu(tcon->fsUnixInfo.Capability))) {
245 rc = cifs_posix_open(full_path, &newinode, inode->i_sb, mode,
246 oflags, oplock, &fid->netfid, xid);
249 if (newinode == NULL) {
250 /* query inode info */
251 goto cifs_create_get_file_info;
254 if (S_ISDIR(newinode->i_mode)) {
255 CIFSSMBClose(xid, tcon, fid->netfid);
261 if (!S_ISREG(newinode->i_mode)) {
263 * The server may allow us to open things like
264 * FIFOs, but the client isn't set up to deal
265 * with that. If it's not a regular file, just
266 * close it and proceed as if it were a normal
269 CIFSSMBClose(xid, tcon, fid->netfid);
270 goto cifs_create_get_file_info;
272 /* success, no need to query */
273 goto cifs_create_set_dentry;
276 goto cifs_create_get_file_info;
281 * EIO could indicate that (posix open) operation is not
282 * supported, despite what server claimed in capability
285 * POSIX open in samba versions 3.3.1 and earlier could
286 * incorrectly fail with invalid parameter.
288 tcon->broken_posix_open = true;
294 * EREMOTE indicates DFS junction, which is not handled
295 * in posix open. If either that or op not supported
296 * returned, follow the normal lookup.
304 * fallthrough to retry, using older open call, this is case
305 * where server does not support this SMB level, and falsely
306 * claims capability (also get here for DFS case which should be
307 * rare for path not covered on files)
312 if (OPEN_FMODE(oflags) & FMODE_READ)
313 desired_access |= GENERIC_READ; /* is this too little? */
314 if (OPEN_FMODE(oflags) & FMODE_WRITE)
315 desired_access |= GENERIC_WRITE;
317 disposition = FILE_OVERWRITE_IF;
318 if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
319 disposition = FILE_CREATE;
320 else if ((oflags & (O_CREAT | O_TRUNC)) == (O_CREAT | O_TRUNC))
321 disposition = FILE_OVERWRITE_IF;
322 else if ((oflags & O_CREAT) == O_CREAT)
323 disposition = FILE_OPEN_IF;
325 cifs_dbg(FYI, "Create flag not set in create function\n");
328 * BB add processing to set equivalent of mode - e.g. via CreateX with
332 if (!server->ops->open) {
337 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
344 * if we're not using unix extensions, see if we need to set
345 * ATTR_READONLY on the create call
347 if (!tcon->unix_ext && (mode & S_IWUGO) == 0)
348 create_options |= CREATE_OPTION_READONLY;
350 if (backup_cred(cifs_sb))
351 create_options |= CREATE_OPEN_BACKUP_INTENT;
354 oparms.cifs_sb = cifs_sb;
355 oparms.desired_access = desired_access;
356 oparms.create_options = create_options;
357 oparms.disposition = disposition;
358 oparms.path = full_path;
360 oparms.reconnect = false;
362 rc = server->ops->open(xid, &oparms, oplock, buf);
364 cifs_dbg(FYI, "cifs_create returned 0x%x\n", rc);
369 * If Open reported that we actually created a file then we now have to
370 * set the mode if possible.
372 if ((tcon->unix_ext) && (*oplock & CIFS_CREATE_ACTION)) {
373 struct cifs_unix_set_info_args args = {
375 .ctime = NO_CHANGE_64,
376 .atime = NO_CHANGE_64,
377 .mtime = NO_CHANGE_64,
381 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
382 args.uid = current_fsuid();
383 if (inode->i_mode & S_ISGID)
384 args.gid = inode->i_gid;
386 args.gid = current_fsgid();
388 args.uid = INVALID_UID; /* no change */
389 args.gid = INVALID_GID; /* no change */
391 CIFSSMBUnixSetFileInfo(xid, tcon, &args, fid->netfid,
395 * BB implement mode setting via Windows security
398 /* CIFSSMBWinSetPerms(xid,tcon,path,mode,-1,-1,nls);*/
400 /* Could set r/o dos attribute if mode & 0222 == 0 */
403 cifs_create_get_file_info:
404 /* server might mask mode so we have to query for it */
406 rc = cifs_get_inode_info_unix(&newinode, full_path, inode->i_sb,
409 rc = cifs_get_inode_info(&newinode, full_path, buf, inode->i_sb,
412 if (server->ops->set_lease_key)
413 server->ops->set_lease_key(newinode, fid);
414 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
415 newinode->i_mode = mode;
416 if ((*oplock & CIFS_CREATE_ACTION) &&
417 (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)) {
418 newinode->i_uid = current_fsuid();
419 if (inode->i_mode & S_ISGID)
420 newinode->i_gid = inode->i_gid;
422 newinode->i_gid = current_fsgid();
427 cifs_create_set_dentry:
429 cifs_dbg(FYI, "Create worked, get_inode_info failed rc = %d\n",
434 if (S_ISDIR(newinode->i_mode)) {
440 d_add(direntry, newinode);
448 if (server->ops->close)
449 server->ops->close(xid, tcon, fid);
456 cifs_atomic_open(struct inode *inode, struct dentry *direntry,
457 struct file *file, unsigned oflags, umode_t mode,
462 struct tcon_link *tlink;
463 struct cifs_tcon *tcon;
464 struct TCP_Server_Info *server;
466 struct cifs_pending_open open;
468 struct cifsFileInfo *file_info;
471 * Posix open is only called (at lookup time) for file create now. For
472 * opens (rather than creates), because we do not know if it is a file
473 * or directory yet, and current Samba no longer allows us to do posix
474 * open on dirs, we could end up wasting an open call on what turns out
475 * to be a dir. For file opens, we wait to call posix open till
476 * cifs_open. It could be added to atomic_open in the future but the
477 * performance tradeoff of the extra network request when EISDIR or
478 * EACCES is returned would have to be weighed against the 50% reduction
479 * in network traffic in the other paths.
481 if (!(oflags & O_CREAT)) {
485 * Check for hashed negative dentry. We have already revalidated
486 * the dentry and it is fine. No need to perform another lookup.
488 if (!d_unhashed(direntry))
491 res = cifs_lookup(inode, direntry, 0);
495 return finish_no_open(file, res);
500 cifs_dbg(FYI, "parent inode = 0x%p name is: %pd and dentry = 0x%p\n",
501 inode, direntry, direntry);
503 tlink = cifs_sb_tlink(CIFS_SB(inode->i_sb));
509 tcon = tlink_tcon(tlink);
511 rc = check_name(direntry, tcon);
515 server = tcon->ses->server;
517 if (server->ops->new_lease_key)
518 server->ops->new_lease_key(&fid);
520 cifs_add_pending_open(&fid, tlink, &open);
522 rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
526 cifs_del_pending_open(&open);
530 if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
531 *opened |= FILE_CREATED;
533 rc = finish_open(file, direntry, generic_file_open, opened);
535 if (server->ops->close)
536 server->ops->close(xid, tcon, &fid);
537 cifs_del_pending_open(&open);
541 if (file->f_flags & O_DIRECT &&
542 CIFS_SB(inode->i_sb)->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) {
543 if (CIFS_SB(inode->i_sb)->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
544 file->f_op = &cifs_file_direct_nobrl_ops;
546 file->f_op = &cifs_file_direct_ops;
549 file_info = cifs_new_fileinfo(&fid, file, tlink, oplock);
550 if (file_info == NULL) {
551 if (server->ops->close)
552 server->ops->close(xid, tcon, &fid);
553 cifs_del_pending_open(&open);
559 cifs_put_tlink(tlink);
565 int cifs_create(struct inode *inode, struct dentry *direntry, umode_t mode,
569 unsigned int xid = get_xid();
571 * BB below access is probably too much for mknod to request
572 * but we have to do query and setpathinfo so requesting
573 * less could fail (unless we want to request getatr and setatr
574 * permissions (only). At least for POSIX we do not have to
577 unsigned oflags = O_EXCL | O_CREAT | O_RDWR;
578 struct tcon_link *tlink;
579 struct cifs_tcon *tcon;
580 struct TCP_Server_Info *server;
584 cifs_dbg(FYI, "cifs_create parent inode = 0x%p name is: %pd and dentry = 0x%p\n",
585 inode, direntry, direntry);
587 tlink = cifs_sb_tlink(CIFS_SB(inode->i_sb));
592 tcon = tlink_tcon(tlink);
593 server = tcon->ses->server;
595 if (server->ops->new_lease_key)
596 server->ops->new_lease_key(&fid);
598 rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
600 if (!rc && server->ops->close)
601 server->ops->close(xid, tcon, &fid);
603 cifs_put_tlink(tlink);
609 int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
614 int create_options = CREATE_NOT_DIR | CREATE_OPTION_SPECIAL;
615 struct cifs_sb_info *cifs_sb;
616 struct tcon_link *tlink;
617 struct cifs_tcon *tcon;
618 struct cifs_io_parms io_parms;
619 char *full_path = NULL;
620 struct inode *newinode = NULL;
623 struct cifs_open_parms oparms;
624 FILE_ALL_INFO *buf = NULL;
625 unsigned int bytes_written;
626 struct win_dev *pdev;
629 if (!old_valid_dev(device_number))
632 cifs_sb = CIFS_SB(inode->i_sb);
633 tlink = cifs_sb_tlink(cifs_sb);
635 return PTR_ERR(tlink);
637 tcon = tlink_tcon(tlink);
641 full_path = build_path_from_dentry(direntry);
642 if (full_path == NULL) {
647 if (tcon->unix_ext) {
648 struct cifs_unix_set_info_args args = {
649 .mode = mode & ~current_umask(),
650 .ctime = NO_CHANGE_64,
651 .atime = NO_CHANGE_64,
652 .mtime = NO_CHANGE_64,
653 .device = device_number,
655 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
656 args.uid = current_fsuid();
657 args.gid = current_fsgid();
659 args.uid = INVALID_UID; /* no change */
660 args.gid = INVALID_GID; /* no change */
662 rc = CIFSSMBUnixSetPathInfo(xid, tcon, full_path, &args,
664 cifs_remap(cifs_sb));
668 rc = cifs_get_inode_info_unix(&newinode, full_path,
672 d_instantiate(direntry, newinode);
676 if (!S_ISCHR(mode) && !S_ISBLK(mode))
679 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
683 cifs_dbg(FYI, "sfu compat create special file\n");
685 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
691 if (backup_cred(cifs_sb))
692 create_options |= CREATE_OPEN_BACKUP_INTENT;
695 oparms.cifs_sb = cifs_sb;
696 oparms.desired_access = GENERIC_WRITE;
697 oparms.create_options = create_options;
698 oparms.disposition = FILE_CREATE;
699 oparms.path = full_path;
701 oparms.reconnect = false;
703 if (tcon->ses->server->oplocks)
707 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
712 * BB Do not bother to decode buf since no local inode yet to put
713 * timestamps in, but we can reuse it safely.
716 pdev = (struct win_dev *)buf;
717 io_parms.pid = current->tgid;
718 io_parms.tcon = tcon;
720 io_parms.length = sizeof(struct win_dev);
721 iov[1].iov_base = buf;
722 iov[1].iov_len = sizeof(struct win_dev);
724 memcpy(pdev->type, "IntxCHR", 8);
725 pdev->major = cpu_to_le64(MAJOR(device_number));
726 pdev->minor = cpu_to_le64(MINOR(device_number));
727 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
728 &bytes_written, iov, 1);
729 } else if (S_ISBLK(mode)) {
730 memcpy(pdev->type, "IntxBLK", 8);
731 pdev->major = cpu_to_le64(MAJOR(device_number));
732 pdev->minor = cpu_to_le64(MINOR(device_number));
733 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
734 &bytes_written, iov, 1);
736 tcon->ses->server->ops->close(xid, tcon, &fid);
739 /* FIXME: add code here to set EAs */
745 cifs_put_tlink(tlink);
750 cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
754 int rc = 0; /* to get around spurious gcc warning, set to zero here */
755 struct cifs_sb_info *cifs_sb;
756 struct tcon_link *tlink;
757 struct cifs_tcon *pTcon;
758 struct inode *newInode = NULL;
759 char *full_path = NULL;
763 cifs_dbg(FYI, "parent inode = 0x%p name is: %pd and dentry = 0x%p\n",
764 parent_dir_inode, direntry, direntry);
766 /* check whether path exists */
768 cifs_sb = CIFS_SB(parent_dir_inode->i_sb);
769 tlink = cifs_sb_tlink(cifs_sb);
772 return (struct dentry *)tlink;
774 pTcon = tlink_tcon(tlink);
776 rc = check_name(direntry, pTcon);
780 /* can not grab the rename sem here since it would
781 deadlock in the cases (beginning of sys_rename itself)
782 in which we already have the sb rename sem */
783 full_path = build_path_from_dentry(direntry);
784 if (full_path == NULL) {
789 if (d_really_is_positive(direntry)) {
790 cifs_dbg(FYI, "non-NULL inode in lookup\n");
792 cifs_dbg(FYI, "NULL inode in lookup\n");
794 cifs_dbg(FYI, "Full path: %s inode = 0x%p\n",
795 full_path, d_inode(direntry));
797 if (pTcon->unix_ext) {
798 rc = cifs_get_inode_info_unix(&newInode, full_path,
799 parent_dir_inode->i_sb, xid);
801 rc = cifs_get_inode_info(&newInode, full_path, NULL,
802 parent_dir_inode->i_sb, xid, NULL);
805 if ((rc == 0) && (newInode != NULL)) {
806 d_add(direntry, newInode);
807 /* since paths are not looked up by component - the parent
808 directories are presumed to be good here */
809 renew_parental_timestamps(direntry);
811 } else if (rc == -ENOENT) {
813 direntry->d_time = jiffies;
814 d_add(direntry, NULL);
815 /* if it was once a directory (but how can we tell?) we could do
816 shrink_dcache_parent(direntry); */
817 } else if (rc != -EACCES) {
818 cifs_dbg(FYI, "Unexpected lookup error %d\n", rc);
819 /* We special case check for Access Denied - since that
820 is a common return code */
825 cifs_put_tlink(tlink);
831 cifs_d_revalidate(struct dentry *direntry, unsigned int flags)
836 if (flags & LOOKUP_RCU)
839 if (d_really_is_positive(direntry)) {
840 inode = d_inode(direntry);
841 if ((flags & LOOKUP_REVAL) && !CIFS_CACHE_READ(CIFS_I(inode)))
842 CIFS_I(inode)->time = 0; /* force reval */
844 rc = cifs_revalidate_dentry(direntry);
846 cifs_dbg(FYI, "cifs_revalidate_dentry failed with rc=%d", rc);
851 * Those errors mean the dentry is invalid
852 * (file was deleted or recreated)
857 * Otherwise some unexpected error happened
858 * report it as-is to VFS layer
865 * If the inode wasn't known to be a dfs entry when
866 * the dentry was instantiated, such as when created
867 * via ->readdir(), it needs to be set now since the
868 * attributes will have been updated by
869 * cifs_revalidate_dentry().
871 if (IS_AUTOMOUNT(inode) &&
872 !(direntry->d_flags & DCACHE_NEED_AUTOMOUNT)) {
873 spin_lock(&direntry->d_lock);
874 direntry->d_flags |= DCACHE_NEED_AUTOMOUNT;
875 spin_unlock(&direntry->d_lock);
883 * This may be nfsd (or something), anyway, we can't see the
884 * intent of this. So, since this can be for creation, drop it.
890 * Drop the negative dentry, in order to make sure to use the
891 * case sensitive name which is specified by user if this is
894 if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET))
897 if (time_after(jiffies, direntry->d_time + HZ) || !lookupCacheEnabled)
903 /* static int cifs_d_delete(struct dentry *direntry)
907 cifs_dbg(FYI, "In cifs d_delete, name = %pd\n", direntry);
912 const struct dentry_operations cifs_dentry_ops = {
913 .d_revalidate = cifs_d_revalidate,
914 .d_automount = cifs_dfs_d_automount,
915 /* d_delete: cifs_d_delete, */ /* not needed except for debugging */
918 static int cifs_ci_hash(const struct dentry *dentry, struct qstr *q)
920 struct nls_table *codepage = CIFS_SB(dentry->d_sb)->local_nls;
925 hash = init_name_hash();
926 for (i = 0; i < q->len; i += charlen) {
927 charlen = codepage->char2uni(&q->name[i], q->len - i, &c);
928 /* error out if we can't convert the character */
929 if (unlikely(charlen < 0))
931 hash = partial_name_hash(cifs_toupper(c), hash);
933 q->hash = end_name_hash(hash);
938 static int cifs_ci_compare(const struct dentry *parent, const struct dentry *dentry,
939 unsigned int len, const char *str, const struct qstr *name)
941 struct nls_table *codepage = CIFS_SB(parent->d_sb)->local_nls;
946 * We make the assumption here that uppercase characters in the local
947 * codepage are always the same length as their lowercase counterparts.
949 * If that's ever not the case, then this will fail to match it.
951 if (name->len != len)
954 for (i = 0; i < len; i += l1) {
955 /* Convert characters in both strings to UTF-16. */
956 l1 = codepage->char2uni(&str[i], len - i, &c1);
957 l2 = codepage->char2uni(&name->name[i], name->len - i, &c2);
960 * If we can't convert either character, just declare it to
961 * be 1 byte long and compare the original byte.
963 if (unlikely(l1 < 0 && l2 < 0)) {
964 if (str[i] != name->name[i])
971 * Here, we again ass|u|me that upper/lowercase versions of
972 * a character are the same length in the local NLS.
977 /* Now compare uppercase versions of these characters */
978 if (cifs_toupper(c1) != cifs_toupper(c2))
985 const struct dentry_operations cifs_ci_dentry_ops = {
986 .d_revalidate = cifs_d_revalidate,
987 .d_hash = cifs_ci_hash,
988 .d_compare = cifs_ci_compare,
989 .d_automount = cifs_dfs_d_automount,