1 // SPDX-License-Identifier: LGPL-2.1
4 * Copyright (C) International Business Machines Corp., 2002, 2011
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]);
39 * note: If cfile is passed, the reference to it is dropped here.
40 * So make sure that you do not reuse cfile after return from this func.
42 * If passing @out_iov and @out_buftype, ensure to make them both large enough
43 * (>= 3) to hold all compounded responses. Caller is also responsible for
44 * freeing them up with free_rsp_buf().
46 static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
47 struct cifs_sb_info *cifs_sb, const char *full_path,
48 __u32 desired_access, __u32 create_disposition, __u32 create_options,
49 umode_t mode, void *ptr, int command, struct cifsFileInfo *cfile,
50 __u8 **extbuf, size_t *extbuflen,
51 struct kvec *out_iov, int *out_buftype)
53 struct smb2_compound_vars *vars = NULL;
55 struct smb_rqst *rqst;
57 __le16 *utf16_path = NULL;
58 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
60 struct cifs_ses *ses = tcon->ses;
61 struct TCP_Server_Info *server;
64 struct smb2_query_info_rsp *qi_rsp = NULL;
65 struct cifs_open_info_data *idata;
67 __u8 delete_pending[8] = {1, 0, 0, 0, 0, 0, 0, 0};
72 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
75 rqst = &vars->rqst[0];
76 rsp_iov = &vars->rsp_iov[0];
78 server = cifs_pick_channel(ses);
80 if (smb3_encryption_required(tcon))
81 flags |= CIFS_TRANSFORM_REQ;
83 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
85 /* We already have a handle so we can skip the open */
90 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
96 vars->oparms = (struct cifs_open_parms) {
99 .desired_access = desired_access,
100 .disposition = create_disposition,
101 .create_options = cifs_create_options(cifs_sb, create_options),
107 rqst[num_rqst].rq_iov = &vars->open_iov[0];
108 rqst[num_rqst].rq_nvec = SMB2_CREATE_IOV_SIZE;
109 rc = SMB2_open_init(tcon, server,
110 &rqst[num_rqst], &oplock, &vars->oparms,
116 smb2_set_next_command(tcon, &rqst[num_rqst]);
123 case SMB2_OP_QUERY_INFO:
124 rqst[num_rqst].rq_iov = &vars->qi_iov;
125 rqst[num_rqst].rq_nvec = 1;
128 rc = SMB2_query_info_init(tcon, server,
130 cfile->fid.persistent_fid,
131 cfile->fid.volatile_fid,
132 FILE_ALL_INFORMATION,
134 sizeof(struct smb2_file_all_info) +
135 PATH_MAX * 2, 0, NULL);
137 rc = SMB2_query_info_init(tcon, server,
141 FILE_ALL_INFORMATION,
143 sizeof(struct smb2_file_all_info) +
144 PATH_MAX * 2, 0, NULL);
146 smb2_set_next_command(tcon, &rqst[num_rqst]);
147 smb2_set_related(&rqst[num_rqst]);
154 trace_smb3_query_info_compound_enter(xid, ses->Suid, tcon->tid,
157 case SMB2_OP_POSIX_QUERY_INFO:
158 rqst[num_rqst].rq_iov = &vars->qi_iov;
159 rqst[num_rqst].rq_nvec = 1;
162 rc = SMB2_query_info_init(tcon, server,
164 cfile->fid.persistent_fid,
165 cfile->fid.volatile_fid,
166 SMB_FIND_FILE_POSIX_INFO,
168 /* TBD: fix following to allow for longer SIDs */
169 sizeof(struct smb311_posix_qinfo *) + (PATH_MAX * 2) +
170 (sizeof(struct cifs_sid) * 2), 0, NULL);
172 rc = SMB2_query_info_init(tcon, server,
176 SMB_FIND_FILE_POSIX_INFO,
178 sizeof(struct smb311_posix_qinfo *) + (PATH_MAX * 2) +
179 (sizeof(struct cifs_sid) * 2), 0, NULL);
181 smb2_set_next_command(tcon, &rqst[num_rqst]);
182 smb2_set_related(&rqst[num_rqst]);
189 trace_smb3_posix_query_info_compound_enter(xid, ses->Suid, tcon->tid, full_path);
192 trace_smb3_delete_enter(xid, ses->Suid, tcon->tid, full_path);
196 * Directories are created through parameters in the
199 trace_smb3_mkdir_enter(xid, ses->Suid, tcon->tid, full_path);
202 rqst[num_rqst].rq_iov = &vars->si_iov[0];
203 rqst[num_rqst].rq_nvec = 1;
205 size[0] = 1; /* sizeof __u8 See MS-FSCC section 2.4.11 */
206 data[0] = &delete_pending[0];
208 rc = SMB2_set_info_init(tcon, server,
209 &rqst[num_rqst], COMPOUND_FID,
210 COMPOUND_FID, current->tgid,
211 FILE_DISPOSITION_INFORMATION,
212 SMB2_O_INFO_FILE, 0, data, size);
215 smb2_set_next_command(tcon, &rqst[num_rqst]);
216 smb2_set_related(&rqst[num_rqst++]);
217 trace_smb3_rmdir_enter(xid, ses->Suid, tcon->tid, full_path);
219 case SMB2_OP_SET_EOF:
220 rqst[num_rqst].rq_iov = &vars->si_iov[0];
221 rqst[num_rqst].rq_nvec = 1;
223 size[0] = 8; /* sizeof __le64 */
227 rc = SMB2_set_info_init(tcon, server,
229 cfile->fid.persistent_fid,
230 cfile->fid.volatile_fid,
232 FILE_END_OF_FILE_INFORMATION,
236 rc = SMB2_set_info_init(tcon, server,
241 FILE_END_OF_FILE_INFORMATION,
245 smb2_set_next_command(tcon, &rqst[num_rqst]);
246 smb2_set_related(&rqst[num_rqst]);
252 trace_smb3_set_eof_enter(xid, ses->Suid, tcon->tid, full_path);
254 case SMB2_OP_SET_INFO:
255 rqst[num_rqst].rq_iov = &vars->si_iov[0];
256 rqst[num_rqst].rq_nvec = 1;
259 size[0] = sizeof(FILE_BASIC_INFO);
263 rc = SMB2_set_info_init(tcon, server,
265 cfile->fid.persistent_fid,
266 cfile->fid.volatile_fid, current->tgid,
267 FILE_BASIC_INFORMATION,
268 SMB2_O_INFO_FILE, 0, data, size);
270 rc = SMB2_set_info_init(tcon, server,
273 COMPOUND_FID, current->tgid,
274 FILE_BASIC_INFORMATION,
275 SMB2_O_INFO_FILE, 0, data, size);
277 smb2_set_next_command(tcon, &rqst[num_rqst]);
278 smb2_set_related(&rqst[num_rqst]);
285 trace_smb3_set_info_compound_enter(xid, ses->Suid, tcon->tid,
289 rqst[num_rqst].rq_iov = &vars->si_iov[0];
290 rqst[num_rqst].rq_nvec = 2;
292 len = (2 * UniStrnlen((wchar_t *)ptr, PATH_MAX));
294 vars->rename_info.ReplaceIfExists = 1;
295 vars->rename_info.RootDirectory = 0;
296 vars->rename_info.FileNameLength = cpu_to_le32(len);
298 size[0] = sizeof(struct smb2_file_rename_info);
299 data[0] = &vars->rename_info;
301 size[1] = len + 2 /* null */;
302 data[1] = (__le16 *)ptr;
305 rc = SMB2_set_info_init(tcon, server,
307 cfile->fid.persistent_fid,
308 cfile->fid.volatile_fid,
309 current->tgid, FILE_RENAME_INFORMATION,
310 SMB2_O_INFO_FILE, 0, data, size);
312 rc = SMB2_set_info_init(tcon, server,
314 COMPOUND_FID, COMPOUND_FID,
315 current->tgid, FILE_RENAME_INFORMATION,
316 SMB2_O_INFO_FILE, 0, data, size);
318 smb2_set_next_command(tcon, &rqst[num_rqst]);
319 smb2_set_related(&rqst[num_rqst]);
325 trace_smb3_rename_enter(xid, ses->Suid, tcon->tid, full_path);
327 case SMB2_OP_HARDLINK:
328 rqst[num_rqst].rq_iov = &vars->si_iov[0];
329 rqst[num_rqst].rq_nvec = 2;
331 len = (2 * UniStrnlen((wchar_t *)ptr, PATH_MAX));
333 vars->link_info.ReplaceIfExists = 0;
334 vars->link_info.RootDirectory = 0;
335 vars->link_info.FileNameLength = cpu_to_le32(len);
337 size[0] = sizeof(struct smb2_file_link_info);
338 data[0] = &vars->link_info;
340 size[1] = len + 2 /* null */;
341 data[1] = (__le16 *)ptr;
343 rc = SMB2_set_info_init(tcon, server,
344 &rqst[num_rqst], COMPOUND_FID,
345 COMPOUND_FID, current->tgid,
346 FILE_LINK_INFORMATION,
347 SMB2_O_INFO_FILE, 0, data, size);
350 smb2_set_next_command(tcon, &rqst[num_rqst]);
351 smb2_set_related(&rqst[num_rqst++]);
352 trace_smb3_hardlink_enter(xid, ses->Suid, tcon->tid, full_path);
355 cifs_dbg(VFS, "Invalid command\n");
361 /* We already have a handle so we can skip the close */
365 flags |= CIFS_CP_CREATE_CLOSE_OP;
366 rqst[num_rqst].rq_iov = &vars->close_iov;
367 rqst[num_rqst].rq_nvec = 1;
368 rc = SMB2_close_init(tcon, server,
369 &rqst[num_rqst], COMPOUND_FID,
370 COMPOUND_FID, false);
371 smb2_set_related(&rqst[num_rqst]);
378 rc = compound_send_recv(xid, ses, server,
380 &rqst[1], &resp_buftype[1],
383 rc = compound_send_recv(xid, ses, server,
389 SMB2_open_free(&rqst[0]);
390 if (rc == -EREMCHG) {
391 pr_warn_once("server share %s deleted\n", tcon->tree_name);
392 tcon->need_reconnect = true;
396 case SMB2_OP_QUERY_INFO:
398 if (rc == 0 && cfile && cfile->symlink_target) {
399 idata->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
400 if (!idata->symlink_target)
404 qi_rsp = (struct smb2_query_info_rsp *)
406 rc = smb2_validate_and_copy_iov(
407 le16_to_cpu(qi_rsp->OutputBufferOffset),
408 le32_to_cpu(qi_rsp->OutputBufferLength),
409 &rsp_iov[1], sizeof(idata->fi), (char *)&idata->fi);
412 SMB2_query_info_free(&rqst[1]);
414 SMB2_close_free(&rqst[2]);
416 trace_smb3_query_info_compound_err(xid, ses->Suid,
419 trace_smb3_query_info_compound_done(xid, ses->Suid,
422 case SMB2_OP_POSIX_QUERY_INFO:
424 if (rc == 0 && cfile && cfile->symlink_target) {
425 idata->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
426 if (!idata->symlink_target)
430 qi_rsp = (struct smb2_query_info_rsp *)
432 rc = smb2_validate_and_copy_iov(
433 le16_to_cpu(qi_rsp->OutputBufferOffset),
434 le32_to_cpu(qi_rsp->OutputBufferLength),
435 &rsp_iov[1], sizeof(idata->posix_fi) /* add SIDs */,
436 (char *)&idata->posix_fi);
439 unsigned int length = le32_to_cpu(qi_rsp->OutputBufferLength);
441 if (length > sizeof(idata->posix_fi)) {
442 char *base = (char *)rsp_iov[1].iov_base +
443 le16_to_cpu(qi_rsp->OutputBufferOffset) +
444 sizeof(idata->posix_fi);
445 *extbuflen = length - sizeof(idata->posix_fi);
446 *extbuf = kmemdup(base, *extbuflen, GFP_KERNEL);
454 SMB2_query_info_free(&rqst[1]);
456 SMB2_close_free(&rqst[2]);
458 trace_smb3_posix_query_info_compound_err(xid, ses->Suid, tcon->tid, rc);
460 trace_smb3_posix_query_info_compound_done(xid, ses->Suid, tcon->tid);
464 trace_smb3_delete_err(xid, ses->Suid, tcon->tid, rc);
466 trace_smb3_delete_done(xid, ses->Suid, tcon->tid);
468 SMB2_close_free(&rqst[1]);
472 trace_smb3_mkdir_err(xid, ses->Suid, tcon->tid, rc);
474 trace_smb3_mkdir_done(xid, ses->Suid, tcon->tid);
476 SMB2_close_free(&rqst[1]);
478 case SMB2_OP_HARDLINK:
480 trace_smb3_hardlink_err(xid, ses->Suid, tcon->tid, rc);
482 trace_smb3_hardlink_done(xid, ses->Suid, tcon->tid);
483 free_set_inf_compound(rqst);
487 trace_smb3_rename_err(xid, ses->Suid, tcon->tid, rc);
489 trace_smb3_rename_done(xid, ses->Suid, tcon->tid);
490 free_set_inf_compound(rqst);
494 trace_smb3_rmdir_err(xid, ses->Suid, tcon->tid, rc);
496 trace_smb3_rmdir_done(xid, ses->Suid, tcon->tid);
497 free_set_inf_compound(rqst);
499 case SMB2_OP_SET_EOF:
501 trace_smb3_set_eof_err(xid, ses->Suid, tcon->tid, rc);
503 trace_smb3_set_eof_done(xid, ses->Suid, tcon->tid);
504 free_set_inf_compound(rqst);
506 case SMB2_OP_SET_INFO:
508 trace_smb3_set_info_compound_err(xid, ses->Suid,
511 trace_smb3_set_info_compound_done(xid, ses->Suid,
513 free_set_inf_compound(rqst);
518 cifsFileInfo_put(cfile);
520 if (out_iov && out_buftype) {
521 memcpy(out_iov, rsp_iov, 3 * sizeof(*out_iov));
522 memcpy(out_buftype, resp_buftype, 3 * sizeof(*out_buftype));
524 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
525 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
526 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
532 static int parse_create_response(struct cifs_open_info_data *data,
533 struct cifs_sb_info *cifs_sb,
534 const struct kvec *iov)
536 struct smb2_create_rsp *rsp = iov->iov_base;
537 bool reparse_point = false;
541 switch (rsp->hdr.Status) {
542 case STATUS_IO_REPARSE_TAG_NOT_HANDLED:
543 reparse_point = true;
545 case STATUS_STOPPED_ON_SYMLINK:
546 rc = smb2_parse_symlink_response(cifs_sb, iov,
547 &data->symlink_target);
550 tag = IO_REPARSE_TAG_SYMLINK;
551 reparse_point = true;
554 reparse_point = !!(rsp->Flags & SMB2_CREATE_FLAG_REPARSEPOINT);
557 data->reparse_point = reparse_point;
558 data->reparse_tag = tag;
562 int smb2_query_path_info(const unsigned int xid,
563 struct cifs_tcon *tcon,
564 struct cifs_sb_info *cifs_sb,
565 const char *full_path,
566 struct cifs_open_info_data *data)
568 __u32 create_options = 0;
569 struct cifsFileInfo *cfile;
570 struct cached_fid *cfid = NULL;
571 struct smb2_hdr *hdr;
572 struct kvec out_iov[3] = {};
573 int out_buftype[3] = {};
577 data->adjust_tz = false;
578 data->reparse_point = false;
580 if (strcmp(full_path, ""))
583 rc = open_cached_dir(xid, tcon, full_path, cifs_sb, false, &cfid);
584 /* If it is a root and its handle is cached then use it */
586 if (cfid->file_all_info_is_valid) {
587 memcpy(&data->fi, &cfid->file_all_info, sizeof(data->fi));
589 rc = SMB2_query_info(xid, tcon, cfid->fid.persistent_fid,
590 cfid->fid.volatile_fid, &data->fi);
592 close_cached_dir(cfid);
596 cifs_get_readable_path(tcon, full_path, &cfile);
597 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES, FILE_OPEN,
598 create_options, ACL_NO_MODE, data, SMB2_OP_QUERY_INFO, cfile,
599 NULL, NULL, out_iov, out_buftype);
600 hdr = out_iov[0].iov_base;
602 * If first iov is unset, then SMB session was dropped or we've got a
603 * cached open file (@cfile).
605 if (!hdr || out_buftype[0] == CIFS_NO_BUFFER)
611 rc = parse_create_response(data, cifs_sb, &out_iov[0]);
612 if (rc || !data->reparse_point)
615 create_options |= OPEN_REPARSE_POINT;
616 /* Failed on a symbolic link - query a reparse point info */
617 cifs_get_readable_path(tcon, full_path, &cfile);
618 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
619 FILE_READ_ATTRIBUTES, FILE_OPEN,
620 create_options, ACL_NO_MODE, data,
621 SMB2_OP_QUERY_INFO, cfile, NULL, NULL,
627 if (hdr->Status != STATUS_OBJECT_NAME_INVALID)
629 rc2 = cifs_inval_name_dfs_link_error(xid, tcon, cifs_sb,
640 free_rsp_buf(out_buftype[0], out_iov[0].iov_base);
641 free_rsp_buf(out_buftype[1], out_iov[1].iov_base);
642 free_rsp_buf(out_buftype[2], out_iov[2].iov_base);
646 int smb311_posix_query_path_info(const unsigned int xid,
647 struct cifs_tcon *tcon,
648 struct cifs_sb_info *cifs_sb,
649 const char *full_path,
650 struct cifs_open_info_data *data,
651 struct cifs_sid *owner,
652 struct cifs_sid *group)
655 __u32 create_options = 0;
656 struct cifsFileInfo *cfile;
657 struct kvec out_iov[3] = {};
658 int out_buftype[3] = {};
659 __u8 *sidsbuf = NULL;
660 __u8 *sidsbuf_end = NULL;
661 size_t sidsbuflen = 0;
662 size_t owner_len, group_len;
664 data->adjust_tz = false;
665 data->reparse_point = false;
668 * BB TODO: Add support for using the cached root handle.
669 * Create SMB2_query_posix_info worker function to do non-compounded query
670 * when we already have an open file handle for this. For now this is fast enough
671 * (always using the compounded version).
674 cifs_get_readable_path(tcon, full_path, &cfile);
675 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES, FILE_OPEN,
676 create_options, ACL_NO_MODE, data, SMB2_OP_POSIX_QUERY_INFO, cfile,
677 &sidsbuf, &sidsbuflen, out_iov, out_buftype);
679 * If first iov is unset, then SMB session was dropped or we've got a
680 * cached open file (@cfile).
682 if (!out_iov[0].iov_base || out_buftype[0] == CIFS_NO_BUFFER)
688 /* BB TODO: When support for special files added to Samba re-verify this path */
689 rc = parse_create_response(data, cifs_sb, &out_iov[0]);
690 if (rc || !data->reparse_point)
693 create_options |= OPEN_REPARSE_POINT;
694 /* Failed on a symbolic link - query a reparse point info */
695 cifs_get_readable_path(tcon, full_path, &cfile);
696 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES,
697 FILE_OPEN, create_options, ACL_NO_MODE, data,
698 SMB2_OP_POSIX_QUERY_INFO, cfile,
699 &sidsbuf, &sidsbuflen, NULL, NULL);
705 sidsbuf_end = sidsbuf + sidsbuflen;
707 owner_len = posix_info_sid_size(sidsbuf, sidsbuf_end);
708 if (owner_len == -1) {
712 memcpy(owner, sidsbuf, owner_len);
714 group_len = posix_info_sid_size(
715 sidsbuf + owner_len, sidsbuf_end);
716 if (group_len == -1) {
720 memcpy(group, sidsbuf + owner_len, group_len);
724 free_rsp_buf(out_buftype[0], out_iov[0].iov_base);
725 free_rsp_buf(out_buftype[1], out_iov[1].iov_base);
726 free_rsp_buf(out_buftype[2], out_iov[2].iov_base);
731 smb2_mkdir(const unsigned int xid, struct inode *parent_inode, umode_t mode,
732 struct cifs_tcon *tcon, const char *name,
733 struct cifs_sb_info *cifs_sb)
735 return smb2_compound_op(xid, tcon, cifs_sb, name,
736 FILE_WRITE_ATTRIBUTES, FILE_CREATE,
737 CREATE_NOT_FILE, mode, NULL, SMB2_OP_MKDIR,
738 NULL, NULL, NULL, NULL, NULL);
742 smb2_mkdir_setinfo(struct inode *inode, const char *name,
743 struct cifs_sb_info *cifs_sb, struct cifs_tcon *tcon,
744 const unsigned int xid)
746 FILE_BASIC_INFO data;
747 struct cifsInodeInfo *cifs_i;
748 struct cifsFileInfo *cfile;
752 memset(&data, 0, sizeof(data));
753 cifs_i = CIFS_I(inode);
754 dosattrs = cifs_i->cifsAttrs | ATTR_READONLY;
755 data.Attributes = cpu_to_le32(dosattrs);
756 cifs_get_writable_path(tcon, name, FIND_WR_ANY, &cfile);
757 tmprc = smb2_compound_op(xid, tcon, cifs_sb, name,
758 FILE_WRITE_ATTRIBUTES, FILE_CREATE,
759 CREATE_NOT_FILE, ACL_NO_MODE,
760 &data, SMB2_OP_SET_INFO, cfile, NULL, NULL, NULL, NULL);
762 cifs_i->cifsAttrs = dosattrs;
766 smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
767 struct cifs_sb_info *cifs_sb)
769 drop_cached_dir_by_name(xid, tcon, name, cifs_sb);
770 return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
771 CREATE_NOT_FILE, ACL_NO_MODE,
772 NULL, SMB2_OP_RMDIR, NULL, NULL, NULL, NULL, NULL);
776 smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
777 struct cifs_sb_info *cifs_sb)
779 return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
780 CREATE_DELETE_ON_CLOSE | OPEN_REPARSE_POINT,
781 ACL_NO_MODE, NULL, SMB2_OP_DELETE, NULL, NULL, NULL, NULL, NULL);
785 smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon,
786 const char *from_name, const char *to_name,
787 struct cifs_sb_info *cifs_sb, __u32 access, int command,
788 struct cifsFileInfo *cfile)
790 __le16 *smb2_to_name = NULL;
793 smb2_to_name = cifs_convert_path_to_utf16(to_name, cifs_sb);
794 if (smb2_to_name == NULL) {
796 goto smb2_rename_path;
798 rc = smb2_compound_op(xid, tcon, cifs_sb, from_name, access,
799 FILE_OPEN, 0, ACL_NO_MODE, smb2_to_name,
800 command, cfile, NULL, NULL, NULL, NULL);
807 smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon,
808 const char *from_name, const char *to_name,
809 struct cifs_sb_info *cifs_sb)
811 struct cifsFileInfo *cfile;
813 drop_cached_dir_by_name(xid, tcon, from_name, cifs_sb);
814 cifs_get_writable_path(tcon, from_name, FIND_WR_WITH_DELETE, &cfile);
816 return smb2_set_path_attr(xid, tcon, from_name, to_name,
817 cifs_sb, DELETE, SMB2_OP_RENAME, cfile);
821 smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon,
822 const char *from_name, const char *to_name,
823 struct cifs_sb_info *cifs_sb)
825 return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb,
826 FILE_READ_ATTRIBUTES, SMB2_OP_HARDLINK,
831 smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon,
832 const char *full_path, __u64 size,
833 struct cifs_sb_info *cifs_sb, bool set_alloc)
835 __le64 eof = cpu_to_le64(size);
836 struct cifsFileInfo *cfile;
838 cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);
839 return smb2_compound_op(xid, tcon, cifs_sb, full_path,
840 FILE_WRITE_DATA, FILE_OPEN, 0, ACL_NO_MODE,
841 &eof, SMB2_OP_SET_EOF, cfile, NULL, NULL, NULL, NULL);
845 smb2_set_file_info(struct inode *inode, const char *full_path,
846 FILE_BASIC_INFO *buf, const unsigned int xid)
848 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
849 struct tcon_link *tlink;
850 struct cifs_tcon *tcon;
851 struct cifsFileInfo *cfile;
854 if ((buf->CreationTime == 0) && (buf->LastAccessTime == 0) &&
855 (buf->LastWriteTime == 0) && (buf->ChangeTime == 0) &&
856 (buf->Attributes == 0))
857 return 0; /* would be a no op, no sense sending this */
859 tlink = cifs_sb_tlink(cifs_sb);
861 return PTR_ERR(tlink);
862 tcon = tlink_tcon(tlink);
864 cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);
865 rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
866 FILE_WRITE_ATTRIBUTES, FILE_OPEN,
867 0, ACL_NO_MODE, buf, SMB2_OP_SET_INFO, cfile,
868 NULL, NULL, NULL, NULL);
869 cifs_put_tlink(tlink);