diff --git a/src/sys/ubixfsv2/device.h b/src/sys/ubixfsv2/device.h index c3d31e6..09bd9b3 100644 --- a/src/sys/ubixfsv2/device.h +++ b/src/sys/ubixfsv2/device.h @@ -36,39 +36,42 @@ struct device_node { struct device_node *prev; struct device_node *next; - struct device_interface *devInfo; + struct device_t *devInfo; struct device_resource *devRec; - char type; - int minor; + char type; + int minor; }; struct device_resource { uInt8 irq; }; -struct device_interface { - uInt8 initialized; - uInt32 size; +typedef struct device_t { int major; void *info; - void (*read)(void *,void *,uInt32,uInt32); - void (*write)(void *,void *,uInt32,uInt32); - void (*reset)(void *); - int (*init)(void *); + uInt32 size; + int (*read)(device_t *,void *,uInt32,uInt32); + int (*write)(device_t *,void *,uInt32,uInt32); + int (*reset)(void *); + int (*init)(device_t *); void (*ioctl)(void *); void (*stop)(void *); void (*start)(void *); void (*standby)(void *); }; - -int device_add(int,char,struct device_interface *); -struct device_node *device_find(int major,int minor); -int device_remove(struct device_node *); #endif /*** $Log$ + Revision 1.1 2004/09/11 12:43:42 flameshadow + add: device.h, types.h. Temporarily moved custom ubix typedefs to types.h + ( supercedes this file when this code is included into + the kernel) + chg: changed dev_t to device_interface so as to not conflict with bsd/linux + definitions + chg: fixed up compiler warnings in btree.cpp + Revision 1.14 2004/08/15 00:33:02 reddawg Wow the ide driver works again diff --git a/src/sys/ubixfsv2/fsAbstract.h b/src/sys/ubixfsv2/fsAbstract.h index 8b81620..c09b8e6 100644 --- a/src/sys/ubixfsv2/fsAbstract.h +++ b/src/sys/ubixfsv2/fsAbstract.h @@ -10,7 +10,7 @@ protected: vfs_abstract * prev; vfs_abstract * next; - device_interface * device; + device_t * device; public: /* File I/O */ virtual int vfs_open(FILE *,int flags,...) = 0; @@ -26,7 +26,7 @@ /* FS Functions */ virtual int vfs_init(void) = 0; - virtual int vfs_format(device_interface *) = 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; diff --git a/src/sys/ubixfsv2/ubixfs.cpp b/src/sys/ubixfsv2/ubixfs.cpp index 06cb0b3..0dbe748 100644 --- a/src/sys/ubixfsv2/ubixfs.cpp +++ b/src/sys/ubixfsv2/ubixfs.cpp @@ -1,17 +1,46 @@ #include #include #include +#include #include "ubixfs.h" #include "btree.h" -UbixFS::UbixFS(device_interface * dev) { +UbixFS::UbixFS(device_t * dev) { device = dev; freeBlockList = NULL; } // UbixFS::UbixFS int UbixFS::vfs_init(void) { +assert(device); + if (device == NULL) return -1; + if (superBlock != NULL) delete superBlock; + superBlock = new diskSuperBlock; +assert(superBlock); + if (superBlock == NULL) return -1; + + // read in the superBlock. It's always the last block on the partition + device->read(device, superBlock, device->size-1, 1); + + assert(superBlock->magic1 == UBIXFS_MAGIC1); + assert(superBlock->magic2 == UBIXFS_MAGIC2); + assert(superBlock->magic3 == UBIXFS_MAGIC3); + assert(strcmp(superBlock->name, "UbixFS") == 0); + assert((1 << superBlock->blockShift) == superBlock->blockSize); + assert((1 << superBlock->AGShift) == superBlock->blocksPerAG); + assert(superBlock->flags == UBIXFS_CLEAN); + + if (freeBlockList != NULL) delete [] freeBlockList; + freeBlockList = new signed char[superBlock->BAT.len*4096]; +assert(freeBlockList); + device->read(device, + freeBlockList, + ((superBlock->BAT.allocationGroup << superBlock->AGShift) + + superBlock->BAT.start) * 8, + superBlock->BAT.len * 8 + ); // device->read() + return 0; } // UbixFS::init @@ -195,6 +224,7 @@ inode->next.offset = 0; inode->prev.offset = 0; + ++superBlock->inodeCount; return inode; } // UbixFS::mknod @@ -204,13 +234,76 @@ } // UbixFS::mknod int -UbixFS::vfs_format(device_interface * dev) { +UbixFS::vfs_format(device_t * dev) { + char sector[512]; + uInt32 blocks, batSect, batSize; if (dev == NULL) return -1; -// ubixDiskLabel *d = new ubixDiskLabel; + + // zero out the sector + memset(§or, 0, sizeof(sector)); + + // fill the drive in with zeroed out sectors + for (unsigned int i = 0; i < dev->size; i++) { + dev->write(dev, §or, i, 1); + } // for i + + // allocate a new superBlock and clear it + diskSuperBlock *sb = new diskSuperBlock; if (sb == NULL) return -1; memset(sb, 0, sizeof(diskSuperBlock)); + // dev->size is the size of the device in 512 sectors + + blocks = (dev->size-1) / 8; // 4k blocks + batSize = (dev->size-1) % 8; // remainder + + // compute the BAT size + + while ((batSize * 4096) < blocks) { + batSize += 8; + --blocks; + } // while + + // batSize is in sectors + batSect = blocks * 8; + + strcpy(sb->name, "UbixFS"); + sb->magic1 = UBIXFS_MAGIC1; + sb->fsByteOrder = 0; + sb->blockSize = 4096; + sb->blockShift = 12; + sb->numBlocks = blocks; + sb->usedBlocks = 1; // root dir takes one block + sb->inodeCount = 1; + sb->inodeSize = 4096; + sb->magic2 = UBIXFS_MAGIC2; + sb->blocksPerAG = 2048; + sb->AGShift = 11; + sb->numAGs = (sb->numBlocks+2047) / 2048; + sb->lastUsedAG = 0; + + sb->BAT.allocationGroup = batSect / sb->blocksPerAG; + sb->BAT.start = batSect % sb->blocksPerAG; + sb->BAT.len = (batSize+7) / 8; + + sb->flags = 0x434C454E; // CLEN + sb->logBlocks.allocationGroup = 0; + sb->logBlocks.start = 0; + sb->logBlocks.len = 0; + sb->logStart = 0; + sb->logEnd = 0; + sb->magic3 = UBIXFS_MAGIC3; + sb->indicies.allocationGroup = 0; + sb->indicies.start = 0; + sb->indicies.len = 0; + + sb->rootDir.allocationGroup = 2; + sb->rootDir.start = 0; + sb->rootDir.len = 1; + + dev->write(dev, sb, dev->size-1, 1); + delete sb; return 0; } // UbixFS::vfs_format diff --git a/src/sys/ubixfsv2/ubixfs.h b/src/sys/ubixfsv2/ubixfs.h index f6e543d..5cb8efe 100644 --- a/src/sys/ubixfsv2/ubixfs.h +++ b/src/sys/ubixfsv2/ubixfs.h @@ -18,6 +18,13 @@ #define NUM_DIRECT_BLOCKS 64 #define MAX_FILENAME_LENGTH 256 +#define UBIXFS_MAGIC1 0x0A0A0A0A +#define UBIXFS_MAGIC2 0x0B0B0B0B +#define UBIXFS_MAGIC3 0x0C0C0C0C + +#define UBIXFS_CLEAN 0x434C454E // CLEN +#define UBIXFS_DIRTY 0x44495254 // DIRT + struct bNode; struct ubixfsInode; @@ -40,15 +47,17 @@ int32 fsByteOrder __attribute__ ((packed)); // blockSize on disk (4096 for UbixFS v2) - uInt32 blockSize __attribute__ ((packed)); + int32 blockSize __attribute__ ((packed)); // number of bits needed to shift a block number to get a byte address - uInt32 blockShift __attribute__ ((packed)); + int32 blockShift __attribute__ ((packed)); -// numBlocks must be divisible by 8 for the getFreeBlock function to work off_t numBlocks __attribute__ ((packed)); off_t usedBlocks __attribute__ ((packed)); +// BlockAllocationTable + blockRun BAT __attribute__ ((packed)); + uInt32 inodeCount __attribute__ ((packed)); int32 inodeSize __attribute__ ((packed)); int32 magic2 __attribute__ ((packed)); @@ -72,7 +81,7 @@ // indicies inodeAddr indicies __attribute__ ((packed)); - char pad[372] __attribute__ ((packed)); + char pad[364] __attribute__ ((packed)); } diskSuperBlock; @@ -110,7 +119,7 @@ class UbixFS : public vfs_abstract { protected: - signed char * freeBlockList; + signed char * freeBlockList; diskSuperBlock * superBlock; blockRun getFreeBlock(uInt32); blockRun getFreeBlock(void); @@ -118,9 +127,9 @@ void * mknod(const char *, ubixfsInode *); uInt32 getNextAG(void); public: - UbixFS(device_interface *); + UbixFS(device_t *); virtual int vfs_init(void); - virtual int vfs_format(device_interface *); + virtual int vfs_format(device_t *); virtual void * vfs_mknod(const char *, mode_t); virtual ~UbixFS(void); }; // UbixFS