REPO.txt
author Kristian H?gsberg <krh@redhat.com>
Mon Apr 07 00:06:22 2008 -0400 (2008-04-07)
changeset 196 b38fc517ea04
permissions -rw-r--r--
Merger razor_transaction_run() and destroy() as finish().
danw@181
     1
The repo file format / razor_set data structure
danw@181
     2
-----------------------------------------------
danw@181
     3
danw@181
     4
The repo starts with a header, containing some number of sections,
danw@181
     5
terminated by a section with type 0:
danw@181
     6
danw@181
     7
	struct razor_set_header {
danw@181
     8
		uint32_t magic;
danw@181
     9
		uint32_t version;
danw@181
    10
		struct razor_set_section sections[0];
danw@181
    11
	};
danw@181
    12
danw@181
    13
	struct razor_set_section {
danw@181
    14
		uint32_t type;
danw@181
    15
		uint32_t offset;
danw@181
    16
		uint32_t size;
danw@181
    17
	};
danw@181
    18
danw@181
    19
razor_set_open() mmaps the repo file, and creates a struct razor_set:
danw@181
    20
danw@181
    21
	struct razor_set {
danw@181
    22
		struct array string_pool;
danw@181
    23
	 	struct array packages;
danw@181
    24
	 	struct array properties;
danw@181
    25
	 	struct array files;
danw@181
    26
		struct array package_pool;
danw@181
    27
	 	struct array property_pool;
danw@181
    28
	 	struct array file_pool;
danw@181
    29
		struct razor_set_header *header;
danw@181
    30
	};
danw@181
    31
danw@181
    32
by finding the sections with those IDs and creating "struct array"s
danw@181
    33
pointing to the right places in the mmapped data. (This is the only
danw@181
    34
processing needed when reading in the file; everything else is used
danw@181
    35
exactly as-is.)
danw@181
    36
danw@181
    37
danw@181
    38
The sections
danw@181
    39
------------
danw@181
    40
danw@181
    41
RAZOR_STRING_POOL
danw@181
    42
danw@181
    43
	Stores one copy of each string that appears in the repo. (At
danw@181
    44
	the moment, this is: package names, package versions, property
danw@181
    45
	names, property versions, and (basenames of) filenames.) The
danw@181
    46
	strings are arbitrarily-sized, 0-terminated, and not in any
danw@181
    47
	particular order (although the empty string always ends up
danw@181
    48
	being at offset 0).
danw@181
    49
danw@181
    50
RAZOR_PACKAGES
danw@181
    51
danw@181
    52
	Array of struct razor_package; one for each package in the
danw@181
    53
	set, sorted by name.
danw@181
    54
danw@181
    55
RAZOR_PROPERTIES
danw@181
    56
danw@181
    57
	Array of struct razor_property; one for each unique property
danw@181
    58
	in the set, sorted by type, then name, then relation type (eg,
danw@181
    59
	"<" or ">="), then version. (Properties with no version have
danw@181
    60
	relation type RAZOR_VERSION_EQUAL, and version "".)
danw@181
    61
danw@181
    62
RAZOR_FILES
danw@181
    63
danw@181
    64
	Array of struct razor_entry; one for each file owned by any
danw@181
    65
	package in the set. The current sort order (which is subject
danw@181
    66
	to change) is breadth-first, sorted by basename. So eg: /, /bin,
danw@181
    67
	/dev, /etc, /bin/false, /bin/true, /dev/null, /etc/passwd.
danw@181
    68
danw@181
    69
RAZOR_PACKAGE_POOL
danw@181
    70
danw@181
    71
	Array of struct list, with each list item containing the index
danw@181
    72
	of a struct razor_package in the packages section. See the
danw@181
    73
	discussion of lists below.
danw@181
    74
danw@181
    75
RAZOR_PROPERTY_POOL
danw@181
    76
danw@181
    77
	Array of struct list, with each list item containing the index
danw@181
    78
	of a struct razor_property in the properties section. See the
danw@181
    79
	discussion of lists below.
danw@181
    80
danw@181
    81
RAZOR_FILE_POOL
danw@181
    82
danw@181
    83
	Array of struct list, with each list item containing the index
danw@181
    84
	of a struct razor_entry in the files section. See the
danw@181
    85
	discussion of lists below.
danw@181
    86
danw@181
    87
danw@181
    88
Data types
danw@181
    89
----------
danw@181
    90
Note that the exact layout of bits involves some historical accidents.
danw@181
    91
