diff --git a/src/sys/ubixfsv2/btree.cpp b/src/sys/ubixfsv2/btree.cpp index e04822c..7812af2 100644 --- a/src/sys/ubixfsv2/btree.cpp +++ b/src/sys/ubixfsv2/btree.cpp @@ -77,7 +77,7 @@ * Find the leaf node the inode goes into */ assert(bnode->used); -// cout << "---Inserting " << inode->name << "@" << inode << endl; +// cout << "---Inserting " << inode->name << " @ " << inode << endl; while (bnode != NULL && !bnode->leaf) { if (strcmp(inode->name, bnode->keys[0]) < 0) { bnode = (bNode *)bnode->head[0]; diff --git a/src/sys/ubixfsv2/fsAbstract.h b/src/sys/ubixfsv2/fsAbstract.h index e04860f..67ca178 100644 --- a/src/sys/ubixfsv2/fsAbstract.h +++ b/src/sys/ubixfsv2/fsAbstract.h @@ -9,7 +9,7 @@ protected: vfs_abstract * prev; vfs_abstract * next; - void * dev; + dev_t * device; public: /* File I/O */ virtual int vfs_open(FILE *,int flags,...) = 0; diff --git a/src/sys/ubixfsv2/ubixfs.cpp b/src/sys/ubixfsv2/ubixfs.cpp index 554a7d4..ef9c28c 100644 --- a/src/sys/ubixfsv2/ubixfs.cpp +++ b/src/sys/ubixfsv2/ubixfs.cpp @@ -3,20 +3,25 @@ #include "inode.h" #include "superblock.h" -UbixFS::UbixFS(void) { +UbixFS::UbixFS(dev_t * dev) { + device = dev; freeBlockList = NULL; } // UbixFS::UbixFS +int +UbixFS::init(void) { + return 0; +} // UbixFS::init + int32 UbixFS::getFreeBlock(uInt32 AG) { // AG == AllocationGroup signed char * ptr; - signed char * endPtr; int32 count; int32 subCount = 128; // Check to make sure neither of these are null - if (freeBlockList == NULL || superBlock == NULL) return -1; + if (device == NULL || freeBlockList == NULL || superBlock == NULL) return -1; // Are there any blocks available? if (superBlock->numBlocks == superBlock->usedBlocks) return -1; @@ -40,28 +45,26 @@ ptr = freeBlockList + (count >> 3); - /* - * endPtr is the very last address we can look at before we wrap around - * This calculation is probably not correct if the number of blocks isn't - * divisible by 8 - */ - - endPtr = freeBlockList + ((superBlock->numAGs << superBlock->AGShift) >> 3); - // Scan through the freeBlockList + +rescan: while (*ptr == -1) { - if (++ptr == endPtr) { - ptr = freeBlockList; - count = 0; - } else { - count +=8; - } // else + ++ptr; + count += 8; + if (count+8 > superBlock->numBlocks) break; } // while *ptr == -1 + subCount = 128; + do { if ((*ptr & subCount) == 0) break; subCount >>= 1; ++count; + if (count == numBlocks) { + count = 0; + ptr = freeBlockList; + goto rescan; + } // if } while(subCount > 1); *ptr |= subCount; // mark this block as used @@ -89,6 +92,39 @@ } // UbixFS::getFreeBlock +int32 +UbixFS::get8FreeBlocks(uInt32 AG) { + // AG == AllocationGroup + signed char * ptr; + signed char * endPtr; + int32 count; + + if (device == NULL || freeBlockList == NULL || superBlock == NULL) return -1; + + // Are there any blocks available? + if (superBlock->usedBlocks+8 > superBlock->numBlocks) return -1; + + /* + * count is the block from the base of the list. + * Since we're given a specific AG to look through, we start the count at + * AG << AGShift, where AGShift is the shift value of the number of blocks + * in an AG + */ + + count = (AG << superBlock->AGShift); + + endPtr = freeBlockList + (superBlock->numBlocks >> 3); + + bool secondTime = false; + while (*ptr != 0 && ptr < endPtr) { + ++ptr; + count += 8; + if (ptr == endPtr) { + count = 0; + + } // if + } // while +} // UbixFS::get8FreeBlocks int UbixFS::format(dev_t * dev) { diff --git a/src/sys/ubixfsv2/ubixfs.h b/src/sys/ubixfsv2/ubixfs.h index a8c1956..49746a8 100644 --- a/src/sys/ubixfsv2/ubixfs.h +++ b/src/sys/ubixfsv2/ubixfs.h @@ -10,8 +10,10 @@ diskSuperBlock * superBlock; int32 getFreeBlock(uInt32); int32 getFreeBlock(void); + int32 get8FreeBlocks(uInt32); public: - UbixFS(void); + UbixFS(dev_t *); + virtual int init(void); virtual int format(dev_t *); virtual ~UbixFS(void); }; // UbixFS