// SPDX-License-Identifier: LGPL-2.1 /* * * Copyright (C) International Business Machines Corp., 2002,2010 * Author(s): Steve French (sfrench@us.ibm.com) * * Contains the routines for constructing the SMB PDUs themselves *
*/
/* SMB/CIFS PDU handling routines here - except for leftovers in connect.c */ /* These are mostly routines that operate on a pathname, or on a tree id */ /* (mounted volume), but there are eight handle based routines which must be */ /* treated slightly differently for reconnection purposes since we never */ /* want to reuse a stale file handle and only the caller knows the file info */
/* define the number of elements in the cifs dialect array */ #ifdef CONFIG_CIFS_POSIX #define CIFS_NUM_PROT 2 #else/* not posix */ #define CIFS_NUM_PROT 1 #endif/* CIFS_POSIX */
/* reconnect the socket, tcon, and smb session if needed */ staticint
cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
{ struct TCP_Server_Info *server; struct cifs_ses *ses; int rc;
/* * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for * tcp and smb session status done differently for those three - in the * calling routine
*/ if (!tcon) return 0;
ses = tcon->ses;
server = ses->server;
/* * only tree disconnect, open, and write, (and ulogoff which does not * have tcon) are allowed as we start umount
*/
spin_lock(&tcon->tc_lock); if (tcon->status == TID_EXITING) { if (smb_command != SMB_COM_TREE_DISCONNECT) {
spin_unlock(&tcon->tc_lock);
cifs_dbg(FYI, "can not send cmd %d while umounting\n",
smb_command); return -ENODEV;
}
}
spin_unlock(&tcon->tc_lock);
again:
rc = cifs_wait_for_server_reconnect(server, tcon->retry); if (rc) return rc;
mutex_lock(&ses->session_mutex); /* * Handle the case where a concurrent thread failed to negotiate or * killed a channel.
*/
spin_lock(&server->srv_lock); switch (server->tcpStatus) { case CifsExiting:
spin_unlock(&server->srv_lock);
mutex_unlock(&ses->session_mutex); return -EHOSTDOWN; case CifsNeedReconnect:
spin_unlock(&server->srv_lock);
mutex_unlock(&ses->session_mutex); if (!tcon->retry) return -EHOSTDOWN; goto again; default: break;
}
spin_unlock(&server->srv_lock);
/* * need to prevent multiple threads trying to simultaneously * reconnect the same SMB session
*/
spin_lock(&ses->ses_lock);
spin_lock(&ses->chan_lock); if (!cifs_chan_needs_reconnect(ses, server) &&
ses->ses_status == SES_GOOD) {
spin_unlock(&ses->chan_lock);
spin_unlock(&ses->ses_lock);
/* this means that we only need to tree connect */ if (tcon->need_reconnect) goto skip_sess_setup;
/* tell server Unix caps we support */ if (cap_unix(ses))
reset_cifs_unix_caps(0, tcon, NULL, NULL);
/* * Removed call to reopen open files here. It is safer (and faster) to * reopen files one at a time as needed in read and write. * * FIXME: what about file locks? don't we need to reclaim them ASAP?
*/
out: /* * Check if handle based operation so we know whether we can continue * or not without returning to caller to reset file handle
*/ switch (smb_command) { case SMB_COM_READ_ANDX: case SMB_COM_WRITE_ANDX: case SMB_COM_CLOSE: case SMB_COM_FIND_CLOSE2: case SMB_COM_LOCKING_ANDX:
rc = -EAGAIN;
}
return rc;
}
/* Allocate and return pointer to an SMB request buffer, and set basic SMB information in the SMB header. If the return code is zero, this
function must have filled in request_buf pointer */ staticint
small_smb_init(int smb_command, int wct, struct cifs_tcon *tcon, void **request_buf)
{ int rc;
rc = cifs_reconnect_tcon(tcon, smb_command); if (rc) return rc;
*request_buf = cifs_small_buf_get(); if (*request_buf == NULL) { /* BB should we add a retry in here if not a writepage? */ return -ENOMEM;
}
/* uid, tid can stay at zero as set in header assemble */
/* BB add support for turning on the signing when
this function is used after 1st of session setup requests */
return rc;
}
/* If the return code is zero, this function must fill in request_buf pointer */ staticint
__smb_init(int smb_command, int wct, struct cifs_tcon *tcon, void **request_buf, void **response_buf)
{
*request_buf = cifs_buf_get(); if (*request_buf == NULL) { /* BB should we add a retry in here if not a writepage? */ return -ENOMEM;
} /* Although the original thought was we needed the response buf for */ /* potential retries of smb operations it turns out we can determine */ /* from the mid flags when the request buffer can be resent without */ /* having to use a second distinct buffer for the response */ if (response_buf)
*response_buf = *request_buf;
if (tcon != NULL)
cifs_stats_inc(&tcon->num_smbs_sent);
return 0;
}
/* If the return code is zero, this function must fill in request_buf pointer */ staticint
smb_init(int smb_command, int wct, struct cifs_tcon *tcon, void **request_buf, void **response_buf)
{ int rc;
rc = cifs_reconnect_tcon(tcon, smb_command); if (rc) return rc;
/* check for plausible wct */ if (pSMB->hdr.WordCount < 10) goto vt2_err;
/* check for parm and data offset going beyond end of smb */ if (get_unaligned_le16(&pSMB->t2_rsp.ParameterOffset) > 1024 ||
get_unaligned_le16(&pSMB->t2_rsp.DataOffset) > 1024) goto vt2_err;
total_size = get_unaligned_le16(&pSMB->t2_rsp.ParameterCount); if (total_size >= 512) goto vt2_err;
/* check that bcc is at least as big as parms + data, and that it is * less than negotiated smb buffer
*/
total_size += get_unaligned_le16(&pSMB->t2_rsp.DataCount); if (total_size > get_bcc(&pSMB->hdr) ||
total_size >= CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) goto vt2_err;
count = 0; /* * We know that all the name entries in the protocols array * are short (< 16 bytes anyway) and are NUL terminated.
*/ for (i = 0; i < CIFS_NUM_PROT; i++) {
size_t len = strlen(protocols[i].name) + 1;
server->dialect = le16_to_cpu(pSMBr->DialectIndex);
cifs_dbg(FYI, "Dialect: %d\n", server->dialect); /* Check wct = 1 error case */ if ((pSMBr->hdr.WordCount <= 13) || (server->dialect == BAD_PROT)) { /* core returns wct = 1, but we do not ask for core - otherwise small wct just comes when dialect index is -1 indicating we
could not negotiate a common dialect */
rc = -EOPNOTSUPP; goto neg_err_exit;
} elseif (pSMBr->hdr.WordCount != 17) { /* unknown wct */
rc = -EOPNOTSUPP; goto neg_err_exit;
} /* else wct == 17, NTLM or better */
/* one byte, so no need to convert this or EncryptionKeyLen from
little endian */
server->maxReq = min_t(unsignedint, le16_to_cpu(pSMBr->MaxMpxCount),
cifs_max_pending);
set_credits(server, server->maxReq); /* probably no need to store and check maxvcs */
server->maxBuf = le32_to_cpu(pSMBr->MaxBufferSize); /* set up max_read for readahead check */
server->max_read = server->maxBuf;
server->max_rw = le32_to_cpu(pSMBr->MaxRawSize);
cifs_dbg(NOISY, "Max buf = %d\n", ses->server->maxBuf);
server->capabilities = le32_to_cpu(pSMBr->Capabilities);
server->session_key_id = pSMBr->SessionKey;
server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone);
server->timeAdj *= 60;
int
CIFSSMBTDis(constunsignedint xid, struct cifs_tcon *tcon)
{ struct smb_hdr *smb_buffer; int rc = 0;
cifs_dbg(FYI, "In tree disconnect\n");
/* BB: do we need to check this? These should never be NULL. */ if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) return -EIO;
/* * No need to return error on this operation if tid invalidated and * closed on server already e.g. due to tcp session crashing. Also, * the tcon is no longer on the list, so no need to take lock before * checking this.
*/
spin_lock(&tcon->ses->chan_lock); if ((tcon->need_reconnect) || CIFS_ALL_CHANS_NEED_RECONNECT(tcon->ses)) {
spin_unlock(&tcon->ses->chan_lock); return -EIO;
}
spin_unlock(&tcon->ses->chan_lock);
/* No need to return error on this operation if tid invalidated and
closed on server already e.g. due to tcp session crashing */ if (rc == -EAGAIN)
rc = 0;
return rc;
}
/* * This is a no-op for now. We're not really interested in the reply, but * rather in the fact that the server sent one and that server->lstrp * gets updated. * * FIXME: maybe we should consider checking that the reply matches request?
*/ staticvoid
cifs_echo_callback(struct mid_q_entry *mid)
{ struct TCP_Server_Info *server = mid->callback_data; struct cifs_credits credits = { .value = 1, .instance = 0 };
int
CIFSSMBLogoff(constunsignedint xid, struct cifs_ses *ses)
{
LOGOFF_ANDX_REQ *pSMB; int rc = 0;
cifs_dbg(FYI, "In SMBLogoff for session disconnect\n");
/* * BB: do we need to check validity of ses and server? They should * always be valid since we have an active reference. If not, that * should probably be a BUG()
*/ if (!ses || !ses->server) return -EIO;
mutex_lock(&ses->session_mutex);
spin_lock(&ses->chan_lock); if (CIFS_ALL_CHANS_NEED_RECONNECT(ses)) {
spin_unlock(&ses->chan_lock); goto session_already_dead; /* no need to send SMBlogoff if uid
already closed due to reconnect */
}
spin_unlock(&ses->chan_lock);
/* if session dead then we do not need to do ulogoff, since server closed smb session, no sense reporting
error */ if (rc == -EAGAIN)
rc = 0; return rc;
}
int
CIFSPOSIXDelFile(constunsignedint xid, struct cifs_tcon *tcon, constchar *fileName, __u16 type, conststruct nls_table *nls_codepage, int remap)
{
TRANSACTION2_SPI_REQ *pSMB = NULL;
TRANSACTION2_SPI_RSP *pSMBr = NULL; struct unlink_psx_rq *pRqD; int name_len; int rc = 0; int bytes_returned = 0;
__u16 params, param_offset, offset, byte_count;
cifs_dbg(FYI, "In POSIX delete\n");
PsxDelete:
rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
(void **) &pSMBr); if (rc) return rc;
if (rc || get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)) {
rc = -EIO; /* bad smb */ goto psx_create_err;
}
/* copy return information to pRetData */
psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol
+ le16_to_cpu(pSMBr->t2.DataOffset));
*pOplock = le16_to_cpu(psx_rsp->OplockFlags); if (netfid)
*netfid = psx_rsp->Fid; /* cifs fid stays in le */ /* Let caller know file was created so we can set the mode. */ /* Do we care about the CreateAction in any other cases? */ if (cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction)
*pOplock |= CIFS_CREATE_ACTION; /* check to make sure response data is there */ if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) {
pRetData->Type = cpu_to_le32(-1); /* unknown */
cifs_dbg(NOISY, "unknown type\n");
} else { if (get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)
+ sizeof(FILE_UNIX_BASIC_INFO)) {
cifs_dbg(VFS, "Open response data too small\n");
pRetData->Type = cpu_to_le32(-1); goto psx_create_err;
}
memcpy((char *) pRetData,
(char *)psx_rsp + sizeof(OPEN_PSX_RSP), sizeof(FILE_UNIX_BASIC_INFO));
}
psx_create_err:
cifs_buf_release(pSMB);
if (posix_flags & SMB_O_DIRECTORY)
cifs_stats_inc(&tcon->stats.cifs_stats.num_posixmkdirs); else
cifs_stats_inc(&tcon->stats.cifs_stats.num_posixopens);
switch (disposition) { case FILE_SUPERSEDE:
ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; break; case FILE_OPEN:
ofun = SMBOPEN_OAPPEND; break; case FILE_CREATE:
ofun = SMBOPEN_OCREATE; break; case FILE_OPEN_IF:
ofun = SMBOPEN_OCREATE | SMBOPEN_OAPPEND; break; case FILE_OVERWRITE:
ofun = SMBOPEN_OTRUNC; break; case FILE_OVERWRITE_IF:
ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; break; default:
cifs_dbg(FYI, "unknown disposition %d\n", disposition);
ofun = SMBOPEN_OAPPEND; /* regular open */
} return ofun;
}
staticint
access_flags_to_smbopen_mode(constint access_flags)
{ /* * SYSTEM_SECURITY grants both read and write access to SACL, treat is as read/write. * MAXIMUM_ALLOWED grants as many access as possible, so treat it as read/write too. * SYNCHRONIZE as is does not grant any specific access, so do not check its mask. * If only SYNCHRONIZE bit is specified then fallback to read access.
*/ bool with_write_flags = access_flags & (FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_WRITE_EA |
FILE_DELETE_CHILD | FILE_WRITE_ATTRIBUTES | DELETE |
WRITE_DAC | WRITE_OWNER | SYSTEM_SECURITY |
MAXIMUM_ALLOWED | GENERIC_WRITE | GENERIC_ALL); bool with_read_flags = access_flags & (FILE_READ_DATA | FILE_READ_EA | FILE_EXECUTE |
FILE_READ_ATTRIBUTES | READ_CONTROL |
SYSTEM_SECURITY | MAXIMUM_ALLOWED | GENERIC_ALL |
GENERIC_EXECUTE | GENERIC_READ); bool with_execute_flags = access_flags & (FILE_EXECUTE | MAXIMUM_ALLOWED | GENERIC_ALL |
GENERIC_EXECUTE);
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
count = 1; /* account for one byte pad to word boundary */
name_len =
cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1),
fileName, PATH_MAX, nls_codepage, remap);
name_len++; /* trailing null */
name_len *= 2;
} else {
count = 0; /* no pad */
name_len = copy_path_name(pSMB->fileName, fileName);
} if (*pOplock & REQ_OPLOCK)
pSMB->OpenFlags = cpu_to_le16(REQ_OPLOCK); elseif (*pOplock & REQ_BATCHOPLOCK)
pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK);
pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO);
pSMB->Mode = cpu_to_le16(access_flags_to_smbopen_mode(access_flags));
pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ /* set file as system file if special file such as fifo, * socket, char or block and server expecting SFU style and
no Unix extensions */
pSMB->ByteCount = cpu_to_le16(count);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
(struct smb_hdr *)pSMBr, &bytes_returned, 0);
cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); if (rc) {
cifs_dbg(FYI, "Error in Open = %d\n", rc);
} else { /* BB verify if wct == 15 */
/* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/
*netfid = pSMBr->Fid; /* cifs fid stays in le */ /* Let caller know file was created so we can set the mode. */ /* Do we care about the CreateAction in any other cases? */ /* BB FIXME BB */ /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction)
*pOplock |= CIFS_CREATE_ACTION; */ /* BB FIXME END */
/* * Set file as system file if special file such as fifo, socket, char * or block and server expecting SFU style and no Unix extensions.
*/ if (create_options & CREATE_OPTION_SPECIAL)
req->FileAttributes = cpu_to_le32(ATTR_SYSTEM); else
req->FileAttributes = cpu_to_le32(ATTR_NORMAL);
/* * XP does not handle ATTR_POSIX_SEMANTICS but it helps speed up case * sensitive checks for other servers such as Samba.
*/ if (tcon->ses->capabilities & CAP_UNIX)
req->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS);
if (create_options & CREATE_OPTION_READONLY)
req->FileAttributes |= cpu_to_le32(ATTR_READONLY);
/* BB Experiment with various impersonation levels and verify */
req->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION);
req->SecurityFlags = SECURITY_CONTEXT_TRACKING|SECURITY_EFFECTIVE_ONLY;
count += name_len;
inc_rfc1001_len(req, count);
req->ByteCount = cpu_to_le16(count);
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *)req,
(struct smb_hdr *)rsp, &bytes_returned, 0);
cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); if (rc) {
cifs_dbg(FYI, "Error in Open = %d\n", rc);
cifs_buf_release(req); if (rc == -EAGAIN) goto openRetry; return rc;
}
/* 1 byte no need to le_to_cpu */
*oplock = rsp->OplockLevel; /* cifs fid stays in le */
oparms->fid->netfid = rsp->Fid;
oparms->fid->access = desired_access;
/* Let caller know file was created so we can set the mode. */ /* Do we care about the CreateAction in any other cases? */ if (cpu_to_le32(FILE_CREATE) == rsp->CreateAction)
*oplock |= CIFS_CREATE_ACTION;
if (buf) { /* copy commonly used attributes */
memcpy(&buf->common_attributes,
&rsp->common_attributes, sizeof(buf->common_attributes)); /* the file_info buf is endian converted by caller */
buf->AllocationSize = rsp->AllocationSize;
buf->EndOfFile = rsp->EndOfFile;
buf->NumberOfLinks = cpu_to_le32(1);
buf->DeletePending = 0;
}
switch (mid->mid_state) { case MID_RESPONSE_RECEIVED: /* result already set, check signature */ if (server->sign) { int rc = 0;
iov_iter_truncate(&rqst.rq_iter, rdata->got_bytes);
rc = cifs_verify_signature(&rqst, server,
mid->sequence_number); if (rc)
cifs_dbg(VFS, "SMB signature verification returned error = %d\n",
rc);
} /* FIXME: should this be counted toward the initiating task? */
task_io_account_read(rdata->got_bytes);
cifs_stats_bytes_read(tcon, rdata->got_bytes); break; case MID_REQUEST_SUBMITTED:
trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_req_submitted); goto do_retry; case MID_RETRY_NEEDED:
trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_retry_needed);
do_retry:
__set_bit(NETFS_SREQ_NEED_RETRY, &rdata->subreq.flags);
rdata->result = -EAGAIN; if (server->sign && rdata->got_bytes) /* reset bytes number since we can not check a sign */
rdata->got_bytes = 0; /* FIXME: should this be counted toward the initiating task? */
task_io_account_read(rdata->got_bytes);
cifs_stats_bytes_read(tcon, rdata->got_bytes); break; case MID_RESPONSE_MALFORMED:
trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_malformed);
rdata->result = -EIO; break; default:
trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_unknown);
rdata->result = -EIO; break;
}
if (rdata->result == -ENODATA) {
rdata->result = 0;
__set_bit(NETFS_SREQ_HIT_EOF, &rdata->subreq.flags);
} else {
size_t trans = rdata->subreq.transferred + rdata->got_bytes; if (trans < rdata->subreq.len &&
rdata->subreq.start + trans == ictx->remote_i_size) {
rdata->result = 0;
__set_bit(NETFS_SREQ_HIT_EOF, &rdata->subreq.flags);
} elseif (rdata->got_bytes > 0) {
__set_bit(NETFS_SREQ_MADE_PROGRESS, &rdata->subreq.flags);
} if (rdata->got_bytes)
__set_bit(NETFS_SREQ_MADE_PROGRESS, &rdata->subreq.flags);
}
/* cifs_async_readv - send an async write, and set up mid to handle result */ int
cifs_async_readv(struct cifs_io_subrequest *rdata)
{ int rc;
READ_REQ *smb = NULL; int wct; struct cifs_tcon *tcon = tlink_tcon(rdata->req->cfile->tlink); struct smb_rqst rqst = { .rq_iov = rdata->iov,
.rq_nvec = 2 };
if (tcon->ses->capabilities & CAP_LARGE_FILES)
wct = 12; else {
wct = 10; /* old style read */ if ((rdata->subreq.start >> 32) > 0) { /* can not handle this big offset for old */ return -EIO;
}
}
cifs_dbg(FYI, "Reading %d bytes on fid %d\n", count, netfid); if (tcon->ses->capabilities & CAP_LARGE_FILES)
wct = 12; else {
wct = 10; /* old style read */ if ((offset >> 32) > 0) { /* can not handle this big offset for old */ return -EIO;
}
}
/* cifs_dbg(FYI, "write at %lld %d bytes\n", offset, count);*/ if (tcon->ses == NULL) return -ECONNABORTED;
if (tcon->ses->capabilities & CAP_LARGE_FILES)
wct = 14; else {
wct = 12; if ((offset >> 32) > 0) { /* can not handle big offset for old srv */ return -EIO;
}
}
/* Can increase buffer size if buffer is big enough in some cases ie we can send more if LARGE_WRITE_X capability returned by the server and if our buffer is big enough or if we convert to iovecs on socket writes
and eliminate the copy to the CIFS buffer */ if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) {
bytes_sent = min_t(constunsignedint, CIFSMaxBufSize, count);
} else {
bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE)
& ~0xFF;
}
if (bytes_sent > count)
bytes_sent = count;
pSMB->DataOffset =
cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); if (buf)
memcpy(pSMB->Data, buf, bytes_sent); elseif (count != 0) { /* No buffer */
cifs_buf_release(pSMB); return -EINVAL;
} /* else setting file size with write of zero bytes */ if (wct == 14)
byte_count = bytes_sent + 1; /* pad */ else/* wct == 12 */
byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */
/* * Mask off high 16 bits when bytes written as returned by the * server is greater than bytes requested by the client. Some * OS/2 servers are known to set incorrect CountHigh values.
*/ if (*nbytes > count)
*nbytes &= 0xFFFF;
}
cifs_buf_release(pSMB);
/* Note: On -EAGAIN error only caller can retry on handle based calls
since file handle passed in no longer valid */
switch (mid->mid_state) { case MID_RESPONSE_RECEIVED:
result = cifs_check_receive(mid, tcon->ses->server, 0); if (result != 0) break;
written = le16_to_cpu(smb->CountHigh);
written <<= 16;
written += le16_to_cpu(smb->Count); /* * Mask off high 16 bits when bytes written as returned * by the server is greater than bytes requested by the * client. OS/2 servers are known to set incorrect * CountHigh values.
*/ if (written > wdata->subreq.len)
written &= 0xFFFF;
if (written < wdata->subreq.len) {
result = -ENOSPC;
} else {
result = written; if (written > 0)
__set_bit(NETFS_SREQ_MADE_PROGRESS, &wdata->subreq.flags);
} break; case MID_REQUEST_SUBMITTED:
trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_req_submitted);
__set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags);
result = -EAGAIN; break; case MID_RETRY_NEEDED:
trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_retry_needed);
__set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags);
result = -EAGAIN; break; case MID_RESPONSE_MALFORMED:
trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_malformed);
result = -EIO; break; default:
trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_unknown);
result = -EIO; break;
}
rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, 0,
&rsp_iov);
cifs_small_buf_release(pSMB);
cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); if (rc) {
cifs_dbg(FYI, "Send error Write2 = %d\n", rc);
} elseif (resp_buf_type == 0) { /* presumably this can not happen, but best to be safe */
rc = -EIO;
} else {
WRITE_RSP *pSMBr = (WRITE_RSP *)rsp_iov.iov_base;
*nbytes = le16_to_cpu(pSMBr->CountHigh);
*nbytes = (*nbytes) << 16;
*nbytes += le16_to_cpu(pSMBr->Count);
/* * Mask off high 16 bits when bytes written as returned by the * server is greater than bytes requested by the client. OS/2 * servers are known to set incorrect CountHigh values.
*/ if (*nbytes > count)
*nbytes &= 0xFFFF;
}
free_rsp_buf(resp_buf_type, rsp_iov.iov_base);
/* Note: On -EAGAIN error only caller can retry on handle based calls
since file handle passed in no longer valid */
if (rc) {
cifs_dbg(FYI, "Send error in Posix Lock = %d\n", rc);
} elseif (pLockData) { /* lock structure can be returned on get */
__u16 data_offset;
__u16 data_count;
rc = validate_t2((struct smb_t2_rsp *)pSMBr);
/* Note: On -EAGAIN error only caller can retry on handle based calls
since file handle passed in no longer valid */
return rc;
}
int
CIFSSMBClose(constunsignedint xid, struct cifs_tcon *tcon, int smb_file_id)
{ int rc = 0;
CLOSE_REQ *pSMB = NULL;
cifs_dbg(FYI, "In CIFSSMBClose\n");
/* do not retry on dead session on close */
rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); if (rc == -EAGAIN) return 0; if (rc) return rc;
pSMB->FileID = (__u16) smb_file_id;
pSMB->LastWriteTime = 0xFFFFFFFF;
pSMB->ByteCount = 0;
rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0);
cifs_small_buf_release(pSMB);
cifs_stats_inc(&tcon->stats.cifs_stats.num_closes); if (rc) { if (rc != -EINTR) { /* EINTR is expected when user ctl-c to kill app */
cifs_dbg(VFS, "Send error in Close = %d\n", rc);
}
}
/* Since session is dead, file will be closed on server already */ if (rc == -EAGAIN)
rc = 0;
return rc;
}
int
CIFSSMBFlush(constunsignedint xid, struct cifs_tcon *tcon, int smb_file_id)
{ int rc = 0;
FLUSH_REQ *pSMB = NULL;
cifs_dbg(FYI, "In CIFSSMBFlush\n");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.