mirror of
https://github.com/samba-team/samba.git
synced 2024-12-24 21:34:56 +03:00
smbd: Move fake_sendfile to smb2_reply.c
Signed-off-by: David Mulder <dmulder@suse.com> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
56ac1efc70
commit
01ee69a958
@ -928,8 +928,6 @@ void reply_ulogoffX(struct smb_request *req);
|
|||||||
void reply_mknew(struct smb_request *req);
|
void reply_mknew(struct smb_request *req);
|
||||||
void reply_ctemp(struct smb_request *req);
|
void reply_ctemp(struct smb_request *req);
|
||||||
void reply_unlink(struct smb_request *req);
|
void reply_unlink(struct smb_request *req);
|
||||||
ssize_t fake_sendfile(struct smbXsrv_connection *xconn, files_struct *fsp,
|
|
||||||
off_t startpos, size_t nread);
|
|
||||||
ssize_t sendfile_short_send(struct smbXsrv_connection *xconn,
|
ssize_t sendfile_short_send(struct smbXsrv_connection *xconn,
|
||||||
files_struct *fsp,
|
files_struct *fsp,
|
||||||
ssize_t nread,
|
ssize_t nread,
|
||||||
@ -1036,6 +1034,8 @@ NTSTATUS unlink_internals(connection_struct *conn,
|
|||||||
struct smb_request *req,
|
struct smb_request *req,
|
||||||
uint32_t dirtype,
|
uint32_t dirtype,
|
||||||
struct smb_filename *smb_fname);
|
struct smb_filename *smb_fname);
|
||||||
|
ssize_t fake_sendfile(struct smbXsrv_connection *xconn, files_struct *fsp,
|
||||||
|
off_t startpos, size_t nread);
|
||||||
|
|
||||||
/* The following definitions come from smbd/seal.c */
|
/* The following definitions come from smbd/seal.c */
|
||||||
|
|
||||||
|
@ -2446,66 +2446,6 @@ static void fail_readraw(void)
|
|||||||
exit_server_cleanly(errstr);
|
exit_server_cleanly(errstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
Fake (read/write) sendfile. Returns -1 on read or write fail.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
ssize_t fake_sendfile(struct smbXsrv_connection *xconn, files_struct *fsp,
|
|
||||||
off_t startpos, size_t nread)
|
|
||||||
{
|
|
||||||
size_t bufsize;
|
|
||||||
size_t tosend = nread;
|
|
||||||
char *buf;
|
|
||||||
|
|
||||||
if (nread == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bufsize = MIN(nread, 65536);
|
|
||||||
|
|
||||||
if (!(buf = SMB_MALLOC_ARRAY(char, bufsize))) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (tosend > 0) {
|
|
||||||
ssize_t ret;
|
|
||||||
size_t cur_read;
|
|
||||||
|
|
||||||
cur_read = MIN(tosend, bufsize);
|
|
||||||
ret = read_file(fsp,buf,startpos,cur_read);
|
|
||||||
if (ret == -1) {
|
|
||||||
SAFE_FREE(buf);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we had a short read, fill with zeros. */
|
|
||||||
if (ret < cur_read) {
|
|
||||||
memset(buf + ret, '\0', cur_read - ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = write_data(xconn->transport.sock, buf, cur_read);
|
|
||||||
if (ret != cur_read) {
|
|
||||||
int saved_errno = errno;
|
|
||||||
/*
|
|
||||||
* Try and give an error message saying what
|
|
||||||
* client failed.
|
|
||||||
*/
|
|
||||||
DEBUG(0, ("write_data failed for client %s. "
|
|
||||||
"Error %s\n",
|
|
||||||
smbXsrv_connection_dbg(xconn),
|
|
||||||
strerror(saved_errno)));
|
|
||||||
SAFE_FREE(buf);
|
|
||||||
errno = saved_errno;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
tosend -= cur_read;
|
|
||||||
startpos += cur_read;
|
|
||||||
}
|
|
||||||
|
|
||||||
SAFE_FREE(buf);
|
|
||||||
return (ssize_t)nread;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Deal with the case of sendfile reading less bytes from the file than
|
Deal with the case of sendfile reading less bytes from the file than
|
||||||
requested. Fill with zeros (all we can do). Returns 0 on success
|
requested. Fill with zeros (all we can do). Returns 0 on success
|
||||||
|
@ -890,3 +890,63 @@ NTSTATUS unlink_internals(connection_struct *conn,
|
|||||||
|
|
||||||
return close_file_free(req, &fsp, NORMAL_CLOSE);
|
return close_file_free(req, &fsp, NORMAL_CLOSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
Fake (read/write) sendfile. Returns -1 on read or write fail.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
ssize_t fake_sendfile(struct smbXsrv_connection *xconn, files_struct *fsp,
|
||||||
|
off_t startpos, size_t nread)
|
||||||
|
{
|
||||||
|
size_t bufsize;
|
||||||
|
size_t tosend = nread;
|
||||||
|
char *buf;
|
||||||
|
|
||||||
|
if (nread == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bufsize = MIN(nread, 65536);
|
||||||
|
|
||||||
|
if (!(buf = SMB_MALLOC_ARRAY(char, bufsize))) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (tosend > 0) {
|
||||||
|
ssize_t ret;
|
||||||
|
size_t cur_read;
|
||||||
|
|
||||||
|
cur_read = MIN(tosend, bufsize);
|
||||||
|
ret = read_file(fsp,buf,startpos,cur_read);
|
||||||
|
if (ret == -1) {
|
||||||
|
SAFE_FREE(buf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If we had a short read, fill with zeros. */
|
||||||
|
if (ret < cur_read) {
|
||||||
|
memset(buf + ret, '\0', cur_read - ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = write_data(xconn->transport.sock, buf, cur_read);
|
||||||
|
if (ret != cur_read) {
|
||||||
|
int saved_errno = errno;
|
||||||
|
/*
|
||||||
|
* Try and give an error message saying what
|
||||||
|
* client failed.
|
||||||
|
*/
|
||||||
|
DEBUG(0, ("write_data failed for client %s. "
|
||||||
|
"Error %s\n",
|
||||||
|
smbXsrv_connection_dbg(xconn),
|
||||||
|
strerror(saved_errno)));
|
||||||
|
SAFE_FREE(buf);
|
||||||
|
errno = saved_errno;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
tosend -= cur_read;
|
||||||
|
startpos += cur_read;
|
||||||
|
}
|
||||||
|
|
||||||
|
SAFE_FREE(buf);
|
||||||
|
return (ssize_t)nread;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user