librazor/razor-internal.h
author Kristian H?gsberg <krh@redhat.com>
Mon Jun 23 17:21:03 2008 -0400 (2008-06-23)
changeset 270 d4a5fba50fd7
parent 258 29d5002bd17f
child 271 3980d1d9148e
permissions -rw-r--r--
Move a couple of unrelated functions out of transaction.c.
     1 #ifndef _RAZOR_INTERNAL_H_
     2 #define _RAZOR_INTERNAL_H_
     3 
     4 #include <stdlib.h>
     5 #include <stdint.h>
     6 
     7 /* GCC visibility */
     8 #if defined(__GNUC__) && __GNUC__ >= 4
     9 #define RAZOR_EXPORT __attribute__ ((visibility("default")))
    10 #else
    11 #define RAZOR_EXPORT
    12 #endif
    13 
    14 
    15 void *zalloc(size_t size);
    16 
    17 struct array {
    18 	void *data;
    19 	int size, alloc;
    20 };
    21 
    22 void array_init(struct array *array);
    23 void array_release(struct array *array);
    24 void *array_add(struct array *array, int size);
    25 
    26 
    27 struct list_head {
    28 	uint32_t list_ptr : 24;
    29 	uint32_t flags    : 8;
    30 };
    31 
    32 struct list {
    33 	uint32_t data  : 24;
    34 	uint32_t flags : 8;
    35 };
    36 
    37 void list_set_empty(struct list_head *head);
    38 void list_set_ptr(struct list_head *head, uint32_t ptr);
    39 void list_set_array(struct list_head *head, struct array *pool, struct array *items, int force_indirect);
    40 
    41 struct list *list_first(struct list_head *head, struct array *pool);
    42 struct list *list_next(struct list *list);
    43 
    44 void list_remap_pool(struct array *pool, uint32_t *map);
    45 void list_remap_head(struct list_head *list, uint32_t *map);
    46 
    47 
    48 struct hashtable {
    49 	struct array buckets;
    50 	struct array *pool;
    51 };
    52 
    53 void hashtable_init(struct hashtable *table, struct array *pool);
    54 void hashtable_release(struct hashtable *table);
    55 uint32_t hashtable_insert(struct hashtable *table, const char *key);
    56 uint32_t hashtable_lookup(struct hashtable *table, const char *key);
    57 uint32_t hashtable_tokenize(struct hashtable *table, const char *string);
    58 
    59 
    60 struct razor_set_section {
    61 	uint32_t type;
    62 	uint32_t offset;
    63 	uint32_t size;
    64 };
    65 
    66 struct razor_set_header {
    67 	uint32_t magic;
    68 	uint32_t version;
    69 	struct razor_set_section sections[0];
    70 };
    71 
    72 #define RAZOR_MAGIC 		0x7a7a7a7a
    73 #define RAZOR_DETAILS_MAGIC 	0x7a7a7a7b
    74 #define RAZOR_FILES_MAGIC 	0x7a7a7a7c
    75 #define RAZOR_VERSION 1
    76 
    77 #define RAZOR_STRING_POOL		0
    78 #define RAZOR_PACKAGES			1
    79 #define RAZOR_PROPERTIES		2
    80 #define RAZOR_PACKAGE_POOL		3
    81 #define RAZOR_PROPERTY_POOL		4
    82 
    83 #define RAZOR_DETAILS_STRING_POOL	0
    84 
    85 #define RAZOR_FILES			0
    86 #define RAZOR_FILE_POOL			1
    87 #define RAZOR_FILE_STRING_POOL		2
    88 
    89 struct razor_package {
    90 	uint name  : 24;
    91 	uint flags : 8;
    92 	uint32_t version;
    93 	uint32_t arch;
    94 	uint32_t summary;
    95 	uint32_t description;
    96 	uint32_t url;
    97 	uint32_t license;
    98 	struct list_head properties;
    99 	struct list_head files;
   100 };
   101 
   102 
   103 struct razor_property {
   104 	uint32_t name;
   105 	uint32_t flags;
   106 	uint32_t version;
   107 	struct list_head packages;
   108 };
   109 
   110 struct razor_entry {
   111 	uint32_t name  : 24;
   112 	uint32_t flags : 8;
   113 	uint32_t start;
   114 	struct list_head packages;
   115 };
   116 
   117 #define RAZOR_ENTRY_LAST	0x80
   118 
   119 struct razor_set {
   120 	struct array string_pool;
   121  	struct array packages;
   122  	struct array properties;
   123  	struct array files;
   124 	struct array package_pool;
   125  	struct array property_pool;
   126  	struct array file_pool;
   127 	struct array file_string_pool;
   128 	struct array details_string_pool;
   129 	struct razor_set_header *header;
   130 	struct razor_set_header *details_header;
   131 	struct razor_set_header *files_header;
   132 };
   133 
   134 struct import_entry {
   135 	uint32_t package;
   136 	char *name;
   137 };
   138 
   139 struct import_directory {
   140 	uint32_t name, count;
   141 	struct array files;
   142 	struct array packages;
   143 	struct import_directory *last;
   144 };
   145 
   146 struct razor_importer {
   147 	struct razor_set *set;
   148 	struct hashtable table;
   149 	struct hashtable file_table;
   150 	struct hashtable details_table;
   151 	struct razor_package *package;
   152 	struct array properties;
   153 	struct array files;
   154 	struct array file_requires;
   155 };
   156 
   157 struct razor_package_iterator {
   158 	struct razor_set *set;
   159 	struct razor_package *package, *end;
   160 	struct list *index;
   161 	int free_index;
   162 };
   163 
   164 void
   165 razor_package_iterator_init_for_property(struct razor_package_iterator *pi,
   166 					 struct razor_set *set,
   167 					 struct razor_property *property);
   168 
   169 struct razor_property_iterator {
   170 	struct razor_set *set;
   171 	struct razor_property *property, *end;
   172 	struct list *index;
   173 };
   174 
   175 #define ALIGN(value, base) (((value) + (base - 1)) & ~((base) - 1))
   176 
   177 struct razor_entry *
   178 razor_set_find_entry(struct razor_set *set,
   179 		     struct razor_entry *dir, const char *pattern);
   180 
   181 struct razor_merger *
   182 razor_merger_create(struct razor_set *set1, struct razor_set *set2);
   183 void
   184 razor_merger_add_package(struct razor_merger *merger,
   185 			 struct razor_package *package);
   186 struct razor_set *
   187 razor_merger_finish(struct razor_merger *merger);
   188 
   189 /* Utility functions */
   190 
   191 int razor_create_dir(const char *root, const char *path);
   192 int razor_write(int fd, const void *data, size_t size);
   193 
   194 
   195 typedef int (*razor_compare_with_data_func_t)(const void *p1,
   196 					      const void *p,
   197 					      void *data);
   198 uint32_t *
   199 razor_qsort_with_data(void *base, size_t nelem, size_t size,
   200 		      razor_compare_with_data_func_t compare, void *data);
   201 
   202 #endif /* _RAZOR_INTERNAL_H_ */