r14736: - the ntvfs subsystem should not know about smb_server.h
[jra/samba/.git] / source4 / ntvfs / simple / vfs_simple.c
index 8bce111e9c60537b2d0a7bc640623d5012e742f5..2347f31bde118d511190318e1d64d23af4a04d3a 100644 (file)
 */
 
 #include "includes.h"
+#include "system/dir.h"
+#include "system/filesys.h"
 #include "svfs.h"
+#include "system/time.h"
+#include "dlinklist.h"
+#include "ntvfs/ntvfs.h"
+#include "ntvfs/simple/proto.h"
 
 #ifndef O_DIRECTORY
 #define O_DIRECTORY 0
 #endif
 
-#define CHECK_READ_ONLY(req) do { if (lp_readonly(req->tcon->service)) return NT_STATUS_ACCESS_DENIED; } while (0)
-
-#ifndef HAVE_PREAD
-static ssize_t pread(int __fd, void *__buf, size_t __nbytes, off_t __offset)
-{
-       if (lseek(__fd, __offset, SEEK_SET) != __offset) {
-               return -1;
-       }
-       return read(__fd, __buf, __nbytes);
-}
-#endif
-
-#ifndef HAVE_PWRITE
-static ssize_t pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset)
-{
-       if (lseek(__fd, __offset, SEEK_SET) != __offset) {
-               return -1;
-       }
-       return write(__fd, __buf, __nbytes);
-}
-#endif
+#define CHECK_READ_ONLY(req) do { if (lp_readonly(ntvfs->ctx->config.snum)) return NT_STATUS_ACCESS_DENIED; } while (0)
 
 /*
   connect to a share - used when a tree_connect operation comes
@@ -61,19 +47,19 @@ static ssize_t pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offs
   directory exists (tho it doesn't need to be accessible by the user,
   that comes later)
 */
