Main Page   Modules   Compound List   File List   Compound Members   File Members   Related Pages  

lib/cpio.c File Reference

Handle cpio payloads within rpm packages. More...

#include "system.h"
#include "cpio.h"
#include "rpmerr.h"
#include "debug.h"

Go to the source code of this file.

Compounds

struct  cpioCrcPhysicalHeader
struct  cpioHeader
struct  hardLink

Defines

#define CPIO_NEWC_MAGIC   "070701"
#define CPIO_CRC_MAGIC   "070702"
#define TRAILER   "TRAILER!!!"
#define PHYS_HDR_SIZE   110
#define GET_NUM_FIELD(phys, log)
#define SET_NUM_FIELD(phys, val, space)

Enumerations

enum  hardLinkType { HARDLINK_INSTALL = 1, HARDLINK_BUILD }

Functions

off_t saferead (FD_t cfd, void *vbuf, size_t amount)
 Read data from payload. More...

off_t ourread (FD_t cfd, void *buf, size_t size)
 Read data from payload and update number of bytes read. More...

void padinfd (FD_t cfd, int modulo)
 Align input payload handle, skipping input bytes. More...

off_t safewrite (FD_t cfd, const void *vbuf, size_t amount)
 Write data to payload. More...

int padoutfd (FD_t cfd, size_t *where, int modulo)
 Align output payload handle, padding with zeroes. More...

int strntoul (const char *str, char **endptr, int base, int num)
 Convert string to unsigned integer (with buffer size check). More...

int getNextHeader (FD_t cfd, struct cpioHeader *hdr)
 Process next cpio heasder. More...

int cpioFileMapCmp (const void *a, const void *b)
int createDirectory (const char *path, mode_t perms)
int setInfo (struct cpioHeader *hdr)
 Set owner, group, and modify/access times. More...

int checkDirectory (const char *filename)
 Create directories in file path (like "mkdir -p"). More...

int expandRegular (FD_t cfd, const struct cpioHeader *hdr, const char *filemd5, cpioCallback cb, void *cbData)
 Create file from payload stream. More...

int expandSymlink (FD_t cfd, const struct cpioHeader *hdr)
 Create symlink from payload stream. More...

int expandFifo (FD_t cfd, const struct cpioHeader *hdr)
 Create fifo from payload stream. More...

int expandDevice (FD_t cfd, const struct cpioHeader *hdr)
 Create fifo from payload stream. More...

struct hardLinknewHardLink (const struct stat *st, enum hardLinkType hltype)
 Create and initialize set of hard links. More...

void freeHardLink (struct hardLink *li)
 Destroy set of hard links. More...

int createLinks (struct hardLink *li, const char **failedFile)
 Create hard links to existing file. More...

int eatBytes (FD_t cfd, int amount)
 Skip amount bytes on input payload stream. More...

int cpioInstallArchive (FD_t cfd, const struct cpioFileMapping *mappings, int numMappings, cpioCallback cb, void *cbData, const char **failedFile)
int writeFile (FD_t cfd, const struct stat *st, const struct cpioFileMapping *map, size_t *sizep, int writeData)
 Write next item to payload stream. More...

int writeLinkedFile (FD_t cfd, const struct hardLink *hlink, const struct cpioFileMapping *mappings, cpioCallback cb, void *cbData, size_t *sizep, const char **failedFile)
 Write set of linked files to payload stream. More...

int cpioBuildArchive (FD_t cfd, const struct cpioFileMapping *mappings, int numMappings, cpioCallback cb, void *cbData, unsigned int *archiveSize, const char **failedFile)
const char* cpioStrerror (int rc)


Detailed Description

Handle cpio payloads within rpm packages.

Warning:
FIXME: We don't translate between cpio and system mode bits! These should both be the same, but really odd things are going to happen if that's not true!

Definition in file cpio.c.


Define Documentation

#define CPIO_CRC_MAGIC   "070702"
 

Definition at line 18 of file cpio.c.

#define CPIO_NEWC_MAGIC   "070701"
 

Definition at line 17 of file cpio.c.

#define GET_NUM_FIELD( phys, log )
 

Value:

        log = strntoul(phys, &end, 16, sizeof(phys)); \
        if (*end) return CPIOERR_BAD_HEADER;

Definition at line 217 of file cpio.c.

Referenced by getNextHeader().

#define PHYS_HDR_SIZE   110
 

Don't depend on sizeof(struct)

Definition at line 64 of file cpio.c.

#define SET_NUM_FIELD( phys, val, space )
 

Value:

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

Definition at line 220 of file cpio.c.

Referenced by writeFile().

#define TRAILER   "TRAILER!!!"
 

Definition at line 19 of file cpio.c.


Function Documentation

int checkDirectory ( const char * filename ) [inline, static]
 

Create directories in file path (like "mkdir -p").

Parameters:
filename   file path
Returns:
0 on success

Definition at line 377 of file cpio.c.

Referenced by cpioInstallArchive().

int createDirectory ( const char * path,
mode_t perms ) [static]
 

Parameters:
path   directory path
perms   directory permissions
Returns:
0 on success

Definition at line 298 of file cpio.c.

Referenced by checkDirectory(), and cpioInstallArchive().

int createLinks ( struct hardLink * li,
const char ** failedFile ) [static]
 

Create hard links to existing file.

Parameters:
li   set of hard links
Return values:
failedFile   on error, file name that failed
Returns:
0 on success

Definition at line 679 of file cpio.c.

Referenced by cpioInstallArchive().

int eatBytes ( FD_t cfd,
int amount ) [static]
 

Skip amount bytes on input payload stream.

Parameters:
cfd   payload file handle
amount   no. bytes to skip
Returns:
0 on success

Definition at line 717 of file cpio.c.

