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