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),
73 FSM_TRAILER = _fd(69),
81 FSM_RCLOSE = _fs(131),
93 typedef enum cpioMapFlags_e {
94 CPIO_MAP_PATH = (1 << 0),
95 CPIO_MAP_MODE = (1 << 1),
96 CPIO_MAP_UID = (1 << 2),
97 CPIO_MAP_GID = (1 << 3),
98 CPIO_FOLLOW_SYMLINKS= (1 << 4), /*!< only for building. */
99 CPIO_MAP_ABSOLUTE = (1 << 5),
100 CPIO_MAP_ADDDOT = (1 << 6),
101 CPIO_ALL_HARDLINKS = (1 << 7), /*!< fail if hardlinks are missing. */
102 CPIO_MAP_TYPE = (1 << 8), /*!< only for building. */
103 CPIO_SBIT_CHECK = (1 << 9)
106 typedef struct fsmIterator_s * FSMI_t;
107 typedef struct fsm_s * FSM_t;
109 typedef struct hardLink_s * hardLink_t;
112 * File name and stat information.
115 const char * path; /*!< Current file name. */
116 const char * opath; /*!< Original file name. */
117 FD_t cfd; /*!< Payload file handle. */
118 FD_t rfd; /*!< read: File handle. */
119 char * rdbuf; /*!< read: Buffer. */
120 char * rdb; /*!< read: Buffer allocated. */
121 size_t rdsize; /*!< read: Buffer allocated size. */
122 size_t rdlen; /*!< read: Number of bytes requested.*/
123 size_t rdnb; /*!< read: Number of bytes returned. */
124 FD_t wfd; /*!< write: File handle. */
125 char * wrbuf; /*!< write: Buffer. */
126 char * wrb; /*!< write: Buffer allocated. */
127 size_t wrsize; /*!< write: Buffer allocated size. */
128 size_t wrlen; /*!< write: Number of bytes requested.*/
129 size_t wrnb; /*!< write: Number of bytes returned. */
130 FSMI_t iter; /*!< File iterator. */
131 int ix; /*!< Current file iterator index. */
132 hardLink_t links; /*!< Pending hard linked file(s). */
133 hardLink_t li; /*!< Current hard linked file(s). */
134 rpm_loff_t * archiveSize; /*!< Pointer to archive size. */
135 rpm_loff_t archivePos; /*!< Current archive position. */
136 char ** failedFile; /*!< First file name that failed. */
137 const char * subdir; /*!< Current file sub-directory. */
138 const char * osuffix; /*!< Old, preserved, file suffix. */
139 const char * nsuffix; /*!< New, created, file suffix. */
140 const char * suffix; /*!< Current file suffix. */
141 char sufbuf[64]; /* XXX eliminate */
142 short * dnlx; /*!< Last dirpath verified indexes. */
143 char * ldn; /*!< Last dirpath verified. */
144 int ldnlen; /*!< Last dirpath current length. */
145 int ldnalloc; /*!< Last dirpath allocated length. */
146 int postpone; /*!< Skip remaining stages? */
147 int diskchecked; /*!< Has stat(2) been performed? */
148 int exists; /*!< Does current file exist on disk? */
149 int mkdirsdone; /*!< Have "orphan" dirs been created? */
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 unsigned char * digest; /*!< Binary digest (NULL disables). */
156 security_context_t fcontext;/*!< File security context (NULL disables). */
157 cap_t fcaps; /*!< File capabilities */
158 pgpHashAlgo digestalgo; /*!< File digest algorithm */
160 unsigned fflags; /*!< File flags. */
161 rpmFileAction action; /*!< File disposition. */
162 fileStage goal; /*!< Package state machine goal. */
163 fileStage stage; /*!< External file stage. */
164 fileStage nstage; /*!< Next file stage. */
165 struct stat sb; /*!< Current file stat(2) info. */
166 struct stat osb; /*!< Original file stat(2) info. */
174 * Create file state machine instance.
175 * @param mapflags CPIO map flags to use
176 * @return file state machine
179 FSM_t newFSM(cpioMapFlags mapflags);
182 * Destroy file state machine instance.
183 * @param fsm file state machine
184 * @return always NULL
187 FSM_t freeFSM(FSM_t fsm);
190 * Load external data into file state machine.
191 * @param fsm file state machine
193 * @param ts transaction set
194 * @param fi transaction element file info
196 * @retval archiveSize pointer to archive size
197 * @retval failedFile pointer to first file name that failed (malloced)
198 * @return 0 on success
200 int fsmSetup(FSM_t fsm, fileStage goal,
205 rpm_loff_t * archiveSize,
209 * Clean file state machine.
210 * @param fsm file state machine
211 * @return 0 on success
213 int fsmTeardown(FSM_t fsm);
216 * File state machine driver.
217 * @param fsm file state machine
218 * @param nstage next stage
219 * @return 0 on success
222 int fsmNext(FSM_t fsm, fileStage nstage);