6 * File state machine to handle a payload within an rpm package.
12 extern int _fsm_debug;
16 #define FSM_VERBOSE 0x8000
17 #define FSM_INTERNAL 0x4000
18 #define FSM_SYSCALL 0x2000
19 #define FSM_DEAD 0x1000
21 #define _fv(_a) ((_a) | FSM_VERBOSE)
22 #define _fi(_a) ((_a) | FSM_INTERNAL)
23 #define _fs(_a) ((_a) | (FSM_INTERNAL | FSM_SYSCALL))
24 #define _fd(_a) ((_a) | (FSM_INTERNAL | FSM_DEAD))
26 typedef enum fileStage_e {
35 FSM_PKGINSTALL = _fd(7),
36 FSM_PKGERASE = _fd(8),
37 FSM_PKGBUILD = _fd(9),
38 FSM_PKGUNDO = _fd(11),
44 FSM_MKLINKS = _fi(21),
46 FSM_DESTROY = _fd(23),
54 FSM_LSETFCON= _fs(39),
59 FSM_SYMLINK = _fs(44),
65 FSM_READLINK= _fs(50),
72 FSM_TRAILER = _fd(69),
86 CPIO_MAP_PATH = (1 << 0),
87 CPIO_MAP_MODE = (1 << 1),
88 CPIO_MAP_UID = (1 << 2),
89 CPIO_MAP_GID = (1 << 3),
90 CPIO_FOLLOW_SYMLINKS= (1 << 4), /*!< only for building. */
91 CPIO_MAP_ABSOLUTE = (1 << 5),
92 CPIO_MAP_ADDDOT = (1 << 6),
93 CPIO_MAP_TYPE = (1 << 8), /*!< only for building. */
94 CPIO_SBIT_CHECK = (1 << 9)
96 typedef rpmFlags cpioMapFlags;
98 typedef struct fsmIterator_s * FSMI_t;
99 typedef struct fsm_s * FSM_t;
100 typedef struct rpmpsm_s * rpmpsm;
102 typedef struct hardLink_s * hardLink_t;
105 * File name and stat information.
108 char * path; /*!< Current file name. */
109 FD_t cfd; /*!< Payload file handle. */
110 rpmcpio_t archive; /*!< cpio archive */
111 char * buf; /*!< read: Buffer. */
112 size_t bufsize; /*!< read: Buffer allocated size. */
113 FSMI_t iter; /*!< File iterator. */
114 int ix; /*!< Current file iterator index. */
115 hardLink_t links; /*!< Pending hard linked file(s). */
116 hardLink_t li; /*!< Current hard linked file(s). */
117 rpm_loff_t * archiveSize; /*!< Pointer to archive size. */
118 char ** failedFile; /*!< First file name that failed. */
119 const char * osuffix; /*!< Old, preserved, file suffix. */
120 const char * nsuffix; /*!< New, created, file suffix. */
121 char * suffix; /*!< Current file suffix. */
122 int postpone; /*!< Skip remaining stages? */
123 int diskchecked; /*!< Has stat(2) been performed? */
124 int exists; /*!< Does current file exist on disk? */
125 int rc; /*!< External file stage return code. */
126 cpioMapFlags mapFlags; /*!< Bit(s) to control mapping. */
127 const char * dirName; /*!< File directory name. */
128 const char * baseName; /*!< File base name. */
129 struct selabel_handle *sehandle; /*!< SELinux label handle (if any). */
131 unsigned fflags; /*!< File flags. */
132 rpmFileAction action; /*!< File disposition. */
133 fileStage goal; /*!< Package state machine goal. */
134 fileStage stage; /*!< External file stage. */
135 fileStage nstage; /*!< Next file stage. */
136 struct stat sb; /*!< Current file stat(2) info. */
137 struct stat osb; /*!< Original file stat(2) info. */
139 rpmpsm psm; /*!< "parent" package state machine */
147 * Execute a file state machine goal
149 * @param ts transaction set
150 * @param fi transaction element file info
152 * @param psm owner psm (or NULL)
153 * @retval archiveSize pointer to archive size
154 * @retval failedFile pointer to first file name that failed (malloced)
155 * @return 0 on success
157 int rpmfsmRun(fileStage goal, rpmts ts, rpmte te, rpmfi fi, FD_t cfd,
158 rpmpsm psm, rpm_loff_t * archiveSize, char ** failedFile);
161 * File state machine driver.
162 * @param fsm file state machine
163 * @param nstage next stage
164 * @return 0 on success
167 int fsmNext(FSM_t fsm, fileStage nstage);
170 void rpmpsmNotify(rpmpsm psm, int what, rpm_loff_t amount);