cpio.c File Reference
PAYLOAD.

Handle cpio(1) archives. More...

`#include "system.h"`
`#include <rpmio.h>`
`#include <ugid.h>`
`#include <cpio.h>`
`#include <iosm.h>`
`#include "debug.h"`
Include dependency graph for cpio.c:

Go to the source code of this file.

## Macros

#define | _IOSM_INTERNAL
#define | _IOSMRC(_rc) if ((_rc) <= 0) return ((_rc) ? (int) -rc : IOSMERR_HDR_TRAILER)
#define | GET_NUM_FIELD(phys, log)
#define | SET_NUM_FIELD(phys, val, space)

## Functions

static int | strntoul (const char *str, char **endptr, int base, size_t num)
| Convert string to unsigned integer (with buffer size check). More...
static ssize_t | cpioRead (void *_iosm, void *buf, size_t count)
int | cpioHeaderRead (void *_iosm, struct stat *st)
| Read cpio header. More...
static ssize_t | cpioWrite (void *_iosm, const void *buf, size_t count)
int | cpioHeaderWrite (void *_iosm, struct stat *st)
| Write cpio header. More...
int | cpioTrailerWrite (void *_iosm)
| Write cpio trailer. More...

## Variables

int | _cpio_debug = 0

## Detailed Description

Handle cpio(1) archives.

Definition in file cpio.c.

## Macro Definition Documentation

#define _IOSM_INTERNAL

Definition at line 12 of file cpio.c.

#define _IOSMRC | ( |  | _rc | ) | if ((_rc) <= 0) return ((_rc) ? (int) -rc : IOSMERR_HDR_TRAILER)

Definition at line 54 of file cpio.c.

Referenced by cpioHeaderRead(), cpioHeaderWrite(), and cpioTrailerWrite().

#define GET_NUM_FIELD | ( |  | phys,
|  |  | log
| ) |  |

Value:
log = strntoul(phys, &end, 16, sizeof(phys)); \
if ( (end - phys) != sizeof(phys) ) return IOSMERR_BAD_HEADER;

Definition at line 88 of file cpio.c.

Referenced by cpioHeaderRead().

#define SET_NUM_FIELD | ( |  | phys,
|  |  | val,
|  |  | space
| ) |  |

Value:
sprintf(space, "%8.8lx", (unsigned long) (val)); \
memcpy(phys, space, 8)

Definition at line 91 of file cpio.c.

Referenced by cpioHeaderWrite().

## Function Documentation

int cpioHeaderRead | ( | void * | _iosm,
|  | struct stat * | st
| ) |  |

Read cpio header.

Return values

  _iosm | file path and stat info
  st |

Returns
  0 on success

Definition at line 95 of file cpio.c.

References _cpio_debug, _free(), _iosmNext, _IOSMRC, CPIO_CRC_MAGIC, CPIO_NEWC_MAGIC, cpioRead(), cpioCrcPhysicalHeader_s::devMajor, cpioCrcPhysicalHeader_s::devMinor, cpioCrcPhysicalHeader_s::filesize, GET_NUM_FIELD, cpioCrcPhysicalHeader_s::gid, cpioCrcPhysicalHeader_s::inode, IOSM_POS, cpioCrcPhysicalHeader_s::magic, major, Makedev, minor, cpioCrcPhysicalHeader_s::mode, cpioCrcPhysicalHeader_s::mtime, cpioCrcPhysicalHeader_s::namesize, cpioCrcPhysicalHeader_s::nlink, PHYS_HDR_SIZE, cpioCrcPhysicalHeader_s::rdevMajor, cpioCrcPhysicalHeader_s::rdevMinor, S_ISLNK, cpioCrcPhysicalHeader_s::uid, and xmalloc().

Referenced by fsmSetup(), and iosmSetup().

int cpioHeaderWrite | ( | void * | _iosm,
|  | struct stat * | st
| ) |  |

Write cpio header.

Return values

  _iosm | file path and stat info

Parameters

  st |

Returns
  0 on success

Definition at line 224 of file cpio.c.

References _cpio_debug, _iosmNext, _IOSMRC, cpioCrcPhysicalHeader_s::checksum, CPIO_NEWC_MAGIC, cpioWrite(), cpioCrcPhysicalHeader_s::devMajor, cpioCrcPhysicalHeader_s::devMinor, cpioCrcPhysicalHeader_s::filesize, cpioCrcPhysicalHeader_s::gid, cpioCrcPhysicalHeader_s::inode, IOSM_PAD, cpioCrcPhysicalHeader_s::magic, major, minor, cpioCrcPhysicalHeader_s::mode, cpioCrcPhysicalHeader_s::mtime, cpioCrcPhysicalHeader_s::namesize, cpioCrcPhysicalHeader_s::nlink, PHYS_HDR_SIZE, cpioCrcPhysicalHeader_s::rdevMajor, cpioCrcPhysicalHeader_s::rdevMinor, S_ISLNK, SET_NUM_FIELD, and cpioCrcPhysicalHeader_s::uid.

Referenced by fsmSetup(), and iosmSetup().

static ssize_t cpioRead | ( | void * | _iosm,
|  | void * | buf,
|  | size_t | count
| ) |  |

static

Definition at line 57 of file cpio.c.

References _cpio_debug, _iosmNext, and IOSM_DREAD.

Referenced by cpioHeaderRead().

int cpioTrailerWrite | ( | void * | _iosm | ) |

Write cpio trailer.

Return values

  _iosm | file path and stat info

Returns
  0 on success

Definition at line 278 of file cpio.c.

References _cpio_debug, _iosmNext, _IOSMRC, CPIO_NEWC_MAGIC, CPIO_TRAILER, cpioWrite(), IOSM_PAD, cpioCrcPhysicalHeader_s::magic, cpioCrcPhysicalHeader_s::namesize, cpioCrcPhysicalHeader_s::nlink, and PHYS_HDR_SIZE.

Referenced by fsmSetup(), and iosmSetup().

static ssize_t cpioWrite | ( | void * | _iosm,
|  | const void * | buf,
|  | size_t | count
| ) |  |

static

Definition at line 188 of file cpio.c.

References _cpio_debug, _iosmNext, IOSM_DWRITE, and IOSM_PAD.

Referenced by cpioHeaderWrite(), and cpioTrailerWrite().

static int strntoul | ( | const char * | str,
|  | char ** | endptr,
|  | int | base,
|  | size_t | num
| ) |  |

static

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

Parameters

  str | input string

Return values

  *endptr | 1st character not processed

Parameters

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

Returns
  converted integer

Definition at line 30 of file cpio.c.

References alloca().

## Variable Documentation

int _cpio_debug = 0

Definition at line 20 of file cpio.c.

Referenced by cpioHeaderRead(), cpioHeaderWrite(), cpioRead(), cpioTrailerWrite(), and cpioWrite().