Move #include "ugid.h" to fsm.c, nuke unused variable in psm.c.
[platform/upstream/rpm.git] / lib / rpmfi.h
1 #ifndef H_RPMFI
2 #define H_RPMFI
3
4 /** \ingroup rpmdep rpmtrans
5  * \file lib/rpmfi.h
6  * Structure(s) used for file info tag sets.
7  */
8
9 /*@-exportlocal@*/
10 /*@unchecked@*/
11 extern int _rpmfi_debug;
12 /*@=exportlocal@*/
13
14 #if defined(_RPMFI_INTERNAL)
15 /**
16  */
17 typedef struct sharedFileInfo_s *               sharedFileInfo;
18
19 /**
20  */
21 struct sharedFileInfo_s {
22     int pkgFileNum;
23     int otherFileNum;
24     int otherPkg;
25     int isRemoved;
26 };
27
28 /**
29  * A package filename set.
30  */
31 struct rpmfi_s {
32     int i;                      /*!< Current file index. */
33     int j;                      /*!< Current directory index. */
34
35 /*@observer@*/
36     const char * Type;          /*!< Tag name. */
37
38     rpmTag tagN;                /*!< Header tag. */
39 /*@refcounted@*/ /*@null@*/
40     Header h;                   /*!< Header for file info set (or NULL) */
41
42 /*@only@*/ /*?null?*/
43     const char ** bnl;          /*!< Base name(s) (from header) */
44 /*@only@*/ /*?null?*/
45     const char ** dnl;          /*!< Directory name(s) (from header) */
46
47 /*@only@*/ /*@relnull@*/
48     const char ** fmd5s;        /*!< File MD5 sum(s) (from header) */
49 /*@only@*/ /*@relnull@*/
50     const char ** flinks;       /*!< File link(s) (from header) */
51 /*@only@*/ /*@null@*/
52     const char ** flangs;       /*!< File lang(s) (from header) */
53
54 /*@only@*/ /*@relnull@*/
55           uint_32 * dil;        /*!< Directory indice(s) (from header) */
56 /*@only@*/ /*?null?*/
57     const uint_32 * fflags;     /*!< File flag(s) (from header) */
58 /*@only@*/ /*?null?*/
59     const uint_32 * fsizes;     /*!< File size(s) (from header) */
60 /*@only@*/ /*?null?*/
61     const uint_32 * fmtimes;    /*!< File modification time(s) (from header) */
62 /*@only@*/ /*?null?*/
63           uint_16 * fmodes;     /*!< File mode(s) (from header) */
64 /*@only@*/ /*?null?*/
65     const uint_16 * frdevs;     /*!< File rdev(s) (from header) */
66 /*@only@*/ /*?null?*/
67     const uint_32 * finodes;    /*!< File inodes(s) (from header) */
68
69 /*@only@*/ /*@null@*/
70     const char ** fuser;        /*!< File owner(s) (from header) */
71 /*@only@*/ /*@null@*/
72     const char ** fgroup;       /*!< File group(s) (from header) */
73
74 /*@only@*/ /*@null@*/
75     char * fstates;             /*!< File state(s) (from header) */
76
77 /*@only@*/ /*@null@*/
78     const uint_32 * fcolors;    /*!< File color bits (header) */
79
80 /*@only@*/ /*@null@*/
81     const char ** fcontexts;    /*! FIle security contexts. */
82
83 /*@only@*/ /*@null@*/
84     const char ** cdict;        /*!< File class dictionary (header) */
85     int_32 ncdict;              /*!< No. of class entries. */
86 /*@only@*/ /*@null@*/
87     const uint_32 * fcdictx;    /*!< File class dictionary index (header) */
88
89 /*@only@*/ /*@null@*/
90     const uint_32 * ddict;      /*!< File depends dictionary (header) */
91     int_32 nddict;              /*!< No. of depends entries. */
92 /*@only@*/ /*@null@*/
93     const uint_32 * fddictx;    /*!< File depends dictionary start (header) */
94 /*@only@*/ /*@null@*/
95     const uint_32 * fddictn;    /*!< File depends dictionary count (header) */
96
97 /*@only@*/ /*?null?*/
98     const uint_32 * vflags;     /*!< File verify flag(s) (from header) */
99
100     int_32 dc;                  /*!< No. of directories. */
101     int_32 fc;                  /*!< No. of files. */
102
103 /*=============================*/
104 /*@dependent@*/ /*@relnull@*/
105     rpmte te;
106
107     HGE_t hge;                  /*!< Vector to headerGetEntry() */
108     HAE_t hae;                  /*!< Vector to headerAddEntry() */
109     HME_t hme;                  /*!< Vector to headerModifyEntry() */
110     HRE_t hre;                  /*!< Vector to headerRemoveEntry() */
111     HFD_t hfd;                  /*!< Vector to headerFreeData() */
112 /*-----------------------------*/
113     uid_t uid;                  /*!< File uid (default). */
114     gid_t gid;                  /*!< File gid (default). */
115     uint_32 flags;              /*!< File flags (default). */
116     fileAction action;          /*!< File disposition (default). */
117 /*@owned@*/ /*@relnull@*/
118     fileAction * actions;       /*!< File disposition(s). */
119 /*@owned@*/
120     struct fingerPrint_s * fps; /*!< File fingerprint(s). */
121 /*@owned@*/
122     const char ** obnl;         /*!< Original basename(s) (from header) */
123 /*@owned@*/
124     const char ** odnl;         /*!< Original dirname(s) (from header) */
125 /*@unused@*/
126     int_32 * odil;              /*!< Original dirindex(s) (from header) */
127
128 /*@only@*/ /*@relnull@*/
129     unsigned char * md5s;       /*!< File md5 sums in binary. */
130
131 /*@only@*/ /*@null@*/
132     char * fn;                  /*!< File name buffer. */
133     int fnlen;                  /*!< FIle name buffer length. */
134
135     int astriplen;
136     int striplen;
137     unsigned int archivePos;
138     unsigned int archiveSize;
139     mode_t dperms;              /*!< Directory perms (0755) if not mapped. */
140     mode_t fperms;              /*!< File perms (0644) if not mapped. */
141 /*@only@*/ /*@null@*/
142     const char ** apath;
143     int mapflags;
144 /*@owned@*/ /*@null@*/
145     int * fmapflags;
146 /*@owned@*/
147     FSM_t fsm;                  /*!< File state machine data. */
148     int keep_header;            /*!< Keep header? */
149     uint_32 color;              /*!< Color bit(s) from file color union. */
150 /*@owned@*/
151     sharedFileInfo replaced;    /*!< (TR_ADDED) */
152 /*@owned@*/
153     uint_32 * replacedSizes;    /*!< (TR_ADDED) */
154     unsigned int record;        /*!< (TR_REMOVED) */
155     int magic;
156 #define RPMFIMAGIC      0x09697923
157 /*=============================*/
158
159 /*@refs@*/ int nrefs;           /*!< Reference count. */
160 };
161
162 #endif  /* _RPMFI_INTERNAL */
163
164 #ifdef __cplusplus
165 extern "C" {
166 #endif
167
168 /**
169  * Unreference a file info set instance.
170  * @param fi            file info set
171  * @param msg
172  * @return              NULL always
173  */
174 /*@unused@*/ /*@null@*/
175 rpmfi rpmfiUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ rpmfi fi,
176                 /*@null@*/ const char * msg)
177         /*@modifies fi @*/;
178
179 /** @todo Remove debugging entry from the ABI.
180  * @param fi            file info set
181  * @param msg
182  * @param fn
183  * @param ln
184  * @return              NULL always
185  */
186 /*@-exportlocal@*/
187 /*@null@*/
188 rpmfi XrpmfiUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ rpmfi fi,
189                 /*@null@*/ const char * msg, const char * fn, unsigned ln)
190         /*@modifies fi @*/;
191 /*@=exportlocal@*/
192 #define rpmfiUnlink(_fi, _msg) XrpmfiUnlink(_fi, _msg, __FILE__, __LINE__)
193
194 /**
195  * Reference a file info set instance.
196  * @param fi            file info set
197  * @param msg
198  * @return              new file info set reference
199  */
200 /*@unused@*/ /*@null@*/
201 rpmfi rpmfiLink (/*@null@*/ rpmfi fi, /*@null@*/ const char * msg)
202         /*@modifies fi @*/;
203
204 /** @todo Remove debugging entry from the ABI.
205  * @param fi            file info set
206  * @param msg
207  * @param fn
208  * @param ln
209  * @return              NULL always
210  */
211 /*@null@*/
212 rpmfi XrpmfiLink (/*@null@*/ rpmfi fi, /*@null@*/ const char * msg,
213                 const char * fn, unsigned ln)
214         /*@modifies fi @*/;
215 #define rpmfiLink(_fi, _msg)    XrpmfiLink(_fi, _msg, __FILE__, __LINE__)
216
217 /**
218  * Return file count from file info set.
219  * @param fi            file info set
220  * @return              current file count
221  */
222 int rpmfiFC(/*@null@*/ rpmfi fi)
223         /*@*/;
224
225 /**
226  * Return current file index from file info set.
227  * @param fi            file info set
228  * @return              current file index
229  */
230 /*@unused@*/
231 int rpmfiFX(/*@null@*/ rpmfi fi)
232         /*@*/;
233
234 /**
235  * Set current file index in file info set.
236  * @param fi            file info set
237  * @param fx            new file index
238  * @return              current file index
239  */
240 /*@unused@*/
241 int rpmfiSetFX(/*@null@*/ rpmfi fi, int fx)
242         /*@modifies fi @*/;
243
244 /**
245  * Return directory count from file info set.
246  * @param fi            file info set
247  * @return              current directory count
248  */
249 int rpmfiDC(/*@null@*/ rpmfi fi)
250         /*@*/;
251
252 /**
253  * Return current directory index from file info set.
254  * @param fi            file info set
255  * @return              current directory index
256  */
257 int rpmfiDX(/*@null@*/ rpmfi fi)
258         /*@*/;
259
260 /**
261  * Set current directory index in file info set.
262  * @param fi            file info set
263  * @param dx            new directory index
264  * @return              current directory index
265  */
266 int rpmfiSetDX(/*@null@*/ rpmfi fi, int dx)
267         /*@modifies fi @*/;
268
269 /**
270  * Return current base name from file info set.
271  * @param fi            file info set
272  * @return              current base name, NULL on invalid
273  */
274 /*@observer@*/ /*@null@*/
275 extern const char * rpmfiBN(/*@null@*/ rpmfi fi)
276         /*@*/;
277
278 /**
279  * Return current directory name from file info set.
280  * @param fi            file info set
281  * @return              current directory, NULL on invalid
282  */
283 /*@observer@*/ /*@null@*/
284 extern const char * rpmfiDN(/*@null@*/ rpmfi fi)
285         /*@*/;
286
287 /**
288  * Return current file name from file info set.
289  * @param fi            file info set
290  * @return              current file name
291  */
292 /*@observer@*/
293 extern const char * rpmfiFN(/*@null@*/ rpmfi fi)
294         /*@modifies fi @*/;
295
296 /**
297  * Return current file flags from file info set.
298  * @param fi            file info set
299  * @return              current file flags, 0 on invalid
300  */
301 int_32 rpmfiFFlags(/*@null@*/ rpmfi fi)
302         /*@*/;
303
304 /**
305  * Return current file verify flags from file info set.
306  * @param fi            file info set
307  * @return              current file verify flags, 0 on invalid
308  */
309 int_32 rpmfiVFlags(/*@null@*/ rpmfi fi)
310         /*@*/;
311
312 /**
313  * Return current file mode from file info set.
314  * @param fi            file info set
315  * @return              current file mode, 0 on invalid
316  */
317 int_16 rpmfiFMode(/*@null@*/ rpmfi fi)
318         /*@*/;
319
320 /**
321  * Return current file state from file info set.
322  * @param fi            file info set
323  * @return              current file state, 0 on invalid
324  */
325 rpmfileState rpmfiFState(/*@null@*/ rpmfi fi)
326         /*@*/;
327
328 /**
329  * Return current file (binary) md5 digest from file info set.
330  * @param fi            file info set
331  * @return              current file md5 digest, NULL on invalid
332  */
333 /*@observer@*/ /*@null@*/
334 extern const unsigned char * rpmfiMD5(/*@null@*/ rpmfi fi)
335         /*@*/;
336
337 /**
338  * Return current file linkto (i.e. symlink(2) target) from file info set.
339  * @param fi            file info set
340  * @return              current file linkto, NULL on invalid
341  */
342 /*@observer@*/ /*@null@*/
343 extern const char * rpmfiFLink(/*@null@*/ rpmfi fi)
344         /*@*/;
345
346 /**
347  * Return current file size from file info set.
348  * @param fi            file info set
349  * @return              current file size, 0 on invalid
350  */
351 int_32 rpmfiFSize(/*@null@*/ rpmfi fi)
352         /*@*/;
353
354 /**
355  * Return current file rdev from file info set.
356  * @param fi            file info set
357  * @return              current file rdev, 0 on invalid
358  */
359 int_16 rpmfiFRdev(/*@null@*/ rpmfi fi)
360         /*@*/;
361
362 /**
363  * Return current file inode from file info set.
364  * @param fi            file info set
365  * @return              current file inode, 0 on invalid
366  */
367 int_32 rpmfiFInode(/*@null@*/ rpmfi fi)
368         /*@*/;
369
370 /**
371  * Return union of all file color bits from file info set.
372  * @param fi            file info set
373  * @return              current color
374  */
375 uint_32 rpmfiColor(/*@null@*/ rpmfi fi)
376         /*@*/;
377
378 /**
379  * Return current file color bits from file info set.
380  * @param fi            file info set
381  * @return              current file color
382  */
383 uint_32 rpmfiFColor(/*@null@*/ rpmfi fi)
384         /*@*/;
385
386 /**
387  * Return current file class from file info set.
388  * @param fi            file info set
389  * @return              current file class, 0 on invalid
390  */
391 /*@-exportlocal@*/
392 /*@observer@*/ /*@null@*/
393 extern const char * rpmfiFClass(/*@null@*/ rpmfi fi)
394         /*@*/;
395 /*@=exportlocal@*/
396
397 /**
398  * Return current file security context from file info set.
399  * @param fi            file info set
400  * @return              current file context, 0 on invalid
401  */
402 /*@-exportlocal@*/
403 /*@observer@*/ /*@null@*/
404 extern const char * rpmfiFContext(/*@null@*/ rpmfi fi)
405         /*@*/;
406 /*@=exportlocal@*/
407
408 /**
409  * Return current file depends dictionary from file info set.
410  * @param fi            file info set
411  * @retval *fddictp     file depends dictionary array (or NULL)
412  * @return              no. of file depends entries, 0 on invalid
413  */
414 int_32 rpmfiFDepends(/*@null@*/ rpmfi fi,
415                 /*@out@*/ /*@null@*/ const int_32 ** fddictp)
416         /*@modifies *fddictp @*/;
417
418 /**
419  * Return (calculated) current file nlink count from file info set.
420  * @param fi            file info set
421  * @return              current file nlink count, 0 on invalid
422  */
423 int_32 rpmfiFNlink(/*@null@*/ rpmfi fi)
424         /*@*/;
425
426 /**
427  * Return current file modify time from file info set.
428  * @param fi            file info set
429  * @return              current file modify time, 0 on invalid
430  */
431 int_32 rpmfiFMtime(/*@null@*/ rpmfi fi)
432         /*@*/;
433
434 /**
435  * Return current file owner from file info set.
436  * @param fi            file info set
437  * @return              current file owner, NULL on invalid
438  */
439 /*@observer@*/ /*@null@*/
440 extern const char * rpmfiFUser(/*@null@*/ rpmfi fi)
441         /*@*/;
442
443 /**
444  * Return current file group from file info set.
445  * @param fi            file info set
446  * @return              current file group, NULL on invalid
447  */
448 /*@observer@*/ /*@null@*/
449 extern const char * rpmfiFGroup(/*@null@*/ rpmfi fi)
450         /*@*/;
451
452 /**
453  * Return next file iterator index.
454  * @param fi            file info set
455  * @return              file iterator index, -1 on termination
456  */
457 int rpmfiNext(/*@null@*/ rpmfi fi)
458         /*@modifies fi @*/;
459
460 /**
461  * Initialize file iterator index.
462  * @param fi            file info set
463  * @param fx            file iterator index
464  * @return              file info set
465  */
466 /*@null@*/
467 rpmfi rpmfiInit(/*@null@*/ rpmfi fi, int fx)
468         /*@modifies fi @*/;
469
470 /**
471  * Return next directory iterator index.
472  * @param fi            file info set
473  * @return              directory iterator index, -1 on termination
474  */
475 /*@unused@*/
476 int rpmfiNextD(/*@null@*/ rpmfi fi)
477         /*@modifies fi @*/;
478
479 /**
480  * Initialize directory iterator index.
481  * @param fi            file info set
482  * @param dx            directory iterator index
483  * @return              file info set, NULL if dx is out of range
484  */
485 /*@unused@*/ /*@null@*/
486 rpmfi rpmfiInitD(/*@null@*/ rpmfi fi, int dx)
487         /*@modifies fi @*/;
488
489 /**
490  * Destroy a file info set.
491  * @param fi            file info set
492  * @return              NULL always
493  */
494 /*@null@*/
495 rpmfi rpmfiFree(/*@killref@*/ /*@only@*/ /*@null@*/ rpmfi fi)
496         /*@globals fileSystem @*/
497         /*@modifies fi, fileSystem @*/;
498
499 /**
500  * Create and load a file info set.
501  * @param ts            transaction set (NULL skips path relocation)
502  * @param h             header
503  * @param tagN          RPMTAG_BASENAMES
504  * @param scareMem      Use pointers to refcounted header memory?
505  * @return              new file info set
506  */
507 /*@null@*/
508 rpmfi rpmfiNew(/*@null@*/ const rpmts ts, Header h, rpmTag tagN, int scareMem)
509         /*@globals rpmGlobalMacroContext, h_errno, fileSystem @*/
510         /*@modifies ts, h, rpmGlobalMacroContext, fileSystem @*/;
511
512 /**
513  * Retrieve file classes from header.
514  *
515  * This function is used to retrieve file classes from the header.
516  * 
517  * @param h             header
518  * @retval *fclassp     array of file classes
519  * @retval *fcp         number of files
520  */
521 void rpmfiBuildFClasses(Header h,
522                 /*@out@*/ const char *** fclassp, /*@out@*/ int * fcp)
523         /*@globals rpmGlobalMacroContext, h_errno, fileSystem @*/
524         /*@modifies h, *fclassp, *fcp, rpmGlobalMacroContext, fileSystem @*/;
525
526 /**
527  * Retrieve file security contexts from header.
528  *
529  * This function is used to retrieve file contexts from the header.
530  * 
531  * @param h             header
532  * @retval *fcontextp   array of file contexts
533  * @retval *fcp         number of files
534  */
535 void rpmfiBuildFContexts(Header h,
536                 /*@out@*/ const char *** fcontextp, /*@out@*/ int * fcp)
537         /*@globals rpmGlobalMacroContext, h_errno, fileSystem @*/
538         /*@modifies h, *fcontextp, *fcp, rpmGlobalMacroContext, fileSystem @*/;
539
540 /**
541  * Retrieve file security contexts from file system.
542  *
543  * This function is used to retrieve file contexts from the file system.
544  * 
545  * @param h             header
546  * @retval *fcontextp   array of file contexts
547  * @retval *fcp         number of files
548  */
549 void rpmfiBuildFSContexts(Header h,
550                 /*@out@*/ const char *** fcontextp, /*@out@*/ int * fcp)
551         /*@globals rpmGlobalMacroContext, h_errno, fileSystem @*/
552         /*@modifies h, *fcontextp, *fcp, rpmGlobalMacroContext, fileSystem @*/;
553
554 /**
555  * Retrieve file security contexts from policy RE's.
556  *
557  * This function is used to retrieve file contexts from policy RE's.
558  * 
559  * @param h             header
560  * @retval *fcontextp   array of file contexts
561  * @retval *fcp         number of files
562  */
563 void rpmfiBuildREContexts(Header h,
564                 /*@out@*/ const char *** fcontextp, /*@out@*/ int * fcp)
565         /*@globals rpmGlobalMacroContext, h_errno, fileSystem @*/
566         /*@modifies h, *fcontextp, *fcp, rpmGlobalMacroContext, fileSystem @*/;
567
568 /**
569  * Retrieve per-file dependencies from header.
570  *
571  * This function is used to retrieve per-file dependencies from the header.
572  * 
573  * @param h             header
574  * @param tagN          RPMTAG_PROVIDENAME | RPMTAG_REQUIRENAME
575  * @retval *fdepsp      array of file dependencies
576  * @retval *fcp         number of files
577  */
578 void rpmfiBuildFDeps(Header h, rpmTag tagN,
579                 /*@out@*/ const char *** fdepsp, /*@out@*/ int * fcp)
580         /*@globals rpmGlobalMacroContext, h_errno, fileSystem @*/
581         /*@modifies h, *fdepsp, *fcp, rpmGlobalMacroContext, fileSystem @*/;
582
583 /**
584  * Return file type from mode_t.
585  * @param mode          file mode bits (from header)
586  * @return              file type
587  */
588 fileTypes whatis(uint_16 mode)
589         /*@*/;
590
591 /**
592  * Return file info comparison.
593  * @param afi           1st file info
594  * @param bfi           2nd file info
595  * @return              0 if identical
596  */
597 int rpmfiCompare(const rpmfi afi, const rpmfi bfi)
598         /*@*/;
599
600 /**
601  * Return file disposition.
602  * @param ofi           old file info
603  * @param nfi           new file info
604  * @param skipMissing   OK to skip missing files?
605  * @return              file dispostion
606  */
607 fileAction rpmfiDecideFate(const rpmfi ofi, rpmfi nfi, int skipMissing)
608         /*@globals h_errno, fileSystem, internalState @*/
609         /*@modifies nfi, fileSystem, internalState @*/;
610
611 /**
612  * Return formatted string representation of package disposition.
613  * @param fi            file info set
614  * @return              formatted string
615  */
616 /*@-redef@*/
617 /*@observer@*/
618 const char *const rpmfiTypeString(rpmfi fi)
619         /*@*/;
620 /*@=redef@*/
621
622 #ifdef __cplusplus
623 }
624 #endif
625
626 #endif  /* H_RPMDS */