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