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