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