diff --git a/src/sys/ubixfsv2/fsAbstract.h b/src/sys/ubixfsv2/fsAbstract.h index c09b8e6..5a03a79 100644 --- a/src/sys/ubixfsv2/fsAbstract.h +++ b/src/sys/ubixfsv2/fsAbstract.h @@ -13,27 +13,27 @@ device_t * device; public: /* File I/O */ - virtual int vfs_open(FILE *,int flags,...) = 0; - virtual int vfs_close(FILE *) = 0; - virtual size_t vfs_read(FILE *,void *,size_t,size_t) = 0; - virtual size_t vfs_write(FILE *,void *,size_t,size_t) = 0; + 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; }; /* Dir I/O */ - virtual int vfs_opendir(DIR *,const char *) = 0x0; - virtual int vfs_closedir(DIR *) = 0x0; - virtual int vfs_mkdir(const char *,mode_t) = 0; - virtual int vfs_readdir(DIR *,struct dirent *) = 0; + virtual int vfs_opendir(DIR *,const char *) { return -1; }; + virtual int vfs_closedir(DIR *) { return -1; }; + virtual int vfs_mkdir(const char *,mode_t) { return -1; }; + virtual int vfs_readdir(DIR *,struct dirent *) { return -1; }; /* FS Functions */ - virtual int vfs_init(void) = 0; - virtual int vfs_format(dev_t *) = 0; - virtual int vfs_stop(void) = 0; - virtual int vfs_sync(void) = 0; - virtual void * vfs_mknod(const char *, mode_t) = 0; + virtual int vfs_init(void) { return -1; }; + virtual int vfs_format(dev_t *) { return -1; }; + virtual int vfs_stop(void) { return -1; }; + virtual int vfs_sync(void) { return -1; }; + virtual void * vfs_mknod(const char *, mode_t) { return NULL; }; /* Misc Functions */ - virtual int vfs_unlink(const char *) = 0; - virtual int vfs_rename(const char *,const char *) = 0; + virtual int vfs_unlink(const char *) { return -1; }; + virtual int vfs_rename(const char *,const char *) { return -1; }; virtual ~vfs_abstract(void) { }; }; // vfs_FS diff --git a/src/sys/ubixfsv2/main.cpp b/src/sys/ubixfsv2/main.cpp index 5e070a4..34d2436 100644 --- a/src/sys/ubixfsv2/main.cpp +++ b/src/sys/ubixfsv2/main.cpp @@ -10,8 +10,13 @@ int main(void) { + device_t * ramDrive = dev_ramDrive(); + UbixFS * fs = new UbixFS(ramDrive); +// fs->vfs_format(ramDrive); + fs->vfs_init(); dev_ramDestroy(); + #if 0 int i = 0; ubixfsInode * inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); @@ -44,14 +49,14 @@ tmpInode = tmpInode->next.iPtr; } // while -cout << sizeof(struct bNode) << endl; -cout << sizeof(struct ubixfsInode) << endl; -cout << sizeof(struct diskSuperBlock) << endl; // tree->Info(); tree->Save("tree.dat"); free(inode); delete tree; #endif + cout << "sizeof(bNode): " << sizeof(struct bNode) << endl; + cout << "sizeof(ubixfsInode): " << sizeof(struct ubixfsInode) << endl; + cout << "sizeof(diskSuperBlock): " << sizeof(struct diskSuperBlock) << endl; return 0; } diff --git a/src/sys/ubixfsv2/ramdrive.cpp b/src/sys/ubixfsv2/ramdrive.cpp index d81fe60..d5fc192 100644 --- a/src/sys/ubixfsv2/ramdrive.cpp +++ b/src/sys/ubixfsv2/ramdrive.cpp @@ -30,8 +30,8 @@ #include #include #include - -#include +#include +#include "device.h" static char *ram_data = 0x0; @@ -40,20 +40,24 @@ static int -ramDrive_read(device_t *dev,void *ptr,uInt32 length,uInt32 offset) { - char *data = ram_data + offset; - - memcpy(ptr,data,length * 512); +ramDrive_read(device_t *dev,void *ptr,uInt32 offset,uInt32 length) { + char *data = ram_data + (offset*512); + assert(ram_data); + assert(offset+length <= dev->sectors); + memcpy(ptr, data, length * 512); return(length); } static int -ramDrive_write(device_t *dev,void *ptr,uInt32 length,uInt32 offset) { - char *data = ram_data + offset; +ramDrive_write(device_t *dev,void *ptr,uInt32 offset,uInt32 length) { + char *data = ram_data + (offset*512); + assert(ram_data); + + assert(offset+length <= dev->sectors); - memcpy(data,ptr,length * 512); + memcpy(data, ptr, length * 512); return(length); } @@ -105,6 +109,9 @@ /*** $Log$ + Revision 1.3 2004/09/13 15:48:29 flameshadow + chg: oops, the ramDrive is 100MB, not 512MB + Revision 1.2 2004/09/13 15:21:26 flameshadow add: ramdrive.h chg: renamed device_t.size to sectors diff --git a/src/sys/ubixfsv2/ubixfs.cpp b/src/sys/ubixfsv2/ubixfs.cpp index 77e70d9..fac1ba6 100644 --- a/src/sys/ubixfsv2/ubixfs.cpp +++ b/src/sys/ubixfsv2/ubixfs.cpp @@ -3,18 +3,52 @@ #include #include #include +#include #include "ubixfs.h" #include "btree.h" +using namespace std; + +UbixFS::UbixFS(void) { + device = NULL; + freeBlockList = NULL; + superBlock = NULL; +} // UbixFS::UbixFS + UbixFS::UbixFS(device_t * dev) { device = dev; freeBlockList = NULL; + superBlock = NULL; } // UbixFS::UbixFS +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.......%d\n", superBlock->numBlocks); + printf("superBlock->usedBlocks......%d\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 + int UbixFS::vfs_init(void) { assert(device); + cout << "vfs_init()" << endl; + assert(device); + if (device == NULL) return -1; if (superBlock != NULL) delete superBlock; superBlock = new diskSuperBlock; @@ -22,7 +56,9 @@ if (superBlock == NULL) return -1; // read in the superBlock. It's always the last block on the partition +cout << "reading in superBlock" << endl; device->read(device, superBlock, device->sectors-1, 1); +cout << "done" << endl; assert(superBlock->magic1 == UBIXFS_MAGIC1); assert(superBlock->magic2 == UBIXFS_MAGIC2); @@ -33,14 +69,16 @@ assert(superBlock->flags == UBIXFS_CLEAN); if (freeBlockList != NULL) delete [] freeBlockList; - freeBlockList = new signed char[superBlock->BAT.len*4096]; + freeBlockList = new signed char[superBlock->batSectors*512]; assert(freeBlockList); +cout << "reading in freeBlockList" << endl; device->read(device, freeBlockList, - ((superBlock->BAT.allocationGroup << superBlock->AGShift) - + superBlock->BAT.start) * 8, - superBlock->BAT.len * 8 + device->sectors-superBlock->batSectors-1, + superBlock->batSectors ); // device->read() + + printSuperBlock(); return 0; } // UbixFS::init @@ -237,6 +275,7 @@ int UbixFS::vfs_format(device_t * dev) { + cout << "vfs_format()" << endl; char sector[512]; uInt32 blocks, batSect, batSize; if (dev == NULL) return -1; @@ -245,9 +284,13 @@ memset(§or, 0, sizeof(sector)); // fill the drive in with zeroed out sectors + cout << "dev->sectors: " << dev->sectors << endl; + cout << "clearing device" << endl; + for (unsigned int i = 0; i < dev->sectors; i++) { dev->write(dev, §or, i, 1); } // for i + cout << "device clear" << endl; // allocate a new superBlock and clear it @@ -276,7 +319,7 @@ sb->blockSize = 4096; sb->blockShift = 12; sb->numBlocks = blocks; - sb->usedBlocks = 1; // root dir takes one block + sb->usedBlocks = 2; // root dir takes two blocks (inode + bTree header) sb->inodeCount = 1; sb->inodeSize = 4096; sb->magic2 = UBIXFS_MAGIC2; @@ -287,10 +330,7 @@ // 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; + sb->batSectors = batSize; sb->flags = 0x434C454E; // CLEN sb->logBlocks.allocationGroup = 0; @@ -308,30 +348,38 @@ 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; + // 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); +cout << "Writing BAT - 1 - " << endl; + dev->write(dev, §or, batSect / 8, 1); // clear the rest sector[0] = 0; // write out the rest of the BAT - dev->write(dev, §or, batSect+1, batSize-1); - +cout << "Writing BAT - 2 - " << endl; + for (unsigned int i = 1; i < batSize; i++) { + dev->write(dev, §or, (batSect / 8)+i, 1); + } // for i +cout << "Finished writing BAT" << endl; /* allocate part of the root dir */ // sanity checks - assert(superBlock->blockSize); - assert((unsigned)superBlock->blockSize >= sizeof(bTreeHeader)); - - bTreeHeader * bth = (bTreeHeader *)malloc(superBlock->blockSize); + assert(sb->blockSize); + assert((unsigned)sb->blockSize >= sizeof(bTreeHeader)); +cout << "allocating bTree header" << endl; + bTreeHeader * bth = (bTreeHeader *)malloc(sb->blockSize); assert(bth); - memset(bth, 0, superBlock->blockSize); + memset(bth, 0, sb->blockSize); bth->firstDeleted = bth->firstNodeOffset = -1; /* create the root dir inode here */ - +cout << "creating root inode" << endl; ubixfsInode * inode = new ubixfsInode; assert(inode); if (inode == NULL) return NULL; @@ -354,7 +402,7 @@ // inode->createTime // inode->lastModifiedTime // inode->type - inode->inodeSize = superBlock->inodeSize; + inode->inodeSize = sb->inodeSize; /* * next and prev are used in memory to hold pointers to the next/prev @@ -367,12 +415,13 @@ // write out the "root" dir inode - dev->write(dev, inode, 0, superBlock->inodeSize / 512); + dev->write(dev, inode, 0, sb->inodeSize / 512); // write out the "root" dir - dev->write(dev, bth, 1, superBlock->blockSize / 512); + dev->write(dev, bth, 1, sb->blockSize / 512); delete inode; free(bth); delete sb; + cout << "format complete" << endl; return 0; } // UbixFS::vfs_format diff --git a/src/sys/ubixfsv2/ubixfs.h b/src/sys/ubixfsv2/ubixfs.h index 5cb8efe..b87e0fb 100644 --- a/src/sys/ubixfsv2/ubixfs.h +++ b/src/sys/ubixfsv2/ubixfs.h @@ -47,16 +47,16 @@ int32 fsByteOrder __attribute__ ((packed)); // blockSize on disk (4096 for UbixFS v2) - int32 blockSize __attribute__ ((packed)); + int32 blockSize __attribute__ ((packed)); // number of bits needed to shift a block number to get a byte address - int32 blockShift __attribute__ ((packed)); + int32 blockShift __attribute__ ((packed)); off_t numBlocks __attribute__ ((packed)); off_t usedBlocks __attribute__ ((packed)); // BlockAllocationTable - blockRun BAT __attribute__ ((packed)); + uInt32 batSectors __attribute__ ((packed)); uInt32 inodeCount __attribute__ ((packed)); int32 inodeSize __attribute__ ((packed)); @@ -81,7 +81,7 @@ // indicies inodeAddr indicies __attribute__ ((packed)); - char pad[364] __attribute__ ((packed)); + char pad[368] __attribute__ ((packed)); } diskSuperBlock; @@ -126,7 +126,9 @@ blockRun get8FreeBlocks(uInt32); void * mknod(const char *, ubixfsInode *); uInt32 getNextAG(void); + void printSuperBlock(void); public: + UbixFS(void); UbixFS(device_t *); virtual int vfs_init(void); virtual int vfs_format(device_t *);