diff --git a/src/sys/ubixfsv2/device.h b/src/sys/ubixfsv2/device.h index 6d81bc1..a6dc063 100644 --- a/src/sys/ubixfsv2/device.h +++ b/src/sys/ubixfsv2/device.h @@ -31,6 +31,7 @@ #define _DEVICE_H // #include +#include #include "types.h" struct device_node { @@ -50,8 +51,8 @@ int major; void *info; uInt32 sectors; - int (*read)(device_t *,void *,uInt32,uInt32); - int (*write)(device_t *,void *,uInt32,uInt32); + int (*read)(device_t *, void *, off_t, size_t); + int (*write)(device_t *, void *, off_t, size_t); int (*reset)(void *); int (*init)(device_t *); void (*ioctl)(void *); @@ -64,6 +65,12 @@ /*** $Log$ + Revision 1.3 2004/09/13 15:21:26 flameshadow + add: ramdrive.h + chg: renamed device_t.size to sectors + chg: made #define for size of ramdisk + chg: calculated sectors of ramdisk and stored in the device_t struct + Revision 1.2 2004/09/11 22:05:59 flameshadow chg: modified UbixFS::vfs_format() to properly init the device chg: modified UbixFS::vfs_init() to verify that it's a ubixfs partition diff --git a/src/sys/ubixfsv2/fsAbstract.h b/src/sys/ubixfsv2/fsAbstract.h index 16354cb..66a296b 100644 --- a/src/sys/ubixfsv2/fsAbstract.h +++ b/src/sys/ubixfsv2/fsAbstract.h @@ -5,6 +5,7 @@ #include #include #include +#include "file.h" class vfs_abstract { protected: @@ -13,10 +14,12 @@ device_t * device; public: /* File I/O */ - virtual int vfs_open(FILE *,int flags,...) { return -1; }; - virtual int vfs_close(FILE *) { return -1; }; - virtual size_t vfs_read(FILE *,void *,size_t,size_t) { return 0; }; - virtual size_t vfs_write(FILE *,void *,size_t,size_t) { return 0; }; + virtual int vfs_open(fileDescriptor *,int flags,...) { return -1; }; + virtual int vfs_close(fileDescriptor *) { return -1; }; + virtual size_t vfs_read(fileDescriptor *, void *, off_t, size_t) + { return 0; }; + virtual size_t vfs_write(fileDescriptor *, void *, off_t, size_t) + { return 0; }; /* Dir I/O */ virtual int vfs_opendir(DIR *,const char *) { return -1; }; diff --git a/src/sys/ubixfsv2/ramdrive.cpp b/src/sys/ubixfsv2/ramdrive.cpp index d5fc192..a8e508f 100644 --- a/src/sys/ubixfsv2/ramdrive.cpp +++ b/src/sys/ubixfsv2/ramdrive.cpp @@ -40,7 +40,7 @@ static int -ramDrive_read(device_t *dev,void *ptr,uInt32 offset,uInt32 length) { +ramDrive_read(device_t *dev,void *ptr,off_t offset,size_t length) { char *data = ram_data + (offset*512); assert(ram_data); assert(offset+length <= dev->sectors); @@ -51,7 +51,7 @@ static int -ramDrive_write(device_t *dev,void *ptr,uInt32 offset,uInt32 length) { +ramDrive_write(device_t *dev,void *ptr,off_t offset,size_t length) { char *data = ram_data + (offset*512); assert(ram_data); @@ -109,6 +109,10 @@ /*** $Log$ + Revision 1.4 2004/09/13 20:10:11 flameshadow + chg: UbixFS::vfs_format() works + chg: UbixFS::vfs_init() works + Revision 1.3 2004/09/13 15:48:29 flameshadow chg: oops, the ramDrive is 100MB, not 512MB diff --git a/src/sys/ubixfsv2/ubixfs.cpp b/src/sys/ubixfsv2/ubixfs.cpp index 7ef1e91..2db23e3 100644 --- a/src/sys/ubixfsv2/ubixfs.cpp +++ b/src/sys/ubixfsv2/ubixfs.cpp @@ -17,6 +17,7 @@ root = NULL; } // UbixFS::UbixFS + UbixFS::UbixFS(device_t * dev) { device = dev; freeBlockList = NULL; @@ -26,22 +27,22 @@ void UbixFS::printSuperBlock(void) { - printf("superBlock->name............%s\n", superBlock->name); - printf("superBlock->magic1..........%X\n", superBlock->magic1); - printf("superBlock->fsByteOrder.....%d\n", superBlock->fsByteOrder); - printf("superBlock->blockSize.......%d\n", superBlock->blockSize); - printf("superBlock->blockShift......%d\n", superBlock->blockShift); - printf("superBlock->numBlocks.......%lld\n", superBlock->numBlocks); - printf("superBlock->usedBlocks......%lld\n", superBlock->usedBlocks); - printf("superBlock->batSectors......%d\n", superBlock->batSectors); - printf("superBlock->inodeCount......%d\n", superBlock->inodeCount); - printf("superBlock->magic2..........%X\n", superBlock->magic2); - printf("superBlock->blocksPerAG.....%d\n", superBlock->blocksPerAG); - printf("superBlock->AGShift.........%d\n", superBlock->AGShift); - printf("superBlock->numAGs..........%d\n", superBlock->numAGs); - printf("superBlock->lastUsedAG......%d\n", superBlock->lastUsedAG); - printf("superBlock->flags...........%X\n", superBlock->flags); - printf("superBlock->magic3..........%X\n", superBlock->magic3); + printf("superBlock->name........... %s\n", superBlock->name); + printf("superBlock->magic1......... %X\n", superBlock->magic1); + printf("superBlock->fsByteOrder.... %d\n", superBlock->fsByteOrder); + printf("superBlock->blockSize...... %d\n", superBlock->blockSize); + printf("superBlock->blockShift..... %d\n", superBlock->blockShift); + printf("superBlock->numBlocks...... %lld\n", superBlock->numBlocks); + printf("superBlock->usedBlocks..... %lld\n", superBlock->usedBlocks); + printf("superBlock->batSectors..... %d\n", superBlock->batSectors); + printf("superBlock->inodeCount..... %d\n", superBlock->inodeCount); + printf("superBlock->magic2......... %X\n", superBlock->magic2); + printf("superBlock->blocksPerAG.... %d\n", superBlock->blocksPerAG); + printf("superBlock->AGShift........ %d\n", superBlock->AGShift); + printf("superBlock->numAGs......... %d\n", superBlock->numAGs); + printf("superBlock->lastUsedAG..... %d\n", superBlock->lastUsedAG); + printf("superBlock->flags.......... %X\n", superBlock->flags); + printf("superBlock->magic3......... %X\n", superBlock->magic3); return; } // UbixFS::printSuperBlock @@ -67,7 +68,7 @@ assert(superBlock->magic3 == UBIXFS_MAGIC3); assert(strcmp(superBlock->name, "UbixFS") == 0); assert((1 << superBlock->blockShift) == superBlock->blockSize); - assert((1 << superBlock->AGShift) == superBlock->blocksPerAG); + assert((unsigned)(1 << superBlock->AGShift) == superBlock->blocksPerAG); assert(superBlock->flags == UBIXFS_CLEAN); if (freeBlockList != NULL) delete [] freeBlockList; @@ -81,46 +82,127 @@ superBlock->batSectors ); // device->read() + root = new fileDescriptor; + assert(root); + memset(root, 0, sizeof(fileDescriptor)); cout << "allocating root dir inode" << endl; - root = new ubixfsInode; - memset(root, 0, sizeof(ubixfsInode)); + root->inode = new ubixfsInode; + memset(root->inode, 0, sizeof(ubixfsInode)); cout << "root dir inode starting sector: " << ((superBlock->rootDir.AG << superBlock->AGShift) + superBlock->rootDir.start) * (superBlock->blockSize / 512) << endl; -cout << "reading in root dir" << endl; - +cout << "reading in root dir inode" << endl; + device->read(device, - root, + root->inode, ((superBlock->rootDir.AG << superBlock->AGShift) + superBlock->rootDir.start) * (superBlock->blockSize / 512), sizeof(ubixfsInode) / 512 ); cout << "done" << endl; - root->data.btPtr = new bTree(); + ubixfsInode * rootInode = static_cast(root->inode); + assert(rootInode); + rootInode->data.btPtr = new bTree(); cout << "reading in root dir header" << endl; + vfs_read(root, rootInode->data.btPtr->header, 0, sizeof(bTreeHeader)); +/* device->read(device, - root->data.btPtr->header, - ((root->blocks.direct[0].AG << superBlock->AGShift) - + root->blocks.direct[0].start) + rootInode->data.btPtr->header, + ((rootInode->blocks.direct[0].AG << superBlock->AGShift) + + rootInode->blocks.direct[0].start) * (superBlock->blockSize / 512), sizeof(bTreeHeader) / 512 ); + */ cout << "done" << endl; - root->data.btPtr->Info(); - + rootInode->data.btPtr->Info(); printSuperBlock(); return 0; } // UbixFS::init +size_t +UbixFS::vfs_read(fileDescriptor * fd, void * data, off_t offset, size_t size) { + + unsigned int i; + off_t sum, startingBlock; + size_t runSize, sectorCount, totalSize, bSize; // blockSize + ubixfsInode * inode = NULL; + + if (fd == NULL || data == NULL) return ~0; + + if (size == 0) return 0; // don't fail if size is 0? + + assert(device); + assert(superBlock); + + inode = static_cast(fd->inode); + + assert(inode); + + bSize = superBlock->blockSize; + + totalSize = sum = i = 0; + + while (size > 0) { + + /* + * place check here to see which set of blocks we're looking through + */ + + // scan through direct blocks + do { + if (offset >= sum && offset < sum + inode->blocks.direct[i].len * bSize) break; + + sum += inode->blocks.direct[i++].len * bSize; + + } while (i < NUM_DIRECT_BLOCKS); + +cout << "i == " << i << endl; + startingBlock = (inode->blocks.direct[i].AG << superBlock->AGShift) + + inode->blocks.direct[i].start + ((offset - sum) / bSize); + +cout << "inode->blocks.direct[" << i << "]." << inode->blocks.direct[i].len; +cout << endl; + runSize = inode->blocks.direct[i].len * bSize; + +cout << "runSize: " << runSize << endl; + // startingBlock is in 4k blocks + startingBlock *= (bSize / 512); + // startingBlock is now in sectors + + + if (runSize >= size) { + runSize = size; + size = 0; + } else { + size -= runSize; + } // else + + sectorCount = runSize / 512; + + cout << "device->read(device, data, " << startingBlock << ", "; + cout << sectorCount << ");" << endl; + + device->read(device, + data, + startingBlock, + sectorCount); + + (uInt8 *)data += runSize; + totalSize += runSize; + } // while + return totalSize; +} // UbixFS::vfs_read + blockRun UbixFS::getFreeBlock(blockRun ibr) { signed char * ptr; signed char * holdPtr; int32 count, holdCount; - blockRun obr = {0, 0, 0}; + blockRun obr = {0, 0, 0}; // output block run // Check to make sure none of these are null if (device == NULL || freeBlockList == NULL || superBlock == NULL) return obr; @@ -510,7 +592,9 @@ memset(bth, 0, sizeof(bTreeHeader)); bth->firstDeleted = -1; bth->firstNodeOffset = -1; - //bth-> + bth->treeDepth = 1; + bth->treeWidth = 0; + bth->treeLeafCount = 0; /* create the root dir inode here */ cout << "creating root inode" << endl; @@ -519,7 +603,7 @@ if (inode == NULL) return NULL; memset(inode, 0, sizeof(ubixfsInode)); - // inode->magic1 = ; + inode->magic1 = UBIXFS_INODE_MAGIC; inode->inodeNum.AG = 0; inode->inodeNum.start = 0; inode->inodeNum.len = 1; @@ -531,7 +615,9 @@ inode->blocks.direct[0].AG = 0; inode->blocks.direct[0].start = 1; inode->blocks.direct[0].len = 1; -// inode->blocks.maxDirectRange = 1; + + inode->blocks.maxDirectRange = 4096; + inode->blocks.size = 4096; strcpy(inode->name, "/"); inode->uid = getuid(); @@ -554,9 +640,21 @@ // write out the "root" dir inode - dev->write(dev, inode, 0, sb->inodeSize / 512); + dev->write(dev, + inode, + ((inode->inodeNum.AG << sb->AGShift) + + inode->inodeNum.start) * (sb->blockSize / 512), + sb->inodeSize / 512 + ); // dev->write + // write out the "root" dir - dev->write(dev, bth, 1, sb->blockSize / 512); + + dev->write(dev, + bth, + ((inode->blocks.direct[0].AG << sb->AGShift) + + inode->blocks.direct[0].start) * (sb->blockSize / 512), + sb->blockSize / 512 + ); // dev->write delete inode; free(bth); delete sb; @@ -567,6 +665,31 @@ int UbixFS::vfs_stop(void) { if (vfs_sync() != 0) return -1; + + // you must delete the root dir first, in case it needs to + // still write anything out + + if (root != NULL) { + ubixfsInode * rootInode = static_cast(root->inode); + delete rootInode->data.btPtr; + delete rootInode; + root->inode = NULL; + + } // if + + delete root; + delete [] freeBlockList; + delete superBlock; + + freeBlockList = NULL; + superBlock = NULL; + root = NULL; + + /* + * The device isn't null at this point, allowing for people to restart + * the mount point. Or, alternatively, to blow things up. + */ + return 0; } // UbixFS::vfs_stop diff --git a/src/sys/ubixfsv2/ubixfs.h b/src/sys/ubixfsv2/ubixfs.h index cf0409e..5d639cd 100644 --- a/src/sys/ubixfsv2/ubixfs.h +++ b/src/sys/ubixfsv2/ubixfs.h @@ -5,6 +5,7 @@ #include #include "fsAbstract.h" #include "types.h" +#include "file.h" #define INODE_IN_USE 0x00000001 #define INODE_DIRECTORY 0x00000002 @@ -22,12 +23,12 @@ #define UBIXFS_MAGIC1 0xA0A0A0A #define UBIXFS_MAGIC2 0xB0B0B0B #define UBIXFS_MAGIC3 0xC0C0C0C +#define UBIXFS_INODE_MAGIC 0x3bbe0ad9 /* befs magic numbers #define SUPER_BLOCK_MAGIC1 0x42465331 // BFS1 #define SUPER_BLOCK_MAGIC2 0xdd121031 #define SUPER_BLOCK_MAGIC3 0x15b6830e -#define INODE_MAGIC 0x3bbe0ad9 */ #define UBIXFS_CLEAN 0x434C454E // CLEN #define UBIXFS_DIRTY 0x44495254 // DIRT @@ -61,7 +62,7 @@ int32 blockSize __attribute__ ((packed)); // number of bits needed to shift a block number to get a byte address - int32 blockShift __attribute__ ((packed)); + uInt32 blockShift __attribute__ ((packed)); off_t numBlocks __attribute__ ((packed)); off_t usedBlocks __attribute__ ((packed)); @@ -70,12 +71,12 @@ uInt32 batSectors __attribute__ ((packed)); uInt32 inodeCount __attribute__ ((packed)); - int32 inodeSize __attribute__ ((packed)); - int32 magic2 __attribute__ ((packed)); - int32 blocksPerAG __attribute__ ((packed)); - int32 AGShift __attribute__ ((packed)); - int32 numAGs __attribute__ ((packed)); - int32 lastUsedAG __attribute__ ((packed)); + uInt32 inodeSize __attribute__ ((packed)); + uInt32 magic2 __attribute__ ((packed)); + uInt32 blocksPerAG __attribute__ ((packed)); + uInt32 AGShift __attribute__ ((packed)); + uInt32 numAGs __attribute__ ((packed)); + uInt32 lastUsedAG __attribute__ ((packed)); // flags tells whether the FS is clean (0x434C454E) or dirty (0x44495954) int32 flags __attribute__ ((packed)); @@ -131,7 +132,7 @@ protected: signed char * freeBlockList; diskSuperBlock * superBlock; - ubixfsInode * root; + fileDescriptor * root; blockRun getFreeBlock(blockRun); blockRun getFreeBlock(uInt32); blockRun getFreeBlock(void); @@ -146,6 +147,7 @@ virtual int vfs_init(void); virtual int vfs_format(device_t *); virtual void * vfs_mknod(const char *, mode_t); + virtual size_t vfs_read(fileDescriptor *, void *, off_t, size_t); virtual int vfs_sync(void); virtual int vfs_stop(void); virtual ~UbixFS(void);