X-Git-Url: http://git.tuebingen.mpg.de/?p=osl.git;a=blobdiff_plain;f=osl_core.h;h=e98c33538bfff043b2ae94145e9dee2b836f28bc;hp=b6d1f8222878de726dfadeced976fc1f9c99799f;hb=758c28419b5b0876bee510f1fb4e01b75b2918f5;hpb=02e6053e5976c6aa4bf538f3469335835d54e478 diff --git a/osl_core.h b/osl_core.h index b6d1f82..e98c335 100644 --- a/osl_core.h +++ b/osl_core.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2008 Andre Noll + * Copyright (C) 2007-2009 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -7,10 +7,9 @@ /** \file osl_core.h Object storage layer details, not visible to users. */ #include "rbtree.h" -#include "osl.h" #include "hash.h" -static __must_check __printf_1_2 __malloc char *make_message(const char *fmt, ...); +__must_check __printf_1_2 __malloc char *make_message(const char *fmt, ...); /** Internal representation of a column of an osl table. */ struct osl_column { @@ -39,6 +38,13 @@ struct osl_column { struct osl_table { /** Pointer to the table description */ const struct osl_table_description *desc; + /** + * The CURRENT_TABLE_VERSION value of the library which created the + * table. This value is stored in the index header at table creation + * time. When the table is opened, the field is initialized from the + * on-disk value. + */ + uint8_t version; /** The size of the index header of this table. */ uint16_t index_header_size; /** Contains the mapping of the table's index file */ @@ -84,7 +90,6 @@ int init_table_structure(const struct osl_table_description *desc, int row_is_invalid(struct osl_table *t, uint32_t row_num); int get_mapped_object(const struct osl_table *t, unsigned col_num, uint32_t row_num, struct osl_object *obj); -int para_truncate(const char *filename, off_t size); int unmap_table(struct osl_table *t, enum osl_close_flags flags); int init_rbtrees(struct osl_table *t); @@ -135,7 +140,7 @@ _static_inline_ struct osl_column_description *get_column_description( */ enum index_header_offsets { /** Bytes 0-8: PARASLASH. */ - IDX_PARA_MAGIC = 0, + IDX_OSL_MAGIC = 0, /** Byte 9: Dirty flag (nonzero if table is mapped). */ IDX_DIRTY_FLAG = 9, /** Byte 10: osl table version number. */ @@ -167,7 +172,7 @@ enum index_column_desc_offsets { }; /** Magic string contained in the header of the index file of each osl table. */ -#define PARA_MAGIC "PARASLASH" +#define OSL_MAGIC "PARASLASH" /** * The minimal number of bytes for a column in the index header. @@ -192,9 +197,20 @@ _static_inline_ size_t index_column_description_size(const char *name) return MIN_IDX_COLUMN_DESCRIPTION_SIZE + strlen(name) - 1; } -#define CURRENT_TABLE_VERSION 1 +/* + * The version used by this instance of the library. Written to the index of + * newly created tables. + */ +#define CURRENT_TABLE_VERSION 3 + +/* + * The lowest table version this library understands. On open, if + * current_version(table) < min_version(lib) the osl_open_table() call + * fails. + */ #define MIN_TABLE_VERSION 1 -#define MAX_TABLE_VERSION 1 + + /** An index header must be at least that many bytes long. */ #define MIN_INDEX_HEADER_SIZE(num_cols) (MIN_IDX_COLUMN_DESCRIPTION_SIZE \ * num_cols + IDX_COLUMN_DESCRIPTIONS) @@ -261,7 +277,7 @@ _static_inline_ int get_row_index(const struct osl_table *t, uint32_t row_num, index_offset = t->index_header_size + t->row_index_size * row_num; if (index_offset + 8 > t->index_map.size) { *row_index = NULL; - return -E_INDEX_CORRUPTION; + return -E_OSL_INDEX_CORRUPTION; } *row_index = (char *)(t->index_map.data) + index_offset; return 1; @@ -305,8 +321,8 @@ _static_inline_ int get_cell_index(const struct osl_table *t, uint32_t row_num, _static_inline_ void update_cell_index(char *row_index, struct osl_column *col, uint32_t map_size, uint32_t object_size) { - write_u32(row_index + col->index_offset, map_size - object_size - 1); - write_u32(row_index + col->index_offset + 4, object_size + 1); + write_u32(row_index + col->index_offset, map_size - object_size); + write_u32(row_index + col->index_offset + 4, object_size); } /** @@ -347,8 +363,8 @@ _static_inline_ char *disk_storage_path(const struct osl_table *t, * \sa FOR_EACH_COLUMN_OF_TYPE, FOR_EACH_MAPPED_COLUMN, FOR_EACH_RBTREE_COLUMN, * FOR_EACH_DISK_STORAGE_COLUMN, FOR_EACH_VOLATILE_COLUMN, osl_storage_type. */ -_static_inline_ int next_column_of_type(enum osl_storage_type type, int col_num, - const struct osl_table *t, +_static_inline_ unsigned next_column_of_type(enum osl_storage_type type, + unsigned col_num, const struct osl_table *t, const struct osl_column_description **cd) { *cd = NULL; @@ -440,12 +456,14 @@ _static_inline_ struct osl_row *get_row_pointer(const struct rb_node *node, /** * Compute a cryptographic hash of an osl object. * + * \param t Determines the hash function to use. * \param obj the Object to compute the hash value from. * \param hash Result is returned here. */ -_static_inline_ void hash_object(const struct osl_object *obj, HASH_TYPE *hash) +_static_inline_ void hash_object(const struct osl_table *t, + const struct osl_object *obj, HASH_TYPE *hash) { - hash_function(obj->data, obj->size, hash); + hash_function(t->version, obj->data, obj->size, hash); } /** @@ -474,23 +492,6 @@ _static_inline_ char *disk_storage_name_of_hash(const struct osl_table *t, HASH_ return strdup(asc); } -/** - * A wrapper for rename(2). - * - * \param old_path The source path. - * \param new_path The destination path. - * - * \return Standard. - * - * \sa rename(2). - */ -_static_inline_ int para_rename(const char *old_path, const char *new_path) -{ - if (rename(old_path, new_path) < 0) - return -ERRNO_TO_ERROR(errno); - return 1; -} - /** * Iterate over each column of an initialized table. *