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_PKGUNDO = _fd(11),
43 FSM_MKLINKS = _fi(21),
45 FSM_DESTROY = _fd(23),
53 FSM_LSETFCON= _fs(39),
58 FSM_SYMLINK = _fs(44),
64 FSM_READLINK= _fs(50),
71 FSM_TRAILER = _fd(69),
85 CPIO_MAP_PATH = (1 << 0),
86 CPIO_MAP_MODE = (1 << 1),
87 CPIO_MAP_UID = (1 << 2),
88 CPIO_MAP_GID = (1 << 3),
89 CPIO_FOLLOW_SYMLINKS= (1 << 4), /*!< only for building. */
90 CPIO_MAP_ABSOLUTE = (1 << 5),
91 CPIO_MAP_ADDDOT = (1 << 6),
92 CPIO_MAP_TYPE = (1 << 8), /*!< only for building. */
93 CPIO_SBIT_CHECK = (1 << 9)
95 typedef rpmFlags cpioMapFlags;
97 typedef struct fsmIterator_s * FSMI_t;
98 typedef struct fsm_s * FSM_t;
99 typedef struct rpmpsm_s * rpmpsm;
101 typedef struct hardLink_s * hardLink_t;
104 * File name and stat information.
107 char * path; /*!< Current file name. */
108 FD_t cfd; /*!< Payload file handle. */
109 char * rdbuf; /*!< read: Buffer. */
110 char * rdb; /*!< read: Buffer allocated. */
111 size_t rdsize; /*!< read: Buffer allocated size. */
112 size_t rdnb; /*!< read: Number of bytes returned. */
113 char * wrbuf; /*!< write: Buffer. */
114 char * wrb; /*!< write: Buffer allocated. */
115 size_t wrsize; /*!< write: Buffer allocated size. */
116 size_t wrlen; /*!< write: Number of bytes requested.*/
117 size_t wrnb; /*!< write: Number of bytes returned. */
118 FSMI_t iter; /*!< File iterator. */
119 int ix; /*!< Current file iterator index. */
120 hardLink_t links; /*!< Pending hard linked file(s). */
121 hardLink_t li; /*!< Current hard linked file(s). */
122 rpm_loff_t * archiveSize; /*!< Pointer to archive size. */
123 rpm_loff_t archivePos; /*!< Current archive position. */
125 char ** failedFile; /*!< First file name that failed. */
126 const char * osuffix; /*!< Old, preserved, file suffix. */
127 const char * nsuffix; /*!< New, created, file suffix. */
128 char * suffix; /*!< Current file suffix. */
129 int postpone; /*!< Skip remaining stages? */
130 int diskchecked; /*!< Has stat(2) been performed? */
131 int exists; /*!< Does current file exist on disk? */
132 int rc; /*!< External file stage return code. */
133 cpioMapFlags mapFlags; /*!< Bit(s) to control mapping. */
134 const char * dirName; /*!< File directory name. */
135 const char * baseName; /*!< File base name. */
136 struct selabel_handle *sehandle; /*!< SELinux label handle (if any). */
138 unsigned fflags; /*!< File flags. */
139 rpmFileAction action; /*!< File disposition. */
140 fileStage goal; /*!< Package state machine goal. */
141 fileStage stage; /*!< External file stage. */
142 fileStage nstage; /*!< Next file stage. */
143 struct stat sb; /*!< Current file stat(2) info. */
144 struct stat osb; /*!< Original file stat(2) info. */
146 rpmpsm psm; /*!< "parent" package state machine */
154 * Execute a file state machine goal
156 * @param ts transaction set
157 * @param fi transaction element file info
159 * @param psm owner psm (or NULL)
160 * @retval archiveSize pointer to archive size
161 * @retval failedFile pointer to first file name that failed (malloced)
162 * @return 0 on success
164 int rpmfsmRun(fileStage goal, rpmts ts, rpmte te, rpmfi fi, FD_t cfd,
165 rpmpsm psm, rpm_loff_t * archiveSize, char ** failedFile);
168 * File state machine driver.
169 * @param fsm file state machine
170 * @param nstage next stage
171 * @return 0 on success
174 int fsmNext(FSM_t fsm, fileStage nstage);
177 void rpmpsmNotify(rpmpsm psm, int what, rpm_loff_t amount);