6 * File state machine to handle a payload within an rpm package.
14 #define FSM_VERBOSE 0x8000
15 #define FSM_INTERNAL 0x4000
16 #define FSM_SYSCALL 0x2000
17 #define FSM_DEAD 0x1000
18 #define _fv(_a) ((_a) | FSM_VERBOSE)
19 #define _fi(_a) ((_a) | FSM_INTERNAL)
20 #define _fs(_a) ((_a) | (FSM_INTERNAL | FSM_SYSCALL))
21 #define _fd(_a) ((_a) | (FSM_INTERNAL | FSM_DEAD))
22 typedef enum fileStage_e {
31 FSM_PKGINSTALL = _fd(7),
32 FSM_PKGERASE = _fd(8),
33 FSM_PKGBUILD = _fd(9),
34 FSM_PKGCOMMIT = _fd(10),
35 FSM_PKGUNDO = _fd(11),
41 FSM_MKLINKS = _fi(21),
43 FSM_DESTROY = _fd(23),
55 FSM_SYMLINK = _fs(41),
61 FSM_READLINK= _fs(47),
68 FSM_TRAILER = _fd(69),
76 FSM_RCLOSE = _fs(131),
79 FSM_WCLOSE = _fs(134),
87 * Keeps track of the set of all hard links to a file in an archive.
90 /*@owned@*/ struct hardLink * next;
91 /*@owned@*/ const char ** nsuffix;
92 /*@owned@*/ int * filex;
102 * Iterator across package file info, forward on install, backward on erase.
104 struct fsmIterator_s {
105 /*@kept@*/ rpmTransactionSet ts; /*!< transaction set. */
106 /*@kept@*/ TFI_t fi; /*!< transaction element file info. */
107 int reverse; /*!< reversed traversal? */
108 int isave; /*!< last returned iterator index. */
109 int i; /*!< iterator index. */
113 * File name and stat information.
116 /*@owned@*/ const char * path; /*!< Current file name. */
117 /*@owned@*/ const char * opath; /*!< Original file name. */
118 FD_t cfd; /*!< Payload file handle. */
119 FD_t rfd; /*!< read: File handle. */
120 /*@dependent@*/ char * rdbuf; /*!< read: Buffer. */
121 /*@owned@*/ char * rdb; /*!< read: Buffer allocated. */
122 size_t rdsize; /*!< read: Buffer allocated size. */
123 size_t rdlen; /*!< read: Number of bytes requested. */
124 size_t rdnb; /*!< read: Number of bytes returned. */
125 FD_t wfd; /*!< write: File handle. */
126 /*@dependent@*/ char * wrbuf; /*!< write: Buffer. */
127 /*@owned@*/ char * wrb; /*!< write: Buffer allocated. */
128 size_t wrsize; /*!< write: Buffer allocated size. */
129 size_t wrlen; /*!< write: Number of bytes requested. */
130 size_t wrnb; /*!< write: Number of bytes returned. */
131 /*@only@*/ FSMI_t iter; /*!< File iterator. */
132 int ix; /*!< Current file iterator index. */
133 /*@only@*/ struct hardLink * links; /*!< Pending hard linked file(s). */
134 /*@only@*/ struct hardLink * li; /*!< Current hard linked file(s). */
135 /*@kept@*/ unsigned int * archiveSize; /*!< Pointer to archive size. */
136 /*@kept@*/ const char ** failedFile; /*!< First file name that failed. */
137 /*@shared@*/ const char * subdir; /*!< Current file sub-directory. */
138 char subbuf[64]; /* XXX eliminate */
139 /*@observer@*/ const char * osuffix; /*!< Old, preserved, file suffix. */
140 /*@observer@*/ const char * nsuffix; /*!< New, created, file suffix. */
141 /*@shared@*/ const char * suffix; /*!< Current file suffix. */
142 char sufbuf[64]; /* XXX eliminate */
143 /*@only@*/ short * dnlx; /*!< Last dirpath verified indexes. */
144 /*@only@*/ char * ldn; /*!< Last dirpath verified. */
145 int ldnlen; /*!< Last dirpath current length. */
146 int ldnalloc; /*!< Last dirpath allocated length. */
147 int postpone; /*!< Skip remaining stages? */
148 int diskchecked; /*!< Has stat(2) been performed? */
149 int exists; /*!< Does current file exist on disk? */
150 int mkdirsdone; /*!< Have "orphan" dirs been created? */
151 int astriplen; /*!< Length of buildroot prefix. */
152 int rc; /*!< External file stage return code. */
153 int commit; /*!< Commit synchronously? */
154 cpioMapFlags mapFlags; /*!< Bit(s) to control mapping. */
155 /*@shared@*/ const char * dirName; /*!< File directory name. */
156 /*@shared@*/ const char * baseName; /*!< File base name. */
157 /*@shared@*/ const char * fmd5sum; /*!< File MD5 sum (NULL disables). */
158 unsigned fflags; /*!< File flags. */
159 fileAction action; /*!< File disposition. */
160 fileStage goal; /*!< Package state machine goal. */
161 fileStage stage; /*!< External file stage. */
162 struct stat sb; /*!< Current file stat(2) info. */
163 struct stat osb; /*!< Original file stat(2) info. */
171 * Return formatted string representation of file stages.
172 * @param a file stage
173 * @return formatted string
175 /*@observer@*/ const char *const fileStageString(fileStage a);
178 * Return formatted string representation of file disposition.
179 * @param a file dispostion
180 * @return formatted string
182 /*@observer@*/ const char *const fileActionString(fileAction a);
185 * Create file state machine instance.
186 * @return file state machine data
188 /*@only@*/ /*@null@*/ FSM_t newFSM(void);
191 * Destroy file state machine instance.
192 * @param fsm file state machine data
193 * @return always NULL
195 /*@null@*/ FSM_t freeFSM(/*@only@*/ /*@null@*/ FSM_t fsm);
198 * Load external data into file state machine.
199 * @param fsm file state machine data
201 * @param ts transaction set
202 * @param fi transaction element file info
203 * @param archiveSize pointer to archive size
204 * @param failedFile pointer to first file name that failed.
205 * @return 0 on success
207 int fsmSetup(FSM_t fsm, fileStage goal,
208 /*@kept@*/ const rpmTransactionSet ts,
209 /*@kept@*/ const TFI_t fi,
211 /*@out@*/ unsigned int * archiveSize,
212 /*@out@*/ const char ** failedFile)
213 /*@modifies fsm, *archiveSize, *failedFile @*/;
216 * Clean file state machine.
217 * @param fsm file state machine data
218 * @return 0 on success
220 int fsmTeardown(FSM_t fsm)
224 * Retrieve transaction set from file state machine iterator.
225 * @param fsm file state machine data
226 * @return transaction set
228 /*@kept@*/ rpmTransactionSet fsmGetTs(const FSM_t fsm) /*@*/;
231 * Retrieve transaction element file info from file state machine iterator.
232 * @param fsm file state machine data
233 * @return transaction element file info
235 /*@kept@*/ TFI_t fsmGetFi(const FSM_t fsm) /*@*/;
238 * Map next file path and action.
239 * @param fsm file state machine data
241 int fsmMapPath(FSM_t fsm)
245 * Map file stat(2) info.
246 * @param fsm file state machine data
248 int fsmMapAttrs(FSM_t fsm)
252 * File state machine driver.
253 * @param fsm file state machine data
254 * @param stage next stage
255 * @return 0 on success
257 int fsmStage(FSM_t fsm, fileStage stage)