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