-static NTSTATUS svfs_connect(struct smbsrv_request *req, const char *sharename)
+static NTSTATUS svfs_connect(struct ntvfs_module_context *ntvfs,
+                            struct ntvfs_request *req, const char *sharename)
 {
        struct stat st;
-       struct smbsrv_tcon *tcon = req->tcon;
        struct svfs_private *private;
+       int snum = ntvfs->ctx->config.snum;
 
-       tcon->ntvfs_private = talloc_p(tcon, struct svfs_private);
-
-       private = tcon->ntvfs_private;
+       private = talloc(ntvfs, struct svfs_private);
 
        private->next_search_handle = 0;
-       private->connectpath = talloc_strdup(tcon, lp_pathname(tcon->service));
+       private->connectpath = talloc_strdup(private, lp_pathname(snum));
        private->open_files = NULL;
+       private->search = NULL;
 
        /* the directory must exist */
        if (stat(private->connectpath, &st) != 0 || !S_ISDIR(st.st_mode)) {
@@ -82,8 +68,12 @@ static NTSTATUS svfs_connect(struct smbsrv_request *req, const char *sharename)
                return NT_STATUS_BAD_NETWORK_NAME;
        }
 
-       tcon->fs_type = talloc_strdup(tcon, "NTFS");
-       tcon->dev_type = talloc_strdup(tcon, "A:");
+       ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
+       NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
+       ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
+       NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
+
+       ntvfs->private_data = private;
 
        DEBUG(0,("WARNING: ntvfs simple: connect to share [%s] with ROOT privileges!!!\n",sharename));
 
@@ -93,7 +83,7 @@ static NTSTATUS svfs_connect(struct smbsrv_request *req, const char *sharename)
 /*
   disconnect from a share
 */
-static NTSTATUS svfs_disconnect(struct smbsrv_tcon *tcon)
+static NTSTATUS svfs_disconnect(struct ntvfs_module_context *ntvfs)
 {
        return NT_STATUS_OK;
 }
@@ -116,13 +106,15 @@ static struct svfs_file *find_fd(struct svfs_private *private, int fd)
   delete a file - the dirtype specifies the file types to include in the search. 
   The name can contain CIFS wildcards, but rarely does (except with OS/2 clients)
 */
-static NTSTATUS svfs_unlink(struct smbsrv_request *req, struct smb_unlink *unl)
+static NTSTATUS svfs_unlink(struct ntvfs_module_context *ntvfs,
+                           struct ntvfs_request *req,
+                           union smb_unlink *unl)
 {
        char *unix_path;
 
        CHECK_READ_ONLY(req);
 
-       unix_path = svfs_unix_path(req, unl->in.pattern);
+       unix_path = svfs_unix_path(ntvfs, req, unl->unlink.in.pattern);
 
        /* ignoring wildcards ... */
        if (unlink(unix_path) == -1) {
@@ -136,7 +128,8 @@ static NTSTATUS svfs_unlink(struct smbsrv_request *req, struct smb_unlink *unl)
 /*
   ioctl interface - we don't do any
 */
-static NTSTATUS svfs_ioctl(struct smbsrv_request *req, union smb_ioctl *io)
+static NTSTATUS svfs_ioctl(struct ntvfs_module_context *ntvfs,
+                          struct ntvfs_request *req, union smb_ioctl *io)
 {
        return NT_STATUS_INVALID_PARAMETER;
 }
@@ -144,12 +137,14 @@ static NTSTATUS svfs_ioctl(struct smbsrv_request *req, union smb_ioctl *io)
 /*
   check if a directory exists
 */
-static NTSTATUS svfs_chkpath(struct smbsrv_request *req, struct smb_chkpath *cp)
+static NTSTATUS svfs_chkpath(struct ntvfs_module_context *ntvfs,
+                            struct ntvfs_request *req,
+                            union smb_chkpath *cp)
 {
        char *unix_path;
        struct stat st;
 
-       unix_path = svfs_unix_path(req, cp->in.path);
+       unix_path = svfs_unix_path(ntvfs, req, cp->chkpath.in.path);
 
        if (stat(unix_path, &st) == -1) {
                return map_nt_error_from_unix(errno);
@@ -162,10 +157,22 @@ static NTSTATUS svfs_chkpath(struct smbsrv_request *req, struct smb_chkpath *cp)
        return NT_STATUS_OK;
 }
 
+/*
+  build a file_id from a stat struct
+*/
+static uint64_t svfs_file_id(struct stat *st)
+{
+       uint64_t ret = st->st_ino;
+       ret <<= 32;
+       ret |= st->st_dev;
+       return ret;
+}
+
 /*
   approximately map a struct stat to a generic fileinfo struct
 */
-static NTSTATUS svfs_map_fileinfo(struct smbsrv_request *req, union smb_fileinfo *info, 
+static NTSTATUS svfs_map_fileinfo(struct ntvfs_module_context *ntvfs,
+                                 struct ntvfs_request *req, union smb_fileinfo *info, 
                                  struct stat *st, const char *unix_path)
 {
        struct svfs_dir *dir = NULL;
@@ -203,7 +210,6 @@ static NTSTATUS svfs_map_fileinfo(struct smbsrv_request *req, union smb_fileinfo
        info->generic.out.num_eas = 0;
        info->generic.out.fname.s = talloc_strdup(req, short_name);
        info->generic.out.alt_fname.s = talloc_strdup(req, short_name);
-       info->generic.out.ex_attrib = 0;
        info->generic.out.compressed_size = 0;
        info->generic.out.format = 0;
        info->generic.out.unit_shift = 0;
@@ -218,7 +224,7 @@ static NTSTATUS svfs_map_fileinfo(struct smbsrv_request *req, union smb_fileinfo
        info->generic.out.num_streams = 0;
        /* setup a single data stream */
        info->generic.out.num_streams = 1 + (dir?dir->count:0);
-       info->generic.out.streams = talloc_array_p(req, 
+       info->generic.out.streams = talloc_array(req, 
                                                   struct stream_struct,
                                                   info->generic.out.num_streams);
        if (!info->generic.out.streams) {
@@ -241,73 +247,74 @@ static NTSTATUS svfs_map_fileinfo(struct smbsrv_request *req, union smb_fileinfo
 /*
   return info on a pathname
 */
-static NTSTATUS svfs_qpathinfo(struct smbsrv_request *req, union smb_fileinfo *info)
+static NTSTATUS svfs_qpathinfo(struct ntvfs_module_context *ntvfs,
+                              struct ntvfs_request *req, union smb_fileinfo *info)
 {
        char *unix_path;
        struct stat st;
 
-       DEBUG(19,("svfs_qpathinfo: file %s level 0x%x\n", info->generic.in.fname, info->generic.level));
+       DEBUG(19,("svfs_qpathinfo: file %s level 0x%x\n", info->generic.in.file.path, info->generic.level));
        if (info->generic.level != RAW_FILEINFO_GENERIC) {
-               return ntvfs_map_qpathinfo(req, info);
+               return ntvfs_map_qpathinfo(ntvfs, req, info);
        }
        
-       unix_path = svfs_unix_path(req, info->generic.in.fname);
+       unix_path = svfs_unix_path(ntvfs, req, info->generic.in.file.path);
        DEBUG(19,("svfs_qpathinfo: file %s\n", unix_path));
        if (stat(unix_path, &st) == -1) {
                DEBUG(19,("svfs_qpathinfo: file %s errno=%d\n", unix_path, errno));
-               if (errno == 0)
-                       errno = ENOENT;
                return map_nt_error_from_unix(errno);
        }
        DEBUG(19,("svfs_qpathinfo: file %s, stat done\n", unix_path));
-       return svfs_map_fileinfo(req, info, &st, unix_path);
+       return svfs_map_fileinfo(ntvfs, req, info, &st, unix_path);
 }
 
 /*
   query info on a open file
 */
-static NTSTATUS svfs_qfileinfo(struct smbsrv_request *req, union smb_fileinfo *info)
+static NTSTATUS svfs_qfileinfo(struct ntvfs_module_context *ntvfs,
+                              struct ntvfs_request *req, union smb_fileinfo *info)
 {
-       struct svfs_private *private = req->tcon->ntvfs_private;
+       struct svfs_private *private = ntvfs->private_data;
        struct svfs_file *f;
        struct stat st;
 
        if (info->generic.level != RAW_FILEINFO_GENERIC) {
-               return ntvfs_map_qfileinfo(req, info);
+               return ntvfs_map_qfileinfo(ntvfs, req, info);
        }
 
-       f = find_fd(private, info->generic.in.fnum);
+       f = find_fd(private, info->generic.in.file.fnum);
        if (!f) {
                return NT_STATUS_INVALID_HANDLE;
        }
        
-       if (fstat(info->generic.in.fnum, &st) == -1) {
-               if (errno == 0)
-                       errno = ENOENT;
+       if (fstat(info->generic.in.file.fnum, &st) == -1) {
                return map_nt_error_from_unix(errno);
        }
 
-       return svfs_map_fileinfo(req, info, &st, f->name);
+       return svfs_map_fileinfo(ntvfs, req,info, &st, f->name);
 }
 
 
 /*
   open a file
 */
-static NTSTATUS svfs_open(struct smbsrv_request *req, union smb_open *io)
+static NTSTATUS svfs_open(struct ntvfs_module_context *ntvfs,
+                         struct ntvfs_request *req, union smb_open *io)
 {
-       struct svfs_private *private = req->tcon->ntvfs_private;
+       struct svfs_private *private = ntvfs->private_data;
        char *unix_path;
        struct stat st;
        int fd, flags;
        struct svfs_file *f;
        int create_flags, rdwr_flags;
+       BOOL readonly;
        
        if (io->generic.level != RAW_OPEN_GENERIC) {
-               return ntvfs_map_open(req, io);
+               return ntvfs_map_open(ntvfs, req, io);
        }
 
-       if (lp_readonly(req->tcon->service)) {
+       readonly = lp_readonly(ntvfs->ctx->config.snum);
+       if (readonly) {
                create_flags = 0;
                rdwr_flags = O_RDONLY;
        } else {
@@ -315,7 +322,7 @@ static NTSTATUS svfs_open(struct smbsrv_request *req, union smb_open *io)
                rdwr_flags = O_RDWR;
        }
 
-       unix_path = svfs_unix_path(req, io->ntcreatex.in.fname);
+       unix_path = svfs_unix_path(ntvfs, req, io->ntcreatex.in.fname);
 
        switch (io->generic.in.open_disposition) {
        case NTCREATEX_DISP_SUPERSEDE:
@@ -341,7 +348,7 @@ static NTSTATUS svfs_open(struct smbsrv_request *req, union smb_open *io)
 
        if (io->generic.in.create_options & NTCREATEX_OPTIONS_DIRECTORY) {
                flags = O_RDONLY | O_DIRECTORY;
-               if (lp_readonly(req->tcon->service)) {
+               if (readonly) {
                        goto do_open;
                }
                switch (io->generic.in.open_disposition) {
@@ -363,22 +370,20 @@ static NTSTATUS svfs_open(struct smbsrv_request *req, union smb_open *io)
 do_open:
        fd = open(unix_path, flags, 0644);
        if (fd == -1) {
-               if (errno == 0)
-                       errno = ENOENT;
                return map_nt_error_from_unix(errno);
        }
 
        if (fstat(fd, &st) == -1) {
                DEBUG(9,("svfs_open: fstat errno=%d\n", errno));
-               if (errno == 0)
-                       errno = ENOENT;
                close(fd);
                return map_nt_error_from_unix(errno);
        }
 
-       f = talloc_p(req->tcon, struct svfs_file);
+       f = talloc(ntvfs, struct svfs_file);
+       NT_STATUS_HAVE_NO_MEMORY(f);
        f->fd = fd;
-       f->name = talloc_strdup(req->tcon, unix_path);
+       f->name = talloc_strdup(f, unix_path);
+       NT_STATUS_HAVE_NO_MEMORY(f->name);
 
        DLIST_ADD(private->open_files, f);
 
@@ -388,7 +393,7 @@ do_open:
        unix_to_nt_time(&io->generic.out.access_time, st.st_atime);
        unix_to_nt_time(&io->generic.out.write_time,  st.st_mtime);
        unix_to_nt_time(&io->generic.out.change_time, st.st_mtime);
-       io->generic.out.fnum = fd;
+       io->generic.out.file.fnum = fd;
        io->generic.out.alloc_size = st.st_size;
        io->generic.out.size = st.st_size;
        io->generic.out.attrib = svfs_unix_to_dos_attrib(st.st_mode);
@@ -400,7 +405,8 @@ do_open:
 /*
   create a directory
 */
-static NTSTATUS svfs_mkdir(struct smbsrv_request *req, union smb_mkdir *md)
+static NTSTATUS svfs_mkdir(struct ntvfs_module_context *ntvfs,
+                          struct ntvfs_request *req, union smb_mkdir *md)
 {
        char *unix_path;
 
@@ -410,7 +416,7 @@ static NTSTATUS svfs_mkdir(struct smbsrv_request *req, union smb_mkdir *md)
                return NT_STATUS_INVALID_LEVEL;
        }
 
-       unix_path = svfs_unix_path(req, md->mkdir.in.path);
+       unix_path = svfs_unix_path(ntvfs, req, md->mkdir.in.path);
 
        if (mkdir(unix_path, 0777) == -1) {
                return map_nt_error_from_unix(errno);
@@ -422,13 +428,14 @@ static NTSTATUS svfs_mkdir(struct smbsrv_request *req, union smb_mkdir *md)
 /*
   remove a directory
 */
-static NTSTATUS svfs_rmdir(struct smbsrv_request *req, struct smb_rmdir *rd)
+static NTSTATUS svfs_rmdir(struct ntvfs_module_context *ntvfs,
+                          struct ntvfs_request *req, struct smb_rmdir *rd)
 {
        char *unix_path;
 
        CHECK_READ_ONLY(req);
 
-       unix_path = svfs_unix_path(req, rd->in.path);
+       unix_path = svfs_unix_path(ntvfs, req, rd->in.path);
 
        if (rmdir(unix_path) == -1) {
                return map_nt_error_from_unix(errno);
@@ -440,7 +447,8 @@ static NTSTATUS svfs_rmdir(struct smbsrv_request *req, struct smb_rmdir *rd)
 /*
   rename a set of files
 */
-static NTSTATUS svfs_rename(struct smbsrv_request *req, union smb_rename *ren)
+static NTSTATUS svfs_rename(struct ntvfs_module_context *ntvfs,
+                           struct ntvfs_request *req, union smb_rename *ren)
 {
        char *unix_path1, *unix_path2;
 
@@ -450,10 +458,10 @@ static NTSTATUS svfs_rename(struct smbsrv_request *req, union smb_rename *ren)
                return NT_STATUS_INVALID_LEVEL;
        }
 
-       unix_path1 = svfs_unix_path(req, ren->rename.in.pattern1);
-       unix_path2 = svfs_unix_path(req, ren->rename.in.pattern2);
+       unix_path1 = svfs_unix_path(ntvfs, req, ren->rename.in.pattern1);
+       unix_path2 = svfs_unix_path(ntvfs, req, ren->rename.in.pattern2);
 
-       if (rename(unix_path1, unix_path2) != 0) {
+       if (rename(unix_path1, unix_path2) == -1) {
                return map_nt_error_from_unix(errno);
        }
        
@@ -463,7 +471,8 @@ static NTSTATUS svfs_rename(struct smbsrv_request *req, union smb_rename *ren)
 /*
   copy a set of files
 */
-static NTSTATUS svfs_copy(struct smbsrv_request *req, struct smb_copy *cp)
+static NTSTATUS svfs_copy(struct ntvfs_module_context *ntvfs,
+                         struct ntvfs_request *req, struct smb_copy *cp)
 {
        return NT_STATUS_NOT_SUPPORTED;
 }
@@ -471,7 +480,8 @@ static NTSTATUS svfs_copy(struct smbsrv_request *req, struct smb_copy *cp)
 /*
   read from a file
 */
-static NTSTATUS svfs_read(struct smbsrv_request *req, union smb_read *rd)
+static NTSTATUS svfs_read(struct ntvfs_module_context *ntvfs,
+                         struct ntvfs_request *req, union smb_read *rd)
 {
        ssize_t ret;
 
@@ -479,7 +489,7 @@ static NTSTATUS svfs_read(struct smbsrv_request *req, union smb_read *rd)
                return NT_STATUS_NOT_SUPPORTED;
        }
 
-       ret = pread(rd->readx.in.fnum, 
+       ret = pread(rd->readx.in.file.fnum, 
                    rd->readx.out.data, 
                    rd->readx.in.maxcnt,
                    rd->readx.in.offset);
@@ -497,53 +507,37 @@ static NTSTATUS svfs_read(struct smbsrv_request *req, union smb_read *rd)
 /*
   write to a file
 */
-static NTSTATUS svfs_write(struct smbsrv_request *req, union smb_write *wr)
+static NTSTATUS svfs_write(struct ntvfs_module_context *ntvfs,
+                          struct ntvfs_request *req, union smb_write *wr)
 {
        ssize_t ret;
 
-       CHECK_READ_ONLY(req);
+       if (wr->generic.level != RAW_WRITE_WRITEX) {
+               return ntvfs_map_write(ntvfs, req, wr);
+       }
 
-       switch (wr->generic.level) {
-       case RAW_WRITE_WRITEX:
-               ret = pwrite(wr->writex.in.fnum, 
-                            wr->writex.in.data, 
-                            wr->writex.in.count,
-                            wr->writex.in.offset);
-               if (ret == -1) {
-                       return map_nt_error_from_unix(errno);
-               }
-               
-               wr->writex.out.nwritten = ret;
-               wr->writex.out.remaining = 0; /* should fill this in? */
-
-               return NT_STATUS_OK;
-
-       case RAW_WRITE_WRITE:
-               if (wr->write.in.count == 0) {
-                       /* a truncate! */
-                       ret = ftruncate(wr->write.in.fnum, wr->write.in.offset);
-               } else {
-                       ret = pwrite(wr->write.in.fnum, 
-                                    wr->write.in.data, 
-                                    wr->write.in.count,
-                                    wr->write.in.offset);
-               }
-               if (ret == -1) {
-                       return map_nt_error_from_unix(errno);
-               }
-               
-               wr->write.out.nwritten = ret;
+       CHECK_READ_ONLY(req);
 
-               return NT_STATUS_OK;
+       ret = pwrite(wr->writex.in.file.fnum, 
+                    wr->writex.in.data, 
+                    wr->writex.in.count,
+                    wr->writex.in.offset);
+       if (ret == -1) {
+               return map_nt_error_from_unix(errno);
        }
-
-       return NT_STATUS_NOT_SUPPORTED;
+               
+       wr->writex.out.nwritten = ret;
+       wr->writex.out.remaining = 0; /* should fill this in? */
+       
+       return NT_STATUS_OK;
 }
 
 /*
   seek in a file
 */
-static NTSTATUS svfs_seek(struct smbsrv_request *req, struct smb_seek *io)
+static NTSTATUS svfs_seek(struct ntvfs_module_context *ntvfs,
+                         struct ntvfs_request *req,
+                         union smb_seek *io)
 {
        return NT_STATUS_NOT_SUPPORTED;
 }
@@ -551,18 +545,22 @@ static NTSTATUS svfs_seek(struct smbsrv_request *req, struct smb_seek *io)
 /*
   flush a file
 */
-static NTSTATUS svfs_flush(struct smbsrv_request *req, struct smb_flush *io)
+static NTSTATUS svfs_flush(struct ntvfs_module_context *ntvfs,
+                          struct ntvfs_request *req,
+                          union smb_flush *io)
 {
-       fsync(io->in.fnum);
+       fsync(io->flush.in.file.fnum);
        return NT_STATUS_OK;
 }
 
 /*
   close a file
 */
-static NTSTATUS svfs_close(struct smbsrv_request *req, union smb_close *io)
+static NTSTATUS svfs_close(struct ntvfs_module_context *ntvfs,
+                          struct ntvfs_request *req,
+                          union smb_close *io)
 {
-       struct svfs_private *private = req->tcon->ntvfs_private;
+       struct svfs_private *private = ntvfs->private_data;
        struct svfs_file *f;
 
        if (io->generic.level != RAW_CLOSE_CLOSE) {
@@ -570,12 +568,12 @@ static NTSTATUS svfs_close(struct smbsrv_request *req, union smb_close *io)
                return NT_STATUS_INVALID_LEVEL;
        }
 
-       f = find_fd(private, io->close.in.fnum);
+       f = find_fd(private, io->close.in.file.fnum);
        if (!f) {
                return NT_STATUS_INVALID_HANDLE;
        }
 
-       if (close(io->close.in.fnum) != 0) {
+       if (close(io->close.in.file.fnum) == -1) {
                return map_nt_error_from_unix(errno);
        }
 
@@ -587,17 +585,46 @@ static NTSTATUS svfs_close(struct smbsrv_request *req, union smb_close *io)
 }
 
 /*
-  exit - closing files?
+  exit - closing files
 */
-static NTSTATUS svfs_exit(struct smbsrv_request *req)
+static NTSTATUS svfs_exit(struct ntvfs_module_context *ntvfs,
+                         struct ntvfs_request *req)
 {
        return NT_STATUS_NOT_SUPPORTED;
 }
 
+/*
+  logoff - closing files
+*/
+static NTSTATUS svfs_logoff(struct ntvfs_module_context *ntvfs,
+                           struct ntvfs_request *req)
+{
+       return NT_STATUS_NOT_SUPPORTED;
+}
+
+/*
+  setup for an async call
+*/
+static NTSTATUS svfs_async_setup(struct ntvfs_module_context *ntvfs,
+                                struct ntvfs_request *req, 
+                                void *private)
+{
+       return NT_STATUS_OK;
+}
+
+/*
+  cancel an async call
+*/
+static NTSTATUS svfs_cancel(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req)
+{
+       return NT_STATUS_UNSUCCESSFUL;
+}
+
 /*
   lock a byte range
 */
-static NTSTATUS svfs_lock(struct smbsrv_request *req, union smb_lock *lck)
+static NTSTATUS svfs_lock(struct ntvfs_module_context *ntvfs,
+                         struct ntvfs_request *req, union smb_lock *lck)
 {
        DEBUG(0,("REWRITE: not doing byte range locking!\n"));
        return NT_STATUS_OK;
@@ -606,7 +633,8 @@ static NTSTATUS svfs_lock(struct smbsrv_request *req, union smb_lock *lck)
 /*
   set info on a pathname
 */
-static NTSTATUS svfs_setpathinfo(struct smbsrv_request *req, union smb_setfileinfo *st)
+static NTSTATUS svfs_setpathinfo(struct ntvfs_module_context *ntvfs,
+                                struct ntvfs_request *req, union smb_setfileinfo *st)
 {
        CHECK_READ_ONLY(req);
 
@@ -616,7 +644,8 @@ static NTSTATUS svfs_setpathinfo(struct smbsrv_request *req, union smb_setfilein
 /*
   set info on a open file
 */
-static NTSTATUS svfs_setfileinfo(struct smbsrv_request *req, 
+static NTSTATUS svfs_setfileinfo(struct ntvfs_module_context *ntvfs,
+                                struct ntvfs_request *req, 
                                 union smb_setfileinfo *info)
 {
        struct utimbuf unix_times;
@@ -627,15 +656,15 @@ static NTSTATUS svfs_setfileinfo(struct smbsrv_request *req,
        switch (info->generic.level) {
        case RAW_SFILEINFO_END_OF_FILE_INFO:
        case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
-               if (ftruncate(info->end_of_file_info.file.fnum, 
-                             info->end_of_file_info.in.size) != 0) {
+               if (ftruncate(info->end_of_file_info.in.file.fnum, 
+                             info->end_of_file_info.in.size) == -1) {
                        return map_nt_error_from_unix(errno);
                }
                break;
        case RAW_SFILEINFO_SETATTRE:
                unix_times.actime = info->setattre.in.access_time;
                unix_times.modtime = info->setattre.in.write_time;
-               fd = info->setattre.file.fnum;
+               fd = info->setattre.in.file.fnum;
        
                if (unix_times.actime == 0 && unix_times.modtime == 0) {
                        break;
@@ -651,6 +680,10 @@ static NTSTATUS svfs_setfileinfo(struct smbsrv_request *req,
                        return NT_STATUS_ACCESS_DENIED;
                }
                break;
+       default:
+               DEBUG(2,("svfs_setfileinfo: level %d not implemented\n", 
+                        info->generic.level));
+               return NT_STATUS_NOT_IMPLEMENTED;
        }
        return NT_STATUS_OK;
 }
@@ -659,13 +692,14 @@ static NTSTATUS svfs_setfileinfo(struct smbsrv_request *req,
 /*
   return filesystem space info
 */
-static NTSTATUS svfs_fsinfo(struct smbsrv_request *req, union smb_fsinfo *fs)
+static NTSTATUS svfs_fsinfo(struct ntvfs_module_context *ntvfs,
+                           struct ntvfs_request *req, union smb_fsinfo *fs)
 {
-       struct svfs_private *private = req->tcon->ntvfs_private;
+       struct svfs_private *private = ntvfs->private_data;
        struct stat st;
 
        if (fs->generic.level != RAW_QFS_GENERIC) {
-               return ntvfs_map_fsinfo(req, fs);
+               return ntvfs_map_fsinfo(ntvfs, req, fs);
        }
 
        if (sys_fsusage(private->connectpath, 
@@ -690,8 +724,8 @@ static NTSTATUS svfs_fsinfo(struct smbsrv_request *req, union smb_fsinfo *fs)
        fs->generic.out.quota_soft = 0;
        fs->generic.out.quota_hard = 0;
        fs->generic.out.quota_flags = 0;
-       fs->generic.out.volume_name = talloc_strdup(req, lp_servicename(req->tcon->service));
-       fs->generic.out.fs_type = req->tcon->fs_type;
+       fs->generic.out.volume_name = talloc_strdup(req, lp_servicename(ntvfs->ctx->config.snum));
+       fs->generic.out.fs_type = ntvfs->ctx->fs_type;
 
        return NT_STATUS_OK;
 }
@@ -700,16 +734,17 @@ static NTSTATUS svfs_fsinfo(struct smbsrv_request *req, union smb_fsinfo *fs)
 /*
   return filesystem attribute info
 */
-static NTSTATUS svfs_fsattr(struct smbsrv_request *req, union smb_fsattr *fs)
+static NTSTATUS svfs_fsattr(struct ntvfs_module_context *ntvfs,
+                           struct ntvfs_request *req, union smb_fsattr *fs)
 {
        struct stat st;
-       struct svfs_private *private = req->tcon->ntvfs_private;
+       struct svfs_private *private = ntvfs->private_data;
 
        if (fs->generic.level != RAW_FSATTR_GENERIC) {
-               return ntvfs_map_fsattr(req, fs);
+               return ntvfs_map_fsattr(ntvfs, req, fs);
        }
 
-       if (stat(private->connectpath, &st) != 0) {
+       if (stat(private->connectpath, &st) == -1) {
                return map_nt_error_from_unix(errno);
        }
 
@@ -731,7 +766,8 @@ static NTSTATUS svfs_fsattr(struct smbsrv_request *req, union smb_fsattr *fs)
 /*
   return print queue info
 */
-static NTSTATUS svfs_lpq(struct smbsrv_request *req, union smb_lpq *lpq)
+static NTSTATUS svfs_lpq(struct ntvfs_module_context *ntvfs,
+                        struct ntvfs_request *req, union smb_lpq *lpq)
 {
        return NT_STATUS_NOT_SUPPORTED;
 }
@@ -739,32 +775,31 @@ static NTSTATUS svfs_lpq(struct smbsrv_request *req, union smb_lpq *lpq)
 /* 
    list files in a directory matching a wildcard pattern
 */
-static NTSTATUS svfs_search_first(struct smbsrv_request *req, union smb_search_first *io, 
+static NTSTATUS svfs_search_first(struct ntvfs_module_context *ntvfs,
+                                 struct ntvfs_request *req, union smb_search_first *io, 
                                  void *search_private, 
                                  BOOL (*callback)(void *, union smb_search_data *))
 {
        struct svfs_dir *dir;
        int i;
-       struct svfs_private *private = req->tcon->ntvfs_private;
+       struct svfs_private *private = ntvfs->private_data;
        struct search_state *search;
        union smb_search_data file;
-       TALLOC_CTX *mem_ctx;
        uint_t max_count;
 
        if (io->generic.level != RAW_SEARCH_BOTH_DIRECTORY_INFO) {
                return NT_STATUS_NOT_SUPPORTED;
        }
 
-       search = talloc_zero(private, sizeof(struct search_state));
+       search = talloc_zero(private, struct search_state);
        if (!search) {
                return NT_STATUS_NO_MEMORY;
        }
 
        max_count = io->t2ffirst.in.max_count;
 
-       dir = svfs_list(private, req, io->t2ffirst.in.pattern);
+       dir = svfs_list(ntvfs, req, io->t2ffirst.in.pattern);
        if (!dir) {
-               talloc_free(mem_ctx);
                return NT_STATUS_FOOBAR;
        }
 
@@ -810,13 +845,14 @@ static NTSTATUS svfs_search_first(struct smbsrv_request *req, union smb_search_f
 }
 
 /* continue a search */
-static NTSTATUS svfs_search_next(struct smbsrv_request *req, union smb_search_next *io, 
+static NTSTATUS svfs_search_next(struct ntvfs_module_context *ntvfs,
+                                struct ntvfs_request *req, union smb_search_next *io, 
                                 void *search_private, 
                                 BOOL (*callback)(void *, union smb_search_data *))
 {
        struct svfs_dir *dir;
        int i;
-       struct svfs_private *private = req->tcon->ntvfs_private;
+       struct svfs_private *private = ntvfs->private_data;
        struct search_state *search;
        union smb_search_data file;
        uint_t max_count;
@@ -897,9 +933,10 @@ found:
 }
 
 /* close a search */
-static NTSTATUS svfs_search_close(struct smbsrv_request *req, union smb_search_close *io)
+static NTSTATUS svfs_search_close(struct ntvfs_module_context *ntvfs,
+                                 struct ntvfs_request *req, union smb_search_close *io)
 {
-       struct svfs_private *private = req->tcon->ntvfs_private;
+       struct svfs_private *private = ntvfs->private_data;
        struct search_state *search;
 
        for (search=private->search; search; search = search->next) {
@@ -918,7 +955,8 @@ static NTSTATUS svfs_search_close(struct smbsrv_request *req, union smb_search_c
 }
 
 /* SMBtrans - not used on file shares */
-static NTSTATUS svfs_trans(struct smbsrv_request *req, struct smb_trans2 *trans2)
+static NTSTATUS svfs_trans(struct ntvfs_module_context *ntvfs,
+                          struct ntvfs_request *req, struct smb_trans2 *trans2)
 {
        return NT_STATUS_ACCESS_DENIED;
 }
@@ -934,9 +972,6 @@ NTSTATUS ntvfs_simple_init(void)
 
        ZERO_STRUCT(ops);
 
-       /* fill in the name and type */
-       ops.type = NTVFS_DISK;
-
        /* fill in all the operations */
        ops.connect = svfs_connect;
        ops.disconnect = svfs_disconnect;
@@ -965,12 +1000,17 @@ NTSTATUS ntvfs_simple_init(void)
        ops.search_next = svfs_search_next;
        ops.search_close = svfs_search_close;
        ops.trans = svfs_trans;
+       ops.logoff = svfs_logoff;
+       ops.async_setup = svfs_async_setup;
+       ops.cancel = svfs_cancel;
 
        /* register ourselves with the NTVFS subsystem. We register
           under names 'simple'
        */
+
+       ops.type = NTVFS_DISK;
        ops.name = "simple";
-       ret = register_backend("ntvfs", &ops);
+       ret = ntvfs_register(&ops);
 
        if (!NT_STATUS_IS_OK(ret)) {
                DEBUG(0,("Failed to register simple backend with name: %s!\n",