diff --git a/src/sys/ubixfsv2/ubixfs.cpp b/src/sys/ubixfsv2/ubixfs.cpp index 0dbe748..a72d4ec 100644 --- a/src/sys/ubixfsv2/ubixfs.cpp +++ b/src/sys/ubixfsv2/ubixfs.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -191,6 +192,7 @@ ubixfsInode * inode = NULL; inode = new ubixfsInode; + assert(inode); if (inode == NULL) return NULL; memset(inode, 0, sizeof(ubixfsInode)); @@ -253,7 +255,7 @@ if (sb == NULL) return -1; memset(sb, 0, sizeof(diskSuperBlock)); - // dev->size is the size of the device in 512 sectors + // dev->size is the size of the device in 512 byte sectors blocks = (dev->size-1) / 8; // 4k blocks batSize = (dev->size-1) % 8; // remainder @@ -283,6 +285,9 @@ sb->numAGs = (sb->numBlocks+2047) / 2048; sb->lastUsedAG = 0; + // the BAT exists outside our official block count, so no + // entries in the BAT need to be set for it + sb->BAT.allocationGroup = batSect / sb->blocksPerAG; sb->BAT.start = batSect % sb->blocksPerAG; sb->BAT.len = (batSize+7) / 8; @@ -298,11 +303,43 @@ sb->indicies.start = 0; sb->indicies.len = 0; - sb->rootDir.allocationGroup = 2; + sb->rootDir.allocationGroup = 0; sb->rootDir.start = 0; sb->rootDir.len = 1; + // write out the superBlock dev->write(dev, sb, dev->size-1, 1); + + // mark the first two 4k blocks used + sector[0] = (1 << 7) | (1 << 6); + // write out the first sector of the BAT + dev->write(dev, §or, batSect, 1); + // clear the rest + sector[0] = 0; + // write out the rest of the BAT + dev->write(dev, §or, batSect+1, batSize-1); + + /* allocate part of the root dir */ + + // sanity checks + assert(superBlock->blockSize); + assert((unsigned)superBlock->blockSize >= sizeof(bTreeHeader)); + + bTreeHeader * bth = (bTreeHeader *)malloc(superBlock->blockSize); + assert(bth); + memset(bth, 0, superBlock->blockSize); + bth->firstDeleted = bth->firstNodeOffset = -1; + + // write out the "root" dir inode + ubixfsInode * inode = new ubixfsInode; + assert(inode); + memset(inode, 0, sizeof(ubixfsInode)); + + strcpy(inode->name, "/"); + dev->write(dev, inode, 0, superBlock->inodeSize / 512); + // write out the "root" dir + dev->write(dev, bth, 1, superBlock->blockSize / 512); + free(bth); delete sb; return 0; } // UbixFS::vfs_format