/*
* ea_refcount.c
- *
+ *
* Copyright (C) 2001 Theodore Ts'o. This file may be
* redistributed under the terms of the GNU Public License.
*/
+#include "config.h"
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <string.h>
#include <stdio.h>
+#ifdef TEST_PROGRAM
+#undef ENABLE_NLS
+#endif
#include "e2fsck.h"
/*
* follows. We keep a sorted array of first EA blocks and its
* reference counts. Once the refcount has dropped to zero, it is
* removed from the array to save memory space. Once the EA block is
- * checked, its bit is set in the block_ea_map bitmap.
+ * checked, its bit is set in the block_ea_map bitmap.
*/
struct ea_refcount_el {
blk_t ea_blk;
new_size = refcount->size + 100;
#ifdef DEBUG
printf("Reallocating refcount %d entries...\n", new_size);
-#endif
+#endif
retval = ext2fs_resize_mem((size_t) refcount->size *
sizeof(struct ea_refcount_el),
(size_t) new_size *
static struct ea_refcount_el *get_refcount_el(ext2_refcount_t refcount,
blk_t blk, int create)
{
- float range;
int low, high, mid;
- blk_t lowval, highval;
if (!refcount || !refcount->list)
return 0;
}
if (refcount->count == 0)
return 0;
-
+
if (refcount->cursor >= refcount->count)
refcount->cursor = 0;
if (blk == refcount->list[refcount->cursor].ea_blk)
printf("Non-cursor get_refcount_el: %u\n", blk);
#endif
while (low <= high) {
-#if 0
mid = (low+high)/2;
-#else
- if (low == high)
- mid = low;
- else {
- /* Interpolate for efficiency */
- lowval = refcount->list[low].ea_blk;
- highval = refcount->list[high].ea_blk;
-
- if (blk < lowval)
- range = 0;
- else if (blk > highval)
- range = 1;
- else
- range = ((float) (blk - lowval)) /
- (highval - lowval);
- mid = low + ((int) (range * (high-low)));
- }
-#endif
if (blk == refcount->list[mid].ea_blk) {
refcount->cursor = mid+1;
return &refcount->list[mid];
int *ret)
{
struct ea_refcount_el *el;
-
+
el = get_refcount_el(refcount, blk, 0);
if (!el) {
*ret = 0;
int *ret)
{
struct ea_refcount_el *list;
-
+
while (1) {
if (refcount->cursor >= refcount->count)
return 0;
errcode_t ret = 0;
int i;
const char *bad = "bad refcount";
-
+
if (refcount->count > refcount->size) {
fprintf(out, "%s: count > size\n", bad);
return EXT2_ET_INVALID_ARGUMENT;
size = bcode_program[i++];
retval = ea_refcount_create(size, &refcount);
if (retval) {
- com_err("ea_refcount_create",
- retval, "");
+ com_err("ea_refcount_create", retval,
+ "while creating size %d", size);
exit(1);
} else
printf("Creating refcount with size %d\n",
case BCODE_STORE:
blk = (blk_t) bcode_program[i++];
arg = bcode_program[i++];
- retval = ea_refcount_store(refcount, blk, arg);
printf("Storing blk %u with value %d\n", blk, arg);
+ retval = ea_refcount_store(refcount, blk, arg);
if (retval)
- com_err("ea_refcount_store", retval, "");
+ com_err("ea_refcount_store", retval,
+ "while storing blk %u", blk);
break;
case BCODE_FETCH:
blk = (blk_t) bcode_program[i++];
retval = ea_refcount_fetch(refcount, blk, &arg);
if (retval)
- com_err("ea_refcount_fetch", retval, "");
+ com_err("ea_refcount_fetch", retval,
+ "while fetching blk %u", blk);
else
printf("bcode_fetch(%u) returns %d\n",
blk, arg);
break;
case BCODE_INCR:
blk = (blk_t) bcode_program[i++];
- retval = ea_refcount_increment(refcount, blk,
- &arg);
+ retval = ea_refcount_increment(refcount, blk, &arg);
if (retval)
com_err("ea_refcount_increment", retval,
- "");
+ "while incrementing blk %u", blk);
else
printf("bcode_increment(%u) returns %d\n",
blk, arg);
break;
case BCODE_DECR:
blk = (blk_t) bcode_program[i++];
- retval = ea_refcount_decrement(refcount, blk,
- &arg);
+ retval = ea_refcount_decrement(refcount, blk, &arg);
if (retval)
com_err("ea_refcount_decrement", retval,
"while decrementing blk %u", blk);
case BCODE_VALIDATE:
retval = ea_refcount_validate(refcount, stderr);
if (retval)
- com_err("ea_refcount_validate",
- retval, "");
+ com_err("ea_refcount_validate", retval,
+ "while validating");
else
printf("Refcount validation OK.\n");
break;
case BCODE_LIST:
ea_refcount_intr_begin(refcount);
while (1) {
- blk = ea_refcount_intr_next(refcount,
- &arg);
+ blk = ea_refcount_intr_next(refcount, &arg);
if (!blk)
break;
- printf("\tblk=%u, count=%d\n", blk,
- arg);
+ printf("\tblk=%u, count=%d\n", blk, arg);
}
break;
case BCODE_COLLAPSE:
refcount_collapse(refcount);
break;
}
-
+
}
}