- fix typos in linux.{req,prov}.
[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 <rpmlib.h>
10 #include "depends.h"
11 #include "fsm.h"
12
13 /**
14  */
15 struct sharedFileInfo {
16     int pkgFileNum;
17     int otherFileNum;
18     int otherPkg;
19     int isRemoved;
20 };
21
22 /**
23  */
24 struct transactionFileInfo_s {
25   /* for all packages */
26     enum rpmTransactionType type;
27     fileAction action;          /*!< File disposition default. */
28 /*@owned@*/ fileAction * actions;       /*!< File disposition(s) */
29 /*@owned@*/ struct fingerPrint_s * fps; /*!< File fingerprint(s) */
30     HGE_t hge;                  /*!< Vector to headerGetEntry() */
31     HFD_t hfd;                  /*!< Vector to headerFreeData() */
32     Header h;                   /*!< Package header */
33 /*@owned@*/ const char * name;
34 /*@owned@*/ const char * version;
35 /*@owned@*/ const char * release;
36     int_32 epoch;
37     uint_32 flags;              /*!< File flag default. */
38     const uint_32 * fflags;     /*!< File flag(s) (from header) */
39     const uint_32 * fsizes;     /*!< File size(s) (from header) */
40     const uint_32 * fmtimes;    /*!< File modification time(s) (from header) */
41 /*@owned@*/ const char ** bnl;  /*!< Base name(s) (from header) */
42 /*@owned@*/ const char ** dnl;  /*!< Directory name(s) (from header) */
43     int_32 * dil;               /*!< Directory indice(s) (from header) */
44 /*@owned@*/ const char ** obnl; /*!< Original base name(s) (from header) */
45 /*@owned@*/ const char ** odnl; /*!< Original directory name(s) (from header) */
46 /*@unused@*/ int_32 * odil;     /*!< Original directory indice(s) (from header) */
47 /*@owned@*/ const char ** fmd5s;/*!< File MD5 sum(s) (from header) */
48 /*@owned@*/ const char ** flinks;       /*!< File link(s) (from header) */
49 /* XXX setuid/setgid bits are turned off if fuser/fgroup doesn't map. */
50     uint_16 * fmodes;           /*!< File mode(s) (from header) */
51 /*@only@*/ /*@null@*/ char * fstates;   /*!< File state(s) (from header) */
52 /*@owned@*/ const char ** fuser;        /*!< File owner(s) */
53 /*@owned@*/ const char ** fgroup;       /*!< File group(s) */
54 /*@owned@*/ const char ** flangs;       /*!< File lang(s) */
55     int fc;                     /*!< No. of files. */
56     int dc;                     /*!< No. of directories. */
57     int bnlmax;                 /*!< Length (in bytes) of longest base name. */
58     int dnlmax;                 /*!< Length (in bytes) of longest dir name. */
59     int astriplen;
60     int striplen;
61     unsigned int archiveSize;
62     mode_t dperms;              /*!< Directory perms (0755) if not mapped. */
63     mode_t fperms;              /*!< File perms (0644) if not mapped. */
64 /*@only@*/ /*@null@*/ const char ** apath;
65     int mapflags;
66 /*@owned@*/ int * fmapflags;
67     uid_t uid;
68 /*@owned@*/ /*@null@*/ uid_t * fuids;   /*!< File uid(s) */
69     gid_t gid;
70 /*@owned@*/ /*@null@*/ gid_t * fgids;   /*!< File gid(s) */
71     int magic;
72 #define TFIMAGIC        0x09697923
73 /*@owned@*/ FSM_t fsm;          /*!< File state machine data. */
74
75   /* these are for TR_ADDED packages */
76 /*@dependent@*/ struct availablePackage * ap;
77 /*@owned@*/ struct sharedFileInfo * replaced;
78 /*@owned@*/ uint_32 * replacedSizes;
79
80   /* for TR_REMOVED packages */
81     unsigned int record;
82 };
83
84 /**
85  */
86 #define PSM_VERBOSE     0x8000
87 #define PSM_INTERNAL    0x4000
88 #define PSM_SYSCALL     0x2000
89 #define PSM_DEAD        0x1000
90 #define _fv(_a)         ((_a) | PSM_VERBOSE)
91 #define _fi(_a)         ((_a) | PSM_INTERNAL)
92 #define _fs(_a)         ((_a) | (PSM_INTERNAL | PSM_SYSCALL))
93 #define _fd(_a)         ((_a) | (PSM_INTERNAL | PSM_DEAD))
94 typedef enum pkgStage_e {
95     PSM_UNKNOWN         =  0,
96     PSM_INIT            =  1,
97     PSM_PRE             =  2,
98     PSM_PROCESS         =  3,
99     PSM_POST            =  4,
100     PSM_UNDO            =  5,
101     PSM_FINI            =  6,
102
103     PSM_PKGINSTALL      =  7,
104     PSM_PKGERASE        =  8,
105     PSM_PKGCOMMIT       = 10,
106     PSM_PKGSAVE         = 12,
107
108     PSM_CREATE          = 17,
109     PSM_NOTIFY          = 22,
110     PSM_DESTROY         = 23,
111     PSM_COMMIT          = 25,
112
113     PSM_CHROOT_IN       = 51,
114     PSM_CHROOT_OUT      = 52,
115     PSM_SCRIPT          = 53,
116     PSM_TRIGGERS        = 54,
117     PSM_IMMED_TRIGGERS  = 55,
118     PSM_RPMIO_FLAGS     = 56,
119
120     PSM_RPMDB_LOAD      = 97,
121     PSM_RPMDB_ADD       = 98,
122     PSM_RPMDB_REMOVE    = 99,
123
124 } pkgStage;
125 #undef  _fv
126 #undef  _fi
127 #undef  _fs
128 #undef  _fd
129
130 /**
131  */
132 struct psm_s {
133 /*@kept@*/ rpmTransactionSet ts;/*!< transaction set */
134 /*@kept@*/ TFI_t fi;            /*!< transaction element file info */
135     FD_t cfd;                   /*!< Payload file handle. */
136     FD_t fd;                    /*!< Repackage file handle. */
137     Header oh;                  /*!< Repackage/multilib header. */
138 /*@null@*/ rpmdbMatchIterator mi;
139 /*@observer@*/ const char * stepName;
140 /*@only@*/ /*@null@*/ const char * rpmio_flags;
141 /*@only@*/ /*@null@*/ const char * failedFile;
142 /*@only@*/ /*@null@*/ const char * pkgURL;      /*!< Repackage URL. */
143 /*@dependent@*/ const char * pkgfn;     /*!< Repackage file name. */
144     int scriptTag;              /*!< Scriptlet data tag. */
145     int progTag;                /*!< Scriptlet interpreter tag. */
146     int npkgs_installed;        /*!< No. of installed instances. */
147     int scriptArg;              /*!< Scriptlet package arg. */
148     int sense;                  /*!< One of RPMSENSE_TRIGGER{IN,UN,POSTUN}. */
149     int countCorrection;        /*!< 0 if installing, -1 if removing. */
150     int chrootDone;             /*!< Was chroot(2) done by pkgStage? */
151     rpmCallbackType what;       /*!< Callback type. */
152     unsigned long amount;       /*!< Callback amount. */
153     unsigned long total;        /*!< Callback total. */
154     rpmRC rc;
155     pkgStage goal;
156 /*@unused@*/ pkgStage stage;
157 };
158
159 #ifdef __cplusplus
160 extern "C" {
161 #endif
162
163 /**
164  * Load data from header into transaction file element info.
165  * @param h             header
166  * @param fi            transaction element file info
167  */
168 void loadFi(Header h, TFI_t fi)
169         /*@modifies h, fi @*/;
170
171 /**
172  * Destroy transaction element file info.
173  * @param fi            transaction element file info
174  */
175 void freeFi(TFI_t fi)
176         /*@modifies fi @*/;
177
178 /**
179  * Return formatted string representation of package disposition.
180  * @param a             package dispostion
181  * @return              formatted string
182  */
183 /*@observer@*/ const char *const fiTypeString(/*@partial@*/TFI_t fi)
184         /*@*/;
185
186 /**
187  * Package state machine driver.
188  * @param psm           package state machine data
189  * @param stage         next stage
190  * @return              0 on success
191  */
192 int psmStage(PSM_t psm, pkgStage stage)
193         /*@modifies psm, fileSystem @*/;
194
195 #ifdef __cplusplus
196 }
197 #endif
198
199 #endif  /* H_ROLLBACK */