Referenced by cpioInstallArchive().

int expandDevice ( FD_t cfd,
const struct cpioHeader * hdr ) [static]
 

Create fifo from payload stream.

Parameters:
cfd   payload file handle
hdr   file name and stat info
Returns:
0 on success

Definition at line 592 of file cpio.c.

Referenced by cpioInstallArchive().

int expandFifo ( FD_t cfd,
const struct cpioHeader * hdr ) [static]
 

Create fifo from payload stream.

Parameters:
cfd   payload file handle
hdr   file name and stat info
Returns:
0 on success

Definition at line 568 of file cpio.c.

Referenced by cpioInstallArchive().

int expandRegular ( FD_t cfd,
const struct cpioHeader * hdr,
const char * filemd5,
cpioCallback cb,
void * cbData ) [static]
 

Create file from payload stream.

Todo:
Legacy: support brokenEndian MD5 checks?
Parameters:
cfd   payload file handle
hdr   file name and stat info
filemd5   file md5 sum
cb   callback function
cbData   callback private data
Returns:
0 on success

Definition at line 432 of file cpio.c.

Referenced by cpioInstallArchive().

int expandSymlink ( FD_t cfd,
const struct cpioHeader * hdr ) [static]
 

Create symlink from payload stream.

Parameters:
cfd   payload file handle
hdr   file name and stat info
Returns:
0 on success

Definition at line 527 of file cpio.c.

Referenced by cpioInstallArchive().

void freeHardLink ( struct hardLink * li ) [static]
 

Destroy set of hard links.

Parameters:
li   set of hard links

Definition at line 653 of file cpio.c.

Referenced by cpioBuildArchive(), and cpioInstallArchive().

int getNextHeader ( FD_t cfd,
struct cpioHeader * hdr ) [static]
 

Process next cpio heasder.

Parameters:
cfd   payload file handle
Return values:
hdr   file name and stat info
Returns:
0 on success

Definition at line 230 of file cpio.c.

Referenced by cpioInstallArchive().

struct hardLink* newHardLink ( const struct stat * st,
enum hardLinkType hltype ) [static]
 

Create and initialize set of hard links.

Parameters:
st   link stat info
hltype   type of hard link set to create
Returns:
pointer to set of hard links

Definition at line 618 of file cpio.c.

Referenced by cpioBuildArchive(), and cpioInstallArchive().

off_t ourread ( FD_t cfd,
void * buf,
size_t size ) [inline, static]
 

Read data from payload and update number of bytes read.

Parameters:
cfd   payload file handle
Return values:
buf   data from read
Parameters:
size   no. bytes to read
Returns:
no. bytes read

Definition at line 117 of file cpio.c.

Referenced by eatBytes(), expandRegular(), expandSymlink(), getNextHeader(), and padinfd().

void padinfd ( FD_t cfd,
int modulo ) [inline, static]
 

Align input payload handle, skipping input bytes.

Parameters:
cfd   payload file handle
modulo   data alignment

Definition at line 131 of file cpio.c.

Referenced by cpioInstallArchive(), and getNextHeader().

int padoutfd ( FD_t cfd,
size_t * where,
int modulo ) [inline, static]
 

Align output payload handle, padding with zeroes.

Parameters:
cfd   payload file handle
modulo   data alignment
Returns:
0 on success, CPIOERR_WRITE_FAILED

Definition at line 176 of file cpio.c.

Referenced by cpioBuildArchive(), and writeFile().

off_t saferead ( FD_t cfd,
void * vbuf,
size_t amount ) [inline, static]
 

Read data from payload.

Parameters:
cfd   payload file handle
Return values:
vbuf   data from read
Parameters:
amount   no. bytes to read
Returns:
no. bytes read

Definition at line 89 of file cpio.c.

Referenced by ourread().

off_t safewrite ( FD_t cfd,
const void * vbuf,
size_t amount ) [inline, static]
 

Write data to payload.

Parameters:
cfd   payload file handle
vbuf   data to write
amount   no. bytes to write
Returns:
no. bytes written

Definition at line 148 of file cpio.c.

Referenced by cpioBuildArchive(), padoutfd(), and writeFile().

int setInfo ( struct cpioHeader * hdr ) [static]
 

Set owner, group, and modify/access times.

Parameters:
hdr   file name and stat info
Returns:
0 on success

Definition at line 340 of file cpio.c.

Referenced by cpioInstallArchive().

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

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

Parameters:
input   string
Return values:
address   of 1st character not processed
Parameters:
base   numerical conversion base
num   max no. of bytes to read
Returns:
converted integer

Definition at line 198 of file cpio.c.

int writeFile ( FD_t cfd,
const struct stat * st,
const struct cpioFileMapping * map,
size_t * sizep,
int writeData ) [static]
 

Write next item to payload stream.

Parameters:
cfd   payload file handle
st   stat info for item
map   mapping name and flags for item
Return values:
sizep   address of no. bytes written
Parameters:
writeData   should data be written?
Returns:
0 on success

Definition at line 922 of file cpio.c.

Referenced by cpioBuildArchive(), and writeLinkedFile().

int writeLinkedFile ( FD_t cfd,
const struct hardLink * hlink,
const struct cpioFileMapping * mappings,
cpioCallback cb,
void * cbData,
size_t * sizep,
const char ** failedFile ) [static]
 

Write set of linked files to payload stream.

Parameters:
cfd   payload file handle
hlink   set of linked files
mappings   mapping name and flags for linked files
cb   callback function
cbData   callback private data
Return values:
sizep   address of no. bytes written
failedFile   on error, file name that failed
Returns:
0 on success

Definition at line 1076 of file cpio.c.

Referenced by cpioBuildArchive().


Generated at Mon May 21 08:53:41 2001 for rpm by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001