2 Unix SMB/CIFS implementation.
4 simple NTVFS filesystem backend
6 Copyright (C) Andrew Tridgell 2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 this implements a very simple NTVFS filesystem backend.
24 this backend largely ignores the POSIX -> CIFS mappings, just doing absolutely
25 minimal work to give a working backend.
29 #include "system/dir.h"
30 #include "system/filesys.h"
32 #include "system/time.h"
33 #include "lib/util/dlinklist.h"
34 #include "ntvfs/ntvfs.h"
35 #include "ntvfs/simple/proto.h"
41 #define CHECK_READ_ONLY(req) do { if (share_bool_option(ntvfs->ctx->config, SHARE_READONLY, true)) return NT_STATUS_ACCESS_DENIED; } while (0)
44 connect to a share - used when a tree_connect operation comes
45 in. For a disk based backend we needs to ensure that the base
46 directory exists (tho it doesn't need to be accessible by the user,
49 static NTSTATUS svfs_connect(struct ntvfs_module_context *ntvfs,
50 struct ntvfs_request *req, const char *sharename)
53 struct svfs_private *private;
54 struct share_config *scfg = ntvfs->ctx->config;
56 private = talloc(ntvfs, struct svfs_private);
57 NT_STATUS_HAVE_NO_MEMORY(private);
58 private->ntvfs = ntvfs;
59 private->next_search_handle = 0;
60 private->connectpath = talloc_strdup(private, share_string_option(scfg, SHARE_PATH, ""));
61 private->open_files = NULL;
62 private->search = NULL;
64 /* the directory must exist */
65 if (stat(private->connectpath, &st) != 0 || !S_ISDIR(st.st_mode)) {
66 DEBUG(0,("'%s' is not a directory, when connecting to [%s]\n",
67 private->connectpath, sharename));
68 return NT_STATUS_BAD_NETWORK_NAME;
71 ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
72 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
73 ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
74 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
76 ntvfs->private_data = private;
82 disconnect from a share
84 static NTSTATUS svfs_disconnect(struct ntvfs_module_context *ntvfs)
90 find open file handle given fd
92 static struct svfs_file *find_fd(struct svfs_private *private, struct ntvfs_handle *handle)
97 p = ntvfs_handle_get_backend_data(handle, private->ntvfs);
100 f = talloc_get_type(p, struct svfs_file);
107 delete a file - the dirtype specifies the file types to include in the search.
108 The name can contain CIFS wildcards, but rarely does (except with OS/2 clients)
110 static NTSTATUS svfs_unlink(struct ntvfs_module_context *ntvfs,
111 struct ntvfs_request *req,
112 union smb_unlink *unl)
116 CHECK_READ_ONLY(req);
118 unix_path = svfs_unix_path(ntvfs, req, unl->unlink.in.pattern);
120 /* ignoring wildcards ... */
121 if (unlink(unix_path) == -1) {
122 return map_nt_error_from_unix(errno);
130 ioctl interface - we don't do any
132 static NTSTATUS svfs_ioctl(struct ntvfs_module_context *ntvfs,
133 struct ntvfs_request *req, union smb_ioctl *io)
135 return NT_STATUS_INVALID_PARAMETER;
139 check if a directory exists
141 static NTSTATUS svfs_chkpath(struct ntvfs_module_context *ntvfs,
142 struct ntvfs_request *req,
143 union smb_chkpath *cp)
148 unix_path = svfs_unix_path(ntvfs, req, cp->chkpath.in.path);
150 if (stat(unix_path, &st) == -1) {
151 return map_nt_error_from_unix(errno);
154 if (!S_ISDIR(st.st_mode)) {
155 return NT_STATUS_NOT_A_DIRECTORY;
162 build a file_id from a stat struct
164 static uint64_t svfs_file_id(struct stat *st)
166 uint64_t ret = st->st_ino;
173 approximately map a struct stat to a generic fileinfo struct
175 static NTSTATUS svfs_map_fileinfo(struct ntvfs_module_context *ntvfs,
176 struct ntvfs_request *req, union smb_fileinfo *info,
177 struct stat *st, const char *unix_path)
179 struct svfs_dir *dir = NULL;
180 char *pattern = NULL;
182 const char *s, *short_name;
184 s = strrchr(unix_path, '/');
191 asprintf(&pattern, "%s:*", unix_path);
194 dir = svfs_list_unix(req, req, pattern);
197 unix_to_nt_time(&info->generic.out.create_time, st->st_ctime);
198 unix_to_nt_time(&info->generic.out.access_time, st->st_atime);
199 unix_to_nt_time(&info->generic.out.write_time, st->st_mtime);
200 unix_to_nt_time(&info->generic.out.change_time, st->st_mtime);
201 info->generic.out.alloc_size = st->st_size;
202 info->generic.out.size = st->st_size;
203 info->generic.out.attrib = svfs_unix_to_dos_attrib(st->st_mode);
204 info->generic.out.alloc_size = st->st_blksize * st->st_blocks;
205 info->generic.out.nlink = st->st_nlink;
206 info->generic.out.directory = S_ISDIR(st->st_mode) ? 1 : 0;
207 info->generic.out.file_id = svfs_file_id(st);
208 /* REWRITE: TODO stuff in here */
209 info->generic.out.delete_pending = 0;
210 info->generic.out.ea_size = 0;
211 info->generic.out.num_eas = 0;
212 info->generic.out.fname.s = talloc_strdup(req, short_name);
213 info->generic.out.alt_fname.s = talloc_strdup(req, short_name);
214 info->generic.out.compressed_size = 0;
215 info->generic.out.format = 0;
216 info->generic.out.unit_shift = 0;
217 info->generic.out.chunk_shift = 0;
218 info->generic.out.cluster_shift = 0;
220 info->generic.out.access_flags = 0;
221 info->generic.out.position = 0;
222 info->generic.out.mode = 0;
223 info->generic.out.alignment_requirement = 0;
224 info->generic.out.reparse_tag = 0;
225 info->generic.out.num_streams = 0;
226 /* setup a single data stream */
227 info->generic.out.num_streams = 1 + (dir?dir->count:0);
228 info->generic.out.streams = talloc_array(req,
229 struct stream_struct,
230 info->generic.out.num_streams);
231 if (!info->generic.out.streams) {
232 return NT_STATUS_NO_MEMORY;
234 info->generic.out.streams[0].size = st->st_size;
235 info->generic.out.streams[0].alloc_size = st->st_size;
236 info->generic.out.streams[0].stream_name.s = talloc_strdup(req,"::$DATA");
238 for (i=0;dir && i<dir->count;i++) {
239 s = strchr(dir->files[i].name, ':');
240 info->generic.out.streams[1+i].size = dir->files[i].st.st_size;
241 info->generic.out.streams[1+i].alloc_size = dir->files[i].st.st_size;
242 info->generic.out.streams[1+i].stream_name.s = s?s:dir->files[i].name;
249 return info on a pathname
251 static NTSTATUS svfs_qpathinfo(struct ntvfs_module_context *ntvfs,
252 struct ntvfs_request *req, union smb_fileinfo *info)
257 DEBUG(19,("svfs_qpathinfo: file %s level 0x%x\n", info->generic.in.file.path, info->generic.level));
258 if (info->generic.level != RAW_FILEINFO_GENERIC) {
259 return ntvfs_map_qpathinfo(ntvfs, req, info);
262 unix_path = svfs_unix_path(ntvfs, req, info->generic.in.file.path);
263 DEBUG(19,("svfs_qpathinfo: file %s\n", unix_path));
264 if (stat(unix_path, &st) == -1) {
265 DEBUG(19,("svfs_qpathinfo: file %s errno=%d\n", unix_path, errno));
266 return map_nt_error_from_unix(errno);
268 DEBUG(19,("svfs_qpathinfo: file %s, stat done\n", unix_path));
269 return svfs_map_fileinfo(ntvfs, req, info, &st, unix_path);
273 query info on a open file
275 static NTSTATUS svfs_qfileinfo(struct ntvfs_module_context *ntvfs,
276 struct ntvfs_request *req, union smb_fileinfo *info)
278 struct svfs_private *private = ntvfs->private_data;
282 if (info->generic.level != RAW_FILEINFO_GENERIC) {
283 return ntvfs_map_qfileinfo(ntvfs, req, info);
286 f = find_fd(private, info->generic.in.file.ntvfs);
288 return NT_STATUS_INVALID_HANDLE;
291 if (fstat(f->fd, &st) == -1) {
292 return map_nt_error_from_unix(errno);
295 return svfs_map_fileinfo(ntvfs, req,info, &st, f->name);
302 static NTSTATUS svfs_open(struct ntvfs_module_context *ntvfs,
303 struct ntvfs_request *req, union smb_open *io)
305 struct svfs_private *private = ntvfs->private_data;
310 int create_flags, rdwr_flags;
313 struct ntvfs_handle *handle;
315 if (io->generic.level != RAW_OPEN_GENERIC) {
316 return ntvfs_map_open(ntvfs, req, io);
319 readonly = share_bool_option(ntvfs->ctx->config, SHARE_READONLY, SHARE_READONLY_DEFAULT);
322 rdwr_flags = O_RDONLY;
324 create_flags = O_CREAT;
328 unix_path = svfs_unix_path(ntvfs, req, io->ntcreatex.in.fname);
330 switch (io->generic.in.open_disposition) {
331 case NTCREATEX_DISP_SUPERSEDE:
332 case NTCREATEX_DISP_OVERWRITE_IF:
333 flags = create_flags | O_TRUNC;
335 case NTCREATEX_DISP_OPEN:
336 case NTCREATEX_DISP_OVERWRITE:
339 case NTCREATEX_DISP_CREATE:
340 flags = create_flags | O_EXCL;
342 case NTCREATEX_DISP_OPEN_IF:
343 flags = create_flags;
352 if (io->generic.in.create_options & NTCREATEX_OPTIONS_DIRECTORY) {
353 flags = O_RDONLY | O_DIRECTORY;
357 switch (io->generic.in.open_disposition) {
358 case NTCREATEX_DISP_CREATE:
359 if (mkdir(unix_path, 0755) == -1) {
360 DEBUG(9,("svfs_open: mkdir %s errno=%d\n", unix_path, errno));
361 return map_nt_error_from_unix(errno);
364 case NTCREATEX_DISP_OPEN_IF:
365 if (mkdir(unix_path, 0755) == -1 && errno != EEXIST) {
366 DEBUG(9,("svfs_open: mkdir %s errno=%d\n", unix_path, errno));
367 return map_nt_error_from_unix(errno);
374 fd = open(unix_path, flags, 0644);
376 return map_nt_error_from_unix(errno);
379 if (fstat(fd, &st) == -1) {
380 DEBUG(9,("svfs_open: fstat errno=%d\n", errno));
382 return map_nt_error_from_unix(errno);
385 status = ntvfs_handle_new(ntvfs, req, &handle);
386 NT_STATUS_NOT_OK_RETURN(status);
388 f = talloc(handle, struct svfs_file);
389 NT_STATUS_HAVE_NO_MEMORY(f);
391 f->name = talloc_strdup(f, unix_path);
392 NT_STATUS_HAVE_NO_MEMORY(f->name);
394 DLIST_ADD(private->open_files, f);
396 status = ntvfs_handle_set_backend_data(handle, ntvfs, f);
397 NT_STATUS_NOT_OK_RETURN(status);
399 ZERO_STRUCT(io->generic.out);
401 unix_to_nt_time(&io->generic.out.create_time, st.st_ctime);
402 unix_to_nt_time(&io->generic.out.access_time, st.st_atime);
403 unix_to_nt_time(&io->generic.out.write_time, st.st_mtime);
404 unix_to_nt_time(&io->generic.out.change_time, st.st_mtime);
405 io->generic.out.file.ntvfs = handle;
406 io->generic.out.alloc_size = st.st_size;
407 io->generic.out.size = st.st_size;
408 io->generic.out.attrib = svfs_unix_to_dos_attrib(st.st_mode);
409 io->generic.out.is_directory = S_ISDIR(st.st_mode) ? 1 : 0;
417 static NTSTATUS svfs_mkdir(struct ntvfs_module_context *ntvfs,
418 struct ntvfs_request *req, union smb_mkdir *md)
422 CHECK_READ_ONLY(req);
424 if (md->generic.level != RAW_MKDIR_MKDIR) {
425 return NT_STATUS_INVALID_LEVEL;
428 unix_path = svfs_unix_path(ntvfs, req, md->mkdir.in.path);
430 if (mkdir(unix_path, 0777) == -1) {
431 return map_nt_error_from_unix(errno);
440 static NTSTATUS svfs_rmdir(struct ntvfs_module_context *ntvfs,
441 struct ntvfs_request *req, struct smb_rmdir *rd)
445 CHECK_READ_ONLY(req);
447 unix_path = svfs_unix_path(ntvfs, req, rd->in.path);
449 if (rmdir(unix_path) == -1) {
450 return map_nt_error_from_unix(errno);
457 rename a set of files
459 static NTSTATUS svfs_rename(struct ntvfs_module_context *ntvfs,
460 struct ntvfs_request *req, union smb_rename *ren)
462 char *unix_path1, *unix_path2;
464 CHECK_READ_ONLY(req);
466 if (ren->generic.level != RAW_RENAME_RENAME) {
467 return NT_STATUS_INVALID_LEVEL;
470 unix_path1 = svfs_unix_path(ntvfs, req, ren->rename.in.pattern1);
471 unix_path2 = svfs_unix_path(ntvfs, req, ren->rename.in.pattern2);
473 if (rename(unix_path1, unix_path2) == -1) {
474 return map_nt_error_from_unix(errno);
483 static NTSTATUS svfs_copy(struct ntvfs_module_context *ntvfs,
484 struct ntvfs_request *req, struct smb_copy *cp)
486 return NT_STATUS_NOT_SUPPORTED;
492 static NTSTATUS svfs_read(struct ntvfs_module_context *ntvfs,
493 struct ntvfs_request *req, union smb_read *rd)
495 struct svfs_private *private = ntvfs->private_data;
499 if (rd->generic.level != RAW_READ_READX) {
500 return NT_STATUS_NOT_SUPPORTED;
503 f = find_fd(private, rd->readx.in.file.ntvfs);
505 return NT_STATUS_INVALID_HANDLE;
511 rd->readx.in.offset);
513 return map_nt_error_from_unix(errno);
516 rd->readx.out.nread = ret;
517 rd->readx.out.remaining = 0; /* should fill this in? */
518 rd->readx.out.compaction_mode = 0;
526 static NTSTATUS svfs_write(struct ntvfs_module_context *ntvfs,
527 struct ntvfs_request *req, union smb_write *wr)
529 struct svfs_private *private = ntvfs->private_data;
533 if (wr->generic.level != RAW_WRITE_WRITEX) {
534 return ntvfs_map_write(ntvfs, req, wr);
537 CHECK_READ_ONLY(req);
539 f = find_fd(private, wr->writex.in.file.ntvfs);
541 return NT_STATUS_INVALID_HANDLE;
547 wr->writex.in.offset);
549 return map_nt_error_from_unix(errno);
552 wr->writex.out.nwritten = ret;
553 wr->writex.out.remaining = 0; /* should fill this in? */
561 static NTSTATUS svfs_seek(struct ntvfs_module_context *ntvfs,
562 struct ntvfs_request *req,
565 return NT_STATUS_NOT_SUPPORTED;
571 static NTSTATUS svfs_flush(struct ntvfs_module_context *ntvfs,
572 struct ntvfs_request *req,
575 struct svfs_private *private = ntvfs->private_data;
578 switch (io->generic.level) {
579 case RAW_FLUSH_FLUSH:
581 /* ignore the additional unknown option in SMB2 */
582 f = find_fd(private, io->generic.in.file.ntvfs);
584 return NT_STATUS_INVALID_HANDLE;
590 for (f=private->open_files;f;f=f->next) {
596 return NT_STATUS_INVALID_LEVEL;
602 static NTSTATUS svfs_close(struct ntvfs_module_context *ntvfs,
603 struct ntvfs_request *req,
606 struct svfs_private *private = ntvfs->private_data;
609 if (io->generic.level != RAW_CLOSE_CLOSE) {
610 /* we need a mapping function */
611 return NT_STATUS_INVALID_LEVEL;
614 f = find_fd(private, io->close.in.file.ntvfs);
616 return NT_STATUS_INVALID_HANDLE;
619 if (close(f->fd) == -1) {
620 return map_nt_error_from_unix(errno);
623 DLIST_REMOVE(private->open_files, f);
624 talloc_free(f->name);
633 static NTSTATUS svfs_exit(struct ntvfs_module_context *ntvfs,
634 struct ntvfs_request *req)
636 return NT_STATUS_NOT_SUPPORTED;
640 logoff - closing files
642 static NTSTATUS svfs_logoff(struct ntvfs_module_context *ntvfs,
643 struct ntvfs_request *req)
645 return NT_STATUS_NOT_SUPPORTED;
649 setup for an async call
651 static NTSTATUS svfs_async_setup(struct ntvfs_module_context *ntvfs,
652 struct ntvfs_request *req,
661 static NTSTATUS svfs_cancel(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req)
663 return NT_STATUS_UNSUCCESSFUL;
669 static NTSTATUS svfs_lock(struct ntvfs_module_context *ntvfs,
670 struct ntvfs_request *req, union smb_lock *lck)
672 DEBUG(0,("REWRITE: not doing byte range locking!\n"));
677 set info on a pathname
679 static NTSTATUS svfs_setpathinfo(struct ntvfs_module_context *ntvfs,
680 struct ntvfs_request *req, union smb_setfileinfo *st)
682 CHECK_READ_ONLY(req);
684 return NT_STATUS_NOT_SUPPORTED;
688 set info on a open file
690 static NTSTATUS svfs_setfileinfo(struct ntvfs_module_context *ntvfs,
691 struct ntvfs_request *req,
692 union smb_setfileinfo *info)
694 struct svfs_private *private = ntvfs->private_data;
696 struct utimbuf unix_times;
698 CHECK_READ_ONLY(req);
700 f = find_fd(private, info->generic.in.file.ntvfs);
702 return NT_STATUS_INVALID_HANDLE;
705 switch (info->generic.level) {
706 case RAW_SFILEINFO_END_OF_FILE_INFO:
707 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
709 info->end_of_file_info.in.size) == -1) {
710 return map_nt_error_from_unix(errno);
713 case RAW_SFILEINFO_SETATTRE:
714 unix_times.actime = info->setattre.in.access_time;
715 unix_times.modtime = info->setattre.in.write_time;
717 if (unix_times.actime == 0 && unix_times.modtime == 0) {
721 /* set modify time = to access time if modify time was 0 */
722 if (unix_times.actime != 0 && unix_times.modtime == 0) {
723 unix_times.modtime = unix_times.actime;
726 /* Set the date on this file */
727 if (svfs_file_utime(f->fd, &unix_times) != 0) {
728 return NT_STATUS_ACCESS_DENIED;
732 DEBUG(2,("svfs_setfileinfo: level %d not implemented\n",
733 info->generic.level));
734 return NT_STATUS_NOT_IMPLEMENTED;
741 return filesystem space info
743 static NTSTATUS svfs_fsinfo(struct ntvfs_module_context *ntvfs,
744 struct ntvfs_request *req, union smb_fsinfo *fs)
746 struct svfs_private *private = ntvfs->private_data;
749 if (fs->generic.level != RAW_QFS_GENERIC) {
750 return ntvfs_map_fsinfo(ntvfs, req, fs);
753 if (sys_fsusage(private->connectpath,
754 &fs->generic.out.blocks_free,
755 &fs->generic.out.blocks_total) == -1) {
756 return map_nt_error_from_unix(errno);
759 fs->generic.out.block_size = 512;
761 if (stat(private->connectpath, &st) != 0) {
762 return NT_STATUS_DISK_CORRUPT_ERROR;
765 fs->generic.out.fs_id = st.st_ino;
766 unix_to_nt_time(&fs->generic.out.create_time, st.st_ctime);
767 fs->generic.out.serial_number = st.st_ino;
768 fs->generic.out.fs_attr = 0;
769 fs->generic.out.max_file_component_length = 255;
770 fs->generic.out.device_type = 0;
771 fs->generic.out.device_characteristics = 0;
772 fs->generic.out.quota_soft = 0;
773 fs->generic.out.quota_hard = 0;
774 fs->generic.out.quota_flags = 0;
775 fs->generic.out.volume_name = talloc_strdup(req, ntvfs->ctx->config->name);
776 fs->generic.out.fs_type = ntvfs->ctx->fs_type;
783 return filesystem attribute info
785 static NTSTATUS svfs_fsattr(struct ntvfs_module_context *ntvfs,
786 struct ntvfs_request *req, union smb_fsattr *fs)
789 struct svfs_private *private = ntvfs->private_data;
791 if (fs->generic.level != RAW_FSATTR_GENERIC) {
792 return ntvfs_map_fsattr(ntvfs, req, fs);
795 if (stat(private->connectpath, &st) == -1) {
796 return map_nt_error_from_unix(errno);
799 unix_to_nt_time(&fs->generic.out.create_time, st.st_ctime);
800 fs->generic.out.fs_attr =
801 FILE_CASE_PRESERVED_NAMES |
802 FILE_CASE_SENSITIVE_SEARCH |
803 FILE_PERSISTENT_ACLS;
804 fs->generic.out.max_file_component_length = 255;
805 fs->generic.out.serial_number = 1;
806 fs->generic.out.fs_type = talloc_strdup(req, "NTFS");
807 fs->generic.out.volume_name = talloc_strdup(req,
808 lp_servicename(req->tcon->service));
815 return print queue info
817 static NTSTATUS svfs_lpq(struct ntvfs_module_context *ntvfs,
818 struct ntvfs_request *req, union smb_lpq *lpq)
820 return NT_STATUS_NOT_SUPPORTED;
824 list files in a directory matching a wildcard pattern
826 static NTSTATUS svfs_search_first(struct ntvfs_module_context *ntvfs,
827 struct ntvfs_request *req, union smb_search_first *io,
828 void *search_private,
829 bool (*callback)(void *, const union smb_search_data *))
831 struct svfs_dir *dir;
833 struct svfs_private *private = ntvfs->private_data;
834 struct search_state *search;
835 union smb_search_data file;
838 if (io->generic.level != RAW_SEARCH_TRANS2) {
839 return NT_STATUS_NOT_SUPPORTED;
842 if (io->generic.data_level != RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO) {
843 return NT_STATUS_NOT_SUPPORTED;
846 search = talloc_zero(private, struct search_state);
848 return NT_STATUS_NO_MEMORY;
851 max_count = io->t2ffirst.in.max_count;
853 dir = svfs_list(ntvfs, req, io->t2ffirst.in.pattern);
855 return NT_STATUS_FOOBAR;
858 search->handle = private->next_search_handle;
861 if (dir->count < max_count) {
862 max_count = dir->count;
865 for (i=0; i < max_count;i++) {
867 unix_to_nt_time(&file.both_directory_info.create_time, dir->files[i].st.st_ctime);
868 unix_to_nt_time(&file.both_directory_info.access_time, dir->files[i].st.st_atime);
869 unix_to_nt_time(&file.both_directory_info.write_time, dir->files[i].st.st_mtime);
870 unix_to_nt_time(&file.both_directory_info.change_time, dir->files[i].st.st_mtime);
871 file.both_directory_info.name.s = dir->files[i].name;
872 file.both_directory_info.short_name.s = dir->files[i].name;
873 file.both_directory_info.size = dir->files[i].st.st_size;
874 file.both_directory_info.attrib = svfs_unix_to_dos_attrib(dir->files[i].st.st_mode);
876 if (!callback(search_private, &file)) {
881 search->current_index = i;
883 io->t2ffirst.out.count = i;
884 io->t2ffirst.out.handle = search->handle;
885 io->t2ffirst.out.end_of_search = (i == dir->count) ? 1 : 0;
887 /* work out if we are going to keep the search state */
888 if ((io->t2ffirst.in.flags & FLAG_TRANS2_FIND_CLOSE) ||
889 ((io->t2ffirst.in.flags & FLAG_TRANS2_FIND_CLOSE_IF_END) && (i == dir->count))) {
892 private->next_search_handle++;
893 DLIST_ADD(private->search, search);
899 /* continue a search */
900 static NTSTATUS svfs_search_next(struct ntvfs_module_context *ntvfs,
901 struct ntvfs_request *req, union smb_search_next *io,
902 void *search_private,
903 bool (*callback)(void *, const union smb_search_data *))
905 struct svfs_dir *dir;
907 struct svfs_private *private = ntvfs->private_data;
908 struct search_state *search;
909 union smb_search_data file;
912 if (io->generic.level != RAW_SEARCH_TRANS2) {
913 return NT_STATUS_NOT_SUPPORTED;
916 if (io->generic.data_level != RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO) {
917 return NT_STATUS_NOT_SUPPORTED;
920 for (search=private->search; search; search = search->next) {
921 if (search->handle == io->t2fnext.in.handle) break;
925 /* we didn't find the search handle */
926 return NT_STATUS_FOOBAR;
931 /* the client might be asking for something other than just continuing
933 if (!(io->t2fnext.in.flags & FLAG_TRANS2_FIND_CONTINUE) &&
934 (io->t2fnext.in.flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) &&
935 io->t2fnext.in.last_name && *io->t2fnext.in.last_name) {
936 /* look backwards first */
937 for (i=search->current_index; i > 0; i--) {
938 if (strcmp(io->t2fnext.in.last_name, dir->files[i-1].name) == 0) {
939 search->current_index = i;
944 /* then look forwards */
945 for (i=search->current_index+1; i <= dir->count; i++) {
946 if (strcmp(io->t2fnext.in.last_name, dir->files[i-1].name) == 0) {
947 search->current_index = i;
954 max_count = search->current_index + io->t2fnext.in.max_count;
956 if (max_count > dir->count) {
957 max_count = dir->count;
960 for (i = search->current_index; i < max_count;i++) {
962 unix_to_nt_time(&file.both_directory_info.create_time, dir->files[i].st.st_ctime);
963 unix_to_nt_time(&file.both_directory_info.access_time, dir->files[i].st.st_atime);
964 unix_to_nt_time(&file.both_directory_info.write_time, dir->files[i].st.st_mtime);
965 unix_to_nt_time(&file.both_directory_info.change_time, dir->files[i].st.st_mtime);
966 file.both_directory_info.name.s = dir->files[i].name;
967 file.both_directory_info.short_name.s = dir->files[i].name;
968 file.both_directory_info.size = dir->files[i].st.st_size;
969 file.both_directory_info.attrib = svfs_unix_to_dos_attrib(dir->files[i].st.st_mode);
971 if (!callback(search_private, &file)) {
976 io->t2fnext.out.count = i - search->current_index;
977 io->t2fnext.out.end_of_search = (i == dir->count) ? 1 : 0;
979 search->current_index = i;
981 /* work out if we are going to keep the search state */
982 if ((io->t2fnext.in.flags & FLAG_TRANS2_FIND_CLOSE) ||
983 ((io->t2fnext.in.flags & FLAG_TRANS2_FIND_CLOSE_IF_END) && (i == dir->count))) {
984 DLIST_REMOVE(private->search, search);
992 static NTSTATUS svfs_search_close(struct ntvfs_module_context *ntvfs,
993 struct ntvfs_request *req, union smb_search_close *io)
995 struct svfs_private *private = ntvfs->private_data;
996 struct search_state *search;
998 for (search=private->search; search; search = search->next) {
999 if (search->handle == io->findclose.in.handle) break;
1003 /* we didn't find the search handle */
1004 return NT_STATUS_FOOBAR;
1007 DLIST_REMOVE(private->search, search);
1008 talloc_free(search);
1010 return NT_STATUS_OK;
1013 /* SMBtrans - not used on file shares */
1014 static NTSTATUS svfs_trans(struct ntvfs_module_context *ntvfs,
1015 struct ntvfs_request *req, struct smb_trans2 *trans2)
1017 return NT_STATUS_ACCESS_DENIED;
1022 initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
1024 NTSTATUS ntvfs_simple_init(void)
1027 struct ntvfs_ops ops;
1028 NTVFS_CURRENT_CRITICAL_SIZES(vers);
1032 /* fill in all the operations */
1033 ops.connect = svfs_connect;
1034 ops.disconnect = svfs_disconnect;
1035 ops.unlink = svfs_unlink;
1036 ops.chkpath = svfs_chkpath;
1037 ops.qpathinfo = svfs_qpathinfo;
1038 ops.setpathinfo = svfs_setpathinfo;
1039 ops.open = svfs_open;
1040 ops.mkdir = svfs_mkdir;
1041 ops.rmdir = svfs_rmdir;
1042 ops.rename = svfs_rename;
1043 ops.copy = svfs_copy;
1044 ops.ioctl = svfs_ioctl;
1045 ops.read = svfs_read;
1046 ops.write = svfs_write;
1047 ops.seek = svfs_seek;
1048 ops.flush = svfs_flush;
1049 ops.close = svfs_close;
1050 ops.exit = svfs_exit;
1051 ops.lock = svfs_lock;
1052 ops.setfileinfo = svfs_setfileinfo;
1053 ops.qfileinfo = svfs_qfileinfo;
1054 ops.fsinfo = svfs_fsinfo;
1056 ops.search_first = svfs_search_first;
1057 ops.search_next = svfs_search_next;
1058 ops.search_close = svfs_search_close;
1059 ops.trans = svfs_trans;
1060 ops.logoff = svfs_logoff;
1061 ops.async_setup = svfs_async_setup;
1062 ops.cancel = svfs_cancel;
1064 /* register ourselves with the NTVFS subsystem. We register
1065 under names 'simple'
1068 ops.type = NTVFS_DISK;
1069 ops.name = "simple";
1070 ret = ntvfs_register(&ops, &vers);
1072 if (!NT_STATUS_IS_OK(ret)) {
1073 DEBUG(0,("Failed to register simple backend with name: %s!\n",