docs/package-set.xml
author J. Ali Harlow <ali@juiblex.co.uk>
Sat Aug 23 16:07:09 2014 +0100 (2014-08-23)
changeset 441 cf499fd51df7
parent 311 cd292c2de0b6
permissions -rw-r--r--
Drop drive letter from path to razor root when RAZOR_ROOT set.

If the RAZOR_ROOT environment variable was set to eg., /root then on
Microsoft Windows we were trying to use paths such as /rootC:/Programs
which is obviously wrong. Instead we should drop the drive letter
giving paths of the form /root/Programs. Note that the drive letter is
_not_ migrated to C:/root/Programs: If a root of C:/root was desired
then RAZOR_ROOT would have been set to C:/root.
     1 <?xml version="1.0" encoding="utf-8"?>
     2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
     3 
     4 <chapter id="file-format">
     5   <title>Package Set File Format</title>
     6   
     7   <sect2 id="file-header">
     8     <title>File header</title>
     9     
    10     <para>
    11       The rzdb file starts with a header, containing some number of
    12       sections, terminated by a section with type 0:
    13     </para>
    14 
    15     <programlisting><![CDATA[
    16 struct razor_set_header {
    17 	uint32_t magic;
    18 	uint32_t version;
    19 	struct razor_set_section sections[0];
    20 };
    21 
    22 struct razor_set_section {
    23 	uint32_t type;
    24 	uint32_t offset;
    25 	uint32_t size;
    26 };
    27 ]]></programlisting>
    28 
    29     <para>
    30       razor_set_open() mmaps the rzdb file, and creates a struct razor_set:
    31     </para>
    32 
    33     <programlisting><![CDATA[
    34 struct razor_set {
    35 	struct array string_pool;
    36  	struct array packages;
    37  	struct array properties;
    38  	struct array files;
    39 	struct array package_pool;
    40  	struct array property_pool;
    41  	struct array file_pool;
    42 	struct razor_set_header *header;
    43 };
    44 ]]></programlisting>
    45 
    46     <para>
    47       by finding the sections with those IDs and creating struct
    48       array's pointing to the right places in the mmapped data. (This
    49       is the only processing needed when reading in the file;
    50       everything else is used exactly as-is.)
    51     </para>
    52 
    53   </sect2>
    54 
    55   <sect2 id="sections">
    56     <title>The sections</title>
    57 
    58     <itemizedlist>
    59       <listitem>
    60         <para>
    61           <emphasis>RAZOR_STRING_POOL</emphasis> Stores one copy of
    62 	  each string that appears in the rzdb file. (At the moment,
    63 	  this is: package names, package versions, property names,
    64 	  property versions, and (basenames of) filenames.) The
    65 	  strings are arbitrarily-sized, 0-terminated, and not in any
    66 	  particular order (although the empty string always ends up
    67 	  being at offset 0).
    68 	</para>
    69       </listitem>
    70 
    71       <listitem>
    72         <para>
    73           <emphasis>RAZOR_PACKAGES</emphasis> Array of struct
    74 	  razor_package; one for each package in the set, sorted by
    75 	  name.
    76 	</para>
    77       </listitem>
    78 
    79       <listitem>
    80         <para>
    81           <emphasis>RAZOR_PROPERTIES</emphasis> Array of struct
    82 	  razor_property; one for each unique property in the set,
    83 	  sorted by type, then name, then relation type (eg, "&lt;" or
    84 	  "&gt;="), then version. (Properties with no version have
    85 	  relation type RAZOR_VERSION_EQUAL, and version "".)
    86 	</para>
    87       </listitem>
    88 	    
    89       <listitem>
    90         <para>
    91           <emphasis>RAZOR_FILES</emphasis> Array of struct
    92 	  razor_entry; one for each file owned by any package in the
    93 	  set. The current sort order (which is subject to change)
    94 	  is breadth-first, sorted by basename. So eg: /, /bin,
    95 	  /dev, /etc, /bin/false, /bin/true, /dev/null, /etc/passwd.
    96 	</para>
    97       </listitem>
    98 
    99       <listitem>
   100         <para>
   101           <emphasis>RAZOR_PACKAGE_POOL</emphasis> Array of struct
   102 	  list, with each list item containing the index of a struct
   103 	  razor_package in the packages section. See the discussion
   104 	  of lists below.
   105 	</para>
   106       </listitem>
   107 
   108       <listitem>
   109         <para>
   110           <emphasis>RAZOR_PROPERTY_POOL</emphasis> Array of struct
   111 	  list, with each list item containing the index of a struct
   112 	  razor_property in the properties section. See the
   113 	  discussion of lists below.
   114 	</para>
   115       </listitem>
   116 
   117       <listitem>
   118         <para>
   119           <emphasis>RAZOR_FILE_POOL</emphasis> Array of struct list,
   120 	  with each list item containing the index of a struct
   121 	  razor_entry in the files section. See the discussion of
   122 	  lists below.
   123 	</para>
   124       </listitem>
   125     </itemizedlist>
   126   </sect2>
   127 
   128   <sect2 id="data-types">
   129     <title>Data types</title>
   130 
   131     <para>
   132       Note that the exact layout of bits involves some historical
   133       accidents.  (Particularly the fact that the "name" field in most
   134       structs loses its high bits to a flags field.)
   135     </para>
   136 
   137     <programlisting><![CDATA[
   138 struct list_head
   139 	uint list_ptr : 24;
   140 	uint flags    : 8;
   141 
   142 struct list
   143 	uint data  : 24;
   144 	uint flags : 8;
   145 ]]></programlisting>
   146 
   147     <para>
   148       Used to store lists of package, property, or file IDs. "struct
   149       list_head" stores the head of the list, which points to one or
   150       more "struct list"s in the appropriate "pool" section.  ("struct
   151       list" should probably be called "struct list_item".)
   152     </para>
   153 
   154     <para>
   155       "list_first(&amp;head, &amp;pool)" returns a "struct list *"
   156       pointing to the first element of the list (or NULL for an empty
   157       list), and "list_next(list)" will return successive elements,
   158       until NULL is returned. Each "list->data" contains the index of
   159       a package, property, or file in the corresponding section of the
   160       set.
   161     </para>
   162 
   163     <para>
   164       Peeking underneath the abstraction, a list_head's "flags" is
   165       0xff if the list is empty, 0x80 if it contains a single element,
   166       or 0x00 if it contains more than one element. In the
   167       single-element case, that element is actually stored in the
   168       list_head directly rather than being stored in a pool (and so
   169       list_first() just casts the list_head* to a list* and returns
   170       it). For multi-element lists, list_ptr is the index in the pool
   171       of the first element of this list; the list continues through
   172       successive elements of the pool until one with non-zero flags is
   173       reached, indicating the end of the list.
   174     </para>
   175 
   176     <programlisting><![CDATA[
   177 struct razor_package
   178 	uint name    : 24;
   179 	uint flags   : 8;
   180 	uint version : 32;
   181 	struct list_head properties;
   182 	struct list_head files;
   183 ]]></programlisting>
   184 
   185     <para>
   186       name and version are indexes into string_pool. properties is a
   187       list of all of the package's properties, and files is a list of
   188       its files. flags is currently only used during razor_set
   189       merging, to keep track of which set a package came from.
   190     </para>
   191 
   192     <programlisting><![CDATA[
   193 struct razor_property
   194 	uint name     : 24;
   195 	uint flags    : 6;
   196 	uint type     : 2;
   197 	uint relation : 32;
   198 	uint version  : 32;
   199 	struct list_head packages;
   200 ]]></programlisting>
   201 
   202     <para>
   203       name and version are indexes into string_pool. type is an enum
   204       razor_property_type (eg, RAZOR_PROPERTY_REQUIRES), and relation
   205       is an enum razor_version_relation (eg,
   206       RAZOR_VERSION_GREATER_OR_EQUAL). packages is a list of the
   207       packages that have this property. flags is currently unused.
   208     </para>
   209 
   210     <programlisting><![CDATA[
   211 struct razor_entry
   212 	uint name  : 24;
   213 	uint flags : 8;
   214 	uint start : 32;
   215 	struct list_head packages;
   216 ]]></programlisting>
   217 
   218     <para>
   219       name is an index into string_pool, giving the basename of the
   220       file. start is either 0, or an index pointing to another
   221       razor_entry that is the first child of this entry (for a
   222       non-empty directory). (Entry 0 is always the root of the tree,
   223       so no entry could have entry 0 as a child.) flags is 0x80
   224       (RAZOR_ENTRY_LAST) if an entry is the last entry in its
   225       directory. Otherwise it is 0.
   226     </para>
   227 
   228     <para>
   229       Note that given a pointer to a struct_razor_entry (eg, from a
   230       package's "files" list), there is no way to reconstruct its full
   231       name without walking the entire files array up to that
   232       point. Because of this and other problems (fix_file_map()), it
   233       seems like razor_entry should be modified to include a pointer
   234       to its parent. (Storing full paths instead of just basenames
   235       would also fix this problem, but that would use much more
   236       memory.)
   237     </para>
   238   </sect2>
   239 </chapter>