PostgreSQL Source Code git master
Data Structures | Macros | Typedefs | Functions
compress_io.h File Reference
#include "pg_backup_archiver.h"
Include dependency graph for compress_io.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct   CompressorState
 
struct   CompressFileHandle
 

Macros

#define  DEFAULT_IO_BUFFER_SIZE   4096
 

Typedefs

typedef void(*  WriteFunc) (ArchiveHandle *AH, const char *buf, size_t len)
 
typedef size_t(*  ReadFunc) (ArchiveHandle *AH, char **buf, size_t *buflen)
 
typedef struct CompressorState  CompressorState
 
 

Functions

char *  supports_compression (const pg_compress_specification compression_spec)
 
 
 
 
CompressFileHandleInitDiscoverCompressFileHandle (const char *path, const char *mode)
 
 

Macro Definition Documentation

DEFAULT_IO_BUFFER_SIZE

#define DEFAULT_IO_BUFFER_SIZE   4096

Definition at line 27 of file compress_io.h.

Typedef Documentation

CompressFileHandle

Definition at line 98 of file compress_io.h.

CompressorState

Definition at line 49 of file compress_io.h.

ReadFunc

typedef size_t(* ReadFunc) (ArchiveHandle *AH, char **buf, size_t *buflen)

Definition at line 47 of file compress_io.h.

WriteFunc

typedef void(* WriteFunc) (ArchiveHandle *AH, const char *buf, size_t len)

Definition at line 34 of file compress_io.h.

Function Documentation

AllocateCompressor()

CompressorState * AllocateCompressor ( const pg_compress_specification  compression_spec,
ReadFunc  readF,
WriteFunc  writeF 
)

Definition at line 123 of file compress_io.c.

125{
126 CompressorState *cs;
127
129 cs->readF = readF;
130 cs->writeF = writeF;
131
132 if (compression_spec.algorithm == PG_COMPRESSION_NONE)
133 InitCompressorNone(cs, compression_spec);
134 else if (compression_spec.algorithm == PG_COMPRESSION_GZIP)
135 InitCompressorGzip(cs, compression_spec);
136 else if (compression_spec.algorithm == PG_COMPRESSION_LZ4)
137 InitCompressorLZ4(cs, compression_spec);
138 else if (compression_spec.algorithm == PG_COMPRESSION_ZSTD)
139 InitCompressorZstd(cs, compression_spec);
140
141 return cs;
142}
void InitCompressorGzip(CompressorState *cs, const pg_compress_specification compression_spec)
Definition: compress_gzip.c:425
void InitCompressorLZ4(CompressorState *cs, const pg_compress_specification compression_spec)
Definition: compress_lz4.c:797
void InitCompressorNone(CompressorState *cs, const pg_compress_specification compression_spec)
Definition: compress_none.c:66
void InitCompressorZstd(CompressorState *cs, const pg_compress_specification compression_spec)
Definition: compress_zstd.c:24
@ PG_COMPRESSION_GZIP
Definition: compression.h:24
@ PG_COMPRESSION_LZ4
Definition: compression.h:25
@ PG_COMPRESSION_NONE
Definition: compression.h:23
@ PG_COMPRESSION_ZSTD
Definition: compression.h:26
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
ReadFunc readF
Definition: compress_io.h:72
WriteFunc writeF
Definition: compress_io.h:77
pg_compress_algorithm algorithm
Definition: compression.h:34

References pg_compress_specification::algorithm, InitCompressorGzip(), InitCompressorLZ4(), InitCompressorNone(), InitCompressorZstd(), PG_COMPRESSION_GZIP, PG_COMPRESSION_LZ4, PG_COMPRESSION_NONE, PG_COMPRESSION_ZSTD, pg_malloc0(), CompressorState::readF, and CompressorState::writeF.

Referenced by _PrintData(), _StartData(), and _StartLO().

EndCompressFileHandle()

bool EndCompressFileHandle ( CompressFileHandleCFH )

