Git init
[pkgs/e/elektra.git] / doc / storage.xml
1
2 <!--
3 $Id$
4 $LastChangedBy$
5 -->
6         <note><para>This section is provided for the sake of the openness of Elektra. You should not access the Elektra's key files directly. You should use the API or the <citerefentry><refentrytitle>kdb</refentrytitle><manvolnum>1</manvolnum></citerefentry> command for that.</para></note>
7         <section id="keystor"><title>Elektra Key Storage Strategy</title>
8                 <para>Elektra implements a very simple way to store the key-value pairs. The value (and some metainfo) for each key is stored in a single file. The key name (and some of its context) is sufficient to find the file name that stores the value.</para>
9                 <para>The <filename>system/*</filename> keys are stored under <filename>/etc/kdb/</filename>, and the <filename>user/*</filename> keys can be found under each user's <filename>$HOME/.kdb/</filename>.</para>
10                 <para>Here are some examples of key names, and where Elektra goes to look for them in the disk.</para>
11                 <variablelist>
12                         <varlistentry><term><filename>system/sw/XFree86/screen0/driver</filename></term>
13                                 <listitem><para>Maps to: <filename>/etc/kdb/system/sw/XFree86/screen0/driver</filename></para></listitem>
14                         </varlistentry>
15                         <varlistentry><term><filename>user/env/PATH</filename></term>
16                                 <listitem><para>Maps to: <filename>~$USER/.kdb/user/env/PATH</filename></para></listitem>
17                         </varlistentry>
18                         <varlistentry><term><filename>user:luciana/env/PATH</filename></term >
19                                 <listitem><para>Maps to: <filename>~luciana/.kdb/user/env/PATH</filename></para></listitem>
20                         </varlistentry>
21                         <varlistentry><term><filename>system/mime.types/some.mime</filename></term>
22                                 <listitem><para>Maps to: <filename>/etc/kdb/system/mime.types/some.mime</filename></para></listitem>
23                         </varlistentry>
24                 </variablelist>
25                 <para>Some may think that one file per key will consume many filesystem i-nodes. Actually, when not using Reiser4 filesystem, it may consume some more disk space, and it may also be not so efficient than reading one single text file, as KConfig does. But Elektra's nature lets applications load their keys on demand; so it is possible to avoid the read-all-use-some approach. Writing updated keys back to disk is also more robust, because unchanged keys won't be touched, different from a single file approach, that must be entirelly rewritten.</para>
26                 <para>Besides that, big applications (like Mozilla, Konqueror, KDE, Gnome) key gathering time is a very small part of what they have to do to start up. And the benefits of an homogeneous key database to the entire system are much bigger then these issues. Think about a common integration between everything, flexibility, security granularity and openness.</para>
27         </section>
28
29         <section id="noxml"><title>XML, Storage Backends and Elektra</title>
30                 <para>This document you are just reading was written in DocBook XML. XML is a wonderfull technology, but brings no value to this software. Two main goals of the Elektra Project are to be lightweight, and to be accessible by early boot stage programs like <command>/sbin/init</command> and the <filename class="directory">/etc/rc.d</filename> scripts.</para>
31                 <para>XML parsing libraries are memory eaters, not so fast as we can expect, and they are usualy located under <filename class="directory">/usr/lib</filename>, which may be unavailable to these early boot stage needs.</para>
32                 <para>Some discussions asked for a sort of plugin architecture to let user decide the format to store keys content. Well, the info that goes into the key file is not big deal as you'll see, and sometimes, too many options is bad business, and not the path for the Elektra Project.</para>
33                 <para>So no XML, no plugin architecture, no sophistication. Lets keep it simple and generic. A very straight forward text based file format was defined to store a single key value.</para>
34         </section>
35                         
36         <section id="keyinternal"><title>Key Files Format</title>
37                 <para>Inside Elektra key database, each key is a file, and every file is a key. So most of the key's metainformation are actually its file attributes, as you can see in a regular <citerefentry><refentrytitle>ls</refentrytitle><manvolnum>1</manvolnum></citerefentry> command output.</para>
38                 <para>So what needs to be stored inside the key file is the data type (binary or text), key comment and the actual data. The format of each key file is:</para>
39                 <screen>File Format Version
40 Data Type
41 As many lines of
42 comments as we want (UTF-8 encoded)
43 &#060;DATA&#062;
44 The data encoded as text
45                 </screen>
46                 <para>So if we set the key <filename>system/hw/eth0/driver</filename> as type <type>String</type> and value "<replaceable>3com</replaceable>", and comment "<replaceable>The driver for my network interface</replaceable>", we'll find the file <filename>/etc/kdb/system/hw/eth0/driver</filename> containing:</para>
47                 <screen>RG002
48 40
49 The driver for my network interface
50 &#060;DATA&#062;
51 3com
52                 </screen>
53                 <para>Other example: setting <filename>user/tmp/proprietary</filename> as <type>Binary</type>, and value "<replaceable>A groovy data I want to hide</replaceable>", and comment "<replaceable>Stay away from here</replaceable>", you'll get in <filename>~$USER/.kdb/user/tmp/proprietary</filename> the following:</para>
54                 <screen>RG002
55 20
56 Stay away from here
57 &#060;DATA&#062;
58 41206772 6f6f7679 20646174 61204920 77616e74 20746f20 68696465
59                 </screen>
60                 <para>The current data types are:</para>
61                 <variablelist>
62                         <varlistentry><term>Between 20 and 39</term>
63                                 <listitem><simpara>Binary value. The data will be encoded into a text format. Today only type 20 is used, and means a raw stream of bytes with no special semantics to Elektra. The other values are reserved for future use; being treated still as binary values but possibly with some semantics to Elektra or a higher level application.</simpara></listitem>
64                         </varlistentry>
65                         <varlistentry><term>40 up to 254</term>
66                                 <listitem><simpara>Text, UTF-8 encoded. Values higher then 40 are reserved for future or application specific implementations of more abstract data types, like time/date, color, font, etc. But always represented as pure text that can be edited in any text editor like <citerefentry><refentrytitle>vi</refentrytitle><manvolnum>1</manvolnum></citerefentry>.</simpara></listitem>
67                         </varlistentry>
68                 </variablelist>
69                 <para>Types between 0 and 19 are used only internaly in the API, and will never appear into a key file. They are used to define meta keys as directory, link, etc.</para>
70         </section>