2 * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
3 * Copyright (C) 2008 Red Hat, Inc
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef _RAZOR_INTERNAL_H_
21 #define _RAZOR_INTERNAL_H_
27 #if defined(__GNUC__) && __GNUC__ >= 4
28 #define RAZOR_EXPORT __attribute__ ((visibility("default")))
33 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
34 #define ALIGN(value, base) (((value) + (base - 1)) & ~((base) - 1))
36 void *zalloc(size_t size);
43 void array_init(struct array *array);
44 void array_release(struct array *array);
45 void *array_add(struct array *array, int size);
49 uint32_t list_ptr : 24;
58 void list_set_empty(struct list_head *head);
59 void list_set_ptr(struct list_head *head, uint32_t ptr);
60 void list_set_array(struct list_head *head, struct array *pool, struct array *items, int force_indirect);
62 struct list *list_first(struct list_head *head, struct array *pool);
63 struct list *list_next(struct list *list);
65 void list_remap_pool(struct array *pool, uint32_t *map);
66 void list_remap_head(struct list_head *list, uint32_t *map);
74 void hashtable_init(struct hashtable *table, struct array *pool);
75 void hashtable_release(struct hashtable *table);
76 uint32_t hashtable_insert(struct hashtable *table, const char *key);
77 uint32_t hashtable_lookup(struct hashtable *table, const char *key);
78 uint32_t hashtable_tokenize(struct hashtable *table, const char *string);
81 struct razor_set_section {
87 struct razor_set_header {
90 struct razor_set_section sections[0];
93 #define RAZOR_MAGIC 0x7a7a7a7a
94 #define RAZOR_DETAILS_MAGIC 0x7a7a7a7b
95 #define RAZOR_FILES_MAGIC 0x7a7a7a7c
96 #define RAZOR_VERSION 1
98 #define RAZOR_STRING_POOL 0
99 #define RAZOR_PACKAGES 1
100 #define RAZOR_PROPERTIES 2
101 #define RAZOR_PACKAGE_POOL 3
102 #define RAZOR_PROPERTY_POOL 4
104 #define RAZOR_DETAILS_STRING_POOL 0
106 #define RAZOR_FILES 0
107 #define RAZOR_FILE_POOL 1
108 #define RAZOR_FILE_STRING_POOL 2
110 struct razor_package {
116 uint32_t description;
119 struct list_head properties;
120 struct list_head files;
124 struct razor_property {
128 struct list_head packages;
135 struct list_head packages;
138 #define RAZOR_ENTRY_LAST 0x80
141 struct array string_pool;
142 struct array packages;
143 struct array properties;
145 struct array package_pool;
146 struct array property_pool;
147 struct array file_pool;
148 struct array file_string_pool;
149 struct array details_string_pool;
150 struct razor_set_header *header;
151 struct razor_set_header *details_header;
152 struct razor_set_header *files_header;
155 struct import_entry {
160 struct import_directory {
161 uint32_t name, count;
163 struct array packages;
164 struct import_directory *last;
167 struct razor_importer {
168 struct razor_set *set;
169 struct hashtable table;
170 struct hashtable file_table;
171 struct hashtable details_table;
172 struct razor_package *package;
173 struct array properties;
175 struct array file_requires;
178 struct razor_package_iterator {
179 struct razor_set *set;
180 struct razor_package *package, *end;
186 razor_package_iterator_init_for_property(struct razor_package_iterator *pi,
187 struct razor_set *set,
188 struct razor_property *property);
190 struct razor_property_iterator {
191 struct razor_set *set;
192 struct razor_property *property, *end;
197 razor_set_find_entry(struct razor_set *set,
198 struct razor_entry *dir, const char *pattern);
200 struct razor_merger *
201 razor_merger_create(struct razor_set *set1, struct razor_set *set2);
203 razor_merger_add_package(struct razor_merger *merger,
204 struct razor_package *package);
206 razor_merger_finish(struct razor_merger *merger);
208 /* Utility functions */
210 int razor_create_dir(const char *root, const char *path);
211 int razor_write(int fd, const void *data, size_t size);
214 typedef int (*razor_compare_with_data_func_t)(const void *p1,
218 razor_qsort_with_data(void *base, size_t nelem, size_t size,
219 razor_compare_with_data_func_t compare, void *data);
221 #endif /* _RAZOR_INTERNAL_H_ */