LCOV - code coverage report
Current view: top level - source3/smbd - vfs.c (source / functions) Hit Total Coverage
Test: coverage report for support-claim-type-attributes 6b5c566e Lines: 765 1015 75.4 %
Date: 2023-11-21 12:31:41 Functions: 130 142 91.5 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/Netbios implementation.
       3             :    Version 1.9.
       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
       9             : 
      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.
      14             : 
      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.
      19             : 
      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/>.
      22             : 
      23             :    This work was sponsored by Optifacio Software Services, Inc.
      24             : */
      25             : 
      26             : #include "includes.h"
      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"
      32             : #include "ntioctl.h"
      33             : #include "lib/util/tevent_unix.h"
      34             : #include "lib/util/tevent_ntstatus.h"
      35             : #include "lib/util/sys_rw.h"
      36             : 
      37             : #undef DBGC_CLASS
      38             : #define DBGC_CLASS DBGC_VFS
      39             : 
      40             : static_decl_vfs;
      41             : 
      42             : struct vfs_fsp_data {
      43             :     struct vfs_fsp_data *next;
      44             :     struct vfs_handle_struct *owner;
      45             :     void (*destroy)(void *p_data);
      46             :     void *_dummy_;
      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.
      49             :      */
      50             : };
      51             : 
      52             : struct vfs_init_function_entry {
      53             :         char *name;
      54             :         struct vfs_init_function_entry *prev, *next;
      55             :         const struct vfs_fn_pointers *fns;
      56             : };
      57             : 
      58             : /****************************************************************************
      59             :     maintain the list of available backends
      60             : ****************************************************************************/
      61             : 
      62      771256 : static struct vfs_init_function_entry *vfs_find_backend_entry(const char *name)
      63             : {
      64      771256 :         struct vfs_init_function_entry *entry = backends;
      65             : 
      66      771256 :         DEBUG(10, ("vfs_find_backend_entry called for %s\n", name));
      67             : 
      68     3392113 :         while(entry) {
      69     2984962 :                 if (strcmp(entry->name, name)==0) return entry;
      70     2620857 :                 entry = entry->next;
      71             :         }
      72             : 
      73      398195 :         return NULL;
      74             : }
      75             : 
      76      252747 : NTSTATUS smb_register_vfs(int version, const char *name,
      77             :                           const struct vfs_fn_pointers *fns)
      78             : {
      79      252747 :         struct vfs_init_function_entry *entry = backends;
      80             : 
      81      252747 :         if ((version != SMB_VFS_INTERFACE_VERSION)) {
      82           0 :                 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           0 :                 return NT_STATUS_OBJECT_TYPE_MISMATCH;
      88             :         }
      89             : 
      90      252747 :         if (!name || !name[0]) {
      91           0 :                 DEBUG(0,("smb_register_vfs() called with NULL pointer or empty name!\n"));
      92           0 :                 return NT_STATUS_INVALID_PARAMETER;
      93             :         }
      94             : 
      95      252747 :         if (vfs_find_backend_entry(name)) {
      96           0 :                 DEBUG(0,("VFS module %s already loaded!\n", name));
      97           0 :                 return NT_STATUS_OBJECT_NAME_COLLISION;
      98             :         }
      99             : 
     100      252747 :         entry = SMB_XMALLOC_P(struct vfs_init_function_entry);
     101      252747 :         entry->name = smb_xstrdup(name);
     102      252747 :         entry->fns = fns;
     103             : 
     104      252747 :         DLIST_ADD(backends, entry);
     105      252747 :         DEBUG(5, ("Successfully added vfs backend '%s'\n", name));
     106      252747 :         return NT_STATUS_OK;
     107             : }
     108             : 
     109             : /****************************************************************************
     110             :   initialise default vfs hooks
     111             : ****************************************************************************/
     112             : 
     113       56433 : static void vfs_init_default(connection_struct *conn)
     114             : {
     115       56433 :         DEBUG(3, ("Initialising default vfs hooks\n"));
     116       56433 :         vfs_init_custom(conn, DEFAULT_VFS_MODULE_NAME);
     117       56433 : }
     118             : 
     119             : /****************************************************************************
     120             :   initialise custom vfs hooks
     121             :  ****************************************************************************/
     122             : 
     123      364105 : bool vfs_init_custom(connection_struct *conn, const char *vfs_object)
     124             : {
     125      364105 :         char *module_path = NULL;
     126      364105 :         char *module_name = NULL;
     127      364105 :         char *module_param = NULL, *p;
     128        5129 :         vfs_handle_struct *handle;
     129        5129 :         const struct vfs_init_function_entry *entry;
     130             : 
     131      364105 :         if (!conn||!vfs_object||!vfs_object[0]) {
     132           0 :                 DEBUG(0, ("vfs_init_custom() called with NULL pointer or "
     133             :                           "empty vfs_object!\n"));
     134           0 :                 return False;
     135             :         }
     136             : 
     137      364105 :         if(!backends) {
     138       28901 :                 static_init_vfs(NULL);
     139             :         }
     140             : 
     141      364105 :         DEBUG(3, ("Initialising custom vfs hooks from [%s]\n", vfs_object));
     142             : 
     143      364105 :         module_path = smb_xstrdup(vfs_object);
     144             : 
     145      364105 :         p = strchr_m(module_path, ':');
     146             : 
     147      364105 :         if (p) {
     148           0 :                 *p = 0;
     149           0 :                 module_param = p+1;
     150           0 :                 trim_char(module_param, ' ', ' ');
     151             :         }
     152             : 
     153      364105 :         trim_char(module_path, ' ', ' ');
     154             : 
     155      364105 :         module_name = smb_xstrdup(module_path);
     156             : 
     157      364105 :         if ((module_name[0] == '/') &&
     158       56433 :             (strcmp(module_path, DEFAULT_VFS_MODULE_NAME) != 0)) {
     159             : 
     160             :                 /*
     161             :                  * Extract the module name from the path. Just use the base
     162             :                  * name of the last path component.
     163             :                  */
     164             : 
     165           0 :                 SAFE_FREE(module_name);
     166           0 :                 module_name = smb_xstrdup(strrchr_m(module_path, '/')+1);
     167             : 
     168           0 :                 p = strchr_m(module_name, '.');
     169             : 
     170           0 :                 if (p != NULL) {
     171           0 :                         *p = '\0';
     172             :                 }
     173             :         }
     174             : 
     175             :         /* First, try to load the module with the new module system */
     176      364105 :         entry = vfs_find_backend_entry(module_name);
     177      364105 :         if (!entry) {
     178        2984 :                 NTSTATUS status;
     179             : 
     180      154404 :                 DEBUG(5, ("vfs module [%s] not loaded - trying to load...\n",
     181             :                           vfs_object));
     182             : 
     183      154404 :                 status = smb_load_module("vfs", module_path);
     184      154404 :                 if (!NT_STATUS_IS_OK(status)) {
     185           0 :                         DEBUG(0, ("error probing vfs module '%s': %s\n",
     186             :                                   module_path, nt_errstr(status)));
     187           0 :                         goto fail;
     188             :                 }
     189             : 
     190      154404 :                 entry = vfs_find_backend_entry(module_name);
     191      154404 :                 if (!entry) {
     192           0 :                         DEBUG(0,("Can't find a vfs module [%s]\n",vfs_object));
     193           0 :                         goto fail;
     194             :                 }
     195             :         }
     196             : 
     197      364105 :         DEBUGADD(5,("Successfully loaded vfs module [%s] with the new modules system\n", vfs_object));
     198             : 
     199      364105 :         handle = talloc_zero(conn, vfs_handle_struct);
     200      364105 :         if (!handle) {
     201           0 :                 DEBUG(0,("TALLOC_ZERO() failed!\n"));
     202           0 :                 goto fail;
     203             :         }
     204      364105 :         handle->conn = conn;
     205      364105 :         handle->fns = entry->fns;
     206      364105 :         if (module_param) {
     207           0 :                 handle->param = talloc_strdup(conn, module_param);
     208             :         }
     209      364105 :         DLIST_ADD(conn->vfs_handles, handle);
     210             : 
     211      364105 :         SAFE_FREE(module_path);
     212      364105 :         SAFE_FREE(module_name);
     213      358976 :         return True;
     214             : 
     215           0 :  fail:
     216           0 :         SAFE_FREE(module_path);
     217           0 :         SAFE_FREE(module_name);
     218           0 :         return False;
     219             : }
     220             : 
     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             : ******************************************************************/
     226             : 
     227             : #define EXT_DATA_AREA(e) ((uint8_t *)(e) + sizeof(struct vfs_fsp_data))
     228             : 
     229      232138 : 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))
     232             : {
     233         431 :         struct vfs_fsp_data *ext;
     234         431 :         void * ext_data;
     235             : 
     236             :         /* Prevent VFS modules adding multiple extensions. */
     237      232138 :         if ((ext_data = vfs_fetch_fsp_extension(handle, fsp))) {
     238        1490 :                 return ext_data;
     239             :         }
     240             : 
     241      230648 :         ext = talloc_zero_size(
     242             :                 handle->conn, sizeof(struct vfs_fsp_data) + ext_size);
     243      230648 :         if (ext == NULL) {
     244           0 :                 return NULL;
     245             :         }
     246             : 
     247      230648 :         ext->owner = handle;
     248      230648 :         ext->next = fsp->vfs_extension;
     249      230648 :         ext->destroy = destroy_fn;
     250      230648 :         fsp->vfs_extension = ext;
     251      230648 :         return EXT_DATA_AREA(ext);
     252             : }
     253             : 
     254      167598 : void vfs_remove_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
     255             : {
     256         431 :         struct vfs_fsp_data *curr;
     257         431 :         struct vfs_fsp_data *prev;
     258             : 
     259      167598 :         for (curr = fsp->vfs_extension, prev = NULL;
     260      168012 :              curr;
     261         414 :              prev = curr, curr = curr->next) {
     262      168012 :                 if (curr->owner == handle) {
     263      167598 :                     if (prev) {
     264         414 :                             prev->next = curr->next;
     265             :                     } else {
     266      167184 :                             fsp->vfs_extension = curr->next;
     267             :                     }
     268      167598 :                     if (curr->destroy) {
     269        1464 :                             curr->destroy(EXT_DATA_AREA(curr));
     270             :                     }
     271      167598 :                     TALLOC_FREE(curr);
     272      167598 :                     return;
     273             :                 }
     274             :         }
     275             : }
     276             : 
     277     6268707 : void vfs_remove_all_fsp_extensions(files_struct *fsp)
     278             : {
     279       32284 :         struct vfs_fsp_data *curr;
     280       32284 :         struct vfs_fsp_data *next;
     281             : 
     282     6331705 :         for (curr = fsp->vfs_extension; curr; curr = next) {
     283             : 
     284       62998 :                 next = curr->next;
     285       62998 :                 fsp->vfs_extension = next;
     286             : 
     287       62998 :                 if (curr->destroy) {
     288        4676 :                         curr->destroy(EXT_DATA_AREA(curr));
     289             :                 }
     290       62998 :                 TALLOC_FREE(curr);
     291             :         }
     292     6268707 : }
     293             : 
     294      901715 : void *vfs_memctx_fsp_extension(vfs_handle_struct *handle,
     295             :                                const struct files_struct *fsp)
     296             : {
     297         946 :         struct vfs_fsp_data *head;
     298             : 
     299     1096961 :         for (head = fsp->vfs_extension; head; head = head->next) {
     300      541835 :                 if (head->owner == handle) {
     301      346589 :                         return head;
     302             :                 }
     303             :         }
     304             : 
     305      554691 :         return NULL;
     306             : }
     307             : 
     308      831875 : void *vfs_fetch_fsp_extension(vfs_handle_struct *handle,
     309             :                               const struct files_struct *fsp)
     310             : {
     311         946 :         struct vfs_fsp_data *head;
     312             : 
     313      831875 :         head = (struct vfs_fsp_data *)vfs_memctx_fsp_extension(handle, fsp);
     314      831875 :         if (head != NULL) {
     315      276749 :                 return EXT_DATA_AREA(head);
     316             :         }
     317             : 
     318      554691 :         return NULL;
     319             : }
     320             : 
     321             : #undef EXT_DATA_AREA
     322             : 
     323             : /*
     324             :  * Ensure this module catches all VFS functions.
     325             :  */
     326             : #ifdef DEVELOPER
     327       95798 : void smb_vfs_assert_all_fns(const struct vfs_fn_pointers* fns,
     328             :                             const char *module)
     329             : {
     330       95798 :         bool missing_fn = false;
     331        1494 :         unsigned int idx;
     332       95798 :         const uintptr_t *end = (const uintptr_t *)(fns + 1);
     333             : 
     334     9484002 :         for (idx = 0; ((const uintptr_t *)fns + idx) < end; idx++) {
     335     9388204 :                 if (*((const uintptr_t *)fns + idx) == 0) {
     336           0 :                         DBG_ERR("VFS function at index %d not implemented "
     337             :                                 "in module %s\n", idx, module);
     338           0 :                         missing_fn = true;
     339             :                 }
     340             :         }
     341             : 
     342       95798 :         if (missing_fn) {
     343           0 :                 smb_panic("Required VFS function not implemented in module.\n");
     344             :         }
     345       95798 : }
     346             : #else
     347             : void smb_vfs_assert_all_fns(const struct vfs_fn_pointers* fns,
     348             :                             const char *module)
     349             : {
     350             : }
     351             : #endif
     352             : 
     353             : /*****************************************************************
     354             :  Generic VFS init.
     355             : ******************************************************************/
     356             : 
     357       56433 : bool smbd_vfs_init(connection_struct *conn)
     358             : {
     359         874 :         const char **vfs_objects;
     360       56433 :         unsigned int i = 0;
     361       56433 :         int j = 0;
     362             : 
     363             :         /* Normal share - initialise with disk access functions */
     364       56433 :         vfs_init_default(conn);
     365             : 
     366             :         /* No need to load vfs modules for printer connections */
     367       56433 :         if (conn->printer) {
     368          28 :                 return True;
     369             :         }
     370             : 
     371       56405 :         if (lp_widelinks(SNUM(conn))) {
     372             :                 /*
     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
     377             :                  * needed.
     378             :                  */
     379         230 :                 bool ok = vfs_init_custom(conn, "widelinks");
     380         230 :                 if (!ok) {
     381           0 :                         DBG_ERR("widelinks enabled and vfs_init_custom "
     382             :                                 "failed for vfs_widelinks module\n");
     383           0 :                         return false;
     384             :                 }
     385             :         }
     386             : 
     387       56405 :         vfs_objects = lp_vfs_objects(SNUM(conn));
     388             : 
     389             :         /* Override VFS functions if 'vfs object' was not specified*/
     390       56405 :         if (!vfs_objects || !vfs_objects[0])
     391          39 :                 return True;
     392             : 
     393      363806 :         for (i=0; vfs_objects[i] ;) {
     394      307440 :                 i++;
     395             :         }
     396             : 
     397      363806 :         for (j=i-1; j >= 0; j--) {
     398      307440 :                 if (!vfs_init_custom(conn, vfs_objects[j])) {
     399           0 :                         DEBUG(0, ("smbd_vfs_init: vfs_init_custom failed for %s\n", vfs_objects[j]));
     400           0 :                         return False;
     401             :                 }
     402             :         }
     403       55492 :         return True;
     404             : }
     405             : 
     406             : /*******************************************************************
     407             :  Check if a file exists in the vfs.
     408             : ********************************************************************/
     409             : 
     410          16 : NTSTATUS vfs_file_exist(connection_struct *conn, struct smb_filename *smb_fname)
     411             : {
     412             :         /* Only return OK if stat was successful and S_ISREG */
     413          16 :         if ((SMB_VFS_STAT(conn, smb_fname) != -1) &&
     414          16 :             S_ISREG(smb_fname->st.st_ex_mode)) {
     415          16 :                 return NT_STATUS_OK;
     416             :         }
     417             : 
     418           0 :         return NT_STATUS_OBJECT_NAME_NOT_FOUND;
     419             : }
     420             : 
     421       17143 : bool vfs_valid_pread_range(off_t offset, size_t length)
     422             : {
     423       17143 :         return sys_valid_io_range(offset, length);
     424             : }
     425             : 
     426      193104 : bool vfs_valid_pwrite_range(off_t offset, size_t length)
     427             : {
     428             :         /*
     429             :          * See MAXFILESIZE in [MS-FSA] 2.1.5.3 Server Requests a Write
     430             :          */
     431         113 :         static const uint64_t maxfilesize = 0xfffffff0000;
     432         113 :         uint64_t last_byte_ofs;
     433         113 :         bool ok;
     434             : 
     435      193104 :         ok = sys_valid_io_range(offset, length);
     436      193104 :         if (!ok) {
     437          36 :                 return false;
     438             :         }
     439             : 
     440      193068 :         if (length == 0) {
     441         663 :                 return true;
     442             :         }
     443             : 
     444      192368 :         last_byte_ofs = offset + length;
     445      192368 :         if (last_byte_ofs > maxfilesize) {
     446           6 :                 return false;
     447             :         }
     448             : 
     449      192286 :         return true;
     450             : }
     451             : 
     452        3336 : ssize_t vfs_pwrite_data(struct smb_request *req,
     453             :                         files_struct *fsp,
     454             :                         const char *buffer,
     455             :                         size_t N,
     456             :                         off_t offset)
     457             : {
     458        3336 :         size_t total=0;
     459          12 :         ssize_t ret;
     460          12 :         bool ok;
     461             : 
     462        3336 :         ok = vfs_valid_pwrite_range(offset, N);
     463        3336 :         if (!ok) {
     464           0 :                 errno = EINVAL;
     465           0 :                 return -1;
     466             :         }
     467             : 
     468        3336 :         if (req && req->unread_bytes) {
     469           0 :                 int sockfd = req->xconn->transport.sock;
     470           0 :                 SMB_ASSERT(req->unread_bytes == N);
     471             :                 /* VFS_RECVFILE must drain the socket
     472             :                  * before returning. */
     473           0 :                 req->unread_bytes = 0;
     474             :                 /*
     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
     479             :                  * the RECVFILE.
     480             :                  */
     481           0 :                 while (total < N) {
     482           0 :                         ret = SMB_VFS_RECVFILE(sockfd,
     483             :                                                 fsp,
     484             :                                                 offset + total,
     485             :                                                 N - total);
     486           0 :                         if (ret == 0 || (ret == -1 &&
     487           0 :                                          (errno == EAGAIN ||
     488           0 :                                           errno == EWOULDBLOCK))) {
     489           0 :                                 int old_flags;
     490             :                                 /* Ensure the socket is blocking. */
     491           0 :                                 old_flags = fcntl(sockfd, F_GETFL, 0);
     492           0 :                                 if (set_blocking(sockfd, true) == -1) {
     493           0 :                                         return (ssize_t)-1;
     494             :                                 }
     495           0 :                                 ret = SMB_VFS_RECVFILE(sockfd,
     496             :                                                         fsp,
     497             :                                                         offset + total,
     498             :                                                         N - total);
     499           0 :                                 if (fcntl(sockfd, F_SETFL, old_flags) == -1) {
     500           0 :                                         return (ssize_t)-1;
     501             :                                 }
     502           0 :                                 if (ret == -1) {
     503           0 :                                         return (ssize_t)-1;
     504             :                                 }
     505           0 :                                 total += ret;
     506           0 :                                 return (ssize_t)total;
     507             :                         }
     508             :                         /* Any other error case. */
     509           0 :                         if (ret == -1) {
     510           0 :                                 return ret;
     511             :                         }
     512           0 :                         total += ret;
     513             :                 }
     514           0 :                 return (ssize_t)total;
     515             :         }
     516             : 
     517        4468 :         while (total < N) {
     518        3336 :                 ret = SMB_VFS_PWRITE(fsp, buffer + total, N - total,
     519             :                                      offset + total);
     520             : 
     521        3336 :                 if (ret == -1)
     522        2204 :                         return -1;
     523        1132 :                 if (ret == 0)
     524           0 :                         return total;
     525             : 
     526        1132 :                 total += ret;
     527             :         }
     528        1132 :         return (ssize_t)total;
     529             : }
     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             : ****************************************************************************/
     535             : 
     536         286 : int vfs_allocate_file_space(files_struct *fsp, uint64_t len)
     537             : {
     538          25 :         int ret;
     539         286 :         connection_struct *conn = fsp->conn;
     540          25 :         uint64_t space_avail;
     541          25 :         uint64_t bsize,dfree,dsize;
     542          25 :         NTSTATUS status;
     543          25 :         bool ok;
     544             : 
     545             :         /*
     546             :          * Actually try and commit the space on disk....
     547             :          */
     548             : 
     549         286 :         DEBUG(10,("vfs_allocate_file_space: file %s, len %.0f\n",
     550             :                   fsp_str_dbg(fsp), (double)len));
     551             : 
     552         286 :         ok = vfs_valid_pwrite_range((off_t)len, 0);
     553         286 :         if (!ok) {
     554           0 :                 DEBUG(0,("vfs_allocate_file_space: %s negative/invalid len "
     555             :                          "requested.\n", fsp_str_dbg(fsp)));
     556           0 :                 errno = EINVAL;
     557           0 :                 return -1;
     558             :         }
     559             : 
     560         286 :         status = vfs_stat_fsp(fsp);
     561         286 :         if (!NT_STATUS_IS_OK(status)) {
     562           0 :                 return -1;
     563             :         }
     564             : 
     565         286 :         if (len == (uint64_t)fsp->fsp_name->st.st_ex_size)
     566          44 :                 return 0;
     567             : 
     568         241 :         if (len < (uint64_t)fsp->fsp_name->st.st_ex_size) {
     569             :                 /* Shrink - use ftruncate. */
     570             : 
     571           6 :                 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));
     574             : 
     575           6 :                 contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_SHRINK);
     576             : 
     577           6 :                 ret = SMB_VFS_FTRUNCATE(fsp, (off_t)len);
     578             : 
     579           6 :                 contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_SHRINK);
     580             : 
     581           6 :                 return ret;
     582             :         }
     583             : 
     584             :         /* Grow - we need to test if we have enough space. */
     585             : 
     586         235 :         contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_GROW);
     587             : 
     588         235 :         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           0 :                 ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_FL_KEEP_SIZE,
     592             :                                         0, len);
     593             :         } else {
     594         211 :                 ret = 0;
     595             :         }
     596             : 
     597         235 :         contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_GROW);
     598             : 
     599         235 :         if (ret == 0) {
     600             :                 /* We changed the allocation size on disk, but not
     601             :                    EOF - exactly as required. We're done ! */
     602         211 :                 return 0;
     603             :         }
     604             : 
     605           0 :         if (ret == -1 && errno == ENOSPC) {
     606           0 :                 return -1;
     607             :         }
     608             : 
     609           0 :         len -= fsp->fsp_name->st.st_ex_size;
     610           0 :         len /= 1024; /* Len is now number of 1k blocks needed. */
     611           0 :         space_avail =
     612           0 :             get_dfree_info(conn, fsp->fsp_name, &bsize, &dfree, &dsize);
     613           0 :         if (space_avail == (uint64_t)-1) {
     614           0 :                 return -1;
     615             :         }
     616             : 
     617           0 :         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));
     621             : 
     622           0 :         if (len > space_avail) {
     623           0 :                 errno = ENOSPC;
     624           0 :                 return -1;
     625             :         }
     626             : 
     627           0 :         return 0;
     628             : }
     629             : 
     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             : ****************************************************************************/
     635             : 
     636         392 : int vfs_set_filelen(files_struct *fsp, off_t len)
     637             : {
     638          10 :         int ret;
     639          10 :         bool ok;
     640             : 
     641         392 :         ok = vfs_valid_pwrite_range(len, 0);
     642         392 :         if (!ok) {
     643           0 :                 errno = EINVAL;
     644           0 :                 return -1;
     645             :         }
     646             : 
     647         392 :         contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_SET_FILE_LEN);
     648             : 
     649         392 :         DEBUG(10,("vfs_set_filelen: ftruncate %s to len %.0f\n",
     650             :                   fsp_str_dbg(fsp), (double)len));
     651         392 :         if ((ret = SMB_VFS_FTRUNCATE(fsp, len)) != -1) {
     652         384 :                 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
     653             :                              FILE_NOTIFY_CHANGE_SIZE
     654             :                              | FILE_NOTIFY_CHANGE_ATTRIBUTES,
     655         384 :                              fsp->fsp_name->base_name);
     656             :         }
     657             : 
     658         392 :         contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_SET_FILE_LEN);
     659             : 
     660         392 :         return ret;
     661             : }
     662             : 
     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             : ****************************************************************************/
     670             : 
     671             : #define SPARSE_BUF_WRITE_SIZE (32*1024)
     672             : 
     673           0 : int vfs_slow_fallocate(files_struct *fsp, off_t offset, off_t len)
     674             : {
     675           0 :         ssize_t pwrite_ret;
     676           0 :         size_t total = 0;
     677           0 :         bool ok;
     678             : 
     679           0 :         ok = vfs_valid_pwrite_range(offset, len);
     680           0 :         if (!ok) {
     681           0 :                 errno = EINVAL;
     682           0 :                 return -1;
     683             :         }
     684             : 
     685           0 :         if (!sparse_buf) {
     686           0 :                 sparse_buf = SMB_CALLOC_ARRAY(char, SPARSE_BUF_WRITE_SIZE);
     687           0 :                 if (!sparse_buf) {
     688           0 :                         errno = ENOMEM;
     689           0 :                         return -1;
     690             :                 }
     691             :         }
     692             : 
     693           0 :         while (total < len) {
     694           0 :                 size_t curr_write_size = MIN(SPARSE_BUF_WRITE_SIZE, (len - total));
     695             : 
     696           0 :                 pwrite_ret = SMB_VFS_PWRITE(fsp, sparse_buf, curr_write_size, offset + total);
     697           0 :                 if (pwrite_ret == -1) {
     698           0 :                         int saved_errno = errno;
     699           0 :                         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)));
     702           0 :                         errno = saved_errno;
     703           0 :                         return -1;
     704             :                 }
     705           0 :                 total += pwrite_ret;
     706             :         }
     707             : 
     708           0 :         return 0;
     709             : }
     710             : 
     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             : ****************************************************************************/
     717             : 
     718           0 : int vfs_fill_sparse(files_struct *fsp, off_t len)
     719             : {
     720           0 :         int ret;
     721           0 :         NTSTATUS status;
     722           0 :         off_t offset;
     723           0 :         size_t num_to_write;
     724           0 :         bool ok;
     725             : 
     726           0 :         ok = vfs_valid_pwrite_range(len, 0);
     727           0 :         if (!ok) {
     728           0 :                 errno = EINVAL;
     729           0 :                 return -1;
     730             :         }
     731             : 
     732           0 :         status = vfs_stat_fsp(fsp);
     733           0 :         if (!NT_STATUS_IS_OK(status)) {
     734           0 :                 return -1;
     735             :         }
     736             : 
     737           0 :         if (len <= fsp->fsp_name->st.st_ex_size) {
     738           0 :                 return 0;
     739             :         }
     740             : 
     741             : #ifdef S_ISFIFO
     742           0 :         if (S_ISFIFO(fsp->fsp_name->st.st_ex_mode)) {
     743           0 :                 return 0;
     744             :         }
     745             : #endif
     746             : 
     747           0 :         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)));
     751             : 
     752           0 :         contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_FILL_SPARSE);
     753             : 
     754           0 :         offset = fsp->fsp_name->st.st_ex_size;
     755           0 :         num_to_write = len - fsp->fsp_name->st.st_ex_size;
     756             : 
     757             :         /* Only do this on non-stream file handles. */
     758           0 :         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           0 :                 ret = SMB_VFS_FALLOCATE(fsp, 0, offset, num_to_write);
     765           0 :                 if (ret == -1 && errno == ENOSPC) {
     766           0 :                         goto out;
     767             :                 }
     768           0 :                 if (ret == 0) {
     769           0 :                         goto out;
     770             :                 }
     771           0 :                 DEBUG(10,("vfs_fill_sparse: SMB_VFS_FALLOCATE failed with "
     772             :                         "error %d. Falling back to slow manual allocation\n", ret));
     773             :         }
     774             : 
     775           0 :         ret = vfs_slow_fallocate(fsp, offset, num_to_write);
     776             : 
     777           0 :  out:
     778             : 
     779           0 :         contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_FILL_SPARSE);
     780           0 :         return ret;
     781             : }
     782             : 
     783             : /*******************************************************************************
     784             :  Set a fd into blocking/nonblocking mode through VFS
     785             : *******************************************************************************/
     786             : 
     787      190971 : int vfs_set_blocking(files_struct *fsp, bool set)
     788             : {
     789         449 :         int val;
     790             : #ifdef O_NONBLOCK
     791             : #define FLAG_TO_SET O_NONBLOCK
     792             : #else
     793             : #ifdef SYSV
     794             : #define FLAG_TO_SET O_NDELAY
     795             : #else /* BSD */
     796             : #define FLAG_TO_SET FNDELAY
     797             : #endif
     798             : #endif
     799             : 
     800      190971 :         if (fsp->fsp_flags.is_pathref) {
     801           0 :                 return 0;
     802             :         }
     803             : 
     804      190971 :         val = SMB_VFS_FCNTL(fsp, F_GETFL, 0);
     805      190971 :         if (val == -1) {
     806           0 :                 return -1;
     807             :         }
     808             : 
     809      190971 :         if (set) {
     810      190971 :                 val &= ~FLAG_TO_SET;
     811             :         } else {
     812           0 :                 val |= FLAG_TO_SET;
     813             :         }
     814             : 
     815      190971 :         return SMB_VFS_FCNTL(fsp, F_SETFL, val);
     816             : #undef FLAG_TO_SET
     817             : }
     818             : 
     819             : /****************************************************************************
     820             :  Transfer some data (n bytes) between two file_struct's.
     821             : ****************************************************************************/
     822             : 
     823          26 : static ssize_t vfs_pread_fn(void *file, void *buf, size_t len, off_t offset)
     824             : {
     825          26 :         struct files_struct *fsp = (struct files_struct *)file;
     826             : 
     827          26 :         return SMB_VFS_PREAD(fsp, buf, len, offset);
     828             : }
     829             : 
     830          26 : static ssize_t vfs_pwrite_fn(void *file, const void *buf, size_t len, off_t offset)
     831             : {
     832          26 :         struct files_struct *fsp = (struct files_struct *)file;
     833             : 
     834          26 :         return SMB_VFS_PWRITE(fsp, buf, len, offset);
     835             : }
     836             : 
     837          26 : off_t vfs_transfer_file(files_struct *in, files_struct *out, off_t n)
     838             : {
     839          26 :         return transfer_file_internal((void *)in, (void *)out, n,
     840             :                                       vfs_pread_fn, vfs_pwrite_fn);
     841             : }
     842             : 
     843             : /*******************************************************************
     844             :  A vfs_readdir wrapper which just returns the file name.
     845             : ********************************************************************/
     846             : 
     847   160968666 : const char *vfs_readdirname(connection_struct *conn,
     848             :                             struct files_struct *dirfsp,
     849             :                             void *p,
     850             :                             char **talloced)
     851             : {
     852   160968666 :         struct dirent *ptr= NULL;
     853        7202 :         const char *dname;
     854        7202 :         char *translated;
     855        7202 :         NTSTATUS status;
     856             : 
     857   160968666 :         if (!p)
     858           0 :                 return(NULL);
     859             : 
     860   160968666 :         ptr = SMB_VFS_READDIR(conn, dirfsp, (DIR *)p);
     861   160968666 :         if (!ptr)
     862      305658 :                 return(NULL);
     863             : 
     864   160661972 :         dname = ptr->d_name;
     865             : 
     866   160661972 :         status = SMB_VFS_TRANSLATE_NAME(conn, dname, vfs_translate_to_windows,
     867             :                                         talloc_tos(), &translated);
     868   160661972 :         if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
     869   160622452 :                 *talloced = NULL;
     870   160622452 :                 return dname;
     871             :         }
     872       39520 :         *talloced = translated;
     873       39520 :         if (!NT_STATUS_IS_OK(status)) {
     874           0 :                 return NULL;
     875             :         }
     876       39520 :         return translated;
     877             : }
     878             : 
     879             : /*******************************************************************
     880             :  A wrapper for vfs_chdir().
     881             : ********************************************************************/
     882             : 
     883     3170626 : int vfs_ChDir(connection_struct *conn, const struct smb_filename *smb_fname)
     884             : {
     885       18944 :         int ret;
     886     3170626 :         struct smb_filename *cwd = NULL;
     887             : 
     888     3170626 :         if (!LastDir) {
     889      973854 :                 LastDir = SMB_STRDUP("");
     890             :         }
     891             : 
     892     3170626 :         if (ISDOT(smb_fname->base_name)) {
     893             :                 /*
     894             :                  * passing a '.' is a noop,
     895             :                  * and we only expect this after
     896             :                  * everything is initialized.
     897             :                  *
     898             :                  * So the first vfs_ChDir() on a given
     899             :                  * connection_struct must not be '.'.
     900             :                  *
     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
     905             :                  * on success!
     906             :                  */
     907           0 :                 if (fsp_get_pathref_fd(conn->cwd_fsp) != AT_FDCWD) {
     908             :                         /*
     909             :                          * This should never happen and
     910             :                          * we might change this to
     911             :                          * SMB_ASSERT() in future.
     912             :                          */
     913           0 :                         DBG_ERR("Called with '.' as first operation!\n");
     914           0 :                         log_stack_trace();
     915           0 :                         errno = EINVAL;
     916           0 :                         return -1;
     917             :                 }
     918           0 :                 return 0;
     919             :         }
     920             : 
     921     6020326 :         if (smb_fname->base_name[0] == '/' &&
     922     2849700 :             strcsequal(LastDir,smb_fname->base_name))
     923             :         {
     924             :                 /*
     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().
     928             :                  *
     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).
     932             :                  */
     933     1373761 :                 fsp_set_fd(conn->cwd_fsp, AT_FDCWD);
     934     1373761 :                 return 0;
     935             :         }
     936             : 
     937     1796865 :         DEBUG(4,("vfs_ChDir to %s\n", smb_fname->base_name));
     938             : 
     939     1796865 :         ret = SMB_VFS_CHDIR(conn, smb_fname);
     940     1796865 :         if (ret != 0) {
     941       16850 :                 return -1;
     942             :         }
     943             : 
     944             :         /*
     945             :          * Always replace conn->cwd_fsp. We
     946             :          * don't know if it's been modified by
     947             :          * VFS modules in the stack.
     948             :          */
     949     1779998 :         fsp_set_fd(conn->cwd_fsp, AT_FDCWD);
     950             : 
     951             :         /* conn cache. */
     952     1779998 :         cwd = vfs_GetWd(conn, conn);
     953     1779998 :         if (cwd == NULL) {
     954             :                 /*
     955             :                  * vfs_GetWd() failed.
     956             :                  * We must be able to read cwd.
     957             :                  * Return to original directory
     958             :                  * and return -1.
     959             :                  */
     960           0 :                 int saved_errno = errno;
     961             : 
     962           0 :                 if (conn->cwd_fsp->fsp_name == NULL) {
     963             :                         /*
     964             :                          * Failed on the very first chdir()+getwd()
     965             :                          * for this connection. We can't
     966             :                          * continue.
     967             :                          */
     968           0 :                         smb_panic("conn->cwd getwd failed\n");
     969             :                         /* NOTREACHED */
     970             :                         return -1;
     971             :                 }
     972             : 
     973             :                 /* Return to the previous $cwd. */
     974           0 :                 ret = SMB_VFS_CHDIR(conn, conn->cwd_fsp->fsp_name);
     975           0 :                 if (ret != 0) {
     976           0 :                         smb_panic("conn->cwd getwd failed\n");
     977             :                         /* NOTREACHED */
     978             :                         return -1;
     979             :                 }
     980           0 :                 errno = saved_errno;
     981             :                 /* And fail the chdir(). */
     982           0 :                 return -1;
     983             :         }
     984             : 
     985             :         /* vfs_GetWd() succeeded. */
     986             :         /* Replace global cache. */
     987     1779998 :         SAFE_FREE(LastDir);
     988     1779998 :         LastDir = SMB_STRDUP(smb_fname->base_name);
     989             : 
     990             :         /*
     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.
     994             :          */
     995     1779998 :         talloc_move(talloc_tos(), &conn->cwd_fsp->fsp_name);
     996             : 
     997     1779998 :         conn->cwd_fsp->fsp_name = talloc_move(conn->cwd_fsp, &cwd);
     998             : 
     999     1779998 :         DBG_INFO("vfs_ChDir got %s\n", fsp_str_dbg(conn->cwd_fsp));
    1000             : 
    1001     1775669 :         return ret;
    1002             : }
    1003             : 
    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             : ********************************************************************/
    1009             : 
    1010     2407428 : struct smb_filename *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
    1011             : {
    1012     2407428 :         struct smb_filename *current_dir_fname = NULL;
    1013        4592 :         struct file_id key;
    1014     2407428 :         struct smb_filename *smb_fname_dot = NULL;
    1015     2407428 :         struct smb_filename *smb_fname_full = NULL;
    1016     2407428 :         struct smb_filename *result = NULL;
    1017             : 
    1018     2407428 :         if (!lp_getwd_cache()) {
    1019           0 :                 goto nocache;
    1020             :         }
    1021             : 
    1022     2407428 :         smb_fname_dot = synthetic_smb_fname(ctx,
    1023             :                                             ".",
    1024             :                                             NULL,
    1025             :                                             NULL,
    1026             :                                             0,
    1027             :                                             0);
    1028     2407428 :         if (smb_fname_dot == NULL) {
    1029           0 :                 errno = ENOMEM;
    1030           0 :                 goto out;
    1031             :         }
    1032             : 
    1033     2407428 :         if (SMB_VFS_STAT(conn, smb_fname_dot) == -1) {
    1034             :                 /*
    1035             :                  * Known to fail for root: the directory may be NFS-mounted
    1036             :                  * and exported with root_squash (so has no root access).
    1037             :                  */
    1038           0 :                 DEBUG(1,("vfs_GetWd: couldn't stat \".\" error %s "
    1039             :                          "(NFS problem ?)\n", strerror(errno) ));
    1040           0 :                 goto nocache;
    1041             :         }
    1042             : 
    1043     2407428 :         key = vfs_file_id_from_sbuf(conn, &smb_fname_dot->st);
    1044             : 
    1045     2407428 :         smb_fname_full = (struct smb_filename *)memcache_lookup_talloc(
    1046             :                                         smbd_memcache(),
    1047             :                                         GETWD_CACHE,
    1048             :                                         data_blob_const(&key, sizeof(key)));
    1049             : 
    1050     2407428 :         if (smb_fname_full == NULL) {
    1051       76292 :                 goto nocache;
    1052             :         }
    1053             : 
    1054     2331136 :         if ((SMB_VFS_STAT(conn, smb_fname_full) == 0) &&
    1055     2330954 :             (smb_fname_dot->st.st_ex_dev == smb_fname_full->st.st_ex_dev) &&
    1056     2330954 :             (smb_fname_dot->st.st_ex_ino == smb_fname_full->st.st_ex_ino) &&
    1057     2330954 :             (S_ISDIR(smb_fname_dot->st.st_ex_mode))) {
    1058             :                 /*
    1059             :                  * Ok, we're done
    1060             :                  * Note: smb_fname_full is owned by smbd_memcache()
    1061             :                  * so we must make a copy to return.
    1062             :                  */
    1063     2330954 :                 result = cp_smb_filename(ctx, smb_fname_full);
    1064     2330954 :                 if (result == NULL) {
    1065           0 :                         errno = ENOMEM;
    1066             :                 }
    1067     2330954 :                 goto out;
    1068             :         }
    1069             : 
    1070         182 :  nocache:
    1071             : 
    1072             :         /*
    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.
    1076             :          */
    1077             : 
    1078       76474 :         current_dir_fname = SMB_VFS_GETWD(conn, ctx);
    1079       76474 :         if (current_dir_fname == NULL) {
    1080           0 :                 DEBUG(0, ("vfs_GetWd: SMB_VFS_GETWD call failed: %s\n",
    1081             :                           strerror(errno)));
    1082           0 :                 goto out;
    1083             :         }
    1084             : 
    1085       76474 :         if (lp_getwd_cache() && VALID_STAT(smb_fname_dot->st)) {
    1086       76474 :                 key = vfs_file_id_from_sbuf(conn, &smb_fname_dot->st);
    1087             : 
    1088             :                 /*
    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.
    1092             :                  */
    1093       76474 :                 result = cp_smb_filename(ctx, current_dir_fname);
    1094       76474 :                 if (result == NULL) {
    1095           0 :                         errno = ENOMEM;
    1096             :                 }
    1097             : 
    1098             :                 /*
    1099             :                  * Ensure the memory going into the cache
    1100             :                  * doesn't have a destructor so it can be
    1101             :                  * cleanly freed.
    1102             :                  */
    1103       76474 :                 talloc_set_destructor(current_dir_fname, NULL);
    1104             : 
    1105       76474 :                 memcache_add_talloc(smbd_memcache(),
    1106             :                                 GETWD_CACHE,
    1107             :                                 data_blob_const(&key, sizeof(key)),
    1108             :                                 &current_dir_fname);
    1109             :                 /* current_dir_fname is now == NULL here. */
    1110             :         } else {
    1111             :                 /* current_dir_fname is already allocated on ctx. */
    1112           0 :                 result = current_dir_fname;
    1113             :         }
    1114             : 
    1115     2407428 :  out:
    1116     2407428 :         TALLOC_FREE(smb_fname_dot);
    1117             :         /*
    1118             :          * Don't free current_dir_fname here. It's either been moved
    1119             :          * to the memcache or is being returned in result.
    1120             :          */
    1121     2407428 :         return result;
    1122             : }
    1123             : 
    1124             : /*
    1125             :  * Ensure LSTAT is called for POSIX paths.
    1126             :  */
    1127       36488 : int vfs_stat(struct connection_struct *conn,
    1128             :              struct smb_filename *smb_fname)
    1129             : {
    1130       36488 :         if (smb_fname->flags & SMB_FILENAME_POSIX_PATH) {
    1131          88 :                 return SMB_VFS_LSTAT(conn, smb_fname);
    1132             :         }
    1133       36400 :         return SMB_VFS_STAT(conn, smb_fname);
    1134             : }
    1135             : 
    1136             : /**
    1137             :  * XXX: This is temporary and there should be no callers of this once
    1138             :  * smb_filename is plumbed through all path based operations.
    1139             :  *
    1140             :  * Called when we know stream name parsing has already been done.
    1141             :  */
    1142           0 : int vfs_stat_smb_basename(struct connection_struct *conn,
    1143             :                         const struct smb_filename *smb_fname_in,
    1144             :                         SMB_STRUCT_STAT *psbuf)
    1145             : {
    1146           0 :         struct smb_filename smb_fname = {
    1147           0 :                 .base_name = discard_const_p(char, smb_fname_in->base_name),
    1148           0 :                 .flags = smb_fname_in->flags,
    1149           0 :                 .twrp = smb_fname_in->twrp,
    1150             :         };
    1151           0 :         int ret;
    1152             : 
    1153           0 :         ret = vfs_stat(conn, &smb_fname);
    1154           0 :         if (ret != -1) {
    1155           0 :                 *psbuf = smb_fname.st;
    1156             :         }
    1157           0 :         return ret;
    1158             : }
    1159             : 
    1160             : /**
    1161             :  * Ensure LSTAT is called for POSIX paths.
    1162             :  */
    1163             : 
    1164     3455964 : NTSTATUS vfs_stat_fsp(files_struct *fsp)
    1165             : {
    1166       14118 :         int ret;
    1167     3455964 :         struct stat_ex saved_stat = fsp->fsp_name->st;
    1168             : 
    1169     3455964 :         if (fsp->fake_file_handle != NULL) {
    1170           0 :                 return NT_STATUS_OK;
    1171             :         }
    1172             : 
    1173     3455964 :         if (fsp_get_pathref_fd(fsp) == -1) {
    1174          67 :                 if (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) {
    1175          67 :                         ret = SMB_VFS_LSTAT(fsp->conn, fsp->fsp_name);
    1176             :                 } else {
    1177           0 :                         ret = SMB_VFS_STAT(fsp->conn, fsp->fsp_name);
    1178             :                 }
    1179             :         } else {
    1180     3455897 :                 ret = SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st);
    1181             :         }
    1182     3455964 :         if (ret == -1) {
    1183           2 :                 return map_nt_error_from_unix(errno);
    1184             :         }
    1185     3455962 :         update_stat_ex_from_saved_stat(&fsp->fsp_name->st, &saved_stat);
    1186     3455962 :         fsp->fsp_flags.is_directory = S_ISDIR(fsp->fsp_name->st.st_ex_mode);
    1187     3455962 :         return NT_STATUS_OK;
    1188             : }
    1189             : 
    1190      369156 : void init_smb_file_time(struct smb_file_time *ft)
    1191             : {
    1192      369972 :         *ft = (struct smb_file_time) {
    1193      369156 :                 .atime = make_omit_timespec(),
    1194      369156 :                 .ctime = make_omit_timespec(),
    1195      369156 :                 .mtime = make_omit_timespec(),
    1196      369156 :                 .create_time = make_omit_timespec()
    1197             :         };
    1198      369156 : }
    1199             : 
    1200             : /**
    1201             :  * Initialize num_streams and streams, then call VFS op streaminfo
    1202             :  */
    1203             : 
    1204      317119 : NTSTATUS vfs_fstreaminfo(struct files_struct *fsp,
    1205             :                         TALLOC_CTX *mem_ctx,
    1206             :                         unsigned int *num_streams,
    1207             :                         struct stream_struct **streams)
    1208             : {
    1209      317119 :         *num_streams = 0;
    1210      317119 :         *streams = NULL;
    1211             : 
    1212      317119 :         if (fsp == NULL) {
    1213             :                 /*
    1214             :                  * Callers may pass fsp == NULL when passing smb_fname->fsp of a
    1215             :                  * symlink. This is ok, handle it here, by just return no
    1216             :                  * streams on a symlink.
    1217             :                  */
    1218           0 :                 return NT_STATUS_OK;
    1219             :         }
    1220             : 
    1221      317119 :         if (fsp_get_pathref_fd(fsp) == -1) {
    1222             :                 /*
    1223             :                  * No streams on non-real files/directories.
    1224             :                  */
    1225         128 :                 return NT_STATUS_OK;
    1226             :         }
    1227             : 
    1228      316991 :         return SMB_VFS_FSTREAMINFO(fsp,
    1229             :                         mem_ctx,
    1230             :                         num_streams,
    1231             :                         streams);
    1232             : }
    1233             : 
    1234        5416 : int vfs_fake_fd(void)
    1235             : {
    1236           0 :         int pipe_fds[2];
    1237           0 :         int ret;
    1238             : 
    1239             :         /*
    1240             :          * Return a valid fd, but ensure any attempt to use
    1241             :          * it returns an error (EPIPE).
    1242             :          */
    1243        5416 :         ret = pipe(pipe_fds);
    1244        5416 :         if (ret != 0) {
    1245           0 :                 return -1;
    1246             :         }
    1247             : 
    1248        5416 :         close(pipe_fds[1]);
    1249        5416 :         return pipe_fds[0];
    1250             : }
    1251             : 
    1252             : /*
    1253             :  * This is just a helper to make
    1254             :  * users of vfs_fake_fd() more symmetric
    1255             :  */
    1256        5398 : int vfs_fake_fd_close(int fd)
    1257             : {
    1258        5398 :         return close(fd);
    1259             : }
    1260             : 
    1261             : /*
    1262             :   generate a file_id from a stat structure
    1263             :  */
    1264     9036559 : struct file_id vfs_file_id_from_sbuf(connection_struct *conn, const SMB_STRUCT_STAT *sbuf)
    1265             : {
    1266     9036559 :         return SMB_VFS_FILE_ID_CREATE(conn, sbuf);
    1267             : }
    1268             : 
    1269        9661 : NTSTATUS vfs_at_fspcwd(TALLOC_CTX *mem_ctx,
    1270             :                        struct connection_struct *conn,
    1271             :                        struct files_struct **_fsp)
    1272             : {
    1273        9661 :         struct files_struct *fsp = NULL;
    1274             : 
    1275        9661 :         fsp = talloc_zero(mem_ctx, struct files_struct);
    1276        9661 :         if (fsp == NULL) {
    1277           0 :                 return NT_STATUS_NO_MEMORY;
    1278             :         }
    1279             : 
    1280        9661 :         fsp->fsp_name = synthetic_smb_fname(fsp, ".", NULL, NULL, 0, 0);
    1281        9661 :         if (fsp->fsp_name == NULL) {
    1282           0 :                 TALLOC_FREE(fsp);
    1283           0 :                 return NT_STATUS_NO_MEMORY;
    1284             :         }
    1285             : 
    1286        9661 :         fsp->fh = fd_handle_create(fsp);
    1287        9661 :         if (fsp->fh == NULL) {
    1288           0 :                 TALLOC_FREE(fsp);
    1289           0 :                 return NT_STATUS_NO_MEMORY;
    1290             :         }
    1291             : 
    1292        9661 :         fsp_set_fd(fsp, AT_FDCWD);
    1293        9661 :         fsp->fnum = FNUM_FIELD_INVALID;
    1294        9661 :         fsp->conn = conn;
    1295             : 
    1296        9661 :         *_fsp = fsp;
    1297        9661 :         return NT_STATUS_OK;
    1298             : }
    1299             : 
    1300             : static struct smb_vfs_deny_state *smb_vfs_deny_global;
    1301             : 
    1302       14524 : void smb_vfs_assert_allowed(void)
    1303             : {
    1304       14524 :         if (unlikely(smb_vfs_deny_global != NULL)) {
    1305           0 :                 DBG_ERR("Called with VFS denied by %s\n",
    1306             :                         smb_vfs_deny_global->location);
    1307           0 :                 smb_panic("Called with VFS denied!");
    1308             :         }
    1309       14524 : }
    1310             : 
    1311     1106527 : void _smb_vfs_deny_push(struct smb_vfs_deny_state *state, const char *location)
    1312             : {
    1313     1106527 :         SMB_ASSERT(smb_vfs_deny_global != state);
    1314             : 
    1315     1106527 :         *state = (struct smb_vfs_deny_state) {
    1316             :                 .parent = smb_vfs_deny_global,
    1317             :                 .location = location,
    1318             :         };
    1319             : 
    1320     1106527 :         smb_vfs_deny_global = state;
    1321     1106527 : }
    1322             : 
    1323     1106527 : void _smb_vfs_deny_pop(struct smb_vfs_deny_state *state, const char *location)
    1324             : {
    1325     1106527 :         SMB_ASSERT(smb_vfs_deny_global == state);
    1326             : 
    1327     1106527 :         smb_vfs_deny_global = state->parent;
    1328             : 
    1329     1106527 :         *state = (struct smb_vfs_deny_state) { .parent = NULL, };
    1330     1106527 : }
    1331             : 
    1332             : #define VFS_FIND(__fn__) do { \
    1333             :         if (unlikely(smb_vfs_deny_global != NULL)) { \
    1334             :                 DBG_ERR("Called with VFS denied by %s\n", \
    1335             :                         smb_vfs_deny_global->location); \
    1336             :                 smb_panic("Called with VFS denied!"); \
    1337             :         } \
    1338             :         while (handle->fns->__fn__##_fn==NULL) { \
    1339             :                 handle = handle->next; \
    1340             :         } \
    1341             : } while(0)
    1342             : 
    1343      311609 : int smb_vfs_call_connect(struct vfs_handle_struct *handle,
    1344             :                          const char *service, const char *user)
    1345             : {
    1346      364169 :         VFS_FIND(connect);
    1347      311609 :         return handle->fns->connect_fn(handle, service, user);
    1348             : }
    1349             : 
    1350      148359 : void smb_vfs_call_disconnect(struct vfs_handle_struct *handle)
    1351             : {
    1352      363845 :         VFS_FIND(disconnect);
    1353      148359 :         handle->fns->disconnect_fn(handle);
    1354      148359 : }
    1355             : 
    1356        3710 : uint64_t smb_vfs_call_disk_free(struct vfs_handle_struct *handle,
    1357             :                                 const struct smb_filename *smb_fname,
    1358             :                                 uint64_t *bsize,
    1359             :                                 uint64_t *dfree,
    1360             :                                 uint64_t *dsize)
    1361             : {
    1362       10009 :         VFS_FIND(disk_free);
    1363        3710 :         return handle->fns->disk_free_fn(handle, smb_fname,
    1364             :                         bsize, dfree, dsize);
    1365             : }
    1366             : 
    1367        7694 : int smb_vfs_call_get_quota(struct vfs_handle_struct *handle,
    1368             :                                 const struct smb_filename *smb_fname,
    1369             :                                 enum SMB_QUOTA_TYPE qtype,
    1370             :                                 unid_t id,
    1371             :                                 SMB_DISK_QUOTA *qt)
    1372             : {
    1373       20742 :         VFS_FIND(get_quota);
    1374        7694 :         return handle->fns->get_quota_fn(handle, smb_fname, qtype, id, qt);
    1375             : }
    1376             : 
    1377          12 : int smb_vfs_call_set_quota(struct vfs_handle_struct *handle,
    1378             :                            enum SMB_QUOTA_TYPE qtype, unid_t id,
    1379             :                            SMB_DISK_QUOTA *qt)
    1380             : {
    1381          28 :         VFS_FIND(set_quota);
    1382          12 :         return handle->fns->set_quota_fn(handle, qtype, id, qt);
    1383             : }
    1384             : 
    1385        3256 : int smb_vfs_call_get_shadow_copy_data(struct vfs_handle_struct *handle,
    1386             :                                       struct files_struct *fsp,
    1387             :                                       struct shadow_copy_data *shadow_copy_data,
    1388             :                                       bool labels)
    1389             : {
    1390        4316 :         VFS_FIND(get_shadow_copy_data);
    1391        3256 :         return handle->fns->get_shadow_copy_data_fn(handle, fsp, 
    1392             :                                                     shadow_copy_data,
    1393             :                                                     labels);
    1394             : }
    1395       68113 : int smb_vfs_call_statvfs(struct vfs_handle_struct *handle,
    1396             :                         const struct smb_filename *smb_fname,
    1397             :                         struct vfs_statvfs_struct *statbuf)
    1398             : {
    1399      186768 :         VFS_FIND(statvfs);
    1400       68113 :         return handle->fns->statvfs_fn(handle, smb_fname, statbuf);
    1401             : }
    1402             : 
    1403       94378 : uint32_t smb_vfs_call_fs_capabilities(struct vfs_handle_struct *handle,
    1404             :                         enum timestamp_set_resolution *p_ts_res)
    1405             : {
    1406      186768 :         VFS_FIND(fs_capabilities);
    1407       94378 :         return handle->fns->fs_capabilities_fn(handle, p_ts_res);
    1408             : }
    1409             : 
    1410       44291 : NTSTATUS smb_vfs_call_get_dfs_referrals(struct vfs_handle_struct *handle,
    1411             :                                         struct dfs_GetDFSReferral *r)
    1412             : {
    1413      103819 :         VFS_FIND(get_dfs_referrals);
    1414       44291 :         return handle->fns->get_dfs_referrals_fn(handle, r);
    1415             : }
    1416             : 
    1417           0 : NTSTATUS smb_vfs_call_create_dfs_pathat(struct vfs_handle_struct *handle,
    1418             :                                 struct files_struct *dirfsp,
    1419             :                                 const struct smb_filename *smb_fname,
    1420             :                                 const struct referral *reflist,
    1421             :                                 size_t referral_count)
    1422             : {
    1423           0 :         VFS_FIND(create_dfs_pathat);
    1424           0 :         return handle->fns->create_dfs_pathat_fn(handle,
    1425             :                                                 dirfsp,
    1426             :                                                 smb_fname,
    1427             :                                                 reflist,
    1428             :                                                 referral_count);
    1429             : }
    1430             : 
    1431       14466 : NTSTATUS smb_vfs_call_read_dfs_pathat(struct vfs_handle_struct *handle,
    1432             :                                 TALLOC_CTX *mem_ctx,
    1433             :                                 struct files_struct *dirfsp,
    1434             :                                 struct smb_filename *smb_fname,
    1435             :                                 struct referral **ppreflist,
    1436             :                                 size_t *preferral_count)
    1437             : {
    1438       33756 :         VFS_FIND(read_dfs_pathat);
    1439       14466 :         return handle->fns->read_dfs_pathat_fn(handle,
    1440             :                                                 mem_ctx,
    1441             :                                                 dirfsp,
    1442             :                                                 smb_fname,
    1443             :                                                 ppreflist,
    1444             :                                                 preferral_count);
    1445             : }
    1446             : 
    1447      621505 : DIR *smb_vfs_call_fdopendir(struct vfs_handle_struct *handle,
    1448             :                                         struct files_struct *fsp,
    1449             :                                         const char *mask,
    1450             :                                         uint32_t attributes)
    1451             : {
    1452     1885459 :         VFS_FIND(fdopendir);
    1453      621505 :         return handle->fns->fdopendir_fn(handle, fsp, mask, attributes);
    1454             : }
    1455             : 
    1456   322270508 : struct dirent *smb_vfs_call_readdir(struct vfs_handle_struct *handle,
    1457             :                                     struct files_struct *dirfsp,
    1458             :                                     DIR *dirp)
    1459             : {
    1460   869881784 :         VFS_FIND(readdir);
    1461   322270508 :         return handle->fns->readdir_fn(handle, dirfsp, dirp);
    1462             : }
    1463             : 
    1464        5088 : void smb_vfs_call_rewind_dir(struct vfs_handle_struct *handle,
    1465             :                              DIR *dirp)
    1466             : {
    1467       15454 :         VFS_FIND(rewind_dir);
    1468        5088 :         handle->fns->rewind_dir_fn(handle, dirp);
    1469        5088 : }
    1470             : 
    1471       37486 : int smb_vfs_call_mkdirat(struct vfs_handle_struct *handle,
    1472             :                         struct files_struct *dirfsp,
    1473             :                         const struct smb_filename *smb_fname,
    1474             :                         mode_t mode)
    1475             : {
    1476       75525 :         VFS_FIND(mkdirat);
    1477       37486 :         return handle->fns->mkdirat_fn(handle,
    1478             :                         dirfsp,
    1479             :                         smb_fname,
    1480             :                         mode);
    1481             : }
    1482             : 
    1483      621505 : int smb_vfs_call_closedir(struct vfs_handle_struct *handle,
    1484             :                           DIR *dir)
    1485             : {
    1486     1885459 :         VFS_FIND(closedir);
    1487      621505 :         return handle->fns->closedir_fn(handle, dir);
    1488             : }
    1489             : 
    1490    25093770 : int smb_vfs_call_openat(struct vfs_handle_struct *handle,
    1491             :                         const struct files_struct *dirfsp,
    1492             :                         const struct smb_filename *smb_fname,
    1493             :                         struct files_struct *fsp,
    1494             :                         const struct vfs_open_how *how)
    1495             : {
    1496    39099002 :         VFS_FIND(openat);
    1497    25093770 :         return handle->fns->openat_fn(handle,
    1498             :                                       dirfsp,
    1499             :                                       smb_fname,
    1500             :                                       fsp,
    1501             :                                       how);
    1502             : }
    1503             : 
    1504     1121106 : NTSTATUS smb_vfs_call_create_file(struct vfs_handle_struct *handle,
    1505             :                                   struct smb_request *req,
    1506             :                                   struct files_struct *dirfsp,
    1507             :                                   struct smb_filename *smb_fname,
    1508             :                                   uint32_t access_mask,
    1509             :                                   uint32_t share_access,
    1510             :                                   uint32_t create_disposition,
    1511             :                                   uint32_t create_options,
    1512             :                                   uint32_t file_attributes,
    1513             :                                   uint32_t oplock_request,
    1514             :                                   const struct smb2_lease *lease,
    1515             :                                   uint64_t allocation_size,
    1516             :                                   uint32_t private_flags,
    1517             :                                   struct security_descriptor *sd,
    1518             :                                   struct ea_list *ea_list,
    1519             :                                   files_struct **result,
    1520             :                                   int *pinfo,
    1521             :                                   const struct smb2_create_blobs *in_context_blobs,
    1522             :                                   struct smb2_create_blobs *out_context_blobs)
    1523             : {
    1524     3375002 :         VFS_FIND(create_file);
    1525     1121106 :         return handle->fns->create_file_fn(
    1526             :                 handle, req, dirfsp, smb_fname,
    1527             :                 access_mask, share_access, create_disposition, create_options,
    1528             :                 file_attributes, oplock_request, lease, allocation_size,
    1529             :                 private_flags, sd, ea_list,
    1530             :                 result, pinfo, in_context_blobs, out_context_blobs);
    1531             : }
    1532             : 
    1533     8632829 : int smb_vfs_call_close(struct vfs_handle_struct *handle,
    1534             :                        struct files_struct *fsp)
    1535             : {
    1536    25902597 :         VFS_FIND(close);
    1537     8632829 :         return handle->fns->close_fn(handle, fsp);
    1538             : }
    1539             : 
    1540       11826 : ssize_t smb_vfs_call_pread(struct vfs_handle_struct *handle,
    1541             :                            struct files_struct *fsp, void *data, size_t n,
    1542             :                            off_t offset)
    1543             : {
    1544       24958 :         VFS_FIND(pread);
    1545       11826 :         return handle->fns->pread_fn(handle, fsp, data, n, offset);
    1546             : }
    1547             : 
    1548             : struct smb_vfs_call_pread_state {
    1549             :         ssize_t (*recv_fn)(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state);
    1550             :         ssize_t retval;
    1551             :         struct vfs_aio_state vfs_aio_state;
    1552             : };
    1553             : 
    1554             : static void smb_vfs_call_pread_done(struct tevent_req *subreq);
    1555             : 
    1556       32597 : struct tevent_req *smb_vfs_call_pread_send(struct vfs_handle_struct *handle,
    1557             :                                            TALLOC_CTX *mem_ctx,
    1558             :                                            struct tevent_context *ev,
    1559             :                                            struct files_struct *fsp,
    1560             :                                            void *data,
    1561             :                                            size_t n, off_t offset)
    1562             : {
    1563          42 :         struct tevent_req *req, *subreq;
    1564          42 :         struct smb_vfs_call_pread_state *state;
    1565             : 
    1566       32597 :         req = tevent_req_create(mem_ctx, &state,
    1567             :                                 struct smb_vfs_call_pread_state);
    1568       32597 :         if (req == NULL) {
    1569           0 :                 return NULL;
    1570             :         }
    1571       83847 :         VFS_FIND(pread_send);
    1572       32597 :         state->recv_fn = handle->fns->pread_recv_fn;
    1573             : 
    1574       32597 :         subreq = handle->fns->pread_send_fn(handle, state, ev, fsp, data, n,
    1575             :                                             offset);
    1576       32597 :         if (tevent_req_nomem(subreq, req)) {
    1577           0 :                 return tevent_req_post(req, ev);
    1578             :         }
    1579       32597 :         tevent_req_set_callback(subreq, smb_vfs_call_pread_done, req);
    1580       32597 :         return req;
    1581             : }
    1582             : 
    1583       32597 : static void smb_vfs_call_pread_done(struct tevent_req *subreq)
    1584             : {
    1585       32597 :         struct tevent_req *req = tevent_req_callback_data(
    1586             :                 subreq, struct tevent_req);
    1587       32597 :         struct smb_vfs_call_pread_state *state = tevent_req_data(
    1588             :                 req, struct smb_vfs_call_pread_state);
    1589             : 
    1590       32597 :         state->retval = state->recv_fn(subreq, &state->vfs_aio_state);
    1591       32597 :         TALLOC_FREE(subreq);
    1592       32597 :         if (state->retval == -1) {
    1593           0 :                 tevent_req_error(req, state->vfs_aio_state.error);
    1594           0 :                 return;
    1595             :         }
    1596       32597 :         tevent_req_done(req);
    1597             : }
    1598             : 
    1599       32597 : ssize_t SMB_VFS_PREAD_RECV(struct tevent_req *req,
    1600             :                            struct vfs_aio_state *vfs_aio_state)
    1601             : {
    1602       32597 :         struct smb_vfs_call_pread_state *state = tevent_req_data(
    1603             :                 req, struct smb_vfs_call_pread_state);
    1604          42 :         ssize_t retval;
    1605             : 
    1606       32597 :         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
    1607           0 :                 tevent_req_received(req);
    1608           0 :                 return -1;
    1609             :         }
    1610       32597 :         *vfs_aio_state = state->vfs_aio_state;
    1611       32597 :         retval = state->retval;
    1612       32597 :         tevent_req_received(req);
    1613       32597 :         return retval;
    1614             : }
    1615             : 
    1616        6404 : ssize_t smb_vfs_call_pwrite(struct vfs_handle_struct *handle,
    1617             :                             struct files_struct *fsp, const void *data,
    1618             :                             size_t n, off_t offset)
    1619             : {
    1620        9412 :         VFS_FIND(pwrite);
    1621        6404 :         return handle->fns->pwrite_fn(handle, fsp, data, n, offset);
    1622             : }
    1623             : 
    1624             : struct smb_vfs_call_pwrite_state {
    1625             :         ssize_t (*recv_fn)(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state);
    1626             :         ssize_t retval;
    1627             :         struct vfs_aio_state vfs_aio_state;
    1628             : };
    1629             : 
    1630             : static void smb_vfs_call_pwrite_done(struct tevent_req *subreq);
    1631             : 
    1632      418508 : struct tevent_req *smb_vfs_call_pwrite_send(struct vfs_handle_struct *handle,
    1633             :                                             TALLOC_CTX *mem_ctx,
    1634             :                                             struct tevent_context *ev,
    1635             :                                             struct files_struct *fsp,
    1636             :                                             const void *data,
    1637             :                                             size_t n, off_t offset)
    1638             : {
    1639          52 :         struct tevent_req *req, *subreq;
    1640          52 :         struct smb_vfs_call_pwrite_state *state;
    1641             : 
    1642      418508 :         req = tevent_req_create(mem_ctx, &state,
    1643             :                                 struct smb_vfs_call_pwrite_state);
    1644      418508 :         if (req == NULL) {
    1645           0 :                 return NULL;
    1646             :         }
    1647     1000041 :         VFS_FIND(pwrite_send);
    1648      418508 :         state->recv_fn = handle->fns->pwrite_recv_fn;
    1649             : 
    1650      418508 :         subreq = handle->fns->pwrite_send_fn(handle, state, ev, fsp, data, n,
    1651             :                                              offset);
    1652      418508 :         if (tevent_req_nomem(subreq, req)) {
    1653           0 :                 return tevent_req_post(req, ev);
    1654             :         }
    1655      418508 :         tevent_req_set_callback(subreq, smb_vfs_call_pwrite_done, req);
    1656      418508 :         return req;
    1657             : }
    1658             : 
    1659      418504 : static void smb_vfs_call_pwrite_done(struct tevent_req *subreq)
    1660             : {
    1661      418504 :         struct tevent_req *req = tevent_req_callback_data(
    1662             :                 subreq, struct tevent_req);
    1663      418504 :         struct smb_vfs_call_pwrite_state *state = tevent_req_data(
    1664             :                 req, struct smb_vfs_call_pwrite_state);
    1665             : 
    1666      418504 :         state->retval = state->recv_fn(subreq, &state->vfs_aio_state);
    1667      418504 :         TALLOC_FREE(subreq);
    1668      418504 :         if (state->retval == -1) {
    1669           0 :                 tevent_req_error(req, state->vfs_aio_state.error);
    1670           0 :                 return;
    1671             :         }
    1672      418504 :         tevent_req_done(req);
    1673             : }
    1674             : 
    1675      418504 : ssize_t SMB_VFS_PWRITE_RECV(struct tevent_req *req,
    1676             :                             struct vfs_aio_state *vfs_aio_state)
    1677             : {
    1678      418504 :         struct smb_vfs_call_pwrite_state *state = tevent_req_data(
    1679             :                 req, struct smb_vfs_call_pwrite_state);
    1680          52 :         ssize_t retval;
    1681             : 
    1682      418504 :         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
    1683           0 :                 tevent_req_received(req);
    1684           0 :                 return -1;
    1685             :         }
    1686      418504 :         *vfs_aio_state = state->vfs_aio_state;
    1687      418504 :         retval = state->retval;
    1688      418504 :         tevent_req_received(req);
    1689      418504 :         return retval;
    1690             : }
    1691             : 
    1692        1109 : off_t smb_vfs_call_lseek(struct vfs_handle_struct *handle,
    1693             :                              struct files_struct *fsp, off_t offset,
    1694             :                              int whence)
    1695             : {
    1696        3112 :         VFS_FIND(lseek);
    1697        1109 :         return handle->fns->lseek_fn(handle, fsp, offset, whence);
    1698             : }
    1699             : 
    1700           0 : ssize_t smb_vfs_call_sendfile(struct vfs_handle_struct *handle, int tofd,
    1701             :                               files_struct *fromfsp, const DATA_BLOB *header,
    1702             :                               off_t offset, size_t count)
    1703             : {
    1704           0 :         VFS_FIND(sendfile);
    1705           0 :         return handle->fns->sendfile_fn(handle, tofd, fromfsp, header, offset,
    1706             :                                         count);
    1707             : }
    1708             : 
    1709           0 : ssize_t smb_vfs_call_recvfile(struct vfs_handle_struct *handle, int fromfd,
    1710             :                               files_struct *tofsp, off_t offset,
    1711             :                               size_t count)
    1712             : {
    1713           0 :         VFS_FIND(recvfile);
    1714           0 :         return handle->fns->recvfile_fn(handle, fromfd, tofsp, offset, count);
    1715             : }
    1716             : 
    1717        3262 : int smb_vfs_call_renameat(struct vfs_handle_struct *handle,
    1718             :                         files_struct *srcfsp,
    1719             :                         const struct smb_filename *smb_fname_src,
    1720             :                         files_struct *dstfsp,
    1721             :                         const struct smb_filename *smb_fname_dst)
    1722             : {
    1723        6412 :         VFS_FIND(renameat);
    1724        3262 :         return handle->fns->renameat_fn(handle,
    1725             :                                 srcfsp,
    1726             :                                 smb_fname_src,
    1727             :                                 dstfsp,
    1728             :                                 smb_fname_dst);
    1729             : }
    1730             : 
    1731             : struct smb_vfs_call_fsync_state {
    1732             :         int (*recv_fn)(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state);
    1733             :         int retval;
    1734             :         struct vfs_aio_state vfs_aio_state;
    1735             : };
    1736             : 
    1737             : static void smb_vfs_call_fsync_done(struct tevent_req *subreq);
    1738             : 
    1739         404 : struct tevent_req *smb_vfs_call_fsync_send(struct vfs_handle_struct *handle,
    1740             :                                            TALLOC_CTX *mem_ctx,
    1741             :                                            struct tevent_context *ev,
    1742             :                                            struct files_struct *fsp)
    1743             : {
    1744           2 :         struct tevent_req *req, *subreq;
    1745           2 :         struct smb_vfs_call_fsync_state *state;
    1746             : 
    1747         404 :         req = tevent_req_create(mem_ctx, &state,
    1748             :                                 struct smb_vfs_call_fsync_state);
    1749         404 :         if (req == NULL) {
    1750           0 :                 return NULL;
    1751             :         }
    1752         968 :         VFS_FIND(fsync_send);
    1753         404 :         state->recv_fn = handle->fns->fsync_recv_fn;
    1754             : 
    1755         404 :         subreq = handle->fns->fsync_send_fn(handle, state, ev, fsp);
    1756         404 :         if (tevent_req_nomem(subreq, req)) {
    1757           0 :                 return tevent_req_post(req, ev);
    1758             :         }
    1759         404 :         tevent_req_set_callback(subreq, smb_vfs_call_fsync_done, req);
    1760         404 :         return req;
    1761             : }
    1762             : 
    1763         404 : static void smb_vfs_call_fsync_done(struct tevent_req *subreq)
    1764             : {
    1765         404 :         struct tevent_req *req = tevent_req_callback_data(
    1766             :                 subreq, struct tevent_req);
    1767         404 :         struct smb_vfs_call_fsync_state *state = tevent_req_data(
    1768             :                 req, struct smb_vfs_call_fsync_state);
    1769             : 
    1770         404 :         state->retval = state->recv_fn(subreq, &state->vfs_aio_state);
    1771         404 :         TALLOC_FREE(subreq);
    1772         404 :         if (state->retval == -1) {
    1773           0 :                 tevent_req_error(req, state->vfs_aio_state.error);
    1774           0 :                 return;
    1775             :         }
    1776         404 :         tevent_req_done(req);
    1777             : }
    1778             : 
    1779         404 : int SMB_VFS_FSYNC_RECV(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state)
    1780             : {
    1781         404 :         struct smb_vfs_call_fsync_state *state = tevent_req_data(
    1782             :                 req, struct smb_vfs_call_fsync_state);
    1783           2 :         ssize_t retval;
    1784             : 
    1785         404 :         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
    1786           0 :                 tevent_req_received(req);
    1787           0 :                 return -1;
    1788             :         }
    1789         404 :         *vfs_aio_state = state->vfs_aio_state;
    1790         404 :         retval = state->retval;
    1791         404 :         tevent_req_received(req);
    1792         404 :         return retval;
    1793             : }
    1794             : 
    1795             : /*
    1796             :  * Synchronous version of fsync, built from backend
    1797             :  * async VFS primitives. Uses a temporary sub-event
    1798             :  * context (NOT NESTED).
    1799             :  */
    1800             : 
    1801           7 : int smb_vfs_fsync_sync(files_struct *fsp)
    1802             : {
    1803           7 :         TALLOC_CTX *frame = talloc_stackframe();
    1804           7 :         struct tevent_req *req = NULL;
    1805           7 :         struct vfs_aio_state aio_state = { 0 };
    1806           7 :         int ret = -1;
    1807           1 :         bool ok;
    1808           7 :         struct tevent_context *ev = samba_tevent_context_init(frame);
    1809             : 
    1810           7 :         if (ev == NULL) {
    1811           0 :                 goto out;
    1812             :         }
    1813             : 
    1814           7 :         req = SMB_VFS_FSYNC_SEND(talloc_tos(), ev, fsp);
    1815           7 :         if (req == NULL) {
    1816           0 :                 goto out;
    1817             :         }
    1818             : 
    1819           7 :         ok = tevent_req_poll(req, ev);
    1820           7 :         if (!ok) {
    1821           0 :                 goto out;
    1822             :         }
    1823             : 
    1824           7 :         ret = SMB_VFS_FSYNC_RECV(req, &aio_state);
    1825             : 
    1826           7 :   out:
    1827             : 
    1828           7 :         TALLOC_FREE(frame);
    1829           7 :         if (aio_state.error != 0) {
    1830           0 :                 errno = aio_state.error;
    1831             :         }
    1832           7 :         return ret;
    1833             : }
    1834             : 
    1835    21534206 : int smb_vfs_call_stat(struct vfs_handle_struct *handle,
    1836             :                       struct smb_filename *smb_fname)
    1837             : {
    1838    32946583 :         VFS_FIND(stat);
    1839    21534206 :         return handle->fns->stat_fn(handle, smb_fname);
    1840             : }
    1841             : 
    1842    73504741 : int smb_vfs_call_fstat(struct vfs_handle_struct *handle,
    1843             :                        struct files_struct *fsp, SMB_STRUCT_STAT *sbuf)
    1844             : {
    1845   126033842 :         VFS_FIND(fstat);
    1846    73504741 :         return handle->fns->fstat_fn(handle, fsp, sbuf);
    1847             : }
    1848             : 
    1849      105141 : int smb_vfs_call_lstat(struct vfs_handle_struct *handle,
    1850             :                        struct smb_filename *smb_filename)
    1851             : {
    1852      142000 :         VFS_FIND(lstat);
    1853      105141 :         return handle->fns->lstat_fn(handle, smb_filename);
    1854             : }
    1855             : 
    1856      119149 : int smb_vfs_call_fstatat(
    1857             :         struct vfs_handle_struct *handle,
    1858             :         const struct files_struct *dirfsp,
    1859             :         const struct smb_filename *smb_fname,
    1860             :         SMB_STRUCT_STAT *sbuf,
    1861             :         int flags)
    1862             : {
    1863      256028 :         VFS_FIND(fstatat);
    1864      119149 :         return handle->fns->fstatat_fn(handle, dirfsp, smb_fname, sbuf, flags);
    1865             : }
    1866             : 
    1867     3388631 : uint64_t smb_vfs_call_get_alloc_size(struct vfs_handle_struct *handle,
    1868             :                                      struct files_struct *fsp,
    1869             :                                      const SMB_STRUCT_STAT *sbuf)
    1870             : {
    1871    10614852 :         VFS_FIND(get_alloc_size);
    1872     3388631 :         return handle->fns->get_alloc_size_fn(handle, fsp, sbuf);
    1873             : }
    1874             : 
    1875      803064 : int smb_vfs_call_unlinkat(struct vfs_handle_struct *handle,
    1876             :                         struct files_struct *dirfsp,
    1877             :                         const struct smb_filename *smb_fname,
    1878             :                         int flags)
    1879             : {
    1880     1035041 :         VFS_FIND(unlinkat);
    1881      803064 :         return handle->fns->unlinkat_fn(handle,
    1882             :                         dirfsp,
    1883             :                         smb_fname,
    1884             :                         flags);
    1885             : }
    1886             : 
    1887       20995 : int smb_vfs_call_fchmod(struct vfs_handle_struct *handle,
    1888             :                         struct files_struct *fsp, mode_t mode)
    1889             : {
    1890       51988 :         VFS_FIND(fchmod);
    1891       20995 :         return handle->fns->fchmod_fn(handle, fsp, mode);
    1892             : }
    1893             : 
    1894      213933 : int smb_vfs_call_fchown(struct vfs_handle_struct *handle,
    1895             :                         struct files_struct *fsp, uid_t uid, gid_t gid)
    1896             : {
    1897      554049 :         VFS_FIND(fchown);
    1898      213933 :         return handle->fns->fchown_fn(handle, fsp, uid, gid);
    1899             : }
    1900             : 
    1901           0 : int smb_vfs_call_lchown(struct vfs_handle_struct *handle,
    1902             :                         const struct smb_filename *smb_fname,
    1903             :                         uid_t uid,
    1904             :                         gid_t gid)
    1905             : {
    1906           0 :         VFS_FIND(lchown);
    1907           0 :         return handle->fns->lchown_fn(handle, smb_fname, uid, gid);
    1908             : }
    1909             : 
    1910     3889540 : int smb_vfs_call_chdir(struct vfs_handle_struct *handle,
    1911             :                         const struct smb_filename *smb_fname)
    1912             : {
    1913    11538224 :         VFS_FIND(chdir);
    1914     3889540 :         return handle->fns->chdir_fn(handle, smb_fname);
    1915             : }
    1916             : 
    1917      204392 : struct smb_filename *smb_vfs_call_getwd(struct vfs_handle_struct *handle,
    1918             :                                 TALLOC_CTX *ctx)
    1919             : {
    1920      540229 :         VFS_FIND(getwd);
    1921      204392 :         return handle->fns->getwd_fn(handle, ctx);
    1922             : }
    1923             : 
    1924       27104 : int smb_vfs_call_fntimes(struct vfs_handle_struct *handle,
    1925             :                          struct files_struct *fsp,
    1926             :                          struct smb_file_time *ft)
    1927             : {
    1928       71005 :         VFS_FIND(fntimes);
    1929       27104 :         return handle->fns->fntimes_fn(handle, fsp, ft);
    1930             : }
    1931             : 
    1932        2453 : int smb_vfs_call_ftruncate(struct vfs_handle_struct *handle,
    1933             :                            struct files_struct *fsp, off_t offset)
    1934             : {
    1935        7307 :         VFS_FIND(ftruncate);
    1936        2453 :         return handle->fns->ftruncate_fn(handle, fsp, offset);
    1937             : }
    1938             : 
    1939         466 : int smb_vfs_call_fallocate(struct vfs_handle_struct *handle,
    1940             :                            struct files_struct *fsp,
    1941             :                            uint32_t mode,
    1942             :                            off_t offset,
    1943             :                            off_t len)
    1944             : {
    1945        1302 :         VFS_FIND(fallocate);
    1946         466 :         return handle->fns->fallocate_fn(handle, fsp, mode, offset, len);
    1947             : }
    1948             : 
    1949           0 : int smb_vfs_call_filesystem_sharemode(struct vfs_handle_struct *handle,
    1950             :                                       struct files_struct *fsp,
    1951             :                                       uint32_t share_mode,
    1952             :                                       uint32_t access_mask)
    1953             : {
    1954           0 :         VFS_FIND(filesystem_sharemode);
    1955           0 :         return handle->fns->filesystem_sharemode_fn(handle,
    1956             :                                                     fsp,
    1957             :                                                     share_mode,
    1958             :                                                     access_mask);
    1959             : }
    1960             : 
    1961      771944 : int smb_vfs_call_fcntl(struct vfs_handle_struct *handle,
    1962             :                        struct files_struct *fsp, int cmd, ...)
    1963             : {
    1964         898 :         int result;
    1965         898 :         va_list cmd_arg;
    1966             : 
    1967     2311338 :         VFS_FIND(fcntl);
    1968             : 
    1969      771944 :         va_start(cmd_arg, cmd);
    1970      771944 :         result = handle->fns->fcntl_fn(handle, fsp, cmd, cmd_arg);
    1971      771944 :         va_end(cmd_arg);
    1972             : 
    1973      771944 :         return result;
    1974             : }
    1975             : 
    1976          26 : int smb_vfs_call_linux_setlease(struct vfs_handle_struct *handle,
    1977             :                                 struct files_struct *fsp, int leasetype)
    1978             : {
    1979          38 :         VFS_FIND(linux_setlease);
    1980          26 :         return handle->fns->linux_setlease_fn(handle, fsp, leasetype);
    1981             : }
    1982             : 
    1983         160 : int smb_vfs_call_symlinkat(struct vfs_handle_struct *handle,
    1984             :                         const struct smb_filename *link_target,
    1985             :                         struct files_struct *dirfsp,
    1986             :                         const struct smb_filename *new_smb_fname)
    1987             : {
    1988         448 :         VFS_FIND(symlinkat);
    1989         160 :         return handle->fns->symlinkat_fn(handle,
    1990             :                                 link_target,
    1991             :                                 dirfsp,
    1992             :                                 new_smb_fname);
    1993             : }
    1994             : 
    1995      216661 : int smb_vfs_call_readlinkat(struct vfs_handle_struct *handle,
    1996             :                         const struct files_struct *dirfsp,
    1997             :                         const struct smb_filename *smb_fname,
    1998             :                         char *buf,
    1999             :                         size_t bufsiz)
    2000             : {
    2001      498885 :         VFS_FIND(readlinkat);
    2002      216661 :         return handle->fns->readlinkat_fn(handle,
    2003             :                                 dirfsp,
    2004             :                                 smb_fname,
    2005             :                                 buf,
    2006             :                                 bufsiz);
    2007             : }
    2008             : 
    2009         107 : int smb_vfs_call_linkat(struct vfs_handle_struct *handle,
    2010             :                         struct files_struct *srcfsp,
    2011             :                         const struct smb_filename *old_smb_fname,
    2012             :                         struct files_struct *dstfsp,
    2013             :                         const struct smb_filename *new_smb_fname,
    2014             :                         int flags)
    2015             : {
    2016         266 :         VFS_FIND(linkat);
    2017         107 :         return handle->fns->linkat_fn(handle,
    2018             :                                 srcfsp,
    2019             :                                 old_smb_fname,
    2020             :                                 dstfsp,
    2021             :                                 new_smb_fname,
    2022             :                                 flags);
    2023             : }
    2024             : 
    2025           2 : int smb_vfs_call_mknodat(struct vfs_handle_struct *handle,
    2026             :                         struct files_struct *dirfsp,
    2027             :                         const struct smb_filename *smb_fname,
    2028             :                         mode_t mode,
    2029             :                         SMB_DEV_T dev)
    2030             : {
    2031           6 :         VFS_FIND(mknodat);
    2032           2 :         return handle->fns->mknodat_fn(handle,
    2033             :                                 dirfsp,
    2034             :                                 smb_fname,
    2035             :                                 mode,
    2036             :                                 dev);
    2037             : }
    2038             : 
    2039     7685339 : struct smb_filename *smb_vfs_call_realpath(struct vfs_handle_struct *handle,
    2040             :                         TALLOC_CTX *ctx,
    2041             :                         const struct smb_filename *smb_fname)
    2042             : {
    2043    22966415 :         VFS_FIND(realpath);
    2044     7685339 :         return handle->fns->realpath_fn(handle, ctx, smb_fname);
    2045             : }
    2046             : 
    2047           0 : int smb_vfs_call_fchflags(struct vfs_handle_struct *handle,
    2048             :                         struct files_struct *fsp,
    2049             :                         unsigned int flags)
    2050             : {
    2051           0 :         VFS_FIND(fchflags);
    2052           0 :         return handle->fns->fchflags_fn(handle, fsp, flags);
    2053             : }
    2054             : 
    2055    69114897 : struct file_id smb_vfs_call_file_id_create(struct vfs_handle_struct *handle,
    2056             :                                            const SMB_STRUCT_STAT *sbuf)
    2057             : {
    2058   135209263 :         VFS_FIND(file_id_create);
    2059    69114897 :         return handle->fns->file_id_create_fn(handle, sbuf);
    2060             : }
    2061             : 
    2062     1783715 : uint64_t smb_vfs_call_fs_file_id(struct vfs_handle_struct *handle,
    2063             :                                  const SMB_STRUCT_STAT *sbuf)
    2064             : {
    2065     5752626 :         VFS_FIND(fs_file_id);
    2066     1783715 :         return handle->fns->fs_file_id_fn(handle, sbuf);
    2067             : }
    2068             : 
    2069      995818 : NTSTATUS smb_vfs_call_fstreaminfo(struct vfs_handle_struct *handle,
    2070             :                                  struct files_struct *fsp,
    2071             :                                  TALLOC_CTX *mem_ctx,
    2072             :                                  unsigned int *num_streams,
    2073             :                                  struct stream_struct **streams)
    2074             : {
    2075     2062322 :         VFS_FIND(fstreaminfo);
    2076      995818 :         return handle->fns->fstreaminfo_fn(handle, fsp, mem_ctx,
    2077             :                                           num_streams, streams);
    2078             : }
    2079             : 
    2080      548849 : NTSTATUS smb_vfs_call_get_real_filename_at(struct vfs_handle_struct *handle,
    2081             :                                            struct files_struct *dirfsp,
    2082             :                                            const char *name,
    2083             :                                            TALLOC_CTX *mem_ctx,
    2084             :                                            char **found_name)
    2085             : {
    2086     1681550 :         VFS_FIND(get_real_filename_at);
    2087      548849 :         return handle->fns->get_real_filename_at_fn(
    2088             :                 handle, dirfsp, name, mem_ctx, found_name);
    2089             : }
    2090             : 
    2091     8315552 : const char *smb_vfs_call_connectpath(struct vfs_handle_struct *handle,
    2092             :                                  const struct files_struct *dirfsp,
    2093             :                                  const struct smb_filename *smb_fname)
    2094             : {
    2095    25113517 :         VFS_FIND(connectpath);
    2096     8315552 :         return handle->fns->connectpath_fn(handle, dirfsp, smb_fname);
    2097             : }
    2098             : 
    2099      461432 : bool smb_vfs_call_strict_lock_check(struct vfs_handle_struct *handle,
    2100             :                                     struct files_struct *fsp,
    2101             :                                     struct lock_struct *plock)
    2102             : {
    2103     1154186 :         VFS_FIND(strict_lock_check);
    2104      461432 :         return handle->fns->strict_lock_check_fn(handle, fsp, plock);
    2105             : }
    2106             : 
    2107   320027662 : NTSTATUS smb_vfs_call_translate_name(struct vfs_handle_struct *handle,
    2108             :                                      const char *name,
    2109             :                                      enum vfs_translate_direction direction,
    2110             :                                      TALLOC_CTX *mem_ctx,
    2111             :                                      char **mapped_name)
    2112             : {
    2113   868115732 :         VFS_FIND(translate_name);
    2114   320027662 :         return handle->fns->translate_name_fn(handle, name, direction, mem_ctx,
    2115             :                                               mapped_name);
    2116             : }
    2117             : 
    2118     8901399 : NTSTATUS smb_vfs_call_parent_pathname(struct vfs_handle_struct *handle,
    2119             :                                       TALLOC_CTX *mem_ctx,
    2120             :                                       const struct smb_filename *smb_fname_in,
    2121             :                                       struct smb_filename **parent_dir_out,
    2122             :                                       struct smb_filename **atname_out)
    2123             : {
    2124    26875023 :         VFS_FIND(parent_pathname);
    2125     8901399 :         return handle->fns->parent_pathname_fn(handle,
    2126             :                                                mem_ctx,
    2127             :                                                smb_fname_in,
    2128             :                                                parent_dir_out,
    2129             :                                                atname_out);
    2130             : }
    2131             : 
    2132        4116 : NTSTATUS smb_vfs_call_fsctl(struct vfs_handle_struct *handle,
    2133             :                             struct files_struct *fsp,
    2134             :                             TALLOC_CTX *ctx,
    2135             :                             uint32_t function,
    2136             :                             uint16_t req_flags,
    2137             :                             const uint8_t *in_data,
    2138             :                             uint32_t in_len,
    2139             :                             uint8_t **out_data,
    2140             :                             uint32_t max_out_len,
    2141             :                             uint32_t *out_len)
    2142             : {
    2143        9418 :         VFS_FIND(fsctl);
    2144        4116 :         return handle->fns->fsctl_fn(handle, fsp, ctx, function, req_flags,
    2145             :                                      in_data, in_len, out_data, max_out_len,
    2146             :                                      out_len);
    2147             : }
    2148             : 
    2149     2859605 : NTSTATUS smb_vfs_call_fget_dos_attributes(struct vfs_handle_struct *handle,
    2150             :                                           struct files_struct *fsp,
    2151             :                                           uint32_t *dosmode)
    2152             : {
    2153     9015658 :         VFS_FIND(fget_dos_attributes);
    2154     2859605 :         return handle->fns->fget_dos_attributes_fn(handle, fsp, dosmode);
    2155             : }
    2156             : 
    2157      350436 : NTSTATUS smb_vfs_call_fset_dos_attributes(struct vfs_handle_struct *handle,
    2158             :                                           struct files_struct *fsp,
    2159             :                                           uint32_t dosmode)
    2160             : {
    2161     1061863 :         VFS_FIND(fset_dos_attributes);
    2162      350436 :         return handle->fns->fset_dos_attributes_fn(handle, fsp, dosmode);
    2163             : }
    2164             : 
    2165         680 : struct tevent_req *smb_vfs_call_offload_read_send(TALLOC_CTX *mem_ctx,
    2166             :                                                   struct tevent_context *ev,
    2167             :                                                   struct vfs_handle_struct *handle,
    2168             :                                                   struct files_struct *fsp,
    2169             :                                                   uint32_t fsctl,
    2170             :                                                   uint32_t ttl,
    2171             :                                                   off_t offset,
    2172             :                                                   size_t to_copy)
    2173             : {
    2174        1890 :         VFS_FIND(offload_read_send);
    2175         680 :         return handle->fns->offload_read_send_fn(mem_ctx, ev, handle,
    2176             :                                                  fsp, fsctl,
    2177             :                                                  ttl, offset, to_copy);
    2178             : }
    2179             : 
    2180         680 : NTSTATUS smb_vfs_call_offload_read_recv(struct tevent_req *req,
    2181             :                                         struct vfs_handle_struct *handle,
    2182             :                                         TALLOC_CTX *mem_ctx,
    2183             :                                         uint32_t *flags,
    2184             :                                         uint64_t *xferlen,
    2185             :                                         DATA_BLOB *token_blob)
    2186             : {
    2187        1890 :         VFS_FIND(offload_read_recv);
    2188         680 :         return handle->fns->offload_read_recv_fn(req, handle, mem_ctx, flags, xferlen, token_blob);
    2189             : }
    2190             : 
    2191         760 : struct tevent_req *smb_vfs_call_offload_write_send(struct vfs_handle_struct *handle,
    2192             :                                                    TALLOC_CTX *mem_ctx,
    2193             :                                                    struct tevent_context *ev,
    2194             :                                                    uint32_t fsctl,
    2195             :                                                    DATA_BLOB *token,
    2196             :                                                    off_t transfer_offset,
    2197             :                                                    struct files_struct *dest_fsp,
    2198             :                                                    off_t dest_off,
    2199             :                                                    off_t num)
    2200             : {
    2201        2114 :         VFS_FIND(offload_write_send);
    2202         760 :         return handle->fns->offload_write_send_fn(handle, mem_ctx, ev, fsctl,
    2203             :                                                token, transfer_offset,
    2204             :                                                dest_fsp, dest_off, num);
    2205             : }
    2206             : 
    2207         760 : NTSTATUS smb_vfs_call_offload_write_recv(struct vfs_handle_struct *handle,
    2208             :                                          struct tevent_req *req,
    2209             :                                          off_t *copied)
    2210             : {
    2211        2114 :         VFS_FIND(offload_write_recv);
    2212         760 :         return handle->fns->offload_write_recv_fn(handle, req, copied);
    2213             : }
    2214             : 
    2215             : struct smb_vfs_call_get_dos_attributes_state {
    2216             :         files_struct *dir_fsp;
    2217             :         NTSTATUS (*recv_fn)(struct tevent_req *req,
    2218             :                             struct vfs_aio_state *aio_state,
    2219             :                             uint32_t *dosmode);
    2220             :         struct vfs_aio_state aio_state;
    2221             :         uint32_t dos_attributes;
    2222             : };
    2223             : 
    2224             : static void smb_vfs_call_get_dos_attributes_done(struct tevent_req *subreq);
    2225             : 
    2226       20138 : struct tevent_req *smb_vfs_call_get_dos_attributes_send(
    2227             :                         TALLOC_CTX *mem_ctx,
    2228             :                         struct tevent_context *ev,
    2229             :                         struct vfs_handle_struct *handle,
    2230             :                         files_struct *dir_fsp,
    2231             :                         struct smb_filename *smb_fname)
    2232             : {
    2233       20138 :         struct tevent_req *req = NULL;
    2234       20138 :         struct smb_vfs_call_get_dos_attributes_state *state = NULL;
    2235       20138 :         struct tevent_req *subreq = NULL;
    2236             : 
    2237       20138 :         req = tevent_req_create(mem_ctx, &state,
    2238             :                                 struct smb_vfs_call_get_dos_attributes_state);
    2239       20138 :         if (req == NULL) {
    2240           0 :                 return NULL;
    2241             :         }
    2242             : 
    2243       50366 :         VFS_FIND(get_dos_attributes_send);
    2244             : 
    2245       20138 :         *state = (struct smb_vfs_call_get_dos_attributes_state) {
    2246             :                 .dir_fsp = dir_fsp,
    2247       20138 :                 .recv_fn = handle->fns->get_dos_attributes_recv_fn,
    2248             :         };
    2249             : 
    2250       20138 :         subreq = handle->fns->get_dos_attributes_send_fn(mem_ctx,
    2251             :                                                          ev,
    2252             :                                                          handle,
    2253             :                                                          dir_fsp,
    2254             :                                                          smb_fname);
    2255       20138 :         if (tevent_req_nomem(subreq, req)) {
    2256           0 :                 return tevent_req_post(req, ev);
    2257             :         }
    2258       20138 :         tevent_req_defer_callback(req, ev);
    2259             : 
    2260       20138 :         tevent_req_set_callback(subreq,
    2261             :                                 smb_vfs_call_get_dos_attributes_done,
    2262             :                                 req);
    2263             : 
    2264       20138 :         return req;
    2265             : }
    2266             : 
    2267       20138 : static void smb_vfs_call_get_dos_attributes_done(struct tevent_req *subreq)
    2268             : {
    2269           0 :         struct tevent_req *req =
    2270       20138 :                 tevent_req_callback_data(subreq,
    2271             :                 struct tevent_req);
    2272           0 :         struct smb_vfs_call_get_dos_attributes_state *state =
    2273       20138 :                 tevent_req_data(req,
    2274             :                 struct smb_vfs_call_get_dos_attributes_state);
    2275           0 :         NTSTATUS status;
    2276           0 :         bool ok;
    2277             : 
    2278             :         /*
    2279             :          * Make sure we run as the user again
    2280             :          */
    2281       20138 :         ok = change_to_user_and_service_by_fsp(state->dir_fsp);
    2282       20138 :         SMB_ASSERT(ok);
    2283             : 
    2284       20138 :         status = state->recv_fn(subreq,
    2285             :                                 &state->aio_state,
    2286             :                                 &state->dos_attributes);
    2287       20138 :         TALLOC_FREE(subreq);
    2288       20138 :         if (tevent_req_nterror(req, status)) {
    2289         120 :                 return;
    2290             :         }
    2291             : 
    2292       20018 :         tevent_req_done(req);
    2293             : }
    2294             : 
    2295       20138 : NTSTATUS smb_vfs_call_get_dos_attributes_recv(
    2296             :                 struct tevent_req *req,
    2297             :                 struct vfs_aio_state *aio_state,
    2298             :                 uint32_t *dos_attributes)
    2299             : {
    2300           0 :         struct smb_vfs_call_get_dos_attributes_state *state =
    2301       20138 :                 tevent_req_data(req,
    2302             :                 struct smb_vfs_call_get_dos_attributes_state);
    2303           0 :         NTSTATUS status;
    2304             : 
    2305       20138 :         if (tevent_req_is_nterror(req, &status)) {
    2306         120 :                 tevent_req_received(req);
    2307         120 :                 return status;
    2308             :         }
    2309             : 
    2310       20018 :         *aio_state = state->aio_state;
    2311       20018 :         *dos_attributes = state->dos_attributes;
    2312       20018 :         tevent_req_received(req);
    2313       20018 :         return NT_STATUS_OK;
    2314             : }
    2315             : 
    2316           0 : NTSTATUS smb_vfs_call_fget_compression(vfs_handle_struct *handle,
    2317             :                                       TALLOC_CTX *mem_ctx,
    2318             :                                       struct files_struct *fsp,
    2319             :                                       uint16_t *_compression_fmt)
    2320             : {
    2321           0 :         VFS_FIND(fget_compression);
    2322           0 :         return handle->fns->fget_compression_fn(handle, mem_ctx, fsp,
    2323             :                                                _compression_fmt);
    2324             : }
    2325             : 
    2326           0 : NTSTATUS smb_vfs_call_set_compression(vfs_handle_struct *handle,
    2327             :                                       TALLOC_CTX *mem_ctx,
    2328             :                                       struct files_struct *fsp,
    2329             :                                       uint16_t compression_fmt)
    2330             : {
    2331           0 :         VFS_FIND(set_compression);
    2332           0 :         return handle->fns->set_compression_fn(handle, mem_ctx, fsp,
    2333             :                                                compression_fmt);
    2334             : }
    2335             : 
    2336          68 : NTSTATUS smb_vfs_call_snap_check_path(vfs_handle_struct *handle,
    2337             :                                       TALLOC_CTX *mem_ctx,
    2338             :                                       const char *service_path,
    2339             :                                       char **base_volume)
    2340             : {
    2341          68 :         VFS_FIND(snap_check_path);
    2342          68 :         return handle->fns->snap_check_path_fn(handle, mem_ctx, service_path,
    2343             :                                                base_volume);
    2344             : }
    2345             : 
    2346          16 : NTSTATUS smb_vfs_call_snap_create(struct vfs_handle_struct *handle,
    2347             :                                   TALLOC_CTX *mem_ctx,
    2348             :                                   const char *base_volume,
    2349             :                                   time_t *tstamp,
    2350             :                                   bool rw,
    2351             :                                   char **base_path,
    2352             :                                   char **snap_path)
    2353             : {
    2354          16 :         VFS_FIND(snap_create);
    2355          16 :         return handle->fns->snap_create_fn(handle, mem_ctx, base_volume, tstamp,
    2356             :                                            rw, base_path, snap_path);
    2357             : }
    2358             : 
    2359          10 : NTSTATUS smb_vfs_call_snap_delete(struct vfs_handle_struct *handle,
    2360             :                                   TALLOC_CTX *mem_ctx,
    2361             :                                   char *base_path,
    2362             :                                   char *snap_path)
    2363             : {
    2364          10 :         VFS_FIND(snap_delete);
    2365          10 :         return handle->fns->snap_delete_fn(handle, mem_ctx, base_path,
    2366             :                                            snap_path);
    2367             : }
    2368             : 
    2369     1513318 : NTSTATUS smb_vfs_call_fget_nt_acl(struct vfs_handle_struct *handle,
    2370             :                                   struct files_struct *fsp,
    2371             :                                   uint32_t security_info,
    2372             :                                   TALLOC_CTX *mem_ctx,
    2373             :                                   struct security_descriptor **ppdesc)
    2374             : {
    2375     2917532 :         VFS_FIND(fget_nt_acl);
    2376     1513318 :         return handle->fns->fget_nt_acl_fn(handle, fsp, security_info,
    2377             :                                            mem_ctx, ppdesc);
    2378             : }
    2379             : 
    2380      499029 : NTSTATUS smb_vfs_call_fset_nt_acl(struct vfs_handle_struct *handle,
    2381             :                                   struct files_struct *fsp,
    2382             :                                   uint32_t security_info_sent,
    2383             :                                   const struct security_descriptor *psd)
    2384             : {
    2385     1038310 :         VFS_FIND(fset_nt_acl);
    2386      499029 :         return handle->fns->fset_nt_acl_fn(handle, fsp, security_info_sent, 
    2387             :                                            psd);
    2388             : }
    2389             : 
    2390           0 : NTSTATUS smb_vfs_call_audit_file(struct vfs_handle_struct *handle,
    2391             :                                  struct smb_filename *file,
    2392             :                                  struct security_acl *sacl,
    2393             :                                  uint32_t access_requested,
    2394             :                                  uint32_t access_denied)
    2395             : {
    2396           0 :         VFS_FIND(audit_file);
    2397           0 :         return handle->fns->audit_file_fn(handle, 
    2398             :                                           file, 
    2399             :                                           sacl, 
    2400             :                                           access_requested, 
    2401             :                                           access_denied);
    2402             : }
    2403             : 
    2404     1935317 : SMB_ACL_T smb_vfs_call_sys_acl_get_fd(struct vfs_handle_struct *handle,
    2405             :                                       struct files_struct *fsp,
    2406             :                                       SMB_ACL_TYPE_T type,
    2407             :                                       TALLOC_CTX *mem_ctx)
    2408             : {
    2409     2916805 :         VFS_FIND(sys_acl_get_fd);
    2410     1935317 :         return handle->fns->sys_acl_get_fd_fn(handle, fsp, type, mem_ctx);
    2411             : }
    2412             : 
    2413      796808 : int smb_vfs_call_sys_acl_blob_get_fd(struct vfs_handle_struct *handle,
    2414             :                                      struct files_struct *fsp,
    2415             :                                      TALLOC_CTX *mem_ctx, 
    2416             :                                      char **blob_description,
    2417             :                                      DATA_BLOB *blob)
    2418             : {
    2419      806624 :         VFS_FIND(sys_acl_blob_get_fd);
    2420      796808 :         return handle->fns->sys_acl_blob_get_fd_fn(handle, fsp, mem_ctx, blob_description, blob);
    2421             : }
    2422             : 
    2423      329401 : int smb_vfs_call_sys_acl_set_fd(struct vfs_handle_struct *handle,
    2424             :                                 struct files_struct *fsp,
    2425             :                                 SMB_ACL_TYPE_T type,
    2426             :                                 SMB_ACL_T theacl)
    2427             : {
    2428      402658 :         VFS_FIND(sys_acl_set_fd);
    2429      329401 :         return handle->fns->sys_acl_set_fd_fn(handle, fsp, type, theacl);
    2430             : }
    2431             : 
    2432         321 : int smb_vfs_call_sys_acl_delete_def_fd(struct vfs_handle_struct *handle,
    2433             :                                 struct files_struct *fsp)
    2434             : {
    2435         788 :         VFS_FIND(sys_acl_delete_def_fd);
    2436         321 :         return handle->fns->sys_acl_delete_def_fd_fn(handle, fsp);
    2437             : }
    2438             : 
    2439             : struct smb_vfs_call_getxattrat_state {
    2440             :         files_struct *dir_fsp;
    2441             :         ssize_t (*recv_fn)(struct tevent_req *req,
    2442             :                            struct vfs_aio_state *aio_state,
    2443             :                            TALLOC_CTX *mem_ctx,
    2444             :                            uint8_t **xattr_value);
    2445             :         ssize_t retval;
    2446             :         uint8_t *xattr_value;
    2447             :         struct vfs_aio_state aio_state;
    2448             : };
    2449             : 
    2450             : static void smb_vfs_call_getxattrat_done(struct tevent_req *subreq);
    2451             : 
    2452       20140 : struct tevent_req *smb_vfs_call_getxattrat_send(
    2453             :                         TALLOC_CTX *mem_ctx,
    2454             :                         struct tevent_context *ev,
    2455             :                         struct vfs_handle_struct *handle,
    2456             :                         files_struct *dir_fsp,
    2457             :                         const struct smb_filename *smb_fname,
    2458             :                         const char *xattr_name,
    2459             :                         size_t alloc_hint)
    2460             : {
    2461       20140 :         struct tevent_req *req = NULL;
    2462       20140 :         struct smb_vfs_call_getxattrat_state *state = NULL;
    2463       20140 :         struct tevent_req *subreq = NULL;
    2464             : 
    2465       20140 :         req = tevent_req_create(mem_ctx, &state,
    2466             :                                 struct smb_vfs_call_getxattrat_state);
    2467       20140 :         if (req == NULL) {
    2468           0 :                 return NULL;
    2469             :         }
    2470             : 
    2471       40308 :         VFS_FIND(getxattrat_send);
    2472             : 
    2473       20140 :         *state = (struct smb_vfs_call_getxattrat_state) {
    2474             :                 .dir_fsp = dir_fsp,
    2475       20140 :                 .recv_fn = handle->fns->getxattrat_recv_fn,
    2476             :         };
    2477             : 
    2478       20140 :         subreq = handle->fns->getxattrat_send_fn(mem_ctx,
    2479             :                                                  ev,
    2480             :                                                  handle,
    2481             :                                                  dir_fsp,
    2482             :                                                  smb_fname,
    2483             :                                                  xattr_name,
    2484             :                                                  alloc_hint);
    2485       20140 :         if (tevent_req_nomem(subreq, req)) {
    2486           0 :                 return tevent_req_post(req, ev);
    2487             :         }
    2488       20140 :         tevent_req_defer_callback(req, ev);
    2489             : 
    2490       20140 :         tevent_req_set_callback(subreq, smb_vfs_call_getxattrat_done, req);
    2491       20140 :         return req;
    2492             : }
    2493             : 
    2494       20140 : static void smb_vfs_call_getxattrat_done(struct tevent_req *subreq)
    2495             : {
    2496       20140 :         struct tevent_req *req = tevent_req_callback_data(
    2497             :                 subreq, struct tevent_req);
    2498       20140 :         struct smb_vfs_call_getxattrat_state *state = tevent_req_data(
    2499             :                 req, struct smb_vfs_call_getxattrat_state);
    2500           0 :         bool ok;
    2501             : 
    2502             :         /*
    2503             :          * Make sure we run as the user again
    2504             :          */
    2505       20140 :         ok = change_to_user_and_service_by_fsp(state->dir_fsp);
    2506       20140 :         SMB_ASSERT(ok);
    2507             : 
    2508       20140 :         state->retval = state->recv_fn(subreq,
    2509             :                                        &state->aio_state,
    2510             :                                        state,
    2511             :                                        &state->xattr_value);
    2512       20140 :         TALLOC_FREE(subreq);
    2513       20140 :         if (state->retval == -1) {
    2514         122 :                 tevent_req_error(req, state->aio_state.error);
    2515         122 :                 return;
    2516             :         }
    2517             : 
    2518       20018 :         tevent_req_done(req);
    2519             : }
    2520             : 
    2521       20140 : ssize_t smb_vfs_call_getxattrat_recv(struct tevent_req *req,
    2522             :                                      struct vfs_aio_state *aio_state,
    2523             :                                      TALLOC_CTX *mem_ctx,
    2524             :                                      uint8_t **xattr_value)
    2525             : {
    2526       20140 :         struct smb_vfs_call_getxattrat_state *state = tevent_req_data(
    2527             :                 req, struct smb_vfs_call_getxattrat_state);
    2528           0 :         size_t xattr_size;
    2529             : 
    2530       20140 :         if (tevent_req_is_unix_error(req, &aio_state->error)) {
    2531         122 :                 tevent_req_received(req);
    2532         122 :                 return -1;
    2533             :         }
    2534             : 
    2535       20018 :         *aio_state = state->aio_state;
    2536       20018 :         xattr_size = state->retval;
    2537       20018 :         if (xattr_value != NULL) {
    2538       20018 :                 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
    2539             :         }
    2540             : 
    2541       20018 :         tevent_req_received(req);
    2542       20018 :         return xattr_size;
    2543             : }
    2544             : 
    2545    25650735 : ssize_t smb_vfs_call_fgetxattr(struct vfs_handle_struct *handle,
    2546             :                                struct files_struct *fsp, const char *name,
    2547             :                                void *value, size_t size)
    2548             : {
    2549    28949512 :         VFS_FIND(fgetxattr);
    2550    25650735 :         return handle->fns->fgetxattr_fn(handle, fsp, name, value, size);
    2551             : }
    2552             : 
    2553     1483785 : ssize_t smb_vfs_call_flistxattr(struct vfs_handle_struct *handle,
    2554             :                                 struct files_struct *fsp, char *list,
    2555             :                                 size_t size)
    2556             : {
    2557     2603410 :         VFS_FIND(flistxattr);
    2558     1483785 :         return handle->fns->flistxattr_fn(handle, fsp, list, size);
    2559             : }
    2560             : 
    2561        4485 : int smb_vfs_call_fremovexattr(struct vfs_handle_struct *handle,
    2562             :                               struct files_struct *fsp, const char *name)
    2563             : {
    2564        7007 :         VFS_FIND(fremovexattr);
    2565        4485 :         return handle->fns->fremovexattr_fn(handle, fsp, name);
    2566             : }
    2567             : 
    2568     1123268 : int smb_vfs_call_fsetxattr(struct vfs_handle_struct *handle,
    2569             :                            struct files_struct *fsp, const char *name,
    2570             :                            const void *value, size_t size, int flags)
    2571             : {
    2572     1593922 :         VFS_FIND(fsetxattr);
    2573     1123268 :         return handle->fns->fsetxattr_fn(handle, fsp, name, value, size, flags);
    2574             : }
    2575             : 
    2576         195 : bool smb_vfs_call_aio_force(struct vfs_handle_struct *handle,
    2577             :                             struct files_struct *fsp)
    2578             : {
    2579         540 :         VFS_FIND(aio_force);
    2580         195 :         return handle->fns->aio_force_fn(handle, fsp);
    2581             : }
    2582             : 
    2583        1318 : NTSTATUS smb_vfs_call_durable_cookie(struct vfs_handle_struct *handle,
    2584             :                                      struct files_struct *fsp,
    2585             :                                      TALLOC_CTX *mem_ctx,
    2586             :                                      DATA_BLOB *cookie)
    2587             : {
    2588        3670 :         VFS_FIND(durable_cookie);
    2589        1318 :         return handle->fns->durable_cookie_fn(handle, fsp, mem_ctx, cookie);
    2590             : }
    2591             : 
    2592         392 : NTSTATUS smb_vfs_call_durable_disconnect(struct vfs_handle_struct *handle,
    2593             :                                          struct files_struct *fsp,
    2594             :                                          const DATA_BLOB old_cookie,
    2595             :                                          TALLOC_CTX *mem_ctx,
    2596             :                                          DATA_BLOB *new_cookie)
    2597             : {
    2598        1106 :         VFS_FIND(durable_disconnect);
    2599         392 :         return handle->fns->durable_disconnect_fn(handle, fsp, old_cookie,
    2600             :                                                   mem_ctx, new_cookie);
    2601             : }
    2602             : 
    2603         378 : NTSTATUS smb_vfs_call_durable_reconnect(struct vfs_handle_struct *handle,
    2604             :                                         struct smb_request *smb1req,
    2605             :                                         struct smbXsrv_open *op,
    2606             :                                         const DATA_BLOB old_cookie,
    2607             :                                         TALLOC_CTX *mem_ctx,
    2608             :                                         struct files_struct **fsp,
    2609             :                                         DATA_BLOB *new_cookie)
    2610             : {
    2611        1050 :         VFS_FIND(durable_reconnect);
    2612         378 :         return handle->fns->durable_reconnect_fn(handle, smb1req, op,
    2613             :                                                  old_cookie, mem_ctx, fsp,
    2614             :                                                  new_cookie);
    2615             : }
    2616             : 
    2617     1738437 : NTSTATUS smb_vfs_call_freaddir_attr(struct vfs_handle_struct *handle,
    2618             :                                     struct files_struct *fsp,
    2619             :                                     TALLOC_CTX *mem_ctx,
    2620             :                                     struct readdir_attr_data **attr_data)
    2621             : {
    2622     5629632 :         VFS_FIND(freaddir_attr);
    2623     1738437 :         return handle->fns->freaddir_attr_fn(handle,
    2624             :                                              fsp,
    2625             :                                              mem_ctx,
    2626             :                                              attr_data);
    2627             : }
    2628             : 
    2629       16496 : bool smb_vfs_call_lock(struct vfs_handle_struct *handle,
    2630             :                        struct files_struct *fsp, int op, off_t offset,
    2631             :                        off_t count, int type)
    2632             : {
    2633       37806 :         VFS_FIND(lock);
    2634       16496 :         return handle->fns->lock_fn(handle, fsp, op, offset, count, type);
    2635             : }
    2636             : 
    2637      466196 : bool smb_vfs_call_getlock(struct vfs_handle_struct *handle,
    2638             :                           struct files_struct *fsp, off_t *poffset,
    2639             :                           off_t *pcount, int *ptype, pid_t *ppid)
    2640             : {
    2641     1161686 :         VFS_FIND(getlock);
    2642      466196 :         return handle->fns->getlock_fn(handle, fsp, poffset, pcount, ptype,
    2643             :                                        ppid);
    2644             : }
    2645             : 
    2646       17121 : NTSTATUS smb_vfs_call_brl_lock_windows(struct vfs_handle_struct *handle,
    2647             :                                        struct byte_range_lock *br_lck,
    2648             :                                        struct lock_struct *plock)
    2649             : {
    2650       40381 :         VFS_FIND(brl_lock_windows);
    2651       17121 :         return handle->fns->brl_lock_windows_fn(handle, br_lck, plock);
    2652             : }
    2653             : 
    2654        8447 : bool smb_vfs_call_brl_unlock_windows(struct vfs_handle_struct *handle,
    2655             :                                      struct byte_range_lock *br_lck,
    2656             :                                      const struct lock_struct *plock)
    2657             : {
    2658       20079 :         VFS_FIND(brl_unlock_windows);
    2659        8447 :         return handle->fns->brl_unlock_windows_fn(handle, br_lck, plock);
    2660             : }

Generated by: LCOV version 1.14