Definition at line 289 of file compress_io.c.

290{
291 bool ret = false;
292
293 errno = 0;
294 if (CFH->private_data)
295 ret = CFH->close_func(CFH);
296
297 free_keep_errno(CFH);
298
299 return ret;
300}
static void free_keep_errno(void *p)
Definition: compress_io.c:178
void * private_data
Definition: compress_io.h:192
bool(* close_func)(CompressFileHandle *CFH)
Definition: compress_io.h:176

References CompressFileHandle::close_func, free_keep_errno(), and CompressFileHandle::private_data.

Referenced by _CloseArchive(), _EndData(), _EndLO(), _EndLOs(), _LoadLOs(), _PrintFileData(), CloseArchive(), InitArchiveFmt_Directory(), and RestoreOutput().

EndCompressor()

void EndCompressor ( ArchiveHandleAH,
CompressorStatecs 
)

Definition at line 148 of file compress_io.c.

149{
150 cs->end(AH, cs);
151 pg_free(cs);
152}
void pg_free(void *ptr)
Definition: fe_memutils.c:105
void(* end)(ArchiveHandle *AH, CompressorState *cs)
Definition: compress_io.h:67

References CompressorState::end, and pg_free().

Referenced by _EndData(), _EndLO(), and _PrintData().

InitCompressFileHandle()

CompressFileHandle * InitCompressFileHandle ( const pg_compress_specification  compression_spec )

Definition at line 194 of file compress_io.c.

195{
197
198 CFH = pg_malloc0(sizeof(CompressFileHandle));
199
200 if (compression_spec.algorithm == PG_COMPRESSION_NONE)
201 InitCompressFileHandleNone(CFH, compression_spec);
202 else if (compression_spec.algorithm == PG_COMPRESSION_GZIP)
203 InitCompressFileHandleGzip(CFH, compression_spec);
204 else if (compression_spec.algorithm == PG_COMPRESSION_LZ4)
205 InitCompressFileHandleLZ4(CFH, compression_spec);
206 else if (compression_spec.algorithm == PG_COMPRESSION_ZSTD)
207 InitCompressFileHandleZstd(CFH, compression_spec);
208
209 return CFH;
210}
void InitCompressFileHandleGzip(CompressFileHandle *CFH, const pg_compress_specification compression_spec)
Definition: compress_gzip.c:432
void InitCompressFileHandleLZ4(CompressFileHandle *CFH, const pg_compress_specification compression_spec)
Definition: compress_lz4.c:804
void InitCompressFileHandleNone(CompressFileHandle *CFH, const pg_compress_specification compression_spec)
Definition: compress_none.c:201
void InitCompressFileHandleZstd(CompressFileHandle *CFH, const pg_compress_specification compression_spec)
Definition: compress_zstd.c:30

References pg_compress_specification::algorithm, InitCompressFileHandleGzip(), InitCompressFileHandleLZ4(), InitCompressFileHandleNone(), InitCompressFileHandleZstd(), PG_COMPRESSION_GZIP, PG_COMPRESSION_LZ4, PG_COMPRESSION_NONE, PG_COMPRESSION_ZSTD, and pg_malloc0().

Referenced by _allocAH(), _CloseArchive(), _StartData(), _StartLO(), _StartLOs(), InitDiscoverCompressFileHandle(), and SetOutput().

InitDiscoverCompressFileHandle()

CompressFileHandle * InitDiscoverCompressFileHandle ( const char *  path,
const char *  mode 
)

Definition at line 240 of file compress_io.c.

