summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Disseldorp <ddiss@suse.de>2013-01-15 17:22:59 +0100
committerJeremy Allison <jra@samba.org>2013-01-16 23:15:06 +0100
commitef00eb90e56dfac2d823582cec92abf1fa9905f1 (patch)
tree3a582f5ce6ae0a1da9e55de2a380a79fa4bd8bdd /examples
parent2bde9636888067210dc38523b6fafaa0b179ec3b (diff)
downloadsamba-ef00eb90e56dfac2d823582cec92abf1fa9905f1.tar.gz
samba-ef00eb90e56dfac2d823582cec92abf1fa9905f1.tar.bz2
samba-ef00eb90e56dfac2d823582cec92abf1fa9905f1.zip
s3-vfs: add copy_chunk vfs hooks
copy_chunk copies n bytes from a source file at a specific offset to a destination file at a given offset. This interface will be used in handling smb2 FSCTL_SRV_COPYCHUNK ioctl requests. Use a pread/pwrite loop in vfs_default, so that requests referring to the same src and dest file are possible. Provide send and receive hooks for copy chunk VFS interface, allowing asynchronous behaviour. Check whether the request source offset + length exceeds the current size. Return STATUS_INVALID_VIEW_SIZE under such a condition, matching Windows server behaviour. Reviewed by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'examples')
-rw-r--r--examples/VFS/skel_opaque.c42
-rw-r--r--examples/VFS/skel_transparent.c75
2 files changed, 117 insertions, 0 deletions
diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c
index 6948d6452e..53c64cafb8 100644
--- a/examples/VFS/skel_opaque.c
+++ b/examples/VFS/skel_opaque.c
@@ -22,6 +22,7 @@
*/
#include "../source3/include/includes.h"
+#include "lib/util/tevent_ntstatus.h"
/* PLEASE,PLEASE READ THE VFS MODULES CHAPTER OF THE
SAMBA DEVELOPERS GUIDE!!!!!!
@@ -488,6 +489,45 @@ static struct file_id skel_file_id_create(vfs_handle_struct *handle,
return id;
}
+struct skel_cc_state {
+ uint64_t unused;
+};
+static struct tevent_req *skel_copy_chunk_send(struct vfs_handle_struct *handle,
+ TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct files_struct *src_fsp,
+ off_t src_off,
+ struct files_struct *dest_fsp,
+ off_t dest_off,
+ off_t num)
+{
+ struct tevent_req *req;
+ struct skel_cc_state *cc_state;
+
+ req = tevent_req_create(mem_ctx, &cc_state, struct skel_cc_state);
+ if (req == NULL) {
+ return NULL;
+ }
+
+ tevent_req_nterror(req, NT_STATUS_NOT_IMPLEMENTED);
+ return tevent_req_post(req, ev);
+}
+
+static NTSTATUS skel_copy_chunk_recv(struct vfs_handle_struct *handle,
+ struct tevent_req *req,
+ off_t *copied)
+{
+ NTSTATUS status;
+
+ if (tevent_req_is_nterror(req, &status)) {
+ tevent_req_received(req);
+ return status;
+ }
+ tevent_req_received(req);
+
+ return NT_STATUS_OK;
+}
+
static NTSTATUS skel_streaminfo(struct vfs_handle_struct *handle,
struct files_struct *fsp,
const char *fname,
@@ -825,6 +865,8 @@ struct vfs_fn_pointers skel_opaque_fns = {
.notify_watch_fn = skel_notify_watch,
.chflags_fn = skel_chflags,
.file_id_create_fn = skel_file_id_create,
+ .copy_chunk_send_fn = skel_copy_chunk_send,
+ .copy_chunk_recv_fn = skel_copy_chunk_recv,
.streaminfo_fn = skel_streaminfo,
.get_real_filename_fn = skel_get_real_filename,
diff --git a/examples/VFS/skel_transparent.c b/examples/VFS/skel_transparent.c
index 02e818424d..99feadec60 100644
--- a/examples/VFS/skel_transparent.c
+++ b/examples/VFS/skel_transparent.c
@@ -23,6 +23,7 @@
#include "../source3/include/includes.h"
#include "lib/util/tevent_unix.h"
+#include "lib/util/tevent_ntstatus.h"
/* PLEASE,PLEASE READ THE VFS MODULES CHAPTER OF THE
SAMBA DEVELOPERS GUIDE!!!!!!
@@ -572,6 +573,78 @@ static struct file_id skel_file_id_create(vfs_handle_struct *handle,
return SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
}
+struct skel_cc_state {
+ struct vfs_handle_struct *handle;
+ off_t copied;
+};
+static void skel_copy_chunk_done(struct tevent_req *subreq);
+
+static struct tevent_req *skel_copy_chunk_send(struct vfs_handle_struct *handle,
+ TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct files_struct *src_fsp,
+ off_t src_off,
+ struct files_struct *dest_fsp,
+ off_t dest_off,
+ off_t num)
+{
+ struct tevent_req *req;
+ struct tevent_req *subreq;
+ struct skel_cc_state *cc_state;
+
+ req = tevent_req_create(mem_ctx, &cc_state, struct skel_cc_state);
+ if (req == NULL) {
+ return NULL;
+ }
+
+ cc_state->handle = handle;
+ subreq = SMB_VFS_NEXT_COPY_CHUNK_SEND(handle, cc_state, ev,
+ src_fsp, src_off,
+ dest_fsp, dest_off, num);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ tevent_req_set_callback(subreq, skel_copy_chunk_done, req);
+ return req;
+}
+
+static void skel_copy_chunk_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct skel_cc_state *cc_state
+ = tevent_req_data(req, struct skel_cc_state);
+ NTSTATUS status;
+
+ status = SMB_VFS_NEXT_COPY_CHUNK_RECV(cc_state->handle,
+ subreq,
+ &cc_state->copied);
+ TALLOC_FREE(subreq);
+ if (tevent_req_nterror(req, status)) {
+ return;
+ }
+ tevent_req_done(req);
+}
+
+static NTSTATUS skel_copy_chunk_recv(struct vfs_handle_struct *handle,
+ struct tevent_req *req,
+ off_t *copied)
+{
+ struct skel_cc_state *cc_state
+ = tevent_req_data(req, struct skel_cc_state);
+ NTSTATUS status;
+
+ *copied = cc_state->copied;
+ if (tevent_req_is_nterror(req, &status)) {
+ tevent_req_received(req);
+ return status;
+ }
+
+ tevent_req_received(req);
+ return NT_STATUS_OK;
+}
+
static NTSTATUS skel_streaminfo(struct vfs_handle_struct *handle,
struct files_struct *fsp,
const char *fname,
@@ -898,6 +971,8 @@ struct vfs_fn_pointers skel_transparent_fns = {
.notify_watch_fn = skel_notify_watch,
.chflags_fn = skel_chflags,
.file_id_create_fn = skel_file_id_create,
+ .copy_chunk_send_fn = skel_copy_chunk_send,
+ .copy_chunk_recv_fn = skel_copy_chunk_recv,
.streaminfo_fn = skel_streaminfo,
.get_real_filename_fn = skel_get_real_filename,