Start deconstructing availablePackage list.
[platform/upstream/rpm.git] / lib / psm.h
1 #ifndef H_PSM
2 #define H_PSM
3
4 /** \ingroup rpmtrans payload
5  * \file lib/psm.h
6  * Package state machine to handle a package from a transaction set.
7  */
8
9 #include "fsm.h"
10 #include "depends.h"
11
12 /*@unchecked@*/
13 /*@-exportlocal@*/
14 extern int _fi_debug;
15 /*@=exportlocal@*/
16
17 /**
18  */
19 struct sharedFileInfo {
20     int pkgFileNum;
21     int otherFileNum;
22     int otherPkg;
23     int isRemoved;
24 };
25
26 /**
27  */
28 struct transactionFileInfo_s {
29 /*@null@*/ Header h;            /*!< Package header */
30
31 /*@owned@*/ const char * name;  /*!< Name: tag (malloc'd). */
32 /*@owned@*/ const char * version; /*!< Version: tag (malloc'd). */
33 /*@owned@*/ const char * release; /*!< Release: tag (malloc'd). */
34
35 #ifdef  NOTYET
36 /*@owned@*/ const char ** provides;     /*!< Provides: name strings. */
37 /*@owned@*/ const char ** providesEVR;  /*!< Provides: [epoch:]version[-release] strings. */
38 /*@dependent@*/ int * provideFlags;     /*!< Provides: logical range qualifiers. */
39 /*@owned@*//*@null@*/ const char ** requires;   /*!< Requires: name strings. */
40 /*@owned@*//*@null@*/ const char ** requiresEVR;/*!< Requires: [epoch:]version[-release] strings. */
41 /*@dependent@*//*@null@*/ int * requireFlags;   /*!< Requires: logical range qualifiers. */
42 /*@owned@*//*@null@*/ const char ** baseNames;  /*!< Header file basenames. */
43 /*@dependent@*//*@null@*/ int_32 * epoch;       /*!< Header epoch (if any). */
44     int providesCount;                  /*!< No. of Provide:'s in header. */
45     int requiresCount;                  /*!< No. of Require:'s in header. */
46     int filesCount;                     /*!< No. of files in header. */
47     int npreds;                         /*!< No. of predecessors. */
48     int depth;                          /*!< Max. depth in dependency tree. */
49     struct tsortInfo_s tsi;             /*!< Dependency tsort data. */
50 #endif
51
52     uint_32 multiLib;           /* MULTILIB */
53 /*@null@*/
54     const void * key;           /*!< Package notify key. */
55 /*@null@*/ /*@dependent@*/
56     rpmRelocation * relocs;     /*!< Package file relocations. */
57 /*@null@*/
58     FD_t fd;                    /*!< Package file handle */
59
60 /*=============================*/
61
62   /* for all packages */
63     enum rpmTransactionType type;
64     fileAction action;          /*!< File disposition default. */
65 /*@owned@*/ fileAction * actions;       /*!< File disposition(s) */
66 /*@owned@*/ struct fingerPrint_s * fps; /*!< File fingerprint(s) */
67     HGE_t hge;                  /*!< Vector to headerGetEntry() */
68     HAE_t hae;                  /*!< Vector to headerAddEntry() */
69     HME_t hme;                  /*!< Vector to headerModifyEntry() */
70     HRE_t hre;                  /*!< Vector to headerRemoveEntry() */
71     HFD_t hfd;                  /*!< Vector to headerFreeData() */
72     int_32 epoch;
73     uint_32 flags;              /*!< File flag default. */
74     const uint_32 * fflags;     /*!< File flag(s) (from header) */
75     const uint_32 * fsizes;     /*!< File size(s) (from header) */
76     const uint_32 * fmtimes;    /*!< File modification time(s) (from header) */
77 /*@owned@*/ const char ** bnl;  /*!< Base name(s) (from header) */
78 /*@owned@*/ const char ** dnl;  /*!< Directory name(s) (from header) */
79     int_32 * dil;               /*!< Directory indice(s) (from header) */
80 /*@owned@*/ const char ** obnl; /*!< Original base name(s) (from header) */
81 /*@owned@*/ const char ** odnl; /*!< Original directory name(s) (from header) */
82 /*@unused@*/ int_32 * odil;     /*!< Original directory indice(s) (from header) */
83 /*@owned@*/ const char ** fmd5s;/*!< File MD5 sum(s) (from header) */
84 /*@owned@*/ const char ** flinks;       /*!< File link(s) (from header) */
85 /* XXX setuid/setgid bits are turned off if fuser/fgroup doesn't map. */
86     uint_16 * fmodes;           /*!< File mode(s) (from header) */
87     uint_16 * frdevs;           /*!< File rdev(s) (from header) */
88 /*@only@*/ /*@null@*/ char * fstates;   /*!< File state(s) (from header) */
89 /*@owned@*/ const char ** fuser;        /*!< File owner(s) */
90 /*@owned@*/ const char ** fgroup;       /*!< File group(s) */
91 /*@owned@*/ const char ** flangs;       /*!< File lang(s) */
92     int fc;                     /*!< No. of files. */
93     int dc;                     /*!< No. of directories. */
94     int bnlmax;                 /*!< Length (in bytes) of longest base name. */
95     int dnlmax;                 /*!< Length (in bytes) of longest dir name. */
96     int astriplen;
97     int striplen;
98     unsigned int archiveSize;
99     mode_t dperms;              /*!< Directory perms (0755) if not mapped. */
100     mode_t fperms;              /*!< File perms (0644) if not mapped. */
101 /*@only@*/ /*@null@*/ const char ** apath;
102     int mapflags;
103 /*@owned@*/ /*@null@*/ int * fmapflags;
104     uid_t uid;
105 /*@owned@*/ /*@null@*/ uid_t * fuids;   /*!< File uid(s) */
106     gid_t gid;
107 /*@owned@*/ /*@null@*/ gid_t * fgids;   /*!< File gid(s) */
108     int magic;
109
110 #define TFIMAGIC        0x09697923
111 /*@owned@*/ FSM_t fsm;          /*!< File state machine data. */
112
113     int keep_header;            /*!< Keep header? */
114 /*@refs@*/ int nrefs;           /*!< Reference count. */
115
116 /*@owned@*/ struct sharedFileInfo * replaced;   /*!< (TR_ADDED) */
117 /*@owned@*/ uint_32 * replacedSizes;    /*!< (TR_ADDED) */
118
119     unsigned int record;        /*!< (TR_REMOVED) */
120 };
121
122 /**
123  */
124 #define PSM_VERBOSE     0x8000
125 #define PSM_INTERNAL    0x4000
126 #define PSM_SYSCALL     0x2000
127 #define PSM_DEAD        0x1000
128 #define _fv(_a)         ((_a) | PSM_VERBOSE)
129 #define _fi(_a)         ((_a) | PSM_INTERNAL)
130 #define _fs(_a)         ((_a) | (PSM_INTERNAL | PSM_SYSCALL))
131 #define _fd(_a)         ((_a) | (PSM_INTERNAL | PSM_DEAD))
132 typedef enum pkgStage_e {
133     PSM_UNKNOWN         =  0,
134     PSM_INIT            =  1,
135     PSM_PRE             =  2,
136     PSM_PROCESS         =  3,
137     PSM_POST            =  4,
138     PSM_UNDO            =  5,
139     PSM_FINI            =  6,
140
141     PSM_PKGINSTALL      =  7,
142     PSM_PKGERASE        =  8,
143     PSM_PKGCOMMIT       = 10,
144     PSM_PKGSAVE         = 12,
145
146     PSM_CREATE          = 17,
147     PSM_NOTIFY          = 22,
148     PSM_DESTROY         = 23,
149     PSM_COMMIT          = 25,
150
151     PSM_CHROOT_IN       = 51,
152     PSM_CHROOT_OUT      = 52,
153     PSM_SCRIPT          = 53,
154     PSM_TRIGGERS        = 54,
155     PSM_IMMED_TRIGGERS  = 55,
156     PSM_RPMIO_FLAGS     = 56,
157
158     PSM_RPMDB_LOAD      = 97,
159     PSM_RPMDB_ADD       = 98,
160     PSM_RPMDB_REMOVE    = 99,
161
162 } pkgStage;
163 #undef  _fv
164 #undef  _fi
165 #undef  _fs
166 #undef  _fd
167
168 /**
169  */
170 struct psm_s {
171 /*@refcounted@*/
172     rpmTransactionSet ts;       /*!< transaction set */
173 /*@refcounted@*/
174     TFI_t fi;                   /*!< transaction element file info */
175     FD_t cfd;                   /*!< Payload file handle. */
176     FD_t fd;                    /*!< Repackage file handle. */
177     Header oh;                  /*!< Repackage/multilib header. */
178 /*@null@*/ rpmdbMatchIterator mi;
179 /*@observer@*/ const char * stepName;
180 /*@only@*/ /*@null@*/ const char * rpmio_flags;
181 /*@only@*/ /*@null@*/ const char * failedFile;
182 /*@only@*/ /*@null@*/ const char * pkgURL;      /*!< Repackage URL. */
183 /*@dependent@*/ const char * pkgfn;     /*!< Repackage file name. */
184     int scriptTag;              /*!< Scriptlet data tag. */
185     int progTag;                /*!< Scriptlet interpreter tag. */
186     int npkgs_installed;        /*!< No. of installed instances. */
187     int scriptArg;              /*!< Scriptlet package arg. */
188     int sense;                  /*!< One of RPMSENSE_TRIGGER{IN,UN,POSTUN}. */
189     int countCorrection;        /*!< 0 if installing, -1 if removing. */
190     int chrootDone;             /*!< Was chroot(2) done by pkgStage? */
191     rpmCallbackType what;       /*!< Callback type. */
192     unsigned long amount;       /*!< Callback amount. */
193     unsigned long total;        /*!< Callback total. */
194     rpmRC rc;
195     pkgStage goal;
196 /*@unused@*/ pkgStage stage;
197 };
198
199 #ifdef __cplusplus
200 extern "C" {
201 #endif
202
203 /**
204  * Return (malloc'd) transaction element name-version-release string.
205  * @param fi            transaction element file info
206  * @return              name-version-release string
207  */
208 /*@only@*/ /*@null@*/
209 char * fiGetNVR(/*@null@*/const TFI_t fi)
210         /*@*/;
211
212 /**
213  * Return file type from mode_t.
214  * @param mode          file mode bits (from header)
215  * @return              file type
216  */
217 fileTypes whatis(uint_16 mode)
218         /*@*/;
219
220 /**
221  * Relocate files in header.
222  * @todo multilib file dispositions need to be checked.
223  * @param ts            transaction set
224  * @param fi            transaction element file info
225  * @param origH         package header
226  * @param actions       file dispositions
227  * @return              header with relocated files
228  */
229 Header relocateFileList(const rpmTransactionSet ts, TFI_t fi,
230                 Header origH, fileAction * actions)
231         /*@modifies ts, fi, origH, actions @*/;
232
233 /**
234  * Load data from header into transaction file element info.
235  * @param ts            transaction set
236  * @param fi            transaction element file info
237  * @param h             header
238  * @param keep_header   use header memory?
239  */
240 void loadFi(/*@null@*/ const rpmTransactionSet ts, TFI_t fi,
241                 Header h, int keep_header)
242         /*@modifies ts, fi, h @*/;
243
244 /**
245  * Destroy transaction element file info.
246  * @param fi            transaction element file info
247  */
248 void freeFi(TFI_t fi)
249         /*@modifies fi @*/;
250
251 /**
252  * Retrieve key from transaction element file info
253  * @param fi            transaction element file info
254  * @return              transaction element file info key
255  */
256 /*@null@*/ const void * rpmfiGetKey(TFI_t fi)
257         /*@*/;
258
259 /**
260  * Return formatted string representation of package disposition.
261  * @param a             package dispostion
262  * @return              formatted string
263  */
264 /*@observer@*/ const char *const fiTypeString(/*@partial@*/TFI_t fi)
265         /*@*/;
266
267 /**
268  * Package state machine driver.
269  * @param psm           package state machine data
270  * @param stage         next stage
271  * @return              0 on success
272  */
273 int psmStage(PSM_t psm, pkgStage stage)
274         /*@globals rpmGlobalMacroContext,
275                 fileSystem, internalState @*/
276         /*@modifies psm, rpmGlobalMacroContext, fileSystem, internalState @*/;
277
278 #ifdef __cplusplus
279 }
280 #endif
281
282 #endif  /* H_ROLLBACK */