# lib/fsm.c File Reference

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

`#include "system.h"`
`#include "psm.h"`
`#include "rpmerr.h"`
`#include "debug.h"`

Go to the source code of this file.

## Data Structures
struct | dnli_s
| Directory name iterator. More...
## Defines
#define | alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
#define | SUFFIX_RPMORIG ".rpmorig"
#define | SUFFIX_RPMSAVE ".rpmsave"
#define | SUFFIX_RPMNEW ".rpmnew"
#define | _fafilter(_a)
#define | _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)
## Typedefs
typedef struct dnli_s * | DNLI_t
| Directory name iterator.
## Functions
rpmTransactionSet | fsmGetTs (const FSM_t fsm)
| Retrieve transaction set from file state machine iterator.
TFI_t | fsmGetFi (const FSM_t fsm)
| Retrieve transaction element file info from file state machine iterator.
static const char * | fsmFsPath (const FSM_t fsm, 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 (const void *p)
| Destroy file info iterator.
static void * | mapInitIterator (const void *a, const void *b)
| Create file info iterator.
static int | mapNextIterator (void *a)
| Return next index into file info.
static int | cpioStrCmp (const void *a, const void *b)
static int | mapFind (void *a, const char *fsmPath)
| 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 FSM_t fsm, int reverse)
| Create directory name iterator.
static const char * | dnlNextIterator (DNLI_t dnli)
| Return next directory name (from file info).
static int | saveHardLink (FSM_t fsm)
| Save hard link in chain.
static void * | freeHardLink (struct hardLink_s *li)
| Destroy set of hard links.
FSM_t | newFSM (void)
| Create file state machine instance.
FSM_t | freeFSM (FSM_t fsm)
| Destroy file state machine instance.
int | fsmSetup (FSM_t fsm, fileStage goal, const rpmTransactionSet ts, const TFI_t fi, FD_t cfd, unsigned int *archiveSize, const char **failedFile)
| Load external data into file state machine.
int | fsmTeardown (FSM_t fsm)
| Clean file state machine.
int | fsmMapPath (FSM_t fsm)
| Map next file path and action.
int | fsmMapAttrs (FSM_t fsm)
| Map file stat(2) info.
static int | expandRegular (FSM_t fsm)
| Create file from payload stream.
static int | writeFile (FSM_t fsm, int writeData)
| Write next item to payload stream.
static int | writeLinkedFile (FSM_t fsm)
| Write set of linked files to payload stream.
static int | fsmMakeLinks (FSM_t fsm)
| Create pending hard links to existing file.
static int | fsmCommitLinks (FSM_t fsm)
| Commit hard linked file set atomically.
static int | fsmRmdirs (FSM_t fsm)
| Remove (if created) directories not explicitly included in package.
static int | fsmMkdirs (FSM_t fsm)
| Create (if necessary) directories not explicitly included in package.
int | fsmStage (FSM_t fsm, fileStage stage)
| File state machine driver.
const char *const | fileActionString (fileAction a)
| Return formatted string representation of file disposition.
const char *const | fileStageString (fileStage a)
| Return formatted string representation of file stages.
## Variables
int | _fsm_debug = 0
int | strict_erasures = 0

## Detailed Description

File state machine to handle a payload from a package.

Definition in file fsm.c.

## Define Documentation

#define _fafilter | ( | _a |  | ) |

Value:

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

#define _tsmask (RPMTRANS_FLAG_PKGCOMMIT | RPMTRANS_FLAG_COMMIT)

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

Definition at line 18 of file fsm.c.

#define SUFFIX_RPMNEW ".rpmnew"

Definition at line 44 of file fsm.c.

#define SUFFIX_RPMORIG ".rpmorig"

Definition at line 42 of file fsm.c.

#define SUFFIX_RPMSAVE ".rpmsave"

Definition at line 43 of file fsm.c.

## Function Documentation

const char* const fileActionString | ( | fileAction | a | ) |

Return formatted string representation of file disposition.

Parameters:

  | a | file dispostion

Returns:
  formatted string

Definition at line 2123 of file fsm.c.

const char* const fileStageString | ( | fileStage | a | ) |

Return formatted string representation of file stages.

Parameters:

  | a | file stage

Returns:
  formatted string

Definition at line 2143 of file fsm.c.

FSM_t freeFSM | ( | FSM_t | fsm | ) |

Destroy file state machine instance.

Parameters:

  | fsm | file state machine data

Returns:
  always NULL

Definition at line 438 of file fsm.c.

TFI_t fsmGetFi | ( | const FSM_t | fsm | ) |

Retrieve transaction element file info from file state machine iterator.

Parameters:

  | fsm | file state machine data

Returns:
  transaction element file info

Definition at line 34 of file fsm.c.

rpmTransactionSet fsmGetTs | ( | const FSM_t | fsm | ) |

Retrieve transaction set from file state machine iterator.

Parameters:

  | fsm | file state machine data

Returns:
  transaction set

Definition at line 27 of file fsm.c.

int fsmMapAttrs | ( | FSM_t | fsm | ) |

Map file stat(2) info.

Parameters:

  | fsm | file state machine data

Definition at line 616 of file fsm.c.

int fsmMapPath | ( | FSM_t | fsm | ) |

Map next file path and action.

Parameters:

  | fsm | file state machine data

Definition at line 521 of file fsm.c.

static int fsmMkdirs | ( | FSM_t | fsm | ) | `[static]`

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

Parameters:

  | fsm | file state machine data

Returns:
  0 on success

Definition at line 1072 of file fsm.c.

static int fsmRmdirs | ( | FSM_t | fsm | ) | `[static]`

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

Parameters:

  | fsm | file state machine data

Returns:
  0 on success

Definition at line 1021 of file fsm.c.

int fsmSetup | ( | FSM_t | fsm,
|  | fileStage | goal,
|  | const rpmTransactionSet | ts,
|  | const TFI_t | fi,
|  | FD_t | cfd,
|  | unsigned int * | archiveSize,
|  | const char ** | failedFile |
| ) |  |  |

Load external data into file state machine.

Parameters:

  | fsm | file state machine data
  | goal |
  | ts | transaction set
  | fi | transaction element file info
  | archiveSize | pointer to archive size
  | failedFile | pointer to first file name that failed.

Returns:
  0 on success

Definition at line 454 of file fsm.c.

int fsmStage | ( | FSM_t | fsm,
|  | fileStage | stage |
| ) |  |  |

File state machine driver.

Parameters:

  | fsm | file state machine data
  | stage | next stage

Returns:
  0 on success

Definition at line 1205 of file fsm.c.

int fsmTeardown | ( | FSM_t | fsm | ) |

Clean file state machine.

Parameters:

  | fsm | file state machine data

Returns:
  0 on success

Definition at line 504 of file fsm.c.

FSM_t newFSM | ( | void |  | ) |

Create file state machine instance.

Returns:
  file state machine data

Definition at line 432 of file fsm.c.

## Variable Documentation

int _fsm_debug = 0

Definition at line 20 of file fsm.c.

int strict_erasures = 0

Definition at line 24 of file fsm.c.