librazor/razor-internal.h
author Kristian H?gsberg <krh@redhat.com>
Fri Jun 20 21:56:43 2008 -0400 (2008-06-20)
changeset 254 ccb1c11968ab
parent 241 c3eb520e2219
child 258 29d5002bd17f
permissions -rw-r--r--
Introduce install/remove iterators.

These iterator constructors lets you pass in two sets and creates
an iterator for the packages to remove or the packages to install.
The iterators will step through the packages in a sequence that respects
the pre, post, preun and postun modifiers.

Right now, the install order isn't actually implemented, this patch just
implements the API changes and updates the applications.
     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_VERSION 1
    66 
    67 #define RAZOR_STRING_POOL	0
    68 #define RAZOR_PACKAGES		1
    69 #define RAZOR_PROPERTIES	2
    70 #define RAZOR_FILES		3
    71 #define RAZOR_PACKAGE_POOL	4
    72 #define RAZOR_PROPERTY_POOL	5
    73 #define RAZOR_FILE_POOL		6
    74 
    75 struct razor_package {
    76 	uint32_t name  : 24;
    77 	uint32_t flags : 8;
    78 	uint32_t version;
    79 	uint32_t arch;
    80 	struct list_head properties;
    81 	struct list_head files;
    82 };
    83 
    84 struct razor_property {
    85 	uint32_t name;
    86 	uint32_t flags;
    87 	uint32_t version;
    88 	struct list_head packages;
    89 };
    90 
    91 struct razor_entry {
    92 	uint32_t name  : 24;
    93 	uint32_t flags : 8;
    94 	uint32_t start;
    95 	struct list_head packages;
    96 };
    97 
    98 #define RAZOR_ENTRY_LAST	0x80
    99 
   100 struct razor_set {
   101 	struct array string_pool;
   102  	struct array packages;
   103  	struct array properties;
   104  	struct array files;
   105 	struct array package_pool;
   106  	struct array property_pool;
   107  	struct array file_pool;
   108 	struct razor_set_header *header;
   109 };
   110 
   111 struct import_entry {
   112 	uint32_t package;
   113 	char *name;
   114 };
   115 
   116 struct import_directory {
   117 	uint32_t name, count;
   118 	struct array files;
   119 	struct array packages;
   120 	struct import_directory *last;
   121 };
   122 
   123 struct razor_importer {
   124 	struct razor_set *set;
   125 	struct hashtable table;
   126 	struct razor_package *package;
   127 	struct array properties;
   128 	struct array files;
   129 	struct array file_requires;
   130 };
   131 
   132 struct razor_package_iterator {
   133 	struct razor_set *set;
   134 	struct razor_package *package, *end;
   135 	struct list *index;
   136 	int free_index;
   137 };
   138 
   139 void
   140 razor_package_iterator_init_for_property(struct razor_package_iterator *pi,
   141 					 struct razor_set *set,
   142 					 struct razor_property *property);
   143 
   144 struct razor_property_iterator {
   145 	struct razor_set *set;
   146 	struct razor_property *property, *end;
   147 	struct list *index;
   148 };
   149 
   150 #define ALIGN(value, base) (((value) + (base - 1)) & ~((base) - 1))
   151 
   152 struct razor_entry *
   153 razor_set_find_entry(struct razor_set *set,
   154 		     struct razor_entry *dir, const char *pattern);
   155 
   156 struct razor_merger *
   157 razor_merger_create(struct razor_set *set1, struct razor_set *set2);
   158 void
   159 razor_merger_add_package(struct razor_merger *merger,
   160 			 struct razor_package *package);
   161 struct razor_set *
   162 razor_merger_finish(struct razor_merger *merger);
   163 
   164 /* Utility functions */
   165 
   166 int razor_create_dir(const char *root, const char *path);
   167 int razor_write(int fd, const void *data, size_t size);
   168 
   169 
   170 typedef int (*razor_compare_with_data_func_t)(const void *p1,
   171 					      const void *p,
   172 					      void *data);
   173 uint32_t *
   174 razor_qsort_with_data(void *base, size_t nelem, size_t size,
   175 		      razor_compare_with_data_func_t compare, void *data);
   176 
   177 #endif /* _RAZOR_INTERNAL_H_ */