f51435fee82a8c0c372508c89b3430ed00ccaeec
[platform/upstream/rpm.git] / lib / header_internal.h
1 #ifndef H_HEADER_INTERNAL
2 #define H_HEADER_INTERNAL
3
4 /** \ingroup header
5  * \file lib/header_internal.h
6  */
7
8 #include <rpm/header.h>
9
10 /** \ingroup header
11  * Description of tag data.
12  */
13 typedef struct entryInfo_s * entryInfo;
14 struct entryInfo_s {
15     rpm_tag_t tag;              /*!< Tag identifier. */
16     rpm_tagtype_t type;         /*!< Tag data type. */
17     int32_t offset;             /*!< Offset into data segment (ondisk only). */
18     rpm_count_t count;          /*!< Number of tag elements. */
19 };
20
21 #define REGION_TAG_TYPE         RPM_BIN_TYPE
22 #define REGION_TAG_COUNT        sizeof(struct entryInfo_s)
23
24 /** \ingroup header
25  * A single tag from a Header.
26  */
27 typedef struct indexEntry_s * indexEntry;
28 struct indexEntry_s {
29     struct entryInfo_s info;    /*!< Description of tag data. */
30     rpm_data_t data;            /*!< Location of tag data. */
31     int length;                 /*!< No. bytes of data. */
32     int rdlen;                  /*!< No. bytes of data in region. */
33 };
34
35 /**
36  * Sanity check on no. of tags.
37  * This check imposes a limit of 65K tags, more than enough.
38  */
39 #define hdrchkTags(_ntags)      ((_ntags) & 0xffff0000)
40
41 /**
42  * Sanity check on type values.
43  */
44 #define hdrchkType(_type) ((_type) < RPM_MIN_TYPE || (_type) > RPM_MAX_TYPE)
45
46 /**
47  * Sanity check on data size and/or offset and/or count.
48  * This check imposes a limit of 16 MB, more than enough.
49  */
50 #define HEADER_DATA_MAX 0x00ffffff
51 #define hdrchkData(_nbytes) ((_nbytes) & (~HEADER_DATA_MAX))
52
53 /**
54  * Sanity check on data alignment for data type.
55  */
56 #define hdrchkAlign(_type, _off)        ((_off) & (typeAlign[_type]-1))
57
58 /**
59  * Sanity check on range of data offset.
60  */
61 #define hdrchkRange(_dl, _off)          ((_off) < 0 || (_off) > (_dl))
62
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66
67 /** \ingroup header
68  * Set header instance (rpmdb record number)
69  * @param h             header
70  * @param instance      record number
71  */
72 RPM_GNUC_INTERNAL
73 void headerSetInstance(Header h, unsigned int instance);
74
75 /* Package IO helper to consolidate partial read and error handling */
76 RPM_GNUC_INTERNAL
77 ssize_t Freadall(FD_t fd, void * buf, ssize_t size);
78 #ifdef __cplusplus
79 }   
80 #endif
81
82 #endif  /* H_HEADER_INTERNAL */