more fixups from provision changes
[Samba.git] / source3 / modules / vfs_default.c
bloba793b337a84270e720cd87e6227702d160aa5893
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"
23 #undef DBGC_CLASS
24 #define DBGC_CLASS DBGC_VFS
26 /* Check for NULL pointer parameters in vfswrap_* functions */
28 /* We don't want to have NULL function pointers lying around. Someone
29 is sure to try and execute them. These stubs are used to prevent
30 this possibility. */
32 static int vfswrap_connect(vfs_handle_struct *handle, const char *service, const char *user)
34 return 0; /* Return >= 0 for success */
37 static void vfswrap_disconnect(vfs_handle_struct *handle)
41 /* Disk operations */
43 static uint64_t vfswrap_disk_free(vfs_handle_struct *handle, const char *path, bool small_query, uint64_t *bsize,
44 uint64_t *dfree, uint64_t *dsize)
46 uint64_t result;
48 result = sys_disk_free(handle->conn, path, small_query, bsize, dfree, dsize);
49 return result;
52 static int vfswrap_get_quota(struct vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
54 #ifdef HAVE_SYS_QUOTAS
55 int result;
57 START_PROFILE(syscall_get_quota);
58 result = sys_get_quota(handle->conn->connectpath, qtype, id, qt);
59 END_PROFILE(syscall_get_quota);
60 return result;
61 #else
62 errno = ENOSYS;
63 return -1;
64 #endif
67 static int vfswrap_set_quota(struct vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
69 #ifdef HAVE_SYS_QUOTAS
70 int result;
72 START_PROFILE(syscall_set_quota);
73 result = sys_set_quota(handle->conn->connectpath, qtype, id, qt);
74 END_PROFILE(syscall_set_quota);
75 return result;
76 #else
77 errno = ENOSYS;
78 return -1;
79 #endif
82 static int vfswrap_get_shadow_copy_data(struct vfs_handle_struct *handle, struct files_struct *fsp, SHADOW_COPY_DATA *shadow_copy_data, bool labels)
84 errno = ENOSYS;
85 return -1; /* Not implemented. */
88 static int vfswrap_statvfs(struct vfs_handle_struct *handle, const char *path, vfs_statvfs_struct *statbuf)
90 return sys_statvfs(path, statbuf);
93 static uint32_t vfswrap_fs_capabilities(struct vfs_handle_struct *handle)
95 #if defined(DARWINOS)
96 struct vfs_statvfs_struct statbuf;
97 ZERO_STRUCT(statbuf);
98 sys_statvfs(handle->conn->connectpath, &statbuf);
99 return statbuf.FsCapabilities;
100 #endif
101 return FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
104 /* Directory operations */
106 static SMB_STRUCT_DIR *vfswrap_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr)
108 SMB_STRUCT_DIR *result;
110 START_PROFILE(syscall_opendir);
111 result = sys_opendir(fname);
112 END_PROFILE(syscall_opendir);
113 return result;
116 static SMB_STRUCT_DIRENT *vfswrap_readdir(vfs_handle_struct *handle,
117 SMB_STRUCT_DIR *dirp,
118 SMB_STRUCT_STAT *sbuf)
120 SMB_STRUCT_DIRENT *result;
122 START_PROFILE(syscall_readdir);
123 result = sys_readdir(dirp);
124 /* Default Posix readdir() does not give us stat info.
125 * Set to invalid to indicate we didn't return this info. */
126 if (sbuf)
127 SET_STAT_INVALID(*sbuf);
128 END_PROFILE(syscall_readdir);
129 return result;
132 static void vfswrap_seekdir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp, long offset)
134 START_PROFILE(syscall_seekdir);
135 sys_seekdir(dirp, offset);
136 END_PROFILE(syscall_seekdir);
139 static long vfswrap_telldir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp)
141 long result;
142 START_PROFILE(syscall_telldir);
143 result = sys_telldir(dirp);
144 END_PROFILE(syscall_telldir);
145 return result;
148 static void vfswrap_rewinddir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp)
150 START_PROFILE(syscall_rewinddir);
151 sys_rewinddir(dirp);
152 END_PROFILE(syscall_rewinddir);
155 static int vfswrap_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode)
157 int result;
158 bool has_dacl = False;
159 char *parent = NULL;
161 START_PROFILE(syscall_mkdir);
163 if (lp_inherit_acls(SNUM(handle->conn))
164 && parent_dirname(talloc_tos(), path, &parent, NULL)
165 && (has_dacl = directory_has_default_acl(handle->conn, parent)))
166 mode = 0777;
168 TALLOC_FREE(parent);
170 result = mkdir(path, mode);
172 if (result == 0 && !has_dacl) {
174 * We need to do this as the default behavior of POSIX ACLs
175 * is to set the mask to be the requested group permission
176 * bits, not the group permission bits to be the requested
177 * group permission bits. This is not what we want, as it will
178 * mess up any inherited ACL bits that were set. JRA.
180 int saved_errno = errno; /* We may get ENOSYS */
181 if ((SMB_VFS_CHMOD_ACL(handle->conn, path, mode) == -1) && (errno == ENOSYS))
182 errno = saved_errno;
185 END_PROFILE(syscall_mkdir);
186 return result;
189 static int vfswrap_rmdir(vfs_handle_struct *handle, const char *path)
191 int result;
193 START_PROFILE(syscall_rmdir);
194 result = rmdir(path);
195 END_PROFILE(syscall_rmdir);
196 return result;
199 static int vfswrap_closedir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp)
201 int result;
203 START_PROFILE(syscall_closedir);
204 result = sys_closedir(dirp);
205 END_PROFILE(syscall_closedir);
206 return result;
209 static void vfswrap_init_search_op(vfs_handle_struct *handle,
210 SMB_STRUCT_DIR *dirp)
212 /* Default behavior is a NOOP */
215 /* File operations */
217 static int vfswrap_open(vfs_handle_struct *handle,
218 struct smb_filename *smb_fname,
219 files_struct *fsp, int flags, mode_t mode)
221 int result = -1;
223 START_PROFILE(syscall_open);
225 if (smb_fname->stream_name) {
226 errno = ENOENT;
227 goto out;
230 result = sys_open(smb_fname->base_name, flags, mode);
231 out:
232 END_PROFILE(syscall_open);
233 return result;
236 static NTSTATUS vfswrap_create_file(vfs_handle_struct *handle,
237 struct smb_request *req,
238 uint16_t root_dir_fid,
239 struct smb_filename *smb_fname,
240 uint32_t access_mask,
241 uint32_t share_access,
242 uint32_t create_disposition,
243 uint32_t create_options,
244 uint32_t file_attributes,
245 uint32_t oplock_request,
246 uint64_t allocation_size,
247 struct security_descriptor *sd,
248 struct ea_list *ea_list,
249 files_struct **result,
250 int *pinfo)
252 return create_file_default(handle->conn, req, root_dir_fid, smb_fname,
253 access_mask, share_access,
254 create_disposition, create_options,
255 file_attributes, oplock_request,
256 allocation_size, sd, ea_list, result,
257 pinfo);
260 static int vfswrap_close(vfs_handle_struct *handle, files_struct *fsp)
262 int result;
264 START_PROFILE(syscall_close);
265 result = fd_close_posix(fsp);
266 END_PROFILE(syscall_close);
267 return result;
270 static ssize_t vfswrap_read(vfs_handle_struct *handle, files_struct *fsp, void *data, size_t n)
272 ssize_t result;
274 START_PROFILE_BYTES(syscall_read, n);
275 result = sys_read(fsp->fh->fd, data, n);
276 END_PROFILE(syscall_read);
277 return result;
280 static ssize_t vfswrap_pread(vfs_handle_struct *handle, files_struct *fsp, void *data,
281 size_t n, SMB_OFF_T offset)
283 ssize_t result;
285 #if defined(HAVE_PREAD) || defined(HAVE_PREAD64)
286 START_PROFILE_BYTES(syscall_pread, n);
287 result = sys_pread(fsp->fh->fd, data, n, offset);
288 END_PROFILE(syscall_pread);
290 if (result == -1 && errno == ESPIPE) {
291 /* Maintain the fiction that pipes can be seeked (sought?) on. */
292 result = SMB_VFS_READ(fsp, data, n);
293 fsp->fh->pos = 0;
296 #else /* HAVE_PREAD */
297 SMB_OFF_T curr;
298 int lerrno;
300 curr = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR);
301 if (curr == -1 && errno == ESPIPE) {
302 /* Maintain the fiction that pipes can be seeked (sought?) on. */
303 result = SMB_VFS_READ(fsp, data, n);
304 fsp->fh->pos = 0;
305 return result;
308 if (SMB_VFS_LSEEK(fsp, offset, SEEK_SET) == -1) {
309 return -1;
312 errno = 0;
313 result = SMB_VFS_READ(fsp, data, n);
314 lerrno = errno;
316 SMB_VFS_LSEEK(fsp, curr, SEEK_SET);
317 errno = lerrno;
319 #endif /* HAVE_PREAD */
321 return result;
324 static ssize_t vfswrap_write(vfs_handle_struct *handle, files_struct *fsp, const void *data, size_t n)
326 ssize_t result;
328 START_PROFILE_BYTES(syscall_write, n);
329 result = sys_write(fsp->fh->fd, data, n);
330 END_PROFILE(syscall_write);
331 return result;
334 static ssize_t vfswrap_pwrite(vfs_handle_struct *handle, files_struct *fsp, const void *data,
335 size_t n, SMB_OFF_T offset)
337 ssize_t result;
339 #if defined(HAVE_PWRITE) || defined(HAVE_PRWITE64)
340 START_PROFILE_BYTES(syscall_pwrite, n);
341 result = sys_pwrite(fsp->fh->fd, data, n, offset);
342 END_PROFILE(syscall_pwrite);
344 if (result == -1 && errno == ESPIPE) {
345 /* Maintain the fiction that pipes can be sought on. */
346 result = SMB_VFS_WRITE(fsp, data, n);
349 #else /* HAVE_PWRITE */
350 SMB_OFF_T curr;
351 int lerrno;
353 curr = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR);
354 if (curr == -1) {
355 return -1;
358 if (SMB_VFS_LSEEK(fsp, offset, SEEK_SET) == -1) {
359 return -1;
362 result = SMB_VFS_WRITE(fsp, data, n);
363 lerrno = errno;
365 SMB_VFS_LSEEK(fsp, curr, SEEK_SET);
366 errno = lerrno;
368 #endif /* HAVE_PWRITE */
370 return result;
373 static SMB_OFF_T vfswrap_lseek(vfs_handle_struct *handle, files_struct *fsp, SMB_OFF_T offset, int whence)
375 SMB_OFF_T result = 0;
377 START_PROFILE(syscall_lseek);
379 /* Cope with 'stat' file opens. */
380 if (fsp->fh->fd != -1)
381 result = sys_lseek(fsp->fh->fd, offset, whence);
384 * We want to maintain the fiction that we can seek
385 * on a fifo for file system purposes. This allows
386 * people to set up UNIX fifo's that feed data to Windows
387 * applications. JRA.
390 if((result == -1) && (errno == ESPIPE)) {
391 result = 0;
392 errno = 0;
395 END_PROFILE(syscall_lseek);
396 return result;
399 static ssize_t vfswrap_sendfile(vfs_handle_struct *handle, int tofd, files_struct *fromfsp, const DATA_BLOB *hdr,
400 SMB_OFF_T offset, size_t n)
402 ssize_t result;
404 START_PROFILE_BYTES(syscall_sendfile, n);
405 result = sys_sendfile(tofd, fromfsp->fh->fd, hdr, offset, n);
406 END_PROFILE(syscall_sendfile);
407 return result;
410 static ssize_t vfswrap_recvfile(vfs_handle_struct *handle,
411 int fromfd,
412 files_struct *tofsp,
413 SMB_OFF_T offset,
414 size_t n)
416 ssize_t result;
418 START_PROFILE_BYTES(syscall_recvfile, n);
419 result = sys_recvfile(fromfd, tofsp->fh->fd, offset, n);
420 END_PROFILE(syscall_recvfile);
421 return result;
424 /*********************************************************
425 For rename across filesystems Patch from Warren Birnbaum
426 <warrenb@hpcvscdp.cv.hp.com>
427 **********************************************************/
429 static int copy_reg(const char *source, const char *dest)
431 SMB_STRUCT_STAT source_stats;
432 int saved_errno;
433 int ifd = -1;
434 int ofd = -1;
436 if (sys_lstat (source, &source_stats) == -1)
437 return -1;
439 if (!S_ISREG (source_stats.st_ex_mode))
440 return -1;
442 if((ifd = sys_open (source, O_RDONLY, 0)) < 0)
443 return -1;
445 if (unlink (dest) && errno != ENOENT)
446 return -1;
448 #ifdef O_NOFOLLOW
449 if((ofd = sys_open (dest, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, 0600)) < 0 )
450 #else
451 if((ofd = sys_open (dest, O_WRONLY | O_CREAT | O_TRUNC , 0600)) < 0 )
452 #endif
453 goto err;
455 if (transfer_file(ifd, ofd, (size_t)-1) == -1)
456 goto err;
459 * Try to preserve ownership. For non-root it might fail, but that's ok.
460 * But root probably wants to know, e.g. if NFS disallows it.
463 #ifdef HAVE_FCHOWN
464 if ((fchown(ofd, source_stats.st_ex_uid, source_stats.st_ex_gid) == -1) && (errno != EPERM))
465 #else
466 if ((chown(dest, source_stats.st_ex_uid, source_stats.st_ex_gid) == -1) && (errno != EPERM))
467 #endif
468 goto err;
471 * fchown turns off set[ug]id bits for non-root,
472 * so do the chmod last.
475 #if defined(HAVE_FCHMOD)
476 if (fchmod (ofd, source_stats.st_ex_mode & 07777))
477 #else
478 if (chmod (dest, source_stats.st_ex_mode & 07777))
479 #endif
480 goto err;
482 if (close (ifd) == -1)
483 goto err;
485 if (close (ofd) == -1)
486 return -1;
488 /* Try to copy the old file's modtime and access time. */
490 struct utimbuf tv;
492 tv.actime = convert_timespec_to_time_t(source_stats.st_ex_atime);
493 tv.modtime = convert_timespec_to_time_t(source_stats.st_ex_mtime);
494 utime(dest, &tv);
497 if (unlink (source) == -1)
498 return -1;
500 return 0;
502 err:
504 saved_errno = errno;
505 if (ifd != -1)
506 close(ifd);
507 if (ofd != -1)
508 close(ofd);
509 errno = saved_errno;
510 return -1;
513 static int vfswrap_rename(vfs_handle_struct *handle,
514 const struct smb_filename *smb_fname_src,
515 const struct smb_filename *smb_fname_dst)
517 int result = -1;
519 START_PROFILE(syscall_rename);
521 if (smb_fname_src->stream_name || smb_fname_dst->stream_name) {
522 errno = ENOENT;
523 goto out;
526 result = rename(smb_fname_src->base_name, smb_fname_dst->base_name);
527 if ((result == -1) && (errno == EXDEV)) {
528 /* Rename across filesystems needed. */
529 result = copy_reg(smb_fname_src->base_name,
530 smb_fname_dst->base_name);
533 out:
534 END_PROFILE(syscall_rename);
535 return result;
538 static int vfswrap_fsync(vfs_handle_struct *handle, files_struct *fsp)
540 #ifdef HAVE_FSYNC
541 int result;
543 START_PROFILE(syscall_fsync);
544 result = fsync(fsp->fh->fd);
545 END_PROFILE(syscall_fsync);
546 return result;
547 #else
548 return 0;
549 #endif
552 static int vfswrap_stat(vfs_handle_struct *handle,
553 struct smb_filename *smb_fname)
555 int result = -1;
557 START_PROFILE(syscall_stat);
559 if (smb_fname->stream_name) {
560 errno = ENOENT;
561 goto out;
564 result = sys_stat(smb_fname->base_name, &smb_fname->st);
565 out:
566 END_PROFILE(syscall_stat);
567 return result;
570 static int vfswrap_fstat(vfs_handle_struct *handle, files_struct *fsp, SMB_STRUCT_STAT *sbuf)
572 int result;
574 START_PROFILE(syscall_fstat);
575 result = sys_fstat(fsp->fh->fd, sbuf);
576 END_PROFILE(syscall_fstat);
577 return result;
580 static int vfswrap_lstat(vfs_handle_struct *handle,
581 struct smb_filename *smb_fname)
583 int result = -1;
585 START_PROFILE(syscall_lstat);
587 if (smb_fname->stream_name) {
588 errno = ENOENT;
589 goto out;
592 result = sys_lstat(smb_fname->base_name, &smb_fname->st);
593 out:
594 END_PROFILE(syscall_lstat);
595 return result;
598 /********************************************************************
599 Given a stat buffer return the allocated size on disk, taking into
600 account sparse files.
601 ********************************************************************/
602 static uint64_t vfswrap_get_alloc_size(vfs_handle_struct *handle,
603 struct files_struct *fsp,
604 const SMB_STRUCT_STAT *sbuf)
606 uint64_t result;
608 START_PROFILE(syscall_get_alloc_size);
610 if(S_ISDIR(sbuf->st_ex_mode)) {
611 result = 0;
612 goto out;
615 #if defined(HAVE_STAT_ST_BLOCKS) && defined(STAT_ST_BLOCKSIZE)
616 result = (uint64_t)STAT_ST_BLOCKSIZE * (uint64_t)sbuf->st_ex_blocks;
617 #else
618 result = get_file_size_stat(sbuf);
619 #endif
621 if (fsp && fsp->initial_allocation_size)
622 result = MAX(result,fsp->initial_allocation_size);
624 result = smb_roundup(handle->conn, result);
626 out:
627 END_PROFILE(syscall_get_alloc_size);
628 return result;
631 static int vfswrap_unlink(vfs_handle_struct *handle,
632 const struct smb_filename *smb_fname)
634 int result = -1;
636 START_PROFILE(syscall_unlink);
638 if (smb_fname->stream_name) {
639 errno = ENOENT;
640 goto out;
642 result = unlink(smb_fname->base_name);
644 out:
645 END_PROFILE(syscall_unlink);
646 return result;
649 static int vfswrap_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
651 int result;
653 START_PROFILE(syscall_chmod);
656 * We need to do this due to the fact that the default POSIX ACL
657 * chmod modifies the ACL *mask* for the group owner, not the
658 * group owner bits directly. JRA.
663 int saved_errno = errno; /* We might get ENOSYS */
664 if ((result = SMB_VFS_CHMOD_ACL(handle->conn, path, mode)) == 0) {
665 END_PROFILE(syscall_chmod);
666 return result;
668 /* Error - return the old errno. */
669 errno = saved_errno;
672 result = chmod(path, mode);
673 END_PROFILE(syscall_chmod);
674 return result;
677 static int vfswrap_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
679 int result;
681 START_PROFILE(syscall_fchmod);
684 * We need to do this due to the fact that the default POSIX ACL
685 * chmod modifies the ACL *mask* for the group owner, not the
686 * group owner bits directly. JRA.
690 int saved_errno = errno; /* We might get ENOSYS */
691 if ((result = SMB_VFS_FCHMOD_ACL(fsp, mode)) == 0) {
692 END_PROFILE(syscall_fchmod);
693 return result;
695 /* Error - return the old errno. */
696 errno = saved_errno;
699 #if defined(HAVE_FCHMOD)
700 result = fchmod(fsp->fh->fd, mode);
701 #else
702 result = -1;
703 errno = ENOSYS;
704 #endif
706 END_PROFILE(syscall_fchmod);
707 return result;
710 static int vfswrap_chown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid)
712 int result;
714 START_PROFILE(syscall_chown);
715 result = chown(path, uid, gid);
716 END_PROFILE(syscall_chown);
717 return result;
720 static int vfswrap_fchown(vfs_handle_struct *handle, files_struct *fsp, uid_t uid, gid_t gid)
722 #ifdef HAVE_FCHOWN
723 int result;
725 START_PROFILE(syscall_fchown);
726 result = fchown(fsp->fh->fd, uid, gid);
727 END_PROFILE(syscall_fchown);
728 return result;
729 #else
730 errno = ENOSYS;
731 return -1;
732 #endif
735 static int vfswrap_lchown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid)
737 int result;
739 START_PROFILE(syscall_lchown);
740 result = lchown(path, uid, gid);
741 END_PROFILE(syscall_lchown);
742 return result;
745 static int vfswrap_chdir(vfs_handle_struct *handle, const char *path)
747 int result;
749 START_PROFILE(syscall_chdir);
750 result = chdir(path);
751 END_PROFILE(syscall_chdir);
752 return result;
755 static char *vfswrap_getwd(vfs_handle_struct *handle, char *path)
757 char *result;
759 START_PROFILE(syscall_getwd);
760 result = sys_getwd(path);
761 END_PROFILE(syscall_getwd);
762 return result;
765 /*********************************************************************
766 nsec timestamp resolution call. Convert down to whatever the underlying
767 system will support.
768 **********************************************************************/
770 static int vfswrap_ntimes(vfs_handle_struct *handle,
771 const struct smb_filename *smb_fname,
772 struct smb_file_time *ft)
774 int result = -1;
776 START_PROFILE(syscall_ntimes);
778 if (smb_fname->stream_name) {
779 errno = ENOENT;
780 goto out;
783 if (null_timespec(ft->atime)) {
784 ft->atime= smb_fname->st.st_ex_atime;
787 if (null_timespec(ft->mtime)) {
788 ft->mtime = smb_fname->st.st_ex_mtime;
791 if ((timespec_compare(&ft->atime,
792 &smb_fname->st.st_ex_atime) == 0) &&
793 (timespec_compare(&ft->mtime,
794 &smb_fname->st.st_ex_mtime) == 0)) {
795 return 0;
798 #if defined(HAVE_UTIMES)
799 if (ft != NULL) {
800 struct timeval tv[2];
801 tv[0] = convert_timespec_to_timeval(ft->atime);
802 tv[1] = convert_timespec_to_timeval(ft->mtime);
803 result = utimes(smb_fname->base_name, tv);
804 } else {
805 result = utimes(smb_fname->base_name, NULL);
807 #elif defined(HAVE_UTIME)
808 if (ft != NULL) {
809 struct utimbuf times;
810 times.actime = convert_timespec_to_time_t(ft->atime);
811 times.modtime = convert_timespec_to_time_t(ft->mtime);
812 result = utime(smb_fname->base_name, &times);
813 } else {
814 result = utime(smb_fname->base_name, NULL);
816 #else
817 errno = ENOSYS;
818 result = -1;
819 #endif
821 if (!null_timespec(ft->create_time) &&
822 lp_store_create_time(SNUM(handle->conn))) {
823 set_create_timespec_ea(handle->conn,
824 NULL,
825 smb_fname,
826 ft->create_time);
829 out:
830 END_PROFILE(syscall_ntimes);
831 return result;
834 /*********************************************************************
835 A version of ftruncate that will write the space on disk if strict
836 allocate is set.
837 **********************************************************************/
839 static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fsp, SMB_OFF_T len)
841 SMB_STRUCT_STAT st;
842 SMB_OFF_T currpos = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR);
843 unsigned char zero_space[4096];
844 SMB_OFF_T space_to_write;
846 if (currpos == -1)
847 return -1;
849 if (SMB_VFS_FSTAT(fsp, &st) == -1)
850 return -1;
852 space_to_write = len - st.st_ex_size;
854 #ifdef S_ISFIFO
855 if (S_ISFIFO(st.st_ex_mode))
856 return 0;
857 #endif
859 if (st.st_ex_size == len)
860 return 0;
862 /* Shrink - just ftruncate. */
863 if (st.st_ex_size > len)
864 return sys_ftruncate(fsp->fh->fd, len);
866 /* available disk space is enough or not? */
867 if (lp_strict_allocate(SNUM(fsp->conn))){
868 uint64_t space_avail;
869 uint64_t bsize,dfree,dsize;
871 space_avail = get_dfree_info(fsp->conn,
872 fsp->fsp_name->base_name, false,
873 &bsize, &dfree, &dsize);
874 /* space_avail is 1k blocks */
875 if (space_avail == (uint64_t)-1 ||
876 ((uint64_t)space_to_write/1024 > space_avail) ) {
877 errno = ENOSPC;
878 return -1;
882 /* Write out the real space on disk. */
883 if (SMB_VFS_LSEEK(fsp, st.st_ex_size, SEEK_SET) != st.st_ex_size)
884 return -1;
886 space_to_write = len - st.st_ex_size;
888 memset(zero_space, '\0', sizeof(zero_space));
889 while ( space_to_write > 0) {
890 SMB_OFF_T retlen;
891 SMB_OFF_T current_len_to_write = MIN(sizeof(zero_space),space_to_write);
893 retlen = SMB_VFS_WRITE(fsp,(char *)zero_space,current_len_to_write);
894 if (retlen <= 0)
895 return -1;
897 space_to_write -= retlen;
900 /* Seek to where we were */
901 if (SMB_VFS_LSEEK(fsp, currpos, SEEK_SET) != currpos)
902 return -1;
904 return 0;
907 static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, SMB_OFF_T len)
909 int result = -1;
910 SMB_STRUCT_STAT st;
911 char c = 0;
912 SMB_OFF_T currpos;
914 START_PROFILE(syscall_ftruncate);
916 if (lp_strict_allocate(SNUM(fsp->conn))) {
917 result = strict_allocate_ftruncate(handle, fsp, len);
918 END_PROFILE(syscall_ftruncate);
919 return result;
922 /* we used to just check HAVE_FTRUNCATE_EXTEND and only use
923 sys_ftruncate if the system supports it. Then I discovered that
924 you can have some filesystems that support ftruncate
925 expansion and some that don't! On Linux fat can't do
926 ftruncate extend but ext2 can. */
928 result = sys_ftruncate(fsp->fh->fd, len);
929 if (result == 0)
930 goto done;
932 /* According to W. R. Stevens advanced UNIX prog. Pure 4.3 BSD cannot
933 extend a file with ftruncate. Provide alternate implementation
934 for this */
935 currpos = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR);
936 if (currpos == -1) {
937 goto done;
940 /* Do an fstat to see if the file is longer than the requested
941 size in which case the ftruncate above should have
942 succeeded or shorter, in which case seek to len - 1 and
943 write 1 byte of zero */
944 if (SMB_VFS_FSTAT(fsp, &st) == -1) {
945 goto done;
948 #ifdef S_ISFIFO
949 if (S_ISFIFO(st.st_ex_mode)) {
950 result = 0;
951 goto done;
953 #endif
955 if (st.st_ex_size == len) {
956 result = 0;
957 goto done;
960 if (st.st_ex_size > len) {
961 /* the sys_ftruncate should have worked */
962 goto done;
965 if (SMB_VFS_LSEEK(fsp, len-1, SEEK_SET) != len -1)
966 goto done;
968 if (SMB_VFS_WRITE(fsp, &c, 1)!=1)
969 goto done;
971 /* Seek to where we were */
972 if (SMB_VFS_LSEEK(fsp, currpos, SEEK_SET) != currpos)
973 goto done;
974 result = 0;
976 done:
978 END_PROFILE(syscall_ftruncate);
979 return result;
982 static bool vfswrap_lock(vfs_handle_struct *handle, files_struct *fsp, int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
984 bool result;
986 START_PROFILE(syscall_fcntl_lock);
987 result = fcntl_lock(fsp->fh->fd, op, offset, count, type);
988 END_PROFILE(syscall_fcntl_lock);
989 return result;
992 static int vfswrap_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
993 uint32 share_mode)
995 START_PROFILE(syscall_kernel_flock);
996 kernel_flock(fsp->fh->fd, share_mode);
997 END_PROFILE(syscall_kernel_flock);
998 return 0;
1001 static bool vfswrap_getlock(vfs_handle_struct *handle, files_struct *fsp, SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid)
1003 bool result;
1005 START_PROFILE(syscall_fcntl_getlock);
1006 result = fcntl_getlock(fsp->fh->fd, poffset, pcount, ptype, ppid);
1007 END_PROFILE(syscall_fcntl_getlock);
1008 return result;
1011 static int vfswrap_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1012 int leasetype)
1014 int result = -1;
1016 START_PROFILE(syscall_linux_setlease);
1018 #ifdef HAVE_KERNEL_OPLOCKS_LINUX
1019 /* first set the signal handler */
1020 if(linux_set_lease_sighandler(fsp->fh->fd) == -1) {
1021 return -1;
1024 result = linux_setlease(fsp->fh->fd, leasetype);
1025 #else
1026 errno = ENOSYS;
1027 #endif
1028 END_PROFILE(syscall_linux_setlease);
1029 return result;
1032 static int vfswrap_symlink(vfs_handle_struct *handle, const char *oldpath, const char *newpath)
1034 int result;
1036 START_PROFILE(syscall_symlink);
1037 result = symlink(oldpath, newpath);
1038 END_PROFILE(syscall_symlink);
1039 return result;
1042 static int vfswrap_readlink(vfs_handle_struct *handle, const char *path, char *buf, size_t bufsiz)
1044 int result;
1046 START_PROFILE(syscall_readlink);
1047 result = readlink(path, buf, bufsiz);
1048 END_PROFILE(syscall_readlink);
1049 return result;
1052 static int vfswrap_link(vfs_handle_struct *handle, const char *oldpath, const char *newpath)
1054 int result;
1056 START_PROFILE(syscall_link);
1057 result = link(oldpath, newpath);
1058 END_PROFILE(syscall_link);
1059 return result;
1062 static int vfswrap_mknod(vfs_handle_struct *handle, const char *pathname, mode_t mode, SMB_DEV_T dev)
1064 int result;
1066 START_PROFILE(syscall_mknod);
1067 result = sys_mknod(pathname, mode, dev);
1068 END_PROFILE(syscall_mknod);
1069 return result;
1072 static char *vfswrap_realpath(vfs_handle_struct *handle, const char *path, char *resolved_path)
1074 char *result;
1076 START_PROFILE(syscall_realpath);
1077 result = realpath(path, resolved_path);
1078 END_PROFILE(syscall_realpath);
1079 return result;
1082 static NTSTATUS vfswrap_notify_watch(vfs_handle_struct *vfs_handle,
1083 struct sys_notify_context *ctx,
1084 struct notify_entry *e,
1085 void (*callback)(struct sys_notify_context *ctx,
1086 void *private_data,
1087 struct notify_event *ev),
1088 void *private_data, void *handle)
1091 * So far inotify is the only supported default notify mechanism. If
1092 * another platform like the the BSD's or a proprietary Unix comes
1093 * along and wants another default, we can play the same trick we
1094 * played with Posix ACLs.
1096 * Until that is the case, hard-code inotify here.
1098 #ifdef HAVE_INOTIFY
1099 if (lp_kernel_change_notify(ctx->conn->params)) {
1100 return inotify_watch(ctx, e, callback, private_data, handle);
1102 #endif
1104 * Do nothing, leave everything to notify_internal.c
1106 return NT_STATUS_OK;
1109 static int vfswrap_chflags(vfs_handle_struct *handle, const char *path,
1110 unsigned int flags)
1112 #ifdef HAVE_CHFLAGS
1113 return chflags(path, flags);
1114 #else
1115 errno = ENOSYS;
1116 return -1;
1117 #endif
1120 static struct file_id vfswrap_file_id_create(struct vfs_handle_struct *handle,
1121 const SMB_STRUCT_STAT *sbuf)
1123 struct file_id key;
1125 /* the ZERO_STRUCT ensures padding doesn't break using the key as a
1126 * blob */
1127 ZERO_STRUCT(key);
1129 key.devid = sbuf->st_ex_dev;
1130 key.inode = sbuf->st_ex_ino;
1131 /* key.extid is unused by default. */
1133 return key;
1136 static NTSTATUS vfswrap_streaminfo(vfs_handle_struct *handle,
1137 struct files_struct *fsp,
1138 const char *fname,
1139 TALLOC_CTX *mem_ctx,
1140 unsigned int *pnum_streams,
1141 struct stream_struct **pstreams)
1143 SMB_STRUCT_STAT sbuf;
1144 unsigned int num_streams = 0;
1145 struct stream_struct *streams = NULL;
1146 int ret;
1148 if ((fsp != NULL) && (fsp->is_directory)) {
1150 * No default streams on directories
1152 goto done;
1155 if ((fsp != NULL) && (fsp->fh->fd != -1)) {
1156 ret = SMB_VFS_FSTAT(fsp, &sbuf);
1158 else {
1159 struct smb_filename *smb_fname = NULL;
1160 NTSTATUS status;
1162 status = create_synthetic_smb_fname(talloc_tos(), fname, NULL,
1163 NULL, &smb_fname);
1164 if (!NT_STATUS_IS_OK(status)) {
1165 return status;
1167 ret = SMB_VFS_STAT(handle->conn, smb_fname);
1168 sbuf = smb_fname->st;
1169 TALLOC_FREE(smb_fname);
1172 if (ret == -1) {
1173 return map_nt_error_from_unix(errno);
1176 if (S_ISDIR(sbuf.st_ex_mode)) {
1177 goto done;
1180 streams = talloc(mem_ctx, struct stream_struct);
1182 if (streams == NULL) {
1183 return NT_STATUS_NO_MEMORY;
1186 streams->size = sbuf.st_ex_size;
1187 streams->alloc_size = SMB_VFS_GET_ALLOC_SIZE(handle->conn, fsp, &sbuf);
1189 streams->name = talloc_strdup(streams, "::$DATA");
1190 if (streams->name == NULL) {
1191 TALLOC_FREE(streams);
1192 return NT_STATUS_NO_MEMORY;
1195 num_streams = 1;
1196 done:
1197 *pnum_streams = num_streams;
1198 *pstreams = streams;
1199 return NT_STATUS_OK;
1202 static int vfswrap_get_real_filename(struct vfs_handle_struct *handle,
1203 const char *path,
1204 const char *name,
1205 TALLOC_CTX *mem_ctx,
1206 char **found_name)
1209 * Don't fall back to get_real_filename so callers can differentiate
1210 * between a full directory scan and an actual case-insensitive stat.
1212 errno = EOPNOTSUPP;
1213 return -1;
1216 static const char *vfswrap_connectpath(struct vfs_handle_struct *handle,
1217 const char *fname)
1219 return handle->conn->connectpath;
1222 static NTSTATUS vfswrap_brl_lock_windows(struct vfs_handle_struct *handle,
1223 struct byte_range_lock *br_lck,
1224 struct lock_struct *plock,
1225 bool blocking_lock,
1226 struct blocking_lock_record *blr)
1228 SMB_ASSERT(plock->lock_flav == WINDOWS_LOCK);
1230 /* Note: blr is not used in the default implementation. */
1231 return brl_lock_windows_default(br_lck, plock, blocking_lock);
1234 static bool vfswrap_brl_unlock_windows(struct vfs_handle_struct *handle,
1235 struct messaging_context *msg_ctx,
1236 struct byte_range_lock *br_lck,
1237 const struct lock_struct *plock)
1239 SMB_ASSERT(plock->lock_flav == WINDOWS_LOCK);
1241 return brl_unlock_windows_default(msg_ctx, br_lck, plock);
1244 static bool vfswrap_brl_cancel_windows(struct vfs_handle_struct *handle,
1245 struct byte_range_lock *br_lck,
1246 struct lock_struct *plock,
1247 struct blocking_lock_record *blr)
1249 SMB_ASSERT(plock->lock_flav == WINDOWS_LOCK);
1251 /* Note: blr is not used in the default implementation. */
1252 return brl_lock_cancel_default(br_lck, plock);
1255 static bool vfswrap_strict_lock(struct vfs_handle_struct *handle,
1256 files_struct *fsp,
1257 struct lock_struct *plock)
1259 SMB_ASSERT(plock->lock_type == READ_LOCK ||
1260 plock->lock_type == WRITE_LOCK);
1262 return strict_lock_default(fsp, plock);
1265 static void vfswrap_strict_unlock(struct vfs_handle_struct *handle,
1266 files_struct *fsp,
1267 struct lock_struct *plock)
1269 SMB_ASSERT(plock->lock_type == READ_LOCK ||
1270 plock->lock_type == WRITE_LOCK);
1272 strict_unlock_default(fsp, plock);
1275 /* NT ACL operations. */
1277 static NTSTATUS vfswrap_fget_nt_acl(vfs_handle_struct *handle,
1278 files_struct *fsp,
1279 uint32 security_info, SEC_DESC **ppdesc)
1281 NTSTATUS result;
1283 START_PROFILE(fget_nt_acl);
1284 result = posix_fget_nt_acl(fsp, security_info, ppdesc);
1285 END_PROFILE(fget_nt_acl);
1286 return result;
1289 static NTSTATUS vfswrap_get_nt_acl(vfs_handle_struct *handle,
1290 const char *name,
1291 uint32 security_info, SEC_DESC **ppdesc)
1293 NTSTATUS result;
1295 START_PROFILE(get_nt_acl);
1296 result = posix_get_nt_acl(handle->conn, name, security_info, ppdesc);
1297 END_PROFILE(get_nt_acl);
1298 return result;
1301 static NTSTATUS vfswrap_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const SEC_DESC *psd)
1303 NTSTATUS result;
1305 START_PROFILE(fset_nt_acl);
1306 result = set_nt_acl(fsp, security_info_sent, psd);
1307 END_PROFILE(fset_nt_acl);
1308 return result;
1311 static int vfswrap_chmod_acl(vfs_handle_struct *handle, const char *name, mode_t mode)
1313 #ifdef HAVE_NO_ACL
1314 errno = ENOSYS;
1315 return -1;
1316 #else
1317 int result;
1319 START_PROFILE(chmod_acl);
1320 result = chmod_acl(handle->conn, name, mode);
1321 END_PROFILE(chmod_acl);
1322 return result;
1323 #endif
1326 static int vfswrap_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
1328 #ifdef HAVE_NO_ACL
1329 errno = ENOSYS;
1330 return -1;
1331 #else
1332 int result;
1334 START_PROFILE(fchmod_acl);
1335 result = fchmod_acl(fsp, mode);
1336 END_PROFILE(fchmod_acl);
1337 return result;
1338 #endif
1341 static int vfswrap_sys_acl_get_entry(vfs_handle_struct *handle, SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1343 return sys_acl_get_entry(theacl, entry_id, entry_p);
1346 static int vfswrap_sys_acl_get_tag_type(vfs_handle_struct *handle, SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1348 return sys_acl_get_tag_type(entry_d, tag_type_p);
1351 static int vfswrap_sys_acl_get_permset(vfs_handle_struct *handle, SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1353 return sys_acl_get_permset(entry_d, permset_p);
1356 static void * vfswrap_sys_acl_get_qualifier(vfs_handle_struct *handle, SMB_ACL_ENTRY_T entry_d)
1358 return sys_acl_get_qualifier(entry_d);
1361 static SMB_ACL_T vfswrap_sys_acl_get_file(vfs_handle_struct *handle, const char *path_p, SMB_ACL_TYPE_T type)
1363 return sys_acl_get_file(handle, path_p, type);
1366 static SMB_ACL_T vfswrap_sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp)
1368 return sys_acl_get_fd(handle, fsp);
1371 static int vfswrap_sys_acl_clear_perms(vfs_handle_struct *handle, SMB_ACL_PERMSET_T permset)
1373 return sys_acl_clear_perms(permset);
1376 static int vfswrap_sys_acl_add_perm(vfs_handle_struct *handle, SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1378 return sys_acl_add_perm(permset, perm);
1381 static char * vfswrap_sys_acl_to_text(vfs_handle_struct *handle, SMB_ACL_T theacl, ssize_t *plen)
1383 return sys_acl_to_text(theacl, plen);
1386 static SMB_ACL_T vfswrap_sys_acl_init(vfs_handle_struct *handle, int count)
1388 return sys_acl_init(count);
1391 static int vfswrap_sys_acl_create_entry(vfs_handle_struct *handle, SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1393 return sys_acl_create_entry(pacl, pentry);
1396 static int vfswrap_sys_acl_set_tag_type(vfs_handle_struct *handle, SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1398 return sys_acl_set_tag_type(entry, tagtype);
1401 static int vfswrap_sys_acl_set_qualifier(vfs_handle_struct *handle, SMB_ACL_ENTRY_T entry, void *qual)
1403 return sys_acl_set_qualifier(entry, qual);
1406 static int vfswrap_sys_acl_set_permset(vfs_handle_struct *handle, SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1408 return sys_acl_set_permset(entry, permset);
1411 static int vfswrap_sys_acl_valid(vfs_handle_struct *handle, SMB_ACL_T theacl )
1413 return sys_acl_valid(theacl );
1416 static int vfswrap_sys_acl_set_file(vfs_handle_struct *handle, const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1418 return sys_acl_set_file(handle, name, acltype, theacl);
1421 static int vfswrap_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp, SMB_ACL_T theacl)
1423 return sys_acl_set_fd(handle, fsp, theacl);
1426 static int vfswrap_sys_acl_delete_def_file(vfs_handle_struct *handle, const char *path)
1428 return sys_acl_delete_def_file(handle, path);
1431 static int vfswrap_sys_acl_get_perm(vfs_handle_struct *handle, SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1433 return sys_acl_get_perm(permset, perm);
1436 static int vfswrap_sys_acl_free_text(vfs_handle_struct *handle, char *text)
1438 return sys_acl_free_text(text);
1441 static int vfswrap_sys_acl_free_acl(vfs_handle_struct *handle, SMB_ACL_T posix_acl)
1443 return sys_acl_free_acl(posix_acl);
1446 static int vfswrap_sys_acl_free_qualifier(vfs_handle_struct *handle, void *qualifier, SMB_ACL_TAG_T tagtype)
1448 return sys_acl_free_qualifier(qualifier, tagtype);
1451 /****************************************************************
1452 Extended attribute operations.
1453 *****************************************************************/
1455 static ssize_t vfswrap_getxattr(struct vfs_handle_struct *handle,const char *path, const char *name, void *value, size_t size)
1457 return sys_getxattr(path, name, value, size);
1460 static ssize_t vfswrap_lgetxattr(struct vfs_handle_struct *handle,const char *path, const char *name, void *value, size_t size)
1462 return sys_lgetxattr(path, name, value, size);
1465 static ssize_t vfswrap_fgetxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name, void *value, size_t size)
1467 return sys_fgetxattr(fsp->fh->fd, name, value, size);
1470 static ssize_t vfswrap_listxattr(struct vfs_handle_struct *handle, const char *path, char *list, size_t size)
1472 return sys_listxattr(path, list, size);
1475 ssize_t vfswrap_llistxattr(struct vfs_handle_struct *handle, const char *path, char *list, size_t size)
1477 return sys_llistxattr(path, list, size);
1480 ssize_t vfswrap_flistxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, char *list, size_t size)
1482 return sys_flistxattr(fsp->fh->fd, list, size);
1485 static int vfswrap_removexattr(struct vfs_handle_struct *handle, const char *path, const char *name)
1487 return sys_removexattr(path, name);
1490 static int vfswrap_lremovexattr(struct vfs_handle_struct *handle, const char *path, const char *name)
1492 return sys_lremovexattr(path, name);
1495 static int vfswrap_fremovexattr(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name)
1497 return sys_fremovexattr(fsp->fh->fd, name);
1500 static int vfswrap_setxattr(struct vfs_handle_struct *handle, const char *path, const char *name, const void *value, size_t size, int flags)
1502 return sys_setxattr(path, name, value, size, flags);
1505 static int vfswrap_lsetxattr(struct vfs_handle_struct *handle, const char *path, const char *name, const void *value, size_t size, int flags)
1507 return sys_lsetxattr(path, name, value, size, flags);
1510 static int vfswrap_fsetxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name, const void *value, size_t size, int flags)
1512 return sys_fsetxattr(fsp->fh->fd, name, value, size, flags);
1515 static int vfswrap_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
1517 int ret;
1519 * aio_read must be done as root, because in the glibc aio
1520 * implementation the helper thread needs to be able to send a signal
1521 * to the main thread, even when it has done a seteuid() to a
1522 * different user.
1524 become_root();
1525 ret = sys_aio_read(aiocb);
1526 unbecome_root();
1527 return ret;
1530 static int vfswrap_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
1532 int ret;
1534 * aio_write must be done as root, because in the glibc aio
1535 * implementation the helper thread needs to be able to send a signal
1536 * to the main thread, even when it has done a seteuid() to a
1537 * different user.
1539 become_root();
1540 ret = sys_aio_write(aiocb);
1541 unbecome_root();
1542 return ret;
1545 static ssize_t vfswrap_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
1547 return sys_aio_return(aiocb);
1550 static int vfswrap_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
1552 return sys_aio_cancel(fsp->fh->fd, aiocb);
1555 static int vfswrap_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
1557 return sys_aio_error(aiocb);
1560 static int vfswrap_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb)
1562 return sys_aio_fsync(op, aiocb);
1565 static int vfswrap_aio_suspend(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_AIOCB * const aiocb[], int n, const struct timespec *timeout)
1567 return sys_aio_suspend(aiocb, n, timeout);
1570 static bool vfswrap_aio_force(struct vfs_handle_struct *handle, struct files_struct *fsp)
1572 return false;
1575 static bool vfswrap_is_offline(struct vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf)
1577 if (ISDOT(path) || ISDOTDOT(path)) {
1578 return false;
1581 if (!lp_dmapi_support(SNUM(handle->conn)) || !dmapi_have_session()) {
1582 #if defined(ENOTSUP)
1583 errno = ENOTSUP;
1584 #endif
1585 return false;
1588 return (dmapi_file_flags(path) & FILE_ATTRIBUTE_OFFLINE) != 0;
1591 static int vfswrap_set_offline(struct vfs_handle_struct *handle, const char *path)
1593 /* We don't know how to set offline bit by default, needs to be overriden in the vfs modules */
1594 #if defined(ENOTSUP)
1595 errno = ENOTSUP;
1596 #endif
1597 return -1;
1600 static struct vfs_fn_pointers vfs_default_fns = {
1601 /* Disk operations */
1603 .connect_fn = vfswrap_connect,
1604 .disconnect = vfswrap_disconnect,
1605 .disk_free = vfswrap_disk_free,
1606 .get_quota = vfswrap_get_quota,
1607 .set_quota = vfswrap_set_quota,
1608 .get_shadow_copy_data = vfswrap_get_shadow_copy_data,
1609 .statvfs = vfswrap_statvfs,
1610 .fs_capabilities = vfswrap_fs_capabilities,
1612 /* Directory operations */
1614 .opendir = vfswrap_opendir,
1615 .readdir = vfswrap_readdir,
1616 .seekdir = vfswrap_seekdir,
1617 .telldir = vfswrap_telldir,
1618 .rewind_dir = vfswrap_rewinddir,
1619 .mkdir = vfswrap_mkdir,
1620 .rmdir = vfswrap_rmdir,
1621 .closedir = vfswrap_closedir,
1622 .init_search_op = vfswrap_init_search_op,
1624 /* File operations */
1626 .open = vfswrap_open,
1627 .create_file = vfswrap_create_file,
1628 .close_fn = vfswrap_close,
1629 .vfs_read = vfswrap_read,
1630 .pread = vfswrap_pread,
1631 .write = vfswrap_write,
1632 .pwrite = vfswrap_pwrite,
1633 .lseek = vfswrap_lseek,
1634 .sendfile = vfswrap_sendfile,
1635 .recvfile = vfswrap_recvfile,
1636 .rename = vfswrap_rename,
1637 .fsync = vfswrap_fsync,
1638 .stat = vfswrap_stat,
1639 .fstat = vfswrap_fstat,
1640 .lstat = vfswrap_lstat,
1641 .get_alloc_size = vfswrap_get_alloc_size,
1642 .unlink = vfswrap_unlink,
1643 .chmod = vfswrap_chmod,
1644 .fchmod = vfswrap_fchmod,
1645 .chown = vfswrap_chown,
1646 .fchown = vfswrap_fchown,
1647 .lchown = vfswrap_lchown,
1648 .chdir = vfswrap_chdir,
1649 .getwd = vfswrap_getwd,
1650 .ntimes = vfswrap_ntimes,
1651 .ftruncate = vfswrap_ftruncate,
1652 .lock = vfswrap_lock,
1653 .kernel_flock = vfswrap_kernel_flock,
1654 .linux_setlease = vfswrap_linux_setlease,
1655 .getlock = vfswrap_getlock,
1656 .symlink = vfswrap_symlink,
1657 .vfs_readlink = vfswrap_readlink,
1658 .link = vfswrap_link,
1659 .mknod = vfswrap_mknod,
1660 .realpath = vfswrap_realpath,
1661 .notify_watch = vfswrap_notify_watch,
1662 .chflags = vfswrap_chflags,
1663 .file_id_create = vfswrap_file_id_create,
1664 .streaminfo = vfswrap_streaminfo,
1665 .get_real_filename = vfswrap_get_real_filename,
1666 .connectpath = vfswrap_connectpath,
1667 .brl_lock_windows = vfswrap_brl_lock_windows,
1668 .brl_unlock_windows = vfswrap_brl_unlock_windows,
1669 .brl_cancel_windows = vfswrap_brl_cancel_windows,
1670 .strict_lock = vfswrap_strict_lock,
1671 .strict_unlock = vfswrap_strict_unlock,
1673 /* NT ACL operations. */
1675 .fget_nt_acl = vfswrap_fget_nt_acl,
1676 .get_nt_acl = vfswrap_get_nt_acl,
1677 .fset_nt_acl = vfswrap_fset_nt_acl,
1679 /* POSIX ACL operations. */
1681 .chmod_acl = vfswrap_chmod_acl,
1682 .fchmod_acl = vfswrap_fchmod_acl,
1684 .sys_acl_get_entry = vfswrap_sys_acl_get_entry,
1685 .sys_acl_get_tag_type = vfswrap_sys_acl_get_tag_type,
1686 .sys_acl_get_permset = vfswrap_sys_acl_get_permset,
1687 .sys_acl_get_qualifier = vfswrap_sys_acl_get_qualifier,
1688 .sys_acl_get_file = vfswrap_sys_acl_get_file,
1689 .sys_acl_get_fd = vfswrap_sys_acl_get_fd,
1690 .sys_acl_clear_perms = vfswrap_sys_acl_clear_perms,
1691 .sys_acl_add_perm = vfswrap_sys_acl_add_perm,
1692 .sys_acl_to_text = vfswrap_sys_acl_to_text,
1693 .sys_acl_init = vfswrap_sys_acl_init,
1694 .sys_acl_create_entry = vfswrap_sys_acl_create_entry,
1695 .sys_acl_set_tag_type = vfswrap_sys_acl_set_tag_type,
1696 .sys_acl_set_qualifier = vfswrap_sys_acl_set_qualifier,
1697 .sys_acl_set_permset = vfswrap_sys_acl_set_permset,
1698 .sys_acl_valid = vfswrap_sys_acl_valid,
1699 .sys_acl_set_file = vfswrap_sys_acl_set_file,
1700 .sys_acl_set_fd = vfswrap_sys_acl_set_fd,
1701 .sys_acl_delete_def_file = vfswrap_sys_acl_delete_def_file,
1702 .sys_acl_get_perm = vfswrap_sys_acl_get_perm,
1703 .sys_acl_free_text = vfswrap_sys_acl_free_text,
1704 .sys_acl_free_acl = vfswrap_sys_acl_free_acl,
1705 .sys_acl_free_qualifier = vfswrap_sys_acl_free_qualifier,
1707 /* EA operations. */
1708 .getxattr = vfswrap_getxattr,
1709 .lgetxattr = vfswrap_lgetxattr,
1710 .fgetxattr = vfswrap_fgetxattr,
1711 .listxattr = vfswrap_listxattr,
1712 .llistxattr = vfswrap_llistxattr,
1713 .flistxattr = vfswrap_flistxattr,
1714 .removexattr = vfswrap_removexattr,
1715 .lremovexattr = vfswrap_lremovexattr,
1716 .fremovexattr = vfswrap_fremovexattr,
1717 .setxattr = vfswrap_setxattr,
1718 .lsetxattr = vfswrap_lsetxattr,
1719 .fsetxattr = vfswrap_fsetxattr,
1721 /* aio operations */
1722 .aio_read = vfswrap_aio_read,
1723 .aio_write = vfswrap_aio_write,
1724 .aio_return_fn = vfswrap_aio_return,
1725 .aio_cancel = vfswrap_aio_cancel,
1726 .aio_error_fn = vfswrap_aio_error,
1727 .aio_fsync = vfswrap_aio_fsync,
1728 .aio_suspend = vfswrap_aio_suspend,
1729 .aio_force = vfswrap_aio_force,
1731 /* offline operations */
1732 .is_offline = vfswrap_is_offline,
1733 .set_offline = vfswrap_set_offline
1736 NTSTATUS vfs_default_init(void);
1737 NTSTATUS vfs_default_init(void)
1739 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
1740 DEFAULT_VFS_MODULE_NAME, &vfs_default_fns);