2001-02-11 00:47:40 +08:00
|
|
|
#ifndef H_FSM
|
|
|
|
#define H_FSM
|
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
/** \ingroup payload
|
|
|
|
* \file lib/fsm.h
|
|
|
|
* File state machine to handle a payload within an rpm package.
|
2001-02-11 00:47:40 +08:00
|
|
|
*/
|
|
|
|
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmfi.h>
|
2001-02-11 00:47:40 +08:00
|
|
|
|
2001-10-18 00:43:36 +08:00
|
|
|
extern int _fsm_debug;
|
|
|
|
|
2001-02-11 00:47:40 +08:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
#define FSM_VERBOSE 0x8000
|
|
|
|
#define FSM_INTERNAL 0x4000
|
|
|
|
#define FSM_SYSCALL 0x2000
|
|
|
|
#define FSM_DEAD 0x1000
|
2002-01-12 07:03:22 +08:00
|
|
|
|
2001-02-11 00:47:40 +08:00
|
|
|
#define _fv(_a) ((_a) | FSM_VERBOSE)
|
|
|
|
#define _fi(_a) ((_a) | FSM_INTERNAL)
|
|
|
|
#define _fs(_a) ((_a) | (FSM_INTERNAL | FSM_SYSCALL))
|
|
|
|
#define _fd(_a) ((_a) | (FSM_INTERNAL | FSM_DEAD))
|
2002-01-12 07:03:22 +08:00
|
|
|
|
2001-02-11 00:47:40 +08:00
|
|
|
typedef enum fileStage_e {
|
|
|
|
FSM_UNKNOWN = 0,
|
|
|
|
FSM_INIT = _fd(1),
|
|
|
|
FSM_PRE = _fd(2),
|
|
|
|
FSM_PROCESS = _fv(3),
|
|
|
|
FSM_POST = _fd(4),
|
|
|
|
FSM_UNDO = 5,
|
|
|
|
FSM_FINI = 6,
|
|
|
|
|
|
|
|
FSM_PKGINSTALL = _fd(7),
|
|
|
|
FSM_PKGERASE = _fd(8),
|
|
|
|
FSM_PKGBUILD = _fd(9),
|
|
|
|
FSM_PKGUNDO = _fd(11),
|
|
|
|
|
|
|
|
FSM_CREATE = _fd(17),
|
|
|
|
FSM_MAP = _fd(18),
|
|
|
|
FSM_MKDIRS = _fi(19),
|
|
|
|
FSM_RMDIRS = _fi(20),
|
|
|
|
FSM_MKLINKS = _fi(21),
|
|
|
|
FSM_NOTIFY = _fd(22),
|
|
|
|
FSM_DESTROY = _fd(23),
|
|
|
|
FSM_VERIFY = _fd(24),
|
|
|
|
FSM_COMMIT = _fd(25),
|
|
|
|
|
|
|
|
FSM_UNLINK = _fs(33),
|
|
|
|
FSM_RENAME = _fs(34),
|
|
|
|
FSM_MKDIR = _fs(35),
|
|
|
|
FSM_RMDIR = _fs(36),
|
2003-12-26 07:00:44 +08:00
|
|
|
FSM_LSETFCON= _fs(39),
|
|
|
|
FSM_CHOWN = _fs(40),
|
|
|
|
FSM_LCHOWN = _fs(41),
|
|
|
|
FSM_CHMOD = _fs(42),
|
|
|
|
FSM_UTIME = _fs(43),
|
|
|
|
FSM_SYMLINK = _fs(44),
|
|
|
|
FSM_LINK = _fs(45),
|
|
|
|
FSM_MKFIFO = _fs(46),
|
|
|
|
FSM_MKNOD = _fs(47),
|
|
|
|
FSM_LSTAT = _fs(48),
|
|
|
|
FSM_STAT = _fs(49),
|
|
|
|
FSM_READLINK= _fs(50),
|
2008-10-29 17:49:38 +08:00
|
|
|
FSM_SETCAP = _fs(52),
|
2001-02-11 00:47:40 +08:00
|
|
|
|
|
|
|
FSM_NEXT = _fd(65),
|
|
|
|
FSM_EAT = _fd(66),
|
|
|
|
FSM_POS = _fd(67),
|
|
|
|
FSM_PAD = _fd(68),
|
|
|
|
FSM_TRAILER = _fd(69),
|
|
|
|
FSM_HREAD = _fd(70),
|
|
|
|
FSM_HWRITE = _fd(71),
|
|
|
|
FSM_DREAD = _fs(72),
|
|
|
|
FSM_DWRITE = _fs(73),
|
|
|
|
|
|
|
|
FSM_ROPEN = _fs(129),
|
|
|
|
FSM_READ = _fs(130),
|
|
|
|
FSM_RCLOSE = _fs(131),
|
|
|
|
FSM_WOPEN = _fs(132),
|
|
|
|
FSM_WRITE = _fs(133),
|
2001-12-21 00:28:46 +08:00
|
|
|
FSM_WCLOSE = _fs(134)
|
2001-02-11 00:47:40 +08:00
|
|
|
} fileStage;
|
|
|
|
#undef _fv
|
|
|
|
#undef _fi
|
|
|
|
#undef _fs
|
|
|
|
#undef _fd
|
|
|
|
|
2007-12-17 19:39:14 +08:00
|
|
|
/** \ingroup payload
|
|
|
|
*/
|
2010-09-21 16:10:14 +08:00
|
|
|
enum cpioMapFlags_e {
|
2007-12-17 19:39:14 +08:00
|
|
|
CPIO_MAP_PATH = (1 << 0),
|
|
|
|
CPIO_MAP_MODE = (1 << 1),
|
|
|
|
CPIO_MAP_UID = (1 << 2),
|
|
|
|
CPIO_MAP_GID = (1 << 3),
|
|
|
|
CPIO_FOLLOW_SYMLINKS= (1 << 4), /*!< only for building. */
|
|
|
|
CPIO_MAP_ABSOLUTE = (1 << 5),
|
|
|
|
CPIO_MAP_ADDDOT = (1 << 6),
|
|
|
|
CPIO_ALL_HARDLINKS = (1 << 7), /*!< fail if hardlinks are missing. */
|
|
|
|
CPIO_MAP_TYPE = (1 << 8), /*!< only for building. */
|
|
|
|
CPIO_SBIT_CHECK = (1 << 9)
|
2010-09-21 16:10:14 +08:00
|
|
|
};
|
|
|
|
typedef rpmFlags cpioMapFlags;
|
2007-12-17 19:39:14 +08:00
|
|
|
|
|
|
|
typedef struct fsmIterator_s * FSMI_t;
|
|
|
|
typedef struct fsm_s * FSM_t;
|
2012-01-05 20:24:33 +08:00
|
|
|
typedef struct rpmpsm_s * rpmpsm;
|
2007-12-17 19:39:14 +08:00
|
|
|
|
2007-12-17 19:15:53 +08:00
|
|
|
typedef struct hardLink_s * hardLink_t;
|
2001-02-11 00:47:40 +08:00
|
|
|
|
|
|
|
/** \ingroup payload
|
|
|
|
* File name and stat information.
|
|
|
|
*/
|
|
|
|
struct fsm_s {
|
2009-12-16 15:43:55 +08:00
|
|
|
char * path; /*!< Current file name. */
|
|
|
|
char * opath; /*!< Original file name. */
|
2001-11-19 01:49:21 +08:00
|
|
|
FD_t cfd; /*!< Payload file handle. */
|
|
|
|
FD_t rfd; /*!< read: File handle. */
|
|
|
|
char * rdbuf; /*!< read: Buffer. */
|
|
|
|
char * rdb; /*!< read: Buffer allocated. */
|
|
|
|
size_t rdsize; /*!< read: Buffer allocated size. */
|
|
|
|
size_t rdlen; /*!< read: Number of bytes requested.*/
|
|
|
|
size_t rdnb; /*!< read: Number of bytes returned. */
|
|
|
|
FD_t wfd; /*!< write: File handle. */
|
|
|
|
char * wrbuf; /*!< write: Buffer. */
|
|
|
|
char * wrb; /*!< write: Buffer allocated. */
|
|
|
|
size_t wrsize; /*!< write: Buffer allocated size. */
|
|
|
|
size_t wrlen; /*!< write: Number of bytes requested.*/
|
|
|
|
size_t wrnb; /*!< write: Number of bytes returned. */
|
|
|
|
FSMI_t iter; /*!< File iterator. */
|
|
|
|
int ix; /*!< Current file iterator index. */
|
2007-12-17 19:15:53 +08:00
|
|
|
hardLink_t links; /*!< Pending hard linked file(s). */
|
|
|
|
hardLink_t li; /*!< Current hard linked file(s). */
|
2008-06-09 17:29:07 +08:00
|
|
|
rpm_loff_t * archiveSize; /*!< Pointer to archive size. */
|
2008-11-11 19:53:31 +08:00
|
|
|
rpm_loff_t archivePos; /*!< Current archive position. */
|
2009-10-14 22:03:14 +08:00
|
|
|
rpm_loff_t cpioPos;
|
2007-12-18 16:10:03 +08:00
|
|
|
char ** failedFile; /*!< First file name that failed. */
|
2001-11-19 01:49:21 +08:00
|
|
|
const char * subdir; /*!< Current file sub-directory. */
|
|
|
|
const char * osuffix; /*!< Old, preserved, file suffix. */
|
|
|
|
const char * nsuffix; /*!< New, created, file suffix. */
|
|
|
|
const char * suffix; /*!< Current file suffix. */
|
2001-02-11 00:47:40 +08:00
|
|
|
char sufbuf[64]; /* XXX eliminate */
|
2001-11-19 01:49:21 +08:00
|
|
|
short * dnlx; /*!< Last dirpath verified indexes. */
|
|
|
|
char * ldn; /*!< Last dirpath verified. */
|
|
|
|
int ldnlen; /*!< Last dirpath current length. */
|
|
|
|
int ldnalloc; /*!< Last dirpath allocated length. */
|
|
|
|
int postpone; /*!< Skip remaining stages? */
|
|
|
|
int diskchecked; /*!< Has stat(2) been performed? */
|
|
|
|
int exists; /*!< Does current file exist on disk? */
|
|
|
|
int mkdirsdone; /*!< Have "orphan" dirs been created? */
|
|
|
|
int rc; /*!< External file stage return code. */
|
|
|
|
cpioMapFlags mapFlags; /*!< Bit(s) to control mapping. */
|
|
|
|
const char * dirName; /*!< File directory name. */
|
|
|
|
const char * baseName; /*!< File base name. */
|
2009-02-27 21:34:39 +08:00
|
|
|
const unsigned char * digest; /*!< Binary digest (NULL disables). */
|
2008-07-03 22:14:45 +08:00
|
|
|
security_context_t fcontext;/*!< File security context (NULL disables). */
|
2010-01-05 19:29:52 +08:00
|
|
|
void *fcaps; /*!< File capabilities */
|
2009-02-27 21:34:39 +08:00
|
|
|
pgpHashAlgo digestalgo; /*!< File digest algorithm */
|
2001-11-19 01:49:21 +08:00
|
|
|
|
|
|
|
unsigned fflags; /*!< File flags. */
|
2007-09-20 21:19:25 +08:00
|
|
|
rpmFileAction action; /*!< File disposition. */
|
2001-11-19 01:49:21 +08:00
|
|
|
fileStage goal; /*!< Package state machine goal. */
|
|
|
|
fileStage stage; /*!< External file stage. */
|
2003-03-19 11:00:02 +08:00
|
|
|
fileStage nstage; /*!< Next file stage. */
|
2001-11-19 01:49:21 +08:00
|
|
|
struct stat sb; /*!< Current file stat(2) info. */
|
|
|
|
struct stat osb; /*!< Original file stat(2) info. */
|
2012-01-05 20:24:33 +08:00
|
|
|
|
|
|
|
rpmpsm psm; /*!< "parent" package state machine */
|
2001-02-11 00:47:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create file state machine instance.
|
2008-11-12 02:48:35 +08:00
|
|
|
* @param mapflags CPIO map flags to use
|
2003-04-03 05:16:26 +08:00
|
|
|
* @return file state machine
|
2001-02-11 00:47:40 +08:00
|
|
|
*/
|
2008-10-09 20:35:36 +08:00
|
|
|
RPM_GNUC_INTERNAL
|
2008-11-12 02:48:35 +08:00
|
|
|
FSM_t newFSM(cpioMapFlags mapflags);
|
2001-02-11 00:47:40 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy file state machine instance.
|
2003-04-03 05:16:26 +08:00
|
|
|
* @param fsm file state machine
|
2001-02-11 00:47:40 +08:00
|
|
|
* @return always NULL
|
|
|
|
*/
|
2008-10-09 20:35:36 +08:00
|
|
|
RPM_GNUC_INTERNAL
|
2007-09-12 01:07:39 +08:00
|
|
|
FSM_t freeFSM(FSM_t fsm);
|
2001-02-11 00:47:40 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load external data into file state machine.
|
2003-04-03 05:16:26 +08:00
|
|
|
* @param fsm file state machine
|
2001-02-11 00:47:40 +08:00
|
|
|
* @param goal
|
|
|
|
* @param ts transaction set
|
|
|
|
* @param fi transaction element file info
|
2002-04-09 02:56:01 +08:00
|
|
|
* @param cfd
|
2012-01-05 20:24:33 +08:00
|
|
|
* @param psm owner psm (or NULL)
|
2002-06-10 06:15:16 +08:00
|
|
|
* @retval archiveSize pointer to archive size
|
2007-12-18 16:10:03 +08:00
|
|
|
* @retval failedFile pointer to first file name that failed (malloced)
|
2001-02-11 00:47:40 +08:00
|
|
|
* @return 0 on success
|
|
|
|
*/
|
|
|
|
int fsmSetup(FSM_t fsm, fileStage goal,
|
2008-11-26 22:01:40 +08:00
|
|
|
rpmts ts,
|
2008-11-26 22:08:04 +08:00
|
|
|
rpmte te,
|
2008-11-26 22:01:40 +08:00
|
|
|
rpmfi fi,
|
2001-05-06 03:28:32 +08:00
|
|
|
FD_t cfd,
|
2012-01-05 20:24:33 +08:00
|
|
|
rpmpsm psm,
|
2008-06-09 17:29:07 +08:00
|
|
|
rpm_loff_t * archiveSize,
|
2007-12-18 16:10:03 +08:00
|
|
|
char ** failedFile);
|
2001-02-11 00:47:40 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean file state machine.
|
2003-04-03 05:16:26 +08:00
|
|
|
* @param fsm file state machine
|
2001-02-11 00:47:40 +08:00
|
|
|
* @return 0 on success
|
|
|
|
*/
|
2007-09-12 01:07:39 +08:00
|
|
|
int fsmTeardown(FSM_t fsm);
|
2001-02-11 00:47:40 +08:00
|
|
|
|
2003-04-03 05:16:26 +08:00
|
|
|
/**
|
|
|
|
* File state machine driver.
|
|
|
|
* @param fsm file state machine
|
|
|
|
* @param nstage next stage
|
|
|
|
* @return 0 on success
|
|
|
|
*/
|
2008-10-09 20:35:36 +08:00
|
|
|
RPM_GNUC_INTERNAL
|
2007-09-12 01:07:39 +08:00
|
|
|
int fsmNext(FSM_t fsm, fileStage nstage);
|
2003-03-19 11:00:02 +08:00
|
|
|
|
2001-02-11 00:47:40 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* H_FSM */
|