}
-int Allocator::find(Extent& ex, int bucket, block_t num, block_t near, bool fwdonly)
+int Allocator::find(Extent& ex, int bucket, block_t num, block_t near, int dir)
{
Table<block_t,block_t>::Cursor cursor(fs->free_tab[bucket]);
bool found = false;
- if (fs->free_tab[bucket]->find( near, cursor ) >= 0) {
+ if ((dir == DIR_ANY || dir == DIR_FWD) &&
+ fs->free_tab[bucket]->find( near, cursor ) >= 0) {
// look to the right
do {
if (cursor.current().value >= num)
} while (!found && cursor.move_right() > 0);
}
- if (!found && !fwdonly) {
+ if ((dir == DIR_ANY || dir == DIR_BACK) &&
+ !found) {
// look to the left
fs->free_tab[bucket]->find( near, cursor );
{
dump_freelist();
- bool fwd = false;
+ int dir = DIR_ANY; // no dir
if (near == NEAR_LAST_FWD) {
near = last_pos;
- fwd = true;
+ dir = DIR_FWD; // fwd
}
else if (near == NEAR_LAST)
near = last_pos;
// look for contiguous extent
for (bucket = pick_bucket(num); bucket < EBOFS_NUM_FREE_BUCKETS; bucket++) {
- if (find(ex, bucket, num, near, fwd) >= 0) {
+ if (find(ex, bucket, num, near, dir) >= 0) {
// yay!
// remove original
}
}
- if (!fwd) break;
- fwd = false;
+ if (dir == DIR_BACK || dir == DIR_ANY) break;
+ dir = DIR_BACK;
}
// ok, find partial extent instead.
const static block_t NEAR_LAST = 0;
const static block_t NEAR_LAST_FWD = 1;
+ const static int DIR_ANY = 0;
+ const static int DIR_FWD = 2;
+ const static int DIR_BACK = 1;
+
protected:
Ebofs *fs;
block_t last_pos;
return b;
}
- int find(Extent& ex, int bucket, block_t num, block_t near, bool fwdonly=false);
+ int find(Extent& ex, int bucket, block_t num, block_t near, int dir = DIR_ANY);
void dump_freelist();