241{
242 CompressFileHandle *CFH = NULL;
243 struct stat st;
244 char *fname;
245 pg_compress_specification compression_spec = {0};
246
247 compression_spec.algorithm = PG_COMPRESSION_NONE;
248
249 Assert(strcmp(mode, PG_BINARY_R) == 0);
250
251 fname = pg_strdup(path);
252
253 if (hasSuffix(fname, ".gz"))
254 compression_spec.algorithm = PG_COMPRESSION_GZIP;
255 else if (hasSuffix(fname, ".lz4"))
256 compression_spec.algorithm = PG_COMPRESSION_LZ4;
257 else if (hasSuffix(fname, ".zst"))
258 compression_spec.algorithm = PG_COMPRESSION_ZSTD;
259 else
260 {
261 if (stat(path, &st) == 0)
262 compression_spec.algorithm = PG_COMPRESSION_NONE;
263 else if (check_compressed_file(path, &fname, "gz"))
264 compression_spec.algorithm = PG_COMPRESSION_GZIP;
265 else if (check_compressed_file(path, &fname, "lz4"))
266 compression_spec.algorithm = PG_COMPRESSION_LZ4;
267 else if (check_compressed_file(path, &fname, "zst"))
268 compression_spec.algorithm = PG_COMPRESSION_ZSTD;
269 }
270
271 CFH = InitCompressFileHandle(compression_spec);
272 errno = 0;
273 if (!CFH->open_func(fname, -1, mode, CFH))
274 {
275 free_keep_errno(CFH);
276 CFH = NULL;
277 }
278 free_keep_errno(fname);
279
280 return CFH;
281}
#define PG_BINARY_R
Definition: c.h:1274
static int hasSuffix(const char *filename, const char *suffix)
Definition: compress_io.c:163
CompressFileHandle * InitCompressFileHandle(const pg_compress_specification compression_spec)
Definition: compress_io.c:194
static bool check_compressed_file(const char *path, char **fname, char *ext)
Definition: compress_io.c:219
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
Assert(PointerIsAligned(start, uint64))
static PgChecksumMode mode
Definition: pg_checksums.c:55
bool(* open_func)(const char *path, int fd, const char *mode, CompressFileHandle *CFH)
Definition: compress_io.h:111
Definition: win32_port.h:255
#define stat
Definition: win32_port.h:274

References pg_compress_specification::algorithm, Assert(), check_compressed_file(), free_keep_errno(), hasSuffix(), InitCompressFileHandle(), mode, CompressFileHandle::open_func, PG_BINARY_R, PG_COMPRESSION_GZIP, PG_COMPRESSION_LZ4, PG_COMPRESSION_NONE, PG_COMPRESSION_ZSTD, pg_strdup(), and stat.

Referenced by _LoadLOs(), _PrintFileData(), and InitArchiveFmt_Directory().

supports_compression()

char * supports_compression ( const pg_compress_specification  compression_spec )

Definition at line 87 of file compress_io.c.

88{
89 const pg_compress_algorithm algorithm = compression_spec.algorithm;
90 bool supported = false;
91
92 if (algorithm == PG_COMPRESSION_NONE)
93 supported = true;
94#ifdef HAVE_LIBZ
95 if (algorithm == PG_COMPRESSION_GZIP)
96 supported = true;
97#endif
98#ifdef USE_LZ4
99 if (algorithm == PG_COMPRESSION_LZ4)
100 supported = true;
101#endif
102#ifdef USE_ZSTD
103 if (algorithm == PG_COMPRESSION_ZSTD)
104 supported = true;
105#endif
106
107 if (!supported)
108 return psprintf(_("this build does not support compression with %s"),
109 get_compress_algorithm_name(algorithm));
110
111 return NULL;
112}
const char * get_compress_algorithm_name(pg_compress_algorithm algorithm)
Definition: compression.c:69
pg_compress_algorithm
Definition: compression.h:22
_
#define _(x)
Definition: elog.c:91
char * psprintf(const char *fmt,...)
Definition: psprintf.c:43

References _, pg_compress_specification::algorithm, get_compress_algorithm_name(), PG_COMPRESSION_GZIP, PG_COMPRESSION_LZ4, PG_COMPRESSION_NONE, PG_COMPRESSION_ZSTD, and psprintf().

Referenced by main(), ReadHead(), and RestoreArchive().

AltStyle によって変換されたページ (->オリジナル) /