Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *   fs/cifs/dir.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *   vfs operations that deal with dentries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *   Copyright (C) International Business Machines  Corp., 2002,2009
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *   Author(s): Steve French (sfrench@us.ibm.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *   This library is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *   it under the terms of the GNU Lesser General Public License as published
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *   by the Free Software Foundation; either version 2.1 of the License, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *   (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *   This library is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *   the GNU Lesser General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *   You should have received a copy of the GNU Lesser General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *   along with this library; if not, write to the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include "cifsfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "cifspdu.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include "cifsglob.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include "cifsproto.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include "cifs_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include "cifs_fs_sb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include "cifs_unicode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) renew_parental_timestamps(struct dentry *direntry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	/* BB check if there is a way to get the kernel to do this or if we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	   really need this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		cifs_set_time(direntry, jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		direntry = direntry->d_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	} while (!IS_ROOT(direntry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			struct cifs_tcon *tcon, int add_treename)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	int dfsplen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	char *full_path = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	/* if no prefix path, simply set path to the root of share to "" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (pplen == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		full_path = kzalloc(1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		return full_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (add_treename)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		dfsplen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	full_path = kmalloc(dfsplen + pplen + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (full_path == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		return full_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (dfsplen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		memcpy(full_path, tcon->treeName, dfsplen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	full_path[dfsplen] = CIFS_DIR_SEP(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	memcpy(full_path + dfsplen + 1, vol->prepath, pplen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	return full_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) /* Note: caller must free return buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) build_path_from_dentry(struct dentry *direntry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	bool prefix = tcon->Flags & SMB_SHARE_IS_IN_DFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	return build_path_from_dentry_optional_prefix(direntry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 						      prefix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) build_path_from_dentry_optional_prefix(struct dentry *direntry, bool prefix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct dentry *temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	int namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	int dfsplen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	int pplen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	char *full_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	char dirsep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	unsigned seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	dirsep = CIFS_DIR_SEP(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (prefix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		dfsplen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		pplen = cifs_sb->prepath ? strlen(cifs_sb->prepath) + 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) cifs_bp_rename_retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	namelen = dfsplen + pplen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	seq = read_seqbegin(&rename_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	for (temp = direntry; !IS_ROOT(temp);) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		namelen += (1 + temp->d_name.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		temp = temp->d_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		if (temp == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			cifs_dbg(VFS, "corrupt dentry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	full_path = kmalloc(namelen+1, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (full_path == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		return full_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	full_path[namelen] = 0;	/* trailing null */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	for (temp = direntry; !IS_ROOT(temp);) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		spin_lock(&temp->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		namelen -= 1 + temp->d_name.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		if (namelen < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			spin_unlock(&temp->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			full_path[namelen] = dirsep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			strncpy(full_path + namelen + 1, temp->d_name.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				temp->d_name.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			cifs_dbg(FYI, "name: %s\n", full_path + namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		spin_unlock(&temp->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		temp = temp->d_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		if (temp == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			cifs_dbg(VFS, "corrupt dentry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			kfree(full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (namelen != dfsplen + pplen || read_seqretry(&rename_lock, seq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		cifs_dbg(FYI, "did not end path lookup where expected. namelen=%ddfsplen=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			 namelen, dfsplen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		/* presumably this is only possible if racing with a rename
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		of one of the parent directories  (we can not lock the dentries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		above us to prevent this, but retrying should be harmless) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		kfree(full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		goto cifs_bp_rename_retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	/* DIR_SEP already set for byte  0 / vs \ but not for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	   subsequent slashes in prepath which currently must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	   be entered the right way - not sure if there is an alternative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	   since the '\' is a valid posix character so we can not switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	   those safely to '/' if any are found in the middle of the prepath */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	/* BB test paths to Windows with '/' in the midst of prepath */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	if (pplen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		cifs_dbg(FYI, "using cifs_sb prepath <%s>\n", cifs_sb->prepath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		memcpy(full_path+dfsplen+1, cifs_sb->prepath, pplen-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		full_path[dfsplen] = dirsep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		for (i = 0; i < pplen-1; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			if (full_path[dfsplen+1+i] == '/')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 				full_path[dfsplen+1+i] = CIFS_DIR_SEP(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (dfsplen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		strncpy(full_path, tcon->treeName, dfsplen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			for (i = 0; i < dfsplen; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 				if (full_path[i] == '\\')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 					full_path[i] = '/';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	return full_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * Don't allow path components longer than the server max.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  * Don't allow the separator character in a path component.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  * The VFS will not allow "/", but "\" is allowed by posix.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) check_name(struct dentry *direntry, struct cifs_tcon *tcon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	if (unlikely(tcon->fsAttrInfo.MaxPathNameComponentLength &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		     direntry->d_name.len >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		     le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		return -ENAMETOOLONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		for (i = 0; i < direntry->d_name.len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			if (direntry->d_name.name[i] == '\\') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 				cifs_dbg(FYI, "Invalid file name\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* Inode operations in similar order to how they appear in Linux file fs.h */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	       struct tcon_link *tlink, unsigned oflags, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	       __u32 *oplock, struct cifs_fid *fid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	int rc = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	int create_options = CREATE_NOT_DIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	int desired_access;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	struct cifs_tcon *tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	char *full_path = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	FILE_ALL_INFO *buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	struct inode *newinode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	int disposition;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	struct TCP_Server_Info *server = tcon->ses->server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	struct cifs_open_parms oparms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	*oplock = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (tcon->ses->server->oplocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		*oplock = REQ_OPLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	full_path = build_path_from_dentry(direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (!full_path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	if (tcon->unix_ext && cap_unix(tcon->ses) && !tcon->broken_posix_open &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	    (CIFS_UNIX_POSIX_PATH_OPS_CAP &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			le64_to_cpu(tcon->fsUnixInfo.Capability))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		rc = cifs_posix_open(full_path, &newinode, inode->i_sb, mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 				     oflags, oplock, &fid->netfid, xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		switch (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			if (newinode == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 				/* query inode info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 				goto cifs_create_get_file_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			if (S_ISDIR(newinode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 				CIFSSMBClose(xid, tcon, fid->netfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 				iput(newinode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 				rc = -EISDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			if (!S_ISREG(newinode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 				 * The server may allow us to open things like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 				 * FIFOs, but the client isn't set up to deal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 				 * with that. If it's not a regular file, just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 				 * close it and proceed as if it were a normal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 				 * lookup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 				CIFSSMBClose(xid, tcon, fid->netfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 				goto cifs_create_get_file_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			/* success, no need to query */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			goto cifs_create_set_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			goto cifs_create_get_file_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		case -EIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		case -EINVAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			 * EIO could indicate that (posix open) operation is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			 * supported, despite what server claimed in capability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			 * negotiation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			 * POSIX open in samba versions 3.3.1 and earlier could
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			 * incorrectly fail with invalid parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			tcon->broken_posix_open = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		case -EREMOTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		case -EOPNOTSUPP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			 * EREMOTE indicates DFS junction, which is not handled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			 * in posix open.  If either that or op not supported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			 * returned, follow the normal lookup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		 * fallthrough to retry, using older open call, this is case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		 * where server does not support this SMB level, and falsely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		 * claims capability (also get here for DFS case which should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		 * rare for path not covered on files)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	desired_access = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	if (OPEN_FMODE(oflags) & FMODE_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		desired_access |= GENERIC_READ; /* is this too little? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (OPEN_FMODE(oflags) & FMODE_WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		desired_access |= GENERIC_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	disposition = FILE_OVERWRITE_IF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		disposition = FILE_CREATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	else if ((oflags & (O_CREAT | O_TRUNC)) == (O_CREAT | O_TRUNC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		disposition = FILE_OVERWRITE_IF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	else if ((oflags & O_CREAT) == O_CREAT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		disposition = FILE_OPEN_IF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		cifs_dbg(FYI, "Create flag not set in create function\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	 * BB add processing to set equivalent of mode - e.g. via CreateX with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	 * ACLs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	if (!server->ops->open) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		rc = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	if (buf == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	 * if we're not using unix extensions, see if we need to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	 * ATTR_READONLY on the create call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	if (!tcon->unix_ext && (mode & S_IWUGO) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		create_options |= CREATE_OPTION_READONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	oparms.tcon = tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	oparms.cifs_sb = cifs_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	oparms.desired_access = desired_access;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	oparms.create_options = cifs_create_options(cifs_sb, create_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	oparms.disposition = disposition;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	oparms.path = full_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	oparms.fid = fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	oparms.reconnect = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	oparms.mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	rc = server->ops->open(xid, &oparms, oplock, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		cifs_dbg(FYI, "cifs_create returned 0x%x\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	 * If Open reported that we actually created a file then we now have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	 * set the mode if possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	if ((tcon->unix_ext) && (*oplock & CIFS_CREATE_ACTION)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		struct cifs_unix_set_info_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 				.mode	= mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 				.ctime	= NO_CHANGE_64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 				.atime	= NO_CHANGE_64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 				.mtime	= NO_CHANGE_64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 				.device	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 			args.uid = current_fsuid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			if (inode->i_mode & S_ISGID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 				args.gid = inode->i_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 				args.gid = current_fsgid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 			args.uid = INVALID_UID; /* no change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 			args.gid = INVALID_GID; /* no change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		CIFSSMBUnixSetFileInfo(xid, tcon, &args, fid->netfid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 				       current->tgid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		 * BB implement mode setting via Windows security
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		 * descriptors e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		/* CIFSSMBWinSetPerms(xid,tcon,path,mode,-1,-1,nls);*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		/* Could set r/o dos attribute if mode & 0222 == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) cifs_create_get_file_info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	/* server might mask mode so we have to query for it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	if (tcon->unix_ext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		rc = cifs_get_inode_info_unix(&newinode, full_path, inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 					      xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		/* TODO: Add support for calling POSIX query info here, but passing in fid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		rc = cifs_get_inode_info(&newinode, full_path, buf, inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 					 xid, fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		if (newinode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 			if (server->ops->set_lease_key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 				server->ops->set_lease_key(newinode, fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 				newinode->i_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 			if ((*oplock & CIFS_CREATE_ACTION) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 			    (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 				newinode->i_uid = current_fsuid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 				if (inode->i_mode & S_ISGID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 					newinode->i_gid = inode->i_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 					newinode->i_gid = current_fsgid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) cifs_create_set_dentry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	if (rc != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		cifs_dbg(FYI, "Create worked, get_inode_info failed rc = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 			 rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	if (S_ISDIR(newinode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		rc = -EISDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	d_drop(direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	d_add(direntry, newinode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	kfree(full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	if (server->ops->close)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		server->ops->close(xid, tcon, fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	if (newinode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		iput(newinode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) cifs_atomic_open(struct inode *inode, struct dentry *direntry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		 struct file *file, unsigned oflags, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	unsigned int xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	struct cifs_tcon *tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	struct TCP_Server_Info *server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	struct cifs_fid fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	struct cifs_pending_open open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	__u32 oplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	struct cifsFileInfo *file_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	 * Posix open is only called (at lookup time) for file create now. For
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	 * opens (rather than creates), because we do not know if it is a file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	 * or directory yet, and current Samba no longer allows us to do posix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	 * open on dirs, we could end up wasting an open call on what turns out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	 * to be a dir. For file opens, we wait to call posix open till
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	 * cifs_open.  It could be added to atomic_open in the future but the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	 * performance tradeoff of the extra network request when EISDIR or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	 * EACCES is returned would have to be weighed against the 50% reduction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	 * in network traffic in the other paths.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	if (!(oflags & O_CREAT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		struct dentry *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		 * Check for hashed negative dentry. We have already revalidated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		 * the dentry and it is fine. No need to perform another lookup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		if (!d_in_lookup(direntry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 			return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		res = cifs_lookup(inode, direntry, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		if (IS_ERR(res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 			return PTR_ERR(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		return finish_no_open(file, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	xid = get_xid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	cifs_dbg(FYI, "parent inode = 0x%p name is: %pd and dentry = 0x%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		 inode, direntry, direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	tlink = cifs_sb_tlink(CIFS_SB(inode->i_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	if (IS_ERR(tlink)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		rc = PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		goto out_free_xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	rc = check_name(direntry, tcon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	server = tcon->ses->server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	if (server->ops->new_lease_key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		server->ops->new_lease_key(&fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	cifs_add_pending_open(&fid, tlink, &open);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 			    &oplock, &fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		cifs_del_pending_open(&open);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		file->f_mode |= FMODE_CREATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	rc = finish_open(file, direntry, generic_file_open);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		if (server->ops->close)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 			server->ops->close(xid, tcon, &fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		cifs_del_pending_open(&open);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	if (file->f_flags & O_DIRECT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	    CIFS_SB(inode->i_sb)->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		if (CIFS_SB(inode->i_sb)->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 			file->f_op = &cifs_file_direct_nobrl_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 			file->f_op = &cifs_file_direct_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	file_info = cifs_new_fileinfo(&fid, file, tlink, oplock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	if (file_info == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 		if (server->ops->close)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 			server->ops->close(xid, tcon, &fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		cifs_del_pending_open(&open);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) out_free_xid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) int cifs_create(struct inode *inode, struct dentry *direntry, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 		bool excl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	unsigned int xid = get_xid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	 * BB below access is probably too much for mknod to request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	 *    but we have to do query and setpathinfo so requesting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	 *    less could fail (unless we want to request getatr and setatr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	 *    permissions (only).  At least for POSIX we do not have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	 *    request so much.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	unsigned oflags = O_EXCL | O_CREAT | O_RDWR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	struct cifs_tcon *tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	struct TCP_Server_Info *server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	struct cifs_fid fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	__u32 oplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	cifs_dbg(FYI, "cifs_create parent inode = 0x%p name is: %pd and dentry = 0x%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		 inode, direntry, direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	tlink = cifs_sb_tlink(CIFS_SB(inode->i_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	rc = PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	if (IS_ERR(tlink))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 		goto out_free_xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	server = tcon->ses->server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	if (server->ops->new_lease_key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 		server->ops->new_lease_key(&fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 			    &oplock, &fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	if (!rc && server->ops->close)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 		server->ops->close(xid, tcon, &fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) out_free_xid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		dev_t device_number)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	int rc = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	unsigned int xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	struct cifs_sb_info *cifs_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	struct cifs_tcon *tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	char *full_path = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	if (!old_valid_dev(device_number))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	cifs_sb = CIFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	tlink = cifs_sb_tlink(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	if (IS_ERR(tlink))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		return PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	xid = get_xid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	full_path = build_path_from_dentry(direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	if (full_path == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 		goto mknod_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	rc = tcon->ses->server->ops->make_node(xid, inode, direntry, tcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 					       full_path, mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 					       device_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) mknod_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	kfree(full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) struct dentry *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	    unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	unsigned int xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	int rc = 0; /* to get around spurious gcc warning, set to zero here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	struct cifs_sb_info *cifs_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	struct cifs_tcon *pTcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	struct inode *newInode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	char *full_path = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	xid = get_xid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	cifs_dbg(FYI, "parent inode = 0x%p name is: %pd and dentry = 0x%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 		 parent_dir_inode, direntry, direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	/* check whether path exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	cifs_sb = CIFS_SB(parent_dir_inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	tlink = cifs_sb_tlink(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	if (IS_ERR(tlink)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 		free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 		return ERR_CAST(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	pTcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	rc = check_name(direntry, pTcon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	if (unlikely(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 		cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 		free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 		return ERR_PTR(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	/* can not grab the rename sem here since it would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	deadlock in the cases (beginning of sys_rename itself)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	in which we already have the sb rename sem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	full_path = build_path_from_dentry(direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	if (full_path == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 		cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	if (d_really_is_positive(direntry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 		cifs_dbg(FYI, "non-NULL inode in lookup\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 		cifs_dbg(FYI, "NULL inode in lookup\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	cifs_dbg(FYI, "Full path: %s inode = 0x%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 		 full_path, d_inode(direntry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	if (pTcon->posix_extensions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 		rc = smb311_posix_get_inode_info(&newInode, full_path, parent_dir_inode->i_sb, xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	else if (pTcon->unix_ext) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 		rc = cifs_get_inode_info_unix(&newInode, full_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 					      parent_dir_inode->i_sb, xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 		rc = cifs_get_inode_info(&newInode, full_path, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 				parent_dir_inode->i_sb, xid, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	if (rc == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 		/* since paths are not looked up by component - the parent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 		   directories are presumed to be good here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 		renew_parental_timestamps(direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	} else if (rc == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 		cifs_set_time(direntry, jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 		newInode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 		if (rc != -EACCES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 			cifs_dbg(FYI, "Unexpected lookup error %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 			/* We special case check for Access Denied - since that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 			is a common return code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 		newInode = ERR_PTR(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	kfree(full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	return d_splice_alias(newInode, direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) cifs_d_revalidate(struct dentry *direntry, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 	if (flags & LOOKUP_RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 		return -ECHILD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	if (d_really_is_positive(direntry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 		inode = d_inode(direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 		if ((flags & LOOKUP_REVAL) && !CIFS_CACHE_READ(CIFS_I(inode)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 			CIFS_I(inode)->time = 0; /* force reval */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 		rc = cifs_revalidate_dentry(direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 			cifs_dbg(FYI, "cifs_revalidate_dentry failed with rc=%d", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 			switch (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 			case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 			case -ESTALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 				 * Those errors mean the dentry is invalid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 				 * (file was deleted or recreated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 				 * Otherwise some unexpected error happened
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 				 * report it as-is to VFS layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 				return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 			 * If the inode wasn't known to be a dfs entry when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 			 * the dentry was instantiated, such as when created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 			 * via ->readdir(), it needs to be set now since the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 			 * attributes will have been updated by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 			 * cifs_revalidate_dentry().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 			if (IS_AUTOMOUNT(inode) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 			   !(direntry->d_flags & DCACHE_NEED_AUTOMOUNT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 				spin_lock(&direntry->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 				direntry->d_flags |= DCACHE_NEED_AUTOMOUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 				spin_unlock(&direntry->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 	 * This may be nfsd (or something), anyway, we can't see the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	 * intent of this. So, since this can be for creation, drop it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 	if (!flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 	 * Drop the negative dentry, in order to make sure to use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 	 * case sensitive name which is specified by user if this is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 	 * for creation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 	if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 	if (time_after(jiffies, cifs_get_time(direntry) + HZ) || !lookupCacheEnabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) /* static int cifs_d_delete(struct dentry *direntry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	cifs_dbg(FYI, "In cifs d_delete, name = %pd\n", direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) }     */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) const struct dentry_operations cifs_dentry_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 	.d_revalidate = cifs_d_revalidate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 	.d_automount = cifs_dfs_d_automount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) /* d_delete:       cifs_d_delete,      */ /* not needed except for debugging */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) static int cifs_ci_hash(const struct dentry *dentry, struct qstr *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 	struct nls_table *codepage = CIFS_SB(dentry->d_sb)->local_nls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 	unsigned long hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 	wchar_t c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 	int i, charlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 	hash = init_name_hash(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 	for (i = 0; i < q->len; i += charlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 		charlen = codepage->char2uni(&q->name[i], q->len - i, &c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 		/* error out if we can't convert the character */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 		if (unlikely(charlen < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 			return charlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 		hash = partial_name_hash(cifs_toupper(c), hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 	q->hash = end_name_hash(hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) static int cifs_ci_compare(const struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 		unsigned int len, const char *str, const struct qstr *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 	struct nls_table *codepage = CIFS_SB(dentry->d_sb)->local_nls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 	wchar_t c1, c2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 	int i, l1, l2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 	 * We make the assumption here that uppercase characters in the local
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 	 * codepage are always the same length as their lowercase counterparts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 	 * If that's ever not the case, then this will fail to match it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 	if (name->len != len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 	for (i = 0; i < len; i += l1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 		/* Convert characters in both strings to UTF-16. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 		l1 = codepage->char2uni(&str[i], len - i, &c1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 		l2 = codepage->char2uni(&name->name[i], name->len - i, &c2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 		 * If we can't convert either character, just declare it to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 		 * be 1 byte long and compare the original byte.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 		if (unlikely(l1 < 0 && l2 < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 			if (str[i] != name->name[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 				return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 			l1 = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) 		 * Here, we again ass|u|me that upper/lowercase versions of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 		 * a character are the same length in the local NLS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 		if (l1 != l2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 		/* Now compare uppercase versions of these characters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 		if (cifs_toupper(c1) != cifs_toupper(c2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) const struct dentry_operations cifs_ci_dentry_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 	.d_revalidate = cifs_d_revalidate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) 	.d_hash = cifs_ci_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) 	.d_compare = cifs_ci_compare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) 	.d_automount = cifs_dfs_d_automount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) };