6 * File state machine to handle a payload within an rpm package.
11 extern int _fsm_debug;
15 #define FSM_VERBOSE 0x8000
16 #define FSM_INTERNAL 0x4000
17 #define FSM_SYSCALL 0x2000
18 #define FSM_DEAD 0x1000
20 #define _fv(_a) ((_a) | FSM_VERBOSE)
21 #define _fi(_a) ((_a) | FSM_INTERNAL)
22 #define _fs(_a) ((_a) | (FSM_INTERNAL | FSM_SYSCALL))
23 #define _fd(_a) ((_a) | (FSM_INTERNAL | FSM_DEAD))
25 typedef enum fileStage_e {
34 FSM_PKGINSTALL = _fd(7),
35 FSM_PKGERASE = _fd(8),
36 FSM_PKGBUILD = _fd(9),
37 FSM_PKGCOMMIT = _fd(10),
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),
80 FSM_RCLOSE = _fs(131),
92 typedef enum cpioMapFlags_e {
93 CPIO_MAP_PATH = (1 << 0),
94 CPIO_MAP_MODE = (1 << 1),
95 CPIO_MAP_UID = (1 << 2),
96 CPIO_MAP_GID = (1 << 3),
97 CPIO_FOLLOW_SYMLINKS= (1 << 4), /*!< only for building. */
98 CPIO_MAP_ABSOLUTE = (1 << 5),
99 CPIO_MAP_ADDDOT = (1 << 6),
100 CPIO_ALL_HARDLINKS = (1 << 7), /*!< fail if hardlinks are missing. */
101 CPIO_MAP_TYPE = (1 << 8), /*!< only for building. */
102 CPIO_SBIT_CHECK = (1 << 9)
105 typedef struct fsmIterator_s * FSMI_t;
106 typedef struct fsm_s * FSM_t;
108 typedef struct hardLink_s * hardLink_t;
111 * File name and stat information.
114 const char * path; /*!< Current file name. */
115 const char * opath; /*!< Original file name. */
116 FD_t cfd; /*!< Payload file handle. */
117 FD_t rfd; /*!< read: File handle. */
118 char * rdbuf; /*!< read: Buffer. */
119 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 char * wrbuf; /*!< write: Buffer. */
125 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 FSMI_t iter; /*!< File iterator. */
130 int ix; /*!< Current file iterator index. */
131 hardLink_t links; /*!< Pending hard linked file(s). */
132 hardLink_t li; /*!< Current hard linked file(s). */
133 rpm_loff_t * archiveSize; /*!< Pointer to archive size. */
134 char ** failedFile; /*!< First file name that failed. */
135 const char * subdir; /*!< Current file sub-directory. */
136 char subbuf[64]; /* XXX eliminate */
137 const char * osuffix; /*!< Old, preserved, file suffix. */
138 const char * nsuffix; /*!< New, created, file suffix. */
139 const char * suffix; /*!< Current file suffix. */
140 char sufbuf[64]; /* XXX eliminate */
141 short * dnlx; /*!< Last dirpath verified indexes. */
142 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 const char * dirName; /*!< File directory name. */
154 const char * baseName; /*!< File base name. */
155 const char * digest; /*!< Binary checksum (NULL disables). */
156 security_context_t fcontext;/*!< File security context (NULL disables). */
157 pgpHashAlgo digestalgo; /*!< File checksum algorithm */
159 unsigned fflags; /*!< File flags. */
160 rpmFileAction action; /*!< File disposition. */
161 fileStage goal; /*!< Package state machine goal. */
162 fileStage stage; /*!< External file stage. */
163 fileStage nstage; /*!< Next file stage. */
164 struct stat sb; /*!< Current file stat(2) info. */
165 struct stat osb; /*!< Original file stat(2) info. */
173 * Create file state machine instance.
174 * @return file state machine
179 * Destroy file state machine instance.
180 * @param fsm file state machine
181 * @return always NULL
183 FSM_t freeFSM(FSM_t fsm);
186 * Load external data into file state machine.
187 * @param fsm file state machine
189 * @param ts transaction set
190 * @param fi transaction element file info
192 * @retval archiveSize pointer to archive size
193 * @retval failedFile pointer to first file name that failed (malloced)
194 * @return 0 on success
196 int fsmSetup(FSM_t fsm, fileStage goal,
200 rpm_loff_t * archiveSize,
204 * Clean file state machine.
205 * @param fsm file state machine
206 * @return 0 on success
208 int fsmTeardown(FSM_t fsm);
211 * File state machine driver.
212 * @param fsm file state machine
213 * @param nstage next stage
214 * @return 0 on success
216 int fsmNext(FSM_t fsm, fileStage nstage);