*/
static int check_index_ranges(struct osl_table *t)
{
- int i, j, ret;
+ int ret;
+ unsigned k, n;
INFO_LOG("checking for range violations in index\n");
//DEBUG_LOG("%d rows. %d columns\n", t->num_rows, t->desc->num_columns);
t->num_invalid_rows = 0;
- for (i = 0; i < t->num_rows; i++) {
+ for (n = 0; n < t->num_rows; n++) {
const struct osl_column_description *cd;
- if (row_is_invalid(t, i)) {
+ if (row_is_invalid(t, n)) {
t->num_invalid_rows++;
continue;
}
- FOR_EACH_MAPPED_COLUMN(j, t, cd) {
- ret = check_range(t, i, j);
+ FOR_EACH_MAPPED_COLUMN(k, t, cd) {
+ ret = check_range(t, n, k);
if (ret < 0) {
if (ret != -E_FSCK_RANGE_VIOLATION)
goto err;
- ret = fsck_mark_row_invalid(t, i);
+ ret = fsck_mark_row_invalid(t, n);
if (ret < 0)
goto err;
t->num_invalid_rows++;
static int check_for_invalid_objects(struct osl_table *t, uint32_t **lost_bytes)
{
- int i, j, ret;
+ int ret;
+ unsigned k, n;
const struct osl_column_description *cd;
uint32_t *loss = fsck_malloc(sizeof(uint32_t) * t->desc->num_columns);
INFO_LOG("looking for mapped objects not contained in index\n");
/* first count used bytes */
- FOR_EACH_MAPPED_COLUMN(i, t, cd) {
- loss[i] = t->columns[i].data_map.size;
- DEBUG_LOG("column %i data map: %zu bytes\n", i,
- t->columns[i].data_map.size);
- for (j = 0; j < t->num_rows; j++) {
+ FOR_EACH_MAPPED_COLUMN(k, t, cd) {
+ loss[k] = t->columns[k].data_map.size;
+ DEBUG_LOG("column %i data map: %zu bytes\n", k,
+ t->columns[k].data_map.size);
+ for (n = 0; n < t->num_rows; n++) {
struct osl_object obj;
- ret = get_mapped_object(t, i, j, &obj);
+ ret = get_mapped_object(t, k, n, &obj);
if (ret < 0)
goto err;
- loss[i] -= obj.size;
+ loss[k] -= obj.size;
}
}
ret = 0;
- FOR_EACH_MAPPED_COLUMN(i, t, cd) {
- if (loss[i]) {
+ FOR_EACH_MAPPED_COLUMN(k, t, cd) {
+ if (loss[k]) {
NOTICE_LOG("column %u contains %u lost bytes\n",
- i, loss[i]);
+ k, loss[k]);
ret = 1;
}
}
/* prune_invalid_rows() must be run on the table before calling this */
static int prune_mapped_column(struct osl_table *t, uint32_t col_num, int fd)
{
- int i, ret;
+ int ret;
+ unsigned n;
uint32_t written = 0;
struct osl_column *col = t->columns + col_num;
INFO_LOG("pruning col %u\n", col_num);
- for (i = 0; i < t->num_rows; i++) {
+ for (n = 0; n < t->num_rows; n++) {
struct osl_object obj;
char *index_entry;
- DEBUG_LOG("checking row %u/%u\n", i, t->num_rows);
- ret = get_mapped_object(t, col_num, i, &obj);
+ DEBUG_LOG("checking row %u/%u\n", n, t->num_rows);
+ ret = get_mapped_object(t, col_num, n, &obj);
if (ret < 0)
return ret;
ret = _write_all(fd, (char *)(obj.data), obj.size);
if (ret < 0)
return ret;
written += obj.size;
- ret = get_row_index(t, i, &index_entry);
+ ret = get_row_index(t, n, &index_entry);
if (ret < 0)
return ret;
update_cell_index(index_entry, col, written, obj.size);
static int check_disk_storage_presence(struct osl_table *t)
{
- int ret, i, j;
+ int ret;
+ unsigned k, n;
struct osl_object obj, hash_obj = {.size = HASH_SIZE};
char *ds_name;
const struct osl_column_description *cd;
return 1;
hashes = fsck_malloc(t->num_rows * HASH_SIZE);
INFO_LOG("looking for missing disk storage objects\n");
- for (i = 0; i < t->num_rows; i++) {
- if (row_is_invalid(t, i))
+ for (k = 0; k < t->num_rows; k++) {
+ if (row_is_invalid(t, k))
continue;
- ret = get_mapped_object(t, dsnc, i, &obj);
+ ret = get_mapped_object(t, dsnc, k, &obj);
if (ret < 0)
return ret;
- hash_object(&obj, hashes + i * HASH_SIZE);
- hash_obj.data = hashes + i * HASH_SIZE;
+ hash_object(&obj, hashes + k * HASH_SIZE);
+ hash_obj.data = hashes + k * HASH_SIZE;
osl_add_row(hash_tree_table, &hash_obj);
- ds_name = disk_storage_name_of_hash(t, hashes + i * HASH_SIZE);
- FOR_EACH_DISK_STORAGE_COLUMN(j, t, cd) {
- ret = check_disk_storage_column(t, i, j, ds_name,
+ ds_name = disk_storage_name_of_hash(t, hashes + k * HASH_SIZE);
+ FOR_EACH_DISK_STORAGE_COLUMN(n, t, cd) {
+ ret = check_disk_storage_column(t, k, n, ds_name,
&missing_objects);
if (ret < 0)
goto err;
int main(int argc, char **argv)
{
- int i, ret;
+ int ret;
+ unsigned n;
char *errctx = NULL;
const char *dd;
ret = check_all_tables(dd);
goto out;
}
- for (i = 0; i < lls_num_inputs(lpr); i++) {
- ret = check_table(dd, lls_input(i, lpr));
+ for (n = 0; n < lls_num_inputs(lpr); n++) {
+ ret = check_table(dd, lls_input(n, lpr));
if (ret < 0)
break;
}
int row_is_invalid(struct osl_table *t, uint32_t row_num)
{
char *row_index;
- int i, ret = get_row_index(t, row_num, &row_index);
+ int ret = get_row_index(t, row_num, &row_index);
+ unsigned n;
if (ret < 0)
return ret;
- for (i = 0; i < t->row_index_size; i++) {
- if ((unsigned char)row_index[i] != 0xff)
+ for (n = 0; n < t->row_index_size; n++) {
+ if ((unsigned char)row_index[n] != 0xff)
return 0;
}
INFO_LOG("row %d is invalid\n", row_num);
*/
int init_rbtrees(struct osl_table *t)
{
- int i, ret;
+ int ret;
+ unsigned n;
const struct osl_column_description *cd;
/* create rbtrees */
- FOR_EACH_RBTREE_COLUMN(i, t, cd)
- t->columns[i].rbtree = RB_ROOT;
+ FOR_EACH_RBTREE_COLUMN(n, t, cd)
+ t->columns[n].rbtree = RB_ROOT;
/* add valid rows to rbtrees */
t->num_invalid_rows = 0;
- for (i = 0; i < t->num_rows; i++) {
+ for (n = 0; n < t->num_rows; n++) {
struct osl_object *volatile_objs;
- ret = row_is_invalid(t, i);
+ ret = row_is_invalid(t, n);
if (ret < 0)
return ret;
if (ret) {
return -E_OSL_NOMEM;
} else
volatile_objs = NULL;
- ret = add_row_to_rbtrees(t, i, volatile_objs, NULL);
+ ret = add_row_to_rbtrees(t, n, volatile_objs, NULL);
if (ret < 0)
return ret;
}