Added per-share parameter "store dos attributes". When set, will store
[tprouty/samba.git] / source / smbd / fileio.c
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.
7    
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 2 of the License, or
11    (at your option) any later version.
12    
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.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24
25 static BOOL setup_write_cache(files_struct *, SMB_OFF_T);
26
27 /****************************************************************************
28  Read from write cache if we can.
29 ****************************************************************************/
30
31
32 static BOOL read_from_write_cache(files_struct *fsp,char *data,SMB_OFF_T pos,size_t n)
33 {
34         write_cache *wcp = fsp->wcp;
35
36         if(!wcp)
37                 return False;
38
39         if(n > wcp->data_size || pos < wcp->offset || pos + n > wcp->offset + wcp->data_size)
40                 return False;
41
42         memcpy(data, wcp->data + (pos - wcp->offset), n);
43
44         DO_PROFILE_INC(writecache_read_hits);
45
46         return True;
47 }
48
49 /****************************************************************************
50  Read from a file.
51 ****************************************************************************/
52
53 ssize_t read_file(files_struct *fsp,char *data,SMB_OFF_T pos,size_t n)
54 {
55         ssize_t ret=0,readret;
56
57         /* you can't read from print files */
58         if (fsp->print_file)
59                 return -1;
60
61         /*
62          * Serve from write cache if we can.
63          */
64
65         if(read_from_write_cache(fsp, data, pos, n)) {
66                 fsp->pos = pos + n;
67                 fsp->position_information = fsp->pos;
68                 return n;
69         }
70
71         flush_write_cache(fsp, READ_FLUSH);
72
73         fsp->pos = pos;
74
75         if (n > 0) {
76 #ifdef DMF_FIX
77                 int numretries = 3;
78 tryagain:
79                 readret = SMB_VFS_PREAD(fsp,fsp->fd,data,n,pos);
80
81                 if (readret == -1) {
82                         if ((errno == EAGAIN) && numretries) {
83                                 DEBUG(3,("read_file EAGAIN retry in 10 seconds\n"));
84                                 (void)sleep(10);
85                                 --numretries;
86                                 goto tryagain;
87                         }
88                         return -1;
89                 }
90 #else /* NO DMF fix. */
91                 readret = SMB_VFS_PREAD(fsp,fsp->fd,data,n,pos);
92
93                 if (readret == -1)
94                         return -1;
95 #endif
96                 if (readret > 0)
97                         ret += readret;
98         }
99
100         DEBUG(10,("read_file (%s): pos = %.0f, size = %lu, returned %lu\n",
101                 fsp->fsp_name, (double)pos, (unsigned long)n, (long)ret ));
102
103         fsp->pos += ret;
104         fsp->position_information = fsp->pos;
105
106         return(ret);
107 }
108
109 /* how many write cache buffers have been allocated */
110 static unsigned int allocated_write_caches;
111
112 /****************************************************************************
113  *Really* write to a file.
114 ****************************************************************************/
115
116 static ssize_t real_write_file(files_struct *fsp,char *data,SMB_OFF_T pos, size_t n)
117 {
118         ssize_t ret;
119
120         if (pos == -1)
121                 ret = vfs_write_data(fsp, data, n);
122         else {
123                 fsp->pos = pos;
124                 ret = vfs_pwrite_data(fsp, data, n, pos);
125         }
126
127         DEBUG(10,("real_write_file (%s): pos = %.0f, size = %lu, returned %ld\n",
128                 fsp->fsp_name, (double)pos, (unsigned long)n, (long)ret ));
129
130         if (ret != -1) {
131                 fsp->pos += ret;
132
133 /* Yes - this is correct - writes don't update this. JRA. */
134 /* Found by Samba4 tests. */
135 #if 0
136                 fsp->position_information = fsp->pos;
137 #endif
138         }
139
140         return ret;
141 }
142
143 /****************************************************************************
144 write to a file
145 ****************************************************************************/
146
147 ssize_t write_file(files_struct *fsp, char *data, SMB_OFF_T pos, size_t n)
148 {
149         write_cache *wcp = fsp->wcp;
150         ssize_t total_written = 0;
151         int write_path = -1; 
152
153         if (fsp->print_file) {
154                 int snum;
155                 uint32 jobid;
156
157                 if (!rap_to_pjobid(fsp->rap_print_jobid, &snum, &jobid)) {
158                         DEBUG(3,("write_file: Unable to map RAP jobid %u to jobid.\n",
159                                                 (unsigned int)fsp->rap_print_jobid ));
160                         errno = EBADF;
161                         return -1;
162                 }
163
164                 return print_job_write(SNUM(fsp->conn), jobid, data, n);
165         }
166
167         if (!fsp->can_write) {
168                 errno = EPERM;
169                 return(0);
170         }
171
172         if (!fsp->modified) {
173                 SMB_STRUCT_STAT st;
174                 fsp->modified = True;
175
176                 if (SMB_VFS_FSTAT(fsp,fsp->fd,&st) == 0) {
177                         int dosmode = dos_mode(fsp->conn,fsp->fsp_name,&st);
178                         fsp->size = (SMB_BIG_UINT)st.st_size;
179                         if ((lp_store_dos_attributes(SNUM(fsp->conn)) || MAP_ARCHIVE(fsp->conn)) && !IS_DOS_ARCHIVE(dosmode)) {
180                                 file_set_dosmode(fsp->conn,fsp->fsp_name,dosmode | aARCH,&st);
181                         }
182
183                         /*
184                          * If this is the first write and we have an exclusive oplock then setup
185                          * the write cache.
186                          */
187
188                         if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && !wcp) {
189                                 setup_write_cache(fsp, st.st_size);
190                                 wcp = fsp->wcp;
191                         } 
192                 }  
193         }
194
195 #ifdef WITH_PROFILE
196         DO_PROFILE_INC(writecache_total_writes);
197         if (!fsp->oplock_type) {
198                 DO_PROFILE_INC(writecache_non_oplock_writes);
199         }
200 #endif
201
202         /*
203          * If this file is level II oplocked then we need
204          * to grab the shared memory lock and inform all
205          * other files with a level II lock that they need
206          * to flush their read caches. We keep the lock over
207          * the shared memory area whilst doing this.
208          */
209
210         release_level_2_oplocks_on_change(fsp);
211
212 #ifdef WITH_PROFILE
213         if (profile_p && profile_p->writecache_total_writes % 500 == 0) {
214                 DEBUG(3,("WRITECACHE: initwrites=%u abutted=%u total=%u \
215 nonop=%u allocated=%u active=%u direct=%u perfect=%u readhits=%u\n",
216                         profile_p->writecache_init_writes,
217                         profile_p->writecache_abutted_writes,
218                         profile_p->writecache_total_writes,
219                         profile_p->writecache_non_oplock_writes,
220                         profile_p->writecache_allocated_write_caches,
221                         profile_p->writecache_num_write_caches,
222                         profile_p->writecache_direct_writes,
223                         profile_p->writecache_num_perfect_writes,
224                         profile_p->writecache_read_hits ));
225
226                 DEBUG(3,("WRITECACHE: Flushes SEEK=%d, READ=%d, WRITE=%d, READRAW=%d, OPLOCK=%d, CLOSE=%d, SYNC=%d\n",
227                         profile_p->writecache_flushed_writes[SEEK_FLUSH],
228                         profile_p->writecache_flushed_writes[READ_FLUSH],
229                         profile_p->writecache_flushed_writes[WRITE_FLUSH],
230                         profile_p->writecache_flushed_writes[READRAW_FLUSH],
231                         profile_p->writecache_flushed_writes[OPLOCK_RELEASE_FLUSH],
232                         profile_p->writecache_flushed_writes[CLOSE_FLUSH],
233                         profile_p->writecache_flushed_writes[SYNC_FLUSH] ));
234         }
235 #endif
236
237         if(!wcp) {
238                 DO_PROFILE_INC(writecache_direct_writes);
239                 total_written = real_write_file(fsp, data, pos, n);
240                 if ((total_written != -1) && (pos + total_written > (SMB_OFF_T)fsp->size)) 
241                         fsp->size = (SMB_BIG_UINT)(pos + total_written);
242                 return total_written;
243         }
244
245         DEBUG(9,("write_file (%s)(fd=%d pos=%.0f size=%u) wcp->offset=%.0f wcp->data_size=%u\n",
246                 fsp->fsp_name, fsp->fd, (double)pos, (unsigned int)n, (double)wcp->offset, (unsigned int)wcp->data_size));
247
248         fsp->pos = pos + n;
249
250         /* 
251          * If we have active cache and it isn't contiguous then we flush.
252          * NOTE: There is a small problem with running out of disk ....
253          */
254
255         if (wcp->data_size) {
256
257                 BOOL cache_flush_needed = False;
258
259                 if ((pos >= wcp->offset) && (pos <= wcp->offset + wcp->data_size)) {
260       
261                         /* ASCII art.... JRA.
262
263       +--------------+-----
264       | Cached data  | Rest of allocated cache buffer....
265       +--------------+-----
266
267             +-------------------+
268             | Data to write     |
269             +-------------------+
270
271                         */
272
273                         /*
274                          * Start of write overlaps or abutts the existing data.
275                          */
276
277                         size_t data_used = MIN((wcp->alloc_size - (pos - wcp->offset)), n);
278
279                         memcpy(wcp->data + (pos - wcp->offset), data, data_used);
280
281                         /*
282                          * Update the current buffer size with the new data.
283                          */
284
285                         if(pos + data_used > wcp->offset + wcp->data_size)
286                                 wcp->data_size = pos + data_used - wcp->offset;
287
288                         /*
289                          * Update the file size if changed.
290                          */
291
292                         if (wcp->offset + wcp->data_size > wcp->file_size) {
293                                 wcp->file_size = wcp->offset + wcp->data_size;
294                                 fsp->size = (SMB_BIG_UINT)wcp->file_size;
295                         }
296
297                         /*
298                          * If we used all the data then
299                          * return here.
300                          */
301
302                         if(n == data_used)
303                                 return n;
304                         else
305                                 cache_flush_needed = True;
306
307                         /*
308                          * Move the start of data forward by the amount used,
309                          * cut down the amount left by the same amount.
310                          */
311
312                         data += data_used;
313                         pos += data_used;
314                         n -= data_used;
315
316                         DO_PROFILE_INC(writecache_abutted_writes);
317                         total_written = data_used;
318
319                         write_path = 1;
320
321                 } else if ((pos < wcp->offset) && (pos + n > wcp->offset) && 
322                                         (pos + n <= wcp->offset + wcp->alloc_size)) {
323
324                         /* ASCII art.... JRA.
325
326                         +---------------+
327                         | Cache buffer  |
328                         +---------------+
329
330             +-------------------+
331             | Data to write     |
332             +-------------------+
333
334                         */
335
336                         /*
337                          * End of write overlaps the existing data.
338                          */
339
340                         size_t data_used = pos + n - wcp->offset;
341
342                         memcpy(wcp->data, data + n - data_used, data_used);
343
344                         /*
345                          * Update the current buffer size with the new data.
346                          */
347
348                         if(pos + n > wcp->offset + wcp->data_size)
349                                 wcp->data_size = pos + n - wcp->offset;
350
351                         /*
352                          * Update the file size if changed.
353                          */
354
355                         if (wcp->offset + wcp->data_size > wcp->file_size) {
356                                 wcp->file_size = wcp->offset + wcp->data_size;
357                                 fsp->size = (SMB_BIG_UINT)wcp->file_size;
358                         }
359
360                         /*
361                          * We don't need to move the start of data, but we
362                          * cut down the amount left by the amount used.
363                          */
364
365                         n -= data_used;
366
367                         /*
368                          * We cannot have used all the data here.
369                          */
370
371                         cache_flush_needed = True;
372
373                         DO_PROFILE_INC(writecache_abutted_writes);
374                         total_written = data_used;
375
376                         write_path = 2;
377
378                 } else if ( (pos >= wcp->file_size) && 
379                                         (wcp->offset + wcp->data_size == wcp->file_size) &&
380                                         (pos > wcp->offset + wcp->data_size) && 
381                                         (pos < wcp->offset + wcp->alloc_size) ) {
382
383                         /* ASCII art.... JRA.
384
385                        End of file ---->|
386
387                         +---------------+---------------+
388                         | Cached data   | Cache buffer  |
389                         +---------------+---------------+
390
391                                               +-------------------+
392                                               | Data to write     |
393                                               +-------------------+
394
395                         */
396
397                         /*
398                          * Non-contiguous write part of which fits within
399                          * the cache buffer and is extending the file
400                          * and the cache contents reflect the current
401                          * data up to the current end of the file.
402                          */
403
404                         size_t data_used;
405
406                         if(pos + n <= wcp->offset + wcp->alloc_size)
407                                 data_used = n;
408                         else
409                                 data_used = wcp->offset + wcp->alloc_size - pos;
410
411                         /*
412                          * Fill in the non-continuous area with zeros.
413                          */
414
415                         memset(wcp->data + wcp->data_size, '\0',
416                                 pos - (wcp->offset + wcp->data_size) );
417
418                         memcpy(wcp->data + (pos - wcp->offset), data, data_used);
419
420                         /*
421                          * Update the current buffer size with the new data.
422                          */
423
424                         if(pos + data_used > wcp->offset + wcp->data_size)
425                                 wcp->data_size = pos + data_used - wcp->offset;
426
427                         /*
428                          * Update the file size if changed.
429                          */
430
431                         if (wcp->offset + wcp->data_size > wcp->file_size) {
432                                 wcp->file_size = wcp->offset + wcp->data_size;
433                                 fsp->size = (SMB_BIG_UINT)wcp->file_size;
434                         }
435
436                         /*
437                          * If we used all the data then
438                          * return here.
439                          */
440
441                         if(n == data_used)
442                                 return n;
443                         else
444                                 cache_flush_needed = True;
445
446                         /*
447                          * Move the start of data forward by the amount used,
448                          * cut down the amount left by the same amount.
449                          */
450
451                         data += data_used;
452                         pos += data_used;
453                         n -= data_used;
454
455                         DO_PROFILE_INC(writecache_abutted_writes);
456                         total_written = data_used;
457
458                         write_path = 3;
459
460                 } else {
461
462                         /* ASCII art..... JRA.
463
464    Case 1).
465
466                         +---------------+---------------+
467                         | Cached data   | Cache buffer  |
468                         +---------------+---------------+
469
470                                                               +-------------------+
471                                                               | Data to write     |
472                                                               +-------------------+
473
474    Case 2).
475
476                            +---------------+---------------+
477                            | Cached data   | Cache buffer  |
478                            +---------------+---------------+
479
480    +-------------------+
481    | Data to write     |
482    +-------------------+
483
484     Case 3).
485
486                            +---------------+---------------+
487                            | Cached data   | Cache buffer  |
488                            +---------------+---------------+
489
490                   +-----------------------------------------------------+
491                   | Data to write                                       |
492                   +-----------------------------------------------------+
493
494                   */
495
496                         /*
497                          * Write is bigger than buffer, or there is no overlap on the
498                          * low or high ends.
499                          */
500
501                         DEBUG(9,("write_file: non cacheable write : fd = %d, pos = %.0f, len = %u, current cache pos = %.0f \
502 len = %u\n",fsp->fd, (double)pos, (unsigned int)n, (double)wcp->offset, (unsigned int)wcp->data_size ));
503
504                         /*
505                          * Update the file size if needed.
506                          */
507
508                         if(pos + n > wcp->file_size) {
509                                 wcp->file_size = pos + n;
510                                 fsp->size = (SMB_BIG_UINT)wcp->file_size;
511                         }
512
513                         /*
514                          * If write would fit in the cache, and is larger than
515                          * the data already in the cache, flush the cache and
516                          * preferentially copy the data new data into it. Otherwise
517                          * just write the data directly.
518                          */
519
520                         if ( n <= wcp->alloc_size && n > wcp->data_size) {
521                                 cache_flush_needed = True;
522                         } else {
523                                 ssize_t ret = real_write_file(fsp, data, pos, n);
524
525                                 /*
526                                  * If the write overlaps the entire cache, then
527                                  * discard the current contents of the cache.
528                                  * Fix from Rasmus Borup Hansen rbh@math.ku.dk.
529                                  */
530
531                                 if ((pos <= wcp->offset) &&
532                                                 (pos + n >= wcp->offset + wcp->data_size) ) {
533                                         DEBUG(9,("write_file: discarding overwritten write \
534 cache: fd = %d, off=%.0f, size=%u\n", fsp->fd, (double)wcp->offset, (unsigned int)wcp->data_size ));
535                                         wcp->data_size = 0;
536                                 }
537
538                                 DO_PROFILE_INC(writecache_direct_writes);
539                                 if (ret == -1)
540                                         return ret;
541
542                                 if (pos + ret > wcp->file_size) {
543                                         wcp->file_size = pos + ret;
544                                         fsp->size = (SMB_BIG_UINT)wcp->file_size;
545                                 }
546
547                                 return ret;
548                         }
549
550                         write_path = 4;
551
552                 }
553
554                 if(wcp->data_size > wcp->file_size) {
555                         wcp->file_size = wcp->data_size;
556                         fsp->size = (SMB_BIG_UINT)wcp->file_size;
557                 }
558
559                 if (cache_flush_needed) {
560                         DEBUG(3,("WRITE_FLUSH:%d: due to noncontinuous write: fd = %d, size = %.0f, pos = %.0f, \
561 n = %u, wcp->offset=%.0f, wcp->data_size=%u\n",
562                                 write_path, fsp->fd, (double)wcp->file_size, (double)pos, (unsigned int)n,
563                                 (double)wcp->offset, (unsigned int)wcp->data_size ));
564
565                         flush_write_cache(fsp, WRITE_FLUSH);
566                 }
567         }
568
569         /*
570          * If the write request is bigger than the cache
571          * size, write it all out.
572          */
573
574         if (n > wcp->alloc_size ) {
575                 ssize_t ret = real_write_file(fsp, data, pos, n);
576                 if (ret == -1)
577                         return -1;
578
579                 if (pos + ret > wcp->file_size) {
580                         wcp->file_size = pos + n;
581                         fsp->size = (SMB_BIG_UINT)wcp->file_size;
582                 }
583
584                 DO_PROFILE_INC(writecache_direct_writes);
585                 return total_written + n;
586         }
587
588         /*
589          * If there's any data left, cache it.
590          */
591
592         if (n) {
593 #ifdef WITH_PROFILE
594                 if (wcp->data_size) {
595                         DO_PROFILE_INC(writecache_abutted_writes);
596                 } else {
597                         DO_PROFILE_INC(writecache_init_writes);
598                 }
599 #endif
600                 memcpy(wcp->data+wcp->data_size, data, n);
601                 if (wcp->data_size == 0) {
602                         wcp->offset = pos;
603                         DO_PROFILE_INC(writecache_num_write_caches);
604                 }
605                 wcp->data_size += n;
606
607                 /*
608                  * Update the file size if changed.
609                  */
610
611                 if (wcp->offset + wcp->data_size > wcp->file_size) {
612                         wcp->file_size = wcp->offset + wcp->data_size;
613                         fsp->size = (SMB_BIG_UINT)wcp->file_size;
614                 }
615                 DEBUG(9,("wcp->offset = %.0f wcp->data_size = %u cache return %u\n",
616                         (double)wcp->offset, (unsigned int)wcp->data_size, (unsigned int)n));
617
618                 total_written += n;
619                 return total_written; /* .... that's a write :) */
620         }
621   
622         return total_written;
623 }
624
625 /****************************************************************************
626  Delete the write cache structure.
627 ****************************************************************************/
628
629 void delete_write_cache(files_struct *fsp)
630 {
631         write_cache *wcp;
632
633         if(!fsp)
634                 return;
635
636         if(!(wcp = fsp->wcp))
637                 return;
638
639         DO_PROFILE_DEC(writecache_allocated_write_caches);
640         allocated_write_caches--;
641
642         SMB_ASSERT(wcp->data_size == 0);
643
644         SAFE_FREE(wcp->data);
645         SAFE_FREE(fsp->wcp);
646
647         DEBUG(10,("delete_write_cache: File %s deleted write cache\n", fsp->fsp_name ));
648 }
649
650 /****************************************************************************
651  Setup the write cache structure.
652 ****************************************************************************/
653
654 static BOOL setup_write_cache(files_struct *fsp, SMB_OFF_T file_size)
655 {
656         ssize_t alloc_size = lp_write_cache_size(SNUM(fsp->conn));
657         write_cache *wcp;
658
659         if (allocated_write_caches >= MAX_WRITE_CACHES) 
660                 return False;
661
662         if(alloc_size == 0 || fsp->wcp)
663                 return False;
664
665         if((wcp = (write_cache *)malloc(sizeof(write_cache))) == NULL) {
666                 DEBUG(0,("setup_write_cache: malloc fail.\n"));
667                 return False;
668         }
669
670         wcp->file_size = file_size;
671         wcp->offset = 0;
672         wcp->alloc_size = alloc_size;
673         wcp->data_size = 0;
674         if((wcp->data = malloc(wcp->alloc_size)) == NULL) {
675                 DEBUG(0,("setup_write_cache: malloc fail for buffer size %u.\n",
676                         (unsigned int)wcp->alloc_size ));
677                 SAFE_FREE(wcp);
678                 return False;
679         }
680
681         memset(wcp->data, '\0', wcp->alloc_size );
682
683         fsp->wcp = wcp;
684         DO_PROFILE_INC(writecache_allocated_write_caches);
685         allocated_write_caches++;
686
687         DEBUG(10,("setup_write_cache: File %s allocated write cache size %lu\n",
688                 fsp->fsp_name, (unsigned long)wcp->alloc_size ));
689
690         return True;
691 }
692
693 /****************************************************************************
694  Cope with a size change.
695 ****************************************************************************/
696
697 void set_filelen_write_cache(files_struct *fsp, SMB_OFF_T file_size)
698 {
699         fsp->size = (SMB_BIG_UINT)file_size;
700         if(fsp->wcp) {
701                 /* The cache *must* have been flushed before we do this. */
702                 if (fsp->wcp->data_size != 0) {
703                         pstring msg;
704                         slprintf(msg, sizeof(msg)-1, "set_filelen_write_cache: size change \
705 on file %s with write cache size = %lu\n", fsp->fsp_name, (unsigned long)fsp->wcp->data_size );
706                         smb_panic(msg);
707                 }
708                 fsp->wcp->file_size = file_size;
709         }
710 }
711
712 /*******************************************************************
713  Flush a write cache struct to disk.
714 ********************************************************************/
715
716 ssize_t flush_write_cache(files_struct *fsp, enum flush_reason_enum reason)
717 {
718         write_cache *wcp = fsp->wcp;
719         size_t data_size;
720         ssize_t ret;
721
722         if(!wcp || !wcp->data_size)
723                 return 0;
724
725         data_size = wcp->data_size;
726         wcp->data_size = 0;
727
728         DO_PROFILE_DEC_INC(writecache_num_write_caches,writecache_flushed_writes[reason]);
729
730         DEBUG(9,("flushing write cache: fd = %d, off=%.0f, size=%u\n",
731                 fsp->fd, (double)wcp->offset, (unsigned int)data_size));
732
733 #ifdef WITH_PROFILE
734         if(data_size == wcp->alloc_size)
735                 DO_PROFILE_INC(writecache_num_perfect_writes);
736 #endif
737
738         ret = real_write_file(fsp, wcp->data, wcp->offset, data_size);
739
740         /*
741          * Ensure file size if kept up to date if write extends file.
742          */
743
744         if ((ret != -1) && (wcp->offset + ret > wcp->file_size))
745                 wcp->file_size = wcp->offset + ret;
746
747         return ret;
748 }
749
750 /*******************************************************************
751 sync a file
752 ********************************************************************/
753
754 void sync_file(connection_struct *conn, files_struct *fsp)
755 {
756         if(lp_strict_sync(SNUM(conn)) && fsp->fd != -1) {
757                 flush_write_cache(fsp, SYNC_FLUSH);
758                 SMB_VFS_FSYNC(fsp,fsp->fd);
759         }
760 }
761
762
763 /************************************************************
764  Perform a stat whether a valid fd or not.
765 ************************************************************/
766
767 int fsp_stat(files_struct *fsp, SMB_STRUCT_STAT *pst)
768 {
769         if (fsp->fd == -1)
770                 return SMB_VFS_STAT(fsp->conn, fsp->fsp_name, pst);
771         else
772                 return SMB_VFS_FSTAT(fsp,fsp->fd, pst);
773 }