summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/lib/util.c28
-rw-r--r--source/smbd/vfs.c20
2 files changed, 32 insertions, 16 deletions
diff --git a/source/lib/util.c b/source/lib/util.c
index 25b2700ae3d..3509294e8ea 100644
--- a/source/lib/util.c
+++ b/source/lib/util.c
@@ -905,8 +905,12 @@ int set_blocking(int fd, bool set)
#define TRANSFER_BUF_SIZE 65536
#endif
-ssize_t transfer_file_internal(int infd, int outfd, size_t n, ssize_t (*read_fn)(int, void *, size_t),
- ssize_t (*write_fn)(int, const void *, size_t))
+
+ssize_t transfer_file_internal(void *in_file,
+ void *out_file,
+ size_t n,
+ ssize_t (*read_fn)(void *, void *, size_t),
+ ssize_t (*write_fn)(void *, void *, size_t))
{
char *buf;
size_t total = 0;
@@ -921,7 +925,7 @@ ssize_t transfer_file_internal(int infd, int outfd, size_t n, ssize_t (*read_fn)
while (total < n) {
num_to_read_thistime = MIN((n - total), TRANSFER_BUF_SIZE);
- read_ret = (*read_fn)(infd, buf, num_to_read_thistime);
+ read_ret = (*read_fn)(in_file, buf, num_to_read_thistime);
if (read_ret == -1) {
DEBUG(0,("transfer_file_internal: read failure. Error = %s\n", strerror(errno) ));
SAFE_FREE(buf);
@@ -933,7 +937,7 @@ ssize_t transfer_file_internal(int infd, int outfd, size_t n, ssize_t (*read_fn)
num_written = 0;
while (num_written < read_ret) {
- write_ret = (*write_fn)(outfd,buf + num_written, read_ret - num_written);
+ write_ret = (*write_fn)(out_file, buf + num_written, read_ret - num_written);
if (write_ret == -1) {
DEBUG(0,("transfer_file_internal: write failure. Error = %s\n", strerror(errno) ));
@@ -953,9 +957,23 @@ ssize_t transfer_file_internal(int infd, int outfd, size_t n, ssize_t (*read_fn)
return (ssize_t)total;
}
+static ssize_t sys_read_fn(void *file, void *buf, size_t len)
+{
+ int *fd = (int *)file;
+
+ return sys_read(*fd, buf, len);
+}
+
+static ssize_t sys_write_fn(void *file, void *buf, size_t len)
+{
+ int *fd = (int *)file;
+
+ return sys_read(*fd, buf, len);
+}
+
SMB_OFF_T transfer_file(int infd,int outfd,SMB_OFF_T n)
{
- return (SMB_OFF_T)transfer_file_internal(infd, outfd, (size_t)n, sys_read, sys_write);
+ return (SMB_OFF_T)transfer_file_internal(&infd, &outfd, (size_t)n, sys_read_fn, sys_write_fn);
}
/*******************************************************************
diff --git a/source/smbd/vfs.c b/source/smbd/vfs.c
index bb4e77ed31f..b6b6b1c0f14 100644
--- a/source/smbd/vfs.c
+++ b/source/smbd/vfs.c
@@ -662,25 +662,23 @@ int vfs_fill_sparse(files_struct *fsp, SMB_OFF_T len)
Transfer some data (n bytes) between two file_struct's.
****************************************************************************/
-static files_struct *in_fsp;
-static files_struct *out_fsp;
-
-static ssize_t read_fn(int fd, void *buf, size_t len)
+static ssize_t vfs_read_fn(void *file, void *buf, size_t len)
{
- return SMB_VFS_READ(in_fsp, fd, buf, len);
+ struct files_struct *fsp = (struct files_struct *)file;
+
+ return SMB_VFS_READ(fsp, fsp->fh->fd, buf, len);
}
-static ssize_t write_fn(int fd, const void *buf, size_t len)
+static ssize_t vfs_write_fn(void *file, const void *buf, size_t len)
{
- return SMB_VFS_WRITE(out_fsp, fd, buf, len);
+ struct files_struct *fsp = (struct files_struct *)file;
+
+ return SMB_VFS_WRITE(fsp, fsp->fh->fd, buf, len);
}
SMB_OFF_T vfs_transfer_file(files_struct *in, files_struct *out, SMB_OFF_T n)
{
- in_fsp = in;
- out_fsp = out;
-
- return transfer_file_internal(in_fsp->fh->fd, out_fsp->fh->fd, n, read_fn, write_fn);
+ return transfer_file_internal(in, out, n, vfs_read_fn, vfs_write_fn);
}
/*******************************************************************