librazor/razor-internal.h
author James Bowes <jbowes@redhat.com>
Wed Jul 09 10:11:13 2008 -0400 (2008-07-09)
changeset 318 829d6711b316
parent 302 9b71b537d175
child 322 66c281524c98
permissions -rw-r--r--
Use strings to identify section types in the on-disk repo format.

Previously, a given razor file type had a fixed number of sections in a
fixed order, identified by an integer type. Now, sections are identified
by a named string (stored in a string pool after the section lists).

This will allow for razor files to contain arbitrary sections.

For bonus points, also drop the 4k section alignment and change the
magic byte string to "RZDB".

committer: Kristian H?gsberg <krh@redhat.com>
richard@300
     1
/*
richard@300
     2
 * Copyright (C) 2008  Kristian Høgsberg <krh@redhat.com>
richard@300
     3
 * Copyright (C) 2008  Red Hat, Inc
richard@300
     4
 *
richard@300
     5
 * This program is free software; you can redistribute it and/or modify
richard@300
     6
 * it under the terms of the GNU General Public License as published by
richard@300
     7
 * the Free Software Foundation; either version 2 of the License, or
richard@300
     8
 * (at your option) any later version.
richard@300
     9
 *
richard@300
    10
 * This program is distributed in the hope that it will be useful,
richard@300
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
richard@300
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
richard@300
    13
 * GNU General Public License for more details.
richard@300
    14
 *
richard@300
    15
 * You should have received a copy of the GNU General Public License along
richard@300
    16
 * with this program; if not, write to the Free Software Foundation, Inc.,
richard@300
    17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
richard@300
    18
 */
richard@300
    19
rhughes@241
    20
#ifndef _RAZOR_INTERNAL_H_
rhughes@241
    21
#define _RAZOR_INTERNAL_H_
rhughes@241
    22
krh@248
    23
#include <stdlib.h>
krh@248
    24
#include <stdint.h>
richard@302
    25
#include <stdarg.h>
richard@302
    26
richard@302
    27
#include "razor.h"
krh@248
    28
krh@269
    29
/* GCC visibility */
krh@269
    30
#if defined(__GNUC__) && __GNUC__ >= 4
krh@269
    31
#define RAZOR_EXPORT __attribute__ ((visibility("default")))
krh@269
    32
#else
krh@269
    33
#define RAZOR_EXPORT
krh@269
    34
#endif
krh@269
    35
krh@271
    36
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
krh@271
    37
#define ALIGN(value, base) (((value) + (base - 1)) & ~((base) - 1))
krh@269
    38
krh@248
    39
void *zalloc(size_t size);
krh@248
    40
krh@248
    41
struct array {
krh@248
    42
	void *data;
krh@248
    43
	int size, alloc;
krh@248
    44
};
krh@248
    45
krh@248
    46
void array_init(struct array *array);
krh@248
    47
void array_release(struct array *array);
krh@248
    48
void *array_add(struct array *array, int size);
krh@248
    49
krh@248
    50
krh@248
    51
struct list_head {
krh@248
    52
	uint32_t list_ptr : 24;
krh@248
    53
	uint32_t flags    : 8;
krh@248
    54
};
krh@248
    55
krh@248
    56
struct list {
krh@248
    57
	uint32_t data  : 24;
krh@248
    58
	uint32_t flags : 8;
krh@248
    59
};
krh@248
    60
krh@248
    61
void list_set_empty(struct list_head *head);
krh@248
    62
void list_set_ptr(struct list_head *head, uint32_t ptr);
krh@248
    63
void list_set_array(struct list_head *head, struct array *pool, struct array *items, int force_indirect);
krh@248
    64
krh@248
    65
struct list *list_first(struct list_head *head, struct array *pool);
krh@248
    66
struct list *list_next(struct list *list);
krh@248
    67
krh@248
    68
void list_remap_pool(struct array *pool, uint32_t *map);
krh@248
    69
void list_remap_head(struct list_head *list, uint32_t *map);
krh@248
    70
krh@248
    71
krh@248
    72
struct hashtable {
krh@248
    73
	struct array buckets;
krh@248
    74
	struct array *pool;
krh@248
    75
};
krh@248
    76
krh@248
    77
void hashtable_init(struct hashtable *table, struct array *pool);
krh@248
    78
void hashtable_release(struct hashtable *table);
krh@248
    79
uint32_t hashtable_insert(struct hashtable *table, const char *key);
krh@248
    80
uint32_t hashtable_lookup(struct hashtable *table, const char *key);
krh@248
    81
uint32_t hashtable_tokenize(struct hashtable *table, const char *string);
krh@248
    82
krh@248
    83
krh@248
    84
struct razor_set_section {
jbowes@318
    85
	uint32_t name;
krh@248
    86
	uint32_t offset;
krh@248
    87
	uint32_t size;
krh@248
    88
};
krh@248
    89
krh@248
    90
struct razor_set_header {
krh@248
    91
	uint32_t magic;
krh@248
    92
	uint32_t version;
jbowes@318
    93
	uint32_t num_sections;
krh@248
    94
};
krh@248
    95
jbowes@318
    96
#define RAZOR_MAGIC 	0x525a4442
jbowes@318
    97
#define RAZOR_VERSION	1
krh@248
    98
jbowes@318
    99
#define RAZOR_STRING_POOL		"string_pool"
jbowes@318
   100
#define RAZOR_PACKAGES			"packages"
jbowes@318
   101
#define RAZOR_PROPERTIES		"properties"
jbowes@318
   102
#define RAZOR_PACKAGE_POOL		"package_pool"
jbowes@318
   103
#define RAZOR_PROPERTY_POOL		"property_pool"
jbowes@258
   104
jbowes@318
   105
