#include "includes.h"
#include "svfs.h"
+#ifndef O_DIRECTORY
+#define O_DIRECTORY 0
+#endif
+
/*
connect to a share - used when a tree_connect operation comes
in. For a disk based backend we needs to ensure that the base
return NT_STATUS_OK;
}
+/*
+ find open file handle given fd
+*/
+static struct svfs_file *find_fd(struct svfs_private *private, int fd)
+{
+ struct svfs_file *f;
+ for (f=private->open_files;f;f=f->next) {
+ if (f->fd == fd) {
+ return f;
+ }
+ }
+ return NULL;
+}
+
/*
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)
/*
ioctl interface - we don't do any
*/
-static NTSTATUS svfs_ioctl(struct request_context *req, struct smb_ioctl *io)
+static NTSTATUS svfs_ioctl(struct request_context *req, union smb_ioctl *io)
{
return NT_STATUS_INVALID_PARAMETER;
}
/*
approximately map a struct stat to a generic fileinfo struct
*/
-static NTSTATUS svfs_map_fileinfo(struct request_context *req, union smb_fileinfo *info, struct stat *st)
+static NTSTATUS svfs_map_fileinfo(struct request_context *req, union smb_fileinfo *info,
+ struct stat *st, const char *unix_path)
{
+ struct svfs_dir *dir = NULL;
+ char *pattern = NULL;
+ int i;
+ char *s, *short_name;
+
+ s = strrchr(unix_path, '/');
+ if (s) {
+ short_name = s+1;
+ } else {
+ short_name = "";
+ }
+
+ asprintf(&pattern, "%s:*", unix_path);
+
+ if (pattern) {
+ dir = svfs_list_unix(req->mem_ctx, req, pattern);
+ }
+
unix_to_nt_time(&info->generic.out.create_time, st->st_ctime);
unix_to_nt_time(&info->generic.out.access_time, st->st_atime);
unix_to_nt_time(&info->generic.out.write_time, st->st_mtime);
info->generic.out.alloc_size = st->st_blksize * st->st_blocks;
info->generic.out.nlink = st->st_nlink;
info->generic.out.directory = S_ISDIR(st->st_mode) ? 1 : 0;
- info->generic.out.device = st->st_dev;
- info->generic.out.inode = st->st_ino;
+ info->generic.out.file_id = svfs_file_id(st);
/* REWRITE: TODO stuff in here */
info->generic.out.delete_pending = 0;
info->generic.out.ea_size = 0;
info->generic.out.num_eas = 0;
- info->generic.out.fname.s = talloc_strdup(req->mem_ctx, "TODO - STORE FILENAME");
- info->generic.out.alt_fname.s = talloc_strdup(req->mem_ctx, "TODO - STORE ALT_FN");
+ info->generic.out.fname.s = talloc_strdup(req->mem_ctx, short_name);
+ info->generic.out.alt_fname.s = talloc_strdup(req->mem_ctx, short_name);
info->generic.out.ex_attrib = 0;
info->generic.out.compressed_size = 0;
info->generic.out.format = 0;
info->generic.out.reparse_tag = 0;
info->generic.out.num_streams = 0;
/* setup a single data stream */
- info->generic.out.num_streams = 1;
- info->generic.out.streams = talloc(req->mem_ctx, sizeof(info->stream_info.out.streams[0]));
+ info->generic.out.num_streams = 1 + (dir?dir->count:0);
+ info->generic.out.streams = talloc_array_p(req->mem_ctx,
+ struct stream_struct,
+ info->generic.out.num_streams);
if (!info->generic.out.streams) {
return NT_STATUS_NO_MEMORY;
}
info->generic.out.streams[0].size = st->st_size;
info->generic.out.streams[0].alloc_size = st->st_size;
info->generic.out.streams[0].stream_name.s = talloc_strdup(req->mem_ctx,"::$DATA");
- /* REWRITE: end */
+
+ for (i=0;dir && i<dir->count;i++) {
+ s = strchr(dir->files[i].name, ':');
+ info->generic.out.streams[1+i].size = dir->files[i].st.st_size;
+ info->generic.out.streams[1+i].alloc_size = dir->files[i].st.st_size;
+ info->generic.out.streams[1+i].stream_name.s = s?s:dir->files[i].name;
+ }
return NT_STATUS_OK;
}
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);
+ return svfs_map_fileinfo(req, info, &st, unix_path);
}
/*
*/
static NTSTATUS svfs_qfileinfo(struct request_context *req, union smb_fileinfo *info)
{
+ struct svfs_private *private = req->conn->ntvfs_private;
+ struct svfs_file *f;
struct stat st;
if (info->generic.level != RAW_FILEINFO_GENERIC) {
return ntvfs_map_qfileinfo(req, info);
}
+
+ f = find_fd(private, info->generic.in.fnum);
+ if (!f) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
if (fstat(info->generic.in.fnum, &st) == -1) {
if (errno == 0)
return map_nt_error_from_unix(errno);
}
- return svfs_map_fileinfo(req, info, &st);
+ return svfs_map_fileinfo(req, info, &st, f->name);
}
*/
static NTSTATUS svfs_open(struct request_context *req, union smb_open *io)
{
+ struct svfs_private *private = req->conn->ntvfs_private;
char *unix_path;
struct stat st;
int fd, flags;
+ struct svfs_file *f;
if (io->generic.level != RAW_OPEN_GENERIC) {
return ntvfs_map_open(req, io);
return map_nt_error_from_unix(errno);
}
+ f = talloc_p(req->conn->mem_ctx, struct svfs_file);
+ f->fd = fd;
+ f->name = talloc_strdup(req->conn->mem_ctx, unix_path);
+
+ DLIST_ADD(private->open_files, f);
+
ZERO_STRUCT(io->generic.out);
unix_to_nt_time(&io->generic.out.create_time, st.st_ctime);
/*
rename a set of files
*/
-static NTSTATUS svfs_rename(struct request_context *req, struct smb_rename *ren)
+static NTSTATUS svfs_rename(struct request_context *req, union smb_rename *ren)
{
char *unix_path1, *unix_path2;
- unix_path1 = svfs_unix_path(req, ren->in.pattern1);
- unix_path2 = svfs_unix_path(req, ren->in.pattern2);
+ if (ren->generic.level != RAW_RENAME_RENAME) {
+ 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);
if (rename(unix_path1, unix_path2) != 0) {
return map_nt_error_from_unix(errno);
*/
static NTSTATUS svfs_close(struct request_context *req, union smb_close *io)
{
+ struct svfs_private *private = req->conn->ntvfs_private;
+ struct svfs_file *f;
+
if (io->generic.level != RAW_CLOSE_CLOSE) {
/* we need a mapping function */
return NT_STATUS_INVALID_LEVEL;
}
+ f = find_fd(private, io->close.in.fnum);
+ if (!f) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
+
if (close(io->close.in.fnum) != 0) {
return map_nt_error_from_unix(errno);
}
+ DLIST_REMOVE(private->open_files, f);
+ talloc_free(req->conn->mem_ctx, f->name);
+ talloc_free(req->conn->mem_ctx, f);
+
return NT_STATUS_OK;
}
return NT_STATUS_OK;
}
+/* SMBtrans - not used on file shares */
+static NTSTATUS svfs_trans(struct request_context *req, struct smb_trans2 *trans2)
+{
+ return NT_STATUS_ACCESS_DENIED;
+}
+
/*
initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
*/
-BOOL posix_vfs_init(void)
+NTSTATUS ntvfs_simple_init(void)
{
- BOOL ret;
+ NTSTATUS ret;
struct ntvfs_ops ops;
ZERO_STRUCT(ops);
-
+
+ /* fill in the name and type */
+ ops.name = "simple";
+ ops.type = NTVFS_DISK;
+
/* fill in all the operations */
ops.connect = svfs_connect;
ops.disconnect = svfs_disconnect;
ops.search_first = svfs_search_first;
ops.search_next = svfs_search_next;
ops.search_close = svfs_search_close;
+ ops.trans = svfs_trans;
/* register ourselves with the NTVFS subsystem. We register under the name 'default'
as we wish to be the default backend */
- ret = ntvfs_register("simple", NTVFS_DISK, &ops);
+ ret = register_backend("ntvfs", &ops);
- if (!ret) {
+ if (!NT_STATUS_IS_OK(ret)) {
DEBUG(0,("Failed to register POSIX backend!\n"));
- return False;
}
- return True;
+ return ret;
}