Linux 6.9-rc1
[linux-2.6-microblaze.git] / fs / cifs / smb2inode.c
1 // SPDX-License-Identifier: LGPL-2.1
2 /*
3  *   fs/cifs/smb2inode.c
4  *
5  *   Copyright (C) International Business Machines  Corp., 2002, 2011
6  *                 Etersoft, 2012
7  *   Author(s): Pavel Shilovsky (pshilovsky@samba.org),
8  *              Steve French (sfrench@us.ibm.com)
9  *
10  */
11 #include <linux/fs.h>
12 #include <linux/stat.h>
13 #include <linux/slab.h>
14 #include <linux/pagemap.h>
15 #include <asm/div64.h>
16 #include "cifsfs.h"
17 #include "cifspdu.h"
18 #include "cifsglob.h"
19 #include "cifsproto.h"
20 #include "cifs_debug.h"
21 #include "cifs_fs_sb.h"
22 #include "cifs_unicode.h"
23 #include "fscache.h"
24 #include "smb2glob.h"
25 #include "smb2pdu.h"
26 #include "smb2proto.h"
27
28 static void
29 free_set_inf_compound(struct smb_rqst *rqst)
30 {
31         if (rqst[1].rq_iov)
32                 SMB2_set_info_free(&rqst[1]);
33         if (rqst[2].rq_iov)
34                 SMB2_close_free(&rqst[2]);
35 }
36
37
38 struct cop_vars {
39         struct cifs_open_parms oparms;
40         struct kvec rsp_iov[3];
41         struct smb_rqst rqst[3];
42         struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
43         struct kvec qi_iov[1];
44         struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
45         struct kvec close_iov[1];
46         struct smb2_file_rename_info rename_info;
47         struct smb2_file_link_info link_info;
48 };
49
50 static int
51 smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
52                  struct cifs_sb_info *cifs_sb, const char *full_path,
53                  __u32 desired_access, __u32 create_disposition,
54                  __u32 create_options, umode_t mode, void *ptr, int command,
55                  struct cifsFileInfo *cfile)
56 {
57         struct cop_vars *vars = NULL;
58         struct kvec *rsp_iov;
59         struct smb_rqst *rqst;
60         int rc;
61         __le16 *utf16_path = NULL;
62         __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
63         struct cifs_fid fid;
64         struct cifs_ses *ses = tcon->ses;
65         struct TCP_Server_Info *server;
66         int num_rqst = 0;
67         int resp_buftype[3];
68         struct smb2_query_info_rsp *qi_rsp = NULL;
69         int flags = 0;
70         __u8 delete_pending[8] = {1, 0, 0, 0, 0, 0, 0, 0};
71         unsigned int size[2];
72         void *data[2];
73         int len;
74
75         vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
76         if (vars == NULL)
77                 return -ENOMEM;
78         rqst = &vars->rqst[0];
79         rsp_iov = &vars->rsp_iov[0];
80
81         server = cifs_pick_channel(ses);
82
83         if (smb3_encryption_required(tcon))
84                 flags |= CIFS_TRANSFORM_REQ;
85
86         resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
87
88         /* We already have a handle so we can skip the open */
89         if (cfile)
90                 goto after_open;
91
92         /* Open */
93         utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
94         if (!utf16_path) {
95                 rc = -ENOMEM;
96                 goto finished;
97         }
98
99         vars->oparms.tcon = tcon;
100         vars->oparms.desired_access = desired_access;
101         vars->oparms.disposition = create_disposition;
102         vars->oparms.create_options = cifs_create_options(cifs_sb, create_options);
103         vars->oparms.fid = &fid;
104         vars->oparms.reconnect = false;
105         vars->oparms.mode = mode;
106         vars->oparms.cifs_sb = cifs_sb;
107
108         rqst[num_rqst].rq_iov = &vars->open_iov[0];
109         rqst[num_rqst].rq_nvec = SMB2_CREATE_IOV_SIZE;
110         rc = SMB2_open_init(tcon, server,
111                             &rqst[num_rqst], &oplock, &vars->oparms,
112                             utf16_path);
113         kfree(utf16_path);
114         if (rc)
115                 goto finished;
116
117         smb2_set_next_command(tcon, &rqst[num_rqst]);
118  after_open:
119         num_rqst++;
120         rc = 0;
121
122         /* Operation */
123         switch (command) {
124         case SMB2_OP_QUERY_INFO:
125                 rqst[num_rqst].rq_iov = &vars->qi_iov[0];
126                 rqst[num_rqst].rq_nvec = 1;
127
128                 if (cfile)
129                         rc = SMB2_query_info_init(tcon, server,
130                                 &rqst[num_rqst],
131                                 cfile->fid.persistent_fid,
132                                 cfile->fid.volatile_fid,
133                                 FILE_ALL_INFORMATION,
134                                 SMB2_O_INFO_FILE, 0,
135                                 sizeof(struct smb2_file_all_info) +
136                                           PATH_MAX * 2, 0, NULL);
137                 else {
138                         rc = SMB2_query_info_init(tcon, server,
139                                 &rqst[num_rqst],
140                                 COMPOUND_FID,
141                                 COMPOUND_FID,
142                                 FILE_ALL_INFORMATION,
143                                 SMB2_O_INFO_FILE, 0,
144                                 sizeof(struct smb2_file_all_info) +
145                                           PATH_MAX * 2, 0, NULL);
146                         if (!rc) {
147                                 smb2_set_next_command(tcon, &rqst[num_rqst]);
148                                 smb2_set_related(&rqst[num_rqst]);
149                         }
150                 }
151
152                 if (rc)
153                         goto finished;
154                 num_rqst++;
155                 trace_smb3_query_info_compound_enter(xid, ses->Suid, tcon->tid,
156                                                      full_path);
157                 break;
158         case SMB2_OP_POSIX_QUERY_INFO:
159                 rqst[num_rqst].rq_iov = &vars->qi_iov[0];
160                 rqst[num_rqst].rq_nvec = 1;
161
162                 if (cfile)
163                         rc = SMB2_query_info_init(tcon, server,
164                                 &rqst[num_rqst],
165                                 cfile->fid.persistent_fid,
166                                 cfile->fid.volatile_fid,
167                                 SMB_FIND_FILE_POSIX_INFO,
168                                 SMB2_O_INFO_FILE, 0,
169                                 /* TBD: fix following to allow for longer SIDs */
170                                 sizeof(struct smb311_posix_qinfo *) + (PATH_MAX * 2) +
171                                 (sizeof(struct cifs_sid) * 2), 0, NULL);
172                 else {
173                         rc = SMB2_query_info_init(tcon, server,
174                                 &rqst[num_rqst],
175                                 COMPOUND_FID,
176                                 COMPOUND_FID,
177                                 SMB_FIND_FILE_POSIX_INFO,
178                                 SMB2_O_INFO_FILE, 0,
179                                 sizeof(struct smb311_posix_qinfo *) + (PATH_MAX * 2) +
180                                 (sizeof(struct cifs_sid) * 2), 0, NULL);
181                         if (!rc) {
182                                 smb2_set_next_command(tcon, &rqst[num_rqst]);
183                                 smb2_set_related(&rqst[num_rqst]);
184                         }
185                 }
186
187                 if (rc)
188                         goto finished;
189                 num_rqst++;
190                 trace_smb3_posix_query_info_compound_enter(xid, ses->Suid, tcon->tid, full_path);
191                 break;
192         case SMB2_OP_DELETE:
193                 trace_smb3_delete_enter(xid, ses->Suid, tcon->tid, full_path);
194                 break;
195         case SMB2_OP_MKDIR:
196                 /*
197                  * Directories are created through parameters in the
198                  * SMB2_open() call.
199                  */
200                 trace_smb3_mkdir_enter(xid, ses->Suid, tcon->tid, full_path);
201                 break;
202         case SMB2_OP_RMDIR:
203                 rqst[num_rqst].rq_iov = &vars->si_iov[0];
204                 rqst[num_rqst].rq_nvec = 1;
205
206                 size[0] = 1; /* sizeof __u8 See MS-FSCC section 2.4.11 */
207                 data[0] = &delete_pending[0];
208
209                 rc = SMB2_set_info_init(tcon, server,
210                                         &rqst[num_rqst], COMPOUND_FID,
211                                         COMPOUND_FID, current->tgid,
212                                         FILE_DISPOSITION_INFORMATION,
213                                         SMB2_O_INFO_FILE, 0, data, size);
214                 if (rc)
215                         goto finished;
216                 smb2_set_next_command(tcon, &rqst[num_rqst]);
217                 smb2_set_related(&rqst[num_rqst++]);
218                 trace_smb3_rmdir_enter(xid, ses->Suid, tcon->tid, full_path);
219                 break;
220         case SMB2_OP_SET_EOF:
221                 rqst[num_rqst].rq_iov = &vars->si_iov[0];
222                 rqst[num_rqst].rq_nvec = 1;
223
224                 size[0] = 8; /* sizeof __le64 */
225                 data[0] = ptr;
226
227                 rc = SMB2_set_info_init(tcon, server,
228                                         &rqst[num_rqst], COMPOUND_FID,
229                                         COMPOUND_FID, current->tgid,
230                                         FILE_END_OF_FILE_INFORMATION,
231                                         SMB2_O_INFO_FILE, 0, data, size);
232                 if (rc)
233                         goto finished;
234                 smb2_set_next_command(tcon, &rqst[num_rqst]);
235                 smb2_set_related(&rqst[num_rqst++]);
236                 trace_smb3_set_eof_enter(xid, ses->Suid, tcon->tid, full_path);
237                 break;
238         case SMB2_OP_SET_INFO:
239                 rqst[num_rqst].rq_iov = &vars->si_iov[0];
240                 rqst[num_rqst].rq_nvec = 1;
241
242
243                 size[0] = sizeof(FILE_BASIC_INFO);
244                 data[0] = ptr;
245
246                 if (cfile)
247                         rc = SMB2_set_info_init(tcon, server,
248                                 &rqst[num_rqst],
249                                 cfile->fid.persistent_fid,
250                                 cfile->fid.volatile_fid, current->tgid,
251                                 FILE_BASIC_INFORMATION,
252                                 SMB2_O_INFO_FILE, 0, data, size);
253                 else {
254                         rc = SMB2_set_info_init(tcon, server,
255                                 &rqst[num_rqst],
256                                 COMPOUND_FID,
257                                 COMPOUND_FID, current->tgid,
258                                 FILE_BASIC_INFORMATION,
259                                 SMB2_O_INFO_FILE, 0, data, size);
260                         if (!rc) {
261                                 smb2_set_next_command(tcon, &rqst[num_rqst]);
262                                 smb2_set_related(&rqst[num_rqst]);
263                         }
264                 }
265
266                 if (rc)
267                         goto finished;
268                 num_rqst++;
269                 trace_smb3_set_info_compound_enter(xid, ses->Suid, tcon->tid,
270                                                    full_path);
271                 break;
272         case SMB2_OP_RENAME:
273                 rqst[num_rqst].rq_iov = &vars->si_iov[0];
274                 rqst[num_rqst].rq_nvec = 2;
275
276                 len = (2 * UniStrnlen((wchar_t *)ptr, PATH_MAX));
277
278                 vars->rename_info.ReplaceIfExists = 1;
279                 vars->rename_info.RootDirectory = 0;
280                 vars->rename_info.FileNameLength = cpu_to_le32(len);
281
282                 size[0] = sizeof(struct smb2_file_rename_info);
283                 data[0] = &vars->rename_info;
284
285                 size[1] = len + 2 /* null */;
286                 data[1] = (__le16 *)ptr;
287
288                 if (cfile)
289                         rc = SMB2_set_info_init(tcon, server,
290                                                 &rqst[num_rqst],
291                                                 cfile->fid.persistent_fid,
292                                                 cfile->fid.volatile_fid,
293                                         current->tgid, FILE_RENAME_INFORMATION,
294                                         SMB2_O_INFO_FILE, 0, data, size);
295                 else {
296                         rc = SMB2_set_info_init(tcon, server,
297                                         &rqst[num_rqst],
298                                         COMPOUND_FID, COMPOUND_FID,
299                                         current->tgid, FILE_RENAME_INFORMATION,
300                                         SMB2_O_INFO_FILE, 0, data, size);
301                         if (!rc) {
302                                 smb2_set_next_command(tcon, &rqst[num_rqst]);
303                                 smb2_set_related(&rqst[num_rqst]);
304                         }
305                 }
306                 if (rc)
307                         goto finished;
308                 num_rqst++;
309                 trace_smb3_rename_enter(xid, ses->Suid, tcon->tid, full_path);
310                 break;
311         case SMB2_OP_HARDLINK:
312                 rqst[num_rqst].rq_iov = &vars->si_iov[0];
313                 rqst[num_rqst].rq_nvec = 2;
314
315                 len = (2 * UniStrnlen((wchar_t *)ptr, PATH_MAX));
316
317                 vars->link_info.ReplaceIfExists = 0;
318                 vars->link_info.RootDirectory = 0;
319                 vars->link_info.FileNameLength = cpu_to_le32(len);
320
321                 size[0] = sizeof(struct smb2_file_link_info);
322                 data[0] = &vars->link_info;
323
324                 size[1] = len + 2 /* null */;
325                 data[1] = (__le16 *)ptr;
326
327                 rc = SMB2_set_info_init(tcon, server,
328                                         &rqst[num_rqst], COMPOUND_FID,
329                                         COMPOUND_FID, current->tgid,
330                                         FILE_LINK_INFORMATION,
331                                         SMB2_O_INFO_FILE, 0, data, size);
332                 if (rc)
333                         goto finished;
334                 smb2_set_next_command(tcon, &rqst[num_rqst]);
335                 smb2_set_related(&rqst[num_rqst++]);
336                 trace_smb3_hardlink_enter(xid, ses->Suid, tcon->tid, full_path);
337                 break;
338         default:
339                 cifs_dbg(VFS, "Invalid command\n");
340                 rc = -EINVAL;
341         }
342         if (rc)
343                 goto finished;
344
345         /* We already have a handle so we can skip the close */
346         if (cfile)
347                 goto after_close;
348         /* Close */
349         flags |= CIFS_CP_CREATE_CLOSE_OP;
350         rqst[num_rqst].rq_iov = &vars->close_iov[0];
351         rqst[num_rqst].rq_nvec = 1;
352         rc = SMB2_close_init(tcon, server,
353                              &rqst[num_rqst], COMPOUND_FID,
354                              COMPOUND_FID, false);
355         smb2_set_related(&rqst[num_rqst]);
356         if (rc)
357                 goto finished;
358  after_close:
359         num_rqst++;
360
361         if (cfile) {
362                 cifsFileInfo_put(cfile);
363                 cfile = NULL;
364                 rc = compound_send_recv(xid, ses, server,
365                                         flags, num_rqst - 2,
366                                         &rqst[1], &resp_buftype[1],
367                                         &rsp_iov[1]);
368         } else
369                 rc = compound_send_recv(xid, ses, server,
370                                         flags, num_rqst,
371                                         rqst, resp_buftype,
372                                         rsp_iov);
373
374  finished:
375         if (cfile)
376                 cifsFileInfo_put(cfile);
377
378         SMB2_open_free(&rqst[0]);
379         if (rc == -EREMCHG) {
380                 pr_warn_once("server share %s deleted\n", tcon->treeName);
381                 tcon->need_reconnect = true;
382         }
383
384         switch (command) {
385         case SMB2_OP_QUERY_INFO:
386                 if (rc == 0) {
387                         qi_rsp = (struct smb2_query_info_rsp *)
388                                 rsp_iov[1].iov_base;
389                         rc = smb2_validate_and_copy_iov(
390                                 le16_to_cpu(qi_rsp->OutputBufferOffset),
391                                 le32_to_cpu(qi_rsp->OutputBufferLength),
392                                 &rsp_iov[1], sizeof(struct smb2_file_all_info),
393                                 ptr);
394                 }
395                 if (rqst[1].rq_iov)
396                         SMB2_query_info_free(&rqst[1]);
397                 if (rqst[2].rq_iov)
398                         SMB2_close_free(&rqst[2]);
399                 if (rc)
400                         trace_smb3_query_info_compound_err(xid,  ses->Suid,
401                                                 tcon->tid, rc);
402                 else
403                         trace_smb3_query_info_compound_done(xid, ses->Suid,
404                                                 tcon->tid);
405                 break;
406         case SMB2_OP_POSIX_QUERY_INFO:
407                 if (rc == 0) {
408                         qi_rsp = (struct smb2_query_info_rsp *)
409                                 rsp_iov[1].iov_base;
410                         rc = smb2_validate_and_copy_iov(
411                                 le16_to_cpu(qi_rsp->OutputBufferOffset),
412                                 le32_to_cpu(qi_rsp->OutputBufferLength),
413                                 &rsp_iov[1], sizeof(struct smb311_posix_qinfo) /* add SIDs */, ptr);
414                 }
415                 if (rqst[1].rq_iov)
416                         SMB2_query_info_free(&rqst[1]);
417                 if (rqst[2].rq_iov)
418                         SMB2_close_free(&rqst[2]);
419                 if (rc)
420                         trace_smb3_posix_query_info_compound_err(xid,  ses->Suid, tcon->tid, rc);
421                 else
422                         trace_smb3_posix_query_info_compound_done(xid, ses->Suid, tcon->tid);
423                 break;
424         case SMB2_OP_DELETE:
425                 if (rc)
426                         trace_smb3_delete_err(xid,  ses->Suid, tcon->tid, rc);
427                 else
428                         trace_smb3_delete_done(xid, ses->Suid, tcon->tid);
429                 if (rqst[1].rq_iov)
430                         SMB2_close_free(&rqst[1]);
431                 break;
432         case SMB2_OP_MKDIR:
433                 if (rc)
434                         trace_smb3_mkdir_err(xid,  ses->Suid, tcon->tid, rc);
435                 else
436                         trace_smb3_mkdir_done(xid, ses->Suid, tcon->tid);
437                 if (rqst[1].rq_iov)
438                         SMB2_close_free(&rqst[1]);
439                 break;
440         case SMB2_OP_HARDLINK:
441                 if (rc)
442                         trace_smb3_hardlink_err(xid,  ses->Suid, tcon->tid, rc);
443                 else
444                         trace_smb3_hardlink_done(xid, ses->Suid, tcon->tid);
445                 free_set_inf_compound(rqst);
446                 break;
447         case SMB2_OP_RENAME:
448                 if (rc)
449                         trace_smb3_rename_err(xid,  ses->Suid, tcon->tid, rc);
450                 else
451                         trace_smb3_rename_done(xid, ses->Suid, tcon->tid);
452                 free_set_inf_compound(rqst);
453                 break;
454         case SMB2_OP_RMDIR:
455                 if (rc)
456                         trace_smb3_rmdir_err(xid,  ses->Suid, tcon->tid, rc);
457                 else
458                         trace_smb3_rmdir_done(xid, ses->Suid, tcon->tid);
459                 free_set_inf_compound(rqst);
460                 break;
461         case SMB2_OP_SET_EOF:
462                 if (rc)
463                         trace_smb3_set_eof_err(xid,  ses->Suid, tcon->tid, rc);
464                 else
465                         trace_smb3_set_eof_done(xid, ses->Suid, tcon->tid);
466                 free_set_inf_compound(rqst);
467                 break;
468         case SMB2_OP_SET_INFO:
469                 if (rc)
470                         trace_smb3_set_info_compound_err(xid,  ses->Suid,
471                                                 tcon->tid, rc);
472                 else
473                         trace_smb3_set_info_compound_done(xid, ses->Suid,
474                                                 tcon->tid);
475                 free_set_inf_compound(rqst);
476                 break;
477         }
478         free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
479         free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
480         free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
481         kfree(vars);
482         return rc;
483 }
484
485 void
486 move_smb2_info_to_cifs(FILE_ALL_INFO *dst, struct smb2_file_all_info *src)
487 {
488         memcpy(dst, src, (size_t)(&src->CurrentByteOffset) - (size_t)src);
489         dst->CurrentByteOffset = src->CurrentByteOffset;
490         dst->Mode = src->Mode;
491         dst->AlignmentRequirement = src->AlignmentRequirement;
492         dst->IndexNumber1 = 0; /* we don't use it */
493 }
494
495 int
496 smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
497                      struct cifs_sb_info *cifs_sb, const char *full_path,
498                      FILE_ALL_INFO *data, bool *adjust_tz, bool *reparse)
499 {
500         int rc;
501         struct smb2_file_all_info *smb2_data;
502         __u32 create_options = 0;
503         struct cifsFileInfo *cfile;
504         struct cached_fid *cfid = NULL;
505
506         *adjust_tz = false;
507         *reparse = false;
508
509         smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
510                             GFP_KERNEL);
511         if (smb2_data == NULL)
512                 return -ENOMEM;
513
514         /* If it is a root and its handle is cached then use it */
515         rc = open_cached_dir(xid, tcon, full_path, cifs_sb, &cfid);
516         if (!rc) {
517                 if (tcon->crfid.file_all_info_is_valid) {
518                         move_smb2_info_to_cifs(data,
519                                                &tcon->crfid.file_all_info);
520                 } else {
521                         rc = SMB2_query_info(xid, tcon,
522                                              cfid->fid->persistent_fid,
523                                              cfid->fid->volatile_fid, smb2_data);
524                         if (!rc)
525                                 move_smb2_info_to_cifs(data, smb2_data);
526                 }
527                 close_cached_dir(cfid);
528                 goto out;
529         }
530
531         cifs_get_readable_path(tcon, full_path, &cfile);
532         rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
533                               FILE_READ_ATTRIBUTES, FILE_OPEN, create_options,
534                               ACL_NO_MODE, smb2_data, SMB2_OP_QUERY_INFO, cfile);
535         if (rc == -EOPNOTSUPP) {
536                 *reparse = true;
537                 create_options |= OPEN_REPARSE_POINT;
538
539                 /* Failed on a symbolic link - query a reparse point info */
540                 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
541                                       FILE_READ_ATTRIBUTES, FILE_OPEN,
542                                       create_options, ACL_NO_MODE,
543                                       smb2_data, SMB2_OP_QUERY_INFO, NULL);
544         }
545         if (rc)
546                 goto out;
547
548         move_smb2_info_to_cifs(data, smb2_data);
549 out:
550         kfree(smb2_data);
551         return rc;
552 }
553
554
555 int
556 smb311_posix_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
557                      struct cifs_sb_info *cifs_sb, const char *full_path,
558                      struct smb311_posix_qinfo *data, bool *adjust_tz, bool *reparse)
559 {
560         int rc;
561         __u32 create_options = 0;
562         struct cifsFileInfo *cfile;
563         struct smb311_posix_qinfo *smb2_data;
564
565         *adjust_tz = false;
566         *reparse = false;
567
568         /* BB TODO: Make struct larger when add support for parsing owner SIDs */
569         smb2_data = kzalloc(sizeof(struct smb311_posix_qinfo),
570                             GFP_KERNEL);
571         if (smb2_data == NULL)
572                 return -ENOMEM;
573
574         /*
575          * BB TODO: Add support for using the cached root handle.
576          * Create SMB2_query_posix_info worker function to do non-compounded query
577          * when we already have an open file handle for this. For now this is fast enough
578          * (always using the compounded version).
579          */
580
581         cifs_get_readable_path(tcon, full_path, &cfile);
582         rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
583                               FILE_READ_ATTRIBUTES, FILE_OPEN, create_options,
584                               ACL_NO_MODE, smb2_data, SMB2_OP_POSIX_QUERY_INFO, cfile);
585         if (rc == -EOPNOTSUPP) {
586                 /* BB TODO: When support for special files added to Samba re-verify this path */
587                 *reparse = true;
588                 create_options |= OPEN_REPARSE_POINT;
589
590                 /* Failed on a symbolic link - query a reparse point info */
591                 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
592                                       FILE_READ_ATTRIBUTES, FILE_OPEN,
593                                       create_options, ACL_NO_MODE,
594                                       smb2_data, SMB2_OP_POSIX_QUERY_INFO, NULL);
595         }
596         if (rc)
597                 goto out;
598
599          /* TODO: will need to allow for the 2 SIDs when add support for getting owner UID/GID */
600         memcpy(data, smb2_data, sizeof(struct smb311_posix_qinfo));
601
602 out:
603         kfree(smb2_data);
604         return rc;
605 }
606
607 int
608 smb2_mkdir(const unsigned int xid, struct inode *parent_inode, umode_t mode,
609            struct cifs_tcon *tcon, const char *name,
610            struct cifs_sb_info *cifs_sb)
611 {
612         return smb2_compound_op(xid, tcon, cifs_sb, name,
613                                 FILE_WRITE_ATTRIBUTES, FILE_CREATE,
614                                 CREATE_NOT_FILE, mode, NULL, SMB2_OP_MKDIR,
615                                 NULL);
616 }
617
618 void
619 smb2_mkdir_setinfo(struct inode *inode, const char *name,
620                    struct cifs_sb_info *cifs_sb, struct cifs_tcon *tcon,
621                    const unsigned int xid)
622 {
623         FILE_BASIC_INFO data;
624         struct cifsInodeInfo *cifs_i;
625         struct cifsFileInfo *cfile;
626         u32 dosattrs;
627         int tmprc;
628
629         memset(&data, 0, sizeof(data));
630         cifs_i = CIFS_I(inode);
631         dosattrs = cifs_i->cifsAttrs | ATTR_READONLY;
632         data.Attributes = cpu_to_le32(dosattrs);
633         cifs_get_writable_path(tcon, name, FIND_WR_ANY, &cfile);
634         tmprc = smb2_compound_op(xid, tcon, cifs_sb, name,
635                                  FILE_WRITE_ATTRIBUTES, FILE_CREATE,
636                                  CREATE_NOT_FILE, ACL_NO_MODE,
637                                  &data, SMB2_OP_SET_INFO, cfile);
638         if (tmprc == 0)
639                 cifs_i->cifsAttrs = dosattrs;
640 }
641
642 int
643 smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
644            struct cifs_sb_info *cifs_sb)
645 {
646         return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
647                                 CREATE_NOT_FILE, ACL_NO_MODE,
648                                 NULL, SMB2_OP_RMDIR, NULL);
649 }
650
651 int
652 smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
653             struct cifs_sb_info *cifs_sb)
654 {
655         return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
656                                 CREATE_DELETE_ON_CLOSE | OPEN_REPARSE_POINT,
657                                 ACL_NO_MODE, NULL, SMB2_OP_DELETE, NULL);
658 }
659
660 static int
661 smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon,
662                    const char *from_name, const char *to_name,
663                    struct cifs_sb_info *cifs_sb, __u32 access, int command,
664                    struct cifsFileInfo *cfile)
665 {
666         __le16 *smb2_to_name = NULL;
667         int rc;
668
669         smb2_to_name = cifs_convert_path_to_utf16(to_name, cifs_sb);
670         if (smb2_to_name == NULL) {
671                 rc = -ENOMEM;
672                 goto smb2_rename_path;
673         }
674         rc = smb2_compound_op(xid, tcon, cifs_sb, from_name, access,
675                               FILE_OPEN, 0, ACL_NO_MODE, smb2_to_name,
676                               command, cfile);
677 smb2_rename_path:
678         kfree(smb2_to_name);
679         return rc;
680 }
681
682 int
683 smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon,
684                  const char *from_name, const char *to_name,
685                  struct cifs_sb_info *cifs_sb)
686 {
687         struct cifsFileInfo *cfile;
688
689         cifs_get_writable_path(tcon, from_name, FIND_WR_WITH_DELETE, &cfile);
690
691         return smb2_set_path_attr(xid, tcon, from_name, to_name,
692                                   cifs_sb, DELETE, SMB2_OP_RENAME, cfile);
693 }
694
695 int
696 smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon,
697                      const char *from_name, const char *to_name,
698                      struct cifs_sb_info *cifs_sb)
699 {
700         return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb,
701                                   FILE_READ_ATTRIBUTES, SMB2_OP_HARDLINK,
702                                   NULL);
703 }
704
705 int
706 smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon,
707                    const char *full_path, __u64 size,
708                    struct cifs_sb_info *cifs_sb, bool set_alloc)
709 {
710         __le64 eof = cpu_to_le64(size);
711
712         return smb2_compound_op(xid, tcon, cifs_sb, full_path,
713                                 FILE_WRITE_DATA, FILE_OPEN, 0, ACL_NO_MODE,
714                                 &eof, SMB2_OP_SET_EOF, NULL);
715 }
716
717 int
718 smb2_set_file_info(struct inode *inode, const char *full_path,
719                    FILE_BASIC_INFO *buf, const unsigned int xid)
720 {
721         struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
722         struct tcon_link *tlink;
723         int rc;
724
725         if ((buf->CreationTime == 0) && (buf->LastAccessTime == 0) &&
726             (buf->LastWriteTime == 0) && (buf->ChangeTime == 0) &&
727             (buf->Attributes == 0))
728                 return 0; /* would be a no op, no sense sending this */
729
730         tlink = cifs_sb_tlink(cifs_sb);
731         if (IS_ERR(tlink))
732                 return PTR_ERR(tlink);
733
734         rc = smb2_compound_op(xid, tlink_tcon(tlink), cifs_sb, full_path,
735                               FILE_WRITE_ATTRIBUTES, FILE_OPEN,
736                               0, ACL_NO_MODE, buf, SMB2_OP_SET_INFO, NULL);
737         cifs_put_tlink(tlink);
738         return rc;
739 }