6 * File state machine to handle a payload within an rpm package.
13 extern int _fsm_debug;
18 #define FSM_VERBOSE 0x8000
19 #define FSM_INTERNAL 0x4000
20 #define FSM_SYSCALL 0x2000
21 #define FSM_DEAD 0x1000
23 #define _fv(_a) ((_a) | FSM_VERBOSE)
24 #define _fi(_a) ((_a) | FSM_INTERNAL)
25 #define _fs(_a) ((_a) | (FSM_INTERNAL | FSM_SYSCALL))
26 #define _fd(_a) ((_a) | (FSM_INTERNAL | FSM_DEAD))
28 typedef enum fileStage_e {
37 FSM_PKGINSTALL = _fd(7),
38 FSM_PKGERASE = _fd(8),
39 FSM_PKGBUILD = _fd(9),
40 FSM_PKGCOMMIT = _fd(10),
41 FSM_PKGUNDO = _fd(11),
47 FSM_MKLINKS = _fi(21),
49 FSM_DESTROY = _fd(23),
61 FSM_SYMLINK = _fs(41),
67 FSM_READLINK= _fs(47),
74 FSM_TRAILER = _fd(69),
82 FSM_RCLOSE = _fs(131),
93 * Keeps track of the set of all hard links to a file in an archive.
96 /*@owned@*/ struct hardLink_s * next;
97 /*@owned@*/ const char ** nsuffix;
98 /*@owned@*/ int * filex;
107 * Iterator across package file info, forward on install, backward on erase.
109 struct fsmIterator_s {
110 rpmts ts; /*!< transaction set. */
111 rpmfi fi; /*!< transaction element file info. */
112 int reverse; /*!< reversed traversal? */
113 int isave; /*!< last returned iterator index. */
114 int i; /*!< iterator index. */
118 * File name and stat information.
122 const char * path; /*!< Current file name. */
124 const char * opath; /*!< Original file name. */
125 FD_t cfd; /*!< Payload file handle. */
126 FD_t rfd; /*!< read: File handle. */
128 char * rdbuf; /*!< read: Buffer. */
130 char * rdb; /*!< read: Buffer allocated. */
131 size_t rdsize; /*!< read: Buffer allocated size. */
132 size_t rdlen; /*!< read: Number of bytes requested.*/
133 size_t rdnb; /*!< read: Number of bytes returned. */
134 FD_t wfd; /*!< write: File handle. */
136 char * wrbuf; /*!< write: Buffer. */
138 char * wrb; /*!< write: Buffer allocated. */
139 size_t wrsize; /*!< write: Buffer allocated size. */
140 size_t wrlen; /*!< write: Number of bytes requested.*/
141 size_t wrnb; /*!< write: Number of bytes returned. */
142 /*@only@*/ /*@null@*/
143 FSMI_t iter; /*!< File iterator. */
144 int ix; /*!< Current file iterator index. */
146 struct hardLink_s * links; /*!< Pending hard linked file(s). */
148 struct hardLink_s * li; /*!< Current hard linked file(s). */
149 /*@kept@*/ /*@null@*/
150 unsigned int * archiveSize; /*!< Pointer to archive size. */
151 /*@kept@*/ /*@null@*/
152 const char ** failedFile; /*!< First file name that failed. */
154 const char * subdir; /*!< Current file sub-directory. */
156 char subbuf[64]; /* XXX eliminate */
158 const char * osuffix; /*!< Old, preserved, file suffix. */
160 const char * nsuffix; /*!< New, created, file suffix. */
162 const char * suffix; /*!< Current file suffix. */
163 char sufbuf[64]; /* XXX eliminate */
164 /*@only@*/ /*@null@*/
165 short * dnlx; /*!< Last dirpath verified indexes. */
166 /*@only@*/ /*@null@*/
167 char * ldn; /*!< Last dirpath verified. */
168 int ldnlen; /*!< Last dirpath current length. */
169 int ldnalloc; /*!< Last dirpath allocated length. */
170 int postpone; /*!< Skip remaining stages? */
171 int diskchecked; /*!< Has stat(2) been performed? */
172 int exists; /*!< Does current file exist on disk? */
173 int mkdirsdone; /*!< Have "orphan" dirs been created? */
174 int astriplen; /*!< Length of buildroot prefix. */
175 int rc; /*!< External file stage return code. */
176 int commit; /*!< Commit synchronously? */
177 cpioMapFlags mapFlags; /*!< Bit(s) to control mapping. */
179 const char * dirName; /*!< File directory name. */
181 const char * baseName; /*!< File base name. */
183 const char * fmd5sum; /*!< Hex MD5 sum (NULL disables). */
185 const char * md5sum; /*!< Binary MD5 sum (NULL disables). */
187 unsigned fflags; /*!< File flags. */
188 fileAction action; /*!< File disposition. */
189 fileStage goal; /*!< Package state machine goal. */
190 fileStage stage; /*!< External file stage. */
191 struct stat sb; /*!< Current file stat(2) info. */
192 struct stat osb; /*!< Original file stat(2) info. */
201 * Return formatted string representation of file stages.
202 * @param a file stage
203 * @return formatted string
205 /*@observer@*/ const char *const fileStageString(fileStage a) /*@*/;
208 * Return formatted string representation of file disposition.
209 * @param a file dispostion
210 * @return formatted string
212 /*@observer@*/ const char *const fileActionString(fileAction a) /*@*/;
216 * Create file state machine instance.
217 * @return file state machine data
219 /*@only@*/ FSM_t newFSM(void)
223 * Destroy file state machine instance.
224 * @param fsm file state machine data
225 * @return always NULL
227 /*@null@*/ FSM_t freeFSM(/*@only@*/ /*@null@*/ FSM_t fsm)
231 * Load external data into file state machine.
232 * @param fsm file state machine data
234 * @param ts transaction set
235 * @param fi transaction element file info
237 * @retval archiveSize pointer to archive size
238 * @retval failedFile pointer to first file name that failed.
239 * @return 0 on success
241 int fsmSetup(FSM_t fsm, fileStage goal,
245 /*@out@*/ unsigned int * archiveSize,
246 /*@out@*/ const char ** failedFile)
247 /*@globals fileSystem @*/
248 /*@modifies fsm, ts, fi, *archiveSize, *failedFile, fileSystem @*/;
251 * Clean file state machine.
252 * @param fsm file state machine data
253 * @return 0 on success
255 int fsmTeardown(FSM_t fsm)
256 /*@globals fileSystem @*/
257 /*@modifies fsm, fileSystem @*/;
261 * Retrieve transaction set from file state machine iterator.
262 * @param fsm file state machine data
263 * @return transaction set
265 rpmts fsmGetTs(const FSM_t fsm)
269 * Retrieve transaction element file info from file state machine iterator.
270 * @param fsm file state machine data
271 * @return transaction element file info
273 rpmfi fsmGetFi(/*@partial@*/ const FSM_t fsm)
277 * Map next file path and action.
278 * @param fsm file state machine data
280 int fsmMapPath(FSM_t fsm)
284 * Map file stat(2) info.
285 * @param fsm file state machine data
287 int fsmMapAttrs(FSM_t fsm)
292 * File state machine driver.
293 * @param fsm file state machine data
294 * @param stage next stage
295 * @return 0 on success
297 int fsmStage(/*@partial@*/ FSM_t fsm, fileStage stage)
298 /*@globals fileSystem @*/
299 /*@modifies fsm, fileSystem @*/;