Move more args into PSM_t.
[platform/upstream/rpm.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 "scriptlet.h"
10 #include "fsm.h"
11
12 /**
13  */
14 typedef enum rollbackDir_e {
15     ROLLBACK_SAVE       = 1,    /*!< Save files. */
16     ROLLBACK_RESTORE    = 2,    /*!< Restore files. */
17 } rollbackDir;
18
19 /**
20  */
21 struct sharedFile {
22     int mainFileNumber;
23     int secRecOffset;
24     int secFileNumber;
25 } ;
26
27 /**
28  */
29 struct sharedFileInfo {
30     int pkgFileNum;
31     int otherFileNum;
32     int otherPkg;
33     int isRemoved;
34 };
35
36 /**
37  */
38 struct transactionFileInfo_s {
39   /* for all packages */
40     enum rpmTransactionType type;
41     fileAction action;          /*!< File disposition default. */
42 /*@owned@*/ fileAction * actions;       /*!< File disposition(s) */
43 /*@owned@*/ struct fingerPrint_s * fps; /*!< File fingerprint(s) */
44     HGE_t hge;                  /*!< Vector to headerGetEntry() */
45     HFD_t hfd;                  /*!< Vector to headerFreeData() */
46     Header h;                   /*!< Package header */
47 /*@owned@*/ const char * name;
48 /*@owned@*/ const char * version;
49 /*@owned@*/ const char * release;
50     int_32 epoch;
51     uint_32 flags;              /*!< File flag default. */
52     const uint_32 * fflags;     /*!< File flag(s) (from header) */
53     const uint_32 * fsizes;     /*!< File size(s) (from header) */
54     const uint_32 * fmtimes;    /*!< File modification time(s) (from header) */
55 /*@owned@*/ const char ** bnl;  /*!< Base name(s) (from header) */
56 /*@owned@*/ const char ** dnl;  /*!< Directory name(s) (from header) */
57     int_32 * dil;               /*!< Directory indice(s) (from header) */
58 /*@owned@*/ const char ** obnl; /*!< Original base name(s) (from header) */
59 /*@owned@*/ const char ** odnl; /*!< Original directory name(s) (from header) */
60     int_32 * odil;      /*!< Original directory indice(s) (from header) */
61 /*@owned@*/ const char ** fmd5s;/*!< File MD5 sum(s) (from header) */
62 /*@owned@*/ const char ** flinks;       /*!< File link(s) (from header) */
63 /* XXX setuid/setgid bits are turned off if fuser/fgroup doesn't map. */
64     uint_16 * fmodes;           /*!< File mode(s) (from header) */
65 /*@owned@*/ char * fstates;     /*!< File state(s) (from header) */
66 /*@owned@*/ const char ** fuser;        /*!< File owner(s) */
67 /*@owned@*/ const char ** fgroup;       /*!< File group(s) */
68 /*@owned@*/ const char ** flangs;       /*!< File lang(s) */
69     int fc;                     /*!< No. of files. */
70     int dc;                     /*!< No. of directories. */
71     int bnlmax;                 /*!< Length (in bytes) of longest base name. */
72     int dnlmax;                 /*!< Length (in bytes) of longest dir name. */
73     int astriplen;
74     int striplen;
75     int chrootDone;
76     unsigned int archiveSize;
77     mode_t dperms;              /*!< Directory perms (0755) if not mapped. */
78     mode_t fperms;              /*!< File perms (0644) if not mapped. */
79 /*@owned@*/ const char ** apath;
80     int mapflags;
81 /*@owned@*/ int * fmapflags;
82     uid_t uid;
83 /*@owned@*/ /*@null@*/ uid_t * fuids;   /*!< File uid(s) */
84     gid_t gid;
85 /*@owned@*/ /*@null@*/ gid_t * fgids;   /*!< File gid(s) */
86     int magic;
87 #define TFIMAGIC        0x09697923
88 /*@owned@*/ FSM_t fsm;          /*!< File state machine data. */
89
90   /* these are for TR_ADDED packages */
91 /*@dependent@*/ struct availablePackage * ap;
92 /*@owned@*/ struct sharedFileInfo * replaced;
93 /*@owned@*/ uint_32 * replacedSizes;
94   /* for TR_REMOVED packages */
95     unsigned int record;
96 };
97
98 /**
99  */
100 struct psm_s {
101     rpmTransactionSet ts;
102     TFI_t fi;
103     int scriptTag;              /*!< Scriptlet tag. */
104     int progTag;                /*!< Scriptlet interpreter tag. */
105     int scriptArg;              /*!< No. of installed instances. */
106     int sense;                  /*!< One of RPMSENSE_TRIGGER{IN,UN,POSTUN}. */
107     int countCorrection;        /*!< 0 if installing, -1 if removing. */
108     int rc;
109     fileStage stage;
110 };
111
112 #ifdef __cplusplus
113 extern "C" {
114 #endif
115
116 /**
117  * Load data from header into transaction file element info.
118  * @param h             header
119  * @param fi            transaction element file info
120  */
121 void loadFi(Header h, TFI_t fi)
122         /*@modifies h, fi @*/;
123
124 /**
125  * Destroy transaction element file info.
126  * @param fi            transaction element file info
127  */
128 void freeFi(TFI_t fi)
129         /*@modifies fi @*/;
130
131 /**
132  * Return formatted string representation of package disposition.
133  * @param a             package dispostion
134  * @return              formatted string
135  */
136 /*@observer@*/ const char *const fiTypeString(TFI_t fi);
137
138 /**
139  * Return formatted string representation of file disposition.
140  * @param a             file dispostion
141  * @return              formatted string
142  */
143 /*@observer@*/ const char *const fileActionString(fileAction a);
144
145 /**
146  * Install binary package (from transaction set).
147  * @param psm           package state machine data
148  * @return              0 on success, 1 on bad magic, 2 on error
149  */
150 int installBinaryPackage(PSM_t psm)
151         /*@modifies psm @*/;
152
153 /**
154  * Erase binary package (from transaction set).
155  * @param psm           package state machine data
156  * @return              0 on success
157  */
158 int removeBinaryPackage(PSM_t psm)
159         /*@modifies psm @*/;
160
161 /**
162  * @param psm           package state machine data
163  * @return              0 on success
164  */
165 int repackage(PSM_t psm)
166         /*@modifies psm @*/;
167
168 /**
169  */
170 int psmStage(PSM_t psm, fileStage stage)
171         /*@modifies psm @*/;
172
173 #ifdef __cplusplus
174 }
175 #endif
176
177 #endif  /* H_ROLLBACK */