/*
- * Copyright (C) 2007-2009 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2007-2009 Andre Noll <maan@tuebingen.mpg.de>
*
* Licensed under the GPL v2. For licencing details see COPYING.
*/
#include "util.h"
#include "osl_core.h"
-/* Taken from Drepper: How to write shared libraries, Appendix B. */
+/*
+ * Taken from Drepper: How to write shared libraries, Appendix B.
+ *
+ * The main reason for this rather fancy implementation of strerror() is to
+ * avoid having an array of pointers. This is desirable because initialized
+ * pointer variables increase the startup time of the library due to the
+ * processing of relocations.
+ */
#include <stddef.h>
#define MSGSTRFIELD(line) MSGSTRFIELD1(line)
#define MSGSTRFIELD1(line) str##line
__printf_2_3 void __log(int ll, const char* fmt,...)
{
va_list argp;
- FILE *outfd;
struct tm *tm;
time_t t1;
char str[255] = "";
if (ll < loglevel)
return;
- outfd = stderr;
time(&t1);
tm = localtime(&t1);
strftime(str, sizeof(str), "%b %d %H:%M:%S", tm);
- fprintf(outfd, "%s ", str);
+ fprintf(stderr, "%s ", str);
va_start(argp, fmt);
- vfprintf(outfd, fmt, argp);
+ vfprintf(stderr, fmt, argp);
va_end(argp);
}
ret = -E_OSL_BAD_STORAGE_FLAGS;
if (st == OSL_DISK_STORAGE && sf & OSL_RBTREE)
goto err;
+ if ((sf & OSL_RBTREE) && !(sf & OSL_UNIQUE))
+ WARNING_LOG("invalid storage flags for column %s: "
+ "OSL_RBTREE && !OSL_UNIQUE\n", cd->name);
ret = -E_OSL_BAD_STORAGE_SIZE;
if (sf & OSL_FIXED_SIZE && !cd->data_size)
goto err;
int read_table_desc(struct osl_object *map, struct osl_table_description *desc)
{
char *buf = map->data;
- uint8_t version;
+ uint8_t table_version;
uint16_t header_size;
int ret, i;
unsigned offset;
return -E_OSL_SHORT_TABLE;
if (strncmp(buf + IDX_OSL_MAGIC, OSL_MAGIC, strlen(OSL_MAGIC)))
return -E_OSL_NO_MAGIC;
- version = read_u8(buf + IDX_VERSION);
- if (version < MIN_TABLE_VERSION || version > MAX_TABLE_VERSION)
+ table_version = read_u8(buf + IDX_VERSION);
+ INFO_LOG("osl versions (table/min/current): %u/%u/%u\n",
+ table_version, MIN_TABLE_VERSION, CURRENT_TABLE_VERSION);
+ if (table_version < MIN_TABLE_VERSION /* table too old */
+ || table_version > CURRENT_TABLE_VERSION) /* libosl too old */
return -E_OSL_VERSION_MISMATCH;
desc->flags = read_u8(buf + IDX_TABLE_FLAGS);
desc->num_columns = read_u16(buf + IDX_NUM_COLUMNS);
strcpy(buf + offset + IDX_CD_NAME, cd->name);
offset += index_column_description_size(cd->name);
}
- assert(offset = size);
+ assert(offset == size);
filename = index_filename(t->desc);
if (filename)
ret = write_file(filename, buf, size);
/* add valid rows to rbtrees */
t->num_invalid_rows = 0;
for (i = 0; i < t->num_rows; i++) {
+ struct osl_object *volatile_objs;
ret = row_is_invalid(t, i);
if (ret < 0)
return ret;
t->num_invalid_rows++;
continue;
}
- ret = add_row_to_rbtrees(t, i, NULL, NULL);
+ if (t->num_volatile_columns > 0) {
+ volatile_objs = calloc(t->num_volatile_columns,
+ sizeof(struct osl_object));
+ if (!volatile_objs)
+ return -E_OSL_NOMEM;
+ } else
+ volatile_objs = NULL;
+ ret = add_row_to_rbtrees(t, i, volatile_objs, NULL);
if (ret < 0)
return ret;
}
__export int osl_open_table(const struct osl_table_description *table_desc,
struct osl_table **result)
{
- int i, ret;
+ int ret;
struct osl_table *t;
- const struct osl_column_description *cd;
NOTICE_LOG("opening table %s\n", table_desc->name);
ret = init_table_structure(table_desc, &t);
if (ret < 0)
return ret;
- FOR_EACH_DISK_STORAGE_COLUMN(i, t, cd) {
- struct stat statbuf;
- char *dirname = column_filename(t, i);
-
- ret = -E_OSL_NOMEM;
- if (!dirname)
- goto err;
- /* check if directory exists */
- ret = osl_stat(dirname, &statbuf);
- free(dirname);
- if (ret < 0)
- goto err;
- ret = -E_OSL_NOTDIR;
- if (!S_ISDIR(statbuf.st_mode))
- goto err;
- }
ret = map_table(t, MAP_TBL_FL_VERIFY_INDEX);
if (ret < 0)
goto err;
}
remove_rb_node(t, col_num, r);
if (cd->storage_type == OSL_NO_STORAGE) { /* TODO: If fixed size, reuse object? */
- free(r->volatile_objects[col->volatile_num].data);
+ if (!(cd->storage_flags & OSL_DONT_FREE))
+ free(r->volatile_objects[col->volatile_num].data);
r->volatile_objects[col->volatile_num] = *obj;
} else if (cd->storage_type == OSL_DISK_STORAGE) {
char *ds_name;
unsigned num_rows;
int ret;
+ *result = NULL;
if (n == 0)
return -E_OSL_RB_KEY_NOT_FOUND;
ret = osl_get_num_rows(t, &num_rows);