Add a comment to search_rbtree().
[osl.git] / osl.c
diff --git a/osl.c b/osl.c
index 44e09d07ad20a179c111f06503ec4415c534e61e..c92412fbce765444c7a0d713cdeeffca35d824c1 100644 (file)
--- a/osl.c
+++ b/osl.c
@@ -11,8 +11,7 @@
 #include "log.h"
 #include "osl.h"
 #include "error.h"
 #include "log.h"
 #include "osl.h"
 #include "error.h"
-#include "fd.h"
-#include "list.h"
+#include "util.h"
 #include "osl_core.h"
 
 /* Taken from Drepper: How to write shared libraries, Appendix B. */
 #include "osl_core.h"
 
 /* Taken from Drepper: How to write shared libraries, Appendix B. */
 #define MSGSTRFIELD1(line) str##line
 static const union msgstr_t {
        struct {
 #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"
 #include "errtab.h"
-#undef _S
+#undef OSL_ERROR
        };
        char str[0];
 } msgstr = { {
        };
        char str[0];
 } msgstr = { {
-#define _S(n, s) s,
+#define OSL_ERROR(n, s) s,
 #include "errtab.h"
 #include "errtab.h"
-#undef _S
+#undef OSL_ERROR
 } };
 static const unsigned int errmsgidx[] = {
 } };
 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"
 #include "errtab.h"
-#undef _S
+#undef OSL_ERROR
 };
 
 __export const char *osl_strerror(int num)
 };
 
 __export const char *osl_strerror(int num)
@@ -107,8 +106,8 @@ static int __lseek(int fd, off_t *offset, int whence)
        return 1;
 }
 
        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;
 
 {
        int ret, fd;
 
@@ -117,11 +116,6 @@ static int append_file(const char *filename, char *header, size_t header_size,
        if (ret < 0)
                return ret;
        fd = ret;
        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;
        ret = write_all(fd, data, &data_size);
        if (ret < 0)
                goto out;
@@ -763,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;
 {
        struct osl_column *col = &t->columns[col_num];
        uint32_t offset;
-       char *header;
        char *cell_index;
        int ret;
 
        char *cell_index;
        int ret;
 
@@ -773,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);
        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;
 }
 
        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)
 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)
@@ -1153,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 *filename = column_filename(t, col_num);
        int ret;
-       char header = 0; /* zero means valid object */
 
        if (!filename)
                return -ERRNO_TO_ERROR(ENOMEM);
 
        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;
 }
        free(filename);
        return ret;
 }
@@ -1173,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);
        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;
 }
        free(filename);
        return ret;
 }
@@ -1380,21 +1368,6 @@ __export int osl_get_object(const struct osl_table *t, const struct osl_row *r,
        return 1;
 }
 
        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;
 __export int osl_del_row(struct osl_table *t, struct osl_row *row)
 {
        struct osl_row *r = row;
@@ -1418,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);
                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;
                        continue;
-               }
                if (st == OSL_NO_STORAGE && !(cd->storage_flags & OSL_DONT_FREE))
                        free(r->volatile_objects[col->volatile_num].data);
        }
                if (st == OSL_NO_STORAGE && !(cd->storage_flags & OSL_DONT_FREE))
                        free(r->volatile_objects[col->volatile_num].data);
        }
@@ -1627,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);
                        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);
                        if (ret < 0)
                                return ret;
                        unmap_column(t, col_num);