XRootD
XrdClFile.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // This file is part of the XRootD software suite.
6 //
7 // XRootD is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // XRootD is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19 //
20 // In applying this licence, CERN does not waive the privileges and immunities
21 // granted to it by virtue of its status as an Intergovernmental Organization
22 // or submit itself to any jurisdiction.
23 //------------------------------------------------------------------------------
24 
25 #ifndef __XRD_CL_FILE_HH__
26 #define __XRD_CL_FILE_HH__
27 
28 #include "XrdCl/XrdClFileSystem.hh"
30 #include "XrdCl/XrdClOptional.hh"
31 #include "XrdOuc/XrdOucCompiler.hh"
32 #include <cstdint>
33 #include <string>
34 #include <vector>
35 #include <sys/uio.h>
36 
37 namespace XrdCl
38 {
39  struct FileImpl;
40  class FilePlugIn;
41  struct CloneLocations;
42 
44  public:
45  virtual ~ExportedFileTemplate() {}
46  };
47 
48  //----------------------------------------------------------------------------
50  //----------------------------------------------------------------------------
51  class File
52  {
53  public:
54  friend struct CloneLocations; // for GetFileTemplate
55 
57  {
60  };
61 
62  //------------------------------------------------------------------------
65  //------------------------------------------------------------------------
66  File( bool enablePlugIns = true );
67 
68  //------------------------------------------------------------------------
72  //------------------------------------------------------------------------
73  File( VirtRedirect virtRedirect, bool enablePlugIns = true );
74 
75  //------------------------------------------------------------------------
80  //------------------------------------------------------------------------
81  File( const std::string &url, bool enablePlugIns = true );
82 
83  //------------------------------------------------------------------------
85  //------------------------------------------------------------------------
86  virtual ~File();
87 
88  //------------------------------------------------------------------------
98  //------------------------------------------------------------------------
99  XRootDStatus Open( const std::string &url,
100  OpenFlags::Flags flags,
101  Access::Mode mode,
102  ResponseHandler *handler,
103  time_t timeout = 0 )
105 
106  //------------------------------------------------------------------------
119  //------------------------------------------------------------------------
120  XRootDStatus OpenUsingTemplate( const File &rfile,
121  const std::string &url,
122  OpenFlags::Flags flags,
123  Access::Mode mode,
124  ResponseHandler *handler,
125  time_t timeout = 0 )
127 
128  //------------------------------------------------------------------------
137  //------------------------------------------------------------------------
138  XRootDStatus Open( const std::string &url,
139  OpenFlags::Flags flags,
140  Access::Mode mode = Access::None,
141  time_t timeout = 0 )
143 
144  //------------------------------------------------------------------------
156  //------------------------------------------------------------------------
157  XRootDStatus OpenUsingTemplate( const File &rfile,
158  const std::string &url,
159  OpenFlags::Flags flags,
160  Access::Mode mode = Access::None,
161  time_t timeout = 0 )
163 
164  //------------------------------------------------------------------------
172  //------------------------------------------------------------------------
173  XRootDStatus Clone( const CloneLocations &locs,
174  ResponseHandler *handler,
175  time_t timeout = 0 )
177 
178  //------------------------------------------------------------------------
185  //------------------------------------------------------------------------
186  XRootDStatus Clone( const CloneLocations &locs,
187  time_t timeout = 0 )
189 
190  //------------------------------------------------------------------------
197  //------------------------------------------------------------------------
199  time_t timeout = 0 )
201 
202  //------------------------------------------------------------------------
208  //------------------------------------------------------------------------
209  XRootDStatus Close( time_t timeout = 0 ) XRD_WARN_UNUSED_RESULT;
210 
211  //------------------------------------------------------------------------
221  //------------------------------------------------------------------------
222  XRootDStatus Stat( bool force,
223  ResponseHandler *handler,
224  time_t timeout = 0 )
226 
227  //------------------------------------------------------------------------
235  //------------------------------------------------------------------------
236  XRootDStatus Stat( bool force,
237  StatInfo *&response,
238  time_t timeout = 0 )
240 
241 
242  //------------------------------------------------------------------------
255  //------------------------------------------------------------------------
256  XRootDStatus Read( uint64_t offset,
257  uint32_t size,
258  void *buffer,
259  ResponseHandler *handler,
260  time_t timeout = 0 )
262 
263  //------------------------------------------------------------------------
273  //------------------------------------------------------------------------
274  XRootDStatus Read( uint64_t offset,
275  uint32_t size,
276  void *buffer,
277  uint32_t &bytesRead,
278  time_t timeout = 0 )
280 
281  //------------------------------------------------------------------------
293  //------------------------------------------------------------------------
294  XRootDStatus PgRead( uint64_t offset,
295  uint32_t size,
296  void *buffer,
297  ResponseHandler *handler,
298  time_t timeout = 0 )
300 
301  //------------------------------------------------------------------------
312  //------------------------------------------------------------------------
313  XRootDStatus PgRead( uint64_t offset,
314  uint32_t size,
315  void *buffer,
316  std::vector<uint32_t> &cksums,
317  uint32_t &bytesRead,
318  time_t timeout = 0 )
320 
321  //------------------------------------------------------------------------
334  //------------------------------------------------------------------------
335  XRootDStatus Write( uint64_t offset,
336  uint32_t size,
337  const void *buffer,
338  ResponseHandler *handler,
339  time_t timeout = 0 )
341 
342  //------------------------------------------------------------------------
355  //------------------------------------------------------------------------
356  XRootDStatus Write( uint64_t offset,
357  uint32_t size,
358  const void *buffer,
359  time_t timeout = 0 )
361 
362  //------------------------------------------------------------------------
372  //------------------------------------------------------------------------
373  XRootDStatus Write( uint64_t offset,
374  Buffer &&buffer,
375  ResponseHandler *handler,
376  time_t timeout = 0 );
377 
378  //------------------------------------------------------------------------
387  //------------------------------------------------------------------------
388  XRootDStatus Write( uint64_t offset,
389  Buffer &&buffer,
390  time_t timeout = 0 );
391 
392  //------------------------------------------------------------------------
405  //------------------------------------------------------------------------
406  XRootDStatus Write( uint64_t offset,
407  uint32_t size,
408  Optional<uint64_t> fdoff,
409  int fd,
410  ResponseHandler *handler,
411  time_t timeout = 0 );
412 
413  //------------------------------------------------------------------------
425  //------------------------------------------------------------------------
426  XRootDStatus Write( uint64_t offset,
427  uint32_t size,
428  Optional<uint64_t> fdoff,
429  int fd,
430  time_t timeout = 0 );
431 
432  //------------------------------------------------------------------------
443  //------------------------------------------------------------------------
444  XRootDStatus PgWrite( uint64_t offset,
445  uint32_t size,
446  const void *buffer,
447  std::vector<uint32_t> &cksums,
448  ResponseHandler *handler,
449  time_t timeout = 0 )
451 
452  //------------------------------------------------------------------------
462  //------------------------------------------------------------------------
463  XRootDStatus PgWrite( uint64_t offset,
464  uint32_t size,
465  const void *buffer,
466  std::vector<uint32_t> &cksums,
467  time_t timeout = 0 )
469 
470  //------------------------------------------------------------------------
477  //------------------------------------------------------------------------
479  time_t timeout = 0 )
481 
482 
483  //------------------------------------------------------------------------
489  //------------------------------------------------------------------------
490  XRootDStatus Sync( time_t timeout = 0 ) XRD_WARN_UNUSED_RESULT;
491 
492  //------------------------------------------------------------------------
500  //------------------------------------------------------------------------
501  XRootDStatus Truncate( uint64_t size,
502  ResponseHandler *handler,
503  time_t timeout = 0 )
505 
506 
507  //------------------------------------------------------------------------
514  //------------------------------------------------------------------------
515  XRootDStatus Truncate( uint64_t size,
516  time_t timeout = 0 )
518 
519  //------------------------------------------------------------------------
533  //------------------------------------------------------------------------
534  XRootDStatus PreRead( const TractList &tracts,
535  ResponseHandler *handler,
536  time_t timeout = 0 )
538 
539  //------------------------------------------------------------------------
552  //------------------------------------------------------------------------
553  XRootDStatus PreRead( const TractList &tracts,
554  time_t timeout = 0 )
556 
557  //------------------------------------------------------------------------
573  //------------------------------------------------------------------------
574  XRootDStatus VectorRead( const ChunkList &chunks,
575  void *buffer,
576  ResponseHandler *handler,
577  time_t timeout = 0 )
579 
580  //------------------------------------------------------------------------
596  //------------------------------------------------------------------------
597  XRootDStatus VectorRead( const ChunkList &chunks,
598  void *buffer,
599  VectorReadInfo *&vReadInfo,
600  time_t timeout = 0 )
602 
603  //------------------------------------------------------------------------
611  //------------------------------------------------------------------------
612  XRootDStatus VectorWrite( const ChunkList &chunks,
613  ResponseHandler *handler,
614  time_t timeout = 0 )
616 
617  //------------------------------------------------------------------------
624  //------------------------------------------------------------------------
625  XRootDStatus VectorWrite( const ChunkList &chunks,
626  time_t timeout = 0 )
628 
629  //------------------------------------------------------------------------
639  //------------------------------------------------------------------------
640  XRootDStatus WriteV( uint64_t offset,
641  const struct iovec *iov,
642  int iovcnt,
643  ResponseHandler *handler,
644  time_t timeout = 0 );
645 
646  //------------------------------------------------------------------------
655  //------------------------------------------------------------------------
656  XRootDStatus WriteV( uint64_t offset,
657  const struct iovec *iov,
658  int iovcnt,
659  time_t timeout = 0 );
660 
661  //------------------------------------------------------------------------
671  //------------------------------------------------------------------------
672  XRootDStatus ReadV( uint64_t offset,
673  struct iovec *iov,
674  int iovcnt,
675  ResponseHandler *handler,
676  time_t timeout = 0 );
677 
678  //------------------------------------------------------------------------
688  //------------------------------------------------------------------------
689  XRootDStatus ReadV( uint64_t offset,
690  struct iovec *iov,
691  int iovcnt,
692  uint32_t &bytesRead,
693  time_t timeout = 0 );
694 
695  //------------------------------------------------------------------------
706  //------------------------------------------------------------------------
707  XRootDStatus Fcntl( const Buffer &arg,
708  ResponseHandler *handler,
709  time_t timeout = 0 )
711 
712  //------------------------------------------------------------------------
721  //------------------------------------------------------------------------
722  XRootDStatus Fcntl( const Buffer &arg,
723  Buffer *&response,
724  time_t timeout = 0 )
726 
727 
728  //------------------------------------------------------------------------
740  //------------------------------------------------------------------------
741  XRootDStatus Fcntl( QueryCode::Code queryCode,
742  const Buffer &arg,
743  ResponseHandler *handler,
744  time_t timeout = 0 )
746 
747  //------------------------------------------------------------------------
757  //------------------------------------------------------------------------
758  XRootDStatus Fcntl( QueryCode::Code queryCode,
759  const Buffer &arg,
760  Buffer *&response,
761  time_t timeout = 0 )
763  //------------------------------------------------------------------------
772  //------------------------------------------------------------------------
774  time_t timeout = 0 )
776 
777  //------------------------------------------------------------------------
784  //------------------------------------------------------------------------
785  XRootDStatus Visa( Buffer *&visa,
786  time_t timeout = 0 )
788 
789  //------------------------------------------------------------------------
800  //------------------------------------------------------------------------
801  XRootDStatus SetXAttr( const std::vector<xattr_t> &attrs,
802  ResponseHandler *handler,
803  time_t timeout = 0 );
804 
805  //------------------------------------------------------------------------
814  //------------------------------------------------------------------------
815  XRootDStatus SetXAttr( const std::vector<xattr_t> &attrs,
816  std::vector<XAttrStatus> &result,
817  time_t timeout = 0 );
818 
819  //------------------------------------------------------------------------
830  //------------------------------------------------------------------------
831  XRootDStatus GetXAttr( const std::vector<std::string> &attrs,
832  ResponseHandler *handler,
833  time_t timeout = 0 );
834 
835  //------------------------------------------------------------------------
844  //------------------------------------------------------------------------
845  XRootDStatus GetXAttr( const std::vector<std::string> &attrs,
846  std::vector<XAttr> &result,
847  time_t timeout = 0 );
848 
849  //------------------------------------------------------------------------
860  //------------------------------------------------------------------------
861  XRootDStatus DelXAttr( const std::vector<std::string> &attrs,
862  ResponseHandler *handler,
863  time_t timeout = 0 );
864 
865  //------------------------------------------------------------------------
874  //------------------------------------------------------------------------
875  XRootDStatus DelXAttr( const std::vector<std::string> &attrs,
876  std::vector<XAttrStatus> &result,
877  time_t timeout = 0 );
878 
879  //------------------------------------------------------------------------
889  //------------------------------------------------------------------------
891  time_t timeout = 0 );
892 
893  //------------------------------------------------------------------------
901  //------------------------------------------------------------------------
902  XRootDStatus ListXAttr( std::vector<XAttr> &result,
903  time_t timeout = 0 );
904 
905  //------------------------------------------------------------------------
912  //------------------------------------------------------------------------
913  XRootDStatus TryOtherServer( time_t timeout = 0 );
914 
915  //------------------------------------------------------------------------
917  //------------------------------------------------------------------------
918  bool IsOpen() const;
919 
920  //------------------------------------------------------------------------
922  //------------------------------------------------------------------------
923  bool IsSecure() const;
924 
925  //------------------------------------------------------------------------
933  //------------------------------------------------------------------------
934  bool SetProperty( const std::string &name, const std::string &value );
935 
936  //------------------------------------------------------------------------
944  //------------------------------------------------------------------------
945  bool GetProperty( const std::string &name, std::string &value ) const;
946 
947  private:
948 
949  template<bool HasHndl>
950  friend class CheckpointImpl;
951 
952  template<bool HasHndl>
953  friend class ChkptWrtImpl;
954 
955  template <bool HasHndl>
956  friend class ChkptWrtVImpl;
957 
958  //------------------------------------------------------------------------
963  //------------------------------------------------------------------------
964  void InitPlugin( const std::string &url);
965 
966  //------------------------------------------------------------------------
976  //------------------------------------------------------------------------
978  ResponseHandler *handler,
979  time_t timeout = 0 );
980 
981  //------------------------------------------------------------------------
991  //------------------------------------------------------------------------
992  XRootDStatus ChkptWrt( uint64_t offset,
993  uint32_t size,
994  const void *buffer,
995  ResponseHandler *handler,
996  time_t timeout = 0 );
997 
998  //------------------------------------------------------------------------
1008  //------------------------------------------------------------------------
1009  XRootDStatus ChkptWrtV( uint64_t offset,
1010  const struct iovec *iov,
1011  int iovcnt,
1012  ResponseHandler *handler,
1013  time_t timeout = 0 );
1014 
1015  std::unique_ptr<ExportedFileTemplate> GetFileTemplate() const;
1016 
1017  FileImpl *pImpl;
1018  FilePlugIn *pPlugIn;
1019  bool pEnablePlugIns;
1020  };
1021 
1023  {
1024  std::unique_ptr<ExportedFileTemplate> file;
1025  off_t srcOffs;
1026  off_t srcLen;
1027  off_t dstOffs;
1028  };
1029 
1031  {
1032  //--------------------------------------------------------------------------
1042  //--------------------------------------------------------------------------
1043  void Add(const File &file, off_t dstOffs, off_t srcOffs, off_t srcLen)
1044  {
1045  CloneLocation loc;
1046  loc.srcOffs = srcOffs;
1047  loc.dstOffs = dstOffs;
1048  loc.srcLen = srcLen;
1049  loc.file = file.GetFileTemplate();
1050  locations.emplace_back(std::move(loc));
1051  }
1052 
1053  std::vector<CloneLocation> locations;
1054  };
1055 
1056 }
1057 
1058 #endif // __XRD_CL_FILE_HH__
unsigned char kXR_char
Definition: XPtypes.hh:65
#define XRD_WARN_UNUSED_RESULT
int Mode
Binary blob representation.
Definition: XrdClBuffer.hh:34
Checkpoint operation (.
Checkpointed write operation (.
Checkpointed WriteV operation (.
Fcntl operation (.
An interface for file plug-ins.
A file.
Definition: XrdClFile.hh:52
bool IsSecure() const
Check if the file is using an encrypted connection.
Definition: XrdClFile.cc:973
XRootDStatus Open(const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:125
XRootDStatus ReadV(uint64_t offset, struct iovec *iov, int iovcnt, ResponseHandler *handler, time_t timeout=0)
Definition: XrdClFile.cc:649
XRootDStatus VectorRead(const ChunkList &chunks, void *buffer, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:552
@ EnableVirtRedirect
Definition: XrdClFile.hh:58
@ DisableVirtRedirect
Definition: XrdClFile.hh:59
XRootDStatus PgRead(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:304
XRootDStatus Sync(ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:473
XRootDStatus WriteV(uint64_t offset, const struct iovec *iov, int iovcnt, ResponseHandler *handler, time_t timeout=0)
Definition: XrdClFile.cc:609
bool IsOpen() const
Check if the file is open.
Definition: XrdClFile.cc:962
XRootDStatus Clone(const CloneLocations &locs, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:1016
XRootDStatus OpenUsingTemplate(const File &rfile, const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:151
XRootDStatus TryOtherServer(time_t timeout=0)
Definition: XrdClFile.cc:954
XRootDStatus Truncate(uint64_t size, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:499
XRootDStatus SetXAttr(const std::vector< xattr_t > &attrs, ResponseHandler *handler, time_t timeout=0)
Definition: XrdClFile.cc:781
bool GetProperty(const std::string &name, std::string &value) const
Definition: XrdClFile.cc:994
XRootDStatus ListXAttr(ResponseHandler *handler, time_t timeout=0)
Definition: XrdClFile.cc:880
XRootDStatus PreRead(const TractList &tracts, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:527
File(bool enablePlugIns=true)
Definition: XrdClFile.cc:59
XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:265
XRootDStatus GetXAttr(const std::vector< std::string > &attrs, ResponseHandler *handler, time_t timeout=0)
Definition: XrdClFile.cc:814
virtual ~File()
Destructor.
Definition: XrdClFile.cc:88
XRootDStatus Close(ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:210
bool SetProperty(const std::string &name, const std::string &value)
Definition: XrdClFile.cc:983
XRootDStatus Stat(bool force, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:236
XRootDStatus PgWrite(uint64_t offset, uint32_t size, const void *buffer, std::vector< uint32_t > &cksums, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:439
XRootDStatus VectorWrite(const ChunkList &chunks, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:582
XRootDStatus DelXAttr(const std::vector< std::string > &attrs, ResponseHandler *handler, time_t timeout=0)
Definition: XrdClFile.cc:847
XRootDStatus Write(uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:345
Handle an async response.
Object stat info.
Visa operation (.
ChkptWrtImpl< false > ChkptWrt(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< const void * > buffer, time_t timeout=0)
Factory for creating ReadImpl objects.
std::unique_ptr< ExportedFileTemplate > file
Definition: XrdClFile.hh:1024
ChkptWrtVImpl< false > ChkptWrtV(Ctx< File > file, Arg< uint64_t > offset, Arg< std::vector< iovec >> iov, time_t timeout=0)
Factory for creating ChkptWrtVImpl objects.
std::vector< TractInfo > TractList
List of Tracts.
std::tuple< std::string, std::string > xattr_t
Extended attribute key - value pair.
std::vector< ChunkInfo > ChunkList
List of chunks.
CheckpointImpl< false > Checkpoint(Ctx< File > file, Arg< ChkPtCode > code, time_t timeout=0)
Factory for creating ReadImpl objects.
none object for initializing empty Optional
Access mode.
Mode
Access mode.
void Add(const File &file, off_t dstOffs, off_t srcOffs, off_t srcLen)
Definition: XrdClFile.hh:1043
std::vector< CloneLocation > locations
Definition: XrdClFile.hh:1053
Open flags, may be or'd when appropriate.
Flags
Open flags, may be or'd when appropriate.
XRootD query request codes.
Extended attribute operation status.
Extended attributes with status.