Doxygen annotations for config files.
[tools/librpm-tizen.git] / lib / fsm.h
1 #ifndef H_FSM
2 #define H_FSM
3
4 /** \ingroup payload
5  * \file lib/fsm.h
6  * File state machine to handle a payload within an rpm package.
7  */
8
9 #include <rpmlib.h>
10 #include "cpio.h"
11
12 /**
13  */
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 {
23     FSM_UNKNOWN =   0,
24     FSM_INIT    =  _fd(1),
25     FSM_PRE     =  _fd(2),
26     FSM_PROCESS =  _fv(3),
27     FSM_POST    =  _fd(4),
28     FSM_UNDO    =  5,
29     FSM_FINI    =  6,
30
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),
36
37     FSM_CREATE  =  _fd(17),
38     FSM_MAP     =  _fd(18),
39     FSM_MKDIRS  =  _fi(19),
40     FSM_RMDIRS  =  _fi(20),
41     FSM_MKLINKS =  _fi(21),
42     FSM_NOTIFY  =  _fd(22),
43     FSM_DESTROY =  _fd(23),
44     FSM_VERIFY  =  _fd(24),
45     FSM_COMMIT  =  _fd(25),
46
47     FSM_UNLINK  =  _fs(33),
48     FSM_RENAME  =  _fs(34),
49     FSM_MKDIR   =  _fs(35),
50     FSM_RMDIR   =  _fs(36),
51     FSM_CHOWN   =  _fs(37),
52     FSM_LCHOWN  =  _fs(38),
53     FSM_CHMOD   =  _fs(39),
54     FSM_UTIME   =  _fs(40),
55     FSM_SYMLINK =  _fs(41),
56     FSM_LINK    =  _fs(42),
57     FSM_MKFIFO  =  _fs(43),
58     FSM_MKNOD   =  _fs(44),
59     FSM_LSTAT   =  _fs(45),
60     FSM_STAT    =  _fs(46),
61     FSM_READLINK=  _fs(47),
62     FSM_CHROOT  =  _fs(48),
63
64     FSM_NEXT    =  _fd(65),
65     FSM_EAT     =  _fd(66),
66     FSM_POS     =  _fd(67),
67     FSM_PAD     =  _fd(68),
68     FSM_TRAILER =  _fd(69),
69     FSM_HREAD   =  _fd(70),
70     FSM_HWRITE  =  _fd(71),
71     FSM_DREAD   =  _fs(72),
72     FSM_DWRITE  =  _fs(73),
73
74     FSM_ROPEN   =  _fs(129),
75     FSM_READ    =  _fs(130),
76     FSM_RCLOSE  =  _fs(131),
77     FSM_WOPEN   =  _fs(132),
78     FSM_WRITE   =  _fs(133),
79     FSM_WCLOSE  =  _fs(134),
80 } fileStage;
81 #undef  _fv
82 #undef  _fi
83 #undef  _fs
84 #undef  _fd
85
86 /** \ingroup payload
87  * Keeps track of the set of all hard links to a file in an archive.
88  */
89 struct hardLink {
90 /*@owned@*/ struct hardLink * next;
91 /*@owned@*/ const char ** nsuffix;
92 /*@owned@*/ int * filex;
93     dev_t dev;
94     ino_t inode;
95     int nlink;
96     int linksLeft;
97     int linkIndex;
98     int createdPath;
99 };
100
101 /** \ingroup payload
102  * Iterator across package file info, forward on install, backward on erase.
103  */
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. */
110 };
111
112 /** \ingroup payload
113  * File name and stat information.
114  */
115 struct fsm_s {
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. */
164 };
165
166 #ifdef __cplusplus
167 extern "C" {
168 #endif
169
170 /**
171  * Return formatted string representation of file stages.
172  * @param a             file stage
173  * @return              formatted string
174  */
175 /*@observer@*/ const char *const fileStageString(fileStage a);
176
177 /**
178  * Return formatted string representation of file disposition.
179  * @param a             file dispostion
180  * @return              formatted string
181  */
182 /*@observer@*/ const char *const fileActionString(fileAction a);
183
184 /**
185  * Create file state machine instance.
186  * @return              file state machine data
187  */
188 /*@only@*/ /*@null@*/ FSM_t newFSM(void);
189
190 /**
191  * Destroy file state machine instance.
192  * @param fsm           file state machine data
193  * @return              always NULL
194  */
195 /*@null@*/ FSM_t freeFSM(/*@only@*/ /*@null@*/ FSM_t fsm);
196
197 /**
198  * Load external data into file state machine.
199  * @param fsm           file state machine data
200  * @param goal
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
206  */
207 int fsmSetup(FSM_t fsm, fileStage goal,
208         /*@kept@*/ const rpmTransactionSet ts,
209         /*@kept@*/ const TFI_t fi,
210         FD_t cfd,
211         /*@out@*/ unsigned int * archiveSize,
212         /*@out@*/ const char ** failedFile)
213                 /*@modifies fsm, *archiveSize, *failedFile  @*/;
214
215 /**
216  * Clean file state machine.
217  * @param fsm           file state machine data
218  * @return              0 on success
219  */
220 int fsmTeardown(FSM_t fsm)
221                 /*@modifies fsm @*/;
222
223 /**
224  * Retrieve transaction set from file state machine iterator.
225  * @param fsm           file state machine data
226  * @return              transaction set
227  */
228 /*@kept@*/ rpmTransactionSet fsmGetTs(const FSM_t fsm)  /*@*/;
229
230 /**
231  * Retrieve transaction element file info from file state machine iterator.
232  * @param fsm           file state machine data
233  * @return              transaction element file info
234  */
235 /*@kept@*/ TFI_t fsmGetFi(const FSM_t fsm)      /*@*/;
236
237 /**
238  * Map next file path and action.
239  * @param fsm           file state machine data
240  */
241 int fsmMapPath(FSM_t fsm)
242                 /*@modifies fsm @*/;
243
244 /**
245  * Map file stat(2) info.
246  * @param fsm           file state machine data
247  */
248 int fsmMapAttrs(FSM_t fsm)
249                 /*@modifies fsm @*/;
250
251 /**
252  * File state machine driver.
253  * @param fsm           file state machine data
254  * @param stage         next stage
255  * @return              0 on success
256  */
257 int fsmStage(FSM_t fsm, fileStage stage)
258                 /*@modifies fsm @*/;
259
260 #ifdef __cplusplus
261 }
262 #endif
263
264 #endif  /* H_FSM */