netapi: add NetShareDel example code.
[Samba/gbeck.git] / source3 / smbd / fileio.c
blob64cea7f7ced116b87b4f1ccac2361484429f8643
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 read/write to a files_struct
5 Copyright (C) Andrew Tridgell 1992-1998
6 Copyright (C) Jeremy Allison 2000-2002. - write cache.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
24 static bool setup_write_cache(files_struct *, SMB_OFF_T);
26 /****************************************************************************
27 Read from write cache if we can.
28 ****************************************************************************/
30 static bool read_from_write_cache(files_struct *fsp,char *data,SMB_OFF_T pos,size_t n)
32 write_cache *wcp = fsp->wcp;
34 if(!wcp) {
35 return False;
38 if( n > wcp->data_size || pos < wcp->offset || pos + n > wcp->offset + wcp->data_size) {
39 return False;
42 memcpy(data, wcp->data + (pos - wcp->offset), n);
44 DO_PROFILE_INC(writecache_read_hits);
46 return True;
49 /****************************************************************************
50 Read from a file.
51 ****************************************************************************/
53 ssize_t read_file(files_struct *fsp,char *data,SMB_OFF_T pos,size_t n)
55 ssize_t ret=0,readret;
57 /* you can't read from print files */
58 if (fsp->print_file) {
59 return -1;
63 * Serve from write cache if we can.
66 if(read_from_write_cache(fsp, data, pos, n)) {
67 fsp->fh->pos = pos + n;
68 fsp->fh->position_information = fsp->fh->pos;
69 return n;
72 flush_write_cache(fsp, READ_FLUSH);
74 fsp->fh->pos = pos;
76 if (n > 0) {
77 #ifdef DMF_FIX
78 int numretries = 3;
79 tryagain:
80 readret = SMB_VFS_PREAD(fsp,data,n,pos);
82 if (readret == -1) {
83 if ((errno == EAGAIN) && numretries) {
84 DEBUG(3,("read_file EAGAIN retry in 10 seconds\n"));
85 (void)sleep(10);
86 --numretries;
87 goto tryagain;
89 return -1;
91 #else /* NO DMF fix. */
92 readret = SMB_VFS_PREAD(fsp,data,n,pos);
94 if (readret == -1) {
95 return -1;
97 #endif
98 if (readret > 0) {
99 ret += readret;
103 DEBUG(10,("read_file (%s): pos = %.0f, size = %lu, returned %lu\n",
104 fsp->fsp_name, (double)pos, (unsigned long)n, (long)ret ));
106 fsp->fh->pos += ret;
107 fsp->fh->position_information = fsp->fh->pos;
109 return(ret);
112 /* how many write cache buffers have been allocated */
113 static unsigned int allocated_write_caches;
115 /****************************************************************************
116 *Really* write to a file.
117 ****************************************************************************/
119 static ssize_t real_write_file(struct smb_request *req,
120 files_struct *fsp,
121 const char *data,
122 SMB_OFF_T pos,
123 size_t n)
125 ssize_t ret;
127 if (pos == -1) {
128 ret = vfs_write_data(req, fsp, data, n);
129 } else {
130 fsp->fh->pos = pos;
131 if (pos && lp_strict_allocate(SNUM(fsp->conn))) {
132 if (vfs_fill_sparse(fsp, pos) == -1) {
133 return -1;
136 ret = vfs_pwrite_data(req, fsp, data, n, pos);
139 DEBUG(10,("real_write_file (%s): pos = %.0f, size = %lu, returned %ld\n",
140 fsp->fsp_name, (double)pos, (unsigned long)n, (long)ret ));
142 if (ret != -1) {
143 fsp->fh->pos += ret;
145 /* Yes - this is correct - writes don't update this. JRA. */
146 /* Found by Samba4 tests. */
147 #if 0
148 fsp->position_information = fsp->pos;
149 #endif
152 return ret;
155 /****************************************************************************
156 File size cache change.
157 Updates size on disk but doesn't flush the cache.
158 ****************************************************************************/
160 static int wcp_file_size_change(files_struct *fsp)
162 int ret;
163 write_cache *wcp = fsp->wcp;
165 wcp->file_size = wcp->offset + wcp->data_size;
166 ret = SMB_VFS_FTRUNCATE(fsp, wcp->file_size);
167 if (ret == -1) {
168 DEBUG(0,("wcp_file_size_change (%s): ftruncate of size %.0f error %s\n",
169 fsp->fsp_name, (double)wcp->file_size, strerror(errno) ));
171 return ret;
174 static void update_write_time_handler(struct event_context *ctx,
175 struct timed_event *te,
176 const struct timeval *now,
177 void *private_data)
179 files_struct *fsp = (files_struct *)private_data;
181 /* Remove the timed event handler. */
182 TALLOC_FREE(fsp->update_write_time_event);
183 DEBUG(5, ("Update write time on %s\n", fsp->fsp_name));
185 /* change the write time if not already changed by someoneelse */
186 set_write_time_fsp(fsp, timespec_current(), false);
189 void trigger_write_time_update(struct files_struct *fsp)
191 int delay;
193 if (fsp->write_time_forced) {
194 return;
197 if (fsp->update_write_time_triggered) {
198 return;
200 fsp->update_write_time_triggered = true;
202 delay = lp_parm_int(SNUM(fsp->conn),
203 "smbd", "writetimeupdatedelay",
204 WRITE_TIME_UPDATE_USEC_DELAY);
206 /* trigger the update 2 seconds later */
207 fsp->update_write_time_on_close = true;
208 fsp->update_write_time_event =
209 event_add_timed(smbd_event_context(), NULL,
210 timeval_current_ofs(0, delay),
211 "update_write_time_handler",
212 update_write_time_handler, fsp);
215 /****************************************************************************
216 Write to a file.
217 ****************************************************************************/
219 ssize_t write_file(struct smb_request *req,
220 files_struct *fsp,
221 const char *data,
222 SMB_OFF_T pos,
223 size_t n)
225 write_cache *wcp = fsp->wcp;
226 ssize_t total_written = 0;
227 int write_path = -1;
229 if (fsp->print_file) {
230 fstring sharename;
231 uint32 jobid;
233 if (!rap_to_pjobid(fsp->rap_print_jobid, sharename, &jobid)) {
234 DEBUG(3,("write_file: Unable to map RAP jobid %u to jobid.\n",
235 (unsigned int)fsp->rap_print_jobid ));
236 errno = EBADF;
237 return -1;
240 return print_job_write(SNUM(fsp->conn), jobid, data, pos, n);
243 if (!fsp->can_write) {
244 errno = EPERM;
245 return -1;
248 if (!fsp->modified) {
249 SMB_STRUCT_STAT st;
250 fsp->modified = True;
252 if (SMB_VFS_FSTAT(fsp, &st) == 0) {
253 int dosmode;
254 trigger_write_time_update(fsp);
255 dosmode = dos_mode(fsp->conn,fsp->fsp_name,&st);
256 if ((lp_store_dos_attributes(SNUM(fsp->conn)) ||
257 MAP_ARCHIVE(fsp->conn)) &&
258 !IS_DOS_ARCHIVE(dosmode)) {
259 file_set_dosmode(fsp->conn,fsp->fsp_name,
260 dosmode | aARCH,&st,
261 NULL,
262 false);
266 * If this is the first write and we have an exclusive oplock then setup
267 * the write cache.
270 if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && !wcp) {
271 setup_write_cache(fsp, st.st_size);
272 wcp = fsp->wcp;
277 #ifdef WITH_PROFILE
278 DO_PROFILE_INC(writecache_total_writes);
279 if (!fsp->oplock_type) {
280 DO_PROFILE_INC(writecache_non_oplock_writes);
282 #endif
285 * If this file is level II oplocked then we need
286 * to grab the shared memory lock and inform all
287 * other files with a level II lock that they need
288 * to flush their read caches. We keep the lock over
289 * the shared memory area whilst doing this.
292 release_level_2_oplocks_on_change(fsp);
294 #ifdef WITH_PROFILE
295 if (profile_p && profile_p->writecache_total_writes % 500 == 0) {
296 DEBUG(3,("WRITECACHE: initwrites=%u abutted=%u total=%u \
297 nonop=%u allocated=%u active=%u direct=%u perfect=%u readhits=%u\n",
298 profile_p->writecache_init_writes,
299 profile_p->writecache_abutted_writes,
300 profile_p->writecache_total_writes,
301 profile_p->writecache_non_oplock_writes,
302 profile_p->writecache_allocated_write_caches,
303 profile_p->writecache_num_write_caches,
304 profile_p->writecache_direct_writes,
305 profile_p->writecache_num_perfect_writes,
306 profile_p->writecache_read_hits ));
308 DEBUG(3,("WRITECACHE: Flushes SEEK=%d, READ=%d, WRITE=%d, READRAW=%d, OPLOCK=%d, CLOSE=%d, SYNC=%d\n",
309 profile_p->writecache_flushed_writes[SEEK_FLUSH],
310 profile_p->writecache_flushed_writes[READ_FLUSH],
311 profile_p->writecache_flushed_writes[WRITE_FLUSH],
312 profile_p->writecache_flushed_writes[READRAW_FLUSH],
313 profile_p->writecache_flushed_writes[OPLOCK_RELEASE_FLUSH],
314 profile_p->writecache_flushed_writes[CLOSE_FLUSH],
315 profile_p->writecache_flushed_writes[SYNC_FLUSH] ));
317 #endif
319 if (wcp && req->unread_bytes) {
320 /* If we're using receivefile don't
321 * deal with a write cache.
323 flush_write_cache(fsp, WRITE_FLUSH);
324 delete_write_cache(fsp);
325 wcp = NULL;
328 if(!wcp) {
329 DO_PROFILE_INC(writecache_direct_writes);
330 total_written = real_write_file(req, fsp, data, pos, n);
331 return total_written;
334 DEBUG(9,("write_file (%s)(fd=%d pos=%.0f size=%u) wcp->offset=%.0f wcp->data_size=%u\n",
335 fsp->fsp_name, fsp->fh->fd, (double)pos, (unsigned int)n, (double)wcp->offset, (unsigned int)wcp->data_size));
337 fsp->fh->pos = pos + n;
340 * If we have active cache and it isn't contiguous then we flush.
341 * NOTE: There is a small problem with running out of disk ....
344 if (wcp->data_size) {
345 bool cache_flush_needed = False;
347 if ((pos >= wcp->offset) && (pos <= wcp->offset + wcp->data_size)) {
349 /* ASCII art.... JRA.
351 +--------------+-----
352 | Cached data | Rest of allocated cache buffer....
353 +--------------+-----
355 +-------------------+
356 | Data to write |
357 +-------------------+
362 * Start of write overlaps or abutts the existing data.
365 size_t data_used = MIN((wcp->alloc_size - (pos - wcp->offset)), n);
367 memcpy(wcp->data + (pos - wcp->offset), data, data_used);
370 * Update the current buffer size with the new data.
373 if(pos + data_used > wcp->offset + wcp->data_size) {
374 wcp->data_size = pos + data_used - wcp->offset;
378 * Update the file size if changed.
381 if (wcp->offset + wcp->data_size > wcp->file_size) {
382 if (wcp_file_size_change(fsp) == -1) {
383 return -1;
388 * If we used all the data then
389 * return here.
392 if(n == data_used) {
393 return n;
394 } else {
395 cache_flush_needed = True;
398 * Move the start of data forward by the amount used,
399 * cut down the amount left by the same amount.
402 data += data_used;
403 pos += data_used;
404 n -= data_used;
406 DO_PROFILE_INC(writecache_abutted_writes);
407 total_written = data_used;
409 write_path = 1;
411 } else if ((pos < wcp->offset) && (pos + n > wcp->offset) &&
412 (pos + n <= wcp->offset + wcp->alloc_size)) {
414 /* ASCII art.... JRA.
416 +---------------+
417 | Cache buffer |
418 +---------------+
420 +-------------------+
421 | Data to write |
422 +-------------------+
427 * End of write overlaps the existing data.
430 size_t data_used = pos + n - wcp->offset;
432 memcpy(wcp->data, data + n - data_used, data_used);
435 * Update the current buffer size with the new data.
438 if(pos + n > wcp->offset + wcp->data_size) {
439 wcp->data_size = pos + n - wcp->offset;
443 * Update the file size if changed.
446 if (wcp->offset + wcp->data_size > wcp->file_size) {
447 if (wcp_file_size_change(fsp) == -1) {
448 return -1;
453 * We don't need to move the start of data, but we
454 * cut down the amount left by the amount used.
457 n -= data_used;
460 * We cannot have used all the data here.
463 cache_flush_needed = True;
465 DO_PROFILE_INC(writecache_abutted_writes);
466 total_written = data_used;
468 write_path = 2;
470 } else if ( (pos >= wcp->file_size) &&
471 (wcp->offset + wcp->data_size == wcp->file_size) &&
472 (pos > wcp->offset + wcp->data_size) &&
473 (pos < wcp->offset + wcp->alloc_size) ) {
475 /* ASCII art.... JRA.
477 End of file ---->|
479 +---------------+---------------+
480 | Cached data | Cache buffer |
481 +---------------+---------------+
483 +-------------------+
484 | Data to write |
485 +-------------------+
490 * Non-contiguous write part of which fits within
491 * the cache buffer and is extending the file
492 * and the cache contents reflect the current
493 * data up to the current end of the file.
496 size_t data_used;
498 if(pos + n <= wcp->offset + wcp->alloc_size) {
499 data_used = n;
500 } else {
501 data_used = wcp->offset + wcp->alloc_size - pos;
505 * Fill in the non-continuous area with zeros.
508 memset(wcp->data + wcp->data_size, '\0',
509 pos - (wcp->offset + wcp->data_size) );
511 memcpy(wcp->data + (pos - wcp->offset), data, data_used);
514 * Update the current buffer size with the new data.
517 if(pos + data_used > wcp->offset + wcp->data_size) {
518 wcp->data_size = pos + data_used - wcp->offset;
522 * Update the file size if changed.
525 if (wcp->offset + wcp->data_size > wcp->file_size) {
526 if (wcp_file_size_change(fsp) == -1) {
527 return -1;
532 * If we used all the data then
533 * return here.
536 if(n == data_used) {
537 return n;
538 } else {
539 cache_flush_needed = True;
543 * Move the start of data forward by the amount used,
544 * cut down the amount left by the same amount.
547 data += data_used;
548 pos += data_used;
549 n -= data_used;
551 DO_PROFILE_INC(writecache_abutted_writes);
552 total_written = data_used;
554 write_path = 3;
556 } else if ( (pos >= wcp->file_size) &&
557 (n == 1) &&
558 (wcp->file_size == wcp->offset + wcp->data_size) &&
559 (pos < wcp->file_size + wcp->alloc_size)) {
563 End of file ---->|
565 +---------------+---------------+
566 | Cached data | Cache buffer |
567 +---------------+---------------+
569 |<------- allocated size ---------------->|
571 +--------+
572 | 1 Byte |
573 +--------+
575 MS-Office seems to do this a lot to determine if there's enough
576 space on the filesystem to write a new file.
578 Change to :
580 End of file ---->|
581 +-----------------------+--------+
582 | Zeroed Cached data | 1 Byte |
583 +-----------------------+--------+
586 flush_write_cache(fsp, WRITE_FLUSH);
587 wcp->offset = wcp->file_size;
588 wcp->data_size = pos - wcp->file_size + 1;
589 memset(wcp->data, '\0', wcp->data_size);
590 memcpy(wcp->data + wcp->data_size-1, data, 1);
593 * Update the file size if changed.
596 if (wcp->offset + wcp->data_size > wcp->file_size) {
597 if (wcp_file_size_change(fsp) == -1) {
598 return -1;
602 return n;
604 } else {
606 /* ASCII art..... JRA.
608 Case 1).
610 +---------------+---------------+
611 | Cached data | Cache buffer |
612 +---------------+---------------+
614 +-------------------+
615 | Data to write |
616 +-------------------+
618 Case 2).
620 +---------------+---------------+
621 | Cached data | Cache buffer |
622 +---------------+---------------+
624 +-------------------+
625 | Data to write |
626 +-------------------+
628 Case 3).
630 +---------------+---------------+
631 | Cached data | Cache buffer |
632 +---------------+---------------+
634 +-----------------------------------------------------+
635 | Data to write |
636 +-----------------------------------------------------+
641 * Write is bigger than buffer, or there is no overlap on the
642 * low or high ends.
645 DEBUG(9,("write_file: non cacheable write : fd = %d, pos = %.0f, len = %u, current cache pos = %.0f \
646 len = %u\n",fsp->fh->fd, (double)pos, (unsigned int)n, (double)wcp->offset, (unsigned int)wcp->data_size ));
649 * If write would fit in the cache, and is larger than
650 * the data already in the cache, flush the cache and
651 * preferentially copy the data new data into it. Otherwise
652 * just write the data directly.
655 if ( n <= wcp->alloc_size && n > wcp->data_size) {
656 cache_flush_needed = True;
657 } else {
658 ssize_t ret = real_write_file(NULL,fsp, data, pos, n);
661 * If the write overlaps the entire cache, then
662 * discard the current contents of the cache.
663 * Fix from Rasmus Borup Hansen rbh@math.ku.dk.
666 if ((pos <= wcp->offset) &&
667 (pos + n >= wcp->offset + wcp->data_size) ) {
668 DEBUG(9,("write_file: discarding overwritten write \
669 cache: fd = %d, off=%.0f, size=%u\n", fsp->fh->fd, (double)wcp->offset, (unsigned int)wcp->data_size ));
670 wcp->data_size = 0;
673 DO_PROFILE_INC(writecache_direct_writes);
674 if (ret == -1) {
675 return ret;
678 if (pos + ret > wcp->file_size) {
679 wcp->file_size = pos + ret;
682 return ret;
685 write_path = 4;
689 if (cache_flush_needed) {
690 DEBUG(3,("WRITE_FLUSH:%d: due to noncontinuous write: fd = %d, size = %.0f, pos = %.0f, \
691 n = %u, wcp->offset=%.0f, wcp->data_size=%u\n",
692 write_path, fsp->fh->fd, (double)wcp->file_size, (double)pos, (unsigned int)n,
693 (double)wcp->offset, (unsigned int)wcp->data_size ));
695 flush_write_cache(fsp, WRITE_FLUSH);
700 * If the write request is bigger than the cache
701 * size, write it all out.
704 if (n > wcp->alloc_size ) {
705 ssize_t ret = real_write_file(NULL,fsp, data, pos, n);
706 if (ret == -1) {
707 return -1;
710 if (pos + ret > wcp->file_size) {
711 wcp->file_size = pos + n;
714 DO_PROFILE_INC(writecache_direct_writes);
715 return total_written + n;
719 * If there's any data left, cache it.
722 if (n) {
723 #ifdef WITH_PROFILE
724 if (wcp->data_size) {
725 DO_PROFILE_INC(writecache_abutted_writes);
726 } else {
727 DO_PROFILE_INC(writecache_init_writes);
729 #endif
730 memcpy(wcp->data+wcp->data_size, data, n);
731 if (wcp->data_size == 0) {
732 wcp->offset = pos;
733 DO_PROFILE_INC(writecache_num_write_caches);
735 wcp->data_size += n;
738 * Update the file size if changed.
741 if (wcp->offset + wcp->data_size > wcp->file_size) {
742 if (wcp_file_size_change(fsp) == -1) {
743 return -1;
746 DEBUG(9,("wcp->offset = %.0f wcp->data_size = %u cache return %u\n",
747 (double)wcp->offset, (unsigned int)wcp->data_size, (unsigned int)n));
749 total_written += n;
750 return total_written; /* .... that's a write :) */
753 return total_written;
756 /****************************************************************************
757 Delete the write cache structure.
758 ****************************************************************************/
760 void delete_write_cache(files_struct *fsp)
762 write_cache *wcp;
764 if(!fsp) {
765 return;
768 if(!(wcp = fsp->wcp)) {
769 return;
772 DO_PROFILE_DEC(writecache_allocated_write_caches);
773 allocated_write_caches--;
775 SMB_ASSERT(wcp->data_size == 0);
777 SAFE_FREE(wcp->data);
778 SAFE_FREE(fsp->wcp);
780 DEBUG(10,("delete_write_cache: File %s deleted write cache\n", fsp->fsp_name ));
783 /****************************************************************************
784 Setup the write cache structure.
785 ****************************************************************************/
787 static bool setup_write_cache(files_struct *fsp, SMB_OFF_T file_size)
789 ssize_t alloc_size = lp_write_cache_size(SNUM(fsp->conn));
790 write_cache *wcp;
792 if (allocated_write_caches >= MAX_WRITE_CACHES) {
793 return False;
796 if(alloc_size == 0 || fsp->wcp) {
797 return False;
800 if((wcp = SMB_MALLOC_P(write_cache)) == NULL) {
801 DEBUG(0,("setup_write_cache: malloc fail.\n"));
802 return False;
805 wcp->file_size = file_size;
806 wcp->offset = 0;
807 wcp->alloc_size = alloc_size;
808 wcp->data_size = 0;
809 if((wcp->data = (char *)SMB_MALLOC(wcp->alloc_size)) == NULL) {
810 DEBUG(0,("setup_write_cache: malloc fail for buffer size %u.\n",
811 (unsigned int)wcp->alloc_size ));
812 SAFE_FREE(wcp);
813 return False;
816 memset(wcp->data, '\0', wcp->alloc_size );
818 fsp->wcp = wcp;
819 DO_PROFILE_INC(writecache_allocated_write_caches);
820 allocated_write_caches++;
822 DEBUG(10,("setup_write_cache: File %s allocated write cache size %lu\n",
823 fsp->fsp_name, (unsigned long)wcp->alloc_size ));
825 return True;
828 /****************************************************************************
829 Cope with a size change.
830 ****************************************************************************/
832 void set_filelen_write_cache(files_struct *fsp, SMB_OFF_T file_size)
834 if(fsp->wcp) {
835 /* The cache *must* have been flushed before we do this. */
836 if (fsp->wcp->data_size != 0) {
837 char *msg;
838 asprintf(&msg, "set_filelen_write_cache: size change "
839 "on file %s with write cache size = %lu\n",
840 fsp->fsp_name,
841 (unsigned long)fsp->wcp->data_size);
842 smb_panic(msg);
844 fsp->wcp->file_size = file_size;
848 /*******************************************************************
849 Flush a write cache struct to disk.
850 ********************************************************************/
852 ssize_t flush_write_cache(files_struct *fsp, enum flush_reason_enum reason)
854 write_cache *wcp = fsp->wcp;
855 size_t data_size;
856 ssize_t ret;
858 if(!wcp || !wcp->data_size) {
859 return 0;
862 data_size = wcp->data_size;
863 wcp->data_size = 0;
865 DO_PROFILE_DEC_INC(writecache_num_write_caches,writecache_flushed_writes[reason]);
867 DEBUG(9,("flushing write cache: fd = %d, off=%.0f, size=%u\n",
868 fsp->fh->fd, (double)wcp->offset, (unsigned int)data_size));
870 #ifdef WITH_PROFILE
871 if(data_size == wcp->alloc_size) {
872 DO_PROFILE_INC(writecache_num_perfect_writes);
874 #endif
876 ret = real_write_file(NULL, fsp, wcp->data, wcp->offset, data_size);
879 * Ensure file size if kept up to date if write extends file.
882 if ((ret != -1) && (wcp->offset + ret > wcp->file_size)) {
883 wcp->file_size = wcp->offset + ret;
886 return ret;
889 /*******************************************************************
890 sync a file
891 ********************************************************************/
893 NTSTATUS sync_file(connection_struct *conn, files_struct *fsp, bool write_through)
895 if (fsp->fh->fd == -1)
896 return NT_STATUS_INVALID_HANDLE;
898 if (lp_strict_sync(SNUM(conn)) &&
899 (lp_syncalways(SNUM(conn)) || write_through)) {
900 int ret = flush_write_cache(fsp, SYNC_FLUSH);
901 if (ret == -1) {
902 return map_nt_error_from_unix(errno);
904 ret = SMB_VFS_FSYNC(fsp);
905 if (ret == -1) {
906 return map_nt_error_from_unix(errno);
909 return NT_STATUS_OK;
912 /************************************************************
913 Perform a stat whether a valid fd or not.
914 ************************************************************/
916 int fsp_stat(files_struct *fsp, SMB_STRUCT_STAT *pst)
918 if (fsp->fh->fd == -1) {
919 return SMB_VFS_STAT(fsp->conn, fsp->fsp_name, pst);
920 } else {
921 return SMB_VFS_FSTAT(fsp, pst);