*/
#include "includes.h"
+#include "smbd/smbd.h"
+#include "lib/util/sys_rw.h"
/* Cache priming module.
*
static bool prime_cache(
struct vfs_handle_struct * handle,
files_struct * fsp,
- SMB_OFF_T offset,
+ off_t offset,
size_t count)
{
- SMB_OFF_T * last;
+ off_t * last;
ssize_t nread;
- last = (SMB_OFF_T *)VFS_ADD_FSP_EXTENSION(handle, fsp, SMB_OFF_T);
+ last = VFS_ADD_FSP_EXTENSION(handle, fsp, off_t, NULL);
if (!last) {
return False;
}
DEBUG(module_debug,
("%s: doing readahead of %lld bytes at %lld for %s\n",
MODULE, (long long)g_readsz, (long long)*last,
- fsp->fsp_name));
+ fsp_str_dbg(fsp)));
- nread = sys_pread(fsp->fh->fd, g_readbuf, g_readsz, *last);
+ nread = sys_pread(fsp_get_io_fd(fsp), g_readbuf, g_readsz, *last);
if (nread < 0) {
*last = -1;
return False;
const char * service,
const char * user)
{
+ int ret;
+
module_debug = lp_parm_int(SNUM(handle->conn), MODULE, "debug", 100);
if (g_readbuf) {
/* Only allocate g_readbuf once. If the config changes and
return SMB_VFS_NEXT_CONNECT(handle, service, user);
}
+ ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
+ if (ret < 0) {
+ return ret;
+ }
+
g_readsz = conv_str_size(lp_parm_const_string(SNUM(handle->conn),
MODULE, "rsize", NULL));
g_readsz = 0;
}
- return SMB_VFS_NEXT_CONNECT(handle, service, user);
+ return 0;
}
static ssize_t cprime_sendfile(
int tofd,
files_struct * fromfsp,
const DATA_BLOB * header,
- SMB_OFF_T offset,
+ off_t offset,
size_t count)
{
if (g_readbuf && offset == 0) {
header, offset, count);
}
-static ssize_t cprime_read(
- vfs_handle_struct * handle,
- files_struct * fsp,
- void * data,
- size_t count)
-{
- SMB_OFF_T offset;
-
- offset = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR);
- if (offset >= 0 && g_readbuf) {
- prime_cache(handle, fsp, offset, count);
- SMB_VFS_LSEEK(fsp, offset, SEEK_SET);
- }
-
- return SMB_VFS_NEXT_READ(handle, fsp, data, count);
-}
-
static ssize_t cprime_pread(
vfs_handle_struct * handle,
files_struct * fsp,
void * data,
size_t count,
- SMB_OFF_T offset)
+ off_t offset)
{
if (g_readbuf) {
prime_cache(handle, fsp, offset, count);
return SMB_VFS_NEXT_PREAD(handle, fsp, data, count, offset);
}
-static vfs_op_tuple cprime_ops [] =
-{
- {SMB_VFS_OP(cprime_sendfile),
- SMB_VFS_OP_SENDFILE, SMB_VFS_LAYER_TRANSPARENT},
- {SMB_VFS_OP(cprime_pread),
- SMB_VFS_OP_PREAD, SMB_VFS_LAYER_TRANSPARENT},
- {SMB_VFS_OP(cprime_read),
- SMB_VFS_OP_READ, SMB_VFS_LAYER_TRANSPARENT},
- {SMB_VFS_OP(cprime_connect),
- SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_TRANSPARENT},
-
- {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
+static struct vfs_fn_pointers vfs_cacheprime_fns = {
+ .sendfile_fn = cprime_sendfile,
+ .pread_fn = cprime_pread,
+ .connect_fn = cprime_connect,
};
/* -------------------------------------------------------------------------
* -------------------------------------------------------------------------
*/
-NTSTATUS vfs_cacheprime_init(void);
-NTSTATUS vfs_cacheprime_init(void)
+static_decl_vfs;
+NTSTATUS vfs_cacheprime_init(TALLOC_CTX *ctx)
{
- return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, MODULE, cprime_ops);
+ return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, MODULE,
+ &vfs_cacheprime_fns);
}
/* vim: set sw=4 ts=4 tw=79 et: */