From: Andre Noll Date: Fri, 20 Jun 2008 08:22:33 +0000 (+0200) Subject: Get rid of E_INVALID_OBJECT. X-Git-Tag: v0.1.0~42 X-Git-Url: http://git.tuebingen.mpg.de/?p=osl.git;a=commitdiff_plain;h=6d7dce7f277fc8606fb8d5ed6360660c13a218af;hp=0c0c4530037fbe7f85ce2575cb3dd3003a424232 Get rid of E_INVALID_OBJECT. It's introduction of the one-byte header for mapped objects was a bad move because it changes the alignment of mapped objects. This also simplifies the code a bit. The downside is of course that this changes the on-disk data format. But hey, this stuff is still pre-beta, so.. --- diff --git a/errlist b/errlist index 06e2e80..9538aff 100644 --- a/errlist +++ b/errlist @@ -21,7 +21,6 @@ RB_KEY_EXISTS "key already exists in rbtree" RB_KEY_NOT_FOUND "key not found in rbtree" BAD_ROW_NUM "invalid row number" INDEX_CORRUPTION "index corruption detected" -INVALID_OBJECT "reference to invalid object" LSEEK "lseek error" BUSY "table is busy" SHORT_TABLE "table too short" diff --git a/fsck.c b/fsck.c index 27004a6..68e3107 100644 --- a/fsck.c +++ b/fsck.c @@ -407,13 +407,8 @@ static int check_index_ranges(struct osl_table *t) continue; ret = check_range(t, i, j); if (ret < 0) { - if (ret != -E_OSL_INVALID_OBJECT && - ret != -E_FSCK_RANGE_VIOLATION) + if (ret != -E_FSCK_RANGE_VIOLATION) goto err; - if (ret == -E_OSL_INVALID_OBJECT) { - CRIT_LOG("row %d, col %d maps to an " - "invalid object\n", i, j); - } ret = mark_row_invalid(t, i); if (ret < 0) goto err; @@ -517,14 +512,9 @@ static int check_for_invalid_objects(struct osl_table *t, uint32_t **lost_bytes) for (j = 0; j < t->num_rows; j++) { struct osl_object obj; ret = get_mapped_object(t, i, j, &obj); - if (ret >= 0) { - loss[i] -= obj.size + 1; /* add one for header byte */ - continue; - } - if (ret != -E_OSL_INVALID_OBJECT) + if (ret < 0) goto err; - CRIT_LOG("row %d, col %d points to an invalid " - "mapped object, bad\n", j, i); + loss[i] -= obj.size; } } ret = 0; diff --git a/osl.c b/osl.c index 974ad0c..9e6de44 100644 --- a/osl.c +++ b/osl.c @@ -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,14 +766,8 @@ 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; } @@ -1152,12 +1140,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 +1158,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 +1364,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 +1387,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 +1594,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); diff --git a/osl_core.h b/osl_core.h index 8a575c6..df32b60 100644 --- a/osl_core.h +++ b/osl_core.h @@ -303,8 +303,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); } /**