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"
30 free_set_inf_compound(struct smb_rqst *rqst)
33 SMB2_set_info_free(&rqst[1]);
35 SMB2_close_free(&rqst[2]);
38 static inline __u32 file_create_options(struct dentry *dentry)
40 struct cifsInodeInfo *ci;
43 ci = CIFS_I(d_inode(dentry));
44 if (ci->cifsAttrs & ATTR_REPARSE)
45 return OPEN_REPARSE_POINT;
51 * note: If cfile is passed, the reference to it is dropped here.
52 * So make sure that you do not reuse cfile after return from this func.
54 * If passing @out_iov and @out_buftype, ensure to make them both large enough
55 * (>= 3) to hold all compounded responses. Caller is also responsible for
56 * freeing them up with free_rsp_buf().
58 static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
59 struct cifs_sb_info *cifs_sb, const char *full_path,
60 __u32 desired_access, __u32 create_disposition, __u32 create_options,
61 umode_t mode, void *ptr, int command, struct cifsFileInfo *cfile,
62 __u8 **extbuf, size_t *extbuflen,
63 struct kvec *out_iov, int *out_buftype)
65 struct smb2_compound_vars *vars = NULL;
67 struct smb_rqst *rqst;
69 __le16 *utf16_path = NULL;
70 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
72 struct cifs_ses *ses = tcon->ses;
73 struct TCP_Server_Info *server;
76 struct smb2_query_info_rsp *qi_rsp = NULL;
77 struct cifs_open_info_data *idata;
79 __u8 delete_pending[8] = {1, 0, 0, 0, 0, 0, 0, 0};
84 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
87 rqst = &vars->rqst[0];
88 rsp_iov = &vars->rsp_iov[0];
90 server = cifs_pick_channel(ses);
92 if (smb3_encryption_required(tcon))
93 flags |= CIFS_TRANSFORM_REQ;
95 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
97 /* We already have a handle so we can skip the open */
102 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
108 vars->oparms = (struct cifs_open_parms) {
111 .desired_access = desired_access,
112 .disposition = create_disposition,
113 .create_options = cifs_create_options(cifs_sb, create_options),
119 rqst[num_rqst].rq_iov = &vars->open_iov[0];
120 rqst[num_rqst].rq_nvec = SMB2_CREATE_IOV_SIZE;
121 rc = SMB2_open_init(tcon, server,
122 &rqst[num_rqst], &oplock, &vars->oparms,
128 smb2_set_next_command(tcon, &rqst[num_rqst]);
135 case SMB2_OP_QUERY_INFO:
136 rqst[num_rqst].rq_iov = &vars->qi_iov;
137 rqst[num_rqst].rq_nvec = 1;
140 rc = SMB2_query_info_init(tcon, server,
142 cfile->fid.persistent_fid,
143 cfile->fid.volatile_fid,
144 FILE_ALL_INFORMATION,
146 sizeof(struct smb2_file_all_info) +
147 PATH_MAX * 2, 0, NULL);
149 rc = SMB2_query_info_init(tcon, server,
153 FILE_ALL_INFORMATION,
155 sizeof(struct smb2_file_all_info) +
156 PATH_MAX * 2, 0, NULL);
158 smb2_set_next_command(tcon, &rqst[num_rqst]);
159 smb2_set_related(&rqst[num_rqst]);
166 trace_smb3_query_info_compound_enter(xid, ses->Suid, tcon->tid,
169 case SMB2_OP_POSIX_QUERY_INFO:
170 rqst[num_rqst].rq_iov = &vars->qi_iov;
171 rqst[num_rqst].rq_nvec = 1;
174 rc = SMB2_query_info_init(tcon, server,
176 cfile->fid.persistent_fid,
177 cfile->fid.volatile_fid,
178 SMB_FIND_FILE_POSIX_INFO,
180 /* TBD: fix following to allow for longer SIDs */
181 sizeof(struct smb311_posix_qinfo *) + (PATH_MAX * 2) +
182 (sizeof(struct cifs_sid) * 2), 0, NULL);
184 rc = SMB2_query_info_init(tcon, server,
188 SMB_FIND_FILE_POSIX_INFO,
190 sizeof(struct smb311_posix_qinfo *) + (PATH_MAX * 2) +
191 (sizeof(struct cifs_sid) * 2), 0, NULL);
193 smb2_set_next_command(tcon, &rqst[num_rqst]);
194 smb2_set_related(&rqst[num_rqst]);
201 trace_smb3_posix_query_info_compound_enter(xid, ses->Suid, tcon->tid, full_path);
204 trace_smb3_delete_enter(xid, ses->Suid, tcon->tid, full_path);
208 * Directories are created through parameters in the
211 trace_smb3_mkdir_enter(xid, ses->Suid, tcon->tid, full_path);
214 rqst[num_rqst].rq_iov = &vars->si_iov[0];
215 rqst[num_rqst].rq_nvec = 1;
217 size[0] = 1; /* sizeof __u8 See MS-FSCC section 2.4.11 */
218 data[0] = &delete_pending[0];
220 rc = SMB2_set_info_init(tcon, server,
221 &rqst[num_rqst], COMPOUND_FID,
222 COMPOUND_FID, current->tgid,
223 FILE_DISPOSITION_INFORMATION,
224 SMB2_O_INFO_FILE, 0, data, size);
227 smb2_set_next_command(tcon, &rqst[num_rqst]);
228 smb2_set_related(&rqst[num_rqst++]);
229 trace_smb3_rmdir_enter(xid, ses->Suid, tcon->tid, full_path);
231 case SMB2_OP_SET_EOF:
232 rqst[num_rqst].rq_iov = &vars->si_iov[0];
233 rqst[num_rqst].rq_nvec = 1;
235 size[0] = 8; /* sizeof __le64 */
239 rc = SMB2_set_info_init(tcon, server,
241 cfile->fid.persistent_fid,
242 cfile->fid.volatile_fid,
244 FILE_END_OF_FILE_INFORMATION,
248 rc = SMB2_set_info_init(tcon, server,
253 FILE_END_OF_FILE_INFORMATION,
257 smb2_set_next_command(tcon, &rqst[num_rqst]);
258 smb2_set_related(&rqst[num_rqst]);
264 trace_smb3_set_eof_enter(xid, ses->Suid, tcon->tid, full_path);
266 case SMB2_OP_SET_INFO:
267 rqst[num_rqst].rq_iov = &vars->si_iov[0];
268 rqst[num_rqst].rq_nvec = 1;
271 size[0] = sizeof(FILE_BASIC_INFO);
275 rc = SMB2_set_info_init(tcon, server,
277 cfile->fid.persistent_fid,
278 cfile->fid.volatile_fid, current->tgid,
279 FILE_BASIC_INFORMATION,
280 SMB2_O_INFO_FILE, 0, data, size);
282 rc = SMB2_set_info_init(tcon, server,
285 COMPOUND_FID, current->tgid,
286 FILE_BASIC_INFORMATION,
287 SMB2_O_INFO_FILE, 0, data, size);
289 smb2_set_next_command(tcon, &rqst[num_rqst]);
290 smb2_set_related(&rqst[num_rqst]);
297 trace_smb3_set_info_compound_enter(xid, ses->Suid, tcon->tid,
301 rqst[num_rqst].rq_iov = &vars->si_iov[0];
302 rqst[num_rqst].rq_nvec = 2;
304 len = (2 * UniStrnlen((wchar_t *)ptr, PATH_MAX));
306 vars->rename_info.ReplaceIfExists = 1;
307 vars->rename_info.RootDirectory = 0;
308 vars->rename_info.FileNameLength = cpu_to_le32(len);
310 size[0] = sizeof(struct smb2_file_rename_info);
311 data[0] = &vars->rename_info;
313 size[1] = len + 2 /* null */;
314 data[1] = (__le16 *)ptr;
317 rc = SMB2_set_info_init(tcon, server,
319 cfile->fid.persistent_fid,
320 cfile->fid.volatile_fid,
321 current->tgid, FILE_RENAME_INFORMATION,
322 SMB2_O_INFO_FILE, 0, data, size);
324 rc = SMB2_set_info_init(tcon, server,
326 COMPOUND_FID, COMPOUND_FID,
327 current->tgid, FILE_RENAME_INFORMATION,
328 SMB2_O_INFO_FILE, 0, data, size);
330 smb2_set_next_command(tcon, &rqst[num_rqst]);
331 smb2_set_related(&rqst[num_rqst]);
337 trace_smb3_rename_enter(xid, ses->Suid, tcon->tid, full_path);
339 case SMB2_OP_HARDLINK:
340 rqst[num_rqst].rq_iov = &vars->si_iov[0];
341 rqst[num_rqst].rq_nvec = 2;
343 len = (2 * UniStrnlen((wchar_t *)ptr, PATH_MAX));
345 vars->link_info.ReplaceIfExists = 0;
346 vars->link_info.RootDirectory = 0;
347 vars->link_info.FileNameLength = cpu_to_le32(len);
349 size[0] = sizeof(struct smb2_file_link_info);
350 data[0] = &vars->link_info;
352 size[1] = len + 2 /* null */;
353 data[1] = (__le16 *)ptr;
355 rc = SMB2_set_info_init(tcon, server,
356 &rqst[num_rqst], COMPOUND_FID,
357 COMPOUND_FID, current->tgid,
358 FILE_LINK_INFORMATION,
359 SMB2_O_INFO_FILE, 0, data, size);
362 smb2_set_next_command(tcon, &rqst[num_rqst]);
363 smb2_set_related(&rqst[num_rqst++]);
364 trace_smb3_hardlink_enter(xid, ses->Suid, tcon->tid, full_path);
367 cifs_dbg(VFS, "Invalid command\n");
373 /* We already have a handle so we can skip the close */
377 flags |= CIFS_CP_CREATE_CLOSE_OP;
378 rqst[num_rqst].rq_iov = &vars->close_iov;
379 rqst[num_rqst].rq_nvec = 1;
380 rc = SMB2_close_init(tcon, server,
381 &rqst[num_rqst], COMPOUND_FID,
382 COMPOUND_FID, false);
383 smb2_set_related(&rqst[num_rqst]);
390 rc = compound_send_recv(xid, ses, server,
392 &rqst[1], &resp_buftype[1],
395 rc = compound_send_recv(xid, ses, server,
401 SMB2_open_free(&rqst[0]);
402 if (rc == -EREMCHG) {
403 pr_warn_once("server share %s deleted\n", tcon->tree_name);
404 tcon->need_reconnect = true;
408 case SMB2_OP_QUERY_INFO:
410 if (rc == 0 && cfile && cfile->symlink_target) {
411 idata->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
412 if (!idata->symlink_target)
416 qi_rsp = (struct smb2_query_info_rsp *)
418 rc = smb2_validate_and_copy_iov(
419 le16_to_cpu(qi_rsp->OutputBufferOffset),
420 le32_to_cpu(qi_rsp->OutputBufferLength),
421 &rsp_iov[1], sizeof(idata->fi), (char *)&idata->fi);
424 SMB2_query_info_free(&rqst[1]);
426 SMB2_close_free(&rqst[2]);
428 trace_smb3_query_info_compound_err(xid, ses->Suid,
431 trace_smb3_query_info_compound_done(xid, ses->Suid,
434 case SMB2_OP_POSIX_QUERY_INFO:
436 if (rc == 0 && cfile && cfile->symlink_target) {
437 idata->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
438 if (!idata->symlink_target)
442 qi_rsp = (struct smb2_query_info_rsp *)
444 rc = smb2_validate_and_copy_iov(
445 le16_to_cpu(qi_rsp->OutputBufferOffset),
446 le32_to_cpu(qi_rsp->OutputBufferLength),
447 &rsp_iov[1], sizeof(idata->posix_fi) /* add SIDs */,
448 (char *)&idata->posix_fi);
451 unsigned int length = le32_to_cpu(qi_rsp->OutputBufferLength);
453 if (length > sizeof(idata->posix_fi)) {
454 char *base = (char *)rsp_iov[1].iov_base +
455 le16_to_cpu(qi_rsp->OutputBufferOffset) +
456 sizeof(idata->posix_fi);
457 *extbuflen = length - sizeof(idata->posix_fi);
458 *extbuf = kmemdup(base, *extbuflen, GFP_KERNEL);
466 SMB2_query_info_free(&rqst[1]);
468 SMB2_close_free(&rqst[2]);
470 trace_smb3_posix_query_info_compound_err(xid, ses->Suid, tcon->tid, rc);
472 trace_smb3_posix_query_info_compound_done(xid, ses->Suid, tcon->tid);
476 trace_smb3_delete_err(xid, ses->Suid, tcon->tid, rc);
478 trace_smb3_delete_done(xid, ses->Suid, tcon->tid);
480 SMB2_close_free(&rqst[1]);
484 trace_smb3_mkdir_err(xid, ses->Suid, tcon->tid, rc);
486 trace_smb3_mkdir_done(xid, ses->Suid, tcon->tid);
488 SMB2_close_free(&rqst[1]);
490 case SMB2_OP_HARDLINK:
492 trace_smb3_hardlink_err(xid, ses->Suid, tcon->tid, rc);
494 trace_smb3_hardlink_done(xid, ses->Suid, tcon->tid);
495 free_set_inf_compound(rqst);
499 trace_smb3_rename_err(xid, ses->Suid, tcon->tid, rc);
501 trace_smb3_rename_done(xid, ses->Suid, tcon->tid);
502 free_set_inf_compound(rqst);
506 trace_smb3_rmdir_err(xid, ses->Suid, tcon->tid, rc);
508 trace_smb3_rmdir_done(xid, ses->Suid, tcon->tid);
509 free_set_inf_compound(rqst);
511 case SMB2_OP_SET_EOF:
513 trace_smb3_set_eof_err(xid, ses->Suid, tcon->tid, rc);
515 trace_smb3_set_eof_done(xid, ses->Suid, tcon->tid);
516 free_set_inf_compound(rqst);
518 case SMB2_OP_SET_INFO:
520 trace_smb3_set_info_compound_err(xid, ses->Suid,
523 trace_smb3_set_info_compound_done(xid, ses->Suid,
525 free_set_inf_compound(rqst);
530 cifsFileInfo_put(cfile);
532 if (out_iov && out_buftype) {
533 memcpy(out_iov, rsp_iov, 3 * sizeof(*out_iov));
534 memcpy(out_buftype, resp_buftype, 3 * sizeof(*out_buftype));
536 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
537 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
538 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
544 static int parse_create_response(struct cifs_open_info_data *data,
545 struct cifs_sb_info *cifs_sb,
546 const struct kvec *iov)
548 struct smb2_create_rsp *rsp = iov->iov_base;
549 bool reparse_point = false;
553 switch (rsp->hdr.Status) {
554 case STATUS_IO_REPARSE_TAG_NOT_HANDLED:
555 reparse_point = true;
557 case STATUS_STOPPED_ON_SYMLINK:
558 rc = smb2_parse_symlink_response(cifs_sb, iov,
559 &data->symlink_target);
562 tag = IO_REPARSE_TAG_SYMLINK;
563 reparse_point = true;
566 reparse_point = !!(rsp->Flags & SMB2_CREATE_FLAG_REPARSEPOINT);
569 data->reparse_point = reparse_point;
570 data->reparse.tag = tag;
574 int smb2_query_path_info(const unsigned int xid,
575 struct cifs_tcon *tcon,
576 struct cifs_sb_info *cifs_sb,
577 const char *full_path,
578 struct cifs_open_info_data *data)
580 __u32 create_options = 0;
581 struct cifsFileInfo *cfile;
582 struct cached_fid *cfid = NULL;
583 struct smb2_hdr *hdr;
584 struct kvec out_iov[3] = {};
585 int out_buftype[3] = {};
589 data->adjust_tz = false;
590 data->reparse_point = false;
592 if (strcmp(full_path, ""))
595 rc = open_cached_dir(xid, tcon, full_path, cifs_sb, false, &cfid);
596 /* If it is a root and its handle is cached then use it */
598 if (cfid->file_all_info_is_valid) {
599 memcpy(&data->fi, &cfid->file_all_info, sizeof(data->fi));
601 rc = SMB2_query_info(xid, tcon, cfid->fid.persistent_fid,
602 cfid->fid.volatile_fid, &data->fi);
604 close_cached_dir(cfid);
608 cifs_get_readable_path(tcon, full_path, &cfile);
609 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES, FILE_OPEN,
610 create_options, ACL_NO_MODE, data, SMB2_OP_QUERY_INFO, cfile,
611 NULL, NULL, out_iov, out_buftype);
612 hdr = out_iov[0].iov_base;
614 * If first iov is unset, then SMB session was dropped or we've got a
615 * cached open file (@cfile).
617 if (!hdr || out_buftype[0] == CIFS_NO_BUFFER)
623 rc = parse_create_response(data, cifs_sb, &out_iov[0]);
624 if (rc || !data->reparse_point)
627 create_options |= OPEN_REPARSE_POINT;
628 /* Failed on a symbolic link - query a reparse point info */
629 cifs_get_readable_path(tcon, full_path, &cfile);
630 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
631 FILE_READ_ATTRIBUTES, FILE_OPEN,
632 create_options, ACL_NO_MODE, data,
633 SMB2_OP_QUERY_INFO, cfile, NULL, NULL,
639 if (hdr->Status != STATUS_OBJECT_NAME_INVALID)
641 rc2 = cifs_inval_name_dfs_link_error(xid, tcon, cifs_sb,
652 free_rsp_buf(out_buftype[0], out_iov[0].iov_base);
653 free_rsp_buf(out_buftype[1], out_iov[1].iov_base);
654 free_rsp_buf(out_buftype[2], out_iov[2].iov_base);
658 int smb311_posix_query_path_info(const unsigned int xid,
659 struct cifs_tcon *tcon,
660 struct cifs_sb_info *cifs_sb,
661 const char *full_path,
662 struct cifs_open_info_data *data,
663 struct cifs_sid *owner,
664 struct cifs_sid *group)
667 __u32 create_options = 0;
668 struct cifsFileInfo *cfile;
669 struct kvec out_iov[3] = {};
670 int out_buftype[3] = {};
671 __u8 *sidsbuf = NULL;
672 __u8 *sidsbuf_end = NULL;
673 size_t sidsbuflen = 0;
674 size_t owner_len, group_len;
676 data->adjust_tz = false;
677 data->reparse_point = false;
680 * BB TODO: Add support for using the cached root handle.
681 * Create SMB2_query_posix_info worker function to do non-compounded query
682 * when we already have an open file handle for this. For now this is fast enough
683 * (always using the compounded version).
686 cifs_get_readable_path(tcon, full_path, &cfile);
687 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES, FILE_OPEN,
688 create_options, ACL_NO_MODE, data, SMB2_OP_POSIX_QUERY_INFO, cfile,
689 &sidsbuf, &sidsbuflen, out_iov, out_buftype);
691 * If first iov is unset, then SMB session was dropped or we've got a
692 * cached open file (@cfile).
694 if (!out_iov[0].iov_base || out_buftype[0] == CIFS_NO_BUFFER)
700 /* BB TODO: When support for special files added to Samba re-verify this path */
701 rc = parse_create_response(data, cifs_sb, &out_iov[0]);
702 if (rc || !data->reparse_point)
705 create_options |= OPEN_REPARSE_POINT;
706 /* Failed on a symbolic link - query a reparse point info */
707 cifs_get_readable_path(tcon, full_path, &cfile);
708 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES,
709 FILE_OPEN, create_options, ACL_NO_MODE, data,
710 SMB2_OP_POSIX_QUERY_INFO, cfile,
711 &sidsbuf, &sidsbuflen, NULL, NULL);
717 sidsbuf_end = sidsbuf + sidsbuflen;
719 owner_len = posix_info_sid_size(sidsbuf, sidsbuf_end);
720 if (owner_len == -1) {
724 memcpy(owner, sidsbuf, owner_len);
726 group_len = posix_info_sid_size(
727 sidsbuf + owner_len, sidsbuf_end);
728 if (group_len == -1) {
732 memcpy(group, sidsbuf + owner_len, group_len);
736 free_rsp_buf(out_buftype[0], out_iov[0].iov_base);
737 free_rsp_buf(out_buftype[1], out_iov[1].iov_base);
738 free_rsp_buf(out_buftype[2], out_iov[2].iov_base);
743 smb2_mkdir(const unsigned int xid, struct inode *parent_inode, umode_t mode,
744 struct cifs_tcon *tcon, const char *name,
745 struct cifs_sb_info *cifs_sb)
747 return smb2_compound_op(xid, tcon, cifs_sb, name,
748 FILE_WRITE_ATTRIBUTES, FILE_CREATE,
749 CREATE_NOT_FILE, mode, NULL, SMB2_OP_MKDIR,
750 NULL, NULL, NULL, NULL, NULL);
754 smb2_mkdir_setinfo(struct inode *inode, const char *name,
755 struct cifs_sb_info *cifs_sb, struct cifs_tcon *tcon,
756 const unsigned int xid)
758 FILE_BASIC_INFO data;
759 struct cifsInodeInfo *cifs_i;
760 struct cifsFileInfo *cfile;
764 memset(&data, 0, sizeof(data));
765 cifs_i = CIFS_I(inode);
766 dosattrs = cifs_i->cifsAttrs | ATTR_READONLY;
767 data.Attributes = cpu_to_le32(dosattrs);
768 cifs_get_writable_path(tcon, name, FIND_WR_ANY, &cfile);
769 tmprc = smb2_compound_op(xid, tcon, cifs_sb, name,
770 FILE_WRITE_ATTRIBUTES, FILE_CREATE,
771 CREATE_NOT_FILE, ACL_NO_MODE,
772 &data, SMB2_OP_SET_INFO, cfile, NULL, NULL, NULL, NULL);
774 cifs_i->cifsAttrs = dosattrs;
778 smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
779 struct cifs_sb_info *cifs_sb)
781 drop_cached_dir_by_name(xid, tcon, name, cifs_sb);
782 return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
783 CREATE_NOT_FILE, ACL_NO_MODE,
784 NULL, SMB2_OP_RMDIR, NULL, NULL, NULL, NULL, NULL);
788 smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
789 struct cifs_sb_info *cifs_sb)
791 return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
792 CREATE_DELETE_ON_CLOSE | OPEN_REPARSE_POINT,
793 ACL_NO_MODE, NULL, SMB2_OP_DELETE, NULL, NULL, NULL, NULL, NULL);
796 static int smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon,
797 const char *from_name, const char *to_name,
798 struct cifs_sb_info *cifs_sb,
799 __u32 create_options, __u32 access,
800 int command, struct cifsFileInfo *cfile)
802 __le16 *smb2_to_name = NULL;
805 smb2_to_name = cifs_convert_path_to_utf16(to_name, cifs_sb);
806 if (smb2_to_name == NULL) {
808 goto smb2_rename_path;
810 rc = smb2_compound_op(xid, tcon, cifs_sb, from_name, access,
811 FILE_OPEN, create_options, ACL_NO_MODE, smb2_to_name,
812 command, cfile, NULL, NULL, NULL, NULL);
818 int smb2_rename_path(const unsigned int xid,
819 struct cifs_tcon *tcon,
820 struct dentry *source_dentry,
821 const char *from_name, const char *to_name,
822 struct cifs_sb_info *cifs_sb)
824 struct cifsFileInfo *cfile;
825 __u32 co = file_create_options(source_dentry);
827 drop_cached_dir_by_name(xid, tcon, from_name, cifs_sb);
828 cifs_get_writable_path(tcon, from_name, FIND_WR_WITH_DELETE, &cfile);
830 return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb,
831 co, DELETE, SMB2_OP_RENAME, cfile);
834 int smb2_create_hardlink(const unsigned int xid,
835 struct cifs_tcon *tcon,
836 struct dentry *source_dentry,
837 const char *from_name, const char *to_name,
838 struct cifs_sb_info *cifs_sb)
840 __u32 co = file_create_options(source_dentry);
842 return smb2_set_path_attr(xid, tcon, from_name, to_name,
843 cifs_sb, co, FILE_READ_ATTRIBUTES,
844 SMB2_OP_HARDLINK, NULL);
848 smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon,
849 const char *full_path, __u64 size,
850 struct cifs_sb_info *cifs_sb, bool set_alloc)
852 __le64 eof = cpu_to_le64(size);
853 struct cifsFileInfo *cfile;
855 cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);
856 return smb2_compound_op(xid, tcon, cifs_sb, full_path,
857 FILE_WRITE_DATA, FILE_OPEN, 0, ACL_NO_MODE,
858 &eof, SMB2_OP_SET_EOF, cfile, NULL, NULL, NULL, NULL);
862 smb2_set_file_info(struct inode *inode, const char *full_path,
863 FILE_BASIC_INFO *buf, const unsigned int xid)
865 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
866 struct tcon_link *tlink;
867 struct cifs_tcon *tcon;
868 struct cifsFileInfo *cfile;
871 if ((buf->CreationTime == 0) && (buf->LastAccessTime == 0) &&
872 (buf->LastWriteTime == 0) && (buf->ChangeTime == 0) &&
873 (buf->Attributes == 0))
874 return 0; /* would be a no op, no sense sending this */
876 tlink = cifs_sb_tlink(cifs_sb);
878 return PTR_ERR(tlink);
879 tcon = tlink_tcon(tlink);
881 cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);
882 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
883 FILE_WRITE_ATTRIBUTES, FILE_OPEN,
884 0, ACL_NO_MODE, buf, SMB2_OP_SET_INFO, cfile,
885 NULL, NULL, NULL, NULL);
886 cifs_put_tlink(tlink);