Lines Matching +full:tcon +full:- +full:channel
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 /* SMB2 PDU handling routines here - except for leftovers (eg session setup) */
86 int smb3_encryption_required(const struct cifs_tcon *tcon) in smb3_encryption_required() argument
88 if (!tcon || !tcon->ses) in smb3_encryption_required()
90 if ((tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) || in smb3_encryption_required()
91 (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA)) in smb3_encryption_required()
93 if (tcon->seal && in smb3_encryption_required()
94 (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION)) in smb3_encryption_required()
101 const struct cifs_tcon *tcon, in smb2_hdr_assemble() argument
104 shdr->ProtocolId = SMB2_PROTO_NUMBER; in smb2_hdr_assemble()
105 shdr->StructureSize = cpu_to_le16(64); in smb2_hdr_assemble()
106 shdr->Command = smb2_cmd; in smb2_hdr_assemble()
108 spin_lock(&server->req_lock); in smb2_hdr_assemble()
110 if (server->credits >= server->max_credits) in smb2_hdr_assemble()
111 shdr->CreditRequest = cpu_to_le16(0); in smb2_hdr_assemble()
113 shdr->CreditRequest = cpu_to_le16( in smb2_hdr_assemble()
114 min_t(int, server->max_credits - in smb2_hdr_assemble()
115 server->credits, 10)); in smb2_hdr_assemble()
116 spin_unlock(&server->req_lock); in smb2_hdr_assemble()
118 shdr->CreditRequest = cpu_to_le16(2); in smb2_hdr_assemble()
120 shdr->ProcessId = cpu_to_le32((__u16)current->tgid); in smb2_hdr_assemble()
122 if (!tcon) in smb2_hdr_assemble()
126 /* See sections 2.2.4 and 3.2.4.1.5 of MS-SMB2 */ in smb2_hdr_assemble()
127 if (server && (server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) in smb2_hdr_assemble()
128 shdr->CreditCharge = cpu_to_le16(1); in smb2_hdr_assemble()
131 shdr->TreeId = tcon->tid; in smb2_hdr_assemble()
133 if (tcon->ses) in smb2_hdr_assemble()
134 shdr->SessionId = tcon->ses->Suid; in smb2_hdr_assemble()
146 /* if (tcon->share_flags & SHI1005_FLAGS_DFS) in smb2_hdr_assemble()
147 shdr->Flags |= SMB2_FLAGS_DFS_OPERATIONS; */ in smb2_hdr_assemble()
149 if (server && server->sign && !smb3_encryption_required(tcon)) in smb2_hdr_assemble()
150 shdr->Flags |= SMB2_FLAGS_SIGNED; in smb2_hdr_assemble()
156 smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, in smb2_reconnect() argument
165 * SMB2s NegProt, SessSetup, Logoff do not have tcon yet so in smb2_reconnect()
167 * for those three - in the calling routine. in smb2_reconnect()
169 if (tcon == NULL) in smb2_reconnect()
175 if (tcon->tidStatus == CifsExiting) { in smb2_reconnect()
178 * (and ulogoff which does not have tcon) in smb2_reconnect()
186 return -ENODEV; in smb2_reconnect()
189 if ((!tcon->ses) || (tcon->ses->status == CifsExiting) || in smb2_reconnect()
190 (!tcon->ses->server) || !server) in smb2_reconnect()
191 return -EIO; in smb2_reconnect()
193 ses = tcon->ses; in smb2_reconnect()
194 retries = server->nr_targets; in smb2_reconnect()
198 * reconnect -- should be greater than cifs socket timeout which is 7 in smb2_reconnect()
201 while (server->tcpStatus == CifsNeedReconnect) { in smb2_reconnect()
214 return -EAGAIN; in smb2_reconnect()
217 rc = wait_event_interruptible_timeout(server->response_q, in smb2_reconnect()
218 (server->tcpStatus != CifsNeedReconnect), in smb2_reconnect()
223 return -ERESTARTSYS; in smb2_reconnect()
227 if (server->tcpStatus != CifsNeedReconnect) in smb2_reconnect()
230 if (retries && --retries) in smb2_reconnect()
236 * back on-line in smb2_reconnect()
238 if (!tcon->retry) { in smb2_reconnect()
240 return -EHOSTDOWN; in smb2_reconnect()
242 retries = server->nr_targets; in smb2_reconnect()
245 if (!tcon->ses->need_reconnect && !tcon->need_reconnect) in smb2_reconnect()
254 mutex_lock(&tcon->ses->session_mutex); in smb2_reconnect()
261 if (server->tcpStatus == CifsNeedReconnect) { in smb2_reconnect()
262 rc = -EHOSTDOWN; in smb2_reconnect()
263 mutex_unlock(&tcon->ses->session_mutex); in smb2_reconnect()
268 * If we are reconnecting an extra channel, bind in smb2_reconnect()
270 if (server->is_channel) { in smb2_reconnect()
271 ses->binding = true; in smb2_reconnect()
272 ses->binding_chan = cifs_ses_find_chan(ses, server); in smb2_reconnect()
275 rc = cifs_negotiate_protocol(0, tcon->ses); in smb2_reconnect()
276 if (!rc && tcon->ses->need_reconnect) { in smb2_reconnect()
277 rc = cifs_setup_session(0, tcon->ses, nls_codepage); in smb2_reconnect()
278 if ((rc == -EACCES) && !tcon->retry) { in smb2_reconnect()
279 rc = -EHOSTDOWN; in smb2_reconnect()
280 ses->binding = false; in smb2_reconnect()
281 ses->binding_chan = NULL; in smb2_reconnect()
282 mutex_unlock(&tcon->ses->session_mutex); in smb2_reconnect()
287 * End of channel binding in smb2_reconnect()
289 ses->binding = false; in smb2_reconnect()
290 ses->binding_chan = NULL; in smb2_reconnect()
292 if (rc || !tcon->need_reconnect) { in smb2_reconnect()
293 mutex_unlock(&tcon->ses->session_mutex); in smb2_reconnect()
297 cifs_mark_open_files_invalid(tcon); in smb2_reconnect()
298 if (tcon->use_persistent) in smb2_reconnect()
299 tcon->need_reopen_files = true; in smb2_reconnect()
301 rc = cifs_tree_connect(0, tcon, nls_codepage); in smb2_reconnect()
302 mutex_unlock(&tcon->ses->session_mutex); in smb2_reconnect()
304 cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc); in smb2_reconnect()
306 /* If sess reconnected but tcon didn't, something strange ... */ in smb2_reconnect()
307 pr_warn_once("reconnect tcon failed rc = %d\n", rc); in smb2_reconnect()
312 mod_delayed_work(cifsiod_wq, &server->reconnect, 0); in smb2_reconnect()
334 rc = -EAGAIN; in smb2_reconnect()
342 fill_small_buf(__le16 smb2_command, struct cifs_tcon *tcon, in fill_small_buf() argument
357 smb2_hdr_assemble(&spdu->sync_hdr, smb2_command, tcon, server); in fill_small_buf()
358 spdu->StructureSize2 = cpu_to_le16(parmsize); in fill_small_buf()
368 static int __smb2_plain_req_init(__le16 smb2_command, struct cifs_tcon *tcon, in __smb2_plain_req_init() argument
379 return -ENOMEM; in __smb2_plain_req_init()
382 fill_small_buf(smb2_command, tcon, server, in __smb2_plain_req_init()
386 if (tcon != NULL) { in __smb2_plain_req_init()
388 cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_sent[com_code]); in __smb2_plain_req_init()
389 cifs_stats_inc(&tcon->num_smbs_sent); in __smb2_plain_req_init()
395 static int smb2_plain_req_init(__le16 smb2_command, struct cifs_tcon *tcon, in smb2_plain_req_init() argument
401 rc = smb2_reconnect(smb2_command, tcon, server); in smb2_plain_req_init()
405 return __smb2_plain_req_init(smb2_command, tcon, server, request_buf, in smb2_plain_req_init()
409 static int smb2_ioctl_req_init(u32 opcode, struct cifs_tcon *tcon, in smb2_ioctl_req_init() argument
415 return __smb2_plain_req_init(SMB2_IOCTL, tcon, server, in smb2_ioctl_req_init()
418 return smb2_plain_req_init(SMB2_IOCTL, tcon, server, in smb2_ioctl_req_init()
422 /* For explanation of negotiate contexts see MS-SMB2 section 2.2.3.1 */
427 pneg_ctxt->ContextType = SMB2_PREAUTH_INTEGRITY_CAPABILITIES; in build_preauth_ctxt()
428 pneg_ctxt->DataLength = cpu_to_le16(38); in build_preauth_ctxt()
429 pneg_ctxt->HashAlgorithmCount = cpu_to_le16(1); in build_preauth_ctxt()
430 pneg_ctxt->SaltLength = cpu_to_le16(SMB311_LINUX_CLIENT_SALT_SIZE); in build_preauth_ctxt()
431 get_random_bytes(pneg_ctxt->Salt, SMB311_LINUX_CLIENT_SALT_SIZE); in build_preauth_ctxt()
432 pneg_ctxt->HashAlgorithms = SMB2_PREAUTH_INTEGRITY_SHA512; in build_preauth_ctxt()
438 pneg_ctxt->ContextType = SMB2_COMPRESSION_CAPABILITIES; in build_compression_ctxt()
439 pneg_ctxt->DataLength = in build_compression_ctxt()
441 - sizeof(struct smb2_neg_context)); in build_compression_ctxt()
442 pneg_ctxt->CompressionAlgorithmCount = cpu_to_le16(3); in build_compression_ctxt()
443 pneg_ctxt->CompressionAlgorithms[0] = SMB3_COMPRESS_LZ77; in build_compression_ctxt()
444 pneg_ctxt->CompressionAlgorithms[1] = SMB3_COMPRESS_LZ77_HUFF; in build_compression_ctxt()
445 pneg_ctxt->CompressionAlgorithms[2] = SMB3_COMPRESS_LZNT1; in build_compression_ctxt()
451 pneg_ctxt->ContextType = SMB2_ENCRYPTION_CAPABILITIES; in build_encrypt_ctxt()
453 pneg_ctxt->DataLength = cpu_to_le16(4); /* Cipher Count + 1 cipher */ in build_encrypt_ctxt()
454 pneg_ctxt->CipherCount = cpu_to_le16(1); in build_encrypt_ctxt()
455 pneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES256_GCM; in build_encrypt_ctxt()
457 pneg_ctxt->DataLength = cpu_to_le16(8); /* Cipher Count + 3 ciphers */ in build_encrypt_ctxt()
458 pneg_ctxt->CipherCount = cpu_to_le16(3); in build_encrypt_ctxt()
459 pneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES128_GCM; in build_encrypt_ctxt()
460 pneg_ctxt->Ciphers[1] = SMB2_ENCRYPTION_AES256_GCM; in build_encrypt_ctxt()
461 pneg_ctxt->Ciphers[2] = SMB2_ENCRYPTION_AES128_CCM; in build_encrypt_ctxt()
463 pneg_ctxt->DataLength = cpu_to_le16(6); /* Cipher Count + 2 ciphers */ in build_encrypt_ctxt()
464 pneg_ctxt->CipherCount = cpu_to_le16(2); in build_encrypt_ctxt()
465 pneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES128_GCM; in build_encrypt_ctxt()
466 pneg_ctxt->Ciphers[1] = SMB2_ENCRYPTION_AES128_CCM; in build_encrypt_ctxt()
475 pneg_ctxt->ContextType = SMB2_NETNAME_NEGOTIATE_CONTEXT_ID; in build_netname_ctxt()
478 pneg_ctxt->DataLength = cpu_to_le16(2 * cifs_strtoUTF16(pneg_ctxt->NetName, hostname, 100, cp)); in build_netname_ctxt()
480 return DIV_ROUND_UP(le16_to_cpu(pneg_ctxt->DataLength) + in build_netname_ctxt()
487 pneg_ctxt->ContextType = SMB2_POSIX_EXTENSIONS_AVAILABLE; in build_posix_ctxt()
488 pneg_ctxt->DataLength = cpu_to_le16(POSIX_CTXT_DATA_LEN); in build_posix_ctxt()
490 pneg_ctxt->Name[0] = 0x93; in build_posix_ctxt()
491 pneg_ctxt->Name[1] = 0xAD; in build_posix_ctxt()
492 pneg_ctxt->Name[2] = 0x25; in build_posix_ctxt()
493 pneg_ctxt->Name[3] = 0x50; in build_posix_ctxt()
494 pneg_ctxt->Name[4] = 0x9C; in build_posix_ctxt()
495 pneg_ctxt->Name[5] = 0xB4; in build_posix_ctxt()
496 pneg_ctxt->Name[6] = 0x11; in build_posix_ctxt()
497 pneg_ctxt->Name[7] = 0xE7; in build_posix_ctxt()
498 pneg_ctxt->Name[8] = 0xB4; in build_posix_ctxt()
499 pneg_ctxt->Name[9] = 0x23; in build_posix_ctxt()
500 pneg_ctxt->Name[10] = 0x83; in build_posix_ctxt()
501 pneg_ctxt->Name[11] = 0xDE; in build_posix_ctxt()
502 pneg_ctxt->Name[12] = 0x96; in build_posix_ctxt()
503 pneg_ctxt->Name[13] = 0x8B; in build_posix_ctxt()
504 pneg_ctxt->Name[14] = 0xCD; in build_posix_ctxt()
505 pneg_ctxt->Name[15] = 0x7C; in build_posix_ctxt()
528 req->NegotiateContextOffset = cpu_to_le32(*total_len); in assemble_neg_contexts()
540 if (server->compress_algorithm) { in assemble_neg_contexts()
548 req->NegotiateContextCount = cpu_to_le16(5); in assemble_neg_contexts()
550 req->NegotiateContextCount = cpu_to_le16(4); in assemble_neg_contexts()
553 server->hostname); in assemble_neg_contexts()
563 unsigned int len = le16_to_cpu(ctxt->DataLength); in decode_preauth_context()
565 /* If invalid preauth context warn but use what we requested, SHA-512 */ in decode_preauth_context()
569 } else if (len < MIN_PREAUTH_CTXT_DATA_LEN + le16_to_cpu(ctxt->SaltLength)) { in decode_preauth_context()
573 if (le16_to_cpu(ctxt->HashAlgorithmCount) != 1) in decode_preauth_context()
575 if (ctxt->HashAlgorithms != SMB2_PREAUTH_INTEGRITY_SHA512) in decode_preauth_context()
582 unsigned int len = le16_to_cpu(ctxt->DataLength); in decode_compress_ctx()
589 if (le16_to_cpu(ctxt->CompressionAlgorithmCount) != 1) { in decode_compress_ctx()
593 if (le16_to_cpu(ctxt->CompressionAlgorithms[0]) > 3) { in decode_compress_ctx()
597 server->compress_algorithm = ctxt->CompressionAlgorithms[0]; in decode_compress_ctx()
603 unsigned int len = le16_to_cpu(ctxt->DataLength); in decode_encrypt_ctx()
608 return -EINVAL; in decode_encrypt_ctx()
611 if (le16_to_cpu(ctxt->CipherCount) != 1) { in decode_encrypt_ctx()
613 return -EINVAL; in decode_encrypt_ctx()
615 cifs_dbg(FYI, "SMB311 cipher type:%d\n", le16_to_cpu(ctxt->Ciphers[0])); in decode_encrypt_ctx()
617 if (ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES256_GCM) { in decode_encrypt_ctx()
619 return -EOPNOTSUPP; in decode_encrypt_ctx()
621 } else if (ctxt->Ciphers[0] == 0) { in decode_encrypt_ctx()
631 server->cipher_type = 0; in decode_encrypt_ctx()
632 server->capabilities &= ~SMB2_GLOBAL_CAP_ENCRYPTION; in decode_encrypt_ctx()
635 } else if ((ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES128_CCM) && in decode_encrypt_ctx()
636 (ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES128_GCM) && in decode_encrypt_ctx()
637 (ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES256_GCM)) { in decode_encrypt_ctx()
640 return -EINVAL; in decode_encrypt_ctx()
642 server->cipher_type = ctxt->Ciphers[0]; in decode_encrypt_ctx()
643 server->capabilities |= SMB2_GLOBAL_CAP_ENCRYPTION; in decode_encrypt_ctx()
652 unsigned int offset = le32_to_cpu(rsp->NegotiateContextOffset); in smb311_decode_neg_context()
653 unsigned int ctxt_cnt = le16_to_cpu(rsp->NegotiateContextCount); in smb311_decode_neg_context()
660 return -EINVAL; in smb311_decode_neg_context()
663 len_of_ctxts = len_of_smb - offset; in smb311_decode_neg_context()
675 clen = le16_to_cpu(pctx->DataLength); in smb311_decode_neg_context()
679 if (pctx->ContextType == SMB2_PREAUTH_INTEGRITY_CAPABILITIES) in smb311_decode_neg_context()
682 else if (pctx->ContextType == SMB2_ENCRYPTION_CAPABILITIES) in smb311_decode_neg_context()
685 else if (pctx->ContextType == SMB2_COMPRESSION_CAPABILITIES) in smb311_decode_neg_context()
688 else if (pctx->ContextType == SMB2_POSIX_EXTENSIONS_AVAILABLE) in smb311_decode_neg_context()
689 server->posix_ext_supported = true; in smb311_decode_neg_context()
692 le16_to_cpu(pctx->ContextType)); in smb311_decode_neg_context()
699 len_of_ctxts -= clen; in smb311_decode_neg_context()
714 buf->ccontext.DataOffset = in create_posix_buf()
716 buf->ccontext.DataLength = cpu_to_le32(4); in create_posix_buf()
717 buf->ccontext.NameOffset = in create_posix_buf()
719 buf->ccontext.NameLength = cpu_to_le16(16); in create_posix_buf()
722 buf->Name[0] = 0x93; in create_posix_buf()
723 buf->Name[1] = 0xAD; in create_posix_buf()
724 buf->Name[2] = 0x25; in create_posix_buf()
725 buf->Name[3] = 0x50; in create_posix_buf()
726 buf->Name[4] = 0x9C; in create_posix_buf()
727 buf->Name[5] = 0xB4; in create_posix_buf()
728 buf->Name[6] = 0x11; in create_posix_buf()
729 buf->Name[7] = 0xE7; in create_posix_buf()
730 buf->Name[8] = 0xB4; in create_posix_buf()
731 buf->Name[9] = 0x23; in create_posix_buf()
732 buf->Name[10] = 0x83; in create_posix_buf()
733 buf->Name[11] = 0xDE; in create_posix_buf()
734 buf->Name[12] = 0x96; in create_posix_buf()
735 buf->Name[13] = 0x8B; in create_posix_buf()
736 buf->Name[14] = 0xCD; in create_posix_buf()
737 buf->Name[15] = 0x7C; in create_posix_buf()
738 buf->Mode = cpu_to_le32(mode); in create_posix_buf()
753 return -ENOMEM; in add_posix_context()
755 if (!req->CreateContextsOffset) in add_posix_context()
756 req->CreateContextsOffset = cpu_to_le32( in add_posix_context()
758 iov[num - 1].iov_len); in add_posix_context()
759 le32_add_cpu(&req->CreateContextsLength, sizeof(struct create_posix)); in add_posix_context()
800 return -EIO; in SMB2_negotiate()
808 req->sync_hdr.SessionId = 0; in SMB2_negotiate()
810 memset(server->preauth_sha_hash, 0, SMB2_PREAUTH_HASH_SIZE); in SMB2_negotiate()
811 memset(ses->preauth_sha_hash, 0, SMB2_PREAUTH_HASH_SIZE); in SMB2_negotiate()
813 if (strcmp(server->vals->version_string, in SMB2_negotiate()
815 req->Dialects[0] = cpu_to_le16(SMB30_PROT_ID); in SMB2_negotiate()
816 req->Dialects[1] = cpu_to_le16(SMB302_PROT_ID); in SMB2_negotiate()
817 req->DialectCount = cpu_to_le16(2); in SMB2_negotiate()
819 } else if (strcmp(server->vals->version_string, in SMB2_negotiate()
821 req->Dialects[0] = cpu_to_le16(SMB21_PROT_ID); in SMB2_negotiate()
822 req->Dialects[1] = cpu_to_le16(SMB30_PROT_ID); in SMB2_negotiate()
823 req->Dialects[2] = cpu_to_le16(SMB302_PROT_ID); in SMB2_negotiate()
824 req->Dialects[3] = cpu_to_le16(SMB311_PROT_ID); in SMB2_negotiate()
825 req->DialectCount = cpu_to_le16(4); in SMB2_negotiate()
829 req->Dialects[0] = cpu_to_le16(server->vals->protocol_id); in SMB2_negotiate()
830 req->DialectCount = cpu_to_le16(1); in SMB2_negotiate()
835 if (ses->sign) in SMB2_negotiate()
836 req->SecurityMode = cpu_to_le16(SMB2_NEGOTIATE_SIGNING_REQUIRED); in SMB2_negotiate()
838 req->SecurityMode = cpu_to_le16(SMB2_NEGOTIATE_SIGNING_ENABLED); in SMB2_negotiate()
840 req->SecurityMode = 0; in SMB2_negotiate()
842 req->Capabilities = cpu_to_le32(server->vals->req_capabilities); in SMB2_negotiate()
843 if (ses->chan_max > 1) in SMB2_negotiate()
844 req->Capabilities |= cpu_to_le32(SMB2_GLOBAL_CAP_MULTI_CHANNEL); in SMB2_negotiate()
847 if (server->vals->protocol_id == SMB20_PROT_ID) in SMB2_negotiate()
848 memset(req->ClientGUID, 0, SMB2_CLIENT_GUID_SIZE); in SMB2_negotiate()
850 memcpy(req->ClientGUID, server->client_guid, in SMB2_negotiate()
852 if ((server->vals->protocol_id == SMB311_PROT_ID) || in SMB2_negotiate()
853 (strcmp(server->vals->version_string, in SMB2_negotiate()
869 * No tcon so can't do in SMB2_negotiate()
870 * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]); in SMB2_negotiate()
872 if (rc == -EOPNOTSUPP) { in SMB2_negotiate()
878 if (strcmp(server->vals->version_string, in SMB2_negotiate()
880 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) { in SMB2_negotiate()
883 return -EIO; in SMB2_negotiate()
884 } else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) { in SMB2_negotiate()
887 return -EIO; in SMB2_negotiate()
889 } else if (strcmp(server->vals->version_string, in SMB2_negotiate()
891 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) { in SMB2_negotiate()
894 return -EIO; in SMB2_negotiate()
895 } else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) { in SMB2_negotiate()
897 server->ops = &smb21_operations; in SMB2_negotiate()
898 server->vals = &smb21_values; in SMB2_negotiate()
899 } else if (rsp->DialectRevision == cpu_to_le16(SMB311_PROT_ID)) { in SMB2_negotiate()
900 server->ops = &smb311_operations; in SMB2_negotiate()
901 server->vals = &smb311_values; in SMB2_negotiate()
903 } else if (le16_to_cpu(rsp->DialectRevision) != in SMB2_negotiate()
904 server->vals->protocol_id) { in SMB2_negotiate()
907 le16_to_cpu(rsp->DialectRevision)); in SMB2_negotiate()
908 return -EIO; in SMB2_negotiate()
911 cifs_dbg(FYI, "mode 0x%x\n", rsp->SecurityMode); in SMB2_negotiate()
913 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) in SMB2_negotiate()
915 else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) in SMB2_negotiate()
917 else if (rsp->DialectRevision == cpu_to_le16(SMB30_PROT_ID)) in SMB2_negotiate()
919 else if (rsp->DialectRevision == cpu_to_le16(SMB302_PROT_ID)) in SMB2_negotiate()
921 else if (rsp->DialectRevision == cpu_to_le16(SMB311_PROT_ID)) in SMB2_negotiate()
925 le16_to_cpu(rsp->DialectRevision)); in SMB2_negotiate()
926 rc = -EIO; in SMB2_negotiate()
929 server->dialect = le16_to_cpu(rsp->DialectRevision); in SMB2_negotiate()
936 memcpy(server->preauth_sha_hash, ses->preauth_sha_hash, in SMB2_negotiate()
940 server->negflavor = CIFS_NEGFLAVOR_EXTENDED; in SMB2_negotiate()
942 server->maxBuf = min_t(unsigned int, le32_to_cpu(rsp->MaxTransactSize), in SMB2_negotiate()
944 server->max_read = le32_to_cpu(rsp->MaxReadSize); in SMB2_negotiate()
945 server->max_write = le32_to_cpu(rsp->MaxWriteSize); in SMB2_negotiate()
946 server->sec_mode = le16_to_cpu(rsp->SecurityMode); in SMB2_negotiate()
947 if ((server->sec_mode & SMB2_SEC_MODE_FLAGS_ALL) != server->sec_mode) in SMB2_negotiate()
949 server->sec_mode); in SMB2_negotiate()
950 server->capabilities = le32_to_cpu(rsp->Capabilities); in SMB2_negotiate()
952 server->capabilities |= SMB2_NT_FIND | SMB2_LARGE_FILES; in SMB2_negotiate()
958 if (server->dialect == SMB30_PROT_ID && (server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION)) in SMB2_negotiate()
959 server->cipher_type = SMB2_ENCRYPTION_AES128_CCM; in SMB2_negotiate()
964 * See MS-SMB2 section 2.2.4: if no blob, client picks default which in SMB2_negotiate()
966 * ses->sectype = RawNTLMSSP; in SMB2_negotiate()
972 server->sec_ntlmssp = true; in SMB2_negotiate()
975 rc = cifs_enable_signing(server, ses->sign); in SMB2_negotiate()
983 rc = -EIO; in SMB2_negotiate()
986 if (rsp->DialectRevision == cpu_to_le16(SMB311_PROT_ID)) { in SMB2_negotiate()
987 if (rsp->NegotiateContextCount) in SMB2_negotiate()
998 int smb3_validate_negotiate(const unsigned int xid, struct cifs_tcon *tcon) in smb3_validate_negotiate() argument
1005 struct TCP_Server_Info *server = tcon->ses->server; in smb3_validate_negotiate()
1010 if (server->dialect == SMB311_PROT_ID) in smb3_validate_negotiate()
1020 if (tcon->ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST) in smb3_validate_negotiate()
1023 if (tcon->ses->user_name == NULL) { in smb3_validate_negotiate()
1028 if (tcon->ses->session_flags & SMB2_SESSION_FLAG_IS_NULL) in smb3_validate_negotiate()
1033 return -ENOMEM; in smb3_validate_negotiate()
1035 pneg_inbuf->Capabilities = in smb3_validate_negotiate()
1036 cpu_to_le32(server->vals->req_capabilities); in smb3_validate_negotiate()
1037 if (tcon->ses->chan_max > 1) in smb3_validate_negotiate()
1038 pneg_inbuf->Capabilities |= cpu_to_le32(SMB2_GLOBAL_CAP_MULTI_CHANNEL); in smb3_validate_negotiate()
1040 memcpy(pneg_inbuf->Guid, server->client_guid, in smb3_validate_negotiate()
1043 if (tcon->ses->sign) in smb3_validate_negotiate()
1044 pneg_inbuf->SecurityMode = in smb3_validate_negotiate()
1047 pneg_inbuf->SecurityMode = in smb3_validate_negotiate()
1050 pneg_inbuf->SecurityMode = 0; in smb3_validate_negotiate()
1053 if (strcmp(server->vals->version_string, in smb3_validate_negotiate()
1055 pneg_inbuf->Dialects[0] = cpu_to_le16(SMB30_PROT_ID); in smb3_validate_negotiate()
1056 pneg_inbuf->Dialects[1] = cpu_to_le16(SMB302_PROT_ID); in smb3_validate_negotiate()
1057 pneg_inbuf->DialectCount = cpu_to_le16(2); in smb3_validate_negotiate()
1059 inbuflen = sizeof(*pneg_inbuf) - in smb3_validate_negotiate()
1060 (2 * sizeof(pneg_inbuf->Dialects[0])); in smb3_validate_negotiate()
1061 } else if (strcmp(server->vals->version_string, in smb3_validate_negotiate()
1063 pneg_inbuf->Dialects[0] = cpu_to_le16(SMB21_PROT_ID); in smb3_validate_negotiate()
1064 pneg_inbuf->Dialects[1] = cpu_to_le16(SMB30_PROT_ID); in smb3_validate_negotiate()
1065 pneg_inbuf->Dialects[2] = cpu_to_le16(SMB302_PROT_ID); in smb3_validate_negotiate()
1066 pneg_inbuf->Dialects[3] = cpu_to_le16(SMB311_PROT_ID); in smb3_validate_negotiate()
1067 pneg_inbuf->DialectCount = cpu_to_le16(4); in smb3_validate_negotiate()
1072 pneg_inbuf->Dialects[0] = in smb3_validate_negotiate()
1073 cpu_to_le16(server->vals->protocol_id); in smb3_validate_negotiate()
1074 pneg_inbuf->DialectCount = cpu_to_le16(1); in smb3_validate_negotiate()
1076 inbuflen = sizeof(*pneg_inbuf) - in smb3_validate_negotiate()
1077 sizeof(pneg_inbuf->Dialects[0]) * 2; in smb3_validate_negotiate()
1080 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, in smb3_validate_negotiate()
1084 if (rc == -EOPNOTSUPP) { in smb3_validate_negotiate()
1095 rc = -EIO; in smb3_validate_negotiate()
1099 rc = -EIO; in smb3_validate_negotiate()
1110 if (pneg_rsp->Dialect != cpu_to_le16(server->dialect)) in smb3_validate_negotiate()
1113 if (pneg_rsp->SecurityMode != cpu_to_le16(server->sec_mode)) in smb3_validate_negotiate()
1118 if ((le32_to_cpu(pneg_rsp->Capabilities) | SMB2_NT_FIND | in smb3_validate_negotiate()
1119 SMB2_LARGE_FILES) != server->capabilities) in smb3_validate_negotiate()
1128 cifs_tcon_dbg(VFS, "protocol revalidation - security settings mismatch\n"); in smb3_validate_negotiate()
1146 if (server->sec_ntlmssp && in smb2_select_sectype()
1149 if ((server->sec_kerberos || server->sec_mskerberos) && in smb2_select_sectype()
1181 struct cifs_ses *ses = sess_data->ses; in SMB2_sess_alloc_buffer()
1192 if (sess_data->ses->binding) { in SMB2_sess_alloc_buffer()
1193 req->sync_hdr.SessionId = sess_data->ses->Suid; in SMB2_sess_alloc_buffer()
1194 req->sync_hdr.Flags |= SMB2_FLAGS_SIGNED; in SMB2_sess_alloc_buffer()
1195 req->PreviousSessionId = 0; in SMB2_sess_alloc_buffer()
1196 req->Flags = SMB2_SESSION_REQ_FLAG_BINDING; in SMB2_sess_alloc_buffer()
1199 req->sync_hdr.SessionId = 0; in SMB2_sess_alloc_buffer()
1204 req->PreviousSessionId = sess_data->previous_session; in SMB2_sess_alloc_buffer()
1205 req->Flags = 0; /* MBZ */ in SMB2_sess_alloc_buffer()
1209 req->sync_hdr.CreditRequest = cpu_to_le16(130); in SMB2_sess_alloc_buffer()
1212 if (server->sign) in SMB2_sess_alloc_buffer()
1213 req->SecurityMode = SMB2_NEGOTIATE_SIGNING_REQUIRED; in SMB2_sess_alloc_buffer()
1215 req->SecurityMode = SMB2_NEGOTIATE_SIGNING_ENABLED; in SMB2_sess_alloc_buffer()
1217 req->SecurityMode = 0; in SMB2_sess_alloc_buffer()
1220 req->Capabilities = cpu_to_le32(SMB2_GLOBAL_CAP_DFS); in SMB2_sess_alloc_buffer()
1222 req->Capabilities = 0; in SMB2_sess_alloc_buffer()
1225 req->Channel = 0; /* MBZ */ in SMB2_sess_alloc_buffer()
1227 sess_data->iov[0].iov_base = (char *)req; in SMB2_sess_alloc_buffer()
1229 sess_data->iov[0].iov_len = total_len - 1; in SMB2_sess_alloc_buffer()
1234 sess_data->buf0_type = CIFS_SMALL_BUFFER; in SMB2_sess_alloc_buffer()
1242 free_rsp_buf(sess_data->buf0_type, sess_data->iov[0].iov_base); in SMB2_sess_free_buffer()
1243 sess_data->buf0_type = CIFS_NO_BUFFER; in SMB2_sess_free_buffer()
1251 struct smb2_sess_setup_req *req = sess_data->iov[0].iov_base; in SMB2_sess_sendreceive()
1255 req->SecurityBufferOffset = in SMB2_sess_sendreceive()
1256 cpu_to_le16(sizeof(struct smb2_sess_setup_req) - 1 /* pad */); in SMB2_sess_sendreceive()
1257 req->SecurityBufferLength = cpu_to_le16(sess_data->iov[1].iov_len); in SMB2_sess_sendreceive()
1260 rqst.rq_iov = sess_data->iov; in SMB2_sess_sendreceive()
1264 rc = cifs_send_recv(sess_data->xid, sess_data->ses, in SMB2_sess_sendreceive()
1265 cifs_ses_server(sess_data->ses), in SMB2_sess_sendreceive()
1267 &sess_data->buf0_type, in SMB2_sess_sendreceive()
1269 cifs_small_buf_release(sess_data->iov[0].iov_base); in SMB2_sess_sendreceive()
1270 memcpy(&sess_data->iov[0], &rsp_iov, sizeof(struct kvec)); in SMB2_sess_sendreceive()
1279 struct cifs_ses *ses = sess_data->ses; in SMB2_sess_establish_session()
1282 mutex_lock(&server->srv_mutex); in SMB2_sess_establish_session()
1283 if (server->ops->generate_signingkey) { in SMB2_sess_establish_session()
1284 rc = server->ops->generate_signingkey(ses); in SMB2_sess_establish_session()
1288 mutex_unlock(&server->srv_mutex); in SMB2_sess_establish_session()
1292 if (!server->session_estab) { in SMB2_sess_establish_session()
1293 server->sequence_number = 0x2; in SMB2_sess_establish_session()
1294 server->session_estab = true; in SMB2_sess_establish_session()
1296 mutex_unlock(&server->srv_mutex); in SMB2_sess_establish_session()
1300 if (!ses->binding) { in SMB2_sess_establish_session()
1302 ses->status = CifsGood; in SMB2_sess_establish_session()
1303 ses->need_reconnect = false; in SMB2_sess_establish_session()
1315 struct cifs_ses *ses = sess_data->ses; in SMB2_auth_kerberos()
1327 if (rc == -ENOKEY) in SMB2_auth_kerberos()
1333 msg = spnego_key->payload.data[0]; in SMB2_auth_kerberos()
1338 if (msg->version != CIFS_SPNEGO_UPCALL_VERSION) { in SMB2_auth_kerberos()
1340 CIFS_SPNEGO_UPCALL_VERSION, msg->version); in SMB2_auth_kerberos()
1341 rc = -EKEYREJECTED; in SMB2_auth_kerberos()
1346 if (!ses->binding) { in SMB2_auth_kerberos()
1347 ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len, in SMB2_auth_kerberos()
1349 if (!ses->auth_key.response) { in SMB2_auth_kerberos()
1351 msg->sesskey_len); in SMB2_auth_kerberos()
1352 rc = -ENOMEM; in SMB2_auth_kerberos()
1355 ses->auth_key.len = msg->sesskey_len; in SMB2_auth_kerberos()
1358 sess_data->iov[1].iov_base = msg->data + msg->sesskey_len; in SMB2_auth_kerberos()
1359 sess_data->iov[1].iov_len = msg->secblob_len; in SMB2_auth_kerberos()
1365 rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base; in SMB2_auth_kerberos()
1367 if (!ses->binding) { in SMB2_auth_kerberos()
1368 ses->Suid = rsp->sync_hdr.SessionId; in SMB2_auth_kerberos()
1369 ses->session_flags = le16_to_cpu(rsp->SessionFlags); in SMB2_auth_kerberos()
1377 sess_data->result = rc; in SMB2_auth_kerberos()
1378 sess_data->func = NULL; in SMB2_auth_kerberos()
1386 sess_data->result = -EOPNOTSUPP; in SMB2_auth_kerberos()
1387 sess_data->func = NULL; in SMB2_auth_kerberos()
1398 struct cifs_ses *ses = sess_data->ses; in SMB2_sess_auth_rawntlmssp_negotiate()
1408 ses->ntlmssp = kmalloc(sizeof(struct ntlmssp_auth), GFP_KERNEL); in SMB2_sess_auth_rawntlmssp_negotiate()
1409 if (!ses->ntlmssp) { in SMB2_sess_auth_rawntlmssp_negotiate()
1410 rc = -ENOMEM; in SMB2_sess_auth_rawntlmssp_negotiate()
1413 ses->ntlmssp->sesskey_per_smbsess = true; in SMB2_sess_auth_rawntlmssp_negotiate()
1422 rc = -ENOMEM; in SMB2_sess_auth_rawntlmssp_negotiate()
1430 rc = -EOPNOTSUPP; in SMB2_sess_auth_rawntlmssp_negotiate()
1436 sess_data->iov[1].iov_base = ntlmssp_blob; in SMB2_sess_auth_rawntlmssp_negotiate()
1437 sess_data->iov[1].iov_len = blob_length; in SMB2_sess_auth_rawntlmssp_negotiate()
1440 rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base; in SMB2_sess_auth_rawntlmssp_negotiate()
1443 if (sess_data->buf0_type != CIFS_NO_BUFFER && in SMB2_sess_auth_rawntlmssp_negotiate()
1444 rsp->sync_hdr.Status == STATUS_MORE_PROCESSING_REQUIRED) in SMB2_sess_auth_rawntlmssp_negotiate()
1451 le16_to_cpu(rsp->SecurityBufferOffset)) { in SMB2_sess_auth_rawntlmssp_negotiate()
1453 le16_to_cpu(rsp->SecurityBufferOffset)); in SMB2_sess_auth_rawntlmssp_negotiate()
1454 rc = -EIO; in SMB2_sess_auth_rawntlmssp_negotiate()
1457 rc = decode_ntlmssp_challenge(rsp->Buffer, in SMB2_sess_auth_rawntlmssp_negotiate()
1458 le16_to_cpu(rsp->SecurityBufferLength), ses); in SMB2_sess_auth_rawntlmssp_negotiate()
1465 if (!ses->binding) { in SMB2_sess_auth_rawntlmssp_negotiate()
1466 ses->Suid = rsp->sync_hdr.SessionId; in SMB2_sess_auth_rawntlmssp_negotiate()
1467 ses->session_flags = le16_to_cpu(rsp->SessionFlags); in SMB2_sess_auth_rawntlmssp_negotiate()
1474 sess_data->result = 0; in SMB2_sess_auth_rawntlmssp_negotiate()
1475 sess_data->func = SMB2_sess_auth_rawntlmssp_authenticate; in SMB2_sess_auth_rawntlmssp_negotiate()
1479 kfree(ses->ntlmssp); in SMB2_sess_auth_rawntlmssp_negotiate()
1480 ses->ntlmssp = NULL; in SMB2_sess_auth_rawntlmssp_negotiate()
1481 sess_data->result = rc; in SMB2_sess_auth_rawntlmssp_negotiate()
1482 sess_data->func = NULL; in SMB2_sess_auth_rawntlmssp_negotiate()
1489 struct cifs_ses *ses = sess_data->ses; in SMB2_sess_auth_rawntlmssp_authenticate()
1500 req = (struct smb2_sess_setup_req *) sess_data->iov[0].iov_base; in SMB2_sess_auth_rawntlmssp_authenticate()
1501 req->sync_hdr.SessionId = ses->Suid; in SMB2_sess_auth_rawntlmssp_authenticate()
1504 sess_data->nls_cp); in SMB2_sess_auth_rawntlmssp_authenticate()
1513 rc = -EOPNOTSUPP; in SMB2_sess_auth_rawntlmssp_authenticate()
1516 sess_data->iov[1].iov_base = ntlmssp_blob; in SMB2_sess_auth_rawntlmssp_authenticate()
1517 sess_data->iov[1].iov_len = blob_length; in SMB2_sess_auth_rawntlmssp_authenticate()
1523 rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base; in SMB2_sess_auth_rawntlmssp_authenticate()
1526 if (!ses->binding) { in SMB2_sess_auth_rawntlmssp_authenticate()
1527 ses->Suid = rsp->sync_hdr.SessionId; in SMB2_sess_auth_rawntlmssp_authenticate()
1528 ses->session_flags = le16_to_cpu(rsp->SessionFlags); in SMB2_sess_auth_rawntlmssp_authenticate()
1533 if (ses->server->dialect < SMB30_PROT_ID) { in SMB2_sess_auth_rawntlmssp_authenticate()
1539 cifs_dbg(VFS, "Session Id %*ph\n", (int)sizeof(ses->Suid), in SMB2_sess_auth_rawntlmssp_authenticate()
1540 &ses->Suid); in SMB2_sess_auth_rawntlmssp_authenticate()
1542 SMB2_NTLMV2_SESSKEY_SIZE, ses->auth_key.response); in SMB2_sess_auth_rawntlmssp_authenticate()
1544 SMB3_SIGN_KEY_SIZE, ses->auth_key.response); in SMB2_sess_auth_rawntlmssp_authenticate()
1550 kfree(ses->ntlmssp); in SMB2_sess_auth_rawntlmssp_authenticate()
1551 ses->ntlmssp = NULL; in SMB2_sess_auth_rawntlmssp_authenticate()
1552 sess_data->result = rc; in SMB2_sess_auth_rawntlmssp_authenticate()
1553 sess_data->func = NULL; in SMB2_sess_auth_rawntlmssp_authenticate()
1561 type = smb2_select_sectype(cifs_ses_server(ses), ses->sectype); in SMB2_select_sec()
1565 return -EINVAL; in SMB2_select_sec()
1570 sess_data->func = SMB2_auth_kerberos; in SMB2_select_sec()
1573 sess_data->func = SMB2_sess_auth_rawntlmssp_negotiate; in SMB2_select_sec()
1577 return -EOPNOTSUPP; in SMB2_select_sec()
1595 return -EIO; in SMB2_sess_setup()
1600 return -ENOMEM; in SMB2_sess_setup()
1605 sess_data->xid = xid; in SMB2_sess_setup()
1606 sess_data->ses = ses; in SMB2_sess_setup()
1607 sess_data->buf0_type = CIFS_NO_BUFFER; in SMB2_sess_setup()
1608 sess_data->nls_cp = (struct nls_table *) nls_cp; in SMB2_sess_setup()
1609 sess_data->previous_session = ses->Suid; in SMB2_sess_setup()
1614 memcpy(ses->preauth_sha_hash, server->preauth_sha_hash, in SMB2_sess_setup()
1617 while (sess_data->func) in SMB2_sess_setup()
1618 sess_data->func(sess_data); in SMB2_sess_setup()
1620 if ((ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST) && (ses->sign)) in SMB2_sess_setup()
1622 rc = sess_data->result; in SMB2_sess_setup()
1643 if (ses && (ses->server)) in SMB2_logoff()
1644 server = ses->server; in SMB2_logoff()
1646 return -EIO; in SMB2_logoff()
1649 if (ses->need_reconnect) in SMB2_logoff()
1652 rc = smb2_plain_req_init(SMB2_LOGOFF, NULL, ses->server, in SMB2_logoff()
1657 /* since no tcon, smb2_init can not do this, so do here */ in SMB2_logoff()
1658 req->sync_hdr.SessionId = ses->Suid; in SMB2_logoff()
1660 if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) in SMB2_logoff()
1662 else if (server->sign) in SMB2_logoff()
1663 req->sync_hdr.Flags |= SMB2_FLAGS_SIGNED; in SMB2_logoff()
1674 rc = cifs_send_recv(xid, ses, ses->server, in SMB2_logoff()
1678 * No tcon so can't do in SMB2_logoff()
1679 * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]); in SMB2_logoff()
1686 static inline void cifs_stats_fail_inc(struct cifs_tcon *tcon, uint16_t code) in cifs_stats_fail_inc() argument
1688 cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_failed[code]); in cifs_stats_fail_inc()
1694 static inline void init_copy_chunk_defaults(struct cifs_tcon *tcon) in init_copy_chunk_defaults() argument
1696 tcon->max_chunks = 256; in init_copy_chunk_defaults()
1697 tcon->max_bytes_chunk = 1048576; in init_copy_chunk_defaults()
1698 tcon->max_bytes_copy = 16777216; in init_copy_chunk_defaults()
1703 struct cifs_tcon *tcon, const struct nls_table *cp) in SMB2_tcon() argument
1718 /* always use master channel */ in SMB2_tcon()
1719 server = ses->server; in SMB2_tcon()
1721 cifs_dbg(FYI, "TCON\n"); in SMB2_tcon()
1724 return -EIO; in SMB2_tcon()
1728 return -ENOMEM; in SMB2_tcon()
1734 return -EINVAL; in SMB2_tcon()
1738 tcon->tid = 0; in SMB2_tcon()
1739 atomic_set(&tcon->num_remote_opens, 0); in SMB2_tcon()
1740 rc = smb2_plain_req_init(SMB2_TREE_CONNECT, tcon, server, in SMB2_tcon()
1747 if (smb3_encryption_required(tcon)) in SMB2_tcon()
1752 iov[0].iov_len = total_len - 1; in SMB2_tcon()
1755 req->PathOffset = cpu_to_le16(sizeof(struct smb2_tree_connect_req) in SMB2_tcon()
1756 - 1 /* pad */); in SMB2_tcon()
1757 req->PathLength = cpu_to_le16(unc_path_len - 2); in SMB2_tcon()
1762 * 3.11 tcon req must be signed if not encrypted. See MS-SMB2 3.2.4.1.1 in SMB2_tcon()
1763 * unless it is guest or anonymous user. See MS-SMB2 3.2.5.3.1 in SMB2_tcon()
1766 if ((server->dialect == SMB311_PROT_ID) && in SMB2_tcon()
1767 !smb3_encryption_required(tcon) && in SMB2_tcon()
1768 !(ses->session_flags & in SMB2_tcon()
1770 ((ses->user_name != NULL) || (ses->sectype == Kerberos))) in SMB2_tcon()
1771 req->sync_hdr.Flags |= SMB2_FLAGS_SIGNED; in SMB2_tcon()
1778 req->sync_hdr.CreditRequest = cpu_to_le16(64); in SMB2_tcon()
1784 trace_smb3_tcon(xid, tcon->tid, ses->Suid, tree, rc); in SMB2_tcon()
1786 if (tcon) { in SMB2_tcon()
1787 cifs_stats_fail_inc(tcon, SMB2_TREE_CONNECT_HE); in SMB2_tcon()
1788 tcon->need_reconnect = true; in SMB2_tcon()
1793 switch (rsp->ShareType) { in SMB2_tcon()
1798 tcon->pipe = true; in SMB2_tcon()
1802 tcon->print = true; in SMB2_tcon()
1806 cifs_server_dbg(VFS, "unknown share type %d\n", rsp->ShareType); in SMB2_tcon()
1807 rc = -EOPNOTSUPP; in SMB2_tcon()
1811 tcon->share_flags = le32_to_cpu(rsp->ShareFlags); in SMB2_tcon()
1812 tcon->capabilities = rsp->Capabilities; /* we keep caps little endian */ in SMB2_tcon()
1813 tcon->maximal_access = le32_to_cpu(rsp->MaximalAccess); in SMB2_tcon()
1814 tcon->tidStatus = CifsGood; in SMB2_tcon()
1815 tcon->need_reconnect = false; in SMB2_tcon()
1816 tcon->tid = rsp->sync_hdr.TreeId; in SMB2_tcon()
1817 strlcpy(tcon->treeName, tree, sizeof(tcon->treeName)); in SMB2_tcon()
1819 if ((rsp->Capabilities & SMB2_SHARE_CAP_DFS) && in SMB2_tcon()
1820 ((tcon->share_flags & SHI1005_FLAGS_DFS) == 0)) in SMB2_tcon()
1823 if (tcon->seal && in SMB2_tcon()
1824 !(server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION)) in SMB2_tcon()
1827 init_copy_chunk_defaults(tcon); in SMB2_tcon()
1828 if (server->ops->validate_negotiate) in SMB2_tcon()
1829 rc = server->ops->validate_negotiate(xid, tcon); in SMB2_tcon()
1837 if (rsp && rsp->sync_hdr.Status == STATUS_BAD_NETWORK_NAME) { in SMB2_tcon()
1844 SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon) in SMB2_tdis() argument
1849 struct cifs_ses *ses = tcon->ses; in SMB2_tdis()
1858 if (!ses || !(ses->server)) in SMB2_tdis()
1859 return -EIO; in SMB2_tdis()
1861 if ((tcon->need_reconnect) || (tcon->ses->need_reconnect)) in SMB2_tdis()
1864 close_shroot_lease(&tcon->crfid); in SMB2_tdis()
1866 rc = smb2_plain_req_init(SMB2_TREE_DISCONNECT, tcon, ses->server, in SMB2_tdis()
1872 if (smb3_encryption_required(tcon)) in SMB2_tdis()
1884 rc = cifs_send_recv(xid, ses, ses->server, in SMB2_tdis()
1888 cifs_stats_fail_inc(tcon, SMB2_TREE_DISCONNECT_HE); in SMB2_tdis()
1903 buf->ccontext.DataOffset = cpu_to_le16(offsetof in create_durable_buf()
1905 buf->ccontext.DataLength = cpu_to_le32(16); in create_durable_buf()
1906 buf->ccontext.NameOffset = cpu_to_le16(offsetof in create_durable_buf()
1908 buf->ccontext.NameLength = cpu_to_le16(4); in create_durable_buf()
1910 buf->Name[0] = 'D'; in create_durable_buf()
1911 buf->Name[1] = 'H'; in create_durable_buf()
1912 buf->Name[2] = 'n'; in create_durable_buf()
1913 buf->Name[3] = 'Q'; in create_durable_buf()
1926 buf->ccontext.DataOffset = cpu_to_le16(offsetof in create_reconnect_durable_buf()
1928 buf->ccontext.DataLength = cpu_to_le32(16); in create_reconnect_durable_buf()
1929 buf->ccontext.NameOffset = cpu_to_le16(offsetof in create_reconnect_durable_buf()
1931 buf->ccontext.NameLength = cpu_to_le16(4); in create_reconnect_durable_buf()
1932 buf->Data.Fid.PersistentFileId = fid->persistent_fid; in create_reconnect_durable_buf()
1933 buf->Data.Fid.VolatileFileId = fid->volatile_fid; in create_reconnect_durable_buf()
1935 buf->Name[0] = 'D'; in create_reconnect_durable_buf()
1936 buf->Name[1] = 'H'; in create_reconnect_durable_buf()
1937 buf->Name[2] = 'n'; in create_reconnect_durable_buf()
1938 buf->Name[3] = 'C'; in create_reconnect_durable_buf()
1948 pdisk_id->DiskFileId, pdisk_id->VolumeId); in parse_query_id_ctxt()
1949 buf->IndexNumber = pdisk_id->DiskFileId; in parse_query_id_ctxt()
1957 u8 *beg = (u8 *)cc + le16_to_cpu(cc->DataOffset); in parse_posix_ctxt()
1958 u8 *end = beg + le32_to_cpu(cc->DataLength); in parse_posix_ctxt()
1963 posix->nlink = le32_to_cpu(*(__le32 *)(beg + 0)); in parse_posix_ctxt()
1964 posix->reparse_tag = le32_to_cpu(*(__le32 *)(beg + 4)); in parse_posix_ctxt()
1965 posix->mode = le32_to_cpu(*(__le32 *)(beg + 8)); in parse_posix_ctxt()
1973 memcpy(&posix->owner, sid, sid_len); in parse_posix_ctxt()
1981 memcpy(&posix->group, sid, sid_len); in parse_posix_ctxt()
1984 posix->nlink, posix->mode, posix->reparse_tag); in parse_posix_ctxt()
2006 data_offset = (char *)rsp + le32_to_cpu(rsp->CreateContextsOffset); in smb2_parse_contexts()
2007 remaining = le32_to_cpu(rsp->CreateContextsLength); in smb2_parse_contexts()
2012 buf->IndexNumber = 0; in smb2_parse_contexts()
2015 name = le16_to_cpu(cc->NameOffset) + (char *)cc; in smb2_parse_contexts()
2016 if (le16_to_cpu(cc->NameLength) == 4 && in smb2_parse_contexts()
2018 *oplock = server->ops->parse_lease_buf(cc, epoch, in smb2_parse_contexts()
2020 else if (buf && (le16_to_cpu(cc->NameLength) == 4) && in smb2_parse_contexts()
2023 else if ((le16_to_cpu(cc->NameLength) == 16)) { in smb2_parse_contexts()
2030 le16_to_cpu(cc->NameLength)); in smb2_parse_contexts()
2034 next = le32_to_cpu(cc->Next); in smb2_parse_contexts()
2037 remaining -= next; in smb2_parse_contexts()
2041 if (rsp->OplockLevel != SMB2_OPLOCK_LEVEL_LEASE) in smb2_parse_contexts()
2042 *oplock = rsp->OplockLevel; in smb2_parse_contexts()
2054 iov[num].iov_base = server->ops->create_lease_buf(lease_key, *oplock); in add_lease_context()
2056 return -ENOMEM; in add_lease_context()
2057 iov[num].iov_len = server->vals->create_lease_size; in add_lease_context()
2058 req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_LEASE; in add_lease_context()
2059 if (!req->CreateContextsOffset) in add_lease_context()
2060 req->CreateContextsOffset = cpu_to_le32( in add_lease_context()
2062 iov[num - 1].iov_len); in add_lease_context()
2063 le32_add_cpu(&req->CreateContextsLength, in add_lease_context()
2064 server->vals->create_lease_size); in add_lease_context()
2072 struct cifs_fid *pfid = oparms->fid; in create_durable_v2_buf()
2079 buf->ccontext.DataOffset = cpu_to_le16(offsetof in create_durable_v2_buf()
2081 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct durable_context_v2)); in create_durable_v2_buf()
2082 buf->ccontext.NameOffset = cpu_to_le16(offsetof in create_durable_v2_buf()
2084 buf->ccontext.NameLength = cpu_to_le16(4); in create_durable_v2_buf()
2093 buf->dcontext.Timeout = cpu_to_le32(oparms->tcon->handle_timeout); in create_durable_v2_buf()
2094 buf->dcontext.Flags = cpu_to_le32(SMB2_DHANDLE_FLAG_PERSISTENT); in create_durable_v2_buf()
2095 generate_random_uuid(buf->dcontext.CreateGuid); in create_durable_v2_buf()
2096 memcpy(pfid->create_guid, buf->dcontext.CreateGuid, 16); in create_durable_v2_buf()
2099 buf->Name[0] = 'D'; in create_durable_v2_buf()
2100 buf->Name[1] = 'H'; in create_durable_v2_buf()
2101 buf->Name[2] = '2'; in create_durable_v2_buf()
2102 buf->Name[3] = 'Q'; in create_durable_v2_buf()
2116 buf->ccontext.DataOffset = in create_reconnect_durable_v2_buf()
2119 buf->ccontext.DataLength = in create_reconnect_durable_v2_buf()
2121 buf->ccontext.NameOffset = in create_reconnect_durable_v2_buf()
2124 buf->ccontext.NameLength = cpu_to_le16(4); in create_reconnect_durable_v2_buf()
2126 buf->dcontext.Fid.PersistentFileId = fid->persistent_fid; in create_reconnect_durable_v2_buf()
2127 buf->dcontext.Fid.VolatileFileId = fid->volatile_fid; in create_reconnect_durable_v2_buf()
2128 buf->dcontext.Flags = cpu_to_le32(SMB2_DHANDLE_FLAG_PERSISTENT); in create_reconnect_durable_v2_buf()
2129 memcpy(buf->dcontext.CreateGuid, fid->create_guid, 16); in create_reconnect_durable_v2_buf()
2132 buf->Name[0] = 'D'; in create_reconnect_durable_v2_buf()
2133 buf->Name[1] = 'H'; in create_reconnect_durable_v2_buf()
2134 buf->Name[2] = '2'; in create_reconnect_durable_v2_buf()
2135 buf->Name[3] = 'C'; in create_reconnect_durable_v2_buf()
2148 return -ENOMEM; in add_durable_v2_context()
2150 if (!req->CreateContextsOffset) in add_durable_v2_context()
2151 req->CreateContextsOffset = in add_durable_v2_context()
2154 le32_add_cpu(&req->CreateContextsLength, sizeof(struct create_durable_v2)); in add_durable_v2_context()
2167 oparms->reconnect = false; in add_durable_reconnect_v2_context()
2169 iov[num].iov_base = create_reconnect_durable_v2_buf(oparms->fid); in add_durable_reconnect_v2_context()
2171 return -ENOMEM; in add_durable_reconnect_v2_context()
2173 if (!req->CreateContextsOffset) in add_durable_reconnect_v2_context()
2174 req->CreateContextsOffset = in add_durable_reconnect_v2_context()
2177 le32_add_cpu(&req->CreateContextsLength, in add_durable_reconnect_v2_context()
2191 if (oparms->reconnect) in add_durable_context()
2198 if (oparms->reconnect) { in add_durable_context()
2199 iov[num].iov_base = create_reconnect_durable_buf(oparms->fid); in add_durable_context()
2201 oparms->reconnect = false; in add_durable_context()
2205 return -ENOMEM; in add_durable_context()
2207 if (!req->CreateContextsOffset) in add_durable_context()
2208 req->CreateContextsOffset = in add_durable_context()
2211 le32_add_cpu(&req->CreateContextsLength, sizeof(struct create_durable)); in add_durable_context()
2216 /* See MS-SMB2 2.2.13.2.7 */
2226 buf->ccontext.DataOffset = cpu_to_le16(offsetof in create_twarp_buf()
2228 buf->ccontext.DataLength = cpu_to_le32(8); in create_twarp_buf()
2229 buf->ccontext.NameOffset = cpu_to_le16(offsetof in create_twarp_buf()
2231 buf->ccontext.NameLength = cpu_to_le16(4); in create_twarp_buf()
2233 buf->Name[0] = 'T'; in create_twarp_buf()
2234 buf->Name[1] = 'W'; in create_twarp_buf()
2235 buf->Name[2] = 'r'; in create_twarp_buf()
2236 buf->Name[3] = 'p'; in create_twarp_buf()
2237 buf->Timestamp = cpu_to_le64(timewarp); in create_twarp_buf()
2241 /* See MS-SMB2 2.2.13.2.7 */
2250 return -ENOMEM; in add_twarp_context()
2252 if (!req->CreateContextsOffset) in add_twarp_context()
2253 req->CreateContextsOffset = cpu_to_le32( in add_twarp_context()
2255 iov[num - 1].iov_len); in add_twarp_context()
2256 le32_add_cpu(&req->CreateContextsLength, sizeof(struct crt_twarp_ctxt)); in add_twarp_context()
2261 /* See See http://technet.microsoft.com/en-us/library/hh509017(v=ws.10).aspx */
2266 /* Populate the user ownership fields S-1-5-88-1 */ in setup_owner_group_sids()
2267 sids->owner.Revision = 1; in setup_owner_group_sids()
2268 sids->owner.NumAuth = 3; in setup_owner_group_sids()
2269 sids->owner.Authority[5] = 5; in setup_owner_group_sids()
2270 sids->owner.SubAuthorities[0] = cpu_to_le32(88); in setup_owner_group_sids()
2271 sids->owner.SubAuthorities[1] = cpu_to_le32(1); in setup_owner_group_sids()
2272 sids->owner.SubAuthorities[2] = cpu_to_le32(current_fsuid().val); in setup_owner_group_sids()
2274 /* Populate the group ownership fields S-1-5-88-2 */ in setup_owner_group_sids()
2275 sids->group.Revision = 1; in setup_owner_group_sids()
2276 sids->group.NumAuth = 3; in setup_owner_group_sids()
2277 sids->group.Authority[5] = 5; in setup_owner_group_sids()
2278 sids->group.SubAuthorities[0] = cpu_to_le32(88); in setup_owner_group_sids()
2279 sids->group.SubAuthorities[1] = cpu_to_le32(2); in setup_owner_group_sids()
2280 sids->group.SubAuthorities[2] = cpu_to_le32(current_fsgid().val); in setup_owner_group_sids()
2282 …cifs_dbg(FYI, "owner S-1-5-88-1-%d, group S-1-5-88-2-%d\n", current_fsuid().val, current_fsgid().v… in setup_owner_group_sids()
2285 /* See MS-SMB2 2.2.13.2.2 and MS-DTYP 2.4.6 */
2310 owner_offset = ptr - (__u8 *)&buf->sd; in create_sd_buf()
2311 buf->sd.OffsetOwner = cpu_to_le32(owner_offset); in create_sd_buf()
2313 buf->sd.OffsetGroup = cpu_to_le32(group_offset); in create_sd_buf()
2318 buf->sd.OffsetOwner = 0; in create_sd_buf()
2319 buf->sd.OffsetGroup = 0; in create_sd_buf()
2322 buf->ccontext.DataOffset = cpu_to_le16(offsetof(struct crt_sd_ctxt, sd)); in create_sd_buf()
2323 buf->ccontext.NameOffset = cpu_to_le16(offsetof(struct crt_sd_ctxt, Name)); in create_sd_buf()
2324 buf->ccontext.NameLength = cpu_to_le16(4); in create_sd_buf()
2326 buf->Name[0] = 'S'; in create_sd_buf()
2327 buf->Name[1] = 'e'; in create_sd_buf()
2328 buf->Name[2] = 'c'; in create_sd_buf()
2329 buf->Name[3] = 'D'; in create_sd_buf()
2330 buf->sd.Revision = 1; /* Must be one see MS-DTYP 2.4.6 */ in create_sd_buf()
2336 buf->sd.Control = cpu_to_le16(ACL_CONTROL_SR | ACL_CONTROL_DP); in create_sd_buf()
2339 buf->sd.OffsetDacl = cpu_to_le32(ptr - (__u8 *)&buf->sd); in create_sd_buf()
2364 acl.AclRevision = ACL_REVISION; /* See 2.4.4.1 of MS-DTYP */ in create_sd_buf()
2369 buf->ccontext.DataLength = cpu_to_le32(ptr - (__u8 *)&buf->sd); in create_sd_buf()
2370 *len = roundup(ptr - (__u8 *)buf, 8); in create_sd_buf()
2384 return -ENOMEM; in add_sd_context()
2386 if (!req->CreateContextsOffset) in add_sd_context()
2387 req->CreateContextsOffset = cpu_to_le32( in add_sd_context()
2389 iov[num - 1].iov_len); in add_sd_context()
2390 le32_add_cpu(&req->CreateContextsLength, len); in add_sd_context()
2404 buf->ccontext.DataOffset = cpu_to_le16(0); in create_query_id_buf()
2405 buf->ccontext.DataLength = cpu_to_le32(0); in create_query_id_buf()
2406 buf->ccontext.NameOffset = cpu_to_le16(offsetof in create_query_id_buf()
2408 buf->ccontext.NameLength = cpu_to_le16(4); in create_query_id_buf()
2410 buf->Name[0] = 'Q'; in create_query_id_buf()
2411 buf->Name[1] = 'F'; in create_query_id_buf()
2412 buf->Name[2] = 'i'; in create_query_id_buf()
2413 buf->Name[3] = 'd'; in create_query_id_buf()
2417 /* See MS-SMB2 2.2.13.2.9 */
2426 return -ENOMEM; in add_query_id_context()
2428 if (!req->CreateContextsOffset) in add_query_id_context()
2429 req->CreateContextsOffset = cpu_to_le32( in add_query_id_context()
2431 iov[num - 1].iov_len); in add_query_id_context()
2432 le32_add_cpu(&req->CreateContextsLength, sizeof(struct crt_query_id_ctxt)); in add_query_id_context()
2450 return -EINVAL; in alloc_path_with_tree_prefix()
2453 treename_len -= 2; in alloc_path_with_tree_prefix()
2464 * final path needs to be null-terminated UTF16 with a in alloc_path_with_tree_prefix()
2471 return -ENOMEM; in alloc_path_with_tree_prefix()
2483 umode_t mode, struct cifs_tcon *tcon, in smb311_posix_mkdir() argument
2490 struct cifs_ses *ses = tcon->ses; in smb311_posix_mkdir()
2511 return -ENOMEM; in smb311_posix_mkdir()
2514 rc = -EIO; in smb311_posix_mkdir()
2519 rc = smb2_plain_req_init(SMB2_CREATE, tcon, server, in smb311_posix_mkdir()
2525 if (smb3_encryption_required(tcon)) in smb311_posix_mkdir()
2528 req->ImpersonationLevel = IL_IMPERSONATION; in smb311_posix_mkdir()
2529 req->DesiredAccess = cpu_to_le32(FILE_WRITE_ATTRIBUTES); in smb311_posix_mkdir()
2531 req->FileAttributes = cpu_to_le32(file_attributes); in smb311_posix_mkdir()
2532 req->ShareAccess = FILE_SHARE_ALL_LE; in smb311_posix_mkdir()
2533 req->CreateDisposition = cpu_to_le32(FILE_CREATE); in smb311_posix_mkdir()
2534 req->CreateOptions = cpu_to_le32(CREATE_NOT_FILE); in smb311_posix_mkdir()
2537 /* -1 since last byte is buf[0] which is sent below (path) */ in smb311_posix_mkdir()
2538 iov[0].iov_len = total_len - 1; in smb311_posix_mkdir()
2540 req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req)); in smb311_posix_mkdir()
2542 /* [MS-SMB2] 2.2.13 NameOffset: in smb311_posix_mkdir()
2550 if (tcon->share_flags & SHI1005_FLAGS_DFS) { in smb311_posix_mkdir()
2553 req->sync_hdr.Flags |= SMB2_FLAGS_DFS_OPERATIONS; in smb311_posix_mkdir()
2556 tcon->treeName, utf16_path); in smb311_posix_mkdir()
2560 req->NameLength = cpu_to_le16(name_len * 2); in smb311_posix_mkdir()
2568 req->NameLength = cpu_to_le16(uni_path_len - 2); in smb311_posix_mkdir()
2573 rc = -ENOMEM; in smb311_posix_mkdir()
2587 req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_NONE; in smb311_posix_mkdir()
2589 if (tcon->posix_extensions) { in smb311_posix_mkdir()
2594 pc_buf = iov[n_iov-1].iov_base; in smb311_posix_mkdir()
2603 trace_smb3_posix_mkdir_enter(xid, tcon->tid, ses->Suid, CREATE_NOT_FILE, in smb311_posix_mkdir()
2609 cifs_stats_fail_inc(tcon, SMB2_CREATE_HE); in smb311_posix_mkdir()
2610 trace_smb3_posix_mkdir_err(xid, tcon->tid, ses->Suid, in smb311_posix_mkdir()
2617 trace_smb3_posix_mkdir_done(xid, rsp->PersistentFileId, tcon->tid, in smb311_posix_mkdir()
2618 ses->Suid, CREATE_NOT_FILE, in smb311_posix_mkdir()
2621 SMB2_close(xid, tcon, rsp->PersistentFileId, rsp->VolatileFileId); in smb311_posix_mkdir()
2636 SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, in SMB2_open_init() argument
2646 struct kvec *iov = rqst->rq_iov; in SMB2_open_init()
2650 rc = smb2_plain_req_init(SMB2_CREATE, tcon, server, in SMB2_open_init()
2656 /* -1 since last byte is buf[0] which is sent below (path) */ in SMB2_open_init()
2657 iov[0].iov_len = total_len - 1; in SMB2_open_init()
2659 if (oparms->create_options & CREATE_OPTION_READONLY) in SMB2_open_init()
2661 if (oparms->create_options & CREATE_OPTION_SPECIAL) in SMB2_open_init()
2664 req->ImpersonationLevel = IL_IMPERSONATION; in SMB2_open_init()
2665 req->DesiredAccess = cpu_to_le32(oparms->desired_access); in SMB2_open_init()
2667 req->FileAttributes = cpu_to_le32(file_attributes); in SMB2_open_init()
2668 req->ShareAccess = FILE_SHARE_ALL_LE; in SMB2_open_init()
2670 req->CreateDisposition = cpu_to_le32(oparms->disposition); in SMB2_open_init()
2671 req->CreateOptions = cpu_to_le32(oparms->create_options & CREATE_OPTIONS_MASK); in SMB2_open_init()
2672 req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req)); in SMB2_open_init()
2674 /* [MS-SMB2] 2.2.13 NameOffset: in SMB2_open_init()
2682 if (tcon->share_flags & SHI1005_FLAGS_DFS) { in SMB2_open_init()
2685 req->sync_hdr.Flags |= SMB2_FLAGS_DFS_OPERATIONS; in SMB2_open_init()
2688 tcon->treeName, path); in SMB2_open_init()
2691 req->NameLength = cpu_to_le16(name_len * 2); in SMB2_open_init()
2697 req->NameLength = cpu_to_le16(uni_path_len - 2); in SMB2_open_init()
2703 return -ENOMEM; in SMB2_open_init()
2713 if ((!server->oplocks) || (tcon->no_lease)) in SMB2_open_init()
2716 if (!(server->capabilities & SMB2_GLOBAL_CAP_LEASING) || in SMB2_open_init()
2718 req->RequestedOplockLevel = *oplock; in SMB2_open_init()
2719 else if (!(server->capabilities & SMB2_GLOBAL_CAP_DIRECTORY_LEASING) && in SMB2_open_init()
2720 (oparms->create_options & CREATE_NOT_FILE)) in SMB2_open_init()
2721 req->RequestedOplockLevel = *oplock; /* no srv lease support */ in SMB2_open_init()
2724 oparms->fid->lease_key, oplock); in SMB2_open_init()
2731 if (server->capabilities & SMB2_GLOBAL_CAP_LEASING) { in SMB2_open_init()
2733 (struct create_context *)iov[n_iov-1].iov_base; in SMB2_open_init()
2734 ccontext->Next = in SMB2_open_init()
2735 cpu_to_le32(server->vals->create_lease_size); in SMB2_open_init()
2739 tcon->use_persistent); in SMB2_open_init()
2744 if (tcon->posix_extensions) { in SMB2_open_init()
2747 (struct create_context *)iov[n_iov-1].iov_base; in SMB2_open_init()
2748 ccontext->Next = in SMB2_open_init()
2749 cpu_to_le32(iov[n_iov-1].iov_len); in SMB2_open_init()
2752 rc = add_posix_context(iov, &n_iov, oparms->mode); in SMB2_open_init()
2757 if (tcon->snapshot_time) { in SMB2_open_init()
2761 (struct create_context *)iov[n_iov-1].iov_base; in SMB2_open_init()
2762 ccontext->Next = in SMB2_open_init()
2763 cpu_to_le32(iov[n_iov-1].iov_len); in SMB2_open_init()
2766 rc = add_twarp_context(iov, &n_iov, tcon->snapshot_time); in SMB2_open_init()
2771 if ((oparms->disposition != FILE_OPEN) && (oparms->cifs_sb)) { in SMB2_open_init()
2775 if ((oparms->cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MODE_FROM_SID) && in SMB2_open_init()
2776 (oparms->mode != ACL_NO_MODE)) in SMB2_open_init()
2780 oparms->mode = ACL_NO_MODE; in SMB2_open_init()
2783 if (oparms->cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UID_FROM_ACL) in SMB2_open_init()
2791 (struct create_context *)iov[n_iov-1].iov_base; in SMB2_open_init()
2792 ccontext->Next = cpu_to_le32(iov[n_iov-1].iov_len); in SMB2_open_init()
2795 cifs_dbg(FYI, "add sd with mode 0x%x\n", oparms->mode); in SMB2_open_init()
2796 rc = add_sd_context(iov, &n_iov, oparms->mode, set_owner); in SMB2_open_init()
2804 (struct create_context *)iov[n_iov-1].iov_base; in SMB2_open_init()
2805 ccontext->Next = cpu_to_le32(iov[n_iov-1].iov_len); in SMB2_open_init()
2809 rqst->rq_nvec = n_iov; in SMB2_open_init()
2821 if (rqst && rqst->rq_iov) { in SMB2_open_free()
2822 cifs_small_buf_release(rqst->rq_iov[0].iov_base); in SMB2_open_free()
2823 for (i = 1; i < rqst->rq_nvec; i++) in SMB2_open_free()
2824 if (rqst->rq_iov[i].iov_base != smb2_padding) in SMB2_open_free()
2825 kfree(rqst->rq_iov[i].iov_base); in SMB2_open_free()
2837 struct cifs_tcon *tcon = oparms->tcon; in SMB2_open() local
2838 struct cifs_ses *ses = tcon->ses; in SMB2_open()
2848 return -EIO; in SMB2_open()
2850 if (smb3_encryption_required(tcon)) in SMB2_open()
2858 rc = SMB2_open_init(tcon, server, in SMB2_open()
2863 trace_smb3_open_enter(xid, tcon->tid, tcon->ses->Suid, in SMB2_open()
2864 oparms->create_options, oparms->desired_access); in SMB2_open()
2872 cifs_stats_fail_inc(tcon, SMB2_CREATE_HE); in SMB2_open()
2879 trace_smb3_open_err(xid, tcon->tid, ses->Suid, in SMB2_open()
2880 oparms->create_options, oparms->desired_access, rc); in SMB2_open()
2881 if (rc == -EREMCHG) { in SMB2_open()
2883 tcon->treeName); in SMB2_open()
2884 tcon->need_reconnect = true; in SMB2_open()
2888 trace_smb3_open_done(xid, rsp->PersistentFileId, tcon->tid, in SMB2_open()
2889 ses->Suid, oparms->create_options, in SMB2_open()
2890 oparms->desired_access); in SMB2_open()
2892 atomic_inc(&tcon->num_remote_opens); in SMB2_open()
2893 oparms->fid->persistent_fid = rsp->PersistentFileId; in SMB2_open()
2894 oparms->fid->volatile_fid = rsp->VolatileFileId; in SMB2_open()
2895 oparms->fid->access = oparms->desired_access; in SMB2_open()
2897 oparms->fid->mid = le64_to_cpu(rsp->sync_hdr.MessageId); in SMB2_open()
2901 memcpy(buf, &rsp->CreationTime, 32); in SMB2_open()
2902 buf->AllocationSize = rsp->AllocationSize; in SMB2_open()
2903 buf->EndOfFile = rsp->EndofFile; in SMB2_open()
2904 buf->Attributes = rsp->FileAttributes; in SMB2_open()
2905 buf->NumberOfLinks = cpu_to_le32(1); in SMB2_open()
2906 buf->DeletePending = 0; in SMB2_open()
2910 smb2_parse_contexts(server, rsp, &oparms->fid->epoch, in SMB2_open()
2911 oparms->fid->lease_key, oplock, buf, posix); in SMB2_open()
2919 SMB2_ioctl_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, in SMB2_ioctl_init() argument
2926 struct kvec *iov = rqst->rq_iov; in SMB2_ioctl_init()
2931 rc = smb2_ioctl_req_init(opcode, tcon, server, in SMB2_ioctl_init()
2944 return -ENOMEM; in SMB2_ioctl_init()
2948 req->CtlCode = cpu_to_le32(opcode); in SMB2_ioctl_init()
2949 req->PersistentFileId = persistent_fid; in SMB2_ioctl_init()
2950 req->VolatileFileId = volatile_fid; in SMB2_ioctl_init()
2962 req->InputCount = cpu_to_le32(indatalen); in SMB2_ioctl_init()
2964 req->InputOffset = in SMB2_ioctl_init()
2966 rqst->rq_nvec = 2; in SMB2_ioctl_init()
2967 iov[0].iov_len = total_len - 1; in SMB2_ioctl_init()
2971 rqst->rq_nvec = 1; in SMB2_ioctl_init()
2975 req->OutputOffset = 0; in SMB2_ioctl_init()
2976 req->OutputCount = 0; /* MBZ */ in SMB2_ioctl_init()
2993 req->MaxOutputResponse = cpu_to_le32(max_response_size); in SMB2_ioctl_init()
2994 req->sync_hdr.CreditCharge = in SMB2_ioctl_init()
2998 req->Flags = cpu_to_le32(SMB2_0_IOCTL_IS_FSCTL); in SMB2_ioctl_init()
3000 req->Flags = 0; in SMB2_ioctl_init()
3002 /* validate negotiate request must be signed - see MS-SMB2 3.2.5.5 */ in SMB2_ioctl_init()
3004 req->sync_hdr.Flags |= SMB2_FLAGS_SIGNED; in SMB2_ioctl_init()
3013 if (rqst && rqst->rq_iov) { in SMB2_ioctl_free()
3014 cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_ioctl_free()
3015 for (i = 1; i < rqst->rq_nvec; i++) in SMB2_ioctl_free()
3016 if (rqst->rq_iov[i].iov_base != smb2_padding) in SMB2_ioctl_free()
3017 kfree(rqst->rq_iov[i].iov_base); in SMB2_ioctl_free()
3026 SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, in SMB2_ioctl() argument
3050 if (!tcon) in SMB2_ioctl()
3051 return -EIO; in SMB2_ioctl()
3053 ses = tcon->ses; in SMB2_ioctl()
3055 return -EIO; in SMB2_ioctl()
3059 return -EIO; in SMB2_ioctl()
3061 if (smb3_encryption_required(tcon)) in SMB2_ioctl()
3069 rc = SMB2_ioctl_init(tcon, server, in SMB2_ioctl()
3081 trace_smb3_fsctl_err(xid, persistent_fid, tcon->tid, in SMB2_ioctl()
3082 ses->Suid, 0, opcode, rc); in SMB2_ioctl()
3084 if ((rc != 0) && (rc != -EINVAL) && (rc != -E2BIG)) { in SMB2_ioctl()
3085 cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE); in SMB2_ioctl()
3087 } else if (rc == -EINVAL) { in SMB2_ioctl()
3090 cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE); in SMB2_ioctl()
3093 } else if (rc == -E2BIG) { in SMB2_ioctl()
3095 cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE); in SMB2_ioctl()
3104 *plen = le32_to_cpu(rsp->OutputCount); in SMB2_ioctl()
3112 rc = -EIO; in SMB2_ioctl()
3116 if (rsp_iov.iov_len - *plen < le32_to_cpu(rsp->OutputOffset)) { in SMB2_ioctl()
3118 le32_to_cpu(rsp->OutputOffset)); in SMB2_ioctl()
3120 rc = -EIO; in SMB2_ioctl()
3124 *out_data = kmemdup((char *)rsp + le32_to_cpu(rsp->OutputOffset), in SMB2_ioctl()
3127 rc = -ENOMEM; in SMB2_ioctl()
3142 SMB2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_set_compression() argument
3152 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid, in SMB2_set_compression()
3164 SMB2_close_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, in SMB2_close_init() argument
3169 struct kvec *iov = rqst->rq_iov; in SMB2_close_init()
3173 rc = smb2_plain_req_init(SMB2_CLOSE, tcon, server, in SMB2_close_init()
3178 req->PersistentFileId = persistent_fid; in SMB2_close_init()
3179 req->VolatileFileId = volatile_fid; in SMB2_close_init()
3181 req->Flags = SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB; in SMB2_close_init()
3183 req->Flags = 0; in SMB2_close_init()
3193 if (rqst && rqst->rq_iov) in SMB2_close_free()
3194 cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_close_free()
3198 __SMB2_close(const unsigned int xid, struct cifs_tcon *tcon, in __SMB2_close() argument
3204 struct cifs_ses *ses = tcon->ses; in __SMB2_close()
3216 return -EIO; in __SMB2_close()
3218 if (smb3_encryption_required(tcon)) in __SMB2_close()
3230 trace_smb3_close_enter(xid, persistent_fid, tcon->tid, ses->Suid); in __SMB2_close()
3231 rc = SMB2_close_init(tcon, server, in __SMB2_close()
3242 cifs_stats_fail_inc(tcon, SMB2_CLOSE_HE); in __SMB2_close()
3243 trace_smb3_close_err(xid, persistent_fid, tcon->tid, ses->Suid, in __SMB2_close()
3247 trace_smb3_close_done(xid, persistent_fid, tcon->tid, in __SMB2_close()
3248 ses->Suid); in __SMB2_close()
3254 memcpy(pbuf, (char *)&rsp->CreationTime, sizeof(*pbuf) - 4); in __SMB2_close()
3257 atomic_dec(&tcon->num_remote_opens); in __SMB2_close()
3266 tmp_rc = smb2_handle_cancelled_close(tcon, persistent_fid, in __SMB2_close()
3276 SMB2_close(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_close() argument
3279 return __SMB2_close(xid, tcon, persistent_fid, volatile_fid, NULL); in SMB2_close()
3286 unsigned int smb_len = iov->iov_len; in smb2_validate_iov()
3287 char *end_of_smb = smb_len + (char *)iov->iov_base; in smb2_validate_iov()
3288 char *begin_of_buf = offset + (char *)iov->iov_base; in smb2_validate_iov()
3295 return -EINVAL; in smb2_validate_iov()
3302 return -EINVAL; in smb2_validate_iov()
3307 return -EINVAL; in smb2_validate_iov()
3322 char *begin_of_buf = offset + (char *)iov->iov_base; in smb2_validate_and_copy_iov()
3326 return -EINVAL; in smb2_validate_and_copy_iov()
3338 SMB2_query_info_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, in SMB2_query_info_init() argument
3345 struct kvec *iov = rqst->rq_iov; in SMB2_query_info_init()
3349 rc = smb2_plain_req_init(SMB2_QUERY_INFO, tcon, server, in SMB2_query_info_init()
3354 req->InfoType = info_type; in SMB2_query_info_init()
3355 req->FileInfoClass = info_class; in SMB2_query_info_init()
3356 req->PersistentFileId = persistent_fid; in SMB2_query_info_init()
3357 req->VolatileFileId = volatile_fid; in SMB2_query_info_init()
3358 req->AdditionalInformation = cpu_to_le32(additional_info); in SMB2_query_info_init()
3360 req->OutputBufferLength = cpu_to_le32(output_len); in SMB2_query_info_init()
3362 req->InputBufferLength = cpu_to_le32(input_len); in SMB2_query_info_init()
3364 req->InputBufferOffset = cpu_to_le16(total_len - 1); in SMB2_query_info_init()
3365 memcpy(req->Buffer, input, input_len); in SMB2_query_info_init()
3370 iov[0].iov_len = total_len - 1 + input_len; in SMB2_query_info_init()
3377 if (rqst && rqst->rq_iov) in SMB2_query_info_free()
3378 cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_query_info_free()
3382 query_info(const unsigned int xid, struct cifs_tcon *tcon, in query_info() argument
3393 struct cifs_ses *ses = tcon->ses; in query_info()
3401 return -EIO; in query_info()
3404 return -EIO; in query_info()
3406 if (smb3_encryption_required(tcon)) in query_info()
3414 rc = SMB2_query_info_init(tcon, server, in query_info()
3421 trace_smb3_query_info_enter(xid, persistent_fid, tcon->tid, in query_info()
3422 ses->Suid, info_class, (__u32)info_type); in query_info()
3429 cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); in query_info()
3430 trace_smb3_query_info_err(xid, persistent_fid, tcon->tid, in query_info()
3431 ses->Suid, info_class, (__u32)info_type, rc); in query_info()
3435 trace_smb3_query_info_done(xid, persistent_fid, tcon->tid, in query_info()
3436 ses->Suid, info_class, (__u32)info_type); in query_info()
3439 *dlen = le32_to_cpu(rsp->OutputBufferLength); in query_info()
3447 rc = -ENOMEM; in query_info()
3454 rc = smb2_validate_and_copy_iov(le16_to_cpu(rsp->OutputBufferOffset), in query_info()
3455 le32_to_cpu(rsp->OutputBufferLength), in query_info()
3469 int SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_query_info() argument
3472 return query_info(xid, tcon, persistent_fid, volatile_fid, in SMB2_query_info()
3480 SMB311_posix_query_info(const unsigned int xid, struct cifs_tcon *tcon, in SMB311_posix_query_info() argument
3487 return query_info(xid, tcon, persistent_fid, volatile_fid, in SMB311_posix_query_info()
3493 SMB2_query_acl(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_query_acl() argument
3500 return query_info(xid, tcon, persistent_fid, volatile_fid, in SMB2_query_acl()
3506 SMB2_get_srv_num(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_get_srv_num() argument
3509 return query_info(xid, tcon, persistent_fid, volatile_fid, in SMB2_get_srv_num()
3518 * See MS-SMB2 2.2.35 and 2.2.36
3523 struct cifs_tcon *tcon, struct TCP_Server_Info *server, in SMB2_notify_init() argument
3528 struct kvec *iov = rqst->rq_iov; in SMB2_notify_init()
3532 rc = smb2_plain_req_init(SMB2_CHANGE_NOTIFY, tcon, server, in SMB2_notify_init()
3537 req->PersistentFileId = persistent_fid; in SMB2_notify_init()
3538 req->VolatileFileId = volatile_fid; in SMB2_notify_init()
3539 /* See note 354 of MS-SMB2, 64K max */ in SMB2_notify_init()
3540 req->OutputBufferLength = in SMB2_notify_init()
3541 cpu_to_le32(SMB2_MAX_BUFFER_SIZE - MAX_SMB2_HDR_SIZE); in SMB2_notify_init()
3542 req->CompletionFilter = cpu_to_le32(completion_filter); in SMB2_notify_init()
3544 req->Flags = cpu_to_le16(SMB2_WATCH_TREE); in SMB2_notify_init()
3546 req->Flags = 0; in SMB2_notify_init()
3555 SMB2_change_notify(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_change_notify() argument
3559 struct cifs_ses *ses = tcon->ses; in SMB2_change_notify()
3570 return -EIO; in SMB2_change_notify()
3572 if (smb3_encryption_required(tcon)) in SMB2_change_notify()
3580 rc = SMB2_notify_init(xid, &rqst, tcon, server, in SMB2_change_notify()
3586 trace_smb3_notify_enter(xid, persistent_fid, tcon->tid, ses->Suid, in SMB2_change_notify()
3592 cifs_stats_fail_inc(tcon, SMB2_CHANGE_NOTIFY_HE); in SMB2_change_notify()
3593 trace_smb3_notify_err(xid, persistent_fid, tcon->tid, ses->Suid, in SMB2_change_notify()
3596 trace_smb3_notify_done(xid, persistent_fid, tcon->tid, in SMB2_change_notify()
3597 ses->Suid, (u8)watch_tree, completion_filter); in SMB2_change_notify()
3609 * This is a no-op for now. We're not really interested in the reply, but
3610 * rather in the fact that the server sent one and that server->lstrp
3618 struct TCP_Server_Info *server = mid->callback_data; in smb2_echo_callback()
3619 struct smb2_echo_rsp *rsp = (struct smb2_echo_rsp *)mid->resp_buf; in smb2_echo_callback()
3622 if (mid->mid_state == MID_RESPONSE_RECEIVED in smb2_echo_callback()
3623 || mid->mid_state == MID_RESPONSE_MALFORMED) { in smb2_echo_callback()
3624 credits.value = le16_to_cpu(rsp->sync_hdr.CreditRequest); in smb2_echo_callback()
3625 credits.instance = server->reconnect_instance; in smb2_echo_callback()
3637 struct cifs_tcon *tcon, *tcon2; in smb2_reconnect_server() local
3644 /* Prevent simultaneous reconnects that can corrupt tcon->rlist list */ in smb2_reconnect_server()
3645 mutex_lock(&server->reconnect_mutex); in smb2_reconnect_server()
3651 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { in smb2_reconnect_server()
3652 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) { in smb2_reconnect_server()
3653 if (tcon->need_reconnect || tcon->need_reopen_files) { in smb2_reconnect_server()
3654 tcon->tc_count++; in smb2_reconnect_server()
3655 list_add_tail(&tcon->rlist, &tmp_list); in smb2_reconnect_server()
3663 if (ses->tcon_ipc && ses->tcon_ipc->need_reconnect) { in smb2_reconnect_server()
3664 list_add_tail(&ses->tcon_ipc->rlist, &tmp_list); in smb2_reconnect_server()
3666 ses->ses_count++; in smb2_reconnect_server()
3674 server->srv_count++; in smb2_reconnect_server()
3678 list_for_each_entry_safe(tcon, tcon2, &tmp_list, rlist) { in smb2_reconnect_server()
3679 rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server); in smb2_reconnect_server()
3681 cifs_reopen_persistent_handles(tcon); in smb2_reconnect_server()
3684 list_del_init(&tcon->rlist); in smb2_reconnect_server()
3685 if (tcon->ipc) in smb2_reconnect_server()
3686 cifs_put_smb_ses(tcon->ses); in smb2_reconnect_server()
3688 cifs_put_tcon(tcon); in smb2_reconnect_server()
3693 queue_delayed_work(cifsiod_wq, &server->reconnect, 2 * HZ); in smb2_reconnect_server()
3694 mutex_unlock(&server->reconnect_mutex); in smb2_reconnect_server()
3713 if (server->tcpStatus == CifsNeedNegotiate) { in SMB2_echo()
3715 mod_delayed_work(cifsiod_wq, &server->reconnect, 0); in SMB2_echo()
3724 req->sync_hdr.CreditRequest = cpu_to_le16(1); in SMB2_echo()
3741 if (rqst && rqst->rq_iov) in SMB2_flush_free()
3742 cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_flush_free()
3747 struct cifs_tcon *tcon, struct TCP_Server_Info *server, in SMB2_flush_init() argument
3751 struct kvec *iov = rqst->rq_iov; in SMB2_flush_init()
3755 rc = smb2_plain_req_init(SMB2_FLUSH, tcon, server, in SMB2_flush_init()
3760 req->PersistentFileId = persistent_fid; in SMB2_flush_init()
3761 req->VolatileFileId = volatile_fid; in SMB2_flush_init()
3770 SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, in SMB2_flush() argument
3773 struct cifs_ses *ses = tcon->ses; in SMB2_flush()
3783 if (!ses || !(ses->server)) in SMB2_flush()
3784 return -EIO; in SMB2_flush()
3786 if (smb3_encryption_required(tcon)) in SMB2_flush()
3794 rc = SMB2_flush_init(xid, &rqst, tcon, server, in SMB2_flush()
3799 trace_smb3_flush_enter(xid, persistent_fid, tcon->tid, ses->Suid); in SMB2_flush()
3804 cifs_stats_fail_inc(tcon, SMB2_FLUSH_HE); in SMB2_flush()
3805 trace_smb3_flush_err(xid, persistent_fid, tcon->tid, ses->Suid, in SMB2_flush()
3808 trace_smb3_flush_done(xid, persistent_fid, tcon->tid, in SMB2_flush()
3809 ses->Suid); in SMB2_flush()
3826 int rc = -EACCES; in smb2_new_read_req()
3829 struct TCP_Server_Info *server = io_parms->server; in smb2_new_read_req()
3831 rc = smb2_plain_req_init(SMB2_READ, io_parms->tcon, server, in smb2_new_read_req()
3837 return -ECONNABORTED; in smb2_new_read_req()
3839 shdr = &req->sync_hdr; in smb2_new_read_req()
3840 shdr->ProcessId = cpu_to_le32(io_parms->pid); in smb2_new_read_req()
3842 req->PersistentFileId = io_parms->persistent_fid; in smb2_new_read_req()
3843 req->VolatileFileId = io_parms->volatile_fid; in smb2_new_read_req()
3844 req->ReadChannelInfoOffset = 0; /* reserved */ in smb2_new_read_req()
3845 req->ReadChannelInfoLength = 0; /* reserved */ in smb2_new_read_req()
3846 req->Channel = 0; /* reserved */ in smb2_new_read_req()
3847 req->MinimumCount = 0; in smb2_new_read_req()
3848 req->Length = cpu_to_le32(io_parms->length); in smb2_new_read_req()
3849 req->Offset = cpu_to_le64(io_parms->offset); in smb2_new_read_req()
3852 io_parms->persistent_fid, in smb2_new_read_req()
3853 io_parms->tcon->tid, io_parms->tcon->ses->Suid, in smb2_new_read_req()
3854 io_parms->offset, io_parms->length); in smb2_new_read_req()
3860 if (server->rdma && rdata && !server->sign && in smb2_new_read_req()
3861 rdata->bytes >= server->smbd_conn->rdma_readwrite_threshold) { in smb2_new_read_req()
3864 bool need_invalidate = server->dialect == SMB30_PROT_ID; in smb2_new_read_req()
3866 rdata->mr = smbd_register_mr( in smb2_new_read_req()
3867 server->smbd_conn, rdata->pages, in smb2_new_read_req()
3868 rdata->nr_pages, rdata->page_offset, in smb2_new_read_req()
3869 rdata->tailsz, true, need_invalidate); in smb2_new_read_req()
3870 if (!rdata->mr) in smb2_new_read_req()
3871 return -EAGAIN; in smb2_new_read_req()
3873 req->Channel = SMB2_CHANNEL_RDMA_V1_INVALIDATE; in smb2_new_read_req()
3875 req->Channel = SMB2_CHANNEL_RDMA_V1; in smb2_new_read_req()
3876 req->ReadChannelInfoOffset = in smb2_new_read_req()
3878 req->ReadChannelInfoLength = in smb2_new_read_req()
3880 v1 = (struct smbd_buffer_descriptor_v1 *) &req->Buffer[0]; in smb2_new_read_req()
3881 v1->offset = cpu_to_le64(rdata->mr->mr->iova); in smb2_new_read_req()
3882 v1->token = cpu_to_le32(rdata->mr->mr->rkey); in smb2_new_read_req()
3883 v1->length = cpu_to_le32(rdata->mr->mr->length); in smb2_new_read_req()
3885 *total_len += sizeof(*v1) - 1; in smb2_new_read_req()
3890 /* next 8-byte aligned request */ in smb2_new_read_req()
3892 shdr->NextCommand = cpu_to_le32(*total_len); in smb2_new_read_req()
3894 shdr->NextCommand = 0; in smb2_new_read_req()
3896 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS; in smb2_new_read_req()
3901 shdr->SessionId = 0xFFFFFFFFFFFFFFFF; in smb2_new_read_req()
3902 shdr->TreeId = 0xFFFFFFFF; in smb2_new_read_req()
3903 req->PersistentFileId = 0xFFFFFFFFFFFFFFFF; in smb2_new_read_req()
3904 req->VolatileFileId = 0xFFFFFFFFFFFFFFFF; in smb2_new_read_req()
3907 if (remaining_bytes > io_parms->length) in smb2_new_read_req()
3908 req->RemainingBytes = cpu_to_le32(remaining_bytes); in smb2_new_read_req()
3910 req->RemainingBytes = 0; in smb2_new_read_req()
3919 struct cifs_readdata *rdata = mid->callback_data; in smb2_readv_callback()
3920 struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); in smb2_readv_callback() local
3921 struct TCP_Server_Info *server = rdata->server; in smb2_readv_callback()
3923 (struct smb2_sync_hdr *)rdata->iov[0].iov_base; in smb2_readv_callback()
3925 struct smb_rqst rqst = { .rq_iov = &rdata->iov[1], in smb2_readv_callback()
3927 .rq_pages = rdata->pages, in smb2_readv_callback()
3928 .rq_offset = rdata->page_offset, in smb2_readv_callback()
3929 .rq_npages = rdata->nr_pages, in smb2_readv_callback()
3930 .rq_pagesz = rdata->pagesz, in smb2_readv_callback()
3931 .rq_tailsz = rdata->tailsz }; in smb2_readv_callback()
3933 WARN_ONCE(rdata->server != mid->server, in smb2_readv_callback()
3935 rdata->server, mid->server); in smb2_readv_callback()
3938 __func__, mid->mid, mid->mid_state, rdata->result, in smb2_readv_callback()
3939 rdata->bytes); in smb2_readv_callback()
3941 switch (mid->mid_state) { in smb2_readv_callback()
3943 credits.value = le16_to_cpu(shdr->CreditRequest); in smb2_readv_callback()
3944 credits.instance = server->reconnect_instance; in smb2_readv_callback()
3946 if (server->sign && !mid->decrypted) { in smb2_readv_callback()
3955 task_io_account_read(rdata->got_bytes); in smb2_readv_callback()
3956 cifs_stats_bytes_read(tcon, rdata->got_bytes); in smb2_readv_callback()
3960 rdata->result = -EAGAIN; in smb2_readv_callback()
3961 if (server->sign && rdata->got_bytes) in smb2_readv_callback()
3963 rdata->got_bytes = 0; in smb2_readv_callback()
3965 task_io_account_read(rdata->got_bytes); in smb2_readv_callback()
3966 cifs_stats_bytes_read(tcon, rdata->got_bytes); in smb2_readv_callback()
3969 credits.value = le16_to_cpu(shdr->CreditRequest); in smb2_readv_callback()
3970 credits.instance = server->reconnect_instance; in smb2_readv_callback()
3973 rdata->result = -EIO; in smb2_readv_callback()
3981 if (rdata->mr) { in smb2_readv_callback()
3982 smbd_deregister_mr(rdata->mr); in smb2_readv_callback()
3983 rdata->mr = NULL; in smb2_readv_callback()
3986 if (rdata->result && rdata->result != -ENODATA) { in smb2_readv_callback()
3987 cifs_stats_fail_inc(tcon, SMB2_READ_HE); in smb2_readv_callback()
3989 rdata->cfile->fid.persistent_fid, in smb2_readv_callback()
3990 tcon->tid, tcon->ses->Suid, rdata->offset, in smb2_readv_callback()
3991 rdata->bytes, rdata->result); in smb2_readv_callback()
3994 rdata->cfile->fid.persistent_fid, in smb2_readv_callback()
3995 tcon->tid, tcon->ses->Suid, in smb2_readv_callback()
3996 rdata->offset, rdata->got_bytes); in smb2_readv_callback()
3998 queue_work(cifsiod_wq, &rdata->work); in smb2_readv_callback()
4003 /* smb2_async_readv - send an async read, and set up mid to handle result */
4011 struct smb_rqst rqst = { .rq_iov = rdata->iov, in smb2_async_readv()
4014 struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); in smb2_async_readv() local
4018 __func__, rdata->offset, rdata->bytes); in smb2_async_readv()
4020 if (!rdata->server) in smb2_async_readv()
4021 rdata->server = cifs_pick_channel(tcon->ses); in smb2_async_readv()
4023 io_parms.tcon = tlink_tcon(rdata->cfile->tlink); in smb2_async_readv()
4024 io_parms.server = server = rdata->server; in smb2_async_readv()
4025 io_parms.offset = rdata->offset; in smb2_async_readv()
4026 io_parms.length = rdata->bytes; in smb2_async_readv()
4027 io_parms.persistent_fid = rdata->cfile->fid.persistent_fid; in smb2_async_readv()
4028 io_parms.volatile_fid = rdata->cfile->fid.volatile_fid; in smb2_async_readv()
4029 io_parms.pid = rdata->pid; in smb2_async_readv()
4036 if (smb3_encryption_required(io_parms.tcon)) in smb2_async_readv()
4039 rdata->iov[0].iov_base = buf; in smb2_async_readv()
4040 rdata->iov[0].iov_len = total_len; in smb2_async_readv()
4044 if (rdata->credits.value > 0) { in smb2_async_readv()
4045 shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(rdata->bytes, in smb2_async_readv()
4047 shdr->CreditRequest = cpu_to_le16(le16_to_cpu(shdr->CreditCharge) + 8); in smb2_async_readv()
4049 rc = adjust_credits(server, &rdata->credits, rdata->bytes); in smb2_async_readv()
4056 kref_get(&rdata->refcount); in smb2_async_readv()
4060 &rdata->credits); in smb2_async_readv()
4062 kref_put(&rdata->refcount, cifs_readdata_release); in smb2_async_readv()
4063 cifs_stats_fail_inc(io_parms.tcon, SMB2_READ_HE); in smb2_async_readv()
4065 io_parms.tcon->tid, in smb2_async_readv()
4066 io_parms.tcon->ses->Suid, in smb2_async_readv()
4087 struct cifs_ses *ses = io_parms->tcon->ses; in SMB2_read()
4089 if (!io_parms->server) in SMB2_read()
4090 io_parms->server = cifs_pick_channel(io_parms->tcon->ses); in SMB2_read()
4097 if (smb3_encryption_required(io_parms->tcon)) in SMB2_read()
4107 rc = cifs_send_recv(xid, ses, io_parms->server, in SMB2_read()
4112 if (rc != -ENODATA) { in SMB2_read()
4113 cifs_stats_fail_inc(io_parms->tcon, SMB2_READ_HE); in SMB2_read()
4115 trace_smb3_read_err(xid, req->PersistentFileId, in SMB2_read()
4116 io_parms->tcon->tid, ses->Suid, in SMB2_read()
4117 io_parms->offset, io_parms->length, in SMB2_read()
4120 trace_smb3_read_done(xid, req->PersistentFileId, in SMB2_read()
4121 io_parms->tcon->tid, ses->Suid, in SMB2_read()
4122 io_parms->offset, 0); in SMB2_read()
4125 return rc == -ENODATA ? 0 : rc; in SMB2_read()
4127 trace_smb3_read_done(xid, req->PersistentFileId, in SMB2_read()
4128 io_parms->tcon->tid, ses->Suid, in SMB2_read()
4129 io_parms->offset, io_parms->length); in SMB2_read()
4133 *nbytes = le32_to_cpu(rsp->DataLength); in SMB2_read()
4135 (*nbytes > io_parms->length)) { in SMB2_read()
4137 *nbytes, io_parms->length); in SMB2_read()
4138 rc = -EIO; in SMB2_read()
4143 memcpy(*buf, (char *)rsp + rsp->DataOffset, *nbytes); in SMB2_read()
4162 struct cifs_writedata *wdata = mid->callback_data; in smb2_writev_callback()
4163 struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); in smb2_writev_callback() local
4164 struct TCP_Server_Info *server = wdata->server; in smb2_writev_callback()
4166 struct smb2_write_rsp *rsp = (struct smb2_write_rsp *)mid->resp_buf; in smb2_writev_callback()
4169 WARN_ONCE(wdata->server != mid->server, in smb2_writev_callback()
4171 wdata->server, mid->server); in smb2_writev_callback()
4173 switch (mid->mid_state) { in smb2_writev_callback()
4175 credits.value = le16_to_cpu(rsp->sync_hdr.CreditRequest); in smb2_writev_callback()
4176 credits.instance = server->reconnect_instance; in smb2_writev_callback()
4177 wdata->result = smb2_check_receive(mid, server, 0); in smb2_writev_callback()
4178 if (wdata->result != 0) in smb2_writev_callback()
4181 written = le32_to_cpu(rsp->DataLength); in smb2_writev_callback()
4188 if (written > wdata->bytes) in smb2_writev_callback()
4191 if (written < wdata->bytes) in smb2_writev_callback()
4192 wdata->result = -ENOSPC; in smb2_writev_callback()
4194 wdata->bytes = written; in smb2_writev_callback()
4198 wdata->result = -EAGAIN; in smb2_writev_callback()
4201 credits.value = le16_to_cpu(rsp->sync_hdr.CreditRequest); in smb2_writev_callback()
4202 credits.instance = server->reconnect_instance; in smb2_writev_callback()
4205 wdata->result = -EIO; in smb2_writev_callback()
4216 if (wdata->mr) { in smb2_writev_callback()
4217 smbd_deregister_mr(wdata->mr); in smb2_writev_callback()
4218 wdata->mr = NULL; in smb2_writev_callback()
4221 if (wdata->result) { in smb2_writev_callback()
4222 cifs_stats_fail_inc(tcon, SMB2_WRITE_HE); in smb2_writev_callback()
4224 wdata->cfile->fid.persistent_fid, in smb2_writev_callback()
4225 tcon->tid, tcon->ses->Suid, wdata->offset, in smb2_writev_callback()
4226 wdata->bytes, wdata->result); in smb2_writev_callback()
4227 if (wdata->result == -ENOSPC) in smb2_writev_callback()
4229 tcon->treeName); in smb2_writev_callback()
4232 wdata->cfile->fid.persistent_fid, in smb2_writev_callback()
4233 tcon->tid, tcon->ses->Suid, in smb2_writev_callback()
4234 wdata->offset, wdata->bytes); in smb2_writev_callback()
4236 queue_work(cifsiod_wq, &wdata->work); in smb2_writev_callback()
4241 /* smb2_async_writev - send an async write, and set up mid to handle result */
4246 int rc = -EACCES, flags = 0; in smb2_async_writev()
4249 struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); in smb2_async_writev() local
4250 struct TCP_Server_Info *server = wdata->server; in smb2_async_writev()
4255 if (!wdata->server) in smb2_async_writev()
4256 server = wdata->server = cifs_pick_channel(tcon->ses); in smb2_async_writev()
4258 rc = smb2_plain_req_init(SMB2_WRITE, tcon, server, in smb2_async_writev()
4263 if (smb3_encryption_required(tcon)) in smb2_async_writev()
4267 shdr->ProcessId = cpu_to_le32(wdata->cfile->pid); in smb2_async_writev()
4269 req->PersistentFileId = wdata->cfile->fid.persistent_fid; in smb2_async_writev()
4270 req->VolatileFileId = wdata->cfile->fid.volatile_fid; in smb2_async_writev()
4271 req->WriteChannelInfoOffset = 0; in smb2_async_writev()
4272 req->WriteChannelInfoLength = 0; in smb2_async_writev()
4273 req->Channel = 0; in smb2_async_writev()
4274 req->Offset = cpu_to_le64(wdata->offset); in smb2_async_writev()
4275 req->DataOffset = cpu_to_le16( in smb2_async_writev()
4277 req->RemainingBytes = 0; in smb2_async_writev()
4279 trace_smb3_write_enter(0 /* xid */, wdata->cfile->fid.persistent_fid, in smb2_async_writev()
4280 tcon->tid, tcon->ses->Suid, wdata->offset, wdata->bytes); in smb2_async_writev()
4286 if (server->rdma && !server->sign && wdata->bytes >= in smb2_async_writev()
4287 server->smbd_conn->rdma_readwrite_threshold) { in smb2_async_writev()
4290 bool need_invalidate = server->dialect == SMB30_PROT_ID; in smb2_async_writev()
4292 wdata->mr = smbd_register_mr( in smb2_async_writev()
4293 server->smbd_conn, wdata->pages, in smb2_async_writev()
4294 wdata->nr_pages, wdata->page_offset, in smb2_async_writev()
4295 wdata->tailsz, false, need_invalidate); in smb2_async_writev()
4296 if (!wdata->mr) { in smb2_async_writev()
4297 rc = -EAGAIN; in smb2_async_writev()
4300 req->Length = 0; in smb2_async_writev()
4301 req->DataOffset = 0; in smb2_async_writev()
4302 if (wdata->nr_pages > 1) in smb2_async_writev()
4303 req->RemainingBytes = in smb2_async_writev()
4305 (wdata->nr_pages - 1) * wdata->pagesz - in smb2_async_writev()
4306 wdata->page_offset + wdata->tailsz in smb2_async_writev()
4309 req->RemainingBytes = cpu_to_le32(wdata->tailsz); in smb2_async_writev()
4310 req->Channel = SMB2_CHANNEL_RDMA_V1_INVALIDATE; in smb2_async_writev()
4312 req->Channel = SMB2_CHANNEL_RDMA_V1; in smb2_async_writev()
4313 req->WriteChannelInfoOffset = in smb2_async_writev()
4315 req->WriteChannelInfoLength = in smb2_async_writev()
4317 v1 = (struct smbd_buffer_descriptor_v1 *) &req->Buffer[0]; in smb2_async_writev()
4318 v1->offset = cpu_to_le64(wdata->mr->mr->iova); in smb2_async_writev()
4319 v1->token = cpu_to_le32(wdata->mr->mr->rkey); in smb2_async_writev()
4320 v1->length = cpu_to_le32(wdata->mr->mr->length); in smb2_async_writev()
4323 iov[0].iov_len = total_len - 1; in smb2_async_writev()
4328 rqst.rq_pages = wdata->pages; in smb2_async_writev()
4329 rqst.rq_offset = wdata->page_offset; in smb2_async_writev()
4330 rqst.rq_npages = wdata->nr_pages; in smb2_async_writev()
4331 rqst.rq_pagesz = wdata->pagesz; in smb2_async_writev()
4332 rqst.rq_tailsz = wdata->tailsz; in smb2_async_writev()
4334 if (wdata->mr) { in smb2_async_writev()
4340 wdata->offset, wdata->bytes); in smb2_async_writev()
4344 if (!wdata->mr) in smb2_async_writev()
4345 req->Length = cpu_to_le32(wdata->bytes); in smb2_async_writev()
4347 req->Length = cpu_to_le32(wdata->bytes); in smb2_async_writev()
4350 if (wdata->credits.value > 0) { in smb2_async_writev()
4351 shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(wdata->bytes, in smb2_async_writev()
4353 shdr->CreditRequest = cpu_to_le16(le16_to_cpu(shdr->CreditCharge) + 8); in smb2_async_writev()
4355 rc = adjust_credits(server, &wdata->credits, wdata->bytes); in smb2_async_writev()
4362 kref_get(&wdata->refcount); in smb2_async_writev()
4364 wdata, flags, &wdata->credits); in smb2_async_writev()
4367 trace_smb3_write_err(0 /* no xid */, req->PersistentFileId, in smb2_async_writev()
4368 tcon->tid, tcon->ses->Suid, wdata->offset, in smb2_async_writev()
4369 wdata->bytes, rc); in smb2_async_writev()
4370 kref_put(&wdata->refcount, release); in smb2_async_writev()
4371 cifs_stats_fail_inc(tcon, SMB2_WRITE_HE); in smb2_async_writev()
4404 if (!io_parms->server) in SMB2_write()
4405 io_parms->server = cifs_pick_channel(io_parms->tcon->ses); in SMB2_write()
4406 server = io_parms->server; in SMB2_write()
4408 return -ECONNABORTED; in SMB2_write()
4410 rc = smb2_plain_req_init(SMB2_WRITE, io_parms->tcon, server, in SMB2_write()
4415 if (smb3_encryption_required(io_parms->tcon)) in SMB2_write()
4418 req->sync_hdr.ProcessId = cpu_to_le32(io_parms->pid); in SMB2_write()
4420 req->PersistentFileId = io_parms->persistent_fid; in SMB2_write()
4421 req->VolatileFileId = io_parms->volatile_fid; in SMB2_write()
4422 req->WriteChannelInfoOffset = 0; in SMB2_write()
4423 req->WriteChannelInfoLength = 0; in SMB2_write()
4424 req->Channel = 0; in SMB2_write()
4425 req->Length = cpu_to_le32(io_parms->length); in SMB2_write()
4426 req->Offset = cpu_to_le64(io_parms->offset); in SMB2_write()
4427 req->DataOffset = cpu_to_le16( in SMB2_write()
4429 req->RemainingBytes = 0; in SMB2_write()
4431 trace_smb3_write_enter(xid, io_parms->persistent_fid, in SMB2_write()
4432 io_parms->tcon->tid, io_parms->tcon->ses->Suid, in SMB2_write()
4433 io_parms->offset, io_parms->length); in SMB2_write()
4437 iov[0].iov_len = total_len - 1; in SMB2_write()
4443 rc = cifs_send_recv(xid, io_parms->tcon->ses, server, in SMB2_write()
4449 trace_smb3_write_err(xid, req->PersistentFileId, in SMB2_write()
4450 io_parms->tcon->tid, in SMB2_write()
4451 io_parms->tcon->ses->Suid, in SMB2_write()
4452 io_parms->offset, io_parms->length, rc); in SMB2_write()
4453 cifs_stats_fail_inc(io_parms->tcon, SMB2_WRITE_HE); in SMB2_write()
4456 *nbytes = le32_to_cpu(rsp->DataLength); in SMB2_write()
4457 trace_smb3_write_done(xid, req->PersistentFileId, in SMB2_write()
4458 io_parms->tcon->tid, in SMB2_write()
4459 io_parms->tcon->ses->Suid, in SMB2_write()
4460 io_parms->offset, *nbytes); in SMB2_write()
4474 return -1; in posix_info_sid_size()
4478 return -1; in posix_info_sid_size()
4482 return -1; in posix_info_sid_size()
4502 end = beg + le32_to_cpu(p->NextEntryOffset); in posix_info_parse()
4510 return -1; in posix_info_parse()
4517 return -1; in posix_info_parse()
4524 return -1; in posix_info_parse()
4529 return -1; in posix_info_parse()
4532 return -1; in posix_info_parse()
4538 return -1; in posix_info_parse()
4542 out->base = beg; in posix_info_parse()
4543 out->size = total_len; in posix_info_parse()
4544 out->name_len = name_len; in posix_info_parse()
4545 out->name = name; in posix_info_parse()
4546 memcpy(&out->owner, owner_sid, in posix_info_parse()
4548 memcpy(&out->group, group_sid, in posix_info_parse()
4559 return -1; in posix_info_extra_size()
4560 return len - sizeof(struct smb2_posix_info); in posix_info_extra_size()
4592 len = le32_to_cpu(dir_info->FileNameLength); in num_entries()
4606 next_offset = le32_to_cpu(dir_info->NextEntryOffset); in num_entries()
4618 struct cifs_tcon *tcon, in SMB2_query_directory_init() argument
4627 unsigned int output_size = CIFSMaxBufSize - in SMB2_query_directory_init()
4628 MAX_SMB2_CREATE_RESPONSE_SIZE - in SMB2_query_directory_init()
4631 struct kvec *iov = rqst->rq_iov; in SMB2_query_directory_init()
4634 rc = smb2_plain_req_init(SMB2_QUERY_DIRECTORY, tcon, server, in SMB2_query_directory_init()
4641 req->FileInformationClass = FILE_DIRECTORY_INFORMATION; in SMB2_query_directory_init()
4644 req->FileInformationClass = FILEID_FULL_DIRECTORY_INFORMATION; in SMB2_query_directory_init()
4647 req->FileInformationClass = SMB_FIND_FILE_POSIX_INFO; in SMB2_query_directory_init()
4652 return -EINVAL; in SMB2_query_directory_init()
4655 req->FileIndex = cpu_to_le32(index); in SMB2_query_directory_init()
4656 req->PersistentFileId = persistent_fid; in SMB2_query_directory_init()
4657 req->VolatileFileId = volatile_fid; in SMB2_query_directory_init()
4660 bufptr = req->Buffer; in SMB2_query_directory_init()
4663 req->FileNameOffset = in SMB2_query_directory_init()
4664 cpu_to_le16(sizeof(struct smb2_query_directory_req) - 1); in SMB2_query_directory_init()
4665 req->FileNameLength = cpu_to_le16(len); in SMB2_query_directory_init()
4670 output_size = min_t(unsigned int, output_size, server->maxBuf); in SMB2_query_directory_init()
4672 req->OutputBufferLength = cpu_to_le32(output_size); in SMB2_query_directory_init()
4676 iov[0].iov_len = total_len - 1; in SMB2_query_directory_init()
4678 iov[1].iov_base = (char *)(req->Buffer); in SMB2_query_directory_init()
4681 trace_smb3_query_dir_enter(xid, persistent_fid, tcon->tid, in SMB2_query_directory_init()
4682 tcon->ses->Suid, index, output_size); in SMB2_query_directory_init()
4689 if (rqst && rqst->rq_iov) { in SMB2_query_directory_free()
4690 cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_query_directory_free()
4695 smb2_parse_query_directory(struct cifs_tcon *tcon, in smb2_parse_query_directory() argument
4705 rsp = (struct smb2_query_directory_rsp *)rsp_iov->iov_base; in smb2_parse_query_directory()
4707 switch (srch_inf->info_level) { in smb2_parse_query_directory()
4709 info_buf_size = sizeof(FILE_DIRECTORY_INFO) - 1; in smb2_parse_query_directory()
4712 info_buf_size = sizeof(SEARCH_ID_FULL_DIR_INFO) - 1; in smb2_parse_query_directory()
4720 srch_inf->info_level); in smb2_parse_query_directory()
4721 return -EINVAL; in smb2_parse_query_directory()
4724 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), in smb2_parse_query_directory()
4725 le32_to_cpu(rsp->OutputBufferLength), rsp_iov, in smb2_parse_query_directory()
4732 srch_inf->unicode = true; in smb2_parse_query_directory()
4734 if (srch_inf->ntwrk_buf_start) { in smb2_parse_query_directory()
4735 if (srch_inf->smallBuf) in smb2_parse_query_directory()
4736 cifs_small_buf_release(srch_inf->ntwrk_buf_start); in smb2_parse_query_directory()
4738 cifs_buf_release(srch_inf->ntwrk_buf_start); in smb2_parse_query_directory()
4740 srch_inf->ntwrk_buf_start = (char *)rsp; in smb2_parse_query_directory()
4741 srch_inf->srch_entries_start = srch_inf->last_entry = in smb2_parse_query_directory()
4742 (char *)rsp + le16_to_cpu(rsp->OutputBufferOffset); in smb2_parse_query_directory()
4743 end_of_smb = rsp_iov->iov_len + (char *)rsp; in smb2_parse_query_directory()
4745 srch_inf->entries_in_buffer = num_entries( in smb2_parse_query_directory()
4746 srch_inf->info_level, in smb2_parse_query_directory()
4747 srch_inf->srch_entries_start, in smb2_parse_query_directory()
4749 &srch_inf->last_entry, in smb2_parse_query_directory()
4752 srch_inf->index_of_last_entry += srch_inf->entries_in_buffer; in smb2_parse_query_directory()
4754 srch_inf->entries_in_buffer, srch_inf->index_of_last_entry, in smb2_parse_query_directory()
4755 srch_inf->srch_entries_start, srch_inf->last_entry); in smb2_parse_query_directory()
4757 srch_inf->smallBuf = false; in smb2_parse_query_directory()
4759 srch_inf->smallBuf = true; in smb2_parse_query_directory()
4767 SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_query_directory() argument
4777 struct cifs_ses *ses = tcon->ses; in SMB2_query_directory()
4781 if (!ses || !(ses->server)) in SMB2_query_directory()
4782 return -EIO; in SMB2_query_directory()
4784 if (smb3_encryption_required(tcon)) in SMB2_query_directory()
4792 rc = SMB2_query_directory_init(xid, tcon, server, in SMB2_query_directory()
4795 srch_inf->info_level); in SMB2_query_directory()
4804 if (rc == -ENODATA && in SMB2_query_directory()
4805 rsp->sync_hdr.Status == STATUS_NO_MORE_FILES) { in SMB2_query_directory()
4807 tcon->tid, tcon->ses->Suid, index, 0); in SMB2_query_directory()
4808 srch_inf->endOfSearch = true; in SMB2_query_directory()
4811 trace_smb3_query_dir_err(xid, persistent_fid, tcon->tid, in SMB2_query_directory()
4812 tcon->ses->Suid, index, 0, rc); in SMB2_query_directory()
4813 cifs_stats_fail_inc(tcon, SMB2_QUERY_DIRECTORY_HE); in SMB2_query_directory()
4818 rc = smb2_parse_query_directory(tcon, &rsp_iov, resp_buftype, in SMB2_query_directory()
4821 trace_smb3_query_dir_err(xid, persistent_fid, tcon->tid, in SMB2_query_directory()
4822 tcon->ses->Suid, index, 0, rc); in SMB2_query_directory()
4827 trace_smb3_query_dir_done(xid, persistent_fid, tcon->tid, in SMB2_query_directory()
4828 tcon->ses->Suid, index, srch_inf->entries_in_buffer); in SMB2_query_directory()
4837 SMB2_set_info_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, in SMB2_set_info_init() argument
4844 struct kvec *iov = rqst->rq_iov; in SMB2_set_info_init()
4848 rc = smb2_plain_req_init(SMB2_SET_INFO, tcon, server, in SMB2_set_info_init()
4853 req->sync_hdr.ProcessId = cpu_to_le32(pid); in SMB2_set_info_init()
4854 req->InfoType = info_type; in SMB2_set_info_init()
4855 req->FileInfoClass = info_class; in SMB2_set_info_init()
4856 req->PersistentFileId = persistent_fid; in SMB2_set_info_init()
4857 req->VolatileFileId = volatile_fid; in SMB2_set_info_init()
4858 req->AdditionalInformation = cpu_to_le32(additional_info); in SMB2_set_info_init()
4860 req->BufferOffset = in SMB2_set_info_init()
4861 cpu_to_le16(sizeof(struct smb2_set_info_req) - 1); in SMB2_set_info_init()
4862 req->BufferLength = cpu_to_le32(*size); in SMB2_set_info_init()
4864 memcpy(req->Buffer, *data, *size); in SMB2_set_info_init()
4869 iov[0].iov_len = total_len - 1; in SMB2_set_info_init()
4871 for (i = 1; i < rqst->rq_nvec; i++) { in SMB2_set_info_init()
4872 le32_add_cpu(&req->BufferLength, size[i]); in SMB2_set_info_init()
4883 if (rqst && rqst->rq_iov) in SMB2_set_info_free()
4884 cifs_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_set_info_free()
4888 send_set_info(const unsigned int xid, struct cifs_tcon *tcon, in send_set_info() argument
4899 struct cifs_ses *ses = tcon->ses; in send_set_info()
4904 return -EIO; in send_set_info()
4907 return -EINVAL; in send_set_info()
4909 if (smb3_encryption_required(tcon)) in send_set_info()
4914 return -ENOMEM; in send_set_info()
4920 rc = SMB2_set_info_init(tcon, server, in send_set_info()
4937 cifs_stats_fail_inc(tcon, SMB2_SET_INFO_HE); in send_set_info()
4938 trace_smb3_set_info_err(xid, persistent_fid, tcon->tid, in send_set_info()
4939 ses->Suid, info_class, (__u32)info_type, rc); in send_set_info()
4948 SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, in SMB2_set_eof() argument
4960 return send_set_info(xid, tcon, persistent_fid, volatile_fid, in SMB2_set_eof()
4966 SMB2_set_acl(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_set_acl() argument
4970 return send_set_info(xid, tcon, persistent_fid, volatile_fid, in SMB2_set_acl()
4971 current->tgid, 0, SMB2_O_INFO_SECURITY, aclflag, in SMB2_set_acl()
4976 SMB2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_set_ea() argument
4980 return send_set_info(xid, tcon, persistent_fid, volatile_fid, in SMB2_set_ea()
4981 current->tgid, FILE_FULL_EA_INFORMATION, SMB2_O_INFO_FILE, in SMB2_set_ea()
4986 SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_oplock_break() argument
4993 struct cifs_ses *ses = tcon->ses; in SMB2_oplock_break()
5002 rc = smb2_plain_req_init(SMB2_OPLOCK_BREAK, tcon, server, in SMB2_oplock_break()
5007 if (smb3_encryption_required(tcon)) in SMB2_oplock_break()
5010 req->VolatileFid = volatile_fid; in SMB2_oplock_break()
5011 req->PersistentFid = persistent_fid; in SMB2_oplock_break()
5012 req->OplockLevel = oplock_level; in SMB2_oplock_break()
5013 req->sync_hdr.CreditRequest = cpu_to_le16(1); in SMB2_oplock_break()
5029 cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE); in SMB2_oplock_break()
5040 kst->f_bsize = le32_to_cpu(pfs_inf->BytesPerSector) * in smb2_copy_fs_info_to_kstatfs()
5041 le32_to_cpu(pfs_inf->SectorsPerAllocationUnit); in smb2_copy_fs_info_to_kstatfs()
5042 kst->f_blocks = le64_to_cpu(pfs_inf->TotalAllocationUnits); in smb2_copy_fs_info_to_kstatfs()
5043 kst->f_bfree = kst->f_bavail = in smb2_copy_fs_info_to_kstatfs()
5044 le64_to_cpu(pfs_inf->CallerAvailableAllocationUnits); in smb2_copy_fs_info_to_kstatfs()
5052 kst->f_bsize = le32_to_cpu(response_data->BlockSize); in copy_posix_fs_info_to_kstatfs()
5053 kst->f_blocks = le64_to_cpu(response_data->TotalBlocks); in copy_posix_fs_info_to_kstatfs()
5054 kst->f_bfree = le64_to_cpu(response_data->BlocksAvail); in copy_posix_fs_info_to_kstatfs()
5055 if (response_data->UserBlocksAvail == cpu_to_le64(-1)) in copy_posix_fs_info_to_kstatfs()
5056 kst->f_bavail = kst->f_bfree; in copy_posix_fs_info_to_kstatfs()
5058 kst->f_bavail = le64_to_cpu(response_data->UserBlocksAvail); in copy_posix_fs_info_to_kstatfs()
5059 if (response_data->TotalFileNodes != cpu_to_le64(-1)) in copy_posix_fs_info_to_kstatfs()
5060 kst->f_files = le64_to_cpu(response_data->TotalFileNodes); in copy_posix_fs_info_to_kstatfs()
5061 if (response_data->FreeFileNodes != cpu_to_le64(-1)) in copy_posix_fs_info_to_kstatfs()
5062 kst->f_ffree = le64_to_cpu(response_data->FreeFileNodes); in copy_posix_fs_info_to_kstatfs()
5068 build_qfs_info_req(struct kvec *iov, struct cifs_tcon *tcon, in build_qfs_info_req() argument
5079 if ((tcon->ses == NULL) || server == NULL) in build_qfs_info_req()
5080 return -EIO; in build_qfs_info_req()
5082 rc = smb2_plain_req_init(SMB2_QUERY_INFO, tcon, server, in build_qfs_info_req()
5087 req->InfoType = SMB2_O_INFO_FILESYSTEM; in build_qfs_info_req()
5088 req->FileInfoClass = level; in build_qfs_info_req()
5089 req->PersistentFileId = persistent_fid; in build_qfs_info_req()
5090 req->VolatileFileId = volatile_fid; in build_qfs_info_req()
5092 req->InputBufferOffset = in build_qfs_info_req()
5093 cpu_to_le16(sizeof(struct smb2_query_info_req) - 1); in build_qfs_info_req()
5094 req->OutputBufferLength = cpu_to_le32( in build_qfs_info_req()
5095 outbuf_len + sizeof(struct smb2_query_info_rsp) - 1); in build_qfs_info_req()
5097 iov->iov_base = (char *)req; in build_qfs_info_req()
5098 iov->iov_len = total_len; in build_qfs_info_req()
5103 SMB311_posix_qfs_info(const unsigned int xid, struct cifs_tcon *tcon, in SMB311_posix_qfs_info() argument
5112 struct cifs_ses *ses = tcon->ses; in SMB311_posix_qfs_info()
5117 rc = build_qfs_info_req(&iov, tcon, server, in SMB311_posix_qfs_info()
5124 if (smb3_encryption_required(tcon)) in SMB311_posix_qfs_info()
5135 cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); in SMB311_posix_qfs_info()
5141 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp); in SMB311_posix_qfs_info()
5142 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), in SMB311_posix_qfs_info()
5143 le32_to_cpu(rsp->OutputBufferLength), &rsp_iov, in SMB311_posix_qfs_info()
5154 SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_QFS_info() argument
5163 struct cifs_ses *ses = tcon->ses; in SMB2_QFS_info()
5168 rc = build_qfs_info_req(&iov, tcon, server, in SMB2_QFS_info()
5175 if (smb3_encryption_required(tcon)) in SMB2_QFS_info()
5186 cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); in SMB2_QFS_info()
5192 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp); in SMB2_QFS_info()
5193 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), in SMB2_QFS_info()
5194 le32_to_cpu(rsp->OutputBufferLength), &rsp_iov, in SMB2_QFS_info()
5205 SMB2_QFS_attr(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_QFS_attr() argument
5214 struct cifs_ses *ses = tcon->ses; in SMB2_QFS_attr()
5233 return -EINVAL; in SMB2_QFS_attr()
5236 rc = build_qfs_info_req(&iov, tcon, server, in SMB2_QFS_attr()
5242 if (smb3_encryption_required(tcon)) in SMB2_QFS_attr()
5253 cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); in SMB2_QFS_attr()
5258 rsp_len = le32_to_cpu(rsp->OutputBufferLength); in SMB2_QFS_attr()
5259 offset = le16_to_cpu(rsp->OutputBufferOffset); in SMB2_QFS_attr()
5265 memcpy(&tcon->fsAttrInfo, offset in SMB2_QFS_attr()
5269 memcpy(&tcon->fsDevInfo, offset in SMB2_QFS_attr()
5274 tcon->ss_flags = le32_to_cpu(ss_info->Flags); in SMB2_QFS_attr()
5275 tcon->perf_sector_size = in SMB2_QFS_attr()
5276 le32_to_cpu(ss_info->PhysicalBytesPerSectorForPerf); in SMB2_QFS_attr()
5280 tcon->vol_serial_number = vol_info->VolumeSerialNumber; in SMB2_QFS_attr()
5281 tcon->vol_create_time = vol_info->VolumeCreationTime; in SMB2_QFS_attr()
5290 smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon, in smb2_lockv() argument
5303 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses); in smb2_lockv()
5307 rc = smb2_plain_req_init(SMB2_LOCK, tcon, server, in smb2_lockv()
5312 if (smb3_encryption_required(tcon)) in smb2_lockv()
5315 req->sync_hdr.ProcessId = cpu_to_le32(pid); in smb2_lockv()
5316 req->LockCount = cpu_to_le16(num_lock); in smb2_lockv()
5318 req->PersistentFileId = persist_fid; in smb2_lockv()
5319 req->VolatileFileId = volatile_fid; in smb2_lockv()
5324 iov[0].iov_len = total_len - sizeof(struct smb2_lock_element); in smb2_lockv()
5328 cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); in smb2_lockv()
5334 rc = cifs_send_recv(xid, tcon->ses, server, in smb2_lockv()
5340 cifs_stats_fail_inc(tcon, SMB2_LOCK_HE); in smb2_lockv()
5341 trace_smb3_lock_err(xid, persist_fid, tcon->tid, in smb2_lockv()
5342 tcon->ses->Suid, rc); in smb2_lockv()
5349 SMB2_lock(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_lock() argument
5362 return smb2_lockv(xid, tcon, persist_fid, volatile_fid, pid, 1, &lock); in SMB2_lock()
5366 SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_lease_break() argument
5372 struct cifs_ses *ses = tcon->ses; in SMB2_lease_break()
5380 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses); in SMB2_lease_break()
5383 rc = smb2_plain_req_init(SMB2_OPLOCK_BREAK, tcon, server, in SMB2_lease_break()
5388 if (smb3_encryption_required(tcon)) in SMB2_lease_break()
5391 req->sync_hdr.CreditRequest = cpu_to_le16(1); in SMB2_lease_break()
5392 req->StructureSize = cpu_to_le16(36); in SMB2_lease_break()
5395 memcpy(req->LeaseKey, lease_key, 16); in SMB2_lease_break()
5396 req->LeaseState = lease_state; in SMB2_lease_break()
5414 cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE); in SMB2_lease_break()
5415 trace_smb3_lease_err(le32_to_cpu(lease_state), tcon->tid, in SMB2_lease_break()
5416 ses->Suid, *please_key_low, *please_key_high, rc); in SMB2_lease_break()
5419 trace_smb3_lease_done(le32_to_cpu(lease_state), tcon->tid, in SMB2_lease_break()
5420 ses->Suid, *please_key_low, *please_key_high); in SMB2_lease_break()