rpm 5.2.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

Data Structures | Defines | Typedefs | Functions | Variables
rpmio/iosm.c File Reference
PAYLOAD.

File state machine to handle a payload from a package. More...

`#include "system.h"`
`#include <rpmio_internal.h>`
`#include <rpmcb.h>`
`#include <ugid.h>`
`#include <rpmsq.h>`
`#include <rpmsw.h>`
`#include "../rpmdb/rpmtag.h"`
`#include <iosm.h>`
`#include "cpio.h"`
`#include "tar.h"`
`#include "ar.h"`
`#include "../lib/rpmfi.h"`
`#include "debug.h"`
Include dependency graph for iosm.c:

Go to the source code of this file.

## Data Structures

struct | dnli_s
| Directory name iterator. More...

## Defines

#define | _IOSM_INTERNAL
#define | iosmUNSAFE iosmStage
#define | _RPMFI_INTERNAL
#define | _RPMFI_NOMETHODS
#define | alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
#define | _IOSM_DEBUG 0
#define | SUFFIX_RPMORIG ".rpmorig"
#define | SUFFIX_RPMSAVE ".rpmsave"
#define | SUFFIX_RPMNEW ".rpmnew"
#define | IS_DEV_LOG(_x)
#define | _fafilter(_a)
#define | IOSM_SKIPPING(_a) ((_a) == FA_SKIP || (_a) == FA_SKIPNSTATE || (_a) == FA_SKIPNETSHARED || (_a) == FA_SKIPCOLOR)

## Typedefs

typedef struct rpmts_s * | rpmts
typedef struct rpmte_s * | rpmte
typedef iosmMapFlags | cpioMapFlags
typedef struct rpmds_s * | rpmds
typedef struct rpmRelocation_s * | rpmRelocation
typedef struct rpmdb_s * | rpmdb
typedef struct rpmmi_s * | rpmmi
typedef struct rpmPRCO_s * | rpmPRCO
typedef struct Spec_s * | Spec
typedef struct dnli_s * | DNLI_t
| Directory name iterator.

## Functions

void * | iosmGetFi (const IOSM_t iosm)
static const char * | iosmFsPath (const IOSM_t iosm, const struct stat *st, const char *subdir, const char *suffix)
| Build path to file from file info, ornamented with subdir and suffix.
static void * | mapFreeIterator (void *p)
| Destroy file info iterator.
static void * | mapInitIterator (rpmfi fi, int reverse)
| Create file info iterator.
static int | mapNextIterator (void *a)
| Return next index into file info.
static int | iosmStrCmp (const void *a, const void *b)
static int | mapFind (IOSMI_t iter, const char *iosmPath)
| Locate archive path in file info.
static void * | dnlFreeIterator (const void *a)
| Destroy directory name iterator.
static int | dnlCount (const DNLI_t dnli)
static int | dnlIndex (const DNLI_t dnli)
static void * | dnlInitIterator (const IOSM_t fsm, int reverse)
| Create directory name iterator.
static const char * | dnlNextIterator (DNLI_t dnli)
| Return next directory name (from file info).
int | iosmNext (IOSM_t iosm, iosmFileStage nstage)
| File state machine driver.
static int | saveHardLink (IOSM_t fsm)
| Save hard link in chain.
static void * | freeHardLink (struct hardLink_s *li)
| Destroy set of hard links.
IOSM_t | newIOSM (void)
IOSM_t | freeIOSM (IOSM_t iosm)
static int | arSetup (IOSM_t iosm, rpmfi fi)
int | iosmSetup (IOSM_t iosm, iosmFileStage goal, const char *afmt, const void *_ts, const void *_fi, FD_t cfd, unsigned int *archiveSize, const char **failedFile)
| Load external data into I/O state machine.
int | iosmTeardown (IOSM_t iosm)
| Clean I/O state machine.
static int | iosmMapFContext (IOSM_t iosm)
int | iosmMapPath (IOSM_t iosm)
int | iosmMapAttrs (IOSM_t iosm)
static int | extractRegular (IOSM_t fsm)
| Create file from payload stream.
static int | writeFile (IOSM_t fsm, int writeData)
| Write next item to payload stream.
static int | writeLinkedFile (IOSM_t fsm)
| Write set of linked files to payload stream.
static int | iosmMakeLinks (IOSM_t iosm)
| Create pending hard links to existing file.
static int | iosmCommitLinks (IOSM_t iosm)
| Commit hard linked file set atomically.
static int | iosmRmdirs (IOSM_t iosm)
| Remove (if created) directories not explicitly included in package.
static int | iosmMkdirs (IOSM_t iosm)
| Create (if necessary) directories not explicitly included in package.
int | iosmStage (IOSM_t iosm, iosmFileStage stage)
| File state machine driver.
int | iosmFileActionSkipped (iosmFileAction action)
| Is the file going to be skipped?
const char * | iosmFileActionString (iosmFileAction a)
| Return formatted string representation of file disposition.
const char * | iosmFileStageString (iosmFileStage a)
| Return formatted string representation of file stages.
char * | iosmStrerror (int rc)
| Return formatted error message on payload handling failure.