(Particularly the fact that the "name" field in most structs loses its
danw@181
    92
high bits to a flags field.)
danw@181
    93
danw@181
    94
struct list_head
danw@181
    95
	uint list_ptr : 24;
danw@181
    96
	uint flags    : 8;
danw@181
    97
danw@181
    98
struct list
danw@181
    99
	uint data  : 24;
danw@181
   100
	uint flags : 8;
danw@181
   101
danw@181
   102
	Used to store lists of package, property, or file IDs. "struct
danw@181
   103
	list_head" stores the head of the list, which points to one or
danw@181
   104
	more "struct list"s in the appropriate "pool" section.
danw@181
   105
	("struct list" should probably be called "struct list_item".)
danw@181
   106
danw@181
   107
	"list_first(&head, &pool)" returns a "struct list *" pointing
danw@181
   108
	to the first element of the list (or NULL for an empty list),
danw@181
   109
	and "list_next(list)" will return successive elements, until
danw@181
   110
	NULL is returned. Each "list->data" contains the index of a
danw@181
   111
	package, property, or file in the corresponding section of the
danw@181
   112
	set.
danw@181
   113
danw@181
   114
	Peeking underneath the abstraction, a list_head's "flags" is
danw@181
   115
	0xff if the list is empty, 0x80 if it contains a single
danw@181
   116
	element, or 0x00 if it contains more than one element. In the
danw@181
   117
	single-element case, that element is actually stored in the
danw@181
   118
	list_head directly rather than being stored in a pool (and so
danw@181
   119
	list_first() just casts the list_head* to a list* and returns
danw@181
   120
	it). For multi-element lists, list_ptr is the index in the
danw@181
   121
	pool of the first element of this list; the list continues
danw@181
   122
	through successive elements of the pool until one with
danw@181
   123
	non-zero flags is reached, indicating the end of the list.
danw@181
   124
danw@181
   125
struct razor_package
danw@181
   126
	uint name    : 24;
danw@181
   127
	uint flags   : 8;
danw@181
   128
	uint version : 32;
danw@181
   129
	struct list_head properties;
danw@181
   130
	struct list_head files;
danw@181
   131
danw@181
   132
	name and version are indexes into string_pool. properties is a
danw@181
   133
	list of all of the package's properties, and files is a list
danw@181
   134
	of its files. flags is currently only used during razor_set
danw@181
   135
	merging, to keep track of which set a package came from.
danw@181
   136
danw@181
   137
struct razor_property
danw@181
   138
	uint name     : 24;
danw@181
   139
	uint flags    : 6;
danw@181
   140
	uint type     : 2;
danw@181
   141
	uint relation : 32;
danw@181
   142
	uint version  : 32;
danw@181
   143
	struct list_head packages;
danw@181
   144
danw@181
   145
	name and version are indexes into string_pool. type is an enum
danw@181
   146
	razor_property_type (eg, RAZOR_PROPERTY_REQUIRES), and
danw@181
   147
	relation is an enum razor_version_relation (eg,
danw@181
   148
	RAZOR_VERSION_GREATER_OR_EQUAL). packages is a list of the
danw@181
   149
	packages that have this property. flags is currently unused.
danw@181
   150
danw@181
   151
struct razor_entry
danw@181
   152
	uint name  : 24;
danw@181
   153
	uint flags : 8;
danw@181
   154
	uint start : 32;
danw@181
   155
	struct list_head packages;
danw@181
   156
danw@181
   157
	name is an index into string_pool, giving the basename of the
danw@181
   158
	file. start is either 0, or an index pointing to another
danw@181
   159
	razor_entry that is the first child of this entry (for a
danw@181
   160
	non-empty directory). (Entry 0 is always the root of the tree,
danw@181
   161
	so no entry could have entry 0 as a child.) flags is 0x80
danw@181
   162
	(RAZOR_ENTRY_LAST) if an entry is the last entry in its
danw@181
   163
	directory. Otherwise it is 0.
danw@181
   164
danw@181
   165
	Note that given a pointer to a struct_razor_entry (eg, from a
danw@181
   166
	package's "files" list), there is no way to reconstruct its
danw@181
   167
	full name without walking the entire files array up to that
danw@181
   168
	point. Because of this and other problems (fix_file_map()), it
danw@181
   169
	seems like razor_entry should be modified to include a pointer
danw@181
   170
	to its parent. (Storing full paths instead of just basenames
danw@181
   171
	would also fix this problem, but that would use much more
danw@181
   172
	memory.)