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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* this module needs to be converted to use ntvfs_handle's! */
24 #define fnum _XXX_use_ntvfs_handle_not_fnum_XXX_
27 this implements a very simple NTVFS filesystem backend.
29 this backend largely ignores the POSIX -> CIFS mappings, just doing absolutely
30 minimal work to give a working backend.
34 #include "system/dir.h"
35 #include "system/filesys.h"
37 #include "system/time.h"
38 #include "dlinklist.h"
39 #include "ntvfs/ntvfs.h"
40 #include "ntvfs/cifs_posix_cli/proto.h"
46 #define CHECK_READ_ONLY(req) do { if (share_bool_option(ntvfs->ctx->config, SHARE_READONLY, True)) return NT_STATUS_ACCESS_DENIED; } while (0)
49 connect to a share - used when a tree_connect operation comes
50 in. For a disk based backend we needs to ensure that the base
51 directory exists (tho it doesn't need to be accessible by the user,
54 static NTSTATUS svfs_connect(struct ntvfs_module_context *ntvfs,
55 struct ntvfs_request *req, const char *sharename)
58 struct svfs_private *private;
60 private = talloc(ntvfs, struct svfs_private);
62 private->next_search_handle = 0;
63 private->connectpath = talloc_strdup(private, share_string_option(ntvfs->ctx->config, SHARE_PATH, ""));
64 private->open_files = NULL;
65 private->search = NULL;
67 /* the directory must exist */
68 if (stat(private->connectpath, &st) != 0 || !S_ISDIR(st.st_mode)) {
69 DEBUG(0,("'%s' is not a directory, when connecting to [%s]\n",
70 private->connectpath, sharename));
71 return NT_STATUS_BAD_NETWORK_NAME;
74 ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
75 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
76 ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
77 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
79 ntvfs->private_data = private;
81 DEBUG(0,("WARNING: ntvfs simple: connect to share [%s] with ROOT privileges!!!\n",sharename));
87 disconnect from a share
89 static NTSTATUS svfs_disconnect(struct ntvfs_module_context *ntvfs)
95 find open file handle given fd
97 static struct svfs_file *find_fd(struct svfs_private *private, int fd)
100 for (f=private->open_files;f;f=f->next) {
109 delete a file - the dirtype specifies the file types to include in the search.
110 The name can contain CIFS wildcards, but rarely does (except with OS/2 clients)
112 static NTSTATUS svfs_unlink(struct ntvfs_module_context *ntvfs,
113 struct ntvfs_request *req,
114 union smb_unlink *unl)
118 CHECK_READ_ONLY(req);
120 unix_path = cvfs_unix_path(ntvfs, req, unl->unlink.in.pattern);
122 /* ignoring wildcards ... */
123 if (unlink(unix_path) == -1) {
124 return map_nt_error_from_unix(errno);
132 ioctl interface - we don't do any
134 static NTSTATUS svfs_ioctl(struct ntvfs_module_context *ntvfs,
135 struct ntvfs_request *req, union smb_ioctl *io)
137 return NT_STATUS_INVALID_PARAMETER;
141 check if a directory exists
143 static NTSTATUS svfs_chkpath(struct ntvfs_module_context *ntvfs,
144 struct ntvfs_request *req,
145 union smb_chkpath *cp)
150 unix_path = cvfs_unix_path(ntvfs, req, cp->chkpath.in.path);
152 if (stat(unix_path, &st) == -1) {
153 return map_nt_error_from_unix(errno);
156 if (!S_ISDIR(st.st_mode)) {
157 return NT_STATUS_NOT_A_DIRECTORY;
164 build a file_id from a stat struct
166 static uint64_t svfs_file_id(struct stat *st)
168 uint64_t ret = st->st_ino;
175 approximately map a struct stat to a generic fileinfo struct
177 static NTSTATUS svfs_map_fileinfo(struct ntvfs_module_context *ntvfs,
178 struct ntvfs_request *req, union smb_fileinfo *info,
179 struct stat *st, const char *unix_path)
181 struct svfs_dir *dir = NULL;
182 char *pattern = NULL;
184 const char *s, *short_name;
186 s = strrchr(unix_path, '/');
193 asprintf(&pattern, "%s:*", unix_path);
196 dir = cvfs_list_unix(req, req, pattern);
199 unix_to_nt_time(&info->generic.out.create_time, st->st_ctime);
200 unix_to_nt_time(&info->generic.out.access_time, st->st_atime);
201 unix_to_nt_time(&info->generic.out.write_time, st->st_mtime);
202 unix_to_nt_time(&info->generic.out.change_time, st->st_mtime);
203 info->generic.out.alloc_size = st->st_size;
204 info->generic.out.size = st->st_size;
205 info->generic.out.attrib = cvfs_unix_to_dos_attrib(st->st_mode);
206 info->generic.out.alloc_size = st->st_blksize * st->st_blocks;
207 info->generic.out.nlink = st->st_nlink;
208 info->generic.out.directory = S_ISDIR(st->st_mode) ? 1 : 0;
209 info->generic.out.file_id = svfs_file_id(st);
210 /* REWRITE: TODO stuff in here */
211 info->generic.out.delete_pending = 0;
212 info->generic.out.ea_size = 0;
213 info->generic.out.num_eas = 0;
214 info->generic.out.fname.s = talloc_strdup(req, short_name);
215 info->generic.out.alt_fname.s = talloc_strdup(req, short_name);
216 info->generic.out.compressed_size = 0;
217 info->generic.out.format = 0;
218 info->generic.out.unit_shift = 0;
219 info->generic.out.chunk_shift = 0;
220 info->generic.out.cluster_shift = 0;
222 info->generic.out.access_flags = 0;
223 info->generic.out.position = 0;
224 info->generic.out.mode = 0;
225 info->generic.out.alignment_requirement = 0;
226 info->generic.out.reparse_tag = 0;
227 info->generic.out.num_streams = 0;
228 /* setup a single data stream */
229 info->generic.out.num_streams = 1 + (dir?dir->count:0);
230 info->generic.out.streams = talloc_array(req,
231 struct stream_struct,
232 info->generic.out.num_streams);
233 if (!info->generic.out.streams) {
234 return NT_STATUS_NO_MEMORY;
236 info->generic.out.streams[0].size = st->st_size;
237 info->generic.out.streams[0].alloc_size = st->st_size;
238 info->generic.out.streams[0].stream_name.s = talloc_strdup(req,"::$DATA");
240 for (i=0;dir && i<dir->count;i++) {
241 s = strchr(dir->files[i].name, ':');
242 info->generic.out.streams[1+i].size = dir->files[i].st.st_size;
243 info->generic.out.streams[1+i].alloc_size = dir->files[i].st.st_size;
244 info->generic.out.streams[1+i].stream_name.s = s?s:dir->files[i].name;
251 return info on a pathname
253 static NTSTATUS svfs_qpathinfo(struct ntvfs_module_context *ntvfs,
254 struct ntvfs_request *req, union smb_fileinfo *info)
259 DEBUG(19,("svfs_qpathinfo: file %s level 0x%x\n", info->generic.in.file.path, info->generic.level));
260 if (info->generic.level != RAW_FILEINFO_GENERIC) {
261 return ntvfs_map_qpathinfo(ntvfs, req, info);
264 unix_path = cvfs_unix_path(ntvfs, req, info->generic.in.file.path);
265 DEBUG(19,("svfs_qpathinfo: file %s\n", unix_path));
266 if (stat(unix_path, &st) == -1) {
267 DEBUG(19,("svfs_qpathinfo: file %s errno=%d\n", unix_path, errno));
268 return map_nt_error_from_unix(errno);
270 DEBUG(19,("svfs_qpathinfo: file %s, stat done\n", unix_path));
271 return svfs_map_fileinfo(ntvfs, req, info, &st, unix_path);
275 query info on a open file
277 static NTSTATUS svfs_qfileinfo(struct ntvfs_module_context *ntvfs,
278 struct ntvfs_request *req, union smb_fileinfo *info)
280 struct svfs_private *private = ntvfs->private_data;
284 if (info->generic.level != RAW_FILEINFO_GENERIC) {
285 return ntvfs_map_qfileinfo(ntvfs, req, info);
288 f = find_fd(private, info->generic.in.file.fnum);
290 return NT_STATUS_INVALID_HANDLE;
293 if (fstat(info->generic.in.file.fnum, &st) == -1) {
294 return map_nt_error_from_unix(errno);
297 return svfs_map_fileinfo(ntvfs, req,info, &st, f->name);
304 static NTSTATUS svfs_open(struct ntvfs_module_context *ntvfs,
305 struct ntvfs_request *req, union smb_open *io)
307 struct svfs_private *private = ntvfs->private_data;
312 int create_flags, rdwr_flags;
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, True);
322 rdwr_flags = O_RDONLY;
324 create_flags = O_CREAT;
328 unix_path = cvfs_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 f = talloc(ntvfs, struct svfs_file);
386 NT_STATUS_HAVE_NO_MEMORY(f);
388 f->name = talloc_strdup(f, unix_path);
389 NT_STATUS_HAVE_NO_MEMORY(f->name);
391 DLIST_ADD(private->open_files, f);
393 ZERO_STRUCT(io->generic.out);
395 unix_to_nt_time(&io->generic.out.create_time, st.st_ctime);
396 unix_to_nt_time(&io->generic.out.access_time, st.st_atime);
397 unix_to_nt_time(&io->generic.out.write_time, st.st_mtime);
398 unix_to_nt_time(&io->generic.out.change_time, st.st_mtime);
399 io->generic.out.file.fnum = fd;
400 io->generic.out.alloc_size = st.st_size;
401 io->generic.out.size = st.st_size;
402 io->generic.out.attrib = cvfs_unix_to_dos_attrib(st.st_mode);
403 io->generic.out.is_directory = S_ISDIR(st.st_mode) ? 1 : 0;
411 static NTSTATUS svfs_mkdir(struct ntvfs_module_context *ntvfs,
412 struct ntvfs_request *req, union smb_mkdir *md)
416 CHECK_READ_ONLY(req);
418 if (md->generic.level != RAW_MKDIR_MKDIR) {
419 return NT_STATUS_INVALID_LEVEL;
422 unix_path = cvfs_unix_path(ntvfs, req, md->mkdir.in.path);
424 if (mkdir(unix_path, 0777) == -1) {
425 return map_nt_error_from_unix(errno);
434 static NTSTATUS svfs_rmdir(struct ntvfs_module_context *ntvfs,
435 struct ntvfs_request *req, struct smb_rmdir *rd)
439 CHECK_READ_ONLY(req);
441 unix_path = cvfs_unix_path(ntvfs, req, rd->in.path);
443 if (rmdir(unix_path) == -1) {
444 return map_nt_error_from_unix(errno);
451 rename a set of files
453 static NTSTATUS svfs_rename(struct ntvfs_module_context *ntvfs,
454 struct ntvfs_request *req, union smb_rename *ren)
456 char *unix_path1, *unix_path2;
458 CHECK_READ_ONLY(req);
460 if (ren->generic.level != RAW_RENAME_RENAME) {
461 return NT_STATUS_INVALID_LEVEL;
464 unix_path1 = cvfs_unix_path(ntvfs, req, ren->rename.in.pattern1);
465 unix_path2 = cvfs_unix_path(ntvfs, req, ren->rename.in.pattern2);
467 if (rename(unix_path1, unix_path2) == -1) {
468 return map_nt_error_from_unix(errno);
477 static NTSTATUS svfs_copy(struct ntvfs_module_context *ntvfs,
478 struct ntvfs_request *req, struct smb_copy *cp)
480 return NT_STATUS_NOT_SUPPORTED;
486 static NTSTATUS svfs_read(struct ntvfs_module_context *ntvfs,
487 struct ntvfs_request *req, union smb_read *rd)
491 if (rd->generic.level != RAW_READ_READX) {
492 return NT_STATUS_NOT_SUPPORTED;
495 ret = pread(rd->readx.in.file.fnum,
498 rd->readx.in.offset);
500 return map_nt_error_from_unix(errno);
503 rd->readx.out.nread = ret;
504 rd->readx.out.remaining = 0; /* should fill this in? */
505 rd->readx.out.compaction_mode = 0;
513 static NTSTATUS svfs_write(struct ntvfs_module_context *ntvfs,
514 struct ntvfs_request *req, union smb_write *wr)
518 if (wr->generic.level != RAW_WRITE_WRITEX) {
519 return ntvfs_map_write(ntvfs, req, wr);
522 CHECK_READ_ONLY(req);
524 ret = pwrite(wr->writex.in.file.fnum,
527 wr->writex.in.offset);
529 return map_nt_error_from_unix(errno);
532 wr->writex.out.nwritten = ret;
533 wr->writex.out.remaining = 0; /* should fill this in? */
541 static NTSTATUS svfs_seek(struct ntvfs_module_context *ntvfs,
542 struct ntvfs_request *req,
545 return NT_STATUS_NOT_SUPPORTED;
551 static NTSTATUS svfs_flush(struct ntvfs_module_context *ntvfs,
552 struct ntvfs_request *req,
555 fsync(io->flush.in.file.fnum);
562 static NTSTATUS svfs_close(struct ntvfs_module_context *ntvfs,
563 struct ntvfs_request *req,
566 struct svfs_private *private = ntvfs->private_data;
569 if (io->generic.level != RAW_CLOSE_CLOSE) {
570 /* we need a mapping function */
571 return NT_STATUS_INVALID_LEVEL;
574 f = find_fd(private, io->close.in.file.fnum);
576 return NT_STATUS_INVALID_HANDLE;
579 if (close(io->close.in.file.fnum) == -1) {
580 return map_nt_error_from_unix(errno);
583 DLIST_REMOVE(private->open_files, f);
584 talloc_free(f->name);
593 static NTSTATUS svfs_exit(struct ntvfs_module_context *ntvfs,
594 struct ntvfs_request *req)
596 return NT_STATUS_NOT_SUPPORTED;
600 logoff - closing files
602 static NTSTATUS svfs_logoff(struct ntvfs_module_context *ntvfs,
603 struct ntvfs_request *req)
605 return NT_STATUS_NOT_SUPPORTED;
609 setup for an async call
611 static NTSTATUS svfs_async_setup(struct ntvfs_module_context *ntvfs,
612 struct ntvfs_request *req,
621 static NTSTATUS svfs_cancel(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req)
623 return NT_STATUS_UNSUCCESSFUL;
629 static NTSTATUS svfs_lock(struct ntvfs_module_context *ntvfs,
630 struct ntvfs_request *req, union smb_lock *lck)
632 DEBUG(0,("REWRITE: not doing byte range locking!\n"));
637 set info on a pathname
639 static NTSTATUS svfs_setpathinfo(struct ntvfs_module_context *ntvfs,
640 struct ntvfs_request *req, union smb_setfileinfo *st)
642 CHECK_READ_ONLY(req);
644 return NT_STATUS_NOT_SUPPORTED;
648 set info on a open file
650 static NTSTATUS svfs_setfileinfo(struct ntvfs_module_context *ntvfs,
651 struct ntvfs_request *req,
652 union smb_setfileinfo *info)
654 struct utimbuf unix_times;
657 CHECK_READ_ONLY(req);
659 switch (info->generic.level) {
660 case RAW_SFILEINFO_END_OF_FILE_INFO:
661 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
662 if (ftruncate(info->end_of_file_info.in.file.fnum,
663 info->end_of_file_info.in.size) == -1) {
664 return map_nt_error_from_unix(errno);
667 case RAW_SFILEINFO_SETATTRE:
668 unix_times.actime = info->setattre.in.access_time;
669 unix_times.modtime = info->setattre.in.write_time;
670 fd = info->setattre.in.file.fnum;
672 if (unix_times.actime == 0 && unix_times.modtime == 0) {
676 /* set modify time = to access time if modify time was 0 */
677 if (unix_times.actime != 0 && unix_times.modtime == 0) {
678 unix_times.modtime = unix_times.actime;
681 /* Set the date on this file */
682 if (cvfs_file_utime(fd, &unix_times) != 0) {
683 return NT_STATUS_ACCESS_DENIED;
687 DEBUG(2,("svfs_setfileinfo: level %d not implemented\n",
688 info->generic.level));
689 return NT_STATUS_NOT_IMPLEMENTED;
696 return filesystem space info
698 static NTSTATUS svfs_fsinfo(struct ntvfs_module_context *ntvfs,
699 struct ntvfs_request *req, union smb_fsinfo *fs)
701 struct svfs_private *private = ntvfs->private_data;
704 if (fs->generic.level != RAW_QFS_GENERIC) {
705 return ntvfs_map_fsinfo(ntvfs, req, fs);
708 if (sys_fsusage(private->connectpath,
709 &fs->generic.out.blocks_free,
710 &fs->generic.out.blocks_total) == -1) {
711 return map_nt_error_from_unix(errno);
714 fs->generic.out.block_size = 512;
716 if (stat(private->connectpath, &st) != 0) {
717 return NT_STATUS_DISK_CORRUPT_ERROR;
720 fs->generic.out.fs_id = st.st_ino;
721 unix_to_nt_time(&fs->generic.out.create_time, st.st_ctime);
722 fs->generic.out.serial_number = st.st_ino;
723 fs->generic.out.fs_attr = 0;
724 fs->generic.out.max_file_component_length = 255;
725 fs->generic.out.device_type = 0;
726 fs->generic.out.device_characteristics = 0;
727 fs->generic.out.quota_soft = 0;
728 fs->generic.out.quota_hard = 0;
729 fs->generic.out.quota_flags = 0;
730 fs->generic.out.volume_name = talloc_strdup(req, ntvfs->ctx->config->name);
731 fs->generic.out.fs_type = ntvfs->ctx->fs_type;
738 return filesystem attribute info
740 static NTSTATUS svfs_fsattr(struct ntvfs_module_context *ntvfs,
741 struct ntvfs_request *req, union smb_fsattr *fs)
744 struct svfs_private *private = ntvfs->private_data;
746 if (fs->generic.level != RAW_FSATTR_GENERIC) {
747 return ntvfs_map_fsattr(ntvfs, req, fs);
750 if (stat(private->connectpath, &st) == -1) {
751 return map_nt_error_from_unix(errno);
754 unix_to_nt_time(&fs->generic.out.create_time, st.st_ctime);
755 fs->generic.out.fs_attr =
756 FILE_CASE_PRESERVED_NAMES |
757 FILE_CASE_SENSITIVE_SEARCH |
758 FILE_PERSISTENT_ACLS;
759 fs->generic.out.max_file_component_length = 255;
760 fs->generic.out.serial_number = 1;
761 fs->generic.out.fs_type = talloc_strdup(req, "NTFS");
762 fs->generic.out.volume_name = talloc_strdup(req,
763 lp_servicename(req->tcon->service));
770 return print queue info
772 static NTSTATUS svfs_lpq(struct ntvfs_module_context *ntvfs,
773 struct ntvfs_request *req, union smb_lpq *lpq)
775 return NT_STATUS_NOT_SUPPORTED;
779 list files in a directory matching a wildcard pattern
781 static NTSTATUS svfs_search_first(struct ntvfs_module_context *ntvfs,
782 struct ntvfs_request *req, union smb_search_first *io,
783 void *search_private,
784 BOOL (*callback)(void *, union smb_search_data *))
786 struct svfs_dir *dir;
788 struct svfs_private *private = ntvfs->private_data;
789 struct search_state *search;
790 union smb_search_data file;
793 if (io->generic.level != RAW_SEARCH_BOTH_DIRECTORY_INFO) {
794 return NT_STATUS_NOT_SUPPORTED;
797 search = talloc_zero(private, struct search_state);
799 return NT_STATUS_NO_MEMORY;
802 max_count = io->t2ffirst.in.max_count;
804 dir = cvfs_list(ntvfs, req, io->t2ffirst.in.pattern);
806 return NT_STATUS_FOOBAR;
809 search->handle = private->next_search_handle;
812 if (dir->count < max_count) {
813 max_count = dir->count;
816 for (i=0; i < max_count;i++) {
818 unix_to_nt_time(&file.both_directory_info.create_time, dir->files[i].st.st_ctime);
819 unix_to_nt_time(&file.both_directory_info.access_time, dir->files[i].st.st_atime);
820 unix_to_nt_time(&file.both_directory_info.write_time, dir->files[i].st.st_mtime);
821 unix_to_nt_time(&file.both_directory_info.change_time, dir->files[i].st.st_mtime);
822 file.both_directory_info.name.s = dir->files[i].name;
823 file.both_directory_info.short_name.s = dir->files[i].name;
824 file.both_directory_info.size = dir->files[i].st.st_size;
825 file.both_directory_info.attrib = cvfs_unix_to_dos_attrib(dir->files[i].st.st_mode);
827 if (!callback(search_private, &file)) {
832 search->current_index = i;
834 io->t2ffirst.out.count = i;
835 io->t2ffirst.out.handle = search->handle;
836 io->t2ffirst.out.end_of_search = (i == dir->count) ? 1 : 0;
838 /* work out if we are going to keep the search state */
839 if ((io->t2ffirst.in.flags & FLAG_TRANS2_FIND_CLOSE) ||
840 ((io->t2ffirst.in.flags & FLAG_TRANS2_FIND_CLOSE_IF_END) && (i == dir->count))) {
843 private->next_search_handle++;
844 DLIST_ADD(private->search, search);
850 /* continue a search */
851 static NTSTATUS svfs_search_next(struct ntvfs_module_context *ntvfs,
852 struct ntvfs_request *req, union smb_search_next *io,
853 void *search_private,
854 BOOL (*callback)(void *, union smb_search_data *))
856 struct svfs_dir *dir;
858 struct svfs_private *private = ntvfs->private_data;
859 struct search_state *search;
860 union smb_search_data file;
863 if (io->generic.level != RAW_SEARCH_BOTH_DIRECTORY_INFO) {
864 return NT_STATUS_NOT_SUPPORTED;
867 for (search=private->search; search; search = search->next) {
868 if (search->handle == io->t2fnext.in.handle) break;
872 /* we didn't find the search handle */
873 return NT_STATUS_FOOBAR;
878 /* the client might be asking for something other than just continuing
880 if (!(io->t2fnext.in.flags & FLAG_TRANS2_FIND_CONTINUE) &&
881 (io->t2fnext.in.flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) &&
882 io->t2fnext.in.last_name && *io->t2fnext.in.last_name) {
883 /* look backwards first */
884 for (i=search->current_index; i > 0; i--) {
885 if (strcmp(io->t2fnext.in.last_name, dir->files[i-1].name) == 0) {
886 search->current_index = i;
891 /* then look forwards */
892 for (i=search->current_index+1; i <= dir->count; i++) {
893 if (strcmp(io->t2fnext.in.last_name, dir->files[i-1].name) == 0) {
894 search->current_index = i;
901 max_count = search->current_index + io->t2fnext.in.max_count;
903 if (max_count > dir->count) {
904 max_count = dir->count;
907 for (i = search->current_index; i < max_count;i++) {
909 unix_to_nt_time(&file.both_directory_info.create_time, dir->files[i].st.st_ctime);
910 unix_to_nt_time(&file.both_directory_info.access_time, dir->files[i].st.st_atime);
911 unix_to_nt_time(&file.both_directory_info.write_time, dir->files[i].st.st_mtime);
912 unix_to_nt_time(&file.both_directory_info.change_time, dir->files[i].st.st_mtime);
913 file.both_directory_info.name.s = dir->files[i].name;
914 file.both_directory_info.short_name.s = dir->files[i].name;
915 file.both_directory_info.size = dir->files[i].st.st_size;
916 file.both_directory_info.attrib = cvfs_unix_to_dos_attrib(dir->files[i].st.st_mode);
918 if (!callback(search_private, &file)) {
923 io->t2fnext.out.count = i - search->current_index;
924 io->t2fnext.out.end_of_search = (i == dir->count) ? 1 : 0;
926 search->current_index = i;
928 /* work out if we are going to keep the search state */
929 if ((io->t2fnext.in.flags & FLAG_TRANS2_FIND_CLOSE) ||
930 ((io->t2fnext.in.flags & FLAG_TRANS2_FIND_CLOSE_IF_END) && (i == dir->count))) {
931 DLIST_REMOVE(private->search, search);
939 static NTSTATUS svfs_search_close(struct ntvfs_module_context *ntvfs,
940 struct ntvfs_request *req, union smb_search_close *io)
942 struct svfs_private *private = ntvfs->private_data;
943 struct search_state *search;
945 for (search=private->search; search; search = search->next) {
946 if (search->handle == io->findclose.in.handle) break;
950 /* we didn't find the search handle */
951 return NT_STATUS_FOOBAR;
954 DLIST_REMOVE(private->search, search);
960 /* SMBtrans - not used on file shares */
961 static NTSTATUS svfs_trans(struct ntvfs_module_context *ntvfs,
962 struct ntvfs_request *req, struct smb_trans2 *trans2)
964 return NT_STATUS_ACCESS_DENIED;
969 initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
971 NTSTATUS ntvfs_cifs_posix_init(void)
974 struct ntvfs_ops ops;
975 NTVFS_CURRENT_CRITICAL_SIZES(vers);
979 /* fill in all the operations */
980 ops.connect = svfs_connect;
981 ops.disconnect = svfs_disconnect;
982 ops.unlink = svfs_unlink;
983 ops.chkpath = svfs_chkpath;
984 ops.qpathinfo = svfs_qpathinfo;
985 ops.setpathinfo = svfs_setpathinfo;
986 ops.open = svfs_open;
987 ops.mkdir = svfs_mkdir;
988 ops.rmdir = svfs_rmdir;
989 ops.rename = svfs_rename;
990 ops.copy = svfs_copy;
991 ops.ioctl = svfs_ioctl;
992 ops.read = svfs_read;
993 ops.write = svfs_write;
994 ops.seek = svfs_seek;
995 ops.flush = svfs_flush;
996 ops.close = svfs_close;
997 ops.exit = svfs_exit;
998 ops.lock = svfs_lock;
999 ops.setfileinfo = svfs_setfileinfo;
1000 ops.qfileinfo = svfs_qfileinfo;
1001 ops.fsinfo = svfs_fsinfo;
1003 ops.search_first = svfs_search_first;
1004 ops.search_next = svfs_search_next;
1005 ops.search_close = svfs_search_close;
1006 ops.trans = svfs_trans;
1007 ops.logoff = svfs_logoff;
1008 ops.async_setup = svfs_async_setup;
1009 ops.cancel = svfs_cancel;
1011 /* register ourselves with the NTVFS subsystem. We register
1012 under names 'simple'
1015 ops.type = NTVFS_DISK;
1016 ops.name = "cifs-posix-cli";
1017 ret = ntvfs_register(&ops, &vers);
1019 if (!NT_STATUS_IS_OK(ret)) {
1020 DEBUG(0,("Failed to register simple backend with name: %s!\n",