## Variables

int | _iosm_debug = 0
int | _iosm_threads = 0
int(* | _iosmNext )(IOSM_t iosm, iosmFileStage nstage) = &iosmNext

## Detailed Description

File state machine to handle a payload from a package.

Definition in file iosm.c.

## Define Documentation

#define _fafilter | ( |  | _a | ) |

Value:

    (!((_a) == FA_CREATE || (_a) == FA_ERASE || (_a) == FA_COPYIN || (_a) == FA_COPYOUT) \
            ? iosmFileActionString(_a) : "")

#define _IOSM_DEBUG 0

Definition at line 65 of file iosm.c.

#define _IOSM_INTERNAL

Definition at line 20 of file iosm.c.

#define _RPMFI_INTERNAL

Definition at line 29 of file iosm.c.

#define _RPMFI_NOMETHODS

Definition at line 30 of file iosm.c.

#define alloca_strdup | ( |  | _s | ) | strcpy(alloca(strlen(_s)+1), (_s))

Definition at line 63 of file iosm.c.

#define IOSM_SKIPPING | ( |  | _a | ) | ((_a) == FA_SKIP || (_a) == FA_SKIPNSTATE || (_a) == FA_SKIPNETSHARED || (_a) == FA_SKIPCOLOR)

Definition at line 2675 of file iosm.c.

Referenced by iosmFileActionSkipped().

#define iosmUNSAFE iosmStage

Definition at line 22 of file iosm.c.

Referenced by iosmMakeLinks(), iosmMkdirs(), iosmSetup(), iosmStage(), and iosmTeardown().

#define IS_DEV_LOG | ( |  | _x | ) |

Value:

    ((_x) != NULL && strlen(_x) >= (sizeof("/dev/log")-1) && \
            !strncmp((_x), "/dev/log", sizeof("/dev/log")-1) && \
            ((_x)[sizeof("/dev/log")-1] == '\0' || \
             (_x)[sizeof("/dev/log")-1] == ';'))

Definition at line 1641 of file iosm.c.

Referenced by iosmStage().

#define SUFFIX_RPMNEW ".rpmnew"

Definition at line 99 of file iosm.c.

Referenced by iosmMapPath().

#define SUFFIX_RPMORIG ".rpmorig"

Definition at line 97 of file iosm.c.

Referenced by iosmMapPath().

#define SUFFIX_RPMSAVE ".rpmsave"

Definition at line 98 of file iosm.c.

Referenced by iosmMapPath().

## Typedef Documentation

typedef iosmMapFlags cpioMapFlags

Definition at line 28 of file iosm.c.

typedef struct rpmdb_s* rpmdb

Definition at line 46 of file iosm.c.

typedef struct rpmds_s* rpmds

Definition at line 33 of file iosm.c.

typedef struct rpmmi_s* rpmmi

Definition at line 47 of file iosm.c.

typedef struct rpmPRCO_s* rpmPRCO

Definition at line 48 of file iosm.c.

typedef struct rpmRelocation_s* rpmRelocation

Definition at line 34 of file iosm.c.

typedef struct rpmte_s* rpmte

Definition at line 18 of file iosm.c.

typedef struct rpmts_s* rpmts

Definition at line 17 of file iosm.c.

typedef struct Spec_s* Spec

Definition at line 49 of file iosm.c.

## Function Documentation

static int arSetup | ( | IOSM_t | iosm,
|  | rpmfi | fi
| ) |  | `[static]`

Definition at line 587 of file iosm.c.

References rpmfiBN(), rpmfiInit(), rpmfiNext(), stpcpy(), urlPath(), and xmalloc().

