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