PostgreSQL Source Code  git master
pgtar.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pgtar.h
4  * Functions for manipulating tarfile datastructures (src/port/tar.c)
5  *
6  *
7  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/pgtar.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef PG_TAR_H
15 #define PG_TAR_H
16 
17 #define TAR_BLOCK_SIZE 512
18 
20 {
21  TAR_OK = 0,
24 };
25 
26 /*
27  * Offsets of fields within a 512-byte tar header.
28  *
29  * "tar number" values should be generated using print_tar_number() and can be
30  * read using read_tar_number(). Fields that contain strings are generally
31  * both filled and read using strlcpy().
32  *
33  * The value for the checksum field can be computed using tarChecksum().
34  *
35  * Some fields are not used by PostgreSQL; see tarCreateHeader().
36  */
38 {
39  TAR_OFFSET_NAME = 0, /* 100 byte string */
40  TAR_OFFSET_MODE = 100, /* 8 byte tar number, excludes S_IFMT */
41  TAR_OFFSET_UID = 108, /* 8 byte tar number */
42  TAR_OFFSET_GID = 116, /* 8 byte tar number */
43  TAR_OFFSET_SIZE = 124, /* 8 byte tar number */
44  TAR_OFFSET_MTIME = 136, /* 12 byte tar number */
45  TAR_OFFSET_CHECKSUM = 148, /* 8 byte tar number */
46  TAR_OFFSET_TYPEFLAG = 156, /* 1 byte file type, see TAR_FILETYPE_* */
47  TAR_OFFSET_LINKNAME = 157, /* 100 byte string */
48  TAR_OFFSET_MAGIC = 257, /* "ustar" with terminating zero byte */
49  TAR_OFFSET_VERSION = 263, /* "00" */
50  TAR_OFFSET_UNAME = 265, /* 32 byte string */
51  TAR_OFFSET_GNAME = 297, /* 32 byte string */
52  TAR_OFFSET_DEVMAJOR = 329, /* 8 byte tar number */
53  TAR_OFFSET_DEVMINOR = 337, /* 8 byte tar number */
54  TAR_OFFSET_PREFIX = 345, /* 155 byte string */
55  /* last 12 bytes of the 512-byte block are unassigned */
56 };
57 
59 {
63 };
64 
65 extern enum tarError tarCreateHeader(char *h, const char *filename,
66  const char *linktarget, pgoff_t size,
67  mode_t mode, uid_t uid, gid_t gid,
68  time_t mtime);
69 extern uint64 read_tar_number(const char *s, int len);
70 extern void print_tar_number(char *s, int len, uint64 val);
71 extern int tarChecksum(char *header);
72 
73 /*
74  * Compute the number of padding bytes required for an entry in a tar
75  * archive. We must pad out to a multiple of TAR_BLOCK_SIZE. Since that's
76  * a power of 2, we can use TYPEALIGN().
77  */
78 static inline size_t
80 {
81  return TYPEALIGN(TAR_BLOCK_SIZE, len) - len;
82 }
83 
84 #endif
#define TYPEALIGN(ALIGNVAL, LEN)
Definition: c.h:793
long val
Definition: informix.c:664
static PgChecksumMode mode
Definition: pg_checksums.c:56
const void size_t len
static char * filename
Definition: pg_dumpall.c:121
uint64 read_tar_number(const char *s, int len)
Definition: tar.c:58
static size_t tarPaddingBytesRequired(size_t len)
Definition: pgtar.h:79
int tarChecksum(char *header)
Definition: tar.c:90
tarFileType
Definition: pgtar.h:59
@ TAR_FILETYPE_SYMLINK
Definition: pgtar.h:61
@ TAR_FILETYPE_DIRECTORY
Definition: pgtar.h:62
@ TAR_FILETYPE_PLAIN
Definition: pgtar.h:60
tarHeaderOffset
Definition: pgtar.h:38
@ TAR_OFFSET_DEVMINOR
Definition: pgtar.h:53
@ TAR_OFFSET_MODE
Definition: pgtar.h:40
@ TAR_OFFSET_PREFIX
Definition: pgtar.h:54
@ TAR_OFFSET_VERSION
Definition: pgtar.h:49
@ TAR_OFFSET_DEVMAJOR
Definition: pgtar.h:52
@ TAR_OFFSET_UID
Definition: pgtar.h:41
@ TAR_OFFSET_TYPEFLAG
Definition: pgtar.h:46
@ TAR_OFFSET_NAME
Definition: pgtar.h:39
@ TAR_OFFSET_SIZE
Definition: pgtar.h:43
@ TAR_OFFSET_GNAME
Definition: pgtar.h:51
@ TAR_OFFSET_CHECKSUM
Definition: pgtar.h:45
@ TAR_OFFSET_GID
Definition: pgtar.h:42
@ TAR_OFFSET_LINKNAME
Definition: pgtar.h:47
@ TAR_OFFSET_MTIME
Definition: pgtar.h:44
@ TAR_OFFSET_UNAME
Definition: pgtar.h:50
@ TAR_OFFSET_MAGIC
Definition: pgtar.h:48
enum tarError tarCreateHeader(char *h, const char *filename, const char *linktarget, pgoff_t size, mode_t mode, uid_t uid, gid_t gid, time_t mtime)
Definition: tar.c:114
tarError
Definition: pgtar.h:20
@ TAR_SYMLINK_TOO_LONG
Definition: pgtar.h:23
@ TAR_OK
Definition: pgtar.h:21
@ TAR_NAME_TOO_LONG
Definition: pgtar.h:22
#define TAR_BLOCK_SIZE
Definition: pgtar.h:17
void print_tar_number(char *s, int len, uint64 val)
Definition: tar.c:22
int gid_t
Definition: win32_port.h:245
#define pgoff_t
Definition: win32_port.h:207
int uid_t
Definition: win32_port.h:244