#define RAZOR_DETAILS_STRING_POOL	"details_string_pool"
jbowes@258
   106
jbowes@318
   107
#define RAZOR_FILES			"files"
jbowes@318
   108
#define RAZOR_FILE_POOL			"file_pool"
jbowes@318
   109
#define RAZOR_FILE_STRING_POOL		"file_string_pool"
krh@248
   110
krh@248
   111
struct razor_package {
jbowes@258
   112
	uint name  : 24;
jbowes@258
   113
	uint flags : 8;
krh@248
   114
	uint32_t version;
krh@248
   115
	uint32_t arch;
jbowes@258
   116
	uint32_t summary;
jbowes@258
   117
	uint32_t description;
jbowes@258
   118
	uint32_t url;
jbowes@258
   119
	uint32_t license;
krh@248
   120
	struct list_head properties;
krh@248
   121
	struct list_head files;
krh@248
   122
};
krh@248
   123
jbowes@258
   124
krh@248
   125
struct razor_property {
krh@248
   126
	uint32_t name;
krh@248
   127
	uint32_t flags;
krh@248
   128
	uint32_t version;
krh@248
   129
	struct list_head packages;
krh@248
   130
};
krh@248
   131
krh@248
   132
struct razor_entry {
krh@248
   133
	uint32_t name  : 24;
krh@248
   134
	uint32_t flags : 8;
krh@248
   135
	uint32_t start;
krh@248
   136
	struct list_head packages;
krh@248
   137
};
krh@248
   138
krh@248
   139
#define RAZOR_ENTRY_LAST	0x80
krh@248
   140
krh@248
   141
struct razor_set {
krh@248
   142
	struct array string_pool;
krh@248
   143
 	struct array packages;
krh@248
   144
 	struct array properties;
krh@248
   145
 	struct array files;
krh@248
   146
	struct array package_pool;
krh@248
   147
 	struct array property_pool;
krh@248
   148
 	struct array file_pool;
jbowes@258
   149
	struct array file_string_pool;
jbowes@258
   150
	struct array details_string_pool;
jbowes@318
   151
krh@248
   152
	struct razor_set_header *header;
jbowes@318
   153
	size_t header_size;
jbowes@318
   154
jbowes@258
   155
	struct razor_set_header *details_header;
jbowes@318
   156
	size_t details_header_size;
jbowes@318
   157
jbowes@258
   158
	struct razor_set_header *files_header;
jbowes@318
   159
	size_t files_header_size;
krh@248
   160
};
krh@248
   161
krh@248
   162
struct import_entry {
krh@248
   163
	uint32_t package;
krh@248
   164
	char *name;
krh@248
   165
};
krh@248
   166
krh@248
   167
struct import_directory {
krh@248
   168
	uint32_t name, count;
krh@248
   169
	struct array files;
krh@248
   170
	struct array packages;
krh@248
   171
	struct import_directory *last;
krh@248
   172
};
krh@248
   173
krh@248
   174
struct razor_importer {
krh@248
   175
	struct razor_set *set;
krh@248
   176
	struct hashtable table;
jbowes@258
   177
	struct hashtable file_table;
jbowes@258
   178
	struct hashtable details_table;
krh@248
   179
	struct razor_package *package;
krh@248
   180
	struct array properties;
krh@248
   181
	struct array files;
krh@248
   182
	struct array file_requires;
krh@248
   183
};
krh@248
   184
krh@248
   185
struct razor_package_iterator {
krh@248
   186
	struct razor_set *set;
krh@248
   187
	struct razor_package *package, *end;
krh@248
   188
	struct list *index;
krh@248
   189
	int free_index;
krh@248
   190
};
krh@248
   191
krh@248
   192
void
krh@248
   193
razor_package_iterator_init_for_property(struct razor_package_iterator *pi,
krh@248
   194
					 struct razor_set *set,
krh@248
   195
					 struct razor_property *property);
krh@248
   196
krh@248
   197
struct razor_property_iterator {
krh@248
   198
	struct razor_set *set;
krh@248
   199
	struct razor_property *property, *end;
krh@248
   200
	struct list *index;
krh@248
   201
};
krh@248
   202
krh@248
   203
struct razor_entry *
krh@248
   204
razor_set_find_entry(struct razor_set *set,
krh@248
   205
		     struct razor_entry *dir, const char *pattern);
krh@248
   206
krh@248
   207
struct razor_merger *
krh@248
   208
razor_merger_create(struct razor_set *set1, struct razor_set *set2);
krh@248
   209
void
krh@248
   210
razor_merger_add_package(struct razor_merger *merger,
krh@248
   211
			 struct razor_package *package);
krh@248
   212
struct razor_set *
krh@248
   213
razor_merger_finish(struct razor_merger *merger);
krh@248
   214
rhughes@241
   215
/* Utility functions */
rhughes@241
   216
richard@302
   217
void
richard@302
   218
razor_package_get_details_varg(struct razor_set *set,
richard@302
   219
			       struct razor_package *package,
richard@302
   220
			       va_list args);
richard@302
   221
rhughes@241
   222
int razor_create_dir(const char *root, const char *path);
rhughes@241
   223
int razor_write(int fd, const void *data, size_t size);
rhughes@241
   224
rhughes@241
   225
rhughes@241
   226
typedef int (*razor_compare_with_data_func_t)(const void *p1,
rhughes@241
   227
					      const void *p,
rhughes@241
   228
					      void *data);
rhughes@241
   229
uint32_t *
rhughes@241
   230
razor_qsort_with_data(void *base, size_t nelem, size_t size,
rhughes@241
   231
		      razor_compare_with_data_func_t compare, void *data);
rhughes@241
   232
rhughes@241
   233
#endif /* _RAZOR_INTERNAL_H_ */