fileio.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Copyright (c) Meta Platforms, Inc. and affiliates.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under both the BSD-style license (found in the
  6. * LICENSE file in the root directory of this source tree) and the GPLv2 (found
  7. * in the COPYING file in the root directory of this source tree).
  8. * You may select, at your option, one of the above-listed licenses.
  9. */
  10. #ifndef FILEIO_H_23981798732
  11. #define FILEIO_H_23981798732
  12. #include "fileio_types.h"
  13. #include "util.h" /* FileNamesTable */
  14. #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */
  15. #include "../lib/zstd.h" /* ZSTD_* */
  16. #if defined (__cplusplus)
  17. extern "C" {
  18. #endif
  19. /* *************************************
  20. * Special i/o constants
  21. **************************************/
  22. #define stdinmark "/*stdin*\\"
  23. #define stdoutmark "/*stdout*\\"
  24. #ifdef _WIN32
  25. # define nulmark "NUL"
  26. #else
  27. # define nulmark "/dev/null"
  28. #endif
  29. /**
  30. * We test whether the extension we found starts with 't', and if so, we append
  31. * ".tar" to the end of the output name.
  32. */
  33. #define LZMA_EXTENSION ".lzma"
  34. #define XZ_EXTENSION ".xz"
  35. #define TXZ_EXTENSION ".txz"
  36. #define GZ_EXTENSION ".gz"
  37. #define TGZ_EXTENSION ".tgz"
  38. #define ZSTD_EXTENSION ".zst"
  39. #define TZSTD_EXTENSION ".tzst"
  40. #define ZSTD_ALT_EXTENSION ".zstd" /* allow decompression of .zstd files */
  41. #define LZ4_EXTENSION ".lz4"
  42. #define TLZ4_EXTENSION ".tlz4"
  43. /*-*************************************
  44. * Types
  45. ***************************************/
  46. FIO_prefs_t* FIO_createPreferences(void);
  47. void FIO_freePreferences(FIO_prefs_t* const prefs);
  48. /* Mutable struct containing relevant context and state regarding (de)compression with respect to file I/O */
  49. typedef struct FIO_ctx_s FIO_ctx_t;
  50. FIO_ctx_t* FIO_createContext(void);
  51. void FIO_freeContext(FIO_ctx_t* const fCtx);
  52. /*-*************************************
  53. * Parameters
  54. ***************************************/
  55. /* FIO_prefs_t functions */
  56. void FIO_setCompressionType(FIO_prefs_t* const prefs, FIO_compressionType_t compressionType);
  57. void FIO_overwriteMode(FIO_prefs_t* const prefs);
  58. void FIO_setAdaptiveMode(FIO_prefs_t* const prefs, int adapt);
  59. void FIO_setAdaptMin(FIO_prefs_t* const prefs, int minCLevel);
  60. void FIO_setAdaptMax(FIO_prefs_t* const prefs, int maxCLevel);
  61. void FIO_setUseRowMatchFinder(FIO_prefs_t* const prefs, int useRowMatchFinder);
  62. void FIO_setBlockSize(FIO_prefs_t* const prefs, int blockSize);
  63. void FIO_setChecksumFlag(FIO_prefs_t* const prefs, int checksumFlag);
  64. void FIO_setDictIDFlag(FIO_prefs_t* const prefs, int dictIDFlag);
  65. void FIO_setLdmBucketSizeLog(FIO_prefs_t* const prefs, int ldmBucketSizeLog);
  66. void FIO_setLdmFlag(FIO_prefs_t* const prefs, unsigned ldmFlag);
  67. void FIO_setLdmHashRateLog(FIO_prefs_t* const prefs, int ldmHashRateLog);
  68. void FIO_setLdmHashLog(FIO_prefs_t* const prefs, int ldmHashLog);
  69. void FIO_setLdmMinMatch(FIO_prefs_t* const prefs, int ldmMinMatch);
  70. void FIO_setMemLimit(FIO_prefs_t* const prefs, unsigned memLimit);
  71. void FIO_setNbWorkers(FIO_prefs_t* const prefs, int nbWorkers);
  72. void FIO_setOverlapLog(FIO_prefs_t* const prefs, int overlapLog);
  73. void FIO_setRemoveSrcFile(FIO_prefs_t* const prefs, int flag);
  74. void FIO_setSparseWrite(FIO_prefs_t* const prefs, int sparse); /**< 0: no sparse; 1: disable on stdout; 2: always enabled */
  75. void FIO_setRsyncable(FIO_prefs_t* const prefs, int rsyncable);
  76. void FIO_setStreamSrcSize(FIO_prefs_t* const prefs, size_t streamSrcSize);
  77. void FIO_setTargetCBlockSize(FIO_prefs_t* const prefs, size_t targetCBlockSize);
  78. void FIO_setSrcSizeHint(FIO_prefs_t* const prefs, size_t srcSizeHint);
  79. void FIO_setTestMode(FIO_prefs_t* const prefs, int testMode);
  80. void FIO_setLiteralCompressionMode(
  81. FIO_prefs_t* const prefs,
  82. ZSTD_paramSwitch_e mode);
  83. void FIO_setProgressSetting(FIO_progressSetting_e progressSetting);
  84. void FIO_setNotificationLevel(int level);
  85. void FIO_setExcludeCompressedFile(FIO_prefs_t* const prefs, int excludeCompressedFiles);
  86. void FIO_setAllowBlockDevices(FIO_prefs_t* const prefs, int allowBlockDevices);
  87. void FIO_setPatchFromMode(FIO_prefs_t* const prefs, int value);
  88. void FIO_setContentSize(FIO_prefs_t* const prefs, int value);
  89. void FIO_displayCompressionParameters(const FIO_prefs_t* prefs);
  90. void FIO_setAsyncIOFlag(FIO_prefs_t* const prefs, int value);
  91. void FIO_setPassThroughFlag(FIO_prefs_t* const prefs, int value);
  92. void FIO_setMMapDict(FIO_prefs_t* const prefs, ZSTD_paramSwitch_e value);
  93. /* FIO_ctx_t functions */
  94. void FIO_setNbFilesTotal(FIO_ctx_t* const fCtx, int value);
  95. void FIO_setHasStdoutOutput(FIO_ctx_t* const fCtx, int value);
  96. void FIO_determineHasStdinInput(FIO_ctx_t* const fCtx, const FileNamesTable* const filenames);
  97. /*-*************************************
  98. * Single File functions
  99. ***************************************/
  100. /** FIO_compressFilename() :
  101. * @return : 0 == ok; 1 == pb with src file. */
  102. int FIO_compressFilename (FIO_ctx_t* const fCtx, FIO_prefs_t* const prefs,
  103. const char* outfilename, const char* infilename,
  104. const char* dictFileName, int compressionLevel,
  105. ZSTD_compressionParameters comprParams);
  106. /** FIO_decompressFilename() :
  107. * @return : 0 == ok; 1 == pb with src file. */
  108. int FIO_decompressFilename (FIO_ctx_t* const fCtx, FIO_prefs_t* const prefs,
  109. const char* outfilename, const char* infilename, const char* dictFileName);
  110. int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int displayLevel);
  111. /*-*************************************
  112. * Multiple File functions
  113. ***************************************/
  114. /** FIO_compressMultipleFilenames() :
  115. * @return : nb of missing files */
  116. int FIO_compressMultipleFilenames(FIO_ctx_t* const fCtx,
  117. FIO_prefs_t* const prefs,
  118. const char** inFileNamesTable,
  119. const char* outMirroredDirName,
  120. const char* outDirName,
  121. const char* outFileName, const char* suffix,
  122. const char* dictFileName, int compressionLevel,
  123. ZSTD_compressionParameters comprParams);
  124. /** FIO_decompressMultipleFilenames() :
  125. * @return : nb of missing or skipped files */
  126. int FIO_decompressMultipleFilenames(FIO_ctx_t* const fCtx,
  127. FIO_prefs_t* const prefs,
  128. const char** srcNamesTable,
  129. const char* outMirroredDirName,
  130. const char* outDirName,
  131. const char* outFileName,
  132. const char* dictFileName);
  133. /* FIO_checkFilenameCollisions() :
  134. * Checks for and warns if there are any files that would have the same output path
  135. */
  136. int FIO_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles);
  137. /*-*************************************
  138. * Advanced stuff (should actually be hosted elsewhere)
  139. ***************************************/
  140. /* custom crash signal handler */
  141. void FIO_addAbortHandler(void);
  142. char const* FIO_zlibVersion(void);
  143. char const* FIO_lz4Version(void);
  144. char const* FIO_lzmaVersion(void);
  145. #if defined (__cplusplus)
  146. }
  147. #endif
  148. #endif /* FILEIO_H_23981798732 */