Referenced by fsmSetup(), and iosmSetup().

IOSM_t freeIOSM | ( | IOSM_t | iosm | ) |

Definition at line 571 of file iosm.c.

References _free(), freeHardLink(), and mapFreeIterator().

int iosmFileActionSkipped | ( | iosmFileAction | action | ) |

Is the file going to be skipped?

Parameters:

  iosm | I/O state machine

Returns:
  Is file to be skipped?

Definition at line 2678 of file iosm.c.

References IOSM_SKIPPING.

Referenced by dnlInitIterator(), fsmCommitLinks(), fsmMakeLinks(), fsmStage(), handleInstInstalledFiles(), handleOverlappedFiles(), iosmCommitLinks(), iosmMakeLinks(), iosmStage(), rpmtsRun(), saveHardLink(), and skipFiles().

const char* iosmFileActionString | ( | iosmFileAction | a | ) |

Return formatted string representation of file disposition.

Parameters:

  a | file dispostion

Returns:
  formatted string

Definition at line 2683 of file iosm.c.

References FA_ALTNAME, FA_BACKUP, FA_COPYIN, FA_COPYOUT, FA_CREATE, FA_ERASE, FA_SAVE, FA_SKIP, FA_SKIPCOLOR, FA_SKIPNETSHARED, FA_SKIPNSTATE, and FA_UNKNOWN.

const char* iosmFileStageString | ( | iosmFileStage | a | ) |

Return formatted string representation of file stages.

Parameters:

  a | file stage

Returns:
  formatted string

Definition at line 2703 of file iosm.c.

References IOSM_CHMOD, IOSM_CHOWN, IOSM_CHROOT, IOSM_COMMIT, IOSM_CREATE, IOSM_DESTROY, IOSM_DREAD, IOSM_DWRITE, IOSM_EAT, IOSM_FINI, IOSM_HREAD, IOSM_HWRITE, IOSM_INIT, IOSM_LCHOWN, IOSM_LINK, IOSM_LSETFCON, IOSM_LSTAT, IOSM_MAP, IOSM_MKDIR, IOSM_MKDIRS, IOSM_MKFIFO, IOSM_MKLINKS, IOSM_MKNOD, IOSM_NEXT, IOSM_NOTIFY, IOSM_PAD, IOSM_PKGBUILD, IOSM_PKGCOMMIT, IOSM_PKGERASE, IOSM_PKGINSTALL, IOSM_PKGUNDO, IOSM_POS, IOSM_POST, IOSM_PRE, IOSM_PROCESS, IOSM_RCLOSE, IOSM_READ, IOSM_READLINK, IOSM_RENAME, IOSM_RMDIR, IOSM_RMDIRS, IOSM_ROPEN, IOSM_STAT, IOSM_SYMLINK, IOSM_TRAILER, IOSM_UNDO, IOSM_UNKNOWN, IOSM_UNLINK, IOSM_UTIME, IOSM_VERIFY, IOSM_WCLOSE, IOSM_WOPEN, and IOSM_WRITE.

Referenced by fsmStage(), and iosmStage().

void* iosmGetFi | ( | const IOSM_t | iosm | ) |

Definition at line 89 of file iosm.c.

Referenced by iosmMapAttrs(), iosmMapFContext(), iosmMapPath(), iosmMkdirs(), and iosmStage().

int iosmMapAttrs | ( | IOSM_t | iosm | ) |

Definition at line 946 of file iosm.c.

References _, gnameToGid(), IOSM_MAP_GID, IOSM_MAP_MODE, IOSM_MAP_TYPE, IOSM_MAP_UID, IOSM_PKGINSTALL, iosmGetFi(), rpmlog(), RPMLOG_WARNING, and unameToUid().

Referenced by iosmStage().

static int iosmMapFContext | ( | IOSM_t | iosm | ) | `[static]`

Definition at line 826 of file iosm.c.

References iosmGetFi(), and matchpathcon.

Referenced by iosmStage().

int iosmMapPath | ( | IOSM_t | iosm | ) |

Definition at line 855 of file iosm.c.

