GDAL
cpl_vsi_virtual.h
1/******************************************************************************
2 *
3 * Project: VSI Virtual File System
4 * Purpose: Declarations for classes related to the virtual filesystem.
5 * These would only be normally required by applications implementing
6 * their own virtual file system classes which should be rare.
7 * The class interface may be fragile through versions.
8 * Author: Frank Warmerdam, warmerdam@pobox.com
9 *
10 ******************************************************************************
11 * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com>
12 * Copyright (c) 2010-2014, Even Rouault <even dot rouault at spatialys.com>
13 *
14 * SPDX-License-Identifier: MIT
15 ****************************************************************************/
16
17#ifndef CPL_VSI_VIRTUAL_H_INCLUDED
18#define CPL_VSI_VIRTUAL_H_INCLUDED
19
20#include "cpl_progress.h"
21#include "cpl_vsi.h"
22#include "cpl_vsi_error.h"
23#include "cpl_string.h"
24
25#include <cstdint>
26#include <map>
27#include <memory>
28#include <mutex>
29#include <vector>
30#include <string>
31
32// To avoid aliasing to GetDiskFreeSpace to GetDiskFreeSpaceA on Windows
33#ifdef GetDiskFreeSpace
34#undef GetDiskFreeSpace
35#endif
36
37// To avoid aliasing to CopyFile to CopyFileA on Windows
38#ifdef CopyFile
39#undef CopyFile
40#endif
41
42/************************************************************************/
43/* VSIVirtualHandle */
44/************************************************************************/
45
47struct CPL_DLL VSIVirtualHandle
48{
49 public:
50 virtual int Seek(vsi_l_offset nOffset, int nWhence) = 0;
51
52#ifdef GDAL_COMPILATION
54 inline int Seek(int &&nOffset, int nWhence)
55 {
56 return Seek(static_cast<vsi_l_offset>(nOffset), nWhence);
57 }
58
59 inline int Seek(unsigned &&nOffset, int nWhence)
60 {
61 return Seek(static_cast<vsi_l_offset>(nOffset), nWhence);
62 }
63
64 template <typename T>
65 inline std::enable_if_t<std::is_same_v<T, uint64_t> &&
66 !std::is_same_v<uint64_t, vsi_l_offset>,
67 int>
68 Seek(T nOffset, int nWhence)
69 {
70 return Seek(static_cast<vsi_l_offset>(nOffset), nWhence);
71 }
72
73 template <typename T>
74 inline std::enable_if_t<std::is_same_v<T, size_t> &&
75 !std::is_same_v<T, uint64_t> &&
76 !std::is_same_v<size_t, unsigned> &&
77 !std::is_same_v<size_t, vsi_l_offset>,
78 int>
79 Seek(T nOffset, int nWhence) = delete;
80
81 int Seek(int &nOffset, int nWhence) = delete;
82 int Seek(const int &nOffset, int nWhence) = delete;
83 int Seek(unsigned &nOffset, int nWhence) = delete;
84 int Seek(const unsigned &nOffset, int nWhence) = delete;
86#endif
87
88 virtual vsi_l_offset Tell() = 0;
89 size_t Read(void *pBuffer, size_t nSize, size_t nCount);
90
91 virtual size_t Read(void *pBuffer, size_t nBytes) = 0;
92
103 template <class T> inline T ReadLSB(bool *pbError = nullptr)
104 {
105 T val;
106 if (Read(&val, sizeof(val)) != sizeof(val))
107 {
108 if (pbError)
109 *pbError = true;
110 return 0;
111 }
112 return CPL_AS_LSB(val);
113 }
114
116 template <class T> inline bool ReadLSB(T &val)
117 {
118 if (Read(&val, sizeof(val)) != sizeof(val))
119 {
120 return false;
121 }
122 val = CPL_AS_LSB(val);
123 return true;
124 }
125
126 bool ReadLSB(bool &) = delete;
127
128 virtual int ReadMultiRange(int nRanges, void **ppData,
129 const vsi_l_offset *panOffsets,
130 const size_t *panSizes);
131
144 virtual void AdviseRead(CPL_UNUSED int nRanges,
145 CPL_UNUSED const vsi_l_offset *panOffsets,
146 CPL_UNUSED const size_t *panSizes)
147 {
148 }
149
162 virtual size_t GetAdviseReadTotalBytesLimit() const
163 {
164 return 0;
165 }
166
167 virtual size_t Write(const void *pBuffer, size_t nBytes) = 0;
168 size_t Write(const void *pBuffer, size_t nSize, size_t nCount);
169
171 template <class T> inline bool WriteLSB(T val)
172 {
173 val = CPL_AS_LSB(val);
174 return Write(&val, sizeof(val)) == sizeof(val);
175 }
176
177 int Printf(CPL_FORMAT_STRING(const char *pszFormat), ...)
179
180 virtual void ClearErr() = 0;
181
182 virtual int Eof() = 0;
183
184 virtual int Error() = 0;
185
186 virtual int Flush()
187 {
188 return 0;
189 }
190
191 virtual int Close() = 0;
192 // Base implementation that only supports file extension.
193 virtual int Truncate(vsi_l_offset nNewSize);
194
196 {
197 return nullptr;
198 }
199
205
206 virtual bool HasPRead() const;
207 virtual size_t PRead(void *pBuffer, size_t nSize,
208 vsi_l_offset nOffset) const;
209
214 virtual void Interrupt()
215 {
216 }
217
221 virtual void CancelCreation()
222 {
223 }
224
225 // NOTE: when adding new methods, besides the "actual" implementations,
226 // also consider the VSICachedFile and VSIVirtualHandleOnlyVisibleAtCloseTime one.
227
228 virtual ~VSIVirtualHandle()
229 {
230 }
231};
232
233/************************************************************************/
234/* VSIVirtualHandleCloser */
235/************************************************************************/
236
240
241{
244 {
245 if (poHandle)
246 {
247 poHandle->Close();
248 delete poHandle;
249 }
250 }
251};
252
254typedef std::unique_ptr<VSIVirtualHandle, VSIVirtualHandleCloser>
255 VSIVirtualHandleUniquePtr;
256
257/************************************************************************/
258/* VSIProxyFileHandle */
259/************************************************************************/
260
261#ifndef DOXYGEN_SKIP
262class VSIProxyFileHandle /* non final */ : public VSIVirtualHandle
263{
264 protected:
265 VSIVirtualHandleUniquePtr m_nativeHandle{};
266
267 public:
268 explicit VSIProxyFileHandle(VSIVirtualHandleUniquePtr &&nativeHandle)
269 : m_nativeHandle(std::move(nativeHandle))
270 {
271 }
272
273 int Seek(vsi_l_offset nOffset, int nWhence) override
274 {
275 return m_nativeHandle->Seek(nOffset, nWhence);
276 }
277
278 vsi_l_offset Tell() override
279 {
280 return m_nativeHandle->Tell();
281 }
282
283 size_t Read(void *pBuffer, size_t nBytes) override
284 {
285 return m_nativeHandle->Read(pBuffer, nBytes);
286 }
287
288 int ReadMultiRange(int nRanges, void **ppData,
289 const vsi_l_offset *panOffsets,
290 const size_t *panSizes) override
291 {
292 return m_nativeHandle->ReadMultiRange(nRanges, ppData, panOffsets,
293 panSizes);
294 }
295
296 void AdviseRead(int nRanges, const vsi_l_offset *panOffsets,
297 const size_t *panSizes) override
298 {
299 return m_nativeHandle->AdviseRead(nRanges, panOffsets, panSizes);
300 }
301
302 size_t GetAdviseReadTotalBytesLimit() const override
303 {
304 return m_nativeHandle->GetAdviseReadTotalBytesLimit();
305 }
306
307 size_t Write(const void *pBuffer, size_t nBytes) override
308 {
309 return m_nativeHandle->Write(pBuffer, nBytes);
310 }
311
312 void ClearErr() override
313 {
314 return m_nativeHandle->ClearErr();
315 }
316
317 int Eof() override
318 {
319 return m_nativeHandle->Eof();
320 }
321
322 int Error() override
323 {
324 return m_nativeHandle->Error();
325 }
326
327 int Flush() override
328 {
329 return m_nativeHandle->Flush();
330 }
331
332 int Close() override
333 {
334 return m_nativeHandle->Close();
335 }
336
337 int Truncate(vsi_l_offset nNewSize) override
338 {
339 return m_nativeHandle->Truncate(nNewSize);
340 }
341
342 void *GetNativeFileDescriptor() override
343 {
344 return m_nativeHandle->GetNativeFileDescriptor();
345 }
346
348 vsi_l_offset nLength) override
349 {
350 return m_nativeHandle->GetRangeStatus(nOffset, nLength);
351 }
352
353 bool HasPRead() const override
354 {
355 return m_nativeHandle->HasPRead();
356 }
357
358 size_t PRead(void *pBuffer, size_t nSize,
359 vsi_l_offset nOffset) const override
360 {
361 return m_nativeHandle->PRead(pBuffer, nSize, nOffset);
362 }
363
364 void Interrupt() override
365 {
366 m_nativeHandle->Interrupt();
367 }
368
369 void CancelCreation() override;
370};
371#endif
372
373/************************************************************************/
374/* VSIFilesystemHandler */
375/************************************************************************/
376
377#ifndef DOXYGEN_SKIP
378class CPL_DLL VSIFilesystemHandler
379{
380
381 public:
382 virtual ~VSIFilesystemHandler() = default;
383
384 static VSIVirtualHandleUniquePtr
385 OpenStatic(const char *pszFilename, const char *pszAccess,
386 bool bSetError = false, CSLConstList papszOptions = nullptr);
387
388 virtual VSIVirtualHandleUniquePtr
389 Open(const char *pszFilename, const char *pszAccess, bool bSetError = false,
390 CSLConstList papszOptions = nullptr) = 0;
391
392 virtual VSIVirtualHandleUniquePtr
393 CreateOnlyVisibleAtCloseTime(const char *pszFilename,
394 bool bEmulationAllowed,
395 CSLConstList papszOptions);
396
397 virtual int Stat(const char *pszFilename, VSIStatBufL *pStatBuf,
398 int nFlags) = 0;
399
400 virtual int Unlink(const char *pszFilename)
401 {
402 (void)pszFilename;
403 errno = ENOENT;
404 return -1;
405 }
406
407 virtual int *UnlinkBatch(CSLConstList papszFiles);
408
409 virtual int Mkdir(const char *pszDirname, long nMode)
410 {
411 (void)pszDirname;
412 (void)nMode;
413 errno = ENOENT;
414 return -1;
415 }
416
417 virtual int Rmdir(const char *pszDirname)
418 {
419 (void)pszDirname;
420 errno = ENOENT;
421 return -1;
422 }
423
424 virtual int RmdirRecursive(const char *pszDirname);
425
426 char **ReadDir(const char *pszDirname)
427 {
428 return ReadDirEx(pszDirname, 0);
429 }
430
431 virtual char **ReadDirEx(const char * /*pszDirname*/, int /* nMaxFiles */)
432 {
433 return nullptr;
434 }
435
436 virtual char **SiblingFiles(const char * /*pszFilename*/)
437 {
438 return nullptr;
439 }
440
441 virtual int Rename(const char *oldpath, const char *newpath,
442 GDALProgressFunc pProgressFunc, void *pProgressData)
443 {
444 (void)oldpath;
445 (void)newpath;
446 (void)pProgressFunc;
447 (void)pProgressData;
448 errno = ENOENT;
449 return -1;
450 }
451
452 virtual int IsCaseSensitive(const char *pszFilename)
453 {
454 (void)pszFilename;
455 return TRUE;
456 }
457
458 virtual GIntBig GetDiskFreeSpace(const char * /* pszDirname */)
459 {
460 return -1;
461 }
462
463 virtual int SupportsSparseFiles(const char * /* pszPath */)
464 {
465 return FALSE;
466 }
467
468 virtual int HasOptimizedReadMultiRange(const char * /* pszPath */)
469 {
470 return FALSE;
471 }
472
473 virtual const char *GetActualURL(const char * /*pszFilename*/)
474 {
475 return nullptr;
476 }
477
478 virtual const char *GetOptions()
479 {
480 return nullptr;
481 }
482
483 virtual char *GetSignedURL(const char * /*pszFilename*/,
484 CSLConstList /* papszOptions */)
485 {
486 return nullptr;
487 }
488
489 virtual bool Sync(const char *pszSource, const char *pszTarget,
490 const char *const *papszOptions,
491 GDALProgressFunc pProgressFunc, void *pProgressData,
492 char ***ppapszOutputs);
493
494 virtual int CopyFile(const char *pszSource, const char *pszTarget,
495 VSILFILE *fpSource, vsi_l_offset nSourceSize,
496 const char *const *papszOptions,
497 GDALProgressFunc pProgressFunc, void *pProgressData);
498
499 virtual int
500 CopyFileRestartable(const char *pszSource, const char *pszTarget,
501 const char *pszInputPayload, char **ppszOutputPayload,
502 CSLConstList papszOptions,
503 GDALProgressFunc pProgressFunc, void *pProgressData);
504
505 virtual VSIDIR *OpenDir(const char *pszPath, int nRecurseDepth,
506 const char *const *papszOptions);
507
508 virtual char **GetFileMetadata(const char *pszFilename,
509 const char *pszDomain,
510 CSLConstList papszOptions);
511
512 virtual bool SetFileMetadata(const char *pszFilename,
513 CSLConstList papszMetadata,
514 const char *pszDomain,
515 CSLConstList papszOptions);
516
517 virtual bool
518 MultipartUploadGetCapabilities(int *pbNonSequentialUploadSupported,
519 int *pbParallelUploadSupported,
520 int *pbAbortSupported, size_t *pnMinPartSize,
521 size_t *pnMaxPartSize, int *pnMaxPartCount);
522
523 virtual char *MultipartUploadStart(const char *pszFilename,
524 CSLConstList papszOptions);
525
526 virtual char *MultipartUploadAddPart(const char *pszFilename,
527 const char *pszUploadId,
528 int nPartNumber,
529 vsi_l_offset nFileOffset,
530 const void *pData, size_t nDataLength,
531 CSLConstList papszOptions);
532
533 virtual bool
534 MultipartUploadEnd(const char *pszFilename, const char *pszUploadId,
535 size_t nPartIdsCount, const char *const *apszPartIds,
536 vsi_l_offset nTotalSize, CSLConstList papszOptions);
537
538 virtual bool MultipartUploadAbort(const char *pszFilename,
539 const char *pszUploadId,
540 CSLConstList papszOptions);
541
542 virtual bool AbortPendingUploads(const char * /*pszFilename*/)
543 {
544 return true;
545 }
546
547 virtual std::string
548 GetStreamingFilename(const std::string &osFilename) const
549 {
550 return osFilename;
551 }
552
553 virtual std::string
554 GetNonStreamingFilename(const std::string &osFilename) const
555 {
556 return osFilename;
557 }
558
566 virtual std::string
567 GetCanonicalFilename(const std::string &osFilename) const
568 {
569 return osFilename;
570 }
571
572 virtual bool IsLocal(const char * /* pszPath */) const
573 {
574 return true;
575 }
576
577 virtual bool IsArchive(const char * /* pszPath */) const
578 {
579 return false;
580 }
581
582 virtual bool SupportsSequentialWrite(const char * /* pszPath */,
583 bool /* bAllowLocalTempFile */)
584 {
585 return true;
586 }
587
588 virtual bool SupportsRandomWrite(const char * /* pszPath */,
589 bool /* bAllowLocalTempFile */)
590 {
591 return true;
592 }
593
594 virtual bool SupportsRead(const char * /* pszPath */)
595 {
596 return true;
597 }
598
599 virtual VSIFilesystemHandler *Duplicate(const char * /* pszPrefix */)
600 {
602 "Duplicate() not supported on this file "
603 "system");
604 return nullptr;
605 }
606
613 virtual const char *GetDirectorySeparator(CPL_UNUSED const char *pszPath)
614 {
615 return "/";
616 }
617
629 virtual std::string
630 GetHintForPotentiallyRecognizedPath(const std::string &osPath)
631 {
632 (void)osPath;
633 return std::string();
634 }
635};
636#endif /* #ifndef DOXYGEN_SKIP */
637
638/************************************************************************/
639/* VSIFileManager */
640/************************************************************************/
641
642#ifndef DOXYGEN_SKIP
643class CPL_DLL VSIFileManager
644{
645 private:
646 std::shared_ptr<VSIFilesystemHandler> m_poDefaultHandler{};
647 std::map<std::string, std::shared_ptr<VSIFilesystemHandler>>
648 m_apoHandlers{};
649
650 VSIFileManager();
651
652 static VSIFileManager *Get();
653
654 CPL_DISALLOW_COPY_ASSIGN(VSIFileManager)
655
656 public:
657 ~VSIFileManager();
658
659 static VSIFilesystemHandler *GetHandler(const char *);
660 static void InstallHandler(const std::string &osPrefix,
661 const std::shared_ptr<VSIFilesystemHandler> &);
662 static void InstallHandler(const std::string &osPrefix,
663 VSIFilesystemHandler *)
664 CPL_WARN_DEPRECATED("Use version with std::shared_ptr<> instead");
665 static void RemoveHandler(const std::string &osPrefix);
666
667 static char **GetPrefixes();
668};
669#endif /* #ifndef DOXYGEN_SKIP */
670
671/************************************************************************/
672/* ==================================================================== */
673/* VSIArchiveFilesystemHandler */
674/* ==================================================================== */
675/************************************************************************/
676
677#ifndef DOXYGEN_SKIP
678
679class VSIArchiveEntryFileOffset
680{
681 public:
682 virtual ~VSIArchiveEntryFileOffset();
683};
684
685class VSIArchiveEntry
686{
687 public:
688 std::string fileName{};
689 vsi_l_offset uncompressed_size = 0;
690 std::unique_ptr<VSIArchiveEntryFileOffset> file_pos{};
691 bool bIsDir = false;
692 GIntBig nModifiedTime = 0;
693};
694
695class VSIArchiveContent
696{
697 public:
698 time_t mTime = 0;
699 vsi_l_offset nFileSize = 0;
700 std::vector<VSIArchiveEntry> entries{};
701
702 // Store list of child indices for each directory
703 using DirectoryChildren = std::vector<int>;
704
705 std::map<std::string, DirectoryChildren> dirIndex{};
706
707 VSIArchiveContent() = default;
708
709 ~VSIArchiveContent();
710
711 private:
712 CPL_DISALLOW_COPY_ASSIGN(VSIArchiveContent)
713};
714
715class VSIArchiveReader
716{
717 public:
718 virtual ~VSIArchiveReader();
719
720 virtual int GotoFirstFile() = 0;
721 virtual int GotoNextFile() = 0;
722 virtual VSIArchiveEntryFileOffset *GetFileOffset() = 0;
723 virtual GUIntBig GetFileSize() = 0;
724 virtual CPLString GetFileName() = 0;
725 virtual GIntBig GetModifiedTime() = 0;
726 virtual int GotoFileOffset(VSIArchiveEntryFileOffset *pOffset) = 0;
727};
728
729class VSIArchiveFilesystemHandler /* non final */ : public VSIFilesystemHandler
730{
731 CPL_DISALLOW_COPY_ASSIGN(VSIArchiveFilesystemHandler)
732
733 bool FindFileInArchive(const char *archiveFilename,
734 const char *fileInArchiveName,
735 const VSIArchiveEntry **archiveEntry);
736
737 protected:
738 mutable std::recursive_mutex oMutex{};
739
740 /* We use a cache that contains the list of files contained in a VSIArchive
741 * file as */
742 /* unarchive.c is quite inefficient in listing them. This speeds up access
743 * to VSIArchive files */
744 /* containing ~1000 files like a CADRG product */
745 std::map<CPLString, std::unique_ptr<VSIArchiveContent>> oFileList{};
746
747 virtual const char *GetPrefix() const = 0;
748 virtual std::vector<CPLString> GetExtensions() const = 0;
749 virtual std::unique_ptr<VSIArchiveReader>
750 CreateReader(const char *pszArchiveFileName) = 0;
751
752 public:
753 VSIArchiveFilesystemHandler();
754 ~VSIArchiveFilesystemHandler() override;
755
756 int Stat(const char *pszFilename, VSIStatBufL *pStatBuf,
757 int nFlags) override;
758 char **ReadDirEx(const char *pszDirname, int nMaxFiles) override;
759
760 virtual const VSIArchiveContent *
761 GetContentOfArchive(const char *archiveFilename,
762 VSIArchiveReader *poReader = nullptr);
763 virtual std::unique_ptr<char, VSIFreeReleaser>
764 SplitFilename(const char *pszFilename, CPLString &osFileInArchive,
765 bool bCheckMainFileExists, bool bSetError) const;
766 virtual std::unique_ptr<VSIArchiveReader>
767 OpenArchiveFile(const char *archiveFilename, const char *fileInArchiveName);
768
769 bool IsLocal(const char *pszPath) const override;
770
771 bool IsArchive(const char *pszPath) const override;
772
773 bool SupportsSequentialWrite(const char * /* pszPath */,
774 bool /* bAllowLocalTempFile */) override
775 {
776 return false;
777 }
778
779 bool SupportsRandomWrite(const char * /* pszPath */,
780 bool /* bAllowLocalTempFile */) override
781 {
782 return false;
783 }
784
785 std::string
786 GetHintForPotentiallyRecognizedPath(const std::string &osPath) override;
787};
788
789/************************************************************************/
790/* VSIDIR */
791/************************************************************************/
792
793struct CPL_DLL VSIDIR
794{
795 VSIDIR() = default;
796 virtual ~VSIDIR();
797
798 virtual const VSIDIREntry *NextDirEntry() = 0;
799
800 private:
801 VSIDIR(const VSIDIR &) = delete;
802 VSIDIR &operator=(const VSIDIR &) = delete;
803};
804
805#endif /* #ifndef DOXYGEN_SKIP */
806
807VSIVirtualHandle CPL_DLL *
808VSICreateBufferedReaderHandle(VSIVirtualHandle *poBaseHandle);
810VSICreateBufferedReaderHandle(VSIVirtualHandle *poBaseHandle,
811 const GByte *pabyBeginningContent,
812 vsi_l_offset nCheatFileSize);
813constexpr int VSI_CACHED_DEFAULT_CHUNK_SIZE = 32768;
814VSIVirtualHandle CPL_DLL *
815VSICreateCachedFile(VSIVirtualHandle *poBaseHandle,
816 size_t nChunkSize = VSI_CACHED_DEFAULT_CHUNK_SIZE,
817 size_t nCacheSize = 0);
818
819const int CPL_DEFLATE_TYPE_GZIP = 0;
820const int CPL_DEFLATE_TYPE_ZLIB = 1;
821const int CPL_DEFLATE_TYPE_RAW_DEFLATE = 2;
822VSIVirtualHandle CPL_DLL *VSICreateGZipWritable(VSIVirtualHandle *poBaseHandle,
823 int nDeflateType,
824 int bAutoCloseBaseHandle);
825
826VSIVirtualHandle *VSICreateGZipWritable(VSIVirtualHandle *poBaseHandle,
827 int nDeflateType,
828 bool bAutoCloseBaseHandle, int nThreads,
829 size_t nChunkSize,
830 size_t nSOZIPIndexEltSize,
831 std::vector<uint8_t> *panSOZIPIndex);
832
834VSICreateUploadOnCloseFile(VSIVirtualHandleUniquePtr &&poWritableHandle,
835 VSIVirtualHandleUniquePtr &&poTmpFile,
836 const std::string &osTmpFilename);
837
838#endif /* ndef CPL_VSI_VIRTUAL_H_INCLUDED */
Convenient string class based on std::string.
Definition cpl_string.h:338
#define CPLE_NotSupported
Not supported.
Definition cpl_error.h:118
@ CE_Failure
Error that prevents the current operation to succeed.
Definition cpl_error.h:60
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition cpl_port.h:198
#define CPL_UNUSED
Qualifier for an argument that is unused.
Definition cpl_port.h:1044
#define CPL_FORMAT_STRING(arg)
Macro into which to wrap the format argument of a printf-like function.
Definition cpl_port.h:1025
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition cpl_port.h:1009
#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:1101
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1252
unsigned char GByte
Unsigned byte type.
Definition cpl_port.h:165
T CPL_AS_LSB(T)
Return the provided value as a LSB ordered one.
Definition cpl_port.h:825
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:195
Various convenience functions for working with strings and string lists.
Standard C Covers.
#define VSIStatBufL
Type for VSIStatL()
Definition cpl_vsi.h:232
VSIRangeStatus
Range status.
Definition cpl_vsi.h:211
@ VSI_RANGE_STATUS_UNKNOWN
Unknown.
Definition cpl_vsi.h:212
struct VSIDIR VSIDIR
Opaque type for a directory iterator.
Definition cpl_vsi.h:433
GUIntBig vsi_l_offset
Type for a file offset.
Definition cpl_vsi.h:136
Directory entry.
Definition cpl_vsi.h:445
Helper close to use with a std:unique_ptr<VSIVirtualHandle>, such as VSIVirtualHandleUniquePtr.
Definition cpl_vsi_virtual.h:241
void operator()(VSIVirtualHandle *poHandle)
Operator () that closes and deletes the file handle.
Definition cpl_vsi_virtual.h:243
Virtual file handle.
Definition cpl_vsi_virtual.h:48
virtual size_t PRead(void *pBuffer, size_t nSize, vsi_l_offset nOffset) const
Do a parallel-compatible read operation.
Definition cpl_vsil.cpp:4507
virtual void CancelCreation()
For a file created with CreateOnlyVisibleAtCloseTime(), ask for the file to not be created at all (if...
Definition cpl_vsi_virtual.h:221
virtual int Error()=0
Test the error indicator.
virtual size_t Read(void *pBuffer, size_t nBytes)=0
Read bytes from file.
virtual int Flush()
Flush pending writes to disk.
Definition cpl_vsi_virtual.h:186
virtual bool HasPRead() const
Returns whether this file handle supports the PRead() method.
Definition cpl_vsil.cpp:4481
bool WriteLSB(T val)
Write a primitive type as LSB-ordered byte sequence.
Definition cpl_vsi_virtual.h:171
bool ReadLSB(T &val)
Read a primitive type from LSB-ordered byte sequence.
Definition cpl_vsi_virtual.h:116
virtual int Close()=0
Close file.
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:200
size_t Read(void *pBuffer, size_t nSize, size_t nCount)
Read bytes from file.
Definition cpl_vsil.cpp:3491
virtual vsi_l_offset Tell()=0
Tell current file offset.
virtual int Seek(vsi_l_offset nOffset, int nWhence)=0
Seek to requested offset.
virtual void * GetNativeFileDescriptor()
Returns the "native" file descriptor for the virtual handle.
Definition cpl_vsi_virtual.h:195
virtual size_t GetAdviseReadTotalBytesLimit() const
Return the total maximum number of bytes that AdviseRead() can handle at once.
Definition cpl_vsi_virtual.h:162
virtual void AdviseRead(int nRanges, const vsi_l_offset *panOffsets, const size_t *panSizes)
This method is called when code plans to access soon one or several ranges in a file.
Definition cpl_vsi_virtual.h:144
virtual int ReadMultiRange(int nRanges, void **ppData, const vsi_l_offset *panOffsets, const size_t *panSizes)
Read several ranges of bytes from file.
virtual int Eof()=0
Test for end of file.
virtual void Interrupt()
Ask current operations to be interrupted.
Definition cpl_vsi_virtual.h:214
T ReadLSB(bool *pbError=nullptr)
Read a primitive type from LSB-ordered byte sequence.
Definition cpl_vsi_virtual.h:103
virtual size_t Write(const void *pBuffer, size_t nBytes)=0
Write bytes to file.
virtual int Truncate(vsi_l_offset nNewSize)
Truncate/expand the file to the specified size.
virtual void ClearErr()=0
Reset the error and end-of-file indicators.