/*
- * Copyright (C) 2007 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2007-2009 Andre Noll <maan@systemlinux.org>
*
* Licensed under the GPL v2. For licencing details see COPYING.
*/
static struct osl_column_description score_cols[] = {
[SCORECOL_AFT_ROW] = {
.storage_type = OSL_NO_STORAGE,
- .storage_flags = OSL_RBTREE | OSL_FIXED_SIZE | OSL_UNIQUE,
+ .storage_flags = OSL_RBTREE | OSL_FIXED_SIZE | OSL_UNIQUE | OSL_DONT_FREE,
.name = "aft_row",
.compare_function = ptr_compare,
.data_size = sizeof(void *)
assert(aft_row);
size = score_table_desc.column_descriptions[SCORECOL_AFT_ROW].data_size;
- score_objs[SCORECOL_AFT_ROW].data = para_malloc(size);
+ score_objs[SCORECOL_AFT_ROW].data = (struct osl_row *)aft_row;
score_objs[SCORECOL_AFT_ROW].size = size;
- *(const void **)(score_objs[SCORECOL_AFT_ROW].data) = aft_row;
size = score_table_desc.column_descriptions[SCORECOL_SCORE].data_size;
score_objs[SCORECOL_SCORE].data = para_malloc(size);
// PARA_DEBUG_LOG("adding %p\n", *(void **) (score_objs[SCORECOL_AFT_ROW].data));
ret = osl_add_row(score_table, score_objs);
if (ret < 0) {
- PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
- free(score_objs[SCORECOL_AFT_ROW].data);
+ PARA_ERROR_LOG("%s\n", para_strerror(-ret));
free(score_objs[SCORECOL_SCORE].data);
}
return ret;
struct osl_row *row;
long new_score;
unsigned n, new_pos;
- struct osl_object obj = {.data = &aft_row, .size = sizeof(void **)};
+ struct osl_object obj = {.data = (struct osl_row *)aft_row,
+ .size = sizeof(aft_row)};
int ret = osl_get_row(score_table, SCORECOL_AFT_ROW, &obj, &row);
+ if (ret == -E_RB_KEY_NOT_FOUND) /* not an error */
+ return 1;
if (ret < 0)
return ret;
ret = get_num_admissible_files(&n);
ret = osl_get_object(score_table, score_row, SCORECOL_AFT_ROW, &obj);
if (ret < 0)
return ret;
- *aft_row = *(void **)obj.data;
+ *aft_row = obj.data;
return 1;
}
static int get_score_row_from_aft_row(const struct osl_row *aft_row,
struct osl_row **score_row)
{
- struct osl_object obj = {.data = &aft_row, .size = sizeof(void **)};
+ struct osl_object obj = {.data = (struct osl_row *)aft_row,
+ .size = sizeof(aft_row)};
return osl_get_row(score_table, SCORECOL_AFT_ROW, &obj, score_row);
}
ret = osl_get_object(score_table, row, SCORECOL_AFT_ROW, &obj);
if (ret < 0)
return ret;
- *aft_row = *(void **)obj.data;
+ *aft_row = obj.data;
return get_score_of_row(row, score);
}
return osl_open_table(&score_table_desc, &score_table);
}
-static int score_event_handler(enum afs_events event, struct para_buffer *pb,
- void *data)
+/**
+ * Remove all entries from the score table, but keep the table open.
+ *
+ * \return Standard.
+ */
+int clear_score_table(void)
{
- int ret;
+ score_close();
+ return score_open(NULL);
+}
- switch(event) {
- case ATTRIBUTE_ADD:
- case ATTRIBUTE_REMOVE:
- case ATTRIBUTE_RENAME: {
- score_close();
- return score_open(NULL);
- }
- default: return 1;
- }
+static int score_event_handler(__a_unused enum afs_events event,
+ __a_unused struct para_buffer *pb, __a_unused void *data)
+{
+ return 1;
}
/**
* Initialize the scoring subsystem.
*
- * \param t The members of \t are filled in by the function.
+ * \param t The members of \a t are filled in by the function.
*/
void score_init(struct afs_table *t)
{