Merge branch 'refs/heads/t/sha3' into master
[osl.git] / fsck.c
diff --git a/fsck.c b/fsck.c
index 42312d9..53b4a9b 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -393,24 +393,25 @@ static int fsck_mark_row_invalid(struct osl_table *t, int i)
  */
 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++;
@@ -505,29 +506,30 @@ static int prune_invalid_rows_from_index(struct osl_table *t)
 
 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;
                }
        }
@@ -543,24 +545,25 @@ err:
 /* 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);
@@ -702,7 +705,8 @@ out:
 
 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;
@@ -712,18 +716,18 @@ static int check_disk_storage_presence(struct osl_table *t)
                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(t, &obj, hashes + i * HASH_SIZE);
-               hash_obj.data = hashes + i * HASH_SIZE;
+               hash_object(t, &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;
@@ -1225,7 +1229,8 @@ static int check_all_tables(const char *db_dir)
 
 int main(int argc, char **argv)
 {
-       int i, ret;
+       int ret;
+       unsigned n;
        char *errctx = NULL;
        const char *dd;
 
@@ -1267,8 +1272,8 @@ int main(int argc, char **argv)
                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;
        }