gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

594 lines
26KB

  1. /******************************************************************************
  2. * $Id: cpl_vsi.h 1d0fc606e71f2c1ce61f3fd040b187de71d70f9b 2019-04-17 15:01:54 +0200 Even Rouault $
  3. *
  4. * Project: CPL - Common Portability Library
  5. * Author: Frank Warmerdam, warmerdam@pobox.com
  6. * Purpose: Include file defining Virtual File System (VSI) functions, a
  7. * layer over POSIX file and other system services.
  8. *
  9. ******************************************************************************
  10. * Copyright (c) 1998, Frank Warmerdam
  11. * Copyright (c) 2008-2014, Even Rouault <even dot rouault at mines-paris dot org>
  12. *
  13. * Permission is hereby granted, free of charge, to any person obtaining a
  14. * copy of this software and associated documentation files (the "Software"),
  15. * to deal in the Software without restriction, including without limitation
  16. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  17. * and/or sell copies of the Software, and to permit persons to whom the
  18. * Software is furnished to do so, subject to the following conditions:
  19. *
  20. * The above copyright notice and this permission notice shall be included
  21. * in all copies or substantial portions of the Software.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  24. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  26. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  28. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  29. * DEALINGS IN THE SOFTWARE.
  30. ****************************************************************************/
  31. #ifndef CPL_VSI_H_INCLUDED
  32. #define CPL_VSI_H_INCLUDED
  33. #include "cpl_port.h"
  34. #include "cpl_progress.h"
  35. /**
  36. * \file cpl_vsi.h
  37. *
  38. * Standard C Covers
  39. *
  40. * The VSI functions are intended to be hookable aliases for Standard C
  41. * I/O, memory allocation and other system functions. They are intended
  42. * to allow virtualization of disk I/O so that non file data sources
  43. * can be made to appear as files, and so that additional error trapping
  44. * and reporting can be interested. The memory access API is aliased
  45. * so that special application memory management services can be used.
  46. *
  47. * It is intended that each of these functions retains exactly the same
  48. * calling pattern as the original Standard C functions they relate to.
  49. * This means we don't have to provide custom documentation, and also means
  50. * that the default implementation is very simple.
  51. */
  52. /* -------------------------------------------------------------------- */
  53. /* We need access to ``struct stat''. */
  54. /* -------------------------------------------------------------------- */
  55. /* Unix */
  56. #if !defined(_WIN32)
  57. # include <unistd.h>
  58. #endif
  59. /* Windows */
  60. #include <sys/stat.h>
  61. CPL_C_START
  62. /*! @cond Doxygen_Suppress */
  63. #ifdef ENABLE_EXPERIMENTAL_CPL_WARN_UNUSED_RESULT
  64. #define EXPERIMENTAL_CPL_WARN_UNUSED_RESULT CPL_WARN_UNUSED_RESULT
  65. #else
  66. #define EXPERIMENTAL_CPL_WARN_UNUSED_RESULT
  67. #endif
  68. /*! @endcond */
  69. /* ==================================================================== */
  70. /* stdio file access functions. These do not support large */
  71. /* files, and do not go through the virtualization API. */
  72. /* ==================================================================== */
  73. /*! @cond Doxygen_Suppress */
  74. FILE CPL_DLL * VSIFOpen( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
  75. int CPL_DLL VSIFClose( FILE * );
  76. int CPL_DLL VSIFSeek( FILE *, long, int ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  77. long CPL_DLL VSIFTell( FILE * ) CPL_WARN_UNUSED_RESULT;
  78. void CPL_DLL VSIRewind( FILE * );
  79. void CPL_DLL VSIFFlush( FILE * );
  80. size_t CPL_DLL VSIFRead( void *, size_t, size_t, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  81. size_t CPL_DLL VSIFWrite( const void *, size_t, size_t, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  82. char CPL_DLL *VSIFGets( char *, int, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  83. int CPL_DLL VSIFPuts( const char *, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  84. int CPL_DLL VSIFPrintf( FILE *, CPL_FORMAT_STRING(const char *), ... ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT CPL_PRINT_FUNC_FORMAT(2, 3);
  85. int CPL_DLL VSIFGetc( FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  86. int CPL_DLL VSIFPutc( int, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  87. int CPL_DLL VSIUngetc( int, FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  88. int CPL_DLL VSIFEof( FILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  89. /*! @endcond */
  90. /* ==================================================================== */
  91. /* VSIStat() related. */
  92. /* ==================================================================== */
  93. /*! @cond Doxygen_Suppress */
  94. typedef struct stat VSIStatBuf;
  95. int CPL_DLL VSIStat( const char *, VSIStatBuf * ) CPL_WARN_UNUSED_RESULT;
  96. /*! @endcond */
  97. #ifdef _WIN32
  98. # define VSI_ISLNK(x) ( 0 ) /* N/A on Windows */
  99. # define VSI_ISREG(x) ((x) & S_IFREG)
  100. # define VSI_ISDIR(x) ((x) & S_IFDIR)
  101. # define VSI_ISCHR(x) ((x) & S_IFCHR)
  102. # define VSI_ISBLK(x) ( 0 ) /* N/A on Windows */
  103. #else
  104. /** Test if the file is a symbolic link */
  105. # define VSI_ISLNK(x) S_ISLNK(x)
  106. /** Test if the file is a regular file */
  107. # define VSI_ISREG(x) S_ISREG(x)
  108. /** Test if the file is a directory */
  109. # define VSI_ISDIR(x) S_ISDIR(x)
  110. /*! @cond Doxygen_Suppress */
  111. # define VSI_ISCHR(x) S_ISCHR(x)
  112. # define VSI_ISBLK(x) S_ISBLK(x)
  113. /*! @endcond */
  114. #endif
  115. /* ==================================================================== */
  116. /* 64bit stdio file access functions. If we have a big size */
  117. /* defined, then provide prototypes for the large file API, */
  118. /* otherwise redefine to use the regular api. */
  119. /* ==================================================================== */
  120. /** Type for a file offset */
  121. typedef GUIntBig vsi_l_offset;
  122. /** Maximum value for a file offset */
  123. #define VSI_L_OFFSET_MAX GUINTBIG_MAX
  124. /*! @cond Doxygen_Suppress */
  125. /* Make VSIL_STRICT_ENFORCE active in DEBUG builds */
  126. #ifdef DEBUG
  127. #define VSIL_STRICT_ENFORCE
  128. #endif
  129. /*! @endcond */
  130. #ifdef VSIL_STRICT_ENFORCE
  131. /** Opaque type for a FILE that implements the VSIVirtualHandle API */
  132. typedef struct _VSILFILE VSILFILE;
  133. #else
  134. /** Opaque type for a FILE that implements the VSIVirtualHandle API */
  135. typedef FILE VSILFILE;
  136. #endif
  137. VSILFILE CPL_DLL * VSIFOpenL( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
  138. VSILFILE CPL_DLL * VSIFOpenExL( const char *, const char *, int ) CPL_WARN_UNUSED_RESULT;
  139. int CPL_DLL VSIFCloseL( VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  140. int CPL_DLL VSIFSeekL( VSILFILE *, vsi_l_offset, int ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  141. vsi_l_offset CPL_DLL VSIFTellL( VSILFILE * ) CPL_WARN_UNUSED_RESULT;
  142. void CPL_DLL VSIRewindL( VSILFILE * );
  143. size_t CPL_DLL VSIFReadL( void *, size_t, size_t, VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  144. int CPL_DLL VSIFReadMultiRangeL( int nRanges, void ** ppData, const vsi_l_offset* panOffsets, const size_t* panSizes, VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  145. size_t CPL_DLL VSIFWriteL( const void *, size_t, size_t, VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  146. int CPL_DLL VSIFEofL( VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  147. int CPL_DLL VSIFTruncateL( VSILFILE *, vsi_l_offset ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  148. int CPL_DLL VSIFFlushL( VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  149. int CPL_DLL VSIFPrintfL( VSILFILE *, CPL_FORMAT_STRING(const char *), ... ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT CPL_PRINT_FUNC_FORMAT(2, 3);
  150. int CPL_DLL VSIFPutcL( int, VSILFILE * ) EXPERIMENTAL_CPL_WARN_UNUSED_RESULT;
  151. /** Range status */
  152. typedef enum
  153. {
  154. VSI_RANGE_STATUS_UNKNOWN, /**< Unknown */
  155. VSI_RANGE_STATUS_DATA, /**< Data present */
  156. VSI_RANGE_STATUS_HOLE /**< Hole */
  157. } VSIRangeStatus;
  158. VSIRangeStatus CPL_DLL VSIFGetRangeStatusL( VSILFILE * fp, vsi_l_offset nStart, vsi_l_offset nLength );
  159. int CPL_DLL VSIIngestFile( VSILFILE* fp,
  160. const char* pszFilename,
  161. GByte** ppabyRet,
  162. vsi_l_offset* pnSize,
  163. GIntBig nMaxSize ) CPL_WARN_UNUSED_RESULT;
  164. #if defined(VSI_STAT64_T)
  165. /** Type for VSIStatL() */
  166. typedef struct VSI_STAT64_T VSIStatBufL;
  167. #else
  168. /** Type for VSIStatL() */
  169. #define VSIStatBufL VSIStatBuf
  170. #endif
  171. int CPL_DLL VSIStatL( const char *, VSIStatBufL * ) CPL_WARN_UNUSED_RESULT;
  172. /** Flag provided to VSIStatExL() to test if the file exists */
  173. #define VSI_STAT_EXISTS_FLAG 0x1
  174. /** Flag provided to VSIStatExL() to query the nature (file/dir) of the file */
  175. #define VSI_STAT_NATURE_FLAG 0x2
  176. /** Flag provided to VSIStatExL() to query the file size */
  177. #define VSI_STAT_SIZE_FLAG 0x4
  178. /** Flag provided to VSIStatExL() to issue a VSIError in case of failure */
  179. #define VSI_STAT_SET_ERROR_FLAG 0x8
  180. int CPL_DLL VSIStatExL( const char * pszFilename, VSIStatBufL * psStatBuf, int nFlags ) CPL_WARN_UNUSED_RESULT;
  181. int CPL_DLL VSIIsCaseSensitiveFS( const char * pszFilename );
  182. int CPL_DLL VSISupportsSparseFiles( const char* pszPath );
  183. int CPL_DLL VSIHasOptimizedReadMultiRange( const char* pszPath );
  184. const char CPL_DLL *VSIGetActualURL( const char* pszFilename );
  185. char CPL_DLL *VSIGetSignedURL( const char* pszFilename, CSLConstList papszOptions );
  186. const char CPL_DLL *VSIGetFileSystemOptions( const char* pszFilename );
  187. char CPL_DLL **VSIGetFileSystemsPrefixes( void );
  188. void CPL_DLL *VSIFGetNativeFileDescriptorL( VSILFILE* );
  189. /* ==================================================================== */
  190. /* Memory allocation */
  191. /* ==================================================================== */
  192. void CPL_DLL *VSICalloc( size_t, size_t ) CPL_WARN_UNUSED_RESULT;
  193. void CPL_DLL *VSIMalloc( size_t ) CPL_WARN_UNUSED_RESULT;
  194. void CPL_DLL VSIFree( void * );
  195. void CPL_DLL *VSIRealloc( void *, size_t ) CPL_WARN_UNUSED_RESULT;
  196. char CPL_DLL *VSIStrdup( const char * ) CPL_WARN_UNUSED_RESULT;
  197. void CPL_DLL *VSIMallocAligned( size_t nAlignment, size_t nSize ) CPL_WARN_UNUSED_RESULT;
  198. void CPL_DLL *VSIMallocAlignedAuto( size_t nSize ) CPL_WARN_UNUSED_RESULT;
  199. void CPL_DLL VSIFreeAligned( void* ptr );
  200. void CPL_DLL *VSIMallocAlignedAutoVerbose( size_t nSize, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
  201. /** VSIMallocAlignedAutoVerbose() with FILE and LINE reporting */
  202. #define VSI_MALLOC_ALIGNED_AUTO_VERBOSE( size ) VSIMallocAlignedAutoVerbose(size,__FILE__,__LINE__)
  203. /**
  204. VSIMalloc2 allocates (nSize1 * nSize2) bytes.
  205. In case of overflow of the multiplication, or if memory allocation fails, a
  206. NULL pointer is returned and a CE_Failure error is raised with CPLError().
  207. If nSize1 == 0 || nSize2 == 0, a NULL pointer will also be returned.
  208. CPLFree() or VSIFree() can be used to free memory allocated by this function.
  209. */
  210. void CPL_DLL *VSIMalloc2( size_t nSize1, size_t nSize2 ) CPL_WARN_UNUSED_RESULT;
  211. /**
  212. VSIMalloc3 allocates (nSize1 * nSize2 * nSize3) bytes.
  213. In case of overflow of the multiplication, or if memory allocation fails, a
  214. NULL pointer is returned and a CE_Failure error is raised with CPLError().
  215. If nSize1 == 0 || nSize2 == 0 || nSize3 == 0, a NULL pointer will also be returned.
  216. CPLFree() or VSIFree() can be used to free memory allocated by this function.
  217. */
  218. void CPL_DLL *VSIMalloc3( size_t nSize1, size_t nSize2, size_t nSize3 ) CPL_WARN_UNUSED_RESULT;
  219. /** VSIMallocVerbose */
  220. void CPL_DLL *VSIMallocVerbose( size_t nSize, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
  221. /** VSI_MALLOC_VERBOSE */
  222. #define VSI_MALLOC_VERBOSE( size ) VSIMallocVerbose(size,__FILE__,__LINE__)
  223. /** VSIMalloc2Verbose */
  224. void CPL_DLL *VSIMalloc2Verbose( size_t nSize1, size_t nSize2, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
  225. /** VSI_MALLOC2_VERBOSE */
  226. #define VSI_MALLOC2_VERBOSE( nSize1, nSize2 ) VSIMalloc2Verbose(nSize1,nSize2,__FILE__,__LINE__)
  227. /** VSIMalloc3Verbose */
  228. void CPL_DLL *VSIMalloc3Verbose( size_t nSize1, size_t nSize2, size_t nSize3, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
  229. /** VSI_MALLOC3_VERBOSE */
  230. #define VSI_MALLOC3_VERBOSE( nSize1, nSize2, nSize3 ) VSIMalloc3Verbose(nSize1,nSize2,nSize3,__FILE__,__LINE__)
  231. /** VSICallocVerbose */
  232. void CPL_DLL *VSICallocVerbose( size_t nCount, size_t nSize, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
  233. /** VSI_CALLOC_VERBOSE */
  234. #define VSI_CALLOC_VERBOSE( nCount, nSize ) VSICallocVerbose(nCount,nSize,__FILE__,__LINE__)
  235. /** VSIReallocVerbose */
  236. void CPL_DLL *VSIReallocVerbose( void* pOldPtr, size_t nNewSize, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
  237. /** VSI_REALLOC_VERBOSE */
  238. #define VSI_REALLOC_VERBOSE( pOldPtr, nNewSize ) VSIReallocVerbose(pOldPtr,nNewSize,__FILE__,__LINE__)
  239. /** VSIStrdupVerbose */
  240. char CPL_DLL *VSIStrdupVerbose( const char* pszStr, const char* pszFile, int nLine ) CPL_WARN_UNUSED_RESULT;
  241. /** VSI_STRDUP_VERBOSE */
  242. #define VSI_STRDUP_VERBOSE( pszStr ) VSIStrdupVerbose(pszStr,__FILE__,__LINE__)
  243. GIntBig CPL_DLL CPLGetPhysicalRAM(void);
  244. GIntBig CPL_DLL CPLGetUsablePhysicalRAM(void);
  245. /* ==================================================================== */
  246. /* Other... */
  247. /* ==================================================================== */
  248. /** Alias of VSIReadDir() */
  249. #define CPLReadDir VSIReadDir
  250. char CPL_DLL **VSIReadDir( const char * );
  251. char CPL_DLL **VSIReadDirRecursive( const char *pszPath );
  252. char CPL_DLL **VSIReadDirEx( const char *pszPath, int nMaxFiles );
  253. /** Opaque type for a directory iterator */
  254. typedef struct VSIDIR VSIDIR;
  255. VSIDIR CPL_DLL *VSIOpenDir( const char *pszPath,
  256. int nRecurseDepth,
  257. const char* const *papszOptions);
  258. /** Directory entry. */
  259. typedef struct VSIDIREntry
  260. {
  261. /** Filename */
  262. char* pszName;
  263. /** File mode. See VSI_ISREG() / VSI_ISDIR() */
  264. int nMode;
  265. /** File size */
  266. vsi_l_offset nSize;
  267. /** Last modification time (seconds since 1970/01/01) */
  268. GIntBig nMTime;
  269. /** Whether nMode is known: 0 = unknown, 1 = known. */
  270. char bModeKnown;
  271. /** Whether nSize is known: 0 = unknown, 1 = known. */
  272. char bSizeKnown;
  273. /** Whether nMTime is known: 0 = unknown, 1 = known. */
  274. char bMTimeKnown;
  275. /** NULL-terminated list of extra properties. */
  276. char** papszExtra;
  277. #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
  278. /*! @cond Doxygen_Suppress */
  279. VSIDIREntry();
  280. ~VSIDIREntry();
  281. VSIDIREntry(const VSIDIREntry&) = delete;
  282. VSIDIREntry& operator=(VSIDIREntry&) = delete;
  283. /*! @endcond */
  284. #endif
  285. } VSIDIREntry;
  286. const VSIDIREntry CPL_DLL *VSIGetNextDirEntry(VSIDIR* dir);
  287. void CPL_DLL VSICloseDir(VSIDIR* dir);
  288. int CPL_DLL VSIMkdir( const char * pszPathname, long mode );
  289. int CPL_DLL VSIMkdirRecursive( const char * pszPathname, long mode );
  290. int CPL_DLL VSIRmdir( const char * pszDirname );
  291. int CPL_DLL VSIRmdirRecursive( const char * pszDirname );
  292. int CPL_DLL VSIUnlink( const char * pszFilename );
  293. int CPL_DLL VSIRename( const char * oldpath, const char * newpath );
  294. int CPL_DLL VSISync( const char* pszSource, const char* pszTarget,
  295. const char* const * papszOptions,
  296. GDALProgressFunc pProgressFunc,
  297. void *pProgressData,
  298. char*** ppapszOutputs );
  299. char CPL_DLL *VSIStrerror( int );
  300. GIntBig CPL_DLL VSIGetDiskFreeSpace(const char *pszDirname);
  301. /* ==================================================================== */
  302. /* Install special file access handlers. */
  303. /* ==================================================================== */
  304. void CPL_DLL VSIInstallMemFileHandler(void);
  305. /*! @cond Doxygen_Suppress */
  306. void CPL_DLL VSIInstallLargeFileHandler(void);
  307. /*! @endcond */
  308. void CPL_DLL VSIInstallSubFileHandler(void);
  309. void VSIInstallCurlFileHandler(void);
  310. void CPL_DLL VSICurlClearCache(void);
  311. void CPL_DLL VSICurlPartialClearCache(const char* pszFilenamePrefix);
  312. void VSIInstallCurlStreamingFileHandler(void);
  313. void VSIInstallS3FileHandler(void);
  314. void VSIInstallS3StreamingFileHandler(void);
  315. void VSIInstallGSFileHandler(void);
  316. void VSIInstallGSStreamingFileHandler(void);
  317. void VSIInstallAzureFileHandler(void);
  318. void VSIInstallAzureStreamingFileHandler(void);
  319. void VSIInstallOSSFileHandler(void);
  320. void VSIInstallOSSStreamingFileHandler(void);
  321. void VSIInstallSwiftFileHandler(void);
  322. void VSIInstallSwiftStreamingFileHandler(void);
  323. void VSIInstallGZipFileHandler(void); /* No reason to export that */
  324. void VSIInstallZipFileHandler(void); /* No reason to export that */
  325. void VSIInstallStdinHandler(void); /* No reason to export that */
  326. void VSIInstallHdfsHandler(void); /* No reason to export that */
  327. void VSIInstallWebHdfsHandler(void); /* No reason to export that */
  328. void VSIInstallStdoutHandler(void); /* No reason to export that */
  329. void CPL_DLL VSIInstallSparseFileHandler(void);
  330. void VSIInstallTarFileHandler(void); /* No reason to export that */
  331. void CPL_DLL VSIInstallCryptFileHandler(void);
  332. void CPL_DLL VSISetCryptKey(const GByte* pabyKey, int nKeySize);
  333. /*! @cond Doxygen_Suppress */
  334. void CPL_DLL VSICleanupFileManager(void);
  335. /*! @endcond */
  336. VSILFILE CPL_DLL *VSIFileFromMemBuffer( const char *pszFilename,
  337. GByte *pabyData,
  338. vsi_l_offset nDataLength,
  339. int bTakeOwnership ) CPL_WARN_UNUSED_RESULT;
  340. GByte CPL_DLL *VSIGetMemFileBuffer( const char *pszFilename,
  341. vsi_l_offset *pnDataLength,
  342. int bUnlinkAndSeize );
  343. /** Callback used by VSIStdoutSetRedirection() */
  344. typedef size_t (*VSIWriteFunction)(const void* ptr, size_t size, size_t nmemb, FILE* stream);
  345. void CPL_DLL VSIStdoutSetRedirection( VSIWriteFunction pFct, FILE* stream );
  346. /**
  347. * Return information about a handle. Optional (driver dependent)
  348. * @since GDAL 2.5
  349. */
  350. typedef int (*VSIFilesystemPluginStatCallback) ( void *pUserData, const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags );
  351. /**
  352. * Remove handle by name. Optional
  353. * @since GDAL 2.5
  354. */
  355. typedef int (*VSIFilesystemPluginUnlinkCallback) ( void *pUserData, const char *pszFilename );
  356. /**
  357. * Rename handle. Optional
  358. * @since GDAL 2.5
  359. */
  360. typedef int (*VSIFilesystemPluginRenameCallback) ( void *pUserData, const char *oldpath, const char *newpath );
  361. /**
  362. * Create Directory. Optional
  363. * @since GDAL 2.5
  364. */
  365. typedef int (*VSIFilesystemPluginMkdirCallback) ( void *pUserData, const char *pszDirname, long nMode );
  366. /**
  367. * Delete Directory. Optional
  368. * @since GDAL 2.5
  369. */
  370. typedef int (*VSIFilesystemPluginRmdirCallback) ( void *pUserData, const char *pszDirname );
  371. /**
  372. * List directory content. Optional
  373. * @since GDAL 2.5
  374. */
  375. typedef char** (*VSIFilesystemPluginReadDirCallback) ( void *pUserData, const char *pszDirname, int nMaxFiles );
  376. /**
  377. * Open a handle. Mandatory. Returns an opaque pointer that will be used in subsequent file I/O calls.
  378. * Should return null and/or set errno if the handle does not exist or the access mode is incorrect.
  379. * @since GDAL 2.5
  380. */
  381. typedef void* (*VSIFilesystemPluginOpenCallback) ( void *pUserData, const char *pszFilename, const char *pszAccess );
  382. /**
  383. * Return current position in handle. Mandatory
  384. * @since GDAL 2.5
  385. */
  386. typedef vsi_l_offset (*VSIFilesystemPluginTellCallback) ( void *pFile );
  387. /**
  388. * Seek to position in handle. Mandatory except for write only handles
  389. * @since GDAL 2.5
  390. */
  391. typedef int (*VSIFilesystemPluginSeekCallback) ( void *pFile, vsi_l_offset nOffset, int nWhence );
  392. /**
  393. * Read data from current position, returns the number of blocks correctly read.
  394. * Mandatory except for write only handles
  395. * @since GDAL 2.5
  396. */
  397. typedef size_t (*VSIFilesystemPluginReadCallback) ( void *pFile, void *pBuffer, size_t nSize, size_t nCount );
  398. /**
  399. * Read from multiple offsets. Optional, will be replaced by multiple calls to Read() if not provided
  400. * @since GDAL 2.5
  401. */
  402. typedef int (*VSIFilesystemPluginReadMultiRangeCallback)( void *pFile, int nRanges, void ** ppData,
  403. const vsi_l_offset* panOffsets, const size_t* panSizes );
  404. /**
  405. * Get empty ranges. Optional
  406. * @since GDAL 2.5
  407. */
  408. typedef VSIRangeStatus (*VSIFilesystemPluginGetRangeStatusCallback)( void *pFile, vsi_l_offset nOffset, vsi_l_offset nLength );
  409. /**
  410. * Has end of file been reached. Mandatory? for read handles.
  411. * @since GDAL 2.5
  412. */
  413. typedef int (*VSIFilesystemPluginEofCallback) ( void *pFile );
  414. /**
  415. * Write bytes at current offset. Mandatory for writable handles
  416. * @since GDAL 2.5
  417. */
  418. typedef size_t (*VSIFilesystemPluginWriteCallback) ( void *pFile, const void *pBuffer, size_t nSize,size_t nCount);
  419. /**
  420. * Sync written bytes. Optional
  421. * @since GDAL 2.5
  422. */
  423. typedef int (*VSIFilesystemPluginFlushCallback) ( void *pFile );
  424. /**
  425. * Truncate handle. Mandatory (driver dependent?) for write handles
  426. */
  427. typedef int (*VSIFilesystemPluginTruncateCallback) ( void *pFile, vsi_l_offset nNewSize );
  428. /**
  429. * Close file handle. Optional
  430. * @since GDAL 2.5
  431. */
  432. typedef int (*VSIFilesystemPluginCloseCallback) ( void *pFile );
  433. /**
  434. * struct containing callbacks to used by the handler.
  435. * (rw), (r), (w) or () at the end indicate wether the given callback is mandatory
  436. * for reading and or writing handlers. A (?) indicates that the callback might
  437. * be mandatory for certain drivers only.
  438. * @since GDAL 2.5
  439. */
  440. typedef struct {
  441. /**
  442. * Optional opaque pointer passed back to filemanager callbacks (e.g. open, stat, rmdir)
  443. */
  444. void *pUserData;
  445. VSIFilesystemPluginStatCallback stat; /**< stat handle by name (rw)*/
  446. VSIFilesystemPluginUnlinkCallback unlink; /**< unlink handle by name ()*/
  447. VSIFilesystemPluginRenameCallback rename; /**< rename handle ()*/
  448. VSIFilesystemPluginMkdirCallback mkdir; /**< make directory ()*/
  449. VSIFilesystemPluginRmdirCallback rmdir; /**< remove directory ()*/
  450. VSIFilesystemPluginReadDirCallback read_dir; /**< list directory content (r?)*/
  451. VSIFilesystemPluginOpenCallback open; /**< open handle by name (rw) */
  452. VSIFilesystemPluginTellCallback tell; /**< get current position of handle (rw) */
  453. VSIFilesystemPluginSeekCallback seek; /**< set current position of handle (rw) */
  454. VSIFilesystemPluginReadCallback read; /**< read from current position (r) */
  455. VSIFilesystemPluginReadMultiRangeCallback read_multi_range; /**< read multiple blocks ()*/
  456. VSIFilesystemPluginGetRangeStatusCallback get_range_status; /**< get range status () */
  457. VSIFilesystemPluginEofCallback eof; /**< has end of file been reached (r?) */
  458. VSIFilesystemPluginWriteCallback write; /**< write bytes to current position (w) */
  459. VSIFilesystemPluginFlushCallback flush; /**< sync bytes (w) */
  460. VSIFilesystemPluginTruncateCallback truncate; /**< truncate handle (w?) */
  461. VSIFilesystemPluginCloseCallback close; /**< close handle (rw) */
  462. /*
  463. Callbacks are defined as a struct allocated by a call to VSIAllocFilesystemPluginCallbacksStruct
  464. in order to try to maintain ABI stability when eventually adding a new member.
  465. Any callbacks added to this struct SHOULD be added to the END of this struct
  466. */
  467. } VSIFilesystemPluginCallbacksStruct;
  468. /**
  469. * return a VSIFilesystemPluginCallbacksStruct to be populated at runtime with handler callbacks
  470. * @since GDAL 2.5
  471. */
  472. VSIFilesystemPluginCallbacksStruct CPL_DLL *VSIAllocFilesystemPluginCallbacksStruct( void );
  473. /**
  474. * free resources allocated by VSIAllocFilesystemPluginCallbacksStruct
  475. * @since GDAL 2.5
  476. */
  477. void CPL_DLL VSIFreeFilesystemPluginCallbacksStruct(VSIFilesystemPluginCallbacksStruct* poCb);
  478. /**
  479. * register a handler on the given prefix. All IO on datasets opened with the filename /prefix/xxxxxx
  480. * will go through these callbacks.
  481. * pszPrefix must begin and end with a '/'
  482. * @since GDAL 2.5
  483. */
  484. int CPL_DLL VSIInstallPluginHandler( const char* pszPrefix, const VSIFilesystemPluginCallbacksStruct* poCb);
  485. /* ==================================================================== */
  486. /* Time querying. */
  487. /* ==================================================================== */
  488. /*! @cond Doxygen_Suppress */
  489. unsigned long CPL_DLL VSITime( unsigned long * );
  490. const char CPL_DLL *VSICTime( unsigned long );
  491. struct tm CPL_DLL *VSIGMTime( const time_t *pnTime,
  492. struct tm *poBrokenTime );
  493. struct tm CPL_DLL *VSILocalTime( const time_t *pnTime,
  494. struct tm *poBrokenTime );
  495. /*! @endcond */
  496. /*! @cond Doxygen_Suppress */
  497. /* -------------------------------------------------------------------- */
  498. /* the following can be turned on for detailed logging of */
  499. /* almost all IO calls. */
  500. /* -------------------------------------------------------------------- */
  501. #ifdef VSI_DEBUG
  502. #ifndef DEBUG
  503. # define DEBUG
  504. #endif
  505. #include "cpl_error.h"
  506. #define VSIDebug4(f,a1,a2,a3,a4) CPLDebug( "VSI", f, a1, a2, a3, a4 );
  507. #define VSIDebug3( f, a1, a2, a3 ) CPLDebug( "VSI", f, a1, a2, a3 );
  508. #define VSIDebug2( f, a1, a2 ) CPLDebug( "VSI", f, a1, a2 );
  509. #define VSIDebug1( f, a1 ) CPLDebug( "VSI", f, a1 );
  510. #else
  511. #define VSIDebug4( f, a1, a2, a3, a4 ) {}
  512. #define VSIDebug3( f, a1, a2, a3 ) {}
  513. #define VSIDebug2( f, a1, a2 ) {}
  514. #define VSIDebug1( f, a1 ) {}
  515. #endif
  516. /*! @endcond */
  517. CPL_C_END
  518. #endif /* ndef CPL_VSI_H_INCLUDED */
上海开阖软件有限公司 沪ICP备12045867号-1