blob: 224d89525dc2b39bf95b63bb30df84a1a0ce31f5 [file] [log] [blame]
Yann Collet32fb4072017-08-18 16:52:05 -07001/*
Elliott Hughes44aba642023-09-12 20:18:59 +00002 * Copyright (c) Meta Platforms, Inc. and affiliates.
Yann Collet4ded9e52016-08-30 10:04:33 -07003 * All rights reserved.
4 *
Yann Collet32fb4072017-08-18 16:52:05 -07005 * 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).
Yann Collet3128e032017-09-08 00:09:23 -07008 * You may select, at your option, one of the above-listed licenses.
Yann Collet4ded9e52016-08-30 10:04:33 -07009 */
Yann Collet439eb772015-01-31 10:52:59 +010010
Yann Collet439eb772015-01-31 10:52:59 +010011
Yann Colleta6bdf552016-09-15 17:02:06 +020012#ifndef FILEIO_H_23981798732
13#define FILEIO_H_23981798732
Yann Collet439eb772015-01-31 10:52:59 +010014
Elliott Hughes44aba642023-09-12 20:18:59 +000015#include "fileio_types.h"
16#include "util.h" /* FileNamesTable */
Yann Colleta9253622022-08-03 20:52:15 +020017#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */
W. Felix Handte7dcca6b2020-05-01 16:20:40 -040018#include "../lib/zstd.h" /* ZSTD_* */
Przemyslaw Skibinski8349d672016-12-13 13:24:59 +010019
Yann Collet439eb772015-01-31 10:52:59 +010020#if defined (__cplusplus)
21extern "C" {
22#endif
23
Yann Collet8dafb1a2017-01-25 17:01:13 -080024
Yann Colletf3eca252015-10-22 15:31:46 +010025/* *************************************
Yann Collet439eb772015-01-31 10:52:59 +010026* Special i/o constants
27**************************************/
Yann Collet743b33f2016-12-02 15:18:57 -080028#define stdinmark "/*stdin*\\"
Przemyslaw Skibinskid0815582016-11-04 11:37:27 +010029#define stdoutmark "/*stdout*\\"
Yann Collet439eb772015-01-31 10:52:59 +010030#ifdef _WIN32
Yann Collet0a24d4e2019-10-17 16:39:47 -070031# define nulmark "NUL"
Yann Collet439eb772015-01-31 10:52:59 +010032#else
33# define nulmark "/dev/null"
34#endif
W. Felix Handte91c3f542019-10-24 20:18:57 -040035
W. Felix Handte4eccc822019-10-25 13:58:58 -040036/**
37 * We test whether the extension we found starts with 't', and if so, we append
W. Felix Handte91c3f542019-10-24 20:18:57 -040038 * ".tar" to the end of the output name.
39 */
Nick Terrellaa8bcf32017-03-13 18:11:07 -070040#define LZMA_EXTENSION ".lzma"
41#define XZ_EXTENSION ".xz"
W. Felix Handte91c3f542019-10-24 20:18:57 -040042#define TXZ_EXTENSION ".txz"
43
Nick Terrellaa8bcf32017-03-13 18:11:07 -070044#define GZ_EXTENSION ".gz"
W. Felix Handte91c3f542019-10-24 20:18:57 -040045#define TGZ_EXTENSION ".tgz"
46
Nick Terrellaa8bcf32017-03-13 18:11:07 -070047#define ZSTD_EXTENSION ".zst"
W. Felix Handte91c3f542019-10-24 20:18:57 -040048#define TZSTD_EXTENSION ".tzst"
senhuang426b6cc802020-09-18 12:49:51 -040049#define ZSTD_ALT_EXTENSION ".zstd" /* allow decompression of .zstd files */
W. Felix Handte91c3f542019-10-24 20:18:57 -040050
Sean Purcell4de86322017-04-24 16:48:25 -070051#define LZ4_EXTENSION ".lz4"
W. Felix Handte91c3f542019-10-24 20:18:57 -040052#define TLZ4_EXTENSION ".tlz4"
Yann Collet439eb772015-01-31 10:52:59 +010053
54
Yann Collet8a1d1a62016-03-10 21:02:25 +010055/*-*************************************
Przemyslaw Skibinskicfd4dc22017-02-08 15:17:55 +010056* Types
57***************************************/
Karl Ostmo5e220bf2019-01-22 17:31:13 -080058FIO_prefs_t* FIO_createPreferences(void);
59void FIO_freePreferences(FIO_prefs_t* const prefs);
60
senhuang42a480b022020-09-03 09:26:30 -040061/* Mutable struct containing relevant context and state regarding (de)compression with respect to file I/O */
senhuang42d54566f2020-08-28 11:01:04 -040062typedef struct FIO_ctx_s FIO_ctx_t;
63
64FIO_ctx_t* FIO_createContext(void);
65void FIO_freeContext(FIO_ctx_t* const fCtx);
66
sen6030cdf2021-05-06 14:50:28 -040067
Przemyslaw Skibinskicfd4dc22017-02-08 15:17:55 +010068/*-*************************************
Yann Collet439eb772015-01-31 10:52:59 +010069* Parameters
Yann Colletf3eca252015-10-22 15:31:46 +010070***************************************/
senhuang42d54566f2020-08-28 11:01:04 -040071/* FIO_prefs_t functions */
Karl Ostmo5e220bf2019-01-22 17:31:13 -080072void FIO_setCompressionType(FIO_prefs_t* const prefs, FIO_compressionType_t compressionType);
73void FIO_overwriteMode(FIO_prefs_t* const prefs);
Elliott Hughes44aba642023-09-12 20:18:59 +000074void FIO_setAdaptiveMode(FIO_prefs_t* const prefs, int adapt);
Karl Ostmo5e220bf2019-01-22 17:31:13 -080075void FIO_setAdaptMin(FIO_prefs_t* const prefs, int minCLevel);
76void FIO_setAdaptMax(FIO_prefs_t* const prefs, int maxCLevel);
Nick Terrell46944232020-11-02 17:52:29 -080077void FIO_setUseRowMatchFinder(FIO_prefs_t* const prefs, int useRowMatchFinder);
Yann Collet07e04782019-01-25 14:42:44 -080078void FIO_setBlockSize(FIO_prefs_t* const prefs, int blockSize);
79void FIO_setChecksumFlag(FIO_prefs_t* const prefs, int checksumFlag);
80void FIO_setDictIDFlag(FIO_prefs_t* const prefs, int dictIDFlag);
81void FIO_setLdmBucketSizeLog(FIO_prefs_t* const prefs, int ldmBucketSizeLog);
Karl Ostmo5e220bf2019-01-22 17:31:13 -080082void FIO_setLdmFlag(FIO_prefs_t* const prefs, unsigned ldmFlag);
Yann Collet07e04782019-01-25 14:42:44 -080083void FIO_setLdmHashRateLog(FIO_prefs_t* const prefs, int ldmHashRateLog);
84void FIO_setLdmHashLog(FIO_prefs_t* const prefs, int ldmHashLog);
85void FIO_setLdmMinMatch(FIO_prefs_t* const prefs, int ldmMinMatch);
Karl Ostmo5e220bf2019-01-22 17:31:13 -080086void FIO_setMemLimit(FIO_prefs_t* const prefs, unsigned memLimit);
Yann Collet07e04782019-01-25 14:42:44 -080087void FIO_setNbWorkers(FIO_prefs_t* const prefs, int nbWorkers);
88void FIO_setOverlapLog(FIO_prefs_t* const prefs, int overlapLog);
Elliott Hughes44aba642023-09-12 20:18:59 +000089void FIO_setRemoveSrcFile(FIO_prefs_t* const prefs, int flag);
90void FIO_setSparseWrite(FIO_prefs_t* const prefs, int sparse); /**< 0: no sparse; 1: disable on stdout; 2: always enabled */
Yann Collet07e04782019-01-25 14:42:44 -080091void FIO_setRsyncable(FIO_prefs_t* const prefs, int rsyncable);
Nick Magerkoaf0c9502019-08-15 23:57:55 -070092void FIO_setStreamSrcSize(FIO_prefs_t* const prefs, size_t streamSrcSize);
Ephraim Park90077012019-06-24 13:40:52 -070093void FIO_setTargetCBlockSize(FIO_prefs_t* const prefs, size_t targetCBlockSize);
Nick Magerkodffbac52019-08-19 08:52:08 -070094void FIO_setSrcSizeHint(FIO_prefs_t* const prefs, size_t srcSizeHint);
Yann Collet0ee36092019-10-17 16:09:53 -070095void FIO_setTestMode(FIO_prefs_t* const prefs, int testMode);
Nick Terrell0c53c5a2019-02-15 14:15:36 -080096void FIO_setLiteralCompressionMode(
97 FIO_prefs_t* const prefs,
senhuang42b5c35d72021-09-20 09:04:07 -040098 ZSTD_paramSwitch_e mode);
Yann Collet439eb772015-01-31 10:52:59 +010099
sen6030cdf2021-05-06 14:50:28 -0400100void FIO_setProgressSetting(FIO_progressSetting_e progressSetting);
Yann Collet07e04782019-01-25 14:42:44 -0800101void FIO_setNotificationLevel(int level);
Shashank Tavildar0f2bff22019-10-28 18:21:47 -0700102void FIO_setExcludeCompressedFile(FIO_prefs_t* const prefs, int excludeCompressedFiles);
W. Felix Handte33f3e292021-05-04 16:24:46 -0400103void FIO_setAllowBlockDevices(FIO_prefs_t* const prefs, int allowBlockDevices);
Bimba Shresthaf25a6e92020-01-10 14:25:24 -0800104void FIO_setPatchFromMode(FIO_prefs_t* const prefs, int value);
Bimba Shrestha6d8e7612020-03-09 14:12:52 -0500105void FIO_setContentSize(FIO_prefs_t* const prefs, int value);
Kevin Svetlitskidf9b7752021-11-10 17:25:27 -0800106void FIO_displayCompressionParameters(const FIO_prefs_t* prefs);
Elliott Hughes44aba642023-09-12 20:18:59 +0000107void FIO_setAsyncIOFlag(FIO_prefs_t* const prefs, int value);
108void FIO_setPassThroughFlag(FIO_prefs_t* const prefs, int value);
109void FIO_setMMapDict(FIO_prefs_t* const prefs, ZSTD_paramSwitch_e value);
senhuang42d54566f2020-08-28 11:01:04 -0400110
111/* FIO_ctx_t functions */
senhuang423a7d6252020-09-01 12:52:18 -0400112void FIO_setNbFilesTotal(FIO_ctx_t* const fCtx, int value);
senhuang4293cd9d82020-10-07 13:44:25 -0400113void FIO_setHasStdoutOutput(FIO_ctx_t* const fCtx, int value);
senhuang42432186c2020-09-24 15:55:30 -0400114void FIO_determineHasStdinInput(FIO_ctx_t* const fCtx, const FileNamesTable* const filenames);
Yann Collet439eb772015-01-31 10:52:59 +0100115
Yann Collet8a1d1a62016-03-10 21:02:25 +0100116/*-*************************************
Yann Collet4f137032015-12-17 02:23:58 +0100117* Single File functions
Yann Colletf3eca252015-10-22 15:31:46 +0100118***************************************/
Yann Collet883a67e2016-02-12 03:50:05 +0100119/** FIO_compressFilename() :
Yann Collet0ee36092019-10-17 16:09:53 -0700120 * @return : 0 == ok; 1 == pb with src file. */
senhuang4251234962020-09-07 13:13:05 -0400121int FIO_compressFilename (FIO_ctx_t* const fCtx, FIO_prefs_t* const prefs,
Sen Huang7f98b462019-09-05 16:03:35 -0700122 const char* outfilename, const char* infilename,
123 const char* dictFileName, int compressionLevel,
124 ZSTD_compressionParameters comprParams);
Yann Collet439eb772015-01-31 10:52:59 +0100125
Yann Collet883a67e2016-02-12 03:50:05 +0100126/** FIO_decompressFilename() :
Yann Collet0ee36092019-10-17 16:09:53 -0700127 * @return : 0 == ok; 1 == pb with src file. */
senhuang4251234962020-09-07 13:13:05 -0400128int FIO_decompressFilename (FIO_ctx_t* const fCtx, FIO_prefs_t* const prefs,
Karl Ostmo5e220bf2019-01-22 17:31:13 -0800129 const char* outfilename, const char* infilename, const char* dictFileName);
Yann Collet439eb772015-01-31 10:52:59 +0100130
Paul Cruzbda57752017-06-20 12:43:10 -0700131int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int displayLevel);
Yann Collet439eb772015-01-31 10:52:59 +0100132
Yann Collet6c51bf42018-09-24 18:16:08 -0700133
Yann Collet8a1d1a62016-03-10 21:02:25 +0100134/*-*************************************
Yann Collet4f137032015-12-17 02:23:58 +0100135* Multiple File functions
136***************************************/
Yann Collet883a67e2016-02-12 03:50:05 +0100137/** FIO_compressMultipleFilenames() :
Yann Collet0ee36092019-10-17 16:09:53 -0700138 * @return : nb of missing files */
senhuang4251234962020-09-07 13:13:05 -0400139int FIO_compressMultipleFilenames(FIO_ctx_t* const fCtx,
140 FIO_prefs_t* const prefs,
senhuang42b6abbc32020-08-26 11:35:07 -0400141 const char** inFileNamesTable,
Xin Xie9a8ccd42020-06-19 19:35:51 -0700142 const char* outMirroredDirName,
Yann Collet17951332019-10-17 15:32:03 -0700143 const char* outDirName,
Nick Terrell4680e852017-12-12 18:32:50 -0800144 const char* outFileName, const char* suffix,
Przemyslaw Skibinski8349d672016-12-13 13:24:59 +0100145 const char* dictFileName, int compressionLevel,
Yann Collet33f77092018-08-13 13:02:03 -0700146 ZSTD_compressionParameters comprParams);
Yann Collet883a67e2016-02-12 03:50:05 +0100147
148/** FIO_decompressMultipleFilenames() :
Yann Collet0ee36092019-10-17 16:09:53 -0700149 * @return : nb of missing or skipped files */
senhuang4251234962020-09-07 13:13:05 -0400150int FIO_decompressMultipleFilenames(FIO_ctx_t* const fCtx,
151 FIO_prefs_t* const prefs,
senhuang42b6abbc32020-08-26 11:35:07 -0400152 const char** srcNamesTable,
Xin Xie9a8ccd42020-06-19 19:35:51 -0700153 const char* outMirroredDirName,
Sen Huang64bc4412019-10-03 13:53:04 -0400154 const char* outDirName,
Nick Terrell4680e852017-12-12 18:32:50 -0800155 const char* outFileName,
Yann Colletdeb078b2015-12-17 20:30:14 +0100156 const char* dictFileName);
Yann Collet4f137032015-12-17 02:23:58 +0100157
Sen Huang64bc4412019-10-03 13:53:04 -0400158/* FIO_checkFilenameCollisions() :
Yann Collet0ee36092019-10-17 16:09:53 -0700159 * Checks for and warns if there are any files that would have the same output path
Sen Huang64bc4412019-10-03 13:53:04 -0400160 */
161int FIO_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles);
Yann Collet439eb772015-01-31 10:52:59 +0100162
Yann Collet0ee36092019-10-17 16:09:53 -0700163
Yann Collet439eb772015-01-31 10:52:59 +0100164
Yann Collet6c51bf42018-09-24 18:16:08 -0700165/*-*************************************
166* Advanced stuff (should actually be hosted elsewhere)
167***************************************/
168
Casey McGintyd4337b62018-09-11 11:39:49 -0700169/* custom crash signal handler */
170void FIO_addAbortHandler(void);
171
Elliott Hughes44aba642023-09-12 20:18:59 +0000172char const* FIO_zlibVersion(void);
173char const* FIO_lz4Version(void);
174char const* FIO_lzmaVersion(void);
Yann Collet6c51bf42018-09-24 18:16:08 -0700175
176
Yann Collet439eb772015-01-31 10:52:59 +0100177#if defined (__cplusplus)
178}
Yann Colletf3eca252015-10-22 15:31:46 +0100179#endif
Yann Colleta6bdf552016-09-15 17:02:06 +0200180
181#endif /* FILEIO_H_23981798732 */