diff --git a/src/sys/ubixfsv2/fsAbstract.h b/src/sys/ubixfsv2/fsAbstract.h index 66a296b..f553489 100644 --- a/src/sys/ubixfsv2/fsAbstract.h +++ b/src/sys/ubixfsv2/fsAbstract.h @@ -14,7 +14,7 @@ device_t * device; public: /* File I/O */ - virtual int vfs_open(fileDescriptor *,int flags,...) { return -1; }; + virtual int vfs_open(const char *, fileDescriptor *,int,...) { return -1; }; virtual int vfs_close(fileDescriptor *) { return -1; }; virtual size_t vfs_read(fileDescriptor *, void *, off_t, size_t) { return 0; }; diff --git a/src/sys/ubixfsv2/ubixfs.cpp b/src/sys/ubixfsv2/ubixfs.cpp index 2db23e3..a98fea4 100644 --- a/src/sys/ubixfsv2/ubixfs.cpp +++ b/src/sys/ubixfsv2/ubixfs.cpp @@ -49,6 +49,7 @@ int UbixFS::vfs_init(void) { assert(device); + size_t result; cout << "vfs_init()" << endl; assert(device); @@ -106,7 +107,9 @@ assert(rootInode); rootInode->data.btPtr = new bTree(); cout << "reading in root dir header" << endl; - vfs_read(root, rootInode->data.btPtr->header, 0, sizeof(bTreeHeader)); + result = vfs_read(root, rootInode->data.btPtr->header, 0, sizeof(bTreeHeader)); + assert(result == sizeof(bTreeHeader)); + /* device->read(device, rootInode->data.btPtr->header, @@ -161,7 +164,7 @@ cout << "i == " << i << endl; startingBlock = (inode->blocks.direct[i].AG << superBlock->AGShift) + - inode->blocks.direct[i].start + ((offset - sum) / bSize); + inode->blocks.direct[i].start + ((offset - sum) / bSize); cout << "inode->blocks.direct[" << i << "]." << inode->blocks.direct[i].len; cout << endl; @@ -185,10 +188,7 @@ cout << "device->read(device, data, " << startingBlock << ", "; cout << sectorCount << ");" << endl; - device->read(device, - data, - startingBlock, - sectorCount); + device->read(device, data, startingBlock, sectorCount); (uInt8 *)data += runSize; totalSize += runSize; @@ -424,7 +424,14 @@ if (inode == NULL) return NULL; memset(inode, 0, sizeof(ubixfsInode)); - // inode->magic1 = ; + inode->magic1 = UBIXFS_INODE_MAGIC; + + /* + * in retrospect.. I'm not sure why parent would be null.. only the + * root directory would have a null parent, but that's manually allocated + * in vfs_format() + */ + if (parent == NULL) { inode->inodeNum = getFreeBlock(); inode->parent.iAddr.AG = 0; @@ -496,12 +503,13 @@ // fill the drive in with zeroed out sectors cout << "dev->sectors: " << dev->sectors << endl; - cout << "clearing device" << endl; + cout << "clearing device..."; for (unsigned int i = 0; i < dev->sectors; i++) { dev->write(dev, §or, i, 1); } // for i - cout << "device clear" << endl; + + cout << "done" << endl; // allocate a new superBlock and clear it @@ -559,37 +567,35 @@ sb->rootDir.len = 1; // write out the superBlock -cout << "writing superBlock" << endl; - dev->write(dev, sb, dev->sectors-1, 1); -cout << "batSector: " << batSect << endl; -cout << "batSize: " << batSize << endl; + dev->write(dev, sb, dev->sectors-1, 1); // mark the first two 4k blocks used memset(§or, 0, sizeof(sector)); sector[0] = (1 << 7) | (1 << 6); -cout << endl; + // write out the first sector of the BAT -cout << "Writing BAT - 1 - " << endl; + dev->write(dev, §or, batSect, 1); // clear the rest sector[0] = 0; - memset(§or, 0, sizeof(sector)); + // write out the rest of the BAT -cout << "Writing BAT - 2 - " << endl; + for (unsigned int i = 1; i < batSize; i++) { dev->write(dev, §or, (batSect)+i, 1); } // for i -cout << "Finished writing BAT" << endl; + /* allocate part of the root dir */ // sanity checks assert(sb->blockSize); assert((unsigned)sb->blockSize >= sizeof(bTreeHeader)); -cout << "allocating bTree header" << endl; + bTreeHeader * bth = new bTreeHeader; assert(bth); memset(bth, 0, sizeof(bTreeHeader)); + bth->firstDeleted = -1; bth->firstNodeOffset = -1; bth->treeDepth = 1; @@ -597,27 +603,31 @@ bth->treeLeafCount = 0; /* create the root dir inode here */ -cout << "creating root inode" << endl; + ubixfsInode * inode = new ubixfsInode; assert(inode); - if (inode == NULL) return NULL; + if (inode == NULL) return -1; memset(inode, 0, sizeof(ubixfsInode)); inode->magic1 = UBIXFS_INODE_MAGIC; + + // inodes point to themselves inode->inodeNum.AG = 0; inode->inodeNum.start = 0; inode->inodeNum.len = 1; + // root dir has no parent directory inode->parent.iAddr.AG = 0; inode->parent.iAddr.start = 0; inode->parent.iAddr.len = 0; + /* this is part of the root dir structure (the bTreeHeader) */ inode->blocks.direct[0].AG = 0; inode->blocks.direct[0].start = 1; inode->blocks.direct[0].len = 1; - inode->blocks.maxDirectRange = 4096; - inode->blocks.size = 4096; + inode->blocks.maxDirectRange = sizeof(bTreeHeader); + inode->blocks.size = sizeof(bTreeHeader); strcpy(inode->name, "/"); inode->uid = getuid(); @@ -655,8 +665,9 @@ inode->blocks.direct[0].start) * (sb->blockSize / 512), sb->blockSize / 512 ); // dev->write + delete inode; - free(bth); + delete bth; delete sb; cout << "format complete" << endl; return 0;