~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/smb/client/dir.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/smb/client/dir.c (Version linux-6.12-rc7) and /fs/smb/client/dir.c (Version linux-6.4.16)


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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php