LCOV - code coverage report
Current view: top level - src/include - pgtar.h (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 100.0 % 2 2
Test Date: 2026-04-07 14:16:30 Functions: 100.0 % 1 1
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /*-------------------------------------------------------------------------
       2              :  *
       3              :  * pgtar.h
       4              :  *    Functions for manipulating tarfile datastructures (src/port/tar.c)
       5              :  *
       6              :  *
       7              :  * Portions Copyright (c) 1996-2026, 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              : 
      19              : enum tarError
      20              : {
      21              :     TAR_OK = 0,
      22              :     TAR_NAME_TOO_LONG,
      23              :     TAR_SYMLINK_TOO_LONG,
      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              :  */
      37              : enum tarHeaderOffset
      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              : 
      58              : /* See POSIX (not all the standard file type codes are listed here) */
      59              : enum tarFileType
      60              : {
      61              :     TAR_FILETYPE_PLAIN = '0',
      62              :     TAR_FILETYPE_PLAIN_OLD = '\0',  /* backwards compatibility, per POSIX */
      63              :     TAR_FILETYPE_SYMLINK = '2',
      64              :     TAR_FILETYPE_DIRECTORY = '5',
      65              :     TAR_FILETYPE_PAX_EXTENDED = 'x',
      66              :     TAR_FILETYPE_PAX_EXTENDED_GLOBAL = 'g',
      67              : };
      68              : 
      69              : extern enum tarError tarCreateHeader(char *h, const char *filename,
      70              :                                      const char *linktarget, pgoff_t size,
      71              :                                      mode_t mode, uid_t uid, gid_t gid,
      72              :                                      time_t mtime);
      73              : extern uint64 read_tar_number(const char *s, int len);
      74              : extern void print_tar_number(char *s, int len, uint64 val);
      75              : extern int  tarChecksum(const char *header);
      76              : extern bool isValidTarHeader(const char *header);
      77              : 
      78              : /*
      79              :  * Compute the number of padding bytes required for an entry in a tar
      80              :  * archive. We must pad out to a multiple of TAR_BLOCK_SIZE. Since that's
      81              :  * a power of 2, we can use TYPEALIGN().
      82              :  */
      83              : static inline size_t
      84       726329 : tarPaddingBytesRequired(size_t len)
      85              : {
      86       726329 :     return TYPEALIGN(TAR_BLOCK_SIZE, len) - len;
      87              : }
      88              : 
      89              : #endif
        

Generated by: LCOV version 2.0-1