2017-08-18 16:52:05 -07:00
|
|
|
/*
|
2021-03-29 14:23:36 -07:00
|
|
|
* Copyright (c) Yann Collet, Facebook, Inc.
|
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 01:52:59 -08:00
|
|
|
|
|
|
|
|
2016-09-15 08:02:06 -07:00
|
|
|
#ifndef FILEIO_H_23981798732
|
|
|
|
#define FILEIO_H_23981798732
|
2015-01-31 01:52:59 -08:00
|
|
|
|
2016-12-13 04:24:59 -08:00
|
|
|
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */
|
2020-05-01 13:20:40 -07:00
|
|
|
#include "../lib/zstd.h" /* ZSTD_* */
|
2016-12-13 04:24:59 -08:00
|
|
|
|
2015-01-31 01:52:59 -08:00
|
|
|
#if defined (__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-01-25 17:01:13 -08:00
|
|
|
|
2015-10-22 07:31:46 -07:00
|
|
|
/* *************************************
|
2015-01-31 01:52:59 -08:00
|
|
|
* Special i/o constants
|
|
|
|
**************************************/
|
2016-12-02 15:18:57 -08:00
|
|
|
#define stdinmark "/*stdin*\\"
|
2016-11-04 03:37:27 -07:00
|
|
|
#define stdoutmark "/*stdout*\\"
|
2015-01-31 01:52:59 -08:00
|
|
|
#ifdef _WIN32
|
2019-10-17 16:39:47 -07:00
|
|
|
# define nulmark "NUL"
|
2015-01-31 01:52:59 -08:00
|
|
|
#else
|
|
|
|
# define nulmark "/dev/null"
|
|
|
|
#endif
|
2019-10-24 17:18:57 -07:00
|
|
|
|
2019-10-25 10:58:58 -07:00
|
|
|
/**
|
|
|
|
* We test whether the extension we found starts with 't', and if so, we append
|
2019-10-24 17:18:57 -07: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 17:18:57 -07:00
|
|
|
#define TXZ_EXTENSION ".txz"
|
|
|
|
|
2017-03-13 18:11:07 -07:00
|
|
|
#define GZ_EXTENSION ".gz"
|
2019-10-24 17:18:57 -07:00
|
|
|
#define TGZ_EXTENSION ".tgz"
|
|
|
|
|
2017-03-13 18:11:07 -07:00
|
|
|
#define ZSTD_EXTENSION ".zst"
|
2019-10-24 17:18:57 -07:00
|
|
|
#define TZSTD_EXTENSION ".tzst"
|
2020-09-18 09:49:51 -07:00
|
|
|
#define ZSTD_ALT_EXTENSION ".zstd" /* allow decompression of .zstd files */
|
2019-10-24 17:18:57 -07:00
|
|
|
|
2017-04-24 16:48:25 -07:00
|
|
|
#define LZ4_EXTENSION ".lz4"
|
2019-10-24 17:18:57 -07:00
|
|
|
#define TLZ4_EXTENSION ".tlz4"
|
2015-01-31 01:52:59 -08:00
|
|
|
|
|
|
|
|
2017-02-08 06:17:55 -08:00
|
|
|
/*-*************************************
|
|
|
|
* Types
|
|
|
|
***************************************/
|
2017-04-24 16:48:25 -07:00
|
|
|
typedef enum { FIO_zstdCompression, FIO_gzipCompression, FIO_xzCompression, FIO_lzmaCompression, FIO_lz4Compression } FIO_compressionType_t;
|
2017-02-08 06:17:55 -08:00
|
|
|
|
2019-01-22 17:31:13 -08:00
|
|
|
typedef struct FIO_prefs_s FIO_prefs_t;
|
|
|
|
|
|
|
|
FIO_prefs_t* FIO_createPreferences(void);
|
|
|
|
void FIO_freePreferences(FIO_prefs_t* const prefs);
|
|
|
|
|
2020-09-03 06:26:30 -07:00
|
|
|
/* Mutable struct containing relevant context and state regarding (de)compression with respect to file I/O */
|
2020-08-28 08:01:04 -07:00
|
|
|
typedef struct FIO_ctx_s FIO_ctx_t;
|
|
|
|
|
|
|
|
FIO_ctx_t* FIO_createContext(void);
|
|
|
|
void FIO_freeContext(FIO_ctx_t* const fCtx);
|
|
|
|
|
2019-01-22 17:31:13 -08:00
|
|
|
typedef struct FIO_display_prefs_s FIO_display_prefs_t;
|
2017-02-08 06:17:55 -08:00
|
|
|
|
2021-05-06 11:50:28 -07:00
|
|
|
typedef enum { FIO_ps_auto, FIO_ps_never, FIO_ps_always } FIO_progressSetting_e;
|
|
|
|
|
2016-03-10 12:02:25 -08:00
|
|
|
/*-*************************************
|
2015-01-31 01:52:59 -08:00
|
|
|
* Parameters
|
2015-10-22 07:31:46 -07:00
|
|
|
***************************************/
|
2020-08-28 08:01:04 -07: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);
|
|
|
|
void FIO_setAdaptiveMode(FIO_prefs_t* const prefs, unsigned adapt);
|
|
|
|
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);
|
2019-01-22 17:31:13 -08:00
|
|
|
void FIO_setRemoveSrcFile(FIO_prefs_t* const prefs, unsigned flag);
|
|
|
|
void FIO_setSparseWrite(FIO_prefs_t* const prefs, unsigned 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,
|
|
|
|
ZSTD_literalCompressionMode_e mode);
|
2015-01-31 01:52:59 -08:00
|
|
|
|
2021-05-06 11:50:28 -07: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 13:24:46 -07: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 12:12:52 -07:00
|
|
|
void FIO_setContentSize(FIO_prefs_t* const prefs, int value);
|
2020-08-28 08:01:04 -07:00
|
|
|
|
|
|
|
/* FIO_ctx_t functions */
|
2020-09-01 09:52:18 -07:00
|
|
|
void FIO_setNbFilesTotal(FIO_ctx_t* const fCtx, int value);
|
2020-10-07 10:44:25 -07:00
|
|
|
void FIO_setHasStdoutOutput(FIO_ctx_t* const fCtx, int value);
|
2020-09-24 12:55:30 -07:00
|
|
|
void FIO_determineHasStdinInput(FIO_ctx_t* const fCtx, const FileNamesTable* const filenames);
|
2015-01-31 01:52:59 -08:00
|
|
|
|
2016-03-10 12:02:25 -08:00
|
|
|
/*-*************************************
|
2015-12-16 17:23:58 -08:00
|
|
|
* Single File functions
|
2015-10-22 07:31:46 -07:00
|
|
|
***************************************/
|
2016-02-11 18:50:05 -08:00
|
|
|
/** FIO_compressFilename() :
|
2019-10-17 16:09:53 -07:00
|
|
|
* @return : 0 == ok; 1 == pb with src file. */
|
2020-09-07 10:13:05 -07: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 01:52:59 -08:00
|
|
|
|
2016-02-11 18:50:05 -08:00
|
|
|
/** FIO_decompressFilename() :
|
2019-10-17 16:09:53 -07:00
|
|
|
* @return : 0 == ok; 1 == pb with src file. */
|
2020-09-07 10:13:05 -07: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 01:52:59 -08:00
|
|
|
|
2017-06-20 12:43:10 -07:00
|
|
|
int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int displayLevel);
|
2015-01-31 01:52:59 -08:00
|
|
|
|
2018-09-24 18:16:08 -07:00
|
|
|
|
2016-03-10 12:02:25 -08:00
|
|
|
/*-*************************************
|
2015-12-16 17:23:58 -08:00
|
|
|
* Multiple File functions
|
|
|
|
***************************************/
|
2016-02-11 18:50:05 -08:00
|
|
|
/** FIO_compressMultipleFilenames() :
|
2019-10-17 16:09:53 -07:00
|
|
|
* @return : nb of missing files */
|
2020-09-07 10:13:05 -07:00
|
|
|
int FIO_compressMultipleFilenames(FIO_ctx_t* const fCtx,
|
|
|
|
FIO_prefs_t* const prefs,
|
2020-08-26 08:35:07 -07: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 04:24:59 -08:00
|
|
|
const char* dictFileName, int compressionLevel,
|
2018-08-13 13:02:03 -07:00
|
|
|
ZSTD_compressionParameters comprParams);
|
2016-02-11 18:50:05 -08:00
|
|
|
|
|
|
|
/** FIO_decompressMultipleFilenames() :
|
2019-10-17 16:09:53 -07:00
|
|
|
* @return : nb of missing or skipped files */
|
2020-09-07 10:13:05 -07:00
|
|
|
int FIO_decompressMultipleFilenames(FIO_ctx_t* const fCtx,
|
|
|
|
FIO_prefs_t* const prefs,
|
2020-08-26 08:35:07 -07:00
|
|
|
const char** srcNamesTable,
|
2020-06-19 19:35:51 -07:00
|
|
|
const char* outMirroredDirName,
|
2019-10-03 10:53:04 -07:00
|
|
|
const char* outDirName,
|
2017-12-12 18:32:50 -08:00
|
|
|
const char* outFileName,
|
2015-12-17 11:30:14 -08:00
|
|
|
const char* dictFileName);
|
2015-12-16 17:23:58 -08:00
|
|
|
|
2019-10-03 10:53:04 -07: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 10:53:04 -07:00
|
|
|
*/
|
|
|
|
int FIO_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles);
|
2015-01-31 01:52:59 -08:00
|
|
|
|
2019-10-17 16:09:53 -07:00
|
|
|
|
2015-01-31 01:52:59 -08: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);
|
|
|
|
|
2018-09-24 18:16:08 -07:00
|
|
|
|
|
|
|
|
2015-01-31 01:52:59 -08:00
|
|
|
#if defined (__cplusplus)
|
|
|
|
}
|
2015-10-22 07:31:46 -07:00
|
|
|
#endif
|
2016-09-15 08:02:06 -07:00
|
|
|
|
|
|
|
#endif /* FILEIO_H_23981798732 */
|