2 Unix SMB/Netbios implementation.
4 VFS initialisation and support functions
5 Copyright (C) Tim Potter 1999
6 Copyright (C) Alexander Bokovoy 2002
7 Copyright (C) James Peach 2006
8 Copyright (C) Volker Lendecke 2009
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 This work was sponsored by Optifacio Software Services, Inc.
27 #include "system/filesys.h"
28 #include "smbd/smbd.h"
29 #include "smbd/globals.h"
30 #include "../lib/util/memcache.h"
31 #include "transfer_file.h"
33 #include "lib/util/tevent_unix.h"
34 #include "lib/util/tevent_ntstatus.h"
35 #include "lib/util/sys_rw.h"
38 #define DBGC_CLASS DBGC_VFS
43 struct vfs_fsp_data
*next
;
44 struct vfs_handle_struct
*owner
;
45 void (*destroy
)(void *p_data
);
47 /* NOTE: This structure contains four pointers so that we can guarantee
48 * that the end of the structure is always both 4-byte and 8-byte aligned.
52 struct vfs_init_function_entry
{
54 struct vfs_init_function_entry
*prev
, *next
;
55 const struct vfs_fn_pointers
*fns
;
58 /****************************************************************************
59 maintain the list of available backends
60 ****************************************************************************/
62 static struct vfs_init_function_entry
*vfs_find_backend_entry(const char *name
)
64 struct vfs_init_function_entry
*entry
= backends
;
66 DEBUG(10, ("vfs_find_backend_entry called for %s\n", name
));
69 if (strcmp(entry
->name
, name
)==0) return entry
;
76 NTSTATUS
smb_register_vfs(int version
, const char *name
,
77 const struct vfs_fn_pointers
*fns
)
79 struct vfs_init_function_entry
*entry
= backends
;
81 if ((version
!= SMB_VFS_INTERFACE_VERSION
)) {
82 DEBUG(0, ("Failed to register vfs module.\n"
83 "The module was compiled against SMB_VFS_INTERFACE_VERSION %d,\n"
84 "current SMB_VFS_INTERFACE_VERSION is %d.\n"
85 "Please recompile against the current Samba Version!\n",
86 version
, SMB_VFS_INTERFACE_VERSION
));
87 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
90 if (!name
|| !name
[0]) {
91 DEBUG(0,("smb_register_vfs() called with NULL pointer or empty name!\n"));
92 return NT_STATUS_INVALID_PARAMETER
;
95 if (vfs_find_backend_entry(name
)) {
96 DEBUG(0,("VFS module %s already loaded!\n", name
));
97 return NT_STATUS_OBJECT_NAME_COLLISION
;
100 entry
= SMB_XMALLOC_P(struct vfs_init_function_entry
);
101 entry
->name
= smb_xstrdup(name
);
104 DLIST_ADD(backends
, entry
);
105 DEBUG(5, ("Successfully added vfs backend '%s'\n", name
));
109 /****************************************************************************
110 initialise default vfs hooks
111 ****************************************************************************/
113 static void vfs_init_default(connection_struct
*conn
)
115 DEBUG(3, ("Initialising default vfs hooks\n"));
116 vfs_init_custom(conn
, DEFAULT_VFS_MODULE_NAME
);
119 /****************************************************************************
120 initialise custom vfs hooks
121 ****************************************************************************/
123 bool vfs_init_custom(connection_struct
*conn
, const char *vfs_object
)
125 char *module_path
= NULL
;
126 char *module_name
= NULL
;
127 char *module_param
= NULL
, *p
;
128 vfs_handle_struct
*handle
;
129 const struct vfs_init_function_entry
*entry
;
131 if (!conn
||!vfs_object
||!vfs_object
[0]) {
132 DEBUG(0, ("vfs_init_custom() called with NULL pointer or "
133 "empty vfs_object!\n"));
138 static_init_vfs(NULL
);
141 DEBUG(3, ("Initialising custom vfs hooks from [%s]\n", vfs_object
));
143 module_path
= smb_xstrdup(vfs_object
);
145 p
= strchr_m(module_path
, ':');
150 trim_char(module_param
, ' ', ' ');
153 trim_char(module_path
, ' ', ' ');
155 module_name
= smb_xstrdup(module_path
);
157 if ((module_name
[0] == '/') &&
158 (strcmp(module_path
, DEFAULT_VFS_MODULE_NAME
) != 0)) {
161 * Extract the module name from the path. Just use the base
162 * name of the last path component.
165 SAFE_FREE(module_name
);
166 module_name
= smb_xstrdup(strrchr_m(module_path
, '/')+1);
168 p
= strchr_m(module_name
, '.');
175 /* First, try to load the module with the new module system */
176 entry
= vfs_find_backend_entry(module_name
);
180 DEBUG(5, ("vfs module [%s] not loaded - trying to load...\n",
183 status
= smb_load_module("vfs", module_path
);
184 if (!NT_STATUS_IS_OK(status
)) {
185 DEBUG(0, ("error probing vfs module '%s': %s\n",
186 module_path
, nt_errstr(status
)));
190 entry
= vfs_find_backend_entry(module_name
);
192 DEBUG(0,("Can't find a vfs module [%s]\n",vfs_object
));
197 DEBUGADD(5,("Successfully loaded vfs module [%s] with the new modules system\n", vfs_object
));
199 handle
= talloc_zero(conn
, vfs_handle_struct
);
201 DEBUG(0,("TALLOC_ZERO() failed!\n"));
205 handle
->fns
= entry
->fns
;
207 handle
->param
= talloc_strdup(conn
, module_param
);
209 DLIST_ADD(conn
->vfs_handles
, handle
);
211 SAFE_FREE(module_path
);
212 SAFE_FREE(module_name
);
216 SAFE_FREE(module_path
);
217 SAFE_FREE(module_name
);
221 /*****************************************************************
222 Allow VFS modules to extend files_struct with VFS-specific state.
223 This will be ok for small numbers of extensions, but might need to
224 be refactored if it becomes more widely used.
225 ******************************************************************/
227 #define EXT_DATA_AREA(e) ((uint8_t *)(e) + sizeof(struct vfs_fsp_data))
229 void *vfs_add_fsp_extension_notype(vfs_handle_struct
*handle
,
230 files_struct
*fsp
, size_t ext_size
,
231 void (*destroy_fn
)(void *p_data
))
233 struct vfs_fsp_data
*ext
;
236 /* Prevent VFS modules adding multiple extensions. */
237 if ((ext_data
= vfs_fetch_fsp_extension(handle
, fsp
))) {
241 ext
= talloc_zero_size(
242 handle
->conn
, sizeof(struct vfs_fsp_data
) + ext_size
);
248 ext
->next
= fsp
->vfs_extension
;
249 ext
->destroy
= destroy_fn
;
250 fsp
->vfs_extension
= ext
;
251 return EXT_DATA_AREA(ext
);
254 void vfs_remove_fsp_extension(vfs_handle_struct
*handle
, files_struct
*fsp
)
256 struct vfs_fsp_data
*curr
;
257 struct vfs_fsp_data
*prev
;
259 for (curr
= fsp
->vfs_extension
, prev
= NULL
;
261 prev
= curr
, curr
= curr
->next
) {
262 if (curr
->owner
== handle
) {
264 prev
->next
= curr
->next
;
266 fsp
->vfs_extension
= curr
->next
;
269 curr
->destroy(EXT_DATA_AREA(curr
));
277 void vfs_remove_all_fsp_extensions(files_struct
*fsp
)
279 struct vfs_fsp_data
*curr
;
280 struct vfs_fsp_data
*next
;
282 for (curr
= fsp
->vfs_extension
; curr
; curr
= next
) {
285 fsp
->vfs_extension
= next
;
288 curr
->destroy(EXT_DATA_AREA(curr
));
294 void *vfs_memctx_fsp_extension(vfs_handle_struct
*handle
,
295 const struct files_struct
*fsp
)
297 struct vfs_fsp_data
*head
;
299 for (head
= fsp
->vfs_extension
; head
; head
= head
->next
) {
300 if (head
->owner
== handle
) {
308 void *vfs_fetch_fsp_extension(vfs_handle_struct
*handle
,
309 const struct files_struct
*fsp
)
311 struct vfs_fsp_data
*head
;
313 head
= (struct vfs_fsp_data
*)vfs_memctx_fsp_extension(handle
, fsp
);
315 return EXT_DATA_AREA(head
);
324 * Ensure this module catches all VFS functions.
327 void smb_vfs_assert_all_fns(const struct vfs_fn_pointers
* fns
,
330 bool missing_fn
= false;
332 const uintptr_t *end
= (const uintptr_t *)(fns
+ 1);
334 for (idx
= 0; ((const uintptr_t *)fns
+ idx
) < end
; idx
++) {
335 if (*((const uintptr_t *)fns
+ idx
) == 0) {
336 DBG_ERR("VFS function at index %d not implemented "
337 "in module %s\n", idx
, module
);
343 smb_panic("Required VFS function not implemented in module.\n");
347 void smb_vfs_assert_all_fns(const struct vfs_fn_pointers
* fns
,
353 /*****************************************************************
355 ******************************************************************/
357 bool smbd_vfs_init(connection_struct
*conn
)
359 const char **vfs_objects
;
363 /* Normal share - initialise with disk access functions */
364 vfs_init_default(conn
);
366 /* No need to load vfs modules for printer connections */
371 if (lp_widelinks(SNUM(conn
))) {
373 * As the widelinks logic is now moving into a
374 * vfs_widelinks module, we need to custom load
375 * it after the default module is initialized.
376 * That way no changes to smb.conf files are
379 bool ok
= vfs_init_custom(conn
, "widelinks");
381 DBG_ERR("widelinks enabled and vfs_init_custom "
382 "failed for vfs_widelinks module\n");
387 vfs_objects
= lp_vfs_objects(SNUM(conn
));
389 /* Override VFS functions if 'vfs object' was not specified*/
390 if (!vfs_objects
|| !vfs_objects
[0])
393 for (i
=0; vfs_objects
[i
] ;) {
397 for (j
=i
-1; j
>= 0; j
--) {
398 if (!vfs_init_custom(conn
, vfs_objects
[j
])) {
399 DEBUG(0, ("smbd_vfs_init: vfs_init_custom failed for %s\n", vfs_objects
[j
]));
406 /*******************************************************************
407 Check if a file exists in the vfs.
408 ********************************************************************/
410 NTSTATUS
vfs_file_exist(connection_struct
*conn
, struct smb_filename
*smb_fname
)
412 /* Only return OK if stat was successful and S_ISREG */
413 if ((SMB_VFS_STAT(conn
, smb_fname
) != -1) &&
414 S_ISREG(smb_fname
->st
.st_ex_mode
)) {
418 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
421 bool vfs_valid_pread_range(off_t offset
, size_t length
)
423 return sys_valid_io_range(offset
, length
);
426 bool vfs_valid_pwrite_range(off_t offset
, size_t length
)
429 * See MAXFILESIZE in [MS-FSA] 2.1.5.3 Server Requests a Write
431 static const uint64_t maxfilesize
= 0xfffffff0000;
432 uint64_t last_byte_ofs
;
435 ok
= sys_valid_io_range(offset
, length
);
444 last_byte_ofs
= offset
+ length
;
445 if (last_byte_ofs
> maxfilesize
) {
452 ssize_t
vfs_pwrite_data(struct smb_request
*req
,
462 ok
= vfs_valid_pwrite_range(offset
, N
);
468 if (req
&& req
->unread_bytes
) {
469 int sockfd
= req
->xconn
->transport
.sock
;
470 SMB_ASSERT(req
->unread_bytes
== N
);
471 /* VFS_RECVFILE must drain the socket
472 * before returning. */
473 req
->unread_bytes
= 0;
475 * Leave the socket non-blocking and
476 * use SMB_VFS_RECVFILE. If it returns
477 * EAGAIN || EWOULDBLOCK temporarily set
478 * the socket blocking and retry
482 ret
= SMB_VFS_RECVFILE(sockfd
,
486 if (ret
== 0 || (ret
== -1 &&
488 errno
== EWOULDBLOCK
))) {
490 /* Ensure the socket is blocking. */
491 old_flags
= fcntl(sockfd
, F_GETFL
, 0);
492 if (set_blocking(sockfd
, true) == -1) {
495 ret
= SMB_VFS_RECVFILE(sockfd
,
499 if (fcntl(sockfd
, F_SETFL
, old_flags
) == -1) {
506 return (ssize_t
)total
;
508 /* Any other error case. */
514 return (ssize_t
)total
;
518 ret
= SMB_VFS_PWRITE(fsp
, buffer
+ total
, N
- total
,
528 return (ssize_t
)total
;
530 /****************************************************************************
531 An allocate file space call using the vfs interface.
532 Allocates space for a file from a filedescriptor.
533 Returns 0 on success, -1 on failure.
534 ****************************************************************************/
536 int vfs_allocate_file_space(files_struct
*fsp
, uint64_t len
)
539 connection_struct
*conn
= fsp
->conn
;
540 uint64_t space_avail
;
541 uint64_t bsize
,dfree
,dsize
;
546 * Actually try and commit the space on disk....
549 DEBUG(10,("vfs_allocate_file_space: file %s, len %.0f\n",
550 fsp_str_dbg(fsp
), (double)len
));
552 ok
= vfs_valid_pwrite_range((off_t
)len
, 0);
554 DEBUG(0,("vfs_allocate_file_space: %s negative/invalid len "
555 "requested.\n", fsp_str_dbg(fsp
)));
560 status
= vfs_stat_fsp(fsp
);
561 if (!NT_STATUS_IS_OK(status
)) {
565 if (len
== (uint64_t)fsp
->fsp_name
->st
.st_ex_size
)
568 if (len
< (uint64_t)fsp
->fsp_name
->st
.st_ex_size
) {
569 /* Shrink - use ftruncate. */
571 DEBUG(10,("vfs_allocate_file_space: file %s, shrink. Current "
572 "size %.0f\n", fsp_str_dbg(fsp
),
573 (double)fsp
->fsp_name
->st
.st_ex_size
));
575 contend_level2_oplocks_begin(fsp
, LEVEL2_CONTEND_ALLOC_SHRINK
);
577 ret
= SMB_VFS_FTRUNCATE(fsp
, (off_t
)len
);
579 contend_level2_oplocks_end(fsp
, LEVEL2_CONTEND_ALLOC_SHRINK
);
584 /* Grow - we need to test if we have enough space. */
586 contend_level2_oplocks_begin(fsp
, LEVEL2_CONTEND_ALLOC_GROW
);
588 if (lp_strict_allocate(SNUM(fsp
->conn
))) {
589 /* See if we have a syscall that will allocate beyond
590 end-of-file without changing EOF. */
591 ret
= SMB_VFS_FALLOCATE(fsp
, VFS_FALLOCATE_FL_KEEP_SIZE
,
597 contend_level2_oplocks_end(fsp
, LEVEL2_CONTEND_ALLOC_GROW
);
600 /* We changed the allocation size on disk, but not
601 EOF - exactly as required. We're done ! */
605 if (ret
== -1 && errno
== ENOSPC
) {
609 len
-= fsp
->fsp_name
->st
.st_ex_size
;
610 len
/= 1024; /* Len is now number of 1k blocks needed. */
612 get_dfree_info(conn
, fsp
->fsp_name
, &bsize
, &dfree
, &dsize
);
613 if (space_avail
== (uint64_t)-1) {
617 DEBUG(10,("vfs_allocate_file_space: file %s, grow. Current size %.0f, "
618 "needed blocks = %.0f, space avail = %.0f\n",
619 fsp_str_dbg(fsp
), (double)fsp
->fsp_name
->st
.st_ex_size
, (double)len
,
620 (double)space_avail
));
622 if (len
> space_avail
) {
630 /****************************************************************************
631 A vfs set_filelen call.
632 set the length of a file from a filedescriptor.
633 Returns 0 on success, -1 on failure.
634 ****************************************************************************/
636 int vfs_set_filelen(files_struct
*fsp
, off_t len
)
641 ok
= vfs_valid_pwrite_range(len
, 0);
647 contend_level2_oplocks_begin(fsp
, LEVEL2_CONTEND_SET_FILE_LEN
);
649 DEBUG(10,("vfs_set_filelen: ftruncate %s to len %.0f\n",
650 fsp_str_dbg(fsp
), (double)len
));
651 if ((ret
= SMB_VFS_FTRUNCATE(fsp
, len
)) != -1) {
652 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
653 FILE_NOTIFY_CHANGE_SIZE
654 | FILE_NOTIFY_CHANGE_ATTRIBUTES
,
655 fsp
->fsp_name
->base_name
);
658 contend_level2_oplocks_end(fsp
, LEVEL2_CONTEND_SET_FILE_LEN
);
663 /****************************************************************************
664 A slow version of fallocate. Fallback code if SMB_VFS_FALLOCATE
665 fails. Needs to be outside of the default version of SMB_VFS_FALLOCATE
666 as this is also called from the default SMB_VFS_FTRUNCATE code.
667 Always extends the file size.
668 Returns 0 on success, -1 on failure.
669 ****************************************************************************/
671 #define SPARSE_BUF_WRITE_SIZE (32*1024)
673 int vfs_slow_fallocate(files_struct
*fsp
, off_t offset
, off_t len
)
679 ok
= vfs_valid_pwrite_range(offset
, len
);
686 sparse_buf
= SMB_CALLOC_ARRAY(char, SPARSE_BUF_WRITE_SIZE
);
693 while (total
< len
) {
694 size_t curr_write_size
= MIN(SPARSE_BUF_WRITE_SIZE
, (len
- total
));
696 pwrite_ret
= SMB_VFS_PWRITE(fsp
, sparse_buf
, curr_write_size
, offset
+ total
);
697 if (pwrite_ret
== -1) {
698 int saved_errno
= errno
;
699 DEBUG(10,("vfs_slow_fallocate: SMB_VFS_PWRITE for file "
700 "%s failed with error %s\n",
701 fsp_str_dbg(fsp
), strerror(saved_errno
)));
711 /****************************************************************************
712 A vfs fill sparse call.
713 Writes zeros from the end of file to len, if len is greater than EOF.
714 Used only by strict_sync.
715 Returns 0 on success, -1 on failure.
716 ****************************************************************************/
718 int vfs_fill_sparse(files_struct
*fsp
, off_t len
)
726 ok
= vfs_valid_pwrite_range(len
, 0);
732 status
= vfs_stat_fsp(fsp
);
733 if (!NT_STATUS_IS_OK(status
)) {
737 if (len
<= fsp
->fsp_name
->st
.st_ex_size
) {
742 if (S_ISFIFO(fsp
->fsp_name
->st
.st_ex_mode
)) {
747 DEBUG(10,("vfs_fill_sparse: write zeros in file %s from len %.0f to "
748 "len %.0f (%.0f bytes)\n", fsp_str_dbg(fsp
),
749 (double)fsp
->fsp_name
->st
.st_ex_size
, (double)len
,
750 (double)(len
- fsp
->fsp_name
->st
.st_ex_size
)));
752 contend_level2_oplocks_begin(fsp
, LEVEL2_CONTEND_FILL_SPARSE
);
754 offset
= fsp
->fsp_name
->st
.st_ex_size
;
755 num_to_write
= len
- fsp
->fsp_name
->st
.st_ex_size
;
757 /* Only do this on non-stream file handles. */
758 if (!fsp_is_alternate_stream(fsp
)) {
759 /* for allocation try fallocate first. This can fail on some
760 * platforms e.g. when the filesystem doesn't support it and no
761 * emulation is being done by the libc (like on AIX with JFS1). In that
762 * case we do our own emulation. fallocate implementations can
763 * return ENOTSUP or EINVAL in cases like that. */
764 ret
= SMB_VFS_FALLOCATE(fsp
, 0, offset
, num_to_write
);
765 if (ret
== -1 && errno
== ENOSPC
) {
771 DEBUG(10,("vfs_fill_sparse: SMB_VFS_FALLOCATE failed with "
772 "error %d. Falling back to slow manual allocation\n", ret
));
775 ret
= vfs_slow_fallocate(fsp
, offset
, num_to_write
);
779 contend_level2_oplocks_end(fsp
, LEVEL2_CONTEND_FILL_SPARSE
);
783 /*******************************************************************************
784 Set a fd into blocking/nonblocking mode through VFS
785 *******************************************************************************/
787 int vfs_set_blocking(files_struct
*fsp
, bool set
)
791 #define FLAG_TO_SET O_NONBLOCK
794 #define FLAG_TO_SET O_NDELAY
796 #define FLAG_TO_SET FNDELAY
800 if (fsp
->fsp_flags
.is_pathref
) {
804 val
= SMB_VFS_FCNTL(fsp
, F_GETFL
, 0);
815 return SMB_VFS_FCNTL(fsp
, F_SETFL
, val
);
819 /****************************************************************************
820 Transfer some data (n bytes) between two file_struct's.
821 ****************************************************************************/
823 static ssize_t
vfs_pread_fn(void *file
, void *buf
, size_t len
, off_t offset
)
825 struct files_struct
*fsp
= (struct files_struct
*)file
;
827 return SMB_VFS_PREAD(fsp
, buf
, len
, offset
);
830 static ssize_t
vfs_pwrite_fn(void *file
, const void *buf
, size_t len
, off_t offset
)
832 struct files_struct
*fsp
= (struct files_struct
*)file
;
834 return SMB_VFS_PWRITE(fsp
, buf
, len
, offset
);
837 off_t
vfs_transfer_file(files_struct
*in
, files_struct
*out
, off_t n
)
839 return transfer_file_internal((void *)in
, (void *)out
, n
,
840 vfs_pread_fn
, vfs_pwrite_fn
);
843 /*******************************************************************
844 A vfs_readdir wrapper which just returns the file name.
845 ********************************************************************/
847 const char *vfs_readdirname(connection_struct
*conn
,
848 struct files_struct
*dirfsp
,
852 struct dirent
*ptr
= NULL
;
860 ptr
= SMB_VFS_READDIR(conn
, dirfsp
, (DIR *)p
);
866 status
= SMB_VFS_TRANSLATE_NAME(conn
, dname
, vfs_translate_to_windows
,
867 talloc_tos(), &translated
);
868 if (NT_STATUS_EQUAL(status
, NT_STATUS_NONE_MAPPED
)) {
872 *talloced
= translated
;
873 if (!NT_STATUS_IS_OK(status
)) {
879 /*******************************************************************
880 A wrapper for vfs_chdir().
881 ********************************************************************/
883 int vfs_ChDir(connection_struct
*conn
, const struct smb_filename
*smb_fname
)
886 struct smb_filename
*cwd
= NULL
;
889 LastDir
= SMB_STRDUP("");
892 if (ISDOT(smb_fname
->base_name
)) {
894 * passing a '.' is a noop,
895 * and we only expect this after
896 * everything is initialized.
898 * So the first vfs_ChDir() on a given
899 * connection_struct must not be '.'.
901 * Note: conn_new() sets
902 * conn->cwd_fsp->fh->fd = -1
903 * and vfs_ChDir() leaves with
904 * conn->cwd_fsp->fh->fd = AT_FDCWD
907 if (fsp_get_pathref_fd(conn
->cwd_fsp
) != AT_FDCWD
) {
909 * This should never happen and
910 * we might change this to
911 * SMB_ASSERT() in future.
913 DBG_ERR("Called with '.' as first operation!\n");
921 if (smb_fname
->base_name
[0] == '/' &&
922 strcsequal(LastDir
,smb_fname
->base_name
))
925 * conn->cwd_fsp->fsp_name and the kernel
926 * are already correct, but conn->cwd_fsp->fh->fd
927 * might still be -1 as initialized in conn_new().
929 * This can happen when a client made a 2nd
930 * tree connect to a share with the same underlying
931 * path (may or may not the same share).
933 fsp_set_fd(conn
->cwd_fsp
, AT_FDCWD
);
937 DEBUG(4,("vfs_ChDir to %s\n", smb_fname
->base_name
));
939 ret
= SMB_VFS_CHDIR(conn
, smb_fname
);
945 * Always replace conn->cwd_fsp. We
946 * don't know if it's been modified by
947 * VFS modules in the stack.
949 fsp_set_fd(conn
->cwd_fsp
, AT_FDCWD
);
952 cwd
= vfs_GetWd(conn
, conn
);
955 * vfs_GetWd() failed.
956 * We must be able to read cwd.
957 * Return to original directory
960 int saved_errno
= errno
;
962 if (conn
->cwd_fsp
->fsp_name
== NULL
) {
964 * Failed on the very first chdir()+getwd()
965 * for this connection. We can't
968 smb_panic("conn->cwd getwd failed\n");
973 /* Return to the previous $cwd. */
974 ret
= SMB_VFS_CHDIR(conn
, conn
->cwd_fsp
->fsp_name
);
976 smb_panic("conn->cwd getwd failed\n");
981 /* And fail the chdir(). */
985 /* vfs_GetWd() succeeded. */
986 /* Replace global cache. */
988 LastDir
= SMB_STRDUP(smb_fname
->base_name
);
991 * (Indirect) Callers of vfs_ChDir() may still hold references to the
992 * old conn->cwd_fsp->fsp_name. Move it to talloc_tos(), that way
993 * callers can use it for the lifetime of the SMB request.
995 talloc_move(talloc_tos(), &conn
->cwd_fsp
->fsp_name
);
997 conn
->cwd_fsp
->fsp_name
= talloc_move(conn
->cwd_fsp
, &cwd
);
999 DBG_INFO("vfs_ChDir got %s\n", fsp_str_dbg(conn
->cwd_fsp
));
1004 /*******************************************************************
1005 Return the absolute current directory path - given a UNIX pathname.
1006 Note that this path is returned in DOS format, not UNIX
1007 format. Note this can be called with conn == NULL.
1008 ********************************************************************/
1010 struct smb_filename
*vfs_GetWd(TALLOC_CTX
*ctx
, connection_struct
*conn
)
1012 struct smb_filename
*current_dir_fname
= NULL
;
1014 struct smb_filename
*smb_fname_dot
= NULL
;
1015 struct smb_filename
*smb_fname_full
= NULL
;
1016 struct smb_filename
*result
= NULL
;
1018 if (!lp_getwd_cache()) {
1022 smb_fname_dot
= synthetic_smb_fname(ctx
,
1028 if (smb_fname_dot
== NULL
) {
1033 if (SMB_VFS_STAT(conn
, smb_fname_dot
) == -1) {
1035 * Known to fail for root: the directory may be NFS-mounted
1036 * and exported with root_squash (so has no root access).
1038 DEBUG(1,("vfs_GetWd: couldn't stat \".\" error %s "
1039 "(NFS problem ?)\n", strerror(errno
) ));
1043 key
= vfs_file_id_from_sbuf(conn
, &smb_fname_dot
->st
);
1045 smb_fname_full
= (struct smb_filename
*)memcache_lookup_talloc(
1048 data_blob_const(&key
, sizeof(key
)));
1050 if (smb_fname_full
== NULL
) {
1054 if ((SMB_VFS_STAT(conn
, smb_fname_full
) == 0) &&
1055 (smb_fname_dot
->st
.st_ex_dev
== smb_fname_full
->st
.st_ex_dev
) &&
1056 (smb_fname_dot
->st
.st_ex_ino
== smb_fname_full
->st
.st_ex_ino
) &&
1057 (S_ISDIR(smb_fname_dot
->st
.st_ex_mode
))) {
1060 * Note: smb_fname_full is owned by smbd_memcache()
1061 * so we must make a copy to return.
1063 result
= cp_smb_filename(ctx
, smb_fname_full
);
1064 if (result
== NULL
) {
1073 * We don't have the information to hand so rely on traditional
1074 * methods. The very slow getcwd, which spawns a process on some
1075 * systems, or the not quite so bad getwd.
1078 current_dir_fname
= SMB_VFS_GETWD(conn
, ctx
);
1079 if (current_dir_fname
== NULL
) {
1080 DEBUG(0, ("vfs_GetWd: SMB_VFS_GETWD call failed: %s\n",
1085 if (lp_getwd_cache() && VALID_STAT(smb_fname_dot
->st
)) {
1086 key
= vfs_file_id_from_sbuf(conn
, &smb_fname_dot
->st
);
1089 * smbd_memcache() will own current_dir_fname after the
1090 * memcache_add_talloc call, so we must make
1091 * a copy on ctx to return.
1093 result
= cp_smb_filename(ctx
, current_dir_fname
);
1094 if (result
== NULL
) {
1099 * Ensure the memory going into the cache
1100 * doesn't have a destructor so it can be
1103 talloc_set_destructor(current_dir_fname
, NULL
);
1105 memcache_add_talloc(smbd_memcache(),
1107 data_blob_const(&key
, sizeof(key
)),
1108 ¤t_dir_fname
);
1109 /* current_dir_fname is now == NULL here. */
1111 /* current_dir_fname is already allocated on ctx. */
1112 result
= current_dir_fname
;
1116 TALLOC_FREE(smb_fname_dot
);
1118 * Don't free current_dir_fname here. It's either been moved
1119 * to the memcache or is being returned in result.
1125 * Ensure LSTAT is called for POSIX paths.
1127 int vfs_stat(struct connection_struct
*conn
,
1128 struct smb_filename
*smb_fname
)
1130 if (smb_fname
->flags
& SMB_FILENAME_POSIX_PATH
) {
1131 return SMB_VFS_LSTAT(conn
, smb_fname
);
1133 return SMB_VFS_STAT(conn
, smb_fname
);
1137 * XXX: This is temporary and there should be no callers of this once
1138 * smb_filename is plumbed through all path based operations.
1140 * Called when we know stream name parsing has already been done.
1142 int vfs_stat_smb_basename(struct connection_struct
*conn
,
1143 const struct smb_filename
*smb_fname_in
,
1144 SMB_STRUCT_STAT
*psbuf
)
1146 struct smb_filename smb_fname
= {
1147 .base_name
= discard_const_p(char, smb_fname_in
->base_name
),
1148 .flags
= smb_fname_in
->flags
,
1149 .twrp
= smb_fname_in
->twrp
,
1153 ret
= vfs_stat(conn
, &smb_fname
);
1155 *psbuf
= smb_fname
.st
;
1161 * Ensure LSTAT is called for POSIX paths.
1164 NTSTATUS
vfs_stat_fsp(files_struct
*fsp
)
1167 struct stat_ex saved_stat
= fsp
->fsp_name
->st
;
1169 if (fsp_get_pathref_fd(fsp
) == -1) {
1170 if (fsp
->posix_flags
& FSP_POSIX_FLAGS_OPEN
) {
1171 ret
= SMB_VFS_LSTAT(fsp
->conn
, fsp
->fsp_name
);
1173 ret
= SMB_VFS_STAT(fsp
->conn
, fsp
->fsp_name
);
1176 ret
= SMB_VFS_FSTAT(fsp
, &fsp
->fsp_name
->st
);
1179 return map_nt_error_from_unix(errno
);
1181 update_stat_ex_from_saved_stat(&fsp
->fsp_name
->st
, &saved_stat
);
1182 fsp
->fsp_flags
.is_directory
= S_ISDIR(fsp
->fsp_name
->st
.st_ex_mode
);
1183 return NT_STATUS_OK
;
1186 void init_smb_file_time(struct smb_file_time
*ft
)
1188 *ft
= (struct smb_file_time
) {
1189 .atime
= make_omit_timespec(),
1190 .ctime
= make_omit_timespec(),
1191 .mtime
= make_omit_timespec(),
1192 .create_time
= make_omit_timespec()
1197 * Initialize num_streams and streams, then call VFS op streaminfo
1200 NTSTATUS
vfs_fstreaminfo(struct files_struct
*fsp
,
1201 TALLOC_CTX
*mem_ctx
,
1202 unsigned int *num_streams
,
1203 struct stream_struct
**streams
)
1210 * Callers may pass fsp == NULL when passing smb_fname->fsp of a
1211 * symlink. This is ok, handle it here, by just return no
1212 * streams on a symlink.
1214 return NT_STATUS_OK
;
1217 if (fsp_get_pathref_fd(fsp
) == -1) {
1219 * No streams on non-real files/directories.
1221 return NT_STATUS_OK
;
1224 return SMB_VFS_FSTREAMINFO(fsp
,
1230 int vfs_fake_fd(void)
1236 * Return a valid fd, but ensure any attempt to use
1237 * it returns an error (EPIPE).
1239 ret
= pipe(pipe_fds
);
1249 * This is just a helper to make
1250 * users of vfs_fake_fd() more symmetric
1252 int vfs_fake_fd_close(int fd
)
1258 generate a file_id from a stat structure
1260 struct file_id
vfs_file_id_from_sbuf(connection_struct
*conn
, const SMB_STRUCT_STAT
*sbuf
)
1262 return SMB_VFS_FILE_ID_CREATE(conn
, sbuf
);
1265 NTSTATUS
vfs_at_fspcwd(TALLOC_CTX
*mem_ctx
,
1266 struct connection_struct
*conn
,
1267 struct files_struct
**_fsp
)
1269 struct files_struct
*fsp
= NULL
;
1271 fsp
= talloc_zero(mem_ctx
, struct files_struct
);
1273 return NT_STATUS_NO_MEMORY
;
1276 fsp
->fsp_name
= synthetic_smb_fname(fsp
, ".", NULL
, NULL
, 0, 0);
1277 if (fsp
->fsp_name
== NULL
) {
1279 return NT_STATUS_NO_MEMORY
;
1282 fsp
->fh
= fd_handle_create(fsp
);
1283 if (fsp
->fh
== NULL
) {
1285 return NT_STATUS_NO_MEMORY
;
1288 fsp_set_fd(fsp
, AT_FDCWD
);
1289 fsp
->fnum
= FNUM_FIELD_INVALID
;
1293 return NT_STATUS_OK
;
1296 NTSTATUS
vfs_fget_dos_attributes(struct files_struct
*fsp
,
1302 * First make sure to pass the base_fsp to the VFS
1304 status
= SMB_VFS_FGET_DOS_ATTRIBUTES(
1305 fsp
->conn
, metadata_fsp(fsp
), dosmode
);
1306 if (!NT_STATUS_IS_OK(status
)) {
1311 * If this isn't a stream fsp we're done, ...
1313 if (!fsp_is_alternate_stream(fsp
)) {
1314 return NT_STATUS_OK
;
1318 * ...otherwise the VFS might have updated the btime, propagate the
1319 * btime from the base_fsp to the stream fsp.
1322 if (fsp
->base_fsp
->fsp_name
->st
.st_ex_iflags
& ST_EX_IFLAG_CALCULATED_BTIME
) {
1324 * Not a value from backend storage, ignore it
1326 return NT_STATUS_OK
;
1329 update_stat_ex_create_time(&fsp
->fsp_name
->st
,
1330 fsp
->base_fsp
->fsp_name
->st
.st_ex_btime
);
1332 return NT_STATUS_OK
;
1335 static struct smb_vfs_deny_state
*smb_vfs_deny_global
;
1337 void smb_vfs_assert_allowed(void)
1339 if (unlikely(smb_vfs_deny_global
!= NULL
)) {
1340 DBG_ERR("Called with VFS denied by %s\n",
1341 smb_vfs_deny_global
->location
);
1342 smb_panic("Called with VFS denied!");
1346 void _smb_vfs_deny_push(struct smb_vfs_deny_state
*state
, const char *location
)
1348 SMB_ASSERT(smb_vfs_deny_global
!= state
);
1350 *state
= (struct smb_vfs_deny_state
) {
1351 .parent
= smb_vfs_deny_global
,
1352 .location
= location
,
1355 smb_vfs_deny_global
= state
;
1358 void _smb_vfs_deny_pop(struct smb_vfs_deny_state
*state
, const char *location
)
1360 SMB_ASSERT(smb_vfs_deny_global
== state
);
1362 smb_vfs_deny_global
= state
->parent
;
1364 *state
= (struct smb_vfs_deny_state
) { .parent
= NULL
, };
1367 #define VFS_FIND(__fn__) do { \
1368 if (unlikely(smb_vfs_deny_global != NULL)) { \
1369 DBG_ERR("Called with VFS denied by %s\n", \
1370 smb_vfs_deny_global->location); \
1371 smb_panic("Called with VFS denied!"); \
1373 while (handle->fns->__fn__##_fn==NULL) { \
1374 handle = handle->next; \
1378 int smb_vfs_call_connect(struct vfs_handle_struct
*handle
,
1379 const char *service
, const char *user
)
1382 return handle
->fns
->connect_fn(handle
, service
, user
);
1385 void smb_vfs_call_disconnect(struct vfs_handle_struct
*handle
)
1387 VFS_FIND(disconnect
);
1388 handle
->fns
->disconnect_fn(handle
);
1391 uint64_t smb_vfs_call_disk_free(struct vfs_handle_struct
*handle
,
1392 const struct smb_filename
*smb_fname
,
1397 VFS_FIND(disk_free
);
1398 return handle
->fns
->disk_free_fn(handle
, smb_fname
,
1399 bsize
, dfree
, dsize
);
1402 int smb_vfs_call_get_quota(struct vfs_handle_struct
*handle
,
1403 const struct smb_filename
*smb_fname
,
1404 enum SMB_QUOTA_TYPE qtype
,
1408 VFS_FIND(get_quota
);
1409 return handle
->fns
->get_quota_fn(handle
, smb_fname
, qtype
, id
, qt
);
1412 int smb_vfs_call_set_quota(struct vfs_handle_struct
*handle
,
1413 enum SMB_QUOTA_TYPE qtype
, unid_t id
,
1416 VFS_FIND(set_quota
);
1417 return handle
->fns
->set_quota_fn(handle
, qtype
, id
, qt
);
1420 int smb_vfs_call_get_shadow_copy_data(struct vfs_handle_struct
*handle
,
1421 struct files_struct
*fsp
,
1422 struct shadow_copy_data
*shadow_copy_data
,
1425 VFS_FIND(get_shadow_copy_data
);
1426 return handle
->fns
->get_shadow_copy_data_fn(handle
, fsp
,
1430 int smb_vfs_call_statvfs(struct vfs_handle_struct
*handle
,
1431 const struct smb_filename
*smb_fname
,
1432 struct vfs_statvfs_struct
*statbuf
)
1435 return handle
->fns
->statvfs_fn(handle
, smb_fname
, statbuf
);
1438 uint32_t smb_vfs_call_fs_capabilities(struct vfs_handle_struct
*handle
,
1439 enum timestamp_set_resolution
*p_ts_res
)
1441 VFS_FIND(fs_capabilities
);
1442 return handle
->fns
->fs_capabilities_fn(handle
, p_ts_res
);
1445 NTSTATUS
smb_vfs_call_get_dfs_referrals(struct vfs_handle_struct
*handle
,
1446 struct dfs_GetDFSReferral
*r
)
1448 VFS_FIND(get_dfs_referrals
);
1449 return handle
->fns
->get_dfs_referrals_fn(handle
, r
);
1452 NTSTATUS
smb_vfs_call_create_dfs_pathat(struct vfs_handle_struct
*handle
,
1453 struct files_struct
*dirfsp
,
1454 const struct smb_filename
*smb_fname
,
1455 const struct referral
*reflist
,
1456 size_t referral_count
)
1458 VFS_FIND(create_dfs_pathat
);
1459 return handle
->fns
->create_dfs_pathat_fn(handle
,
1466 NTSTATUS
smb_vfs_call_read_dfs_pathat(struct vfs_handle_struct
*handle
,
1467 TALLOC_CTX
*mem_ctx
,
1468 struct files_struct
*dirfsp
,
1469 struct smb_filename
*smb_fname
,
1470 struct referral
**ppreflist
,
1471 size_t *preferral_count
)
1473 VFS_FIND(read_dfs_pathat
);
1474 return handle
->fns
->read_dfs_pathat_fn(handle
,
1482 DIR *smb_vfs_call_fdopendir(struct vfs_handle_struct
*handle
,
1483 struct files_struct
*fsp
,
1485 uint32_t attributes
)
1487 VFS_FIND(fdopendir
);
1488 return handle
->fns
->fdopendir_fn(handle
, fsp
, mask
, attributes
);
1491 struct dirent
*smb_vfs_call_readdir(struct vfs_handle_struct
*handle
,
1492 struct files_struct
*dirfsp
,
1496 return handle
->fns
->readdir_fn(handle
, dirfsp
, dirp
);
1499 void smb_vfs_call_rewind_dir(struct vfs_handle_struct
*handle
,
1502 VFS_FIND(rewind_dir
);
1503 handle
->fns
->rewind_dir_fn(handle
, dirp
);
1506 int smb_vfs_call_mkdirat(struct vfs_handle_struct
*handle
,
1507 struct files_struct
*dirfsp
,
1508 const struct smb_filename
*smb_fname
,
1512 return handle
->fns
->mkdirat_fn(handle
,
1518 int smb_vfs_call_closedir(struct vfs_handle_struct
*handle
,
1522 return handle
->fns
->closedir_fn(handle
, dir
);
1525 int smb_vfs_call_openat(struct vfs_handle_struct
*handle
,
1526 const struct files_struct
*dirfsp
,
1527 const struct smb_filename
*smb_fname
,
1528 struct files_struct
*fsp
,
1529 const struct vfs_open_how
*how
)
1532 return handle
->fns
->openat_fn(handle
,
1539 NTSTATUS
smb_vfs_call_create_file(struct vfs_handle_struct
*handle
,
1540 struct smb_request
*req
,
1541 struct files_struct
*dirfsp
,
1542 struct smb_filename
*smb_fname
,
1543 uint32_t access_mask
,
1544 uint32_t share_access
,
1545 uint32_t create_disposition
,
1546 uint32_t create_options
,
1547 uint32_t file_attributes
,
1548 uint32_t oplock_request
,
1549 const struct smb2_lease
*lease
,
1550 uint64_t allocation_size
,
1551 uint32_t private_flags
,
1552 struct security_descriptor
*sd
,
1553 struct ea_list
*ea_list
,
1554 files_struct
**result
,
1556 const struct smb2_create_blobs
*in_context_blobs
,
1557 struct smb2_create_blobs
*out_context_blobs
)
1559 VFS_FIND(create_file
);
1560 return handle
->fns
->create_file_fn(
1561 handle
, req
, dirfsp
, smb_fname
,
1562 access_mask
, share_access
, create_disposition
, create_options
,
1563 file_attributes
, oplock_request
, lease
, allocation_size
,
1564 private_flags
, sd
, ea_list
,
1565 result
, pinfo
, in_context_blobs
, out_context_blobs
);
1568 int smb_vfs_call_close(struct vfs_handle_struct
*handle
,
1569 struct files_struct
*fsp
)
1572 return handle
->fns
->close_fn(handle
, fsp
);
1575 ssize_t
smb_vfs_call_pread(struct vfs_handle_struct
*handle
,
1576 struct files_struct
*fsp
, void *data
, size_t n
,
1580 return handle
->fns
->pread_fn(handle
, fsp
, data
, n
, offset
);
1583 struct smb_vfs_call_pread_state
{
1584 ssize_t (*recv_fn
)(struct tevent_req
*req
, struct vfs_aio_state
*vfs_aio_state
);
1586 struct vfs_aio_state vfs_aio_state
;
1589 static void smb_vfs_call_pread_done(struct tevent_req
*subreq
);
1591 struct tevent_req
*smb_vfs_call_pread_send(struct vfs_handle_struct
*handle
,
1592 TALLOC_CTX
*mem_ctx
,
1593 struct tevent_context
*ev
,
1594 struct files_struct
*fsp
,
1596 size_t n
, off_t offset
)
1598 struct tevent_req
*req
, *subreq
;
1599 struct smb_vfs_call_pread_state
*state
;
1601 req
= tevent_req_create(mem_ctx
, &state
,
1602 struct smb_vfs_call_pread_state
);
1606 VFS_FIND(pread_send
);
1607 state
->recv_fn
= handle
->fns
->pread_recv_fn
;
1609 subreq
= handle
->fns
->pread_send_fn(handle
, state
, ev
, fsp
, data
, n
,
1611 if (tevent_req_nomem(subreq
, req
)) {
1612 return tevent_req_post(req
, ev
);
1614 tevent_req_set_callback(subreq
, smb_vfs_call_pread_done
, req
);
1618 static void smb_vfs_call_pread_done(struct tevent_req
*subreq
)
1620 struct tevent_req
*req
= tevent_req_callback_data(
1621 subreq
, struct tevent_req
);
1622 struct smb_vfs_call_pread_state
*state
= tevent_req_data(
1623 req
, struct smb_vfs_call_pread_state
);
1625 state
->retval
= state
->recv_fn(subreq
, &state
->vfs_aio_state
);
1626 TALLOC_FREE(subreq
);
1627 if (state
->retval
== -1) {
1628 tevent_req_error(req
, state
->vfs_aio_state
.error
);
1631 tevent_req_done(req
);
1634 ssize_t
SMB_VFS_PREAD_RECV(struct tevent_req
*req
,
1635 struct vfs_aio_state
*vfs_aio_state
)
1637 struct smb_vfs_call_pread_state
*state
= tevent_req_data(
1638 req
, struct smb_vfs_call_pread_state
);
1641 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
1642 tevent_req_received(req
);
1645 *vfs_aio_state
= state
->vfs_aio_state
;
1646 retval
= state
->retval
;
1647 tevent_req_received(req
);
1651 ssize_t
smb_vfs_call_pwrite(struct vfs_handle_struct
*handle
,
1652 struct files_struct
*fsp
, const void *data
,
1653 size_t n
, off_t offset
)
1656 return handle
->fns
->pwrite_fn(handle
, fsp
, data
, n
, offset
);
1659 struct smb_vfs_call_pwrite_state
{
1660 ssize_t (*recv_fn
)(struct tevent_req
*req
, struct vfs_aio_state
*vfs_aio_state
);
1662 struct vfs_aio_state vfs_aio_state
;
1665 static void smb_vfs_call_pwrite_done(struct tevent_req
*subreq
);
1667 struct tevent_req
*smb_vfs_call_pwrite_send(struct vfs_handle_struct
*handle
,
1668 TALLOC_CTX
*mem_ctx
,
1669 struct tevent_context
*ev
,
1670 struct files_struct
*fsp
,
1672 size_t n
, off_t offset
)
1674 struct tevent_req
*req
, *subreq
;
1675 struct smb_vfs_call_pwrite_state
*state
;
1677 req
= tevent_req_create(mem_ctx
, &state
,
1678 struct smb_vfs_call_pwrite_state
);
1682 VFS_FIND(pwrite_send
);
1683 state
->recv_fn
= handle
->fns
->pwrite_recv_fn
;
1685 subreq
= handle
->fns
->pwrite_send_fn(handle
, state
, ev
, fsp
, data
, n
,
1687 if (tevent_req_nomem(subreq
, req
)) {
1688 return tevent_req_post(req
, ev
);
1690 tevent_req_set_callback(subreq
, smb_vfs_call_pwrite_done
, req
);
1694 static void smb_vfs_call_pwrite_done(struct tevent_req
*subreq
)
1696 struct tevent_req
*req
= tevent_req_callback_data(
1697 subreq
, struct tevent_req
);
1698 struct smb_vfs_call_pwrite_state
*state
= tevent_req_data(
1699 req
, struct smb_vfs_call_pwrite_state
);
1701 state
->retval
= state
->recv_fn(subreq
, &state
->vfs_aio_state
);
1702 TALLOC_FREE(subreq
);
1703 if (state
->retval
== -1) {
1704 tevent_req_error(req
, state
->vfs_aio_state
.error
);
1707 tevent_req_done(req
);
1710 ssize_t
SMB_VFS_PWRITE_RECV(struct tevent_req
*req
,
1711 struct vfs_aio_state
*vfs_aio_state
)
1713 struct smb_vfs_call_pwrite_state
*state
= tevent_req_data(
1714 req
, struct smb_vfs_call_pwrite_state
);
1717 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
1718 tevent_req_received(req
);
1721 *vfs_aio_state
= state
->vfs_aio_state
;
1722 retval
= state
->retval
;
1723 tevent_req_received(req
);
1727 off_t
smb_vfs_call_lseek(struct vfs_handle_struct
*handle
,
1728 struct files_struct
*fsp
, off_t offset
,
1732 return handle
->fns
->lseek_fn(handle
, fsp
, offset
, whence
);
1735 ssize_t
smb_vfs_call_sendfile(struct vfs_handle_struct
*handle
, int tofd
,
1736 files_struct
*fromfsp
, const DATA_BLOB
*header
,
1737 off_t offset
, size_t count
)
1740 return handle
->fns
->sendfile_fn(handle
, tofd
, fromfsp
, header
, offset
,
1744 ssize_t
smb_vfs_call_recvfile(struct vfs_handle_struct
*handle
, int fromfd
,
1745 files_struct
*tofsp
, off_t offset
,
1749 return handle
->fns
->recvfile_fn(handle
, fromfd
, tofsp
, offset
, count
);
1752 int smb_vfs_call_renameat(struct vfs_handle_struct
*handle
,
1753 files_struct
*srcfsp
,
1754 const struct smb_filename
*smb_fname_src
,
1755 files_struct
*dstfsp
,
1756 const struct smb_filename
*smb_fname_dst
)
1759 return handle
->fns
->renameat_fn(handle
,
1766 struct smb_vfs_call_fsync_state
{
1767 int (*recv_fn
)(struct tevent_req
*req
, struct vfs_aio_state
*vfs_aio_state
);
1769 struct vfs_aio_state vfs_aio_state
;
1772 static void smb_vfs_call_fsync_done(struct tevent_req
*subreq
);
1774 struct tevent_req
*smb_vfs_call_fsync_send(struct vfs_handle_struct
*handle
,
1775 TALLOC_CTX
*mem_ctx
,
1776 struct tevent_context
*ev
,
1777 struct files_struct
*fsp
)
1779 struct tevent_req
*req
, *subreq
;
1780 struct smb_vfs_call_fsync_state
*state
;
1782 req
= tevent_req_create(mem_ctx
, &state
,
1783 struct smb_vfs_call_fsync_state
);
1787 VFS_FIND(fsync_send
);
1788 state
->recv_fn
= handle
->fns
->fsync_recv_fn
;
1790 subreq
= handle
->fns
->fsync_send_fn(handle
, state
, ev
, fsp
);
1791 if (tevent_req_nomem(subreq
, req
)) {
1792 return tevent_req_post(req
, ev
);
1794 tevent_req_set_callback(subreq
, smb_vfs_call_fsync_done
, req
);
1798 static void smb_vfs_call_fsync_done(struct tevent_req
*subreq
)
1800 struct tevent_req
*req
= tevent_req_callback_data(
1801 subreq
, struct tevent_req
);
1802 struct smb_vfs_call_fsync_state
*state
= tevent_req_data(
1803 req
, struct smb_vfs_call_fsync_state
);
1805 state
->retval
= state
->recv_fn(subreq
, &state
->vfs_aio_state
);
1806 TALLOC_FREE(subreq
);
1807 if (state
->retval
== -1) {
1808 tevent_req_error(req
, state
->vfs_aio_state
.error
);
1811 tevent_req_done(req
);
1814 int SMB_VFS_FSYNC_RECV(struct tevent_req
*req
, struct vfs_aio_state
*vfs_aio_state
)
1816 struct smb_vfs_call_fsync_state
*state
= tevent_req_data(
1817 req
, struct smb_vfs_call_fsync_state
);
1820 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
1821 tevent_req_received(req
);
1824 *vfs_aio_state
= state
->vfs_aio_state
;
1825 retval
= state
->retval
;
1826 tevent_req_received(req
);
1831 * Synchronous version of fsync, built from backend
1832 * async VFS primitives. Uses a temporary sub-event
1833 * context (NOT NESTED).
1836 int smb_vfs_fsync_sync(files_struct
*fsp
)
1838 TALLOC_CTX
*frame
= talloc_stackframe();
1839 struct tevent_req
*req
= NULL
;
1840 struct vfs_aio_state aio_state
= { 0 };
1843 struct tevent_context
*ev
= samba_tevent_context_init(frame
);
1849 req
= SMB_VFS_FSYNC_SEND(talloc_tos(), ev
, fsp
);
1854 ok
= tevent_req_poll(req
, ev
);
1859 ret
= SMB_VFS_FSYNC_RECV(req
, &aio_state
);
1864 if (aio_state
.error
!= 0) {
1865 errno
= aio_state
.error
;
1870 int smb_vfs_call_stat(struct vfs_handle_struct
*handle
,
1871 struct smb_filename
*smb_fname
)
1874 return handle
->fns
->stat_fn(handle
, smb_fname
);
1877 int smb_vfs_call_fstat(struct vfs_handle_struct
*handle
,
1878 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1881 return handle
->fns
->fstat_fn(handle
, fsp
, sbuf
);
1884 int smb_vfs_call_lstat(struct vfs_handle_struct
*handle
,
1885 struct smb_filename
*smb_filename
)
1888 return handle
->fns
->lstat_fn(handle
, smb_filename
);
1891 int smb_vfs_call_fstatat(
1892 struct vfs_handle_struct
*handle
,
1893 const struct files_struct
*dirfsp
,
1894 const struct smb_filename
*smb_fname
,
1895 SMB_STRUCT_STAT
*sbuf
,
1899 return handle
->fns
->fstatat_fn(handle
, dirfsp
, smb_fname
, sbuf
, flags
);
1902 uint64_t smb_vfs_call_get_alloc_size(struct vfs_handle_struct
*handle
,
1903 struct files_struct
*fsp
,
1904 const SMB_STRUCT_STAT
*sbuf
)
1906 VFS_FIND(get_alloc_size
);
1907 return handle
->fns
->get_alloc_size_fn(handle
, fsp
, sbuf
);
1910 int smb_vfs_call_unlinkat(struct vfs_handle_struct
*handle
,
1911 struct files_struct
*dirfsp
,
1912 const struct smb_filename
*smb_fname
,
1916 return handle
->fns
->unlinkat_fn(handle
,
1922 int smb_vfs_call_fchmod(struct vfs_handle_struct
*handle
,
1923 struct files_struct
*fsp
, mode_t mode
)
1926 return handle
->fns
->fchmod_fn(handle
, fsp
, mode
);
1929 int smb_vfs_call_fchown(struct vfs_handle_struct
*handle
,
1930 struct files_struct
*fsp
, uid_t uid
, gid_t gid
)
1933 return handle
->fns
->fchown_fn(handle
, fsp
, uid
, gid
);
1936 int smb_vfs_call_lchown(struct vfs_handle_struct
*handle
,
1937 const struct smb_filename
*smb_fname
,
1942 return handle
->fns
->lchown_fn(handle
, smb_fname
, uid
, gid
);
1945 int smb_vfs_call_chdir(struct vfs_handle_struct
*handle
,
1946 const struct smb_filename
*smb_fname
)
1949 return handle
->fns
->chdir_fn(handle
, smb_fname
);
1952 struct smb_filename
*smb_vfs_call_getwd(struct vfs_handle_struct
*handle
,
1956 return handle
->fns
->getwd_fn(handle
, ctx
);
1959 int smb_vfs_call_fntimes(struct vfs_handle_struct
*handle
,
1960 struct files_struct
*fsp
,
1961 struct smb_file_time
*ft
)
1964 return handle
->fns
->fntimes_fn(handle
, fsp
, ft
);
1967 int smb_vfs_call_ftruncate(struct vfs_handle_struct
*handle
,
1968 struct files_struct
*fsp
, off_t offset
)
1970 VFS_FIND(ftruncate
);
1971 return handle
->fns
->ftruncate_fn(handle
, fsp
, offset
);
1974 int smb_vfs_call_fallocate(struct vfs_handle_struct
*handle
,
1975 struct files_struct
*fsp
,
1980 VFS_FIND(fallocate
);
1981 return handle
->fns
->fallocate_fn(handle
, fsp
, mode
, offset
, len
);
1984 int smb_vfs_call_filesystem_sharemode(struct vfs_handle_struct
*handle
,
1985 struct files_struct
*fsp
,
1986 uint32_t share_mode
,
1987 uint32_t access_mask
)
1989 VFS_FIND(filesystem_sharemode
);
1990 return handle
->fns
->filesystem_sharemode_fn(handle
,
1996 int smb_vfs_call_fcntl(struct vfs_handle_struct
*handle
,
1997 struct files_struct
*fsp
, int cmd
, ...)
2004 va_start(cmd_arg
, cmd
);
2005 result
= handle
->fns
->fcntl_fn(handle
, fsp
, cmd
, cmd_arg
);
2011 int smb_vfs_call_linux_setlease(struct vfs_handle_struct
*handle
,
2012 struct files_struct
*fsp
, int leasetype
)
2014 VFS_FIND(linux_setlease
);
2015 return handle
->fns
->linux_setlease_fn(handle
, fsp
, leasetype
);
2018 int smb_vfs_call_symlinkat(struct vfs_handle_struct
*handle
,
2019 const struct smb_filename
*link_target
,
2020 struct files_struct
*dirfsp
,
2021 const struct smb_filename
*new_smb_fname
)
2023 VFS_FIND(symlinkat
);
2024 return handle
->fns
->symlinkat_fn(handle
,
2030 int smb_vfs_call_readlinkat(struct vfs_handle_struct
*handle
,
2031 const struct files_struct
*dirfsp
,
2032 const struct smb_filename
*smb_fname
,
2036 VFS_FIND(readlinkat
);
2037 return handle
->fns
->readlinkat_fn(handle
,
2044 int smb_vfs_call_linkat(struct vfs_handle_struct
*handle
,
2045 struct files_struct
*srcfsp
,
2046 const struct smb_filename
*old_smb_fname
,
2047 struct files_struct
*dstfsp
,
2048 const struct smb_filename
*new_smb_fname
,
2052 return handle
->fns
->linkat_fn(handle
,
2060 int smb_vfs_call_mknodat(struct vfs_handle_struct
*handle
,
2061 struct files_struct
*dirfsp
,
2062 const struct smb_filename
*smb_fname
,
2067 return handle
->fns
->mknodat_fn(handle
,
2074 struct smb_filename
*smb_vfs_call_realpath(struct vfs_handle_struct
*handle
,
2076 const struct smb_filename
*smb_fname
)
2079 return handle
->fns
->realpath_fn(handle
, ctx
, smb_fname
);
2082 int smb_vfs_call_fchflags(struct vfs_handle_struct
*handle
,
2083 struct files_struct
*fsp
,
2087 return handle
->fns
->fchflags_fn(handle
, fsp
, flags
);
2090 struct file_id
smb_vfs_call_file_id_create(struct vfs_handle_struct
*handle
,
2091 const SMB_STRUCT_STAT
*sbuf
)
2093 VFS_FIND(file_id_create
);
2094 return handle
->fns
->file_id_create_fn(handle
, sbuf
);
2097 uint64_t smb_vfs_call_fs_file_id(struct vfs_handle_struct
*handle
,
2098 const SMB_STRUCT_STAT
*sbuf
)
2100 VFS_FIND(fs_file_id
);
2101 return handle
->fns
->fs_file_id_fn(handle
, sbuf
);
2104 NTSTATUS
smb_vfs_call_fstreaminfo(struct vfs_handle_struct
*handle
,
2105 struct files_struct
*fsp
,
2106 TALLOC_CTX
*mem_ctx
,
2107 unsigned int *num_streams
,
2108 struct stream_struct
**streams
)
2110 VFS_FIND(fstreaminfo
);
2111 return handle
->fns
->fstreaminfo_fn(handle
, fsp
, mem_ctx
,
2112 num_streams
, streams
);
2115 NTSTATUS
smb_vfs_call_get_real_filename_at(struct vfs_handle_struct
*handle
,
2116 struct files_struct
*dirfsp
,
2118 TALLOC_CTX
*mem_ctx
,
2121 VFS_FIND(get_real_filename_at
);
2122 return handle
->fns
->get_real_filename_at_fn(
2123 handle
, dirfsp
, name
, mem_ctx
, found_name
);
2126 const char *smb_vfs_call_connectpath(struct vfs_handle_struct
*handle
,
2127 const struct files_struct
*dirfsp
,
2128 const struct smb_filename
*smb_fname
)
2130 VFS_FIND(connectpath
);
2131 return handle
->fns
->connectpath_fn(handle
, dirfsp
, smb_fname
);
2134 bool smb_vfs_call_strict_lock_check(struct vfs_handle_struct
*handle
,
2135 struct files_struct
*fsp
,
2136 struct lock_struct
*plock
)
2138 VFS_FIND(strict_lock_check
);
2139 return handle
->fns
->strict_lock_check_fn(handle
, fsp
, plock
);
2142 NTSTATUS
smb_vfs_call_translate_name(struct vfs_handle_struct
*handle
,
2144 enum vfs_translate_direction direction
,
2145 TALLOC_CTX
*mem_ctx
,
2148 VFS_FIND(translate_name
);
2149 return handle
->fns
->translate_name_fn(handle
, name
, direction
, mem_ctx
,
2153 NTSTATUS
smb_vfs_call_parent_pathname(struct vfs_handle_struct
*handle
,
2154 TALLOC_CTX
*mem_ctx
,
2155 const struct smb_filename
*smb_fname_in
,
2156 struct smb_filename
**parent_dir_out
,
2157 struct smb_filename
**atname_out
)
2159 VFS_FIND(parent_pathname
);
2160 return handle
->fns
->parent_pathname_fn(handle
,
2167 NTSTATUS
smb_vfs_call_fsctl(struct vfs_handle_struct
*handle
,
2168 struct files_struct
*fsp
,
2172 const uint8_t *in_data
,
2175 uint32_t max_out_len
,
2179 return handle
->fns
->fsctl_fn(handle
, fsp
, ctx
, function
, req_flags
,
2180 in_data
, in_len
, out_data
, max_out_len
,
2184 NTSTATUS
smb_vfs_call_fget_dos_attributes(struct vfs_handle_struct
*handle
,
2185 struct files_struct
*fsp
,
2188 VFS_FIND(fget_dos_attributes
);
2189 return handle
->fns
->fget_dos_attributes_fn(handle
, fsp
, dosmode
);
2192 NTSTATUS
smb_vfs_call_fset_dos_attributes(struct vfs_handle_struct
*handle
,
2193 struct files_struct
*fsp
,
2196 VFS_FIND(fset_dos_attributes
);
2197 return handle
->fns
->fset_dos_attributes_fn(handle
, fsp
, dosmode
);
2200 struct tevent_req
*smb_vfs_call_offload_read_send(TALLOC_CTX
*mem_ctx
,
2201 struct tevent_context
*ev
,
2202 struct vfs_handle_struct
*handle
,
2203 struct files_struct
*fsp
,
2209 VFS_FIND(offload_read_send
);
2210 return handle
->fns
->offload_read_send_fn(mem_ctx
, ev
, handle
,
2212 ttl
, offset
, to_copy
);
2215 NTSTATUS
smb_vfs_call_offload_read_recv(struct tevent_req
*req
,
2216 struct vfs_handle_struct
*handle
,
2217 TALLOC_CTX
*mem_ctx
,
2220 DATA_BLOB
*token_blob
)
2222 VFS_FIND(offload_read_recv
);
2223 return handle
->fns
->offload_read_recv_fn(req
, handle
, mem_ctx
, flags
, xferlen
, token_blob
);
2226 struct tevent_req
*smb_vfs_call_offload_write_send(struct vfs_handle_struct
*handle
,
2227 TALLOC_CTX
*mem_ctx
,
2228 struct tevent_context
*ev
,
2231 off_t transfer_offset
,
2232 struct files_struct
*dest_fsp
,
2236 VFS_FIND(offload_write_send
);
2237 return handle
->fns
->offload_write_send_fn(handle
, mem_ctx
, ev
, fsctl
,
2238 token
, transfer_offset
,
2239 dest_fsp
, dest_off
, num
);
2242 NTSTATUS
smb_vfs_call_offload_write_recv(struct vfs_handle_struct
*handle
,
2243 struct tevent_req
*req
,
2246 VFS_FIND(offload_write_recv
);
2247 return handle
->fns
->offload_write_recv_fn(handle
, req
, copied
);
2250 struct smb_vfs_call_get_dos_attributes_state
{
2251 files_struct
*dir_fsp
;
2252 NTSTATUS (*recv_fn
)(struct tevent_req
*req
,
2253 struct vfs_aio_state
*aio_state
,
2255 struct vfs_aio_state aio_state
;
2256 uint32_t dos_attributes
;
2259 static void smb_vfs_call_get_dos_attributes_done(struct tevent_req
*subreq
);
2261 struct tevent_req
*smb_vfs_call_get_dos_attributes_send(
2262 TALLOC_CTX
*mem_ctx
,
2263 struct tevent_context
*ev
,
2264 struct vfs_handle_struct
*handle
,
2265 files_struct
*dir_fsp
,
2266 struct smb_filename
*smb_fname
)
2268 struct tevent_req
*req
= NULL
;
2269 struct smb_vfs_call_get_dos_attributes_state
*state
= NULL
;
2270 struct tevent_req
*subreq
= NULL
;
2272 req
= tevent_req_create(mem_ctx
, &state
,
2273 struct smb_vfs_call_get_dos_attributes_state
);
2278 VFS_FIND(get_dos_attributes_send
);
2280 *state
= (struct smb_vfs_call_get_dos_attributes_state
) {
2282 .recv_fn
= handle
->fns
->get_dos_attributes_recv_fn
,
2285 subreq
= handle
->fns
->get_dos_attributes_send_fn(mem_ctx
,
2290 if (tevent_req_nomem(subreq
, req
)) {
2291 return tevent_req_post(req
, ev
);
2293 tevent_req_defer_callback(req
, ev
);
2295 tevent_req_set_callback(subreq
,
2296 smb_vfs_call_get_dos_attributes_done
,
2302 static void smb_vfs_call_get_dos_attributes_done(struct tevent_req
*subreq
)
2304 struct tevent_req
*req
=
2305 tevent_req_callback_data(subreq
,
2307 struct smb_vfs_call_get_dos_attributes_state
*state
=
2308 tevent_req_data(req
,
2309 struct smb_vfs_call_get_dos_attributes_state
);
2314 * Make sure we run as the user again
2316 ok
= change_to_user_and_service_by_fsp(state
->dir_fsp
);
2319 status
= state
->recv_fn(subreq
,
2321 &state
->dos_attributes
);
2322 TALLOC_FREE(subreq
);
2323 if (tevent_req_nterror(req
, status
)) {
2327 tevent_req_done(req
);
2330 NTSTATUS
smb_vfs_call_get_dos_attributes_recv(
2331 struct tevent_req
*req
,
2332 struct vfs_aio_state
*aio_state
,
2333 uint32_t *dos_attributes
)
2335 struct smb_vfs_call_get_dos_attributes_state
*state
=
2336 tevent_req_data(req
,
2337 struct smb_vfs_call_get_dos_attributes_state
);
2340 if (tevent_req_is_nterror(req
, &status
)) {
2341 tevent_req_received(req
);
2345 *aio_state
= state
->aio_state
;
2346 *dos_attributes
= state
->dos_attributes
;
2347 tevent_req_received(req
);
2348 return NT_STATUS_OK
;
2351 NTSTATUS
smb_vfs_call_fget_compression(vfs_handle_struct
*handle
,
2352 TALLOC_CTX
*mem_ctx
,
2353 struct files_struct
*fsp
,
2354 uint16_t *_compression_fmt
)
2356 VFS_FIND(fget_compression
);
2357 return handle
->fns
->fget_compression_fn(handle
, mem_ctx
, fsp
,
2361 NTSTATUS
smb_vfs_call_set_compression(vfs_handle_struct
*handle
,
2362 TALLOC_CTX
*mem_ctx
,
2363 struct files_struct
*fsp
,
2364 uint16_t compression_fmt
)
2366 VFS_FIND(set_compression
);
2367 return handle
->fns
->set_compression_fn(handle
, mem_ctx
, fsp
,
2371 NTSTATUS
smb_vfs_call_snap_check_path(vfs_handle_struct
*handle
,
2372 TALLOC_CTX
*mem_ctx
,
2373 const char *service_path
,
2376 VFS_FIND(snap_check_path
);
2377 return handle
->fns
->snap_check_path_fn(handle
, mem_ctx
, service_path
,
2381 NTSTATUS
smb_vfs_call_snap_create(struct vfs_handle_struct
*handle
,
2382 TALLOC_CTX
*mem_ctx
,
2383 const char *base_volume
,
2389 VFS_FIND(snap_create
);
2390 return handle
->fns
->snap_create_fn(handle
, mem_ctx
, base_volume
, tstamp
,
2391 rw
, base_path
, snap_path
);
2394 NTSTATUS
smb_vfs_call_snap_delete(struct vfs_handle_struct
*handle
,
2395 TALLOC_CTX
*mem_ctx
,
2399 VFS_FIND(snap_delete
);
2400 return handle
->fns
->snap_delete_fn(handle
, mem_ctx
, base_path
,
2404 NTSTATUS
smb_vfs_call_fget_nt_acl(struct vfs_handle_struct
*handle
,
2405 struct files_struct
*fsp
,
2406 uint32_t security_info
,
2407 TALLOC_CTX
*mem_ctx
,
2408 struct security_descriptor
**ppdesc
)
2410 VFS_FIND(fget_nt_acl
);
2411 return handle
->fns
->fget_nt_acl_fn(handle
, fsp
, security_info
,
2415 NTSTATUS
smb_vfs_call_fset_nt_acl(struct vfs_handle_struct
*handle
,
2416 struct files_struct
*fsp
,
2417 uint32_t security_info_sent
,
2418 const struct security_descriptor
*psd
)
2420 VFS_FIND(fset_nt_acl
);
2421 return handle
->fns
->fset_nt_acl_fn(handle
, fsp
, security_info_sent
,
2425 NTSTATUS
smb_vfs_call_audit_file(struct vfs_handle_struct
*handle
,
2426 struct smb_filename
*file
,
2427 struct security_acl
*sacl
,
2428 uint32_t access_requested
,
2429 uint32_t access_denied
)
2431 VFS_FIND(audit_file
);
2432 return handle
->fns
->audit_file_fn(handle
,
2439 SMB_ACL_T
smb_vfs_call_sys_acl_get_fd(struct vfs_handle_struct
*handle
,
2440 struct files_struct
*fsp
,
2441 SMB_ACL_TYPE_T type
,
2442 TALLOC_CTX
*mem_ctx
)
2444 VFS_FIND(sys_acl_get_fd
);
2445 return handle
->fns
->sys_acl_get_fd_fn(handle
, fsp
, type
, mem_ctx
);
2448 int smb_vfs_call_sys_acl_blob_get_fd(struct vfs_handle_struct
*handle
,
2449 struct files_struct
*fsp
,
2450 TALLOC_CTX
*mem_ctx
,
2451 char **blob_description
,
2454 VFS_FIND(sys_acl_blob_get_fd
);
2455 return handle
->fns
->sys_acl_blob_get_fd_fn(handle
, fsp
, mem_ctx
, blob_description
, blob
);
2458 int smb_vfs_call_sys_acl_set_fd(struct vfs_handle_struct
*handle
,
2459 struct files_struct
*fsp
,
2460 SMB_ACL_TYPE_T type
,
2463 VFS_FIND(sys_acl_set_fd
);
2464 return handle
->fns
->sys_acl_set_fd_fn(handle
, fsp
, type
, theacl
);
2467 int smb_vfs_call_sys_acl_delete_def_fd(struct vfs_handle_struct
*handle
,
2468 struct files_struct
*fsp
)
2470 VFS_FIND(sys_acl_delete_def_fd
);
2471 return handle
->fns
->sys_acl_delete_def_fd_fn(handle
, fsp
);
2474 struct smb_vfs_call_getxattrat_state
{
2475 files_struct
*dir_fsp
;
2476 ssize_t (*recv_fn
)(struct tevent_req
*req
,
2477 struct vfs_aio_state
*aio_state
,
2478 TALLOC_CTX
*mem_ctx
,
2479 uint8_t **xattr_value
);
2481 uint8_t *xattr_value
;
2482 struct vfs_aio_state aio_state
;
2485 static void smb_vfs_call_getxattrat_done(struct tevent_req
*subreq
);
2487 struct tevent_req
*smb_vfs_call_getxattrat_send(
2488 TALLOC_CTX
*mem_ctx
,
2489 struct tevent_context
*ev
,
2490 struct vfs_handle_struct
*handle
,
2491 files_struct
*dir_fsp
,
2492 const struct smb_filename
*smb_fname
,
2493 const char *xattr_name
,
2496 struct tevent_req
*req
= NULL
;
2497 struct smb_vfs_call_getxattrat_state
*state
= NULL
;
2498 struct tevent_req
*subreq
= NULL
;
2500 req
= tevent_req_create(mem_ctx
, &state
,
2501 struct smb_vfs_call_getxattrat_state
);
2506 VFS_FIND(getxattrat_send
);
2508 *state
= (struct smb_vfs_call_getxattrat_state
) {
2510 .recv_fn
= handle
->fns
->getxattrat_recv_fn
,
2513 subreq
= handle
->fns
->getxattrat_send_fn(mem_ctx
,
2520 if (tevent_req_nomem(subreq
, req
)) {
2521 return tevent_req_post(req
, ev
);
2523 tevent_req_defer_callback(req
, ev
);
2525 tevent_req_set_callback(subreq
, smb_vfs_call_getxattrat_done
, req
);
2529 static void smb_vfs_call_getxattrat_done(struct tevent_req
*subreq
)
2531 struct tevent_req
*req
= tevent_req_callback_data(
2532 subreq
, struct tevent_req
);
2533 struct smb_vfs_call_getxattrat_state
*state
= tevent_req_data(
2534 req
, struct smb_vfs_call_getxattrat_state
);
2538 * Make sure we run as the user again
2540 ok
= change_to_user_and_service_by_fsp(state
->dir_fsp
);
2543 state
->retval
= state
->recv_fn(subreq
,
2546 &state
->xattr_value
);
2547 TALLOC_FREE(subreq
);
2548 if (state
->retval
== -1) {
2549 tevent_req_error(req
, state
->aio_state
.error
);
2553 tevent_req_done(req
);
2556 ssize_t
smb_vfs_call_getxattrat_recv(struct tevent_req
*req
,
2557 struct vfs_aio_state
*aio_state
,
2558 TALLOC_CTX
*mem_ctx
,
2559 uint8_t **xattr_value
)
2561 struct smb_vfs_call_getxattrat_state
*state
= tevent_req_data(
2562 req
, struct smb_vfs_call_getxattrat_state
);
2565 if (tevent_req_is_unix_error(req
, &aio_state
->error
)) {
2566 tevent_req_received(req
);
2570 *aio_state
= state
->aio_state
;
2571 xattr_size
= state
->retval
;
2572 if (xattr_value
!= NULL
) {
2573 *xattr_value
= talloc_move(mem_ctx
, &state
->xattr_value
);
2576 tevent_req_received(req
);
2580 ssize_t
smb_vfs_call_fgetxattr(struct vfs_handle_struct
*handle
,
2581 struct files_struct
*fsp
, const char *name
,
2582 void *value
, size_t size
)
2584 VFS_FIND(fgetxattr
);
2585 return handle
->fns
->fgetxattr_fn(handle
, fsp
, name
, value
, size
);
2588 ssize_t
smb_vfs_call_flistxattr(struct vfs_handle_struct
*handle
,
2589 struct files_struct
*fsp
, char *list
,
2592 VFS_FIND(flistxattr
);
2593 return handle
->fns
->flistxattr_fn(handle
, fsp
, list
, size
);
2596 int smb_vfs_call_fremovexattr(struct vfs_handle_struct
*handle
,
2597 struct files_struct
*fsp
, const char *name
)
2599 VFS_FIND(fremovexattr
);
2600 return handle
->fns
->fremovexattr_fn(handle
, fsp
, name
);
2603 int smb_vfs_call_fsetxattr(struct vfs_handle_struct
*handle
,
2604 struct files_struct
*fsp
, const char *name
,
2605 const void *value
, size_t size
, int flags
)
2607 VFS_FIND(fsetxattr
);
2608 return handle
->fns
->fsetxattr_fn(handle
, fsp
, name
, value
, size
, flags
);
2611 bool smb_vfs_call_aio_force(struct vfs_handle_struct
*handle
,
2612 struct files_struct
*fsp
)
2614 VFS_FIND(aio_force
);
2615 return handle
->fns
->aio_force_fn(handle
, fsp
);
2618 NTSTATUS
smb_vfs_call_durable_cookie(struct vfs_handle_struct
*handle
,
2619 struct files_struct
*fsp
,
2620 TALLOC_CTX
*mem_ctx
,
2623 VFS_FIND(durable_cookie
);
2624 return handle
->fns
->durable_cookie_fn(handle
, fsp
, mem_ctx
, cookie
);
2627 NTSTATUS
smb_vfs_call_durable_disconnect(struct vfs_handle_struct
*handle
,
2628 struct files_struct
*fsp
,
2629 const DATA_BLOB old_cookie
,
2630 TALLOC_CTX
*mem_ctx
,
2631 DATA_BLOB
*new_cookie
)
2633 VFS_FIND(durable_disconnect
);
2634 return handle
->fns
->durable_disconnect_fn(handle
, fsp
, old_cookie
,
2635 mem_ctx
, new_cookie
);
2638 NTSTATUS
smb_vfs_call_durable_reconnect(struct vfs_handle_struct
*handle
,
2639 struct smb_request
*smb1req
,
2640 struct smbXsrv_open
*op
,
2641 const DATA_BLOB old_cookie
,
2642 TALLOC_CTX
*mem_ctx
,
2643 struct files_struct
**fsp
,
2644 DATA_BLOB
*new_cookie
)
2646 VFS_FIND(durable_reconnect
);
2647 return handle
->fns
->durable_reconnect_fn(handle
, smb1req
, op
,
2648 old_cookie
, mem_ctx
, fsp
,
2652 NTSTATUS
smb_vfs_call_freaddir_attr(struct vfs_handle_struct
*handle
,
2653 struct files_struct
*fsp
,
2654 TALLOC_CTX
*mem_ctx
,
2655 struct readdir_attr_data
**attr_data
)
2657 VFS_FIND(freaddir_attr
);
2658 return handle
->fns
->freaddir_attr_fn(handle
,
2664 bool smb_vfs_call_lock(struct vfs_handle_struct
*handle
,
2665 struct files_struct
*fsp
, int op
, off_t offset
,
2666 off_t count
, int type
)
2669 return handle
->fns
->lock_fn(handle
, fsp
, op
, offset
, count
, type
);
2672 bool smb_vfs_call_getlock(struct vfs_handle_struct
*handle
,
2673 struct files_struct
*fsp
, off_t
*poffset
,
2674 off_t
*pcount
, int *ptype
, pid_t
*ppid
)
2677 return handle
->fns
->getlock_fn(handle
, fsp
, poffset
, pcount
, ptype
,
2681 NTSTATUS
smb_vfs_call_brl_lock_windows(struct vfs_handle_struct
*handle
,
2682 struct byte_range_lock
*br_lck
,
2683 struct lock_struct
*plock
)
2685 VFS_FIND(brl_lock_windows
);
2686 return handle
->fns
->brl_lock_windows_fn(handle
, br_lck
, plock
);
2689 bool smb_vfs_call_brl_unlock_windows(struct vfs_handle_struct
*handle
,
2690 struct byte_range_lock
*br_lck
,
2691 const struct lock_struct
*plock
)
2693 VFS_FIND(brl_unlock_windows
);
2694 return handle
->fns
->brl_unlock_windows_fn(handle
, br_lck
, plock
);