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