2 * Copyright (C) 2007-2008 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file osl.h User interface for the object storage layer. */
11 /** Export all declarations in this file. */
12 #pragma GCC visibility push(default)
14 /** Describes an object of the object storage layer (osl) */
16 /** Pointer to the data of the object. */
18 /** The object's size. */
22 /** Flags that change the internal handling of osl tables. */
23 enum osl_table_flags {
24 /** This table will have many rows. */
28 /** The three different types of storage for an osl column */
29 enum osl_storage_type {
31 * All data for this column is stored in one file which gets mmapped by
32 * osl_open_table(). This is suitable for columns that do not hold much
37 * Each entry is stored on disk and is loaded on demand by
38 * open_disk_object(). This is the preferable storage type for large
39 * objects that need not be in memory all the time.
43 * Objects for columns of this type are volatile: They are only stored
44 * in memory and are discarded once the table gets closed.
50 * Additional per-column flags
52 enum osl_storage_flags {
54 * Build an rbtree for this column. This is only possible if the
55 * storage type of the column is either \a OSL_MAPPED_STORAGE or \a
56 * OSL_NO_STORAGE. In order to lookup objects in the table by using \a
57 * osl_get_row(), the lookup column must have an associated rbtree.
59 * \sa osl_storage_type, osl_get_row()
62 /** The data for this column will have constant size. */
64 /** All values of this column will be different. */
66 /** Do not free the data for this column (\p OSL_NO_STORAGE). */
70 /** Opaque osl table structure. */
72 /** Opaque osl row structure. */
76 * In order to build up an rbtree a compare function for the objects must be
77 * specified. Such a function always takes pointers to the two objects to be
78 * compared. It must return -1, zero, or 1, if the first argument is considered
79 * to be respectively less than, equal to, or greater than the second. If two
80 * members compare as equal, their order in the sorted array is undefined.
82 typedef int osl_compare_func(const struct osl_object *obj1,
83 const struct osl_object *obj2);
86 * The osl_rbreee_loop functions take a function pointer of this type. For each
87 * node in the rbtree, the given function is called.
89 * \sa osl_rbtree_loop(), osl_rbtree_loop_reverse().
91 typedef int osl_rbtree_loop_func(struct osl_row *row, void *data);
94 * Describes one column of a osl table.
96 struct osl_column_description {
97 /** One of the tree possible types of storage */
98 enum osl_storage_type storage_type;
99 /** Specifies further properties of the column */
100 enum osl_storage_flags storage_flags;
102 * The column name determines the name of the directory where all data
103 * for this column will be stored. Its hash is stored in the table
104 * header. This field is ignored if the storage type is \a NO_STORAGE
108 * For columns with an associated rbtree, this must point to a function
109 * that compares the values of two objects, either a built-in function
110 * or a function defined by the application may be supplied. This
111 * field is ignored if the column does not have an associated rbtree.
113 * \sa osl_storage_flags, osl_compare_func
115 osl_compare_func *compare_function;
117 * If the \a OSL_FIXED_SIZE flag is set for this column, this value
118 * determines the fixed size of all objects of this column. It is
119 * ignored, if \a OSL_FIXED_SIZE is not set.
125 * Describes one osl table.
127 struct osl_table_description {
128 /** The directory which contains all files of this table. */
131 * The table name. A subdirectory of \a dir called \a name is created
132 * at table creation time. It must be a valid name for a subdirectory.
133 * In particular, no slashes are allowed for \a name.
136 /** The number of columns of this table. */
137 uint16_t num_columns;
138 /** Further table-wide information. */
139 enum osl_table_flags flags;
140 /** The array describing the individual columns of the table. */
141 struct osl_column_description *column_descriptions;
144 /** Flags to be passed to \a osl_close_table(). */
145 enum osl_close_flags {
147 * The table header contains a "dirty" flag which specifies whether
148 * the table is currently open by another process. This flag specifies
149 * that the dirty flag should be cleared before closing the table.
153 * If the table contains columns of type \a OSL_NO_STORAGE and this
154 * flag is passed to osl_close_table(), free(3) is called for each
155 * object of each column of type \a OSL_NO_STORAGE.
157 OSL_FREE_VOLATILE = 2
160 int osl_create_table(const struct osl_table_description *desc);
161 int osl_open_table(const struct osl_table_description *desc,
162 struct osl_table **result);
163 int osl_close_table(struct osl_table *t, enum osl_close_flags flags);
164 int osl_get_row(const struct osl_table *t, unsigned col_num,
165 const struct osl_object *obj, struct osl_row **result);
166 int osl_get_object(const struct osl_table *t, const struct osl_row *row,
167 unsigned col_num, struct osl_object *object);
168 int osl_open_disk_object(const struct osl_table *t,
169 const struct osl_row *r, unsigned col_num, struct osl_object *obj);
170 int osl_close_disk_object(struct osl_object *obj);
171 int osl_add_and_get_row(struct osl_table *t, struct osl_object *objects,
172 struct osl_row **row);
173 int osl_add_row(struct osl_table *t, struct osl_object *objects);
174 int osl_del_row(struct osl_table *t, struct osl_row *row);
175 int osl_rbtree_loop(const struct osl_table *t, unsigned col_num,
176 void *private_data, osl_rbtree_loop_func *func);
177 int osl_rbtree_loop_reverse(const struct osl_table *t, unsigned col_num,
178 void *private_data, osl_rbtree_loop_func *func);
179 int osl_update_object(struct osl_table *t, const struct osl_row *r,
180 unsigned col_num, struct osl_object *obj);
181 int osl_get_num_rows(const struct osl_table *t, unsigned *num_rows);
182 int osl_rbtree_first_row(const struct osl_table *t, unsigned col_num,
183 struct osl_row **result);
184 int osl_rbtree_last_row(const struct osl_table *t, unsigned col_num,
185 struct osl_row **result);
186 int osl_get_nth_row(const struct osl_table *t, unsigned col_num,
187 unsigned n, struct osl_row **result);
188 int osl_get_rank(const struct osl_table *t, struct osl_row *r,
189 unsigned col_num, unsigned *rank);
190 int osl_hash_compare(const struct osl_object *obj1,
191 const struct osl_object *obj2);
192 const char *osl_strerror(int nr);
194 #pragma GCC visibility pop