2017-08-18 16:52:05 -07:00
|
|
|
/*
|
2023-02-09 07:37:37 -08:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2016-08-30 10:04:33 -07:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2017-08-18 16:52:05 -07:00
|
|
|
* This source code is licensed under both the BSD-style license (found in the
|
|
|
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
|
|
* in the COPYING file in the root directory of this source tree).
|
2017-09-08 00:09:23 -07:00
|
|
|
* You may select, at your option, one of the above-listed licenses.
|
2016-08-30 10:04:33 -07:00
|
|
|
*/
|
2015-01-31 10:52:59 +01:00
|
|
|
|
|
|
|
|
2016-09-15 17:02:06 +02:00
|
|
|
#ifndef FILEIO_H_23981798732
|
|
|
|
#define FILEIO_H_23981798732
|
2015-01-31 10:52:59 +01:00
|
|
|
|
2022-01-24 14:43:02 -08:00
|
|
|
#include "fileio_types.h"
|
2022-08-03 20:52:15 +02:00
|
|
|
#include "util.h" /* FileNamesTable */
|
|
|
|
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */
|
2020-05-01 16:20:40 -04:00
|
|
|
#include "../lib/zstd.h" /* ZSTD_* */
|
2016-12-13 13:24:59 +01:00
|
|
|
|
2015-10-22 15:31:46 +01:00
|
|
|
/* *************************************
|
2015-01-31 10:52:59 +01:00
|
|
|
* Special i/o constants
|
|
|
|
**************************************/
|
2016-12-02 15:18:57 -08:00
|
|
|
#define stdinmark "/*stdin*\\"
|
2016-11-04 11:37:27 +01:00
|
|
|
#define stdoutmark "/*stdout*\\"
|
2015-01-31 10:52:59 +01:00
|
|
|
#ifdef _WIN32
|
2019-10-17 16:39:47 -07:00
|
|
|
# define nulmark "NUL"
|
2015-01-31 10:52:59 +01:00
|
|
|
#else
|
|
|
|
# define nulmark "/dev/null"
|
|
|
|
#endif
|
2019-10-24 20:18:57 -04:00
|
|
|
|
2019-10-25 13:58:58 -04:00
|
|
|
/**
|
|
|
|
* We test whether the extension we found starts with 't', and if so, we append
|
2019-10-24 20:18:57 -04:00
|
|
|
* ".tar" to the end of the output name.
|
|
|
|
*/
|
2017-03-13 18:11:07 -07:00
|
|
|
#define LZMA_EXTENSION ".lzma"
|
|
|
|
#define XZ_EXTENSION ".xz"
|
2019-10-24 20:18:57 -04:00
|
|
|
#define TXZ_EXTENSION ".txz"
|
|
|
|
|
2017-03-13 18:11:07 -07:00
|
|
|
#define GZ_EXTENSION ".gz"
|
2019-10-24 20:18:57 -04:00
|
|
|
#define TGZ_EXTENSION ".tgz"
|
|
|
|
|
2017-03-13 18:11:07 -07:00
|
|
|
#define ZSTD_EXTENSION ".zst"
|
2019-10-24 20:18:57 -04:00
|
|
|
#define TZSTD_EXTENSION ".tzst"
|
2020-09-18 12:49:51 -04:00
|
|
|
#define ZSTD_ALT_EXTENSION ".zstd" /* allow decompression of .zstd files */
|
2019-10-24 20:18:57 -04:00
|
|
|
|
2017-04-24 16:48:25 -07:00
|
|
|
#define LZ4_EXTENSION ".lz4"
|
2019-10-24 20:18:57 -04:00
|
|
|
#define TLZ4_EXTENSION ".tlz4"
|
2015-01-31 10:52:59 +01:00
|
|
|
|
|
|
|
|
2017-02-08 15:17:55 +01:00
|
|
|
/*-*************************************
|
|
|
|
* Types
|
|
|
|
***************************************/
|
2019-01-22 17:31:13 -08:00
|
|
|
FIO_prefs_t* FIO_createPreferences(void);
|
|
|
|
void FIO_freePreferences(FIO_prefs_t* const prefs);
|
|
|
|
|
2020-09-03 09:26:30 -04:00
|
|
|
/* Mutable struct containing relevant context and state regarding (de)compression with respect to file I/O */
|
2020-08-28 11:01:04 -04:00
|
|
|
typedef struct FIO_ctx_s FIO_ctx_t;
|
|
|
|
|
|
|
|
FIO_ctx_t* FIO_createContext(void);
|
|
|
|
void FIO_freeContext(FIO_ctx_t* const fCtx);
|
|
|
|
|
2021-05-06 14:50:28 -04:00
|
|
|
|
2016-03-10 21:02:25 +01:00
|
|
|
/*-*************************************
|
2015-01-31 10:52:59 +01:00
|
|
|
* Parameters
|
2015-10-22 15:31:46 +01:00
|
|
|
***************************************/
|
2020-08-28 11:01:04 -04:00
|
|
|
/* FIO_prefs_t functions */
|
2019-01-22 17:31:13 -08:00
|
|
|
void FIO_setCompressionType(FIO_prefs_t* const prefs, FIO_compressionType_t compressionType);
|
|
|
|
void FIO_overwriteMode(FIO_prefs_t* const prefs);
|
fileio_types.h : avoid dependency on mem.h
fileio_types.h cannot be parsed by itself
because it relies on basic types defined in `lib/common/mem.h`.
As for #3231, it likely wasn't detected because `mem.h` was probably included before within target files.
But this is not proper.
A "easy" solution would be to add the missing include,
but each dependency should be considered "bad" by default,
and only allowed if it brings some tangible value.
In this case, since these types are only used to declare internal structure variables
which are effectively only flags,
I believe it's really not valuable to add a dependency on `mem.h` for this purpose
while the standard `int` type can do the same job.
I was expecting some compiler warnings following this change,
but it turns out we don't use `-Wconversion` by default on `zstd` source code,
so there is none.
Nevertheless, I enabled `-Wconversion` locally and proceeded to fix a few conversion warnings in the process.
Adding `-Wconversion` to the list of flags used for `zstd` is something I would be favorable over the long term,
but it cannot be done overnight,
because the nb of places where this warning is triggered is daunting.
Better progressively reduce the nb of triggered `-Wconversion` warnings before enabling this flag by default.
2022-08-03 21:39:35 +02:00
|
|
|
void FIO_setAdaptiveMode(FIO_prefs_t* const prefs, int adapt);
|
2019-01-22 17:31:13 -08:00
|
|
|
void FIO_setAdaptMin(FIO_prefs_t* const prefs, int minCLevel);
|
|
|
|
void FIO_setAdaptMax(FIO_prefs_t* const prefs, int maxCLevel);
|
2020-11-02 17:52:29 -08:00
|
|
|
void FIO_setUseRowMatchFinder(FIO_prefs_t* const prefs, int useRowMatchFinder);
|
2019-01-25 14:42:44 -08:00
|
|
|
void FIO_setBlockSize(FIO_prefs_t* const prefs, int blockSize);
|
|
|
|
void FIO_setChecksumFlag(FIO_prefs_t* const prefs, int checksumFlag);
|
|
|
|
void FIO_setDictIDFlag(FIO_prefs_t* const prefs, int dictIDFlag);
|
|
|
|
void FIO_setLdmBucketSizeLog(FIO_prefs_t* const prefs, int ldmBucketSizeLog);
|
2019-01-22 17:31:13 -08:00
|
|
|
void FIO_setLdmFlag(FIO_prefs_t* const prefs, unsigned ldmFlag);
|
2019-01-25 14:42:44 -08:00
|
|
|
void FIO_setLdmHashRateLog(FIO_prefs_t* const prefs, int ldmHashRateLog);
|
|
|
|
void FIO_setLdmHashLog(FIO_prefs_t* const prefs, int ldmHashLog);
|
|
|
|
void FIO_setLdmMinMatch(FIO_prefs_t* const prefs, int ldmMinMatch);
|
2019-01-22 17:31:13 -08:00
|
|
|
void FIO_setMemLimit(FIO_prefs_t* const prefs, unsigned memLimit);
|
2019-01-25 14:42:44 -08:00
|
|
|
void FIO_setNbWorkers(FIO_prefs_t* const prefs, int nbWorkers);
|
|
|
|
void FIO_setOverlapLog(FIO_prefs_t* const prefs, int overlapLog);
|
2023-02-09 07:37:37 -08:00
|
|
|
void FIO_setRemoveSrcFile(FIO_prefs_t* const prefs, int flag);
|
fileio_types.h : avoid dependency on mem.h
fileio_types.h cannot be parsed by itself
because it relies on basic types defined in `lib/common/mem.h`.
As for #3231, it likely wasn't detected because `mem.h` was probably included before within target files.
But this is not proper.
A "easy" solution would be to add the missing include,
but each dependency should be considered "bad" by default,
and only allowed if it brings some tangible value.
In this case, since these types are only used to declare internal structure variables
which are effectively only flags,
I believe it's really not valuable to add a dependency on `mem.h` for this purpose
while the standard `int` type can do the same job.
I was expecting some compiler warnings following this change,
but it turns out we don't use `-Wconversion` by default on `zstd` source code,
so there is none.
Nevertheless, I enabled `-Wconversion` locally and proceeded to fix a few conversion warnings in the process.
Adding `-Wconversion` to the list of flags used for `zstd` is something I would be favorable over the long term,
but it cannot be done overnight,
because the nb of places where this warning is triggered is daunting.
Better progressively reduce the nb of triggered `-Wconversion` warnings before enabling this flag by default.
2022-08-03 21:39:35 +02:00
|
|
|
void FIO_setSparseWrite(FIO_prefs_t* const prefs, int sparse); /**< 0: no sparse; 1: disable on stdout; 2: always enabled */
|
2019-01-25 14:42:44 -08:00
|
|
|
void FIO_setRsyncable(FIO_prefs_t* const prefs, int rsyncable);
|
2019-08-15 23:57:55 -07:00
|
|
|
void FIO_setStreamSrcSize(FIO_prefs_t* const prefs, size_t streamSrcSize);
|
2019-06-24 13:40:52 -07:00
|
|
|
void FIO_setTargetCBlockSize(FIO_prefs_t* const prefs, size_t targetCBlockSize);
|
2019-08-19 08:52:08 -07:00
|
|
|
void FIO_setSrcSizeHint(FIO_prefs_t* const prefs, size_t srcSizeHint);
|
2019-10-17 16:09:53 -07:00
|
|
|
void FIO_setTestMode(FIO_prefs_t* const prefs, int testMode);
|
2019-02-15 14:15:36 -08:00
|
|
|
void FIO_setLiteralCompressionMode(
|
|
|
|
FIO_prefs_t* const prefs,
|
2024-12-10 16:54:53 -08:00
|
|
|
ZSTD_ParamSwitch_e mode);
|
2015-01-31 10:52:59 +01:00
|
|
|
|
2021-05-06 14:50:28 -04:00
|
|
|
void FIO_setProgressSetting(FIO_progressSetting_e progressSetting);
|
2019-01-25 14:42:44 -08:00
|
|
|
void FIO_setNotificationLevel(int level);
|
2019-10-28 18:21:47 -07:00
|
|
|
void FIO_setExcludeCompressedFile(FIO_prefs_t* const prefs, int excludeCompressedFiles);
|
2021-05-04 16:24:46 -04:00
|
|
|
void FIO_setAllowBlockDevices(FIO_prefs_t* const prefs, int allowBlockDevices);
|
2020-01-10 14:25:24 -08:00
|
|
|
void FIO_setPatchFromMode(FIO_prefs_t* const prefs, int value);
|
2020-03-09 14:12:52 -05:00
|
|
|
void FIO_setContentSize(FIO_prefs_t* const prefs, int value);
|
2021-11-10 17:25:27 -08:00
|
|
|
void FIO_displayCompressionParameters(const FIO_prefs_t* prefs);
|
fileio_types.h : avoid dependency on mem.h
fileio_types.h cannot be parsed by itself
because it relies on basic types defined in `lib/common/mem.h`.
As for #3231, it likely wasn't detected because `mem.h` was probably included before within target files.
But this is not proper.
A "easy" solution would be to add the missing include,
but each dependency should be considered "bad" by default,
and only allowed if it brings some tangible value.
In this case, since these types are only used to declare internal structure variables
which are effectively only flags,
I believe it's really not valuable to add a dependency on `mem.h` for this purpose
while the standard `int` type can do the same job.
I was expecting some compiler warnings following this change,
but it turns out we don't use `-Wconversion` by default on `zstd` source code,
so there is none.
Nevertheless, I enabled `-Wconversion` locally and proceeded to fix a few conversion warnings in the process.
Adding `-Wconversion` to the list of flags used for `zstd` is something I would be favorable over the long term,
but it cannot be done overnight,
because the nb of places where this warning is triggered is daunting.
Better progressively reduce the nb of triggered `-Wconversion` warnings before enabling this flag by default.
2022-08-03 21:39:35 +02:00
|
|
|
void FIO_setAsyncIOFlag(FIO_prefs_t* const prefs, int value);
|
2022-08-04 17:15:59 -07:00
|
|
|
void FIO_setPassThroughFlag(FIO_prefs_t* const prefs, int value);
|
2024-12-10 16:54:53 -08:00
|
|
|
void FIO_setMMapDict(FIO_prefs_t* const prefs, ZSTD_ParamSwitch_e value);
|
2020-08-28 11:01:04 -04:00
|
|
|
|
|
|
|
/* FIO_ctx_t functions */
|
2020-09-01 12:52:18 -04:00
|
|
|
void FIO_setNbFilesTotal(FIO_ctx_t* const fCtx, int value);
|
2020-10-07 13:44:25 -04:00
|
|
|
void FIO_setHasStdoutOutput(FIO_ctx_t* const fCtx, int value);
|
2020-09-24 15:55:30 -04:00
|
|
|
void FIO_determineHasStdinInput(FIO_ctx_t* const fCtx, const FileNamesTable* const filenames);
|
2015-01-31 10:52:59 +01:00
|
|
|
|
2016-03-10 21:02:25 +01:00
|
|
|
/*-*************************************
|
2015-12-17 02:23:58 +01:00
|
|
|
* Single File functions
|
2015-10-22 15:31:46 +01:00
|
|
|
***************************************/
|
2016-02-12 03:50:05 +01:00
|
|
|
/** FIO_compressFilename() :
|
2019-10-17 16:09:53 -07:00
|
|
|
* @return : 0 == ok; 1 == pb with src file. */
|
2020-09-07 13:13:05 -04:00
|
|
|
int FIO_compressFilename (FIO_ctx_t* const fCtx, FIO_prefs_t* const prefs,
|
2019-09-05 16:03:35 -07:00
|
|
|
const char* outfilename, const char* infilename,
|
|
|
|
const char* dictFileName, int compressionLevel,
|
|
|
|
ZSTD_compressionParameters comprParams);
|
2015-01-31 10:52:59 +01:00
|
|
|
|
2016-02-12 03:50:05 +01:00
|
|
|
/** FIO_decompressFilename() :
|
2019-10-17 16:09:53 -07:00
|
|
|
* @return : 0 == ok; 1 == pb with src file. */
|
2020-09-07 13:13:05 -04:00
|
|
|
int FIO_decompressFilename (FIO_ctx_t* const fCtx, FIO_prefs_t* const prefs,
|
2019-01-22 17:31:13 -08:00
|
|
|
const char* outfilename, const char* infilename, const char* dictFileName);
|
2015-01-31 10:52:59 +01:00
|
|
|
|
2017-06-20 12:43:10 -07:00
|
|
|
int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int displayLevel);
|
2015-01-31 10:52:59 +01:00
|
|
|
|
2018-09-24 18:16:08 -07:00
|
|
|
|
2016-03-10 21:02:25 +01:00
|
|
|
/*-*************************************
|
2015-12-17 02:23:58 +01:00
|
|
|
* Multiple File functions
|
|
|
|
***************************************/
|
2016-02-12 03:50:05 +01:00
|
|
|
/** FIO_compressMultipleFilenames() :
|
2019-10-17 16:09:53 -07:00
|
|
|
* @return : nb of missing files */
|
2020-09-07 13:13:05 -04:00
|
|
|
int FIO_compressMultipleFilenames(FIO_ctx_t* const fCtx,
|
|
|
|
FIO_prefs_t* const prefs,
|
2020-08-26 11:35:07 -04:00
|
|
|
const char** inFileNamesTable,
|
2020-06-19 19:35:51 -07:00
|
|
|
const char* outMirroredDirName,
|
2019-10-17 15:32:03 -07:00
|
|
|
const char* outDirName,
|
2017-12-12 18:32:50 -08:00
|
|
|
const char* outFileName, const char* suffix,
|
2016-12-13 13:24:59 +01:00
|
|
|
const char* dictFileName, int compressionLevel,
|
2018-08-13 13:02:03 -07:00
|
|
|
ZSTD_compressionParameters comprParams);
|
2016-02-12 03:50:05 +01:00
|
|
|
|
|
|
|
/** FIO_decompressMultipleFilenames() :
|
2019-10-17 16:09:53 -07:00
|
|
|
* @return : nb of missing or skipped files */
|
2020-09-07 13:13:05 -04:00
|
|
|
int FIO_decompressMultipleFilenames(FIO_ctx_t* const fCtx,
|
|
|
|
FIO_prefs_t* const prefs,
|
2020-08-26 11:35:07 -04:00
|
|
|
const char** srcNamesTable,
|
2020-06-19 19:35:51 -07:00
|
|
|
const char* outMirroredDirName,
|
2019-10-03 13:53:04 -04:00
|
|
|
const char* outDirName,
|
2017-12-12 18:32:50 -08:00
|
|
|
const char* outFileName,
|
2015-12-17 20:30:14 +01:00
|
|
|
const char* dictFileName);
|
2015-12-17 02:23:58 +01:00
|
|
|
|
2019-10-03 13:53:04 -04:00
|
|
|
/* FIO_checkFilenameCollisions() :
|
2019-10-17 16:09:53 -07:00
|
|
|
* Checks for and warns if there are any files that would have the same output path
|
2019-10-03 13:53:04 -04:00
|
|
|
*/
|
|
|
|
int FIO_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles);
|
2015-01-31 10:52:59 +01:00
|
|
|
|
2019-10-17 16:09:53 -07:00
|
|
|
|
2015-01-31 10:52:59 +01:00
|
|
|
|
2018-09-24 18:16:08 -07:00
|
|
|
/*-*************************************
|
|
|
|
* Advanced stuff (should actually be hosted elsewhere)
|
|
|
|
***************************************/
|
|
|
|
|
2018-09-11 11:39:49 -07:00
|
|
|
/* custom crash signal handler */
|
|
|
|
void FIO_addAbortHandler(void);
|
|
|
|
|
2022-01-26 17:55:26 -08:00
|
|
|
char const* FIO_zlibVersion(void);
|
|
|
|
char const* FIO_lz4Version(void);
|
|
|
|
char const* FIO_lzmaVersion(void);
|
2018-09-24 18:16:08 -07:00
|
|
|
|
2016-09-15 17:02:06 +02:00
|
|
|
#endif /* FILEIO_H_23981798732 */
|