summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2008-01-10 13:30:43 +0100
committerMichael Adam <obnox@samba.org>2008-01-10 13:30:46 +0100
commit5661ac6a389620ac543a384832de9ee9b64893c7 (patch)
tree0d606250a2d50ae2a5617697f67dfa775bd77674 /source3
parent9f67ee6334f36f30ddfc2e86459cb764bccf1edf (diff)
downloadsamba-5661ac6a389620ac543a384832de9ee9b64893c7.tar.gz
samba-5661ac6a389620ac543a384832de9ee9b64893c7.tar.bz2
samba-5661ac6a389620ac543a384832de9ee9b64893c7.zip
Correctly abstract the transfer_file mechanism with callbacks and void ptrs.
This removes the in_fsp and out_fsp global variables hack from smbd/vfs.c. Michael (This used to be commit b2e7cdc6e899ca3c16edbb6c8786ff9aa999fa6e)
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/util.c28
-rw-r--r--source3/smbd/vfs.c20
2 files changed, 32 insertions, 16 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 25b2700ae3..3509294e8e 100644
--- a/source3/lib/util.c
+++ b/source3/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/source3/smbd/vfs.c b/source3/smbd/vfs.c
index bb4e77ed31..b6b6b1c0f1 100644
--- a/source3/smbd/vfs.c
+++ b/source3/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);
}
/*******************************************************************