1 // SPDX-License-Identifier: LGPL-2.1
4 * Copyright (C) International Business Machines Corp., 2002, 2011
6 * Author(s): Pavel Shilovsky (pshilovsky@samba.org),
7 * Steve French (sfrench@us.ibm.com)
11 #include <linux/stat.h>
12 #include <linux/slab.h>
13 #include <linux/pagemap.h>
14 #include <asm/div64.h>
18 #include "cifsproto.h"
19 #include "cifs_debug.h"
20 #include "cifs_fs_sb.h"
21 #include "cifs_unicode.h"
25 #include "smb2proto.h"
26 #include "cached_dir.h"
27 #include "smb2status.h"
29 static struct reparse_data_buffer *reparse_buf_ptr(struct kvec *iov)
31 struct reparse_data_buffer *buf;
32 struct smb2_ioctl_rsp *io = iov->iov_base;
35 count = le32_to_cpu(io->OutputCount);
36 off = le32_to_cpu(io->OutputOffset);
37 if (check_add_overflow(off, count, &len) || len > iov->iov_len)
40 buf = (struct reparse_data_buffer *)((u8 *)io + off);
42 if (count < len || count < le16_to_cpu(buf->ReparseDataLength) + len)
47 static inline __u32 file_create_options(struct dentry *dentry)
49 struct cifsInodeInfo *ci;
52 ci = CIFS_I(d_inode(dentry));
53 if (ci->cifsAttrs & ATTR_REPARSE)
54 return OPEN_REPARSE_POINT;
59 /* Parse owner and group from SMB3.1.1 POSIX query info */
60 static int parse_posix_sids(struct cifs_open_info_data *data,
63 struct smb2_query_info_rsp *qi = rsp_iov->iov_base;
64 unsigned int out_len = le32_to_cpu(qi->OutputBufferLength);
65 unsigned int qi_len = sizeof(data->posix_fi);
66 int owner_len, group_len;
67 u8 *sidsbuf, *sidsbuf_end;
69 if (out_len <= qi_len)
72 sidsbuf = (u8 *)qi + le16_to_cpu(qi->OutputBufferOffset) + qi_len;
73 sidsbuf_end = sidsbuf + out_len - qi_len;
75 owner_len = posix_info_sid_size(sidsbuf, sidsbuf_end);
79 memcpy(&data->posix_owner, sidsbuf, owner_len);
80 group_len = posix_info_sid_size(sidsbuf + owner_len, sidsbuf_end);
84 memcpy(&data->posix_group, sidsbuf + owner_len, group_len);
89 * note: If cfile is passed, the reference to it is dropped here.
90 * So make sure that you do not reuse cfile after return from this func.
92 * If passing @out_iov and @out_buftype, ensure to make them both large enough
93 * (>= 3) to hold all compounded responses. Caller is also responsible for
94 * freeing them up with free_rsp_buf().
96 static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
97 struct cifs_sb_info *cifs_sb, const char *full_path,
98 __u32 desired_access, __u32 create_disposition,
99 __u32 create_options, umode_t mode, struct kvec *in_iov,
100 int *cmds, int num_cmds, struct cifsFileInfo *cfile,
101 struct kvec *out_iov, int *out_buftype)
104 struct reparse_data_buffer *rbuf;
105 struct smb2_compound_vars *vars = NULL;
106 struct kvec *rsp_iov, *iov;
107 struct smb_rqst *rqst;
109 __le16 *utf16_path = NULL;
110 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
112 struct cifs_ses *ses = tcon->ses;
113 struct TCP_Server_Info *server;
115 int resp_buftype[MAX_COMPOUND];
116 struct smb2_query_info_rsp *qi_rsp = NULL;
117 struct cifs_open_info_data *idata;
119 __u8 delete_pending[8] = {1, 0, 0, 0, 0, 0, 0, 0};
120 unsigned int size[2];
124 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
127 rqst = &vars->rqst[0];
128 rsp_iov = &vars->rsp_iov[0];
130 server = cifs_pick_channel(ses);
132 if (smb3_encryption_required(tcon))
133 flags |= CIFS_TRANSFORM_REQ;
135 for (i = 0; i < ARRAY_SIZE(resp_buftype); i++)
136 resp_buftype[i] = CIFS_NO_BUFFER;
138 /* We already have a handle so we can skip the open */
143 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
149 vars->oparms = (struct cifs_open_parms) {
152 .desired_access = desired_access,
153 .disposition = create_disposition,
154 .create_options = cifs_create_options(cifs_sb, create_options),
160 rqst[num_rqst].rq_iov = &vars->open_iov[0];
161 rqst[num_rqst].rq_nvec = SMB2_CREATE_IOV_SIZE;
162 rc = SMB2_open_init(tcon, server,
163 &rqst[num_rqst], &oplock, &vars->oparms,
169 smb2_set_next_command(tcon, &rqst[num_rqst]);
174 for (i = 0; i < num_cmds; i++) {
177 case SMB2_OP_QUERY_INFO:
178 rqst[num_rqst].rq_iov = &vars->qi_iov;
179 rqst[num_rqst].rq_nvec = 1;
182 rc = SMB2_query_info_init(tcon, server,
184 cfile->fid.persistent_fid,
185 cfile->fid.volatile_fid,
186 FILE_ALL_INFORMATION,
188 sizeof(struct smb2_file_all_info) +
189 PATH_MAX * 2, 0, NULL);
191 rc = SMB2_query_info_init(tcon, server,
195 FILE_ALL_INFORMATION,
197 sizeof(struct smb2_file_all_info) +
198 PATH_MAX * 2, 0, NULL);
200 smb2_set_next_command(tcon, &rqst[num_rqst]);
201 smb2_set_related(&rqst[num_rqst]);
208 trace_smb3_query_info_compound_enter(xid, ses->Suid,
209 tcon->tid, full_path);
211 case SMB2_OP_POSIX_QUERY_INFO:
212 rqst[num_rqst].rq_iov = &vars->qi_iov;
213 rqst[num_rqst].rq_nvec = 1;
216 /* TBD: fix following to allow for longer SIDs */
217 rc = SMB2_query_info_init(tcon, server,
219 cfile->fid.persistent_fid,
220 cfile->fid.volatile_fid,
221 SMB_FIND_FILE_POSIX_INFO,
223 sizeof(struct smb311_posix_qinfo *) +
225 (sizeof(struct cifs_sid) * 2), 0, NULL);
227 rc = SMB2_query_info_init(tcon, server,
231 SMB_FIND_FILE_POSIX_INFO,
233 sizeof(struct smb311_posix_qinfo *) +
235 (sizeof(struct cifs_sid) * 2), 0, NULL);
237 smb2_set_next_command(tcon, &rqst[num_rqst]);
238 smb2_set_related(&rqst[num_rqst]);
245 trace_smb3_posix_query_info_compound_enter(xid, ses->Suid,
246 tcon->tid, full_path);
249 trace_smb3_delete_enter(xid, ses->Suid, tcon->tid, full_path);
253 * Directories are created through parameters in the
256 trace_smb3_mkdir_enter(xid, ses->Suid, tcon->tid, full_path);
259 rqst[num_rqst].rq_iov = &vars->si_iov[0];
260 rqst[num_rqst].rq_nvec = 1;
262 size[0] = 1; /* sizeof __u8 See MS-FSCC section 2.4.11 */
263 data[0] = &delete_pending[0];
265 rc = SMB2_set_info_init(tcon, server,
266 &rqst[num_rqst], COMPOUND_FID,
267 COMPOUND_FID, current->tgid,
268 FILE_DISPOSITION_INFORMATION,
269 SMB2_O_INFO_FILE, 0, data, size);
272 smb2_set_next_command(tcon, &rqst[num_rqst]);
273 smb2_set_related(&rqst[num_rqst++]);
274 trace_smb3_rmdir_enter(xid, ses->Suid, tcon->tid, full_path);
276 case SMB2_OP_SET_EOF:
277 rqst[num_rqst].rq_iov = &vars->si_iov[0];
278 rqst[num_rqst].rq_nvec = 1;
280 size[0] = in_iov[i].iov_len;
281 data[0] = in_iov[i].iov_base;
284 rc = SMB2_set_info_init(tcon, server,
286 cfile->fid.persistent_fid,
287 cfile->fid.volatile_fid,
289 FILE_END_OF_FILE_INFORMATION,
293 rc = SMB2_set_info_init(tcon, server,
298 FILE_END_OF_FILE_INFORMATION,
302 smb2_set_next_command(tcon, &rqst[num_rqst]);
303 smb2_set_related(&rqst[num_rqst]);
309 trace_smb3_set_eof_enter(xid, ses->Suid, tcon->tid, full_path);
311 case SMB2_OP_SET_INFO:
312 rqst[num_rqst].rq_iov = &vars->si_iov[0];
313 rqst[num_rqst].rq_nvec = 1;
315 size[0] = in_iov[i].iov_len;
316 data[0] = in_iov[i].iov_base;
319 rc = SMB2_set_info_init(tcon, server,
321 cfile->fid.persistent_fid,
322 cfile->fid.volatile_fid, current->tgid,
323 FILE_BASIC_INFORMATION,
324 SMB2_O_INFO_FILE, 0, data, size);
326 rc = SMB2_set_info_init(tcon, server,
329 COMPOUND_FID, current->tgid,
330 FILE_BASIC_INFORMATION,
331 SMB2_O_INFO_FILE, 0, data, size);
333 smb2_set_next_command(tcon, &rqst[num_rqst]);
334 smb2_set_related(&rqst[num_rqst]);
341 trace_smb3_set_info_compound_enter(xid, ses->Suid,
342 tcon->tid, full_path);
345 rqst[num_rqst].rq_iov = &vars->si_iov[0];
346 rqst[num_rqst].rq_nvec = 2;
348 len = in_iov[i].iov_len;
350 vars->rename_info.ReplaceIfExists = 1;
351 vars->rename_info.RootDirectory = 0;
352 vars->rename_info.FileNameLength = cpu_to_le32(len);
354 size[0] = sizeof(struct smb2_file_rename_info);
355 data[0] = &vars->rename_info;
357 size[1] = len + 2 /* null */;
358 data[1] = in_iov[i].iov_base;
361 rc = SMB2_set_info_init(tcon, server,
363 cfile->fid.persistent_fid,
364 cfile->fid.volatile_fid,
365 current->tgid, FILE_RENAME_INFORMATION,
366 SMB2_O_INFO_FILE, 0, data, size);
368 rc = SMB2_set_info_init(tcon, server,
370 COMPOUND_FID, COMPOUND_FID,
371 current->tgid, FILE_RENAME_INFORMATION,
372 SMB2_O_INFO_FILE, 0, data, size);
374 smb2_set_next_command(tcon, &rqst[num_rqst]);
375 smb2_set_related(&rqst[num_rqst]);
381 trace_smb3_rename_enter(xid, ses->Suid, tcon->tid, full_path);
383 case SMB2_OP_HARDLINK:
384 rqst[num_rqst].rq_iov = &vars->si_iov[0];
385 rqst[num_rqst].rq_nvec = 2;
387 len = in_iov[i].iov_len;
389 vars->link_info.ReplaceIfExists = 0;
390 vars->link_info.RootDirectory = 0;
391 vars->link_info.FileNameLength = cpu_to_le32(len);
393 size[0] = sizeof(struct smb2_file_link_info);
394 data[0] = &vars->link_info;
396 size[1] = len + 2 /* null */;
397 data[1] = in_iov[i].iov_base;
399 rc = SMB2_set_info_init(tcon, server,
400 &rqst[num_rqst], COMPOUND_FID,
401 COMPOUND_FID, current->tgid,
402 FILE_LINK_INFORMATION,
403 SMB2_O_INFO_FILE, 0, data, size);
406 smb2_set_next_command(tcon, &rqst[num_rqst]);
407 smb2_set_related(&rqst[num_rqst++]);
408 trace_smb3_hardlink_enter(xid, ses->Suid, tcon->tid, full_path);
410 case SMB2_OP_SET_REPARSE:
411 rqst[num_rqst].rq_iov = vars->io_iov;
412 rqst[num_rqst].rq_nvec = ARRAY_SIZE(vars->io_iov);
414 rc = SMB2_ioctl_init(tcon, server, &rqst[num_rqst],
415 COMPOUND_FID, COMPOUND_FID,
416 FSCTL_SET_REPARSE_POINT,
418 in_iov[i].iov_len, 0);
421 smb2_set_next_command(tcon, &rqst[num_rqst]);
422 smb2_set_related(&rqst[num_rqst++]);
423 trace_smb3_set_reparse_compound_enter(xid, ses->Suid,
424 tcon->tid, full_path);
426 case SMB2_OP_GET_REPARSE:
427 rqst[num_rqst].rq_iov = vars->io_iov;
428 rqst[num_rqst].rq_nvec = ARRAY_SIZE(vars->io_iov);
430 rc = SMB2_ioctl_init(tcon, server, &rqst[num_rqst],
431 COMPOUND_FID, COMPOUND_FID,
432 FSCTL_GET_REPARSE_POINT,
433 NULL, 0, CIFSMaxBufSize);
436 smb2_set_next_command(tcon, &rqst[num_rqst]);
437 smb2_set_related(&rqst[num_rqst++]);
438 trace_smb3_get_reparse_compound_enter(xid, ses->Suid,
439 tcon->tid, full_path);
442 cifs_dbg(VFS, "Invalid command\n");
449 /* We already have a handle so we can skip the close */
453 flags |= CIFS_CP_CREATE_CLOSE_OP;
454 rqst[num_rqst].rq_iov = &vars->close_iov;
455 rqst[num_rqst].rq_nvec = 1;
456 rc = SMB2_close_init(tcon, server,
457 &rqst[num_rqst], COMPOUND_FID,
458 COMPOUND_FID, false);
459 smb2_set_related(&rqst[num_rqst]);
466 rc = compound_send_recv(xid, ses, server,
468 &rqst[1], &resp_buftype[1],
471 rc = compound_send_recv(xid, ses, server,
478 SMB2_open_free(&rqst[num_rqst++]);
479 if (rc == -EREMCHG) {
480 pr_warn_once("server share %s deleted\n", tcon->tree_name);
481 tcon->need_reconnect = true;
484 for (i = 0; i < num_cmds; i++) {
486 case SMB2_OP_QUERY_INFO:
487 idata = in_iov[i].iov_base;
488 if (rc == 0 && cfile && cfile->symlink_target) {
489 idata->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
490 if (!idata->symlink_target)
494 qi_rsp = (struct smb2_query_info_rsp *)
495 rsp_iov[i + 1].iov_base;
496 rc = smb2_validate_and_copy_iov(
497 le16_to_cpu(qi_rsp->OutputBufferOffset),
498 le32_to_cpu(qi_rsp->OutputBufferLength),
499 &rsp_iov[i + 1], sizeof(idata->fi), (char *)&idata->fi);
501 SMB2_query_info_free(&rqst[num_rqst++]);
503 trace_smb3_query_info_compound_err(xid, ses->Suid,
506 trace_smb3_query_info_compound_done(xid, ses->Suid,
509 case SMB2_OP_POSIX_QUERY_INFO:
510 idata = in_iov[i].iov_base;
511 if (rc == 0 && cfile && cfile->symlink_target) {
512 idata->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
513 if (!idata->symlink_target)
517 qi_rsp = (struct smb2_query_info_rsp *)
518 rsp_iov[i + 1].iov_base;
519 rc = smb2_validate_and_copy_iov(
520 le16_to_cpu(qi_rsp->OutputBufferOffset),
521 le32_to_cpu(qi_rsp->OutputBufferLength),
522 &rsp_iov[i + 1], sizeof(idata->posix_fi) /* add SIDs */,
523 (char *)&idata->posix_fi);
526 rc = parse_posix_sids(idata, &rsp_iov[i + 1]);
528 SMB2_query_info_free(&rqst[num_rqst++]);
530 trace_smb3_posix_query_info_compound_err(xid, ses->Suid,
533 trace_smb3_posix_query_info_compound_done(xid, ses->Suid,
538 trace_smb3_delete_err(xid, ses->Suid, tcon->tid, rc);
540 trace_smb3_delete_done(xid, ses->Suid, tcon->tid);
544 trace_smb3_mkdir_err(xid, ses->Suid, tcon->tid, rc);
546 trace_smb3_mkdir_done(xid, ses->Suid, tcon->tid);
548 case SMB2_OP_HARDLINK:
550 trace_smb3_hardlink_err(xid, ses->Suid, tcon->tid, rc);
552 trace_smb3_hardlink_done(xid, ses->Suid, tcon->tid);
553 SMB2_set_info_free(&rqst[num_rqst++]);
557 trace_smb3_rename_err(xid, ses->Suid, tcon->tid, rc);
559 trace_smb3_rename_done(xid, ses->Suid, tcon->tid);
560 SMB2_set_info_free(&rqst[num_rqst++]);
564 trace_smb3_rmdir_err(xid, ses->Suid, tcon->tid, rc);
566 trace_smb3_rmdir_done(xid, ses->Suid, tcon->tid);
567 SMB2_set_info_free(&rqst[num_rqst++]);
569 case SMB2_OP_SET_EOF:
571 trace_smb3_set_eof_err(xid, ses->Suid, tcon->tid, rc);
573 trace_smb3_set_eof_done(xid, ses->Suid, tcon->tid);
574 SMB2_set_info_free(&rqst[num_rqst++]);
576 case SMB2_OP_SET_INFO:
578 trace_smb3_set_info_compound_err(xid, ses->Suid,
581 trace_smb3_set_info_compound_done(xid, ses->Suid,
583 SMB2_set_info_free(&rqst[num_rqst++]);
585 case SMB2_OP_SET_REPARSE:
587 trace_smb3_set_reparse_compound_err(xid, ses->Suid,
590 trace_smb3_set_reparse_compound_done(xid, ses->Suid,
593 SMB2_ioctl_free(&rqst[num_rqst++]);
595 case SMB2_OP_GET_REPARSE:
597 iov = &rsp_iov[i + 1];
598 idata = in_iov[i].iov_base;
599 idata->reparse.io.iov = *iov;
600 idata->reparse.io.buftype = resp_buftype[i + 1];
601 rbuf = reparse_buf_ptr(iov);
604 trace_smb3_set_reparse_compound_err(xid, ses->Suid,
607 idata->reparse.tag = le32_to_cpu(rbuf->ReparseTag);
608 trace_smb3_set_reparse_compound_done(xid, ses->Suid,
611 memset(iov, 0, sizeof(*iov));
612 resp_buftype[i + 1] = CIFS_NO_BUFFER;
614 trace_smb3_set_reparse_compound_err(xid, ses->Suid,
617 SMB2_ioctl_free(&rqst[num_rqst++]);
621 SMB2_close_free(&rqst[num_rqst]);
624 cifsFileInfo_put(cfile);
627 if (out_iov && out_buftype) {
628 memcpy(out_iov, rsp_iov, num_cmds * sizeof(*out_iov));
629 memcpy(out_buftype, resp_buftype,
630 num_cmds * sizeof(*out_buftype));
632 for (i = 0; i < num_cmds; i++)
633 free_rsp_buf(resp_buftype[i], rsp_iov[i].iov_base);
639 static int parse_create_response(struct cifs_open_info_data *data,
640 struct cifs_sb_info *cifs_sb,
641 const struct kvec *iov)
643 struct smb2_create_rsp *rsp = iov->iov_base;
644 bool reparse_point = false;
648 switch (rsp->hdr.Status) {
649 case STATUS_IO_REPARSE_TAG_NOT_HANDLED:
650 reparse_point = true;
652 case STATUS_STOPPED_ON_SYMLINK:
653 rc = smb2_parse_symlink_response(cifs_sb, iov,
654 &data->symlink_target);
657 tag = IO_REPARSE_TAG_SYMLINK;
658 reparse_point = true;
661 reparse_point = !!(rsp->Flags & SMB2_CREATE_FLAG_REPARSEPOINT);
664 data->reparse_point = reparse_point;
665 data->reparse.tag = tag;
669 int smb2_query_path_info(const unsigned int xid,
670 struct cifs_tcon *tcon,
671 struct cifs_sb_info *cifs_sb,
672 const char *full_path,
673 struct cifs_open_info_data *data)
675 __u32 create_options = 0;
676 struct cifsFileInfo *cfile;
677 struct cached_fid *cfid = NULL;
678 struct smb2_hdr *hdr;
679 struct kvec in_iov[2], out_iov[3] = {};
680 int out_buftype[3] = {};
686 data->adjust_tz = false;
687 data->reparse_point = false;
690 * BB TODO: Add support for using cached root handle in SMB3.1.1 POSIX.
691 * Create SMB2_query_posix_info worker function to do non-compounded
692 * query when we already have an open file handle for this. For now this
693 * is fast enough (always using the compounded version).
695 if (!tcon->posix_extensions) {
699 rc = open_cached_dir(xid, tcon, full_path,
700 cifs_sb, false, &cfid);
702 /* If it is a root and its handle is cached then use it */
704 if (cfid->file_all_info_is_valid) {
705 memcpy(&data->fi, &cfid->file_all_info,
708 rc = SMB2_query_info(xid, tcon,
709 cfid->fid.persistent_fid,
710 cfid->fid.volatile_fid,
713 close_cached_dir(cfid);
716 cmds[0] = SMB2_OP_QUERY_INFO;
718 cmds[0] = SMB2_OP_POSIX_QUERY_INFO;
721 in_iov[0].iov_base = data;
722 in_iov[0].iov_len = sizeof(*data);
723 in_iov[1] = in_iov[0];
725 cifs_get_readable_path(tcon, full_path, &cfile);
726 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
727 FILE_READ_ATTRIBUTES, FILE_OPEN,
728 create_options, ACL_NO_MODE, in_iov,
729 cmds, 1, cfile, out_iov, out_buftype);
730 hdr = out_iov[0].iov_base;
732 * If first iov is unset, then SMB session was dropped or we've got a
733 * cached open file (@cfile).
735 if (!hdr || out_buftype[0] == CIFS_NO_BUFFER)
742 * BB TODO: When support for special files added to Samba
743 * re-verify this path.
745 rc = parse_create_response(data, cifs_sb, &out_iov[0]);
746 if (rc || !data->reparse_point)
749 if (data->reparse.tag == IO_REPARSE_TAG_SYMLINK) {
750 /* symlink already parsed in create response */
753 cmds[1] = SMB2_OP_GET_REPARSE;
756 create_options |= OPEN_REPARSE_POINT;
757 cifs_get_readable_path(tcon, full_path, &cfile);
758 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
759 FILE_READ_ATTRIBUTES, FILE_OPEN,
760 create_options, ACL_NO_MODE, in_iov,
761 cmds, num_cmds, cfile, NULL, NULL);
766 if (hdr->Status != STATUS_OBJECT_NAME_INVALID)
768 rc2 = cifs_inval_name_dfs_link_error(xid, tcon, cifs_sb,
779 for (i = 0; i < ARRAY_SIZE(out_buftype); i++)
780 free_rsp_buf(out_buftype[i], out_iov[i].iov_base);
785 smb2_mkdir(const unsigned int xid, struct inode *parent_inode, umode_t mode,
786 struct cifs_tcon *tcon, const char *name,
787 struct cifs_sb_info *cifs_sb)
789 return smb2_compound_op(xid, tcon, cifs_sb, name,
790 FILE_WRITE_ATTRIBUTES, FILE_CREATE,
791 CREATE_NOT_FILE, mode,
792 NULL, &(int){SMB2_OP_MKDIR}, 1,
797 smb2_mkdir_setinfo(struct inode *inode, const char *name,
798 struct cifs_sb_info *cifs_sb, struct cifs_tcon *tcon,
799 const unsigned int xid)
801 FILE_BASIC_INFO data = {};
802 struct cifsInodeInfo *cifs_i;
803 struct cifsFileInfo *cfile;
808 in_iov.iov_base = &data;
809 in_iov.iov_len = sizeof(data);
810 cifs_i = CIFS_I(inode);
811 dosattrs = cifs_i->cifsAttrs | ATTR_READONLY;
812 data.Attributes = cpu_to_le32(dosattrs);
813 cifs_get_writable_path(tcon, name, FIND_WR_ANY, &cfile);
814 tmprc = smb2_compound_op(xid, tcon, cifs_sb, name,
815 FILE_WRITE_ATTRIBUTES, FILE_CREATE,
816 CREATE_NOT_FILE, ACL_NO_MODE, &in_iov,
817 &(int){SMB2_OP_SET_INFO}, 1,
820 cifs_i->cifsAttrs = dosattrs;
824 smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
825 struct cifs_sb_info *cifs_sb)
827 drop_cached_dir_by_name(xid, tcon, name, cifs_sb);
828 return smb2_compound_op(xid, tcon, cifs_sb, name,
829 DELETE, FILE_OPEN, CREATE_NOT_FILE,
831 &(int){SMB2_OP_RMDIR}, 1,
836 smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
837 struct cifs_sb_info *cifs_sb)
839 return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
840 CREATE_DELETE_ON_CLOSE | OPEN_REPARSE_POINT,
842 &(int){SMB2_OP_DELETE}, 1,
846 static int smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon,
847 const char *from_name, const char *to_name,
848 struct cifs_sb_info *cifs_sb,
849 __u32 create_options, __u32 access,
850 int command, struct cifsFileInfo *cfile)
853 __le16 *smb2_to_name = NULL;
856 smb2_to_name = cifs_convert_path_to_utf16(to_name, cifs_sb);
857 if (smb2_to_name == NULL) {
859 goto smb2_rename_path;
861 in_iov.iov_base = smb2_to_name;
862 in_iov.iov_len = 2 * UniStrnlen((wchar_t *)smb2_to_name, PATH_MAX);
863 rc = smb2_compound_op(xid, tcon, cifs_sb, from_name, access,
864 FILE_OPEN, create_options, ACL_NO_MODE,
865 &in_iov, &command, 1, cfile, NULL, NULL);
871 int smb2_rename_path(const unsigned int xid,
872 struct cifs_tcon *tcon,
873 struct dentry *source_dentry,
874 const char *from_name, const char *to_name,
875 struct cifs_sb_info *cifs_sb)
877 struct cifsFileInfo *cfile;
878 __u32 co = file_create_options(source_dentry);
880 drop_cached_dir_by_name(xid, tcon, from_name, cifs_sb);
881 cifs_get_writable_path(tcon, from_name, FIND_WR_WITH_DELETE, &cfile);
883 return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb,
884 co, DELETE, SMB2_OP_RENAME, cfile);
887 int smb2_create_hardlink(const unsigned int xid,
888 struct cifs_tcon *tcon,
889 struct dentry *source_dentry,
890 const char *from_name, const char *to_name,
891 struct cifs_sb_info *cifs_sb)
893 __u32 co = file_create_options(source_dentry);
895 return smb2_set_path_attr(xid, tcon, from_name, to_name,
896 cifs_sb, co, FILE_READ_ATTRIBUTES,
897 SMB2_OP_HARDLINK, NULL);
901 smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon,
902 const char *full_path, __u64 size,
903 struct cifs_sb_info *cifs_sb, bool set_alloc)
905 struct cifsFileInfo *cfile;
907 __le64 eof = cpu_to_le64(size);
909 in_iov.iov_base = &eof;
910 in_iov.iov_len = sizeof(eof);
911 cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);
912 return smb2_compound_op(xid, tcon, cifs_sb, full_path,
913 FILE_WRITE_DATA, FILE_OPEN,
914 0, ACL_NO_MODE, &in_iov,
915 &(int){SMB2_OP_SET_EOF}, 1,
920 smb2_set_file_info(struct inode *inode, const char *full_path,
921 FILE_BASIC_INFO *buf, const unsigned int xid)
923 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
924 struct tcon_link *tlink;
925 struct cifs_tcon *tcon;
926 struct cifsFileInfo *cfile;
927 struct kvec in_iov = { .iov_base = buf, .iov_len = sizeof(*buf), };
930 if ((buf->CreationTime == 0) && (buf->LastAccessTime == 0) &&
931 (buf->LastWriteTime == 0) && (buf->ChangeTime == 0) &&
932 (buf->Attributes == 0))
933 return 0; /* would be a no op, no sense sending this */
935 tlink = cifs_sb_tlink(cifs_sb);
937 return PTR_ERR(tlink);
938 tcon = tlink_tcon(tlink);
940 cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);
941 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
942 FILE_WRITE_ATTRIBUTES, FILE_OPEN,
943 0, ACL_NO_MODE, &in_iov,
944 &(int){SMB2_OP_SET_INFO}, 1,
946 cifs_put_tlink(tlink);
950 struct inode *smb2_get_reparse_inode(struct cifs_open_info_data *data,
951 struct super_block *sb,
952 const unsigned int xid,
953 struct cifs_tcon *tcon,
954 const char *full_path,
957 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
958 struct cifsFileInfo *cfile;
959 struct inode *new = NULL;
960 struct kvec in_iov[2];
965 da = SYNCHRONIZE | DELETE |
966 FILE_READ_ATTRIBUTES |
967 FILE_WRITE_ATTRIBUTES;
968 co = CREATE_NOT_DIR | OPEN_REPARSE_POINT;
970 cmds[0] = SMB2_OP_SET_REPARSE;
972 in_iov[1].iov_base = data;
973 in_iov[1].iov_len = sizeof(*data);
975 if (tcon->posix_extensions) {
976 cmds[1] = SMB2_OP_POSIX_QUERY_INFO;
977 cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);
978 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
979 da, cd, co, ACL_NO_MODE, in_iov,
980 cmds, 2, cfile, NULL, NULL);
982 rc = smb311_posix_get_inode_info(&new, full_path,
986 cmds[1] = SMB2_OP_QUERY_INFO;
987 cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);
988 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
989 da, cd, co, ACL_NO_MODE, in_iov,
990 cmds, 2, cfile, NULL, NULL);
992 rc = cifs_get_inode_info(&new, full_path,
993 data, sb, xid, NULL);
996 return rc ? ERR_PTR(rc) : new;
999 int smb2_query_reparse_point(const unsigned int xid,
1000 struct cifs_tcon *tcon,
1001 struct cifs_sb_info *cifs_sb,
1002 const char *full_path,
1003 u32 *tag, struct kvec *rsp,
1006 struct cifs_open_info_data data = {};
1007 struct cifsFileInfo *cfile;
1008 struct kvec in_iov = { .iov_base = &data, .iov_len = sizeof(data), };
1011 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
1013 cifs_get_readable_path(tcon, full_path, &cfile);
1014 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
1015 FILE_READ_ATTRIBUTES, FILE_OPEN,
1016 OPEN_REPARSE_POINT, ACL_NO_MODE, &in_iov,
1017 &(int){SMB2_OP_GET_REPARSE}, 1,
1022 *tag = data.reparse.tag;
1023 *rsp = data.reparse.io.iov;
1024 *rsp_buftype = data.reparse.io.buftype;
1025 memset(&data.reparse.io.iov, 0, sizeof(data.reparse.io.iov));
1026 data.reparse.io.buftype = CIFS_NO_BUFFER;
1028 cifs_free_open_info(&data);