References _free(), FA_ALTNAME, FA_BACKUP, FA_COPYIN, FA_COPYOUT, FA_CREATE, FA_ERASE, FA_SAVE, FA_SKIP, FA_SKIPCOLOR, FA_SKIPNETSHARED, FA_SKIPNSTATE, FA_UNKNOWN, IOSM_MAP_PATH, iosmFsPath(), iosmGetFi(), RPMFILE_GHOST, RPMFILE_STATE_NETSHARED, RPMFILE_STATE_NOTINSTALLED, RPMFILE_STATE_WRONGCOLOR, rpmteType(), SUFFIX_RPMNEW, SUFFIX_RPMORIG, SUFFIX_RPMSAVE, and TR_REMOVED.

Referenced by iosmStage().

static int iosmMkdirs | ( | IOSM_t | iosm | ) | `[static]`

Create (if necessary) directories not explicitly included in package.

Parameters:

  iosm | file state machine data

Returns:
  0 on success

Definition at line 1476 of file iosm.c.

References _free(), D_, dc, dnlCount(), dnlFreeIterator(), dnlIndex(), dnlInitIterator(), dnlNextIterator(), IOSM_LSETFCON, IOSM_LSTAT, IOSM_MKDIR, iosmGetFi(), iosmNext(), iosmUNSAFE, matchpathcon, rpmlog(), RPMLOG_DEBUG, stpcpy(), urlPath(), xcalloc(), and xrealloc().

Referenced by iosmStage().

int iosmNext | ( | IOSM_t | iosm,
|  | iosmFileStage | nstage
| ) |  |

File state machine driver.

Parameters:

  iosm | I/O state machine
  nstage | next stage

Returns:
  0 on success

Definition at line 452 of file iosm.c.

References iosmStage(), rpmsqJoin(), and rpmsqThread().

Referenced by iosmCommitLinks(), iosmMakeLinks(), iosmMkdirs(), iosmRmdirs(), iosmSetup(), and iosmStage().

static int iosmRmdirs | ( | IOSM_t | iosm | ) | `[static]`

Remove (if created) directories not explicitly included in package.

Parameters:

  iosm | file state machine data

Returns:
  0 on success

Definition at line 1421 of file iosm.c.

References dc, dnlCount(), dnlFreeIterator(), dnlIndex(), dnlInitIterator(), dnlNextIterator(), IOSM_RMDIR, iosmNext(), and stpcpy().

Referenced by iosmStage().

int iosmSetup | ( | IOSM_t | iosm,
|  | iosmFileStage | goal,
|  | const char * | afmt,
|  | const void * | _ts,
|  | const void * | _fi,
|  | FD_t | cfd,
|  | unsigned int * | archiveSize,
|  | const char ** | failedFile
| ) |  |

Load external data into I/O state machine.

Parameters:

  iosm | I/O state machine
  goal |
  afmt | archive format (NULL uses cpio)
  _ts | transaction set
  _fi | transaction element file info
  cfd | payload descriptor

Return values:

  archiveSize | pointer to archive size
  failedFile | pointer to first file name that failed.

Returns:
  0 on success

Definition at line 660 of file iosm.c.

References _iosm_debug, _iosm_threads, _iosmNext, _tsmask, arHeaderRead(), arHeaderWrite(), arSetup(), arTrailerWrite(), cpioHeaderRead(), cpioHeaderWrite(), cpioTrailerWrite(), FA_COPYOUT, fdGetCpioPos(), fdLink(), fdSetCpioPos(), IOSM_CREATE, IOSM_PKGBUILD, IOSM_PKGCOMMIT, IOSM_PKGERASE, IOSM_PKGINSTALL, iosmNext(), iosmUNSAFE, mapInitIterator(), RPMCALLBACK_INST_START, rpmteType(), RPMTRANS_FLAG_NOCONTEXTS, RPMTRANS_FLAG_NOFDIGESTS, rpmtsFlags(), rpmtsGetTid(), rpmtsLink(), rpmtsNotify(), TAR_BLOCK_SIZE, tarHeaderRead(), tarHeaderWrite(), tarTrailerWrite(), TR_ADDED, and TR_REMOVED.

int iosmStage | ( | IOSM_t | iosm,
|  | iosmFileStage | stage
| ) |  |

File state machine driver.

Parameters:

  iosm | I/O state machine
  stage | next stage

Returns:
  0 on success

Definition at line 1648 of file iosm.c.

