# lib/tar.c File Reference

Handle tar payloads within rpm packages. More...

`#include "system.h"`
`#include <rpmio.h>`
`#include <rpmlib.h>`
`#include "tar.h"`
`#include "fsm.h"`
`#include "ugid.h"`
`#include "debug.h"`

Include dependency graph for tar.c:

Go to the source code of this file.

## Functions

static int | strntoul (const char *str, char **endptr, int base, int num)
| Convert string to unsigned integer (with buffer size check).
static int | tarHeaderReadName (FSM_t fsm, int len, const char **fnp)
| Read long file/link name from tar archive.
int | tarHeaderRead (FSM_t fsm, struct stat *st)
| Read tar header from payload.
static int | tarHeaderWriteName (FSM_t fsm, const char *path)
| Write long file/link name into tar archive.
static int | tarHeaderWriteBlock (FSM_t fsm, struct stat *st, tarHeader hdr)
| Write tar header block with checksum into tar archive.
int | tarHeaderWrite (FSM_t fsm, struct stat *st)
| Write tar header to payload.
int | tarTrailerWrite (FSM_t fsm)
| Write cpio trailer to payload.

## Variables

int | _tar_debug = 0
static int | nochksum = 0

## Detailed Description

Handle tar payloads within rpm packages.

Definition in file tar.c.

## Function Documentation

static int strntoul | ( | const char * | str,
|  | char ** | endptr,
|  | int | base,
|  | int | num |
| ) |  |  | `[static]`

Convert string to unsigned integer (with buffer size check).

Parameters:

  | str | input string

Return values:

  | endptr | address of 1st character not processed

Parameters:

  | base | numerical conversion base
  | num | max no. of bytes to read

Returns:
  converted integer

Definition at line 33 of file tar.c.

References alloca().

Referenced by tarHeaderRead().

int tarHeaderRead | ( | FSM_t | fsm,
|  | struct stat * | st |
| ) |  |  |

Read tar header from payload.

Return values:

  | fsm | file path and stat info
  | st |

Returns:
  0 on success

Definition at line 92 of file tar.c.

References _tar_debug, tarHeader_s::checksum, CPIOERR_BAD_HEADER, CPIOERR_BAD_MAGIC, CPIOERR_HDR_TRAILER, CPIOERR_READ_FAILED, tarHeader_s::devMajor, tarHeader_s::devMinor, tarHeader_s::filesize, FSM_DREAD, fsmNext(), tarHeader_s::gid, tarHeader_s::linkname, fsm_s::lpath, tarHeader_s::magic, major, Makedev, minor, tarHeader_s::mode, tarHeader_s::mtime, tarHeader_s::name, nochksum, fsm_s::path, fsm_s::rdnb, strntoul(), TAR_BLOCK_SIZE, TAR_MAGIC, tarHeaderReadName(), tarHeader_s::typeflag, tarHeader_s::uid, fsm_s::wrbuf, fsm_s::wrlen, and xmalloc().

Referenced by fsmSetup().

static int tarHeaderReadName | ( | FSM_t | fsm,
|  | int | len,
|  | const char ** | fnp |
| ) |  |  | `[static]`

Read long file/link name from tar archive.

Parameters:

  | fsm | file state machine
  | len | no. bytes of name

Return values:

  | *fnp | long file/link name

Returns:
  0 on success

Definition at line 62 of file tar.c.

References _free(), CPIOERR_READ_FAILED, FSM_DREAD, fsmNext(), fsm_s::rdnb, TAR_BLOCK_SIZE, fsm_s::wrbuf, fsm_s::wrlen, and xmalloc().

Referenced by tarHeaderRead().

int tarHeaderWrite | ( | FSM_t | fsm,
|  | struct stat * | st |
| ) |  |  |

Write tar header to payload.

Return values:

  | fsm | file path and stat info

Parameters:

  | st |

Returns:
  0 on success

Definition at line 342 of file tar.c.

References _tar_debug, tarHeader_s::devMajor, tarHeader_s::devMinor, tarHeader_s::filesize, FSM_PAD, fsmNext(), tarHeader_s::gid, gidToGname(), tarHeader_s::gname, tarHeader_s::linkname, fsm_s::lpath, major, minor, tarHeader_s::mode, tarHeader_s::mtime, tarHeader_s::name, fsm_s::path, fsm_s::rdbuf, S_ISLNK, S_ISSOCK, tarHeaderWriteBlock(), tarHeaderWriteName(), tarHeader_s::typeflag, tarHeader_s::uid, uidToUname(), and tarHeader_s::uname.

Referenced by fsmSetup(), and writeLinkedFile().

static int tarHeaderWriteBlock | ( | FSM_t | fsm,
|  | struct stat * | st,
|  | tarHeader | hdr |
| ) |  |  | `[static]`

Write tar header block with checksum into tar archive.

Parameters:

  | fsm | file state machine
  | st | file info
  | hdr | tar header block

Returns:
  0 on success

Definition at line 303 of file tar.c.

References _tar_debug, tarHeader_s::checksum, CPIOERR_WRITE_FAILED, FSM_DWRITE, fsmNext(), tarHeader_s::magic, fsm_s::path, fsm_s::rdnb, stpcpy(), TAR_BLOCK_SIZE, TAR_MAGIC, TAR_VERSION, tarHeader_s::typeflag, and fsm_s::wrnb.

Referenced by tarHeaderWrite().

static int tarHeaderWriteName | ( | FSM_t | fsm,
|  | const char * | path |
| ) |  |  | `[static]`

Write long file/link name into tar archive.

Parameters:

  | fsm | file state machine
  | path | long file/link name

Returns:
  0 on success

Definition at line 264 of file tar.c.

References _tar_debug, CPIOERR_WRITE_FAILED, FSM_DWRITE, FSM_PAD, fsmNext(), fsm_s::rdbuf, fsm_s::rdnb, TAR_BLOCK_SIZE, and fsm_s::wrnb.

Referenced by tarHeaderWrite().

int tarTrailerWrite | ( | FSM_t | fsm | ) |

Write cpio trailer to payload.

Return values:

  | fsm | file path and stat info

Returns:
  0 on success

Definition at line 448 of file tar.c.

References _tar_debug, fsm_s::blksize, FSM_PAD, and fsmNext().

Referenced by fsmSetup().

## Variable Documentation

int _tar_debug = 0

Definition at line 20 of file tar.c.

Referenced by tarHeaderRead(), tarHeaderWrite(), tarHeaderWriteBlock(), tarHeaderWriteName(), and tarTrailerWrite().

int nochksum = 0`[static]`

Definition at line 23 of file tar.c.

Referenced by tarHeaderRead().