s3:vfs_default: optimize vfswrap_asys_finished() and read as much as we can
[Samba/gebeck_regimport.git] / source3 / modules / vfs_default.c
blob0f651dca51119879c184cc5485455f472b1fa271
1 /*
2 Unix SMB/CIFS implementation.
3 Wrap disk only vfs functions to sidestep dodgy compilers.
4 Copyright (C) Tim Potter 1998
5 Copyright (C) Jeremy Allison 2007
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "system/time.h"
23 #include "system/filesys.h"
24 #include "smbd/smbd.h"
25 #include "smbd/globals.h"
26 #include "ntioctl.h"
27 #include "smbprofile.h"
28 #include "../libcli/security/security.h"
29 #include "passdb/lookup_sid.h"
30 #include "source3/include/msdfs.h"
31 #include "librpc/gen_ndr/ndr_dfsblobs.h"
32 #include "lib/util/tevent_unix.h"
33 #include "lib/asys/asys.h"
35 #undef DBGC_CLASS
36 #define DBGC_CLASS DBGC_VFS
38 /* Check for NULL pointer parameters in vfswrap_* functions */
40 /* We don't want to have NULL function pointers lying around. Someone
41 is sure to try and execute them. These stubs are used to prevent
42 this possibility. */
44 static int vfswrap_connect(vfs_handle_struct *handle, const char *service, const char *user)
46 return 0; /* Return >= 0 for success */
49 static void vfswrap_disconnect(vfs_handle_struct *handle)
53 /* Disk operations */
55 static uint64_t vfswrap_disk_free(vfs_handle_struct *handle, const char *path, bool small_query, uint64_t *bsize,
56 uint64_t *dfree, uint64_t *dsize)
58 uint64_t result;
60 result = sys_disk_free(handle->conn, path, small_query, bsize, dfree, dsize);
61 return result;
64 static int vfswrap_get_quota(struct vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
66 #ifdef HAVE_SYS_QUOTAS
67 int result;
69 START_PROFILE(syscall_get_quota);
70 result = sys_get_quota(handle->conn->connectpath, qtype, id, qt);
71 END_PROFILE(syscall_get_quota);
72 return result;
73 #else
74 errno = ENOSYS;
75 return -1;
76 #endif
79 static int vfswrap_set_quota(struct vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
81 #ifdef HAVE_SYS_QUOTAS
82 int result;
84 START_PROFILE(syscall_set_quota);
85 result = sys_set_quota(handle->conn->connectpath, qtype, id, qt);
86 END_PROFILE(syscall_set_quota);
87 return result;
88 #else
89 errno = ENOSYS;
90 return -1;
91 #endif
94 static int vfswrap_get_shadow_copy_data(struct vfs_handle_struct *handle,
95 struct files_struct *fsp,
96 struct shadow_copy_data *shadow_copy_data,
97 bool labels)
99 errno = ENOSYS;
100 return -1; /* Not implemented. */
103 static int vfswrap_statvfs(struct vfs_handle_struct *handle, const char *path, vfs_statvfs_struct *statbuf)
105 return sys_statvfs(path, statbuf);
108 static uint32_t vfswrap_fs_capabilities(struct vfs_handle_struct *handle,
109 enum timestamp_set_resolution *p_ts_res)
111 connection_struct *conn = handle->conn;
112 uint32_t caps = FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
113 struct smb_filename *smb_fname_cpath = NULL;
114 struct vfs_statvfs_struct statbuf;
115 NTSTATUS status;
116 int ret;
118 ZERO_STRUCT(statbuf);
119 ret = sys_statvfs(conn->connectpath, &statbuf);
120 if (ret == 0) {
121 caps = statbuf.FsCapabilities;
124 *p_ts_res = TIMESTAMP_SET_SECONDS;
126 /* Work out what timestamp resolution we can
127 * use when setting a timestamp. */
129 status = create_synthetic_smb_fname(talloc_tos(),
130 conn->connectpath,
131 NULL,
132 NULL,
133 &smb_fname_cpath);
134 if (!NT_STATUS_IS_OK(status)) {
135 return caps;
138 ret = SMB_VFS_STAT(conn, smb_fname_cpath);
139 if (ret == -1) {
140 TALLOC_FREE(smb_fname_cpath);
141 return caps;
144 if (smb_fname_cpath->st.st_ex_mtime.tv_nsec ||
145 smb_fname_cpath->st.st_ex_atime.tv_nsec ||
146 smb_fname_cpath->st.st_ex_ctime.tv_nsec) {
147 /* If any of the normal UNIX directory timestamps
148 * have a non-zero tv_nsec component assume
149 * we might be able to set sub-second timestamps.
150 * See what filetime set primitives we have.
152 #if defined(HAVE_UTIMENSAT)
153 *p_ts_res = TIMESTAMP_SET_NT_OR_BETTER;
154 #elif defined(HAVE_UTIMES)
155 /* utimes allows msec timestamps to be set. */
156 *p_ts_res = TIMESTAMP_SET_MSEC;
157 #elif defined(HAVE_UTIME)
158 /* utime only allows sec timestamps to be set. */
159 *p_ts_res = TIMESTAMP_SET_SECONDS;
160 #endif
162 DEBUG(10,("vfswrap_fs_capabilities: timestamp "
163 "resolution of %s "
164 "available on share %s, directory %s\n",
165 *p_ts_res == TIMESTAMP_SET_MSEC ? "msec" : "sec",
166 lp_servicename(talloc_tos(), conn->params->service),
167 conn->connectpath ));
169 TALLOC_FREE(smb_fname_cpath);
170 return caps;
173 static NTSTATUS vfswrap_get_dfs_referrals(struct vfs_handle_struct *handle,
174 struct dfs_GetDFSReferral *r)
176 struct junction_map *junction = NULL;
177 int consumedcnt = 0;
178 bool self_referral = false;
179 char *pathnamep = NULL;
180 char *local_dfs_path = NULL;
181 NTSTATUS status;
182 int i;
183 uint16_t max_referral_level = r->in.req.max_referral_level;
185 if (DEBUGLVL(10)) {
186 NDR_PRINT_IN_DEBUG(dfs_GetDFSReferral, r);
189 /* get the junction entry */
190 if (r->in.req.servername == NULL) {
191 return NT_STATUS_NOT_FOUND;
195 * Trim pathname sent by client so it begins with only one backslash.
196 * Two backslashes confuse some dfs clients
199 local_dfs_path = talloc_strdup(r, r->in.req.servername);
200 if (local_dfs_path == NULL) {
201 return NT_STATUS_NO_MEMORY;
203 pathnamep = local_dfs_path;
204 while (IS_DIRECTORY_SEP(pathnamep[0]) &&
205 IS_DIRECTORY_SEP(pathnamep[1])) {
206 pathnamep++;
209 junction = talloc_zero(r, struct junction_map);
210 if (junction == NULL) {
211 return NT_STATUS_NO_MEMORY;
214 /* The following call can change cwd. */
215 status = get_referred_path(r, pathnamep,
216 !handle->conn->sconn->using_smb2,
217 junction, &consumedcnt, &self_referral);
218 if (!NT_STATUS_IS_OK(status)) {
219 vfs_ChDir(handle->conn, handle->conn->connectpath);
220 return status;
222 vfs_ChDir(handle->conn, handle->conn->connectpath);
224 if (!self_referral) {
225 pathnamep[consumedcnt] = '\0';
227 if (DEBUGLVL(3)) {
228 dbgtext("setup_dfs_referral: Path %s to "
229 "alternate path(s):",
230 pathnamep);
231 for (i=0; i < junction->referral_count; i++) {
232 dbgtext(" %s",
233 junction->referral_list[i].alternate_path);
235 dbgtext(".\n");
239 if (r->in.req.max_referral_level <= 2) {
240 max_referral_level = 2;
242 if (r->in.req.max_referral_level >= 3) {
243 max_referral_level = 3;
246 r->out.resp = talloc_zero(r, struct dfs_referral_resp);
247 if (r->out.resp == NULL) {
248 return NT_STATUS_NO_MEMORY;
251 r->out.resp->path_consumed = strlen_m(pathnamep) * 2;
252 r->out.resp->nb_referrals = junction->referral_count;
254 r->out.resp->header_flags = DFS_HEADER_FLAG_STORAGE_SVR;
255 if (self_referral) {
256 r->out.resp->header_flags |= DFS_HEADER_FLAG_REFERAL_SVR;
259 r->out.resp->referral_entries = talloc_zero_array(r,
260 struct dfs_referral_type,
261 r->out.resp->nb_referrals);
262 if (r->out.resp->referral_entries == NULL) {
263 return NT_STATUS_NO_MEMORY;
266 switch (max_referral_level) {
267 case 2:
268 for(i=0; i < junction->referral_count; i++) {
269 struct referral *ref = &junction->referral_list[i];
270 TALLOC_CTX *mem_ctx = r->out.resp->referral_entries;
271 struct dfs_referral_type *t =
272 &r->out.resp->referral_entries[i];
273 struct dfs_referral_v2 *v2 = &t->referral.v2;
275 t->version = 2;
276 v2->size = VERSION2_REFERRAL_SIZE;
277 if (self_referral) {
278 v2->server_type = DFS_SERVER_ROOT;
279 } else {
280 v2->server_type = DFS_SERVER_NON_ROOT;
282 v2->entry_flags = 0;
283 v2->proximity = ref->proximity;
284 v2->ttl = ref->ttl;
285 v2->DFS_path = talloc_strdup(mem_ctx, pathnamep);
286 if (v2->DFS_path == NULL) {
287 return NT_STATUS_NO_MEMORY;
289 v2->DFS_alt_path = talloc_strdup(mem_ctx, pathnamep);
290 if (v2->DFS_alt_path == NULL) {
291 return NT_STATUS_NO_MEMORY;
293 v2->netw_address = talloc_strdup(mem_ctx,
294 ref->alternate_path);
295 if (v2->netw_address == NULL) {
296 return NT_STATUS_NO_MEMORY;
300 break;
301 case 3:
302 for(i=0; i < junction->referral_count; i++) {
303 struct referral *ref = &junction->referral_list[i];
304 TALLOC_CTX *mem_ctx = r->out.resp->referral_entries;
305 struct dfs_referral_type *t =
306 &r->out.resp->referral_entries[i];
307 struct dfs_referral_v3 *v3 = &t->referral.v3;
308 struct dfs_normal_referral *r1 = &v3->referrals.r1;
310 t->version = 3;
311 v3->size = VERSION3_REFERRAL_SIZE;
312 if (self_referral) {
313 v3->server_type = DFS_SERVER_ROOT;
314 } else {
315 v3->server_type = DFS_SERVER_NON_ROOT;
317 v3->entry_flags = 0;
318 v3->ttl = ref->ttl;
319 r1->DFS_path = talloc_strdup(mem_ctx, pathnamep);
320 if (r1->DFS_path == NULL) {
321 return NT_STATUS_NO_MEMORY;
323 r1->DFS_alt_path = talloc_strdup(mem_ctx, pathnamep);
324 if (r1->DFS_alt_path == NULL) {
325 return NT_STATUS_NO_MEMORY;
327 r1->netw_address = talloc_strdup(mem_ctx,
328 ref->alternate_path);
329 if (r1->netw_address == NULL) {
330 return NT_STATUS_NO_MEMORY;
333 break;
334 default:
335 DEBUG(0,("setup_dfs_referral: Invalid dfs referral "
336 "version: %d\n",
337 max_referral_level));
338 return NT_STATUS_INVALID_LEVEL;
341 if (DEBUGLVL(10)) {
342 NDR_PRINT_OUT_DEBUG(dfs_GetDFSReferral, r);
345 return NT_STATUS_OK;
348 /* Directory operations */
350 static DIR *vfswrap_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr)
352 DIR *result;
354 START_PROFILE(syscall_opendir);
355 result = opendir(fname);
356 END_PROFILE(syscall_opendir);
357 return result;
360 static DIR *vfswrap_fdopendir(vfs_handle_struct *handle,
361 files_struct *fsp,
362 const char *mask,
363 uint32 attr)
365 DIR *result;
367 START_PROFILE(syscall_fdopendir);
368 result = sys_fdopendir(fsp->fh->fd);
369 END_PROFILE(syscall_fdopendir);
370 return result;
374 static struct dirent *vfswrap_readdir(vfs_handle_struct *handle,
375 DIR *dirp,
376 SMB_STRUCT_STAT *sbuf)
378 struct dirent *result;
380 START_PROFILE(syscall_readdir);
381 result = readdir(dirp);
382 /* Default Posix readdir() does not give us stat info.
383 * Set to invalid to indicate we didn't return this info. */
384 if (sbuf)
385 SET_STAT_INVALID(*sbuf);
386 END_PROFILE(syscall_readdir);
387 return result;
390 static void vfswrap_seekdir(vfs_handle_struct *handle, DIR *dirp, long offset)
392 START_PROFILE(syscall_seekdir);
393 seekdir(dirp, offset);
394 END_PROFILE(syscall_seekdir);
397 static long vfswrap_telldir(vfs_handle_struct *handle, DIR *dirp)
399 long result;
400 START_PROFILE(syscall_telldir);
401 result = telldir(dirp);
402 END_PROFILE(syscall_telldir);
403 return result;
406 static void vfswrap_rewinddir(vfs_handle_struct *handle, DIR *dirp)
408 START_PROFILE(syscall_rewinddir);
409 rewinddir(dirp);
410 END_PROFILE(syscall_rewinddir);
413 static int vfswrap_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode)
415 int result;
416 bool has_dacl = False;
417 char *parent = NULL;
419 START_PROFILE(syscall_mkdir);
421 if (lp_inherit_acls(SNUM(handle->conn))
422 && parent_dirname(talloc_tos(), path, &parent, NULL)
423 && (has_dacl = directory_has_default_acl(handle->conn, parent)))
424 mode = (0777 & lp_dir_mask(SNUM(handle->conn)));
426 TALLOC_FREE(parent);
428 result = mkdir(path, mode);
430 if (result == 0 && !has_dacl) {
432 * We need to do this as the default behavior of POSIX ACLs
433 * is to set the mask to be the requested group permission
434 * bits, not the group permission bits to be the requested
435 * group permission bits. This is not what we want, as it will
436 * mess up any inherited ACL bits that were set. JRA.
438 int saved_errno = errno; /* We may get ENOSYS */
439 if ((SMB_VFS_CHMOD_ACL(handle->conn, path, mode) == -1) && (errno == ENOSYS))
440 errno = saved_errno;
443 END_PROFILE(syscall_mkdir);
444 return result;
447 static int vfswrap_rmdir(vfs_handle_struct *handle, const char *path)
449 int result;
451 START_PROFILE(syscall_rmdir);
452 result = rmdir(path);
453 END_PROFILE(syscall_rmdir);
454 return result;
457 static int vfswrap_closedir(vfs_handle_struct *handle, DIR *dirp)
459 int result;
461 START_PROFILE(syscall_closedir);
462 result = closedir(dirp);
463 END_PROFILE(syscall_closedir);
464 return result;
467 static void vfswrap_init_search_op(vfs_handle_struct *handle,
468 DIR *dirp)
470 /* Default behavior is a NOOP */
473 /* File operations */
475 static int vfswrap_open(vfs_handle_struct *handle,
476 struct smb_filename *smb_fname,
477 files_struct *fsp, int flags, mode_t mode)
479 int result = -1;
481 START_PROFILE(syscall_open);
483 if (smb_fname->stream_name) {
484 errno = ENOENT;
485 goto out;
488 result = open(smb_fname->base_name, flags, mode);
489 out:
490 END_PROFILE(syscall_open);
491 return result;
494 static NTSTATUS vfswrap_create_file(vfs_handle_struct *handle,
495 struct smb_request *req,
496 uint16_t root_dir_fid,
497 struct smb_filename *smb_fname,
498 uint32_t access_mask,
499 uint32_t share_access,
500 uint32_t create_disposition,
501 uint32_t create_options,
502 uint32_t file_attributes,
503 uint32_t oplock_request,
504 uint64_t allocation_size,
505 uint32_t private_flags,
506 struct security_descriptor *sd,
507 struct ea_list *ea_list,
508 files_struct **result,
509 int *pinfo)
511 return create_file_default(handle->conn, req, root_dir_fid, smb_fname,
512 access_mask, share_access,
513 create_disposition, create_options,
514 file_attributes, oplock_request,
515 allocation_size, private_flags,
516 sd, ea_list, result,
517 pinfo);
520 static int vfswrap_close(vfs_handle_struct *handle, files_struct *fsp)
522 int result;
524 START_PROFILE(syscall_close);
525 result = fd_close_posix(fsp);
526 END_PROFILE(syscall_close);
527 return result;
530 static ssize_t vfswrap_read(vfs_handle_struct *handle, files_struct *fsp, void *data, size_t n)
532 ssize_t result;
534 START_PROFILE_BYTES(syscall_read, n);
535 result = sys_read(fsp->fh->fd, data, n);
536 END_PROFILE(syscall_read);
537 return result;
540 static ssize_t vfswrap_pread(vfs_handle_struct *handle, files_struct *fsp, void *data,
541 size_t n, off_t offset)
543 ssize_t result;
545 #if defined(HAVE_PREAD) || defined(HAVE_PREAD64)
546 START_PROFILE_BYTES(syscall_pread, n);
547 result = sys_pread(fsp->fh->fd, data, n, offset);
548 END_PROFILE(syscall_pread);
550 if (result == -1 && errno == ESPIPE) {
551 /* Maintain the fiction that pipes can be seeked (sought?) on. */
552 result = SMB_VFS_READ(fsp, data, n);
553 fsp->fh->pos = 0;
556 #else /* HAVE_PREAD */
557 off_t curr;
558 int lerrno;
560 curr = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR);
561 if (curr == -1 && errno == ESPIPE) {
562 /* Maintain the fiction that pipes can be seeked (sought?) on. */
563 result = SMB_VFS_READ(fsp, data, n);
564 fsp->fh->pos = 0;
565 return result;
568 if (SMB_VFS_LSEEK(fsp, offset, SEEK_SET) == -1) {
569 return -1;
572 errno = 0;
573 result = SMB_VFS_READ(fsp, data, n);
574 lerrno = errno;
576 SMB_VFS_LSEEK(fsp, curr, SEEK_SET);
577 errno = lerrno;
579 #endif /* HAVE_PREAD */
581 return result;
584 static ssize_t vfswrap_write(vfs_handle_struct *handle, files_struct *fsp, const void *data, size_t n)
586 ssize_t result;
588 START_PROFILE_BYTES(syscall_write, n);
589 result = sys_write(fsp->fh->fd, data, n);
590 END_PROFILE(syscall_write);
591 return result;
594 static ssize_t vfswrap_pwrite(vfs_handle_struct *handle, files_struct *fsp, const void *data,
595 size_t n, off_t offset)
597 ssize_t result;
599 #if defined(HAVE_PWRITE) || defined(HAVE_PRWITE64)
600 START_PROFILE_BYTES(syscall_pwrite, n);
601 result = sys_pwrite(fsp->fh->fd, data, n, offset);
602 END_PROFILE(syscall_pwrite);
604 if (result == -1 && errno == ESPIPE) {
605 /* Maintain the fiction that pipes can be sought on. */
606 result = SMB_VFS_WRITE(fsp, data, n);
609 #else /* HAVE_PWRITE */
610 off_t curr;
611 int lerrno;
613 curr = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR);
614 if (curr == -1) {
615 return -1;
618 if (SMB_VFS_LSEEK(fsp, offset, SEEK_SET) == -1) {
619 return -1;
622 result = SMB_VFS_WRITE(fsp, data, n);
623 lerrno = errno;
625 SMB_VFS_LSEEK(fsp, curr, SEEK_SET);
626 errno = lerrno;
628 #endif /* HAVE_PWRITE */
630 return result;
633 static void vfswrap_asys_finished(struct tevent_context *ev,
634 struct tevent_fd *fde,
635 uint16_t flags, void *p);
637 static bool vfswrap_init_asys_ctx(struct smbXsrv_connection *conn)
639 int ret;
640 int fd;
642 if (conn->asys_ctx != NULL) {
643 return true;
645 ret = asys_context_init(&conn->asys_ctx, aio_pending_size);
646 if (ret != 0) {
647 DEBUG(1, ("asys_context_init failed: %s\n", strerror(ret)));
648 return false;
651 fd = asys_signalfd(conn->asys_ctx);
653 set_blocking(fd, false);
655 conn->asys_fde = tevent_add_fd(conn->ev_ctx, conn, fd,
656 TEVENT_FD_READ,
657 vfswrap_asys_finished,
658 conn->asys_ctx);
659 if (conn->asys_fde == NULL) {
660 DEBUG(1, ("tevent_add_fd failed\n"));
661 asys_context_destroy(conn->asys_ctx);
662 conn->asys_ctx = NULL;
663 return false;
665 return true;
668 struct vfswrap_asys_state {
669 struct asys_context *asys_ctx;
670 struct tevent_req *req;
671 ssize_t ret;
672 int err;
675 static int vfswrap_asys_state_destructor(struct vfswrap_asys_state *s)
677 asys_cancel(s->asys_ctx, s->req);
678 return 0;
681 static struct tevent_req *vfswrap_pread_send(struct vfs_handle_struct *handle,
682 TALLOC_CTX *mem_ctx,
683 struct tevent_context *ev,
684 struct files_struct *fsp,
685 void *data,
686 size_t n, off_t offset)
688 struct tevent_req *req;
689 struct vfswrap_asys_state *state;
690 int ret;
692 req = tevent_req_create(mem_ctx, &state, struct vfswrap_asys_state);
693 if (req == NULL) {
694 return NULL;
696 if (!vfswrap_init_asys_ctx(handle->conn->sconn->conn)) {
697 tevent_req_oom(req);
698 return tevent_req_post(req, ev);
700 state->asys_ctx = handle->conn->sconn->conn->asys_ctx;
701 state->req = req;
703 ret = asys_pread(state->asys_ctx, fsp->fh->fd, data, n, offset, req);
704 if (ret != 0) {
705 tevent_req_error(req, ret);
706 return tevent_req_post(req, ev);
708 talloc_set_destructor(state, vfswrap_asys_state_destructor);
710 return req;
713 static struct tevent_req *vfswrap_pwrite_send(struct vfs_handle_struct *handle,
714 TALLOC_CTX *mem_ctx,
715 struct tevent_context *ev,
716 struct files_struct *fsp,
717 const void *data,
718 size_t n, off_t offset)
720 struct tevent_req *req;
721 struct vfswrap_asys_state *state;
722 int ret;
724 req = tevent_req_create(mem_ctx, &state, struct vfswrap_asys_state);
725 if (req == NULL) {
726 return NULL;
728 if (!vfswrap_init_asys_ctx(handle->conn->sconn->conn)) {
729 tevent_req_oom(req);
730 return tevent_req_post(req, ev);
732 state->asys_ctx = handle->conn->sconn->conn->asys_ctx;
733 state->req = req;
735 ret = asys_pwrite(state->asys_ctx, fsp->fh->fd, data, n, offset, req);
736 if (ret != 0) {
737 tevent_req_error(req, ret);
738 return tevent_req_post(req, ev);
740 talloc_set_destructor(state, vfswrap_asys_state_destructor);
742 return req;
745 static struct tevent_req *vfswrap_fsync_send(struct vfs_handle_struct *handle,
746 TALLOC_CTX *mem_ctx,
747 struct tevent_context *ev,
748 struct files_struct *fsp)
750 struct tevent_req *req;
751 struct vfswrap_asys_state *state;
752 int ret;
754 req = tevent_req_create(mem_ctx, &state, struct vfswrap_asys_state);
755 if (req == NULL) {
756 return NULL;
758 if (!vfswrap_init_asys_ctx(handle->conn->sconn->conn)) {
759 tevent_req_oom(req);
760 return tevent_req_post(req, ev);
762 state->asys_ctx = handle->conn->sconn->conn->asys_ctx;
763 state->req = req;
765 ret = asys_fsync(state->asys_ctx, fsp->fh->fd, req);
766 if (ret != 0) {
767 tevent_req_error(req, ret);
768 return tevent_req_post(req, ev);
770 talloc_set_destructor(state, vfswrap_asys_state_destructor);
772 return req;
775 static void vfswrap_asys_finished(struct tevent_context *ev,
776 struct tevent_fd *fde,
777 uint16_t flags, void *p)
779 struct asys_context *asys_ctx = (struct asys_context *)p;
780 struct tevent_req *req;
781 struct vfswrap_asys_state *state;
782 int res;
783 ssize_t ret;
784 int err;
785 void *private_data;
787 if ((flags & TEVENT_FD_READ) == 0) {
788 return;
791 while (true) {
792 res = asys_result(asys_ctx, &ret, &err, &private_data);
793 if (res == EINTR || res == EAGAIN) {
794 return;
796 #ifdef EWOULDBLOCK
797 if (res == EWOULDBLOCK) {
798 return;
800 #endif
802 if (res == ECANCELED) {
803 return;
806 if (res != 0) {
807 DEBUG(1, ("asys_result returned %s\n", strerror(res)));
808 return;
811 req = talloc_get_type_abort(private_data, struct tevent_req);
812 state = tevent_req_data(req, struct vfswrap_asys_state);
814 talloc_set_destructor(state, NULL);
816 state->ret = ret;
817 state->err = err;
818 tevent_req_defer_callback(req, ev);
819 tevent_req_done(req);
823 static ssize_t vfswrap_asys_ssize_t_recv(struct tevent_req *req, int *err)
825 struct vfswrap_asys_state *state = tevent_req_data(
826 req, struct vfswrap_asys_state);
828 if (tevent_req_is_unix_error(req, err)) {
829 return -1;
831 *err = state->err;
832 return state->ret;
835 static int vfswrap_asys_int_recv(struct tevent_req *req, int *err)
837 struct vfswrap_asys_state *state = tevent_req_data(
838 req, struct vfswrap_asys_state);
840 if (tevent_req_is_unix_error(req, err)) {
841 return -1;
843 *err = state->err;
844 return state->ret;
847 static off_t vfswrap_lseek(vfs_handle_struct *handle, files_struct *fsp, off_t offset, int whence)
849 off_t result = 0;
851 START_PROFILE(syscall_lseek);
853 /* Cope with 'stat' file opens. */
854 if (fsp->fh->fd != -1)
855 result = lseek(fsp->fh->fd, offset, whence);
858 * We want to maintain the fiction that we can seek
859 * on a fifo for file system purposes. This allows
860 * people to set up UNIX fifo's that feed data to Windows
861 * applications. JRA.
864 if((result == -1) && (errno == ESPIPE)) {
865 result = 0;
866 errno = 0;
869 END_PROFILE(syscall_lseek);
870 return result;
873 static ssize_t vfswrap_sendfile(vfs_handle_struct *handle, int tofd, files_struct *fromfsp, const DATA_BLOB *hdr,
874 off_t offset, size_t n)
876 ssize_t result;
878 START_PROFILE_BYTES(syscall_sendfile, n);
879 result = sys_sendfile(tofd, fromfsp->fh->fd, hdr, offset, n);
880 END_PROFILE(syscall_sendfile);
881 return result;
884 static ssize_t vfswrap_recvfile(vfs_handle_struct *handle,
885 int fromfd,
886 files_struct *tofsp,
887 off_t offset,
888 size_t n)
890 ssize_t result;
892 START_PROFILE_BYTES(syscall_recvfile, n);
893 result = sys_recvfile(fromfd, tofsp->fh->fd, offset, n);
894 END_PROFILE(syscall_recvfile);
895 return result;
898 static int vfswrap_rename(vfs_handle_struct *handle,
899 const struct smb_filename *smb_fname_src,
900 const struct smb_filename *smb_fname_dst)
902 int result = -1;
904 START_PROFILE(syscall_rename);
906 if (smb_fname_src->stream_name || smb_fname_dst->stream_name) {
907 errno = ENOENT;
908 goto out;
911 result = rename(smb_fname_src->base_name, smb_fname_dst->base_name);
913 out:
914 END_PROFILE(syscall_rename);
915 return result;
918 static int vfswrap_fsync(vfs_handle_struct *handle, files_struct *fsp)
920 #ifdef HAVE_FSYNC
921 int result;
923 START_PROFILE(syscall_fsync);
924 result = fsync(fsp->fh->fd);
925 END_PROFILE(syscall_fsync);
926 return result;
927 #else
928 return 0;
929 #endif
932 static int vfswrap_stat(vfs_handle_struct *handle,
933 struct smb_filename *smb_fname)
935 int result = -1;
937 START_PROFILE(syscall_stat);
939 if (smb_fname->stream_name) {
940 errno = ENOENT;
941 goto out;
944 result = sys_stat(smb_fname->base_name, &smb_fname->st,
945 lp_fake_dir_create_times(SNUM(handle->conn)));
946 out:
947 END_PROFILE(syscall_stat);
948 return result;
951 static int vfswrap_fstat(vfs_handle_struct *handle, files_struct *fsp, SMB_STRUCT_STAT *sbuf)
953 int result;
955 START_PROFILE(syscall_fstat);
956 result = sys_fstat(fsp->fh->fd,
957 sbuf, lp_fake_dir_create_times(SNUM(handle->conn)));
958 END_PROFILE(syscall_fstat);
959 return result;
962 static int vfswrap_lstat(vfs_handle_struct *handle,
963 struct smb_filename *smb_fname)
965 int result = -1;
967 START_PROFILE(syscall_lstat);
969 if (smb_fname->stream_name) {
970 errno = ENOENT;
971 goto out;
974 result = sys_lstat(smb_fname->base_name, &smb_fname->st,
975 lp_fake_dir_create_times(SNUM(handle->conn)));
976 out:
977 END_PROFILE(syscall_lstat);
978 return result;
981 static NTSTATUS vfswrap_translate_name(struct vfs_handle_struct *handle,
982 const char *name,
983 enum vfs_translate_direction direction,
984 TALLOC_CTX *mem_ctx,
985 char **mapped_name)
987 return NT_STATUS_NONE_MAPPED;
991 * Implement the default fsctl operation.
993 static bool vfswrap_logged_ioctl_message = false;
995 static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
996 struct files_struct *fsp,
997 TALLOC_CTX *ctx,
998 uint32_t function,
999 uint16_t req_flags, /* Needed for UNICODE ... */
1000 const uint8_t *_in_data,
1001 uint32_t in_len,
1002 uint8_t **_out_data,
1003 uint32_t max_out_len,
1004 uint32_t *out_len)
1006 const char *in_data = (const char *)_in_data;
1007 char **out_data = (char **)_out_data;
1009 switch (function) {
1010 case FSCTL_SET_SPARSE:
1012 bool set_sparse = true;
1013 NTSTATUS status;
1015 if (in_len >= 1 && in_data[0] == 0) {
1016 set_sparse = false;
1019 status = file_set_sparse(handle->conn, fsp, set_sparse);
1021 DEBUG(NT_STATUS_IS_OK(status) ? 10 : 9,
1022 ("FSCTL_SET_SPARSE: fname[%s] set[%u] - %s\n",
1023 smb_fname_str_dbg(fsp->fsp_name), set_sparse,
1024 nt_errstr(status)));
1026 return status;
1029 case FSCTL_CREATE_OR_GET_OBJECT_ID:
1031 unsigned char objid[16];
1032 char *return_data = NULL;
1034 /* This should return the object-id on this file.
1035 * I think I'll make this be the inode+dev. JRA.
1038 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on %s\n",
1039 fsp_fnum_dbg(fsp)));
1041 *out_len = (max_out_len >= 64) ? 64 : max_out_len;
1042 /* Hmmm, will this cause problems if less data asked for? */
1043 return_data = talloc_array(ctx, char, 64);
1044 if (return_data == NULL) {
1045 return NT_STATUS_NO_MEMORY;
1048 /* For backwards compatibility only store the dev/inode. */
1049 push_file_id_16(return_data, &fsp->file_id);
1050 memcpy(return_data+16,create_volume_objectid(fsp->conn,objid),16);
1051 push_file_id_16(return_data+32, &fsp->file_id);
1052 *out_data = return_data;
1053 return NT_STATUS_OK;
1056 case FSCTL_GET_REPARSE_POINT:
1058 /* Fail it with STATUS_NOT_A_REPARSE_POINT */
1059 DEBUG(10, ("FSCTL_GET_REPARSE_POINT: called on %s. "
1060 "Status: NOT_IMPLEMENTED\n", fsp_fnum_dbg(fsp)));
1061 return NT_STATUS_NOT_A_REPARSE_POINT;
1064 case FSCTL_SET_REPARSE_POINT:
1066 /* Fail it with STATUS_NOT_A_REPARSE_POINT */
1067 DEBUG(10, ("FSCTL_SET_REPARSE_POINT: called on %s. "
1068 "Status: NOT_IMPLEMENTED\n", fsp_fnum_dbg(fsp)));
1069 return NT_STATUS_NOT_A_REPARSE_POINT;
1072 case FSCTL_GET_SHADOW_COPY_DATA:
1075 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1076 * and return their volume names. If max_data_count is 16, then it is just
1077 * asking for the number of volumes and length of the combined names.
1079 * pdata is the data allocated by our caller, but that uses
1080 * total_data_count (which is 0 in our case) rather than max_data_count.
1081 * Allocate the correct amount and return the pointer to let
1082 * it be deallocated when we return.
1084 struct shadow_copy_data *shadow_data = NULL;
1085 bool labels = False;
1086 uint32 labels_data_count = 0;
1087 uint32 i;
1088 char *cur_pdata = NULL;
1090 if (max_out_len < 16) {
1091 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1092 max_out_len));
1093 return NT_STATUS_INVALID_PARAMETER;
1096 if (max_out_len > 16) {
1097 labels = True;
1100 shadow_data = talloc_zero(ctx, struct shadow_copy_data);
1101 if (shadow_data == NULL) {
1102 DEBUG(0,("TALLOC_ZERO() failed!\n"));
1103 return NT_STATUS_NO_MEMORY;
1107 * Call the VFS routine to actually do the work.
1109 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
1110 TALLOC_FREE(shadow_data);
1111 if (errno == ENOSYS) {
1112 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
1113 fsp->conn->connectpath));
1114 return NT_STATUS_NOT_SUPPORTED;
1115 } else {
1116 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
1117 fsp->conn->connectpath));
1118 return NT_STATUS_UNSUCCESSFUL;
1122 labels_data_count = (shadow_data->num_volumes * 2 *
1123 sizeof(SHADOW_COPY_LABEL)) + 2;
1125 if (!labels) {
1126 *out_len = 16;
1127 } else {
1128 *out_len = 12 + labels_data_count + 4;
1131 if (max_out_len < *out_len) {
1132 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
1133 max_out_len, *out_len));
1134 TALLOC_FREE(shadow_data);
1135 return NT_STATUS_BUFFER_TOO_SMALL;
1138 cur_pdata = talloc_array(ctx, char, *out_len);
1139 if (cur_pdata == NULL) {
1140 TALLOC_FREE(shadow_data);
1141 return NT_STATUS_NO_MEMORY;
1144 *out_data = cur_pdata;
1146 /* num_volumes 4 bytes */
1147 SIVAL(cur_pdata, 0, shadow_data->num_volumes);
1149 if (labels) {
1150 /* num_labels 4 bytes */
1151 SIVAL(cur_pdata, 4, shadow_data->num_volumes);
1154 /* needed_data_count 4 bytes */
1155 SIVAL(cur_pdata, 8, labels_data_count + 4);
1157 cur_pdata += 12;
1159 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
1160 shadow_data->num_volumes, fsp_str_dbg(fsp)));
1161 if (labels && shadow_data->labels) {
1162 for (i=0; i<shadow_data->num_volumes; i++) {
1163 srvstr_push(cur_pdata, req_flags,
1164 cur_pdata, shadow_data->labels[i],
1165 2 * sizeof(SHADOW_COPY_LABEL),
1166 STR_UNICODE|STR_TERMINATE);
1167 cur_pdata += 2 * sizeof(SHADOW_COPY_LABEL);
1168 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
1172 TALLOC_FREE(shadow_data);
1174 return NT_STATUS_OK;
1177 case FSCTL_FIND_FILES_BY_SID:
1179 /* pretend this succeeded -
1181 * we have to send back a list with all files owned by this SID
1183 * but I have to check that --metze
1185 struct dom_sid sid;
1186 uid_t uid;
1187 size_t sid_len;
1189 DEBUG(10, ("FSCTL_FIND_FILES_BY_SID: called on %s\n",
1190 fsp_fnum_dbg(fsp)));
1192 if (in_len < 8) {
1193 /* NT_STATUS_BUFFER_TOO_SMALL maybe? */
1194 return NT_STATUS_INVALID_PARAMETER;
1197 sid_len = MIN(in_len - 4,SID_MAX_SIZE);
1199 /* unknown 4 bytes: this is not the length of the sid :-( */
1200 /*unknown = IVAL(pdata,0);*/
1202 if (!sid_parse(in_data + 4, sid_len, &sid)) {
1203 return NT_STATUS_INVALID_PARAMETER;
1205 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
1207 if (!sid_to_uid(&sid, &uid)) {
1208 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
1209 sid_string_dbg(&sid),
1210 (unsigned long)sid_len));
1211 uid = (-1);
1214 /* we can take a look at the find source :-)
1216 * find ./ -uid $uid -name '*' is what we need here
1219 * and send 4bytes len and then NULL terminated unicode strings
1220 * for each file
1222 * but I don't know how to deal with the paged results
1223 * (maybe we can hang the result anywhere in the fsp struct)
1225 * but I don't know how to deal with the paged results
1226 * (maybe we can hang the result anywhere in the fsp struct)
1228 * we don't send all files at once
1229 * and at the next we should *not* start from the beginning,
1230 * so we have to cache the result
1232 * --metze
1235 /* this works for now... */
1236 return NT_STATUS_OK;
1239 case FSCTL_QUERY_ALLOCATED_RANGES:
1241 /* FIXME: This is just a dummy reply, telling that all of the
1242 * file is allocated. MKS cp needs that.
1243 * Adding the real allocated ranges via FIEMAP on Linux
1244 * and SEEK_DATA/SEEK_HOLE on Solaris is needed to make
1245 * this FSCTL correct for sparse files.
1247 NTSTATUS status;
1248 uint64_t offset, length;
1249 char *out_data_tmp = NULL;
1251 if (in_len != 16) {
1252 DEBUG(0,("FSCTL_QUERY_ALLOCATED_RANGES: data_count(%u) != 16 is invalid!\n",
1253 in_len));
1254 return NT_STATUS_INVALID_PARAMETER;
1257 if (max_out_len < 16) {
1258 DEBUG(0,("FSCTL_QUERY_ALLOCATED_RANGES: max_out_len (%u) < 16 is invalid!\n",
1259 max_out_len));
1260 return NT_STATUS_INVALID_PARAMETER;
1263 offset = BVAL(in_data,0);
1264 length = BVAL(in_data,8);
1266 if (offset + length < offset) {
1267 /* No 64-bit integer wrap. */
1268 return NT_STATUS_INVALID_PARAMETER;
1271 /* Shouldn't this be SMB_VFS_STAT ... ? */
1272 status = vfs_stat_fsp(fsp);
1273 if (!NT_STATUS_IS_OK(status)) {
1274 return status;
1277 *out_len = 16;
1278 out_data_tmp = talloc_array(ctx, char, *out_len);
1279 if (out_data_tmp == NULL) {
1280 DEBUG(10, ("unable to allocate memory for response\n"));
1281 return NT_STATUS_NO_MEMORY;
1284 if (offset > fsp->fsp_name->st.st_ex_size ||
1285 fsp->fsp_name->st.st_ex_size == 0 ||
1286 length == 0) {
1287 memset(out_data_tmp, 0, *out_len);
1288 } else {
1289 uint64_t end = offset + length;
1290 end = MIN(end, fsp->fsp_name->st.st_ex_size);
1291 SBVAL(out_data_tmp, 0, 0);
1292 SBVAL(out_data_tmp, 8, end);
1295 *out_data = out_data_tmp;
1297 return NT_STATUS_OK;
1300 case FSCTL_IS_VOLUME_DIRTY:
1302 DEBUG(10,("FSCTL_IS_VOLUME_DIRTY: called on %s "
1303 "(but remotely not supported)\n", fsp_fnum_dbg(fsp)));
1305 * http://msdn.microsoft.com/en-us/library/cc232128%28PROT.10%29.aspx
1306 * says we have to respond with NT_STATUS_INVALID_PARAMETER
1308 return NT_STATUS_INVALID_PARAMETER;
1311 default:
1313 * Only print once ... unfortunately there could be lots of
1314 * different FSCTLs that are called.
1316 if (!vfswrap_logged_ioctl_message) {
1317 vfswrap_logged_ioctl_message = true;
1318 DEBUG(2, ("%s (0x%x): Currently not implemented.\n",
1319 __func__, function));
1323 return NT_STATUS_NOT_SUPPORTED;
1326 /********************************************************************
1327 Given a stat buffer return the allocated size on disk, taking into
1328 account sparse files.
1329 ********************************************************************/
1330 static uint64_t vfswrap_get_alloc_size(vfs_handle_struct *handle,
1331 struct files_struct *fsp,
1332 const SMB_STRUCT_STAT *sbuf)
1334 uint64_t result;
1336 START_PROFILE(syscall_get_alloc_size);
1338 if(S_ISDIR(sbuf->st_ex_mode)) {
1339 result = 0;
1340 goto out;
1343 #if defined(HAVE_STAT_ST_BLOCKS) && defined(STAT_ST_BLOCKSIZE)
1344 /* The type of st_blocksize is blkcnt_t which *MUST* be
1345 signed (according to POSIX) and can be less than 64-bits.
1346 Ensure when we're converting to 64 bits wide we don't
1347 sign extend. */
1348 #if defined(SIZEOF_BLKCNT_T_8)
1349 result = (uint64_t)STAT_ST_BLOCKSIZE * (uint64_t)sbuf->st_ex_blocks;
1350 #elif defined(SIZEOF_BLKCNT_T_4)
1352 uint64_t bs = ((uint64_t)sbuf->st_ex_blocks) & 0xFFFFFFFFLL;
1353 result = (uint64_t)STAT_ST_BLOCKSIZE * bs;
1355 #else
1356 #error SIZEOF_BLKCNT_T_NOT_A_SUPPORTED_VALUE
1357 #endif
1358 #else
1359 result = get_file_size_stat(sbuf);
1360 #endif
1362 if (fsp && fsp->initial_allocation_size)
1363 result = MAX(result,fsp->initial_allocation_size);
1365 result = smb_roundup(handle->conn, result);
1367 out:
1368 END_PROFILE(syscall_get_alloc_size);
1369 return result;
1372 static int vfswrap_unlink(vfs_handle_struct *handle,
1373 const struct smb_filename *smb_fname)
1375 int result = -1;
1377 START_PROFILE(syscall_unlink);
1379 if (smb_fname->stream_name) {
1380 errno = ENOENT;
1381 goto out;
1383 result = unlink(smb_fname->base_name);
1385 out:
1386 END_PROFILE(syscall_unlink);
1387 return result;
1390 static int vfswrap_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
1392 int result;
1394 START_PROFILE(syscall_chmod);
1397 * We need to do this due to the fact that the default POSIX ACL
1398 * chmod modifies the ACL *mask* for the group owner, not the
1399 * group owner bits directly. JRA.
1404 int saved_errno = errno; /* We might get ENOSYS */
1405 if ((result = SMB_VFS_CHMOD_ACL(handle->conn, path, mode)) == 0) {
1406 END_PROFILE(syscall_chmod);
1407 return result;
1409 /* Error - return the old errno. */
1410 errno = saved_errno;
1413 result = chmod(path, mode);
1414 END_PROFILE(syscall_chmod);
1415 return result;
1418 static int vfswrap_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
1420 int result;
1422 START_PROFILE(syscall_fchmod);
1425 * We need to do this due to the fact that the default POSIX ACL
1426 * chmod modifies the ACL *mask* for the group owner, not the
1427 * group owner bits directly. JRA.
1431 int saved_errno = errno; /* We might get ENOSYS */
1432 if ((result = SMB_VFS_FCHMOD_ACL(fsp, mode)) == 0) {
1433 END_PROFILE(syscall_fchmod);
1434 return result;
1436 /* Error - return the old errno. */
1437 errno = saved_errno;
1440 #if defined(HAVE_FCHMOD)
1441 result = fchmod(fsp->fh->fd, mode);
1442 #else
1443 result = -1;
1444 errno = ENOSYS;
1445 #endif
1447 END_PROFILE(syscall_fchmod);
1448 return result;
1451 static int vfswrap_chown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid)
1453 int result;
1455 START_PROFILE(syscall_chown);
1456 result = chown(path, uid, gid);
1457 END_PROFILE(syscall_chown);
1458 return result;
1461 static int vfswrap_fchown(vfs_handle_struct *handle, files_struct *fsp, uid_t uid, gid_t gid)
1463 #ifdef HAVE_FCHOWN
1464 int result;
1466 START_PROFILE(syscall_fchown);
1467 result = fchown(fsp->fh->fd, uid, gid);
1468 END_PROFILE(syscall_fchown);
1469 return result;
1470 #else
1471 errno = ENOSYS;
1472 return -1;
1473 #endif
1476 static int vfswrap_lchown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid)
1478 int result;
1480 START_PROFILE(syscall_lchown);
1481 result = lchown(path, uid, gid);
1482 END_PROFILE(syscall_lchown);
1483 return result;
1486 static int vfswrap_chdir(vfs_handle_struct *handle, const char *path)
1488 int result;
1490 START_PROFILE(syscall_chdir);
1491 result = chdir(path);
1492 END_PROFILE(syscall_chdir);
1493 return result;
1496 static char *vfswrap_getwd(vfs_handle_struct *handle)
1498 char *result;
1500 START_PROFILE(syscall_getwd);
1501 result = sys_getwd();
1502 END_PROFILE(syscall_getwd);
1503 return result;
1506 /*********************************************************************
1507 nsec timestamp resolution call. Convert down to whatever the underlying
1508 system will support.
1509 **********************************************************************/
1511 static int vfswrap_ntimes(vfs_handle_struct *handle,
1512 const struct smb_filename *smb_fname,
1513 struct smb_file_time *ft)
1515 int result = -1;
1517 START_PROFILE(syscall_ntimes);
1519 if (smb_fname->stream_name) {
1520 errno = ENOENT;
1521 goto out;
1524 if (ft != NULL) {
1525 if (null_timespec(ft->atime)) {
1526 ft->atime= smb_fname->st.st_ex_atime;
1529 if (null_timespec(ft->mtime)) {
1530 ft->mtime = smb_fname->st.st_ex_mtime;
1533 if (!null_timespec(ft->create_time)) {
1534 set_create_timespec_ea(handle->conn,
1535 smb_fname,
1536 ft->create_time);
1539 if ((timespec_compare(&ft->atime,
1540 &smb_fname->st.st_ex_atime) == 0) &&
1541 (timespec_compare(&ft->mtime,
1542 &smb_fname->st.st_ex_mtime) == 0)) {
1543 return 0;
1547 #if defined(HAVE_UTIMENSAT)
1548 if (ft != NULL) {
1549 struct timespec ts[2];
1550 ts[0] = ft->atime;
1551 ts[1] = ft->mtime;
1552 result = utimensat(AT_FDCWD, smb_fname->base_name, ts, 0);
1553 } else {
1554 result = utimensat(AT_FDCWD, smb_fname->base_name, NULL, 0);
1556 if (!((result == -1) && (errno == ENOSYS))) {
1557 goto out;
1559 #endif
1560 #if defined(HAVE_UTIMES)
1561 if (ft != NULL) {
1562 struct timeval tv[2];
1563 tv[0] = convert_timespec_to_timeval(ft->atime);
1564 tv[1] = convert_timespec_to_timeval(ft->mtime);
1565 result = utimes(smb_fname->base_name, tv);
1566 } else {
1567 result = utimes(smb_fname->base_name, NULL);
1569 if (!((result == -1) && (errno == ENOSYS))) {
1570 goto out;
1572 #endif
1573 #if defined(HAVE_UTIME)
1574 if (ft != NULL) {
1575 struct utimbuf times;
1576 times.actime = convert_timespec_to_time_t(ft->atime);
1577 times.modtime = convert_timespec_to_time_t(ft->mtime);
1578 result = utime(smb_fname->base_name, &times);
1579 } else {
1580 result = utime(smb_fname->base_name, NULL);
1582 if (!((result == -1) && (errno == ENOSYS))) {
1583 goto out;
1585 #endif
1586 errno = ENOSYS;
1587 result = -1;
1589 out:
1590 END_PROFILE(syscall_ntimes);
1591 return result;
1594 /*********************************************************************
1595 A version of ftruncate that will write the space on disk if strict
1596 allocate is set.
1597 **********************************************************************/
1599 static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fsp, off_t len)
1601 off_t space_to_write;
1602 uint64_t space_avail;
1603 uint64_t bsize,dfree,dsize;
1604 int ret;
1605 NTSTATUS status;
1606 SMB_STRUCT_STAT *pst;
1608 status = vfs_stat_fsp(fsp);
1609 if (!NT_STATUS_IS_OK(status)) {
1610 return -1;
1612 pst = &fsp->fsp_name->st;
1614 #ifdef S_ISFIFO
1615 if (S_ISFIFO(pst->st_ex_mode))
1616 return 0;
1617 #endif
1619 if (pst->st_ex_size == len)
1620 return 0;
1622 /* Shrink - just ftruncate. */
1623 if (pst->st_ex_size > len)
1624 return ftruncate(fsp->fh->fd, len);
1626 space_to_write = len - pst->st_ex_size;
1628 /* for allocation try fallocate first. This can fail on some
1629 platforms e.g. when the filesystem doesn't support it and no
1630 emulation is being done by the libc (like on AIX with JFS1). In that
1631 case we do our own emulation. fallocate implementations can
1632 return ENOTSUP or EINVAL in cases like that. */
1633 ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_EXTEND_SIZE,
1634 pst->st_ex_size, space_to_write);
1635 if (ret == ENOSPC) {
1636 errno = ENOSPC;
1637 return -1;
1639 if (ret == 0) {
1640 return 0;
1642 DEBUG(10,("strict_allocate_ftruncate: SMB_VFS_FALLOCATE failed with "
1643 "error %d. Falling back to slow manual allocation\n", ret));
1645 /* available disk space is enough or not? */
1646 space_avail = get_dfree_info(fsp->conn,
1647 fsp->fsp_name->base_name, false,
1648 &bsize,&dfree,&dsize);
1649 /* space_avail is 1k blocks */
1650 if (space_avail == (uint64_t)-1 ||
1651 ((uint64_t)space_to_write/1024 > space_avail) ) {
1652 errno = ENOSPC;
1653 return -1;
1656 /* Write out the real space on disk. */
1657 ret = vfs_slow_fallocate(fsp, pst->st_ex_size, space_to_write);
1658 if (ret != 0) {
1659 errno = ret;
1660 ret = -1;
1663 return 0;
1666 static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, off_t len)
1668 int result = -1;
1669 SMB_STRUCT_STAT *pst;
1670 NTSTATUS status;
1671 char c = 0;
1673 START_PROFILE(syscall_ftruncate);
1675 if (lp_strict_allocate(SNUM(fsp->conn)) && !fsp->is_sparse) {
1676 result = strict_allocate_ftruncate(handle, fsp, len);
1677 END_PROFILE(syscall_ftruncate);
1678 return result;
1681 /* we used to just check HAVE_FTRUNCATE_EXTEND and only use
1682 ftruncate if the system supports it. Then I discovered that
1683 you can have some filesystems that support ftruncate
1684 expansion and some that don't! On Linux fat can't do
1685 ftruncate extend but ext2 can. */
1687 result = ftruncate(fsp->fh->fd, len);
1688 if (result == 0)
1689 goto done;
1691 /* According to W. R. Stevens advanced UNIX prog. Pure 4.3 BSD cannot
1692 extend a file with ftruncate. Provide alternate implementation
1693 for this */
1695 /* Do an fstat to see if the file is longer than the requested
1696 size in which case the ftruncate above should have
1697 succeeded or shorter, in which case seek to len - 1 and
1698 write 1 byte of zero */
1699 status = vfs_stat_fsp(fsp);
1700 if (!NT_STATUS_IS_OK(status)) {
1701 goto done;
1703 pst = &fsp->fsp_name->st;
1705 #ifdef S_ISFIFO
1706 if (S_ISFIFO(pst->st_ex_mode)) {
1707 result = 0;
1708 goto done;
1710 #endif
1712 if (pst->st_ex_size == len) {
1713 result = 0;
1714 goto done;
1717 if (pst->st_ex_size > len) {
1718 /* the ftruncate should have worked */
1719 goto done;
1722 if (SMB_VFS_PWRITE(fsp, &c, 1, len-1)!=1) {
1723 goto done;
1726 result = 0;
1728 done:
1730 END_PROFILE(syscall_ftruncate);
1731 return result;
1734 static int vfswrap_fallocate(vfs_handle_struct *handle,
1735 files_struct *fsp,
1736 enum vfs_fallocate_mode mode,
1737 off_t offset,
1738 off_t len)
1740 int result;
1742 START_PROFILE(syscall_fallocate);
1743 if (mode == VFS_FALLOCATE_EXTEND_SIZE) {
1744 result = sys_posix_fallocate(fsp->fh->fd, offset, len);
1745 } else if (mode == VFS_FALLOCATE_KEEP_SIZE) {
1746 result = sys_fallocate(fsp->fh->fd, mode, offset, len);
1747 } else {
1748 errno = EINVAL;
1749 result = -1;
1751 END_PROFILE(syscall_fallocate);
1752 return result;
1755 static bool vfswrap_lock(vfs_handle_struct *handle, files_struct *fsp, int op, off_t offset, off_t count, int type)
1757 bool result;
1759 START_PROFILE(syscall_fcntl_lock);
1760 result = fcntl_lock(fsp->fh->fd, op, offset, count, type);
1761 END_PROFILE(syscall_fcntl_lock);
1762 return result;
1765 static int vfswrap_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
1766 uint32 share_mode, uint32 access_mask)
1768 START_PROFILE(syscall_kernel_flock);
1769 kernel_flock(fsp->fh->fd, share_mode, access_mask);
1770 END_PROFILE(syscall_kernel_flock);
1771 return 0;
1774 static bool vfswrap_getlock(vfs_handle_struct *handle, files_struct *fsp, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1776 bool result;
1778 START_PROFILE(syscall_fcntl_getlock);
1779 result = fcntl_getlock(fsp->fh->fd, poffset, pcount, ptype, ppid);
1780 END_PROFILE(syscall_fcntl_getlock);
1781 return result;
1784 static int vfswrap_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1785 int leasetype)
1787 int result = -1;
1789 START_PROFILE(syscall_linux_setlease);
1791 #ifdef HAVE_KERNEL_OPLOCKS_LINUX
1792 result = linux_setlease(fsp->fh->fd, leasetype);
1793 #else
1794 errno = ENOSYS;
1795 #endif
1796 END_PROFILE(syscall_linux_setlease);
1797 return result;
1800 static int vfswrap_symlink(vfs_handle_struct *handle, const char *oldpath, const char *newpath)
1802 int result;
1804 START_PROFILE(syscall_symlink);
1805 result = symlink(oldpath, newpath);
1806 END_PROFILE(syscall_symlink);
1807 return result;
1810 static int vfswrap_readlink(vfs_handle_struct *handle, const char *path, char *buf, size_t bufsiz)
1812 int result;
1814 START_PROFILE(syscall_readlink);
1815 result = readlink(path, buf, bufsiz);
1816 END_PROFILE(syscall_readlink);
1817 return result;
1820 static int vfswrap_link(vfs_handle_struct *handle, const char *oldpath, const char *newpath)
1822 int result;
1824 START_PROFILE(syscall_link);
1825 result = link(oldpath, newpath);
1826 END_PROFILE(syscall_link);
1827 return result;
1830 static int vfswrap_mknod(vfs_handle_struct *handle, const char *pathname, mode_t mode, SMB_DEV_T dev)
1832 int result;
1834 START_PROFILE(syscall_mknod);
1835 result = sys_mknod(pathname, mode, dev);
1836 END_PROFILE(syscall_mknod);
1837 return result;
1840 static char *vfswrap_realpath(vfs_handle_struct *handle, const char *path)
1842 char *result;
1844 START_PROFILE(syscall_realpath);
1845 #ifdef REALPATH_TAKES_NULL
1846 result = realpath(path, NULL);
1847 #else
1848 result = SMB_MALLOC_ARRAY(char, PATH_MAX+1);
1849 if (result) {
1850 char *resolved_path = realpath(path, result);
1851 if (!resolved_path) {
1852 SAFE_FREE(result);
1853 } else {
1854 /* SMB_ASSERT(result == resolved_path) ? */
1855 result = resolved_path;
1858 #endif
1859 END_PROFILE(syscall_realpath);
1860 return result;
1863 static NTSTATUS vfswrap_notify_watch(vfs_handle_struct *vfs_handle,
1864 struct sys_notify_context *ctx,
1865 const char *path,
1866 uint32_t *filter,
1867 uint32_t *subdir_filter,
1868 void (*callback)(struct sys_notify_context *ctx,
1869 void *private_data,
1870 struct notify_event *ev),
1871 void *private_data, void *handle)
1874 * So far inotify is the only supported default notify mechanism. If
1875 * another platform like the the BSD's or a proprietary Unix comes
1876 * along and wants another default, we can play the same trick we
1877 * played with Posix ACLs.
1879 * Until that is the case, hard-code inotify here.
1881 #ifdef HAVE_INOTIFY
1882 if (lp_kernel_change_notify(vfs_handle->conn->params)) {
1883 return inotify_watch(ctx, path, filter, subdir_filter,
1884 callback, private_data, handle);
1886 #endif
1888 * Do nothing, leave everything to notify_internal.c
1890 return NT_STATUS_OK;
1893 static int vfswrap_chflags(vfs_handle_struct *handle, const char *path,
1894 unsigned int flags)
1896 #ifdef HAVE_CHFLAGS
1897 return chflags(path, flags);
1898 #else
1899 errno = ENOSYS;
1900 return -1;
1901 #endif
1904 static struct file_id vfswrap_file_id_create(struct vfs_handle_struct *handle,
1905 const SMB_STRUCT_STAT *sbuf)
1907 struct file_id key;
1909 /* the ZERO_STRUCT ensures padding doesn't break using the key as a
1910 * blob */
1911 ZERO_STRUCT(key);
1913 key.devid = sbuf->st_ex_dev;
1914 key.inode = sbuf->st_ex_ino;
1915 /* key.extid is unused by default. */
1917 return key;
1920 static NTSTATUS vfswrap_streaminfo(vfs_handle_struct *handle,
1921 struct files_struct *fsp,
1922 const char *fname,
1923 TALLOC_CTX *mem_ctx,
1924 unsigned int *pnum_streams,
1925 struct stream_struct **pstreams)
1927 SMB_STRUCT_STAT sbuf;
1928 struct stream_struct *tmp_streams = NULL;
1929 int ret;
1931 if ((fsp != NULL) && (fsp->is_directory)) {
1933 * No default streams on directories
1935 goto done;
1938 if ((fsp != NULL) && (fsp->fh->fd != -1)) {
1939 ret = SMB_VFS_FSTAT(fsp, &sbuf);
1941 else {
1942 struct smb_filename smb_fname;
1944 ZERO_STRUCT(smb_fname);
1945 smb_fname.base_name = discard_const_p(char, fname);
1947 if (lp_posix_pathnames()) {
1948 ret = SMB_VFS_LSTAT(handle->conn, &smb_fname);
1949 } else {
1950 ret = SMB_VFS_STAT(handle->conn, &smb_fname);
1952 sbuf = smb_fname.st;
1955 if (ret == -1) {
1956 return map_nt_error_from_unix(errno);
1959 if (S_ISDIR(sbuf.st_ex_mode)) {
1960 goto done;
1963 tmp_streams = talloc_realloc(mem_ctx, *pstreams, struct stream_struct,
1964 (*pnum_streams) + 1);
1965 if (tmp_streams == NULL) {
1966 return NT_STATUS_NO_MEMORY;
1968 tmp_streams[*pnum_streams].name = talloc_strdup(tmp_streams, "::$DATA");
1969 if (tmp_streams[*pnum_streams].name == NULL) {
1970 return NT_STATUS_NO_MEMORY;
1972 tmp_streams[*pnum_streams].size = sbuf.st_ex_size;
1973 tmp_streams[*pnum_streams].alloc_size = SMB_VFS_GET_ALLOC_SIZE(handle->conn, fsp, &sbuf);
1975 *pnum_streams += 1;
1976 *pstreams = tmp_streams;
1977 done:
1978 return NT_STATUS_OK;
1981 static int vfswrap_get_real_filename(struct vfs_handle_struct *handle,
1982 const char *path,
1983 const char *name,
1984 TALLOC_CTX *mem_ctx,
1985 char **found_name)
1988 * Don't fall back to get_real_filename so callers can differentiate
1989 * between a full directory scan and an actual case-insensitive stat.
1991 errno = EOPNOTSUPP;
1992 return -1;
1995 static const char *vfswrap_connectpath(struct vfs_handle_struct *handle,
1996 const char *fname)
1998 return handle->conn->connectpath;
2001 static NTSTATUS vfswrap_brl_lock_windows(struct vfs_handle_struct *handle,
2002 struct byte_range_lock *br_lck,
2003 struct lock_struct *plock,
2004 bool blocking_lock,
2005 struct blocking_lock_record *blr)
2007 SMB_ASSERT(plock->lock_flav == WINDOWS_LOCK);
2009 /* Note: blr is not used in the default implementation. */
2010 return brl_lock_windows_default(br_lck, plock, blocking_lock);
2013 static bool vfswrap_brl_unlock_windows(struct vfs_handle_struct *handle,
2014 struct messaging_context *msg_ctx,
2015 struct byte_range_lock *br_lck,
2016 const struct lock_struct *plock)
2018 SMB_ASSERT(plock->lock_flav == WINDOWS_LOCK);
2020 return brl_unlock_windows_default(msg_ctx, br_lck, plock);
2023 static bool vfswrap_brl_cancel_windows(struct vfs_handle_struct *handle,
2024 struct byte_range_lock *br_lck,
2025 struct lock_struct *plock,
2026 struct blocking_lock_record *blr)
2028 SMB_ASSERT(plock->lock_flav == WINDOWS_LOCK);
2030 /* Note: blr is not used in the default implementation. */
2031 return brl_lock_cancel_default(br_lck, plock);
2034 static bool vfswrap_strict_lock(struct vfs_handle_struct *handle,
2035 files_struct *fsp,
2036 struct lock_struct *plock)
2038 SMB_ASSERT(plock->lock_type == READ_LOCK ||
2039 plock->lock_type == WRITE_LOCK);
2041 return strict_lock_default(fsp, plock);
2044 static void vfswrap_strict_unlock(struct vfs_handle_struct *handle,
2045 files_struct *fsp,
2046 struct lock_struct *plock)
2048 SMB_ASSERT(plock->lock_type == READ_LOCK ||
2049 plock->lock_type == WRITE_LOCK);
2051 strict_unlock_default(fsp, plock);
2054 /* NT ACL operations. */
2056 static NTSTATUS vfswrap_fget_nt_acl(vfs_handle_struct *handle,
2057 files_struct *fsp,
2058 uint32 security_info,
2059 TALLOC_CTX *mem_ctx,
2060 struct security_descriptor **ppdesc)
2062 NTSTATUS result;
2064 START_PROFILE(fget_nt_acl);
2065 result = posix_fget_nt_acl(fsp, security_info,
2066 mem_ctx, ppdesc);
2067 END_PROFILE(fget_nt_acl);
2068 return result;
2071 static NTSTATUS vfswrap_get_nt_acl(vfs_handle_struct *handle,
2072 const char *name,
2073 uint32 security_info,
2074 TALLOC_CTX *mem_ctx,
2075 struct security_descriptor **ppdesc)
2077 NTSTATUS result;
2079 START_PROFILE(get_nt_acl);
2080 result = posix_get_nt_acl(handle->conn, name, security_info,
2081 mem_ctx, ppdesc);
2082 END_PROFILE(get_nt_acl);
2083 return result;
2086 static NTSTATUS vfswrap_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
2088 NTSTATUS result;
2090 START_PROFILE(fset_nt_acl);
2091 result = set_nt_acl(fsp, security_info_sent, psd);
2092 END_PROFILE(fset_nt_acl);
2093 return result;
2096 static NTSTATUS vfswrap_audit_file(struct vfs_handle_struct *handle,
2097 struct smb_filename *file,
2098 struct security_acl *sacl,
2099 uint32_t access_requested,
2100 uint32_t access_denied)
2102 return NT_STATUS_OK; /* Nothing to do here ... */
2105 static int vfswrap_chmod_acl(vfs_handle_struct *handle, const char *name, mode_t mode)
2107 #ifdef HAVE_NO_ACL
2108 errno = ENOSYS;
2109 return -1;
2110 #else
2111 int result;
2113 START_PROFILE(chmod_acl);
2114 result = chmod_acl(handle->conn, name, mode);
2115 END_PROFILE(chmod_acl);
2116 return result;
2117 #endif
2120 static int vfswrap_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
2122 #ifdef HAVE_NO_ACL
2123 errno = ENOSYS;
2124 return -1;
2125 #else
2126 int result;
2128 START_PROFILE(fchmod_acl);
2129 result = fchmod_acl(fsp, mode);
2130 END_PROFILE(fchmod_acl);
2131 return result;
2132 #endif
2135 static SMB_ACL_T vfswrap_sys_acl_get_file(vfs_handle_struct *handle,
2136 const char *path_p,
2137 SMB_ACL_TYPE_T type,
2138 TALLOC_CTX *mem_ctx)
2140 return sys_acl_get_file(handle, path_p, type, mem_ctx);
2143 static SMB_ACL_T vfswrap_sys_acl_get_fd(vfs_handle_struct *handle,
2144 files_struct *fsp,
2145 TALLOC_CTX *mem_ctx)
2147 return sys_acl_get_fd(handle, fsp, mem_ctx);
2150 static int vfswrap_sys_acl_set_file(vfs_handle_struct *handle, const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2152 return sys_acl_set_file(handle, name, acltype, theacl);
2155 static int vfswrap_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp, SMB_ACL_T theacl)
2157 return sys_acl_set_fd(handle, fsp, theacl);
2160 static int vfswrap_sys_acl_delete_def_file(vfs_handle_struct *handle, const char *path)
2162 return sys_acl_delete_def_file(handle, path);
2165 /****************************************************************
2166 Extended attribute operations.
2167 *****************************************************************/
2169 static ssize_t vfswrap_getxattr(struct vfs_handle_struct *handle,const char *path, const char *name, void *value, size_t size)
2171 return getxattr(path, name, value, size);
2174 static ssize_t vfswrap_fgetxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name, void *value, size_t size)
2176 return fgetxattr(fsp->fh->fd, name, value, size);
2179 static ssize_t vfswrap_listxattr(struct vfs_handle_struct *handle, const char *path, char *list, size_t size)
2181 return listxattr(path, list, size);
2184 static ssize_t vfswrap_flistxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, char *list, size_t size)
2186 return flistxattr(fsp->fh->fd, list, size);
2189 static int vfswrap_removexattr(struct vfs_handle_struct *handle, const char *path, const char *name)
2191 return removexattr(path, name);
2194 static int vfswrap_fremovexattr(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name)
2196 return fremovexattr(fsp->fh->fd, name);
2199 static int vfswrap_setxattr(struct vfs_handle_struct *handle, const char *path, const char *name, const void *value, size_t size, int flags)
2201 return setxattr(path, name, value, size, flags);
2204 static int vfswrap_fsetxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name, const void *value, size_t size, int flags)
2206 return fsetxattr(fsp->fh->fd, name, value, size, flags);
2209 static bool vfswrap_aio_force(struct vfs_handle_struct *handle, struct files_struct *fsp)
2211 return false;
2214 static bool vfswrap_is_offline(struct vfs_handle_struct *handle,
2215 const struct smb_filename *fname,
2216 SMB_STRUCT_STAT *sbuf)
2218 NTSTATUS status;
2219 char *path;
2220 bool offline = false;
2222 if (ISDOT(fname->base_name) || ISDOTDOT(fname->base_name)) {
2223 return false;
2226 if (!lp_dmapi_support(SNUM(handle->conn)) || !dmapi_have_session()) {
2227 #if defined(ENOTSUP)
2228 errno = ENOTSUP;
2229 #endif
2230 return false;
2233 status = get_full_smb_filename(talloc_tos(), fname, &path);
2234 if (!NT_STATUS_IS_OK(status)) {
2235 errno = map_errno_from_nt_status(status);
2236 return false;
2239 offline = (dmapi_file_flags(path) & FILE_ATTRIBUTE_OFFLINE) != 0;
2241 TALLOC_FREE(path);
2243 return offline;
2246 static int vfswrap_set_offline(struct vfs_handle_struct *handle,
2247 const struct smb_filename *fname)
2249 /* We don't know how to set offline bit by default, needs to be overriden in the vfs modules */
2250 #if defined(ENOTSUP)
2251 errno = ENOTSUP;
2252 #endif
2253 return -1;
2256 static NTSTATUS vfswrap_durable_cookie(struct vfs_handle_struct *handle,
2257 struct files_struct *fsp,
2258 TALLOC_CTX *mem_ctx,
2259 DATA_BLOB *cookie)
2261 return vfs_default_durable_cookie(fsp, mem_ctx, cookie);
2264 static NTSTATUS vfswrap_durable_disconnect(struct vfs_handle_struct *handle,
2265 struct files_struct *fsp,
2266 const DATA_BLOB old_cookie,
2267 TALLOC_CTX *mem_ctx,
2268 DATA_BLOB *new_cookie)
2270 return vfs_default_durable_disconnect(fsp, old_cookie, mem_ctx,
2271 new_cookie);
2274 static NTSTATUS vfswrap_durable_reconnect(struct vfs_handle_struct *handle,
2275 struct smb_request *smb1req,
2276 struct smbXsrv_open *op,
2277 const DATA_BLOB old_cookie,
2278 TALLOC_CTX *mem_ctx,
2279 struct files_struct **fsp,
2280 DATA_BLOB *new_cookie)
2282 return vfs_default_durable_reconnect(handle->conn, smb1req, op,
2283 old_cookie, mem_ctx,
2284 fsp, new_cookie);
2287 static struct vfs_fn_pointers vfs_default_fns = {
2288 /* Disk operations */
2290 .connect_fn = vfswrap_connect,
2291 .disconnect_fn = vfswrap_disconnect,
2292 .disk_free_fn = vfswrap_disk_free,
2293 .get_quota_fn = vfswrap_get_quota,
2294 .set_quota_fn = vfswrap_set_quota,
2295 .get_shadow_copy_data_fn = vfswrap_get_shadow_copy_data,
2296 .statvfs_fn = vfswrap_statvfs,
2297 .fs_capabilities_fn = vfswrap_fs_capabilities,
2298 .get_dfs_referrals_fn = vfswrap_get_dfs_referrals,
2300 /* Directory operations */
2302 .opendir_fn = vfswrap_opendir,
2303 .fdopendir_fn = vfswrap_fdopendir,
2304 .readdir_fn = vfswrap_readdir,
2305 .seekdir_fn = vfswrap_seekdir,
2306 .telldir_fn = vfswrap_telldir,
2307 .rewind_dir_fn = vfswrap_rewinddir,
2308 .mkdir_fn = vfswrap_mkdir,
2309 .rmdir_fn = vfswrap_rmdir,
2310 .closedir_fn = vfswrap_closedir,
2311 .init_search_op_fn = vfswrap_init_search_op,
2313 /* File operations */
2315 .open_fn = vfswrap_open,
2316 .create_file_fn = vfswrap_create_file,
2317 .close_fn = vfswrap_close,
2318 .read_fn = vfswrap_read,
2319 .pread_fn = vfswrap_pread,
2320 .pread_send_fn = vfswrap_pread_send,
2321 .pread_recv_fn = vfswrap_asys_ssize_t_recv,
2322 .write_fn = vfswrap_write,
2323 .pwrite_fn = vfswrap_pwrite,
2324 .pwrite_send_fn = vfswrap_pwrite_send,
2325 .pwrite_recv_fn = vfswrap_asys_ssize_t_recv,
2326 .lseek_fn = vfswrap_lseek,
2327 .sendfile_fn = vfswrap_sendfile,
2328 .recvfile_fn = vfswrap_recvfile,
2329 .rename_fn = vfswrap_rename,
2330 .fsync_fn = vfswrap_fsync,
2331 .fsync_send_fn = vfswrap_fsync_send,
2332 .fsync_recv_fn = vfswrap_asys_int_recv,
2333 .stat_fn = vfswrap_stat,
2334 .fstat_fn = vfswrap_fstat,
2335 .lstat_fn = vfswrap_lstat,
2336 .get_alloc_size_fn = vfswrap_get_alloc_size,
2337 .unlink_fn = vfswrap_unlink,
2338 .chmod_fn = vfswrap_chmod,
2339 .fchmod_fn = vfswrap_fchmod,
2340 .chown_fn = vfswrap_chown,
2341 .fchown_fn = vfswrap_fchown,
2342 .lchown_fn = vfswrap_lchown,
2343 .chdir_fn = vfswrap_chdir,
2344 .getwd_fn = vfswrap_getwd,
2345 .ntimes_fn = vfswrap_ntimes,
2346 .ftruncate_fn = vfswrap_ftruncate,
2347 .fallocate_fn = vfswrap_fallocate,
2348 .lock_fn = vfswrap_lock,
2349 .kernel_flock_fn = vfswrap_kernel_flock,
2350 .linux_setlease_fn = vfswrap_linux_setlease,
2351 .getlock_fn = vfswrap_getlock,
2352 .symlink_fn = vfswrap_symlink,
2353 .readlink_fn = vfswrap_readlink,
2354 .link_fn = vfswrap_link,
2355 .mknod_fn = vfswrap_mknod,
2356 .realpath_fn = vfswrap_realpath,
2357 .notify_watch_fn = vfswrap_notify_watch,
2358 .chflags_fn = vfswrap_chflags,
2359 .file_id_create_fn = vfswrap_file_id_create,
2360 .streaminfo_fn = vfswrap_streaminfo,
2361 .get_real_filename_fn = vfswrap_get_real_filename,
2362 .connectpath_fn = vfswrap_connectpath,
2363 .brl_lock_windows_fn = vfswrap_brl_lock_windows,
2364 .brl_unlock_windows_fn = vfswrap_brl_unlock_windows,
2365 .brl_cancel_windows_fn = vfswrap_brl_cancel_windows,
2366 .strict_lock_fn = vfswrap_strict_lock,
2367 .strict_unlock_fn = vfswrap_strict_unlock,
2368 .translate_name_fn = vfswrap_translate_name,
2369 .fsctl_fn = vfswrap_fsctl,
2371 /* NT ACL operations. */
2373 .fget_nt_acl_fn = vfswrap_fget_nt_acl,
2374 .get_nt_acl_fn = vfswrap_get_nt_acl,
2375 .fset_nt_acl_fn = vfswrap_fset_nt_acl,
2376 .audit_file_fn = vfswrap_audit_file,
2378 /* POSIX ACL operations. */
2380 .chmod_acl_fn = vfswrap_chmod_acl,
2381 .fchmod_acl_fn = vfswrap_fchmod_acl,
2383 .sys_acl_get_file_fn = vfswrap_sys_acl_get_file,
2384 .sys_acl_get_fd_fn = vfswrap_sys_acl_get_fd,
2385 .sys_acl_blob_get_file_fn = posix_sys_acl_blob_get_file,
2386 .sys_acl_blob_get_fd_fn = posix_sys_acl_blob_get_fd,
2387 .sys_acl_set_file_fn = vfswrap_sys_acl_set_file,
2388 .sys_acl_set_fd_fn = vfswrap_sys_acl_set_fd,
2389 .sys_acl_delete_def_file_fn = vfswrap_sys_acl_delete_def_file,
2391 /* EA operations. */
2392 .getxattr_fn = vfswrap_getxattr,
2393 .fgetxattr_fn = vfswrap_fgetxattr,
2394 .listxattr_fn = vfswrap_listxattr,
2395 .flistxattr_fn = vfswrap_flistxattr,
2396 .removexattr_fn = vfswrap_removexattr,
2397 .fremovexattr_fn = vfswrap_fremovexattr,
2398 .setxattr_fn = vfswrap_setxattr,
2399 .fsetxattr_fn = vfswrap_fsetxattr,
2401 /* aio operations */
2402 .aio_force_fn = vfswrap_aio_force,
2404 /* offline operations */
2405 .is_offline_fn = vfswrap_is_offline,
2406 .set_offline_fn = vfswrap_set_offline,
2408 /* durable handle operations */
2409 .durable_cookie_fn = vfswrap_durable_cookie,
2410 .durable_disconnect_fn = vfswrap_durable_disconnect,
2411 .durable_reconnect_fn = vfswrap_durable_reconnect,
2414 NTSTATUS vfs_default_init(void);
2415 NTSTATUS vfs_default_init(void)
2417 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2418 DEFAULT_VFS_MODULE_NAME, &vfs_default_fns);