34 #ifndef CPL_VSI_VIRTUAL_H_INCLUDED 35 #define CPL_VSI_VIRTUAL_H_INCLUDED 38 #include "cpl_vsi_error.h" 40 #include "cpl_multiproc.h" 47 #ifdef GetDiskFreeSpace 48 #undef GetDiskFreeSpace 58 virtual int Seek(
vsi_l_offset nOffset,
int nWhence ) = 0;
60 virtual size_t Read(
void *pBuffer,
size_t nSize,
size_t nCount ) = 0;
61 virtual int ReadMultiRange(
int nRanges,
void ** ppData,
63 const size_t* panSizes );
64 virtual size_t Write(
const void *pBuffer,
size_t nSize,
size_t nCount)=0;
65 virtual int Eof() = 0;
67 virtual int Close() = 0;
83 class CPL_DLL VSIFilesystemHandler {
87 virtual ~VSIFilesystemHandler() {}
90 const char *pszAccess );
93 const char *pszAccess,
95 virtual int Stat(
const char *pszFilename,
VSIStatBufL *pStatBuf,
int nFlags) = 0;
96 virtual int Unlink(
const char *pszFilename )
97 { (void) pszFilename; errno=ENOENT;
return -1; }
98 virtual int Mkdir(
const char *pszDirname,
long nMode )
99 {(void)pszDirname; (void)nMode; errno=ENOENT;
return -1;}
100 virtual int Rmdir(
const char *pszDirname )
101 { (void) pszDirname; errno=ENOENT;
return -1; }
102 virtual char **ReadDir(
const char *pszDirname )
103 { (void) pszDirname;
return nullptr; }
104 virtual char **ReadDirEx(
const char *pszDirname,
int )
105 {
return ReadDir(pszDirname); }
106 virtual int Rename(
const char *oldpath,
const char *newpath )
107 { (void) oldpath; (void)newpath; errno=ENOENT;
return -1; }
108 virtual int IsCaseSensitive(
const char* pszFilename )
109 { (void) pszFilename;
return TRUE; }
110 virtual GIntBig GetDiskFreeSpace(
const char* ) {
return -1; }
111 virtual int SupportsSparseFiles(
const char* ) {
return FALSE; }
112 virtual int HasOptimizedReadMultiRange(
const char* ) {
return FALSE; }
113 virtual const char* GetActualURL(
const char* ) {
return nullptr; }
114 virtual const char* GetOptions() {
return nullptr; }
115 virtual char* GetSignedURL(
const char* ,
CSLConstList ) {
return nullptr; }
116 virtual bool Sync(
const char* pszSource,
const char* pszTarget,
117 const char*
const * papszOptions,
118 GDALProgressFunc pProgressFunc,
120 char*** ppapszOutputs );
122 virtual VSIDIR* OpenDir(
const char *pszPath,
int nRecurseDepth,
123 const char*
const *papszOptions);
132 class CPL_DLL VSIFileManager
135 VSIFilesystemHandler *poDefaultHandler =
nullptr;
136 std::map<std::string, VSIFilesystemHandler *> oHandlers{};
140 static VSIFileManager *Get();
147 static VSIFilesystemHandler *GetHandler(
const char * );
148 static void InstallHandler(
const std::string& osPrefix,
149 VSIFilesystemHandler * );
153 static char** GetPrefixes();
165 class VSIArchiveEntryFileOffset
168 virtual ~VSIArchiveEntryFileOffset();
175 VSIArchiveEntryFileOffset* file_pos;
180 class VSIArchiveContent
186 VSIArchiveEntry* entries =
nullptr;
188 ~VSIArchiveContent();
191 class VSIArchiveReader
194 virtual ~VSIArchiveReader();
196 virtual int GotoFirstFile() = 0;
197 virtual int GotoNextFile() = 0;
198 virtual VSIArchiveEntryFileOffset* GetFileOffset() = 0;
201 virtual GIntBig GetModifiedTime() = 0;
202 virtual int GotoFileOffset(VSIArchiveEntryFileOffset* pOffset) = 0;
205 class VSIArchiveFilesystemHandler :
public VSIFilesystemHandler
210 CPLMutex* hMutex =
nullptr;
214 std::map<CPLString,VSIArchiveContent*> oFileList{};
216 virtual const char* GetPrefix() = 0;
217 virtual std::vector<CPLString> GetExtensions() = 0;
218 virtual VSIArchiveReader* CreateReader(
const char* pszArchiveFileName) = 0;
221 VSIArchiveFilesystemHandler();
222 virtual ~VSIArchiveFilesystemHandler();
224 int Stat(
const char *pszFilename,
VSIStatBufL *pStatBuf,
225 int nFlags )
override;
226 int Unlink(
const char *pszFilename )
override;
227 int Rename(
const char *oldpath,
const char *newpath )
override;
228 int Mkdir(
const char *pszDirname,
long nMode )
override;
229 int Rmdir(
const char *pszDirname )
override;
230 char **ReadDirEx(
const char *pszDirname,
int nMaxFiles )
override;
232 virtual const VSIArchiveContent* GetContentOfArchive(
const char* archiveFilename, VSIArchiveReader* poReader =
nullptr);
233 virtual char* SplitFilename(
const char *pszFilename,
CPLString &osFileInArchive,
int bCheckMainFileExists);
234 virtual VSIArchiveReader* OpenArchiveFile(
const char* archiveFilename,
const char* fileInArchiveName);
235 virtual int FindFileInArchive(
const char* archiveFilename,
const char* fileInArchiveName,
const VSIArchiveEntry** archiveEntry);
242 struct CPL_DLL VSIDIR
250 VSIDIR(
const VSIDIR&) =
delete;
251 VSIDIR& operator=(
const VSIDIR&) =
delete;
258 const GByte* pabyBeginningContent,
262 const int CPL_DEFLATE_TYPE_GZIP = 0;
263 const int CPL_DEFLATE_TYPE_ZLIB = 1;
264 const int CPL_DEFLATE_TYPE_RAW_DEFLATE = 2;
Directory entry.
Definition: cpl_vsi.h:314
VSIRangeStatus
Range status.
Definition: cpl_vsi.h:175
virtual VSIRangeStatus GetRangeStatus(vsi_l_offset nOffset, vsi_l_offset nLength)
Return if a given file range contains data or holes filled with zeroes.
Definition: cpl_vsi_virtual.h:71
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:215
Virtual file handle.
Definition: cpl_vsi_virtual.h:56
virtual void * GetNativeFileDescriptor()
Returns the "native" file descriptor for the virtual handle.
Definition: cpl_vsi_virtual.h:70
Convenient string class based on std::string.
Definition: cpl_string.h:329
Various convenience functions for working with strings and string lists.
struct VSI_STAT64_T VSIStatBufL
Type for VSIStatL()
Definition: cpl_vsi.h:192
Unknown.
Definition: cpl_vsi.h:177
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1186
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition: cpl_port.h:251
#define CPL_UNUSED
Qualifier for an argument that is unused.
Definition: cpl_port.h:940
GUIntBig vsi_l_offset
Type for a file offset.
Definition: cpl_vsi.h:140
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:248
struct VSIDIR VSIDIR
Opaque type for a directory iterator.
Definition: cpl_vsi.h:307
virtual int Flush()
Flush pending writes to disk.
Definition: cpl_vsi_virtual.h:66
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition: cpl_port.h:989