X-Git-Url: http://git.tuebingen.mpg.de/?p=osl.git;a=blobdiff_plain;f=osl.c;h=c92412fbce765444c7a0d713cdeeffca35d824c1;hp=31b40c2c8d84c58cdfe5537faf7124f254196e15;hb=5498b872d9e28af6210b957c2336be65b1900522;hpb=c1a4bb030717f2d2d209ccd8ab898ab66fa16869 diff --git a/osl.c b/osl.c index 31b40c2..c92412f 100644 --- a/osl.c +++ b/osl.c @@ -20,20 +20,20 @@ #define MSGSTRFIELD1(line) str##line static const union msgstr_t { struct { -#define _S(n, s) char MSGSTRFIELD(__LINE__)[sizeof(s)]; +#define OSL_ERROR(n, s) char MSGSTRFIELD(__LINE__)[sizeof(s)]; #include "errtab.h" -#undef _S +#undef OSL_ERROR }; char str[0]; } msgstr = { { -#define _S(n, s) s, +#define OSL_ERROR(n, s) s, #include "errtab.h" -#undef _S +#undef OSL_ERROR } }; static const unsigned int errmsgidx[] = { -#define _S(n, s) [n] = offsetof(union msgstr_t, MSGSTRFIELD(__LINE__)), +#define OSL_ERROR(n, s) [n] = offsetof(union msgstr_t, MSGSTRFIELD(__LINE__)), #include "errtab.h" -#undef _S +#undef OSL_ERROR }; __export const char *osl_strerror(int num) @@ -106,8 +106,8 @@ static int __lseek(int fd, off_t *offset, int whence) return 1; } -static int append_file(const char *filename, char *header, size_t header_size, - char *data, size_t data_size, uint32_t *new_pos) +static int append_file(const char *filename, char *data, size_t data_size, + uint32_t *new_pos) { int ret, fd; @@ -116,11 +116,6 @@ static int append_file(const char *filename, char *header, size_t header_size, if (ret < 0) return ret; fd = ret; - if (header && header_size) { - ret = write_all(fd, header, &header_size); - if (ret < 0) - goto out; - } ret = write_all(fd, data, &data_size); if (ret < 0) goto out; @@ -762,7 +757,6 @@ int get_mapped_object(const struct osl_table *t, unsigned col_num, { struct osl_column *col = &t->columns[col_num]; uint32_t offset; - char *header; char *cell_index; int ret; @@ -772,17 +766,15 @@ int get_mapped_object(const struct osl_table *t, unsigned col_num, if (ret < 0) return ret; offset = read_u32(cell_index); - obj->size = read_u32(cell_index + 4) - 1; - header = col->data_map.data + offset; - obj->data = header + 1; - if (read_u8(header) == 0xff) { - ERROR_LOG("col %u, size %zu, offset %u\n", col_num, - obj->size, offset); - return -E_OSL_INVALID_OBJECT; - } + obj->size = read_u32(cell_index + 4); + obj->data = col->data_map.data + offset; return 1; } +/* + * It's OK to call this with result = rb_node = NULL. If result is not NULL, + * and rb key was not found, result points to the parent node. + */ static int search_rbtree(const struct osl_object *obj, const struct osl_table *t, unsigned col_num, struct rb_node **result, struct rb_node ***rb_link) @@ -1152,12 +1144,10 @@ static int append_map_file(const struct osl_table *t, unsigned col_num, { char *filename = column_filename(t, col_num); int ret; - char header = 0; /* zero means valid object */ if (!filename) return -ERRNO_TO_ERROR(ENOMEM); - ret = append_file(filename, &header, 1, obj->data, obj->size, - new_size); + ret = append_file(filename, obj->data, obj->size, new_size); free(filename); return ret; } @@ -1172,8 +1162,7 @@ static int append_row_index(const struct osl_table *t, char *row_index) filename = index_filename(t->desc); if (!filename) return -ERRNO_TO_ERROR(ENOMEM); - ret = append_file(filename, NULL, 0, row_index, - t->row_index_size, NULL); + ret = append_file(filename, row_index, t->row_index_size, NULL); free(filename); return ret; } @@ -1379,21 +1368,6 @@ __export int osl_get_object(const struct osl_table *t, const struct osl_row *r, return 1; } -static int mark_mapped_object_invalid(const struct osl_table *t, - uint32_t row_num, unsigned col_num) -{ - struct osl_object obj; - char *p; - int ret = get_mapped_object(t, col_num, row_num, &obj); - - if (ret < 0) - return ret; - p = obj.data; - p--; - *p = 0xff; - return 1; -} - __export int osl_del_row(struct osl_table *t, struct osl_row *row) { struct osl_row *r = row; @@ -1417,10 +1391,8 @@ __export int osl_del_row(struct osl_table *t, struct osl_row *row) struct osl_column *col = t->columns + i; enum osl_storage_type st = cd->storage_type; remove_rb_node(t, i, r); - if (st == OSL_MAPPED_STORAGE) { - mark_mapped_object_invalid(t, r->num, i); + if (st == OSL_MAPPED_STORAGE) continue; - } if (st == OSL_NO_STORAGE && !(cd->storage_flags & OSL_DONT_FREE)) free(r->volatile_objects[col->volatile_num].data); } @@ -1626,9 +1598,6 @@ __export int osl_update_object(struct osl_table *t, const struct osl_row *r, uint32_t new_data_map_size; char *row_index; ret = get_row_index(t, r->num, &row_index); - if (ret < 0) - return ret; - ret = mark_mapped_object_invalid(t, r->num, col_num); if (ret < 0) return ret; unmap_column(t, col_num);