References _, _fafilter, _free(), alloca(), Chmod(), Chown(), CPIO_TRAILER, errno, extractRegular(), FA_ERASE, FA_UNKNOWN, Fclose(), fdGetCpioPos(), fdSetCpioPos(), FDSTAT_DIGEST, fdstat_op(), Ferror(), Fopen(), Fread(), freeHardLink(), Fwrite(), IOSM_ALL_HARDLINKS, IOSM_CHMOD, IOSM_CHOWN, IOSM_CHROOT, IOSM_COMMIT, IOSM_CREATE, IOSM_DEAD, IOSM_DESTROY, IOSM_DREAD, IOSM_DWRITE, IOSM_EAT, IOSM_FINI, IOSM_FOLLOW_SYMLINKS, IOSM_HREAD, IOSM_HWRITE, IOSM_INIT, IOSM_INTERNAL, IOSM_LCHOWN, IOSM_LINK, IOSM_LSETFCON, IOSM_LSTAT, IOSM_MAP, IOSM_MKDIR, IOSM_MKDIRS, IOSM_MKFIFO, IOSM_MKLINKS, IOSM_MKNOD, IOSM_NEXT, IOSM_NOTIFY, IOSM_PAD, IOSM_PAYLOAD_EXTRACT, IOSM_PAYLOAD_LIST, IOSM_PKGBUILD, IOSM_PKGCOMMIT, IOSM_PKGERASE, IOSM_PKGINSTALL, IOSM_POS, IOSM_POST, IOSM_PRE, IOSM_PROCESS, IOSM_RCLOSE, IOSM_READ, IOSM_READLINK, IOSM_RENAME, IOSM_RMDIR, IOSM_RMDIRS, IOSM_ROPEN, IOSM_SBIT_CHECK, IOSM_STAT, IOSM_SYMLINK, IOSM_SYSCALL, IOSM_TRAILER, IOSM_UNDO, IOSM_UNKNOWN, IOSM_UNLINK, IOSM_UTIME, IOSM_VERBOSE, IOSM_VERIFY, IOSM_WCLOSE, IOSM_WOPEN, IOSM_WRITE, iosmCommitLinks(), iosmFileActionSkipped(), iosmFileStageString(), iosmFsPath(), iosmGetFi(), iosmMakeLinks(), iosmMapAttrs(), iosmMapFContext(), iosmMapPath(), iosmMkdirs(), iosmNext(), iosmRmdirs(), iosmUNSAFE, IS_DEV_LOG, Lchown(), Link(), lsetfilecon, Lstat(), mapFind(), mapNextIterator(), Mkdir(), Mkfifo(), Mknod(), Readlink(), Rename(), Rmdir(), RPMCALLBACK_INST_PROGRESS, RPMFILE_GHOST, RPMFILE_MISSINGOK, rpmlog(), RPMLOG_DEBUG, RPMLOG_ERR, RPMLOG_WARNING, rpmswAdd(), rpmtsNotify(), S_ISLNK, S_ISSOCK, saveHardLink(), Stat(), stpcpy(), Symlink(), Unlink(), urlPath(), Utime(), writeFile(), writeLinkedFile(), xmalloc(), and xstrdup().

Referenced by fsmStage(), and iosmNext().

int iosmTeardown | ( | IOSM_t | iosm | ) |

Clean I/O state machine.

Parameters:

  iosm | I/O state machine

Returns:
  0 on success

Definition at line 793 of file iosm.c.

References _free(), fdFree(), IOSM_DESTROY, iosmUNSAFE, mapFreeIterator(), rpmswAdd(), RPMTS_OP_DIGEST, rpmtsFree(), and rpmtsOp().

IOSM_t newIOSM | ( | void |  | ) |

Definition at line 565 of file iosm.c.

References xcalloc().

## Variable Documentation

int _iosm_debug = 0

Definition at line 67 of file iosm.c.

Referenced by iosmSetup().

int _iosm_threads = 0

Definition at line 71 of file iosm.c.

Referenced by iosmSetup().

int(* _iosmNext)(IOSM_t iosm, iosmFileStage nstage) = &iosmNext

Definition at line 75 of file iosm.c.

Referenced by arHeaderRead(), arHeaderWrite(), arRead(), arTrailerWrite(), arWrite(), cpioHeaderRead(), cpioHeaderWrite(), cpioRead(), cpioTrailerWrite(), cpioWrite(), fsmSetup(), iosmSetup(), tarHeaderWrite(), tarHeaderWriteName(), tarRead(), tarTrailerWrite(), and tarWrite().