diff --git a/src/sys/ubixfsv2/btree.cpp b/src/sys/ubixfsv2/btree.cpp index e0af1d4..9123e87 100644 --- a/src/sys/ubixfsv2/btree.cpp +++ b/src/sys/ubixfsv2/btree.cpp @@ -4,14 +4,14 @@ #include #include #include +#include #include "btree.h" -#include "inode.h" -#include "assert.h" +#include "ubixfs.h" using namespace std; #define VERIFY(x, y, z, n) if ((x) != (y)) { cout << "verify " << z << " failed" << endl; PrintWholeTree(); } -bTree::bTree(ubixfsInode * inode) : root(NULL) { +bTree::bTree(const char * key, ubixfsInode * inode) : root(NULL) { tag = 0; header.treeDepth = 1; header.treeWidth = 0; @@ -25,7 +25,7 @@ root->childCount[1] = 1; // cout << "---Creating " << inode->name << "@" << inode << endl; - strncpy(root->keys[0], inode->name, B_MAX_NAME_LENGTH); + strncpy(root->keys[0], key, B_MAX_NAME_LENGTH); // insert pointer to data page to the right of the data root->head[1].iPtr = inode; root->tail[1].iPtr = inode; @@ -38,7 +38,7 @@ } // bTree:bTree bool -bTree::Insert(ubixfsInode * inode) { +bTree::Insert(const char * key, ubixfsInode * inode) { bNode * bnode = root; ubixfsInode * tmpInode = NULL; unsigned int curSlot = 0; @@ -59,7 +59,7 @@ root->leaf = true; root->childCount[1] = 1; - strncpy(root->keys[0], inode->name, B_MAX_NAME_LENGTH); + strncpy(root->keys[0], key, B_MAX_NAME_LENGTH); // insert pointer to data page to the right of the data root->head[1].iPtr = inode; root->tail[1].iPtr = inode; @@ -69,10 +69,10 @@ return true; } // if - tmpInode = Find(inode->name); + tmpInode = Find(key); if (tmpInode != NULL) return false; // PrintWholeTree(); -// cout << "Insert(" << inode->name << ")" << endl; +// cout << "Insert(" << key << ")" << endl; //Info(bnode); ++header.treeLeafCount; /* @@ -81,14 +81,14 @@ assert(bnode->used); // cout << "---Inserting " << inode->name << " @ " << inode << endl; while (bnode != NULL && !bnode->leaf) { - if (strcmp(inode->name, bnode->keys[0]) < 0) { + if (strcmp(key, bnode->keys[0]) < 0) { bnode = bnode->head[0].bPtr; } else { - if (strcmp(inode->name, bnode->keys[bnode->used-1]) >= 0) { + if (strcmp(key, bnode->keys[bnode->used-1]) >= 0) { bnode = bnode->head[bnode->used].bPtr; } else { for (unsigned int i = 1; i < bnode->used; i++) { - if (strcmp(inode->name, bnode->keys[i]) < 0) { + if (strcmp(key, bnode->keys[i]) < 0) { bnode = bnode->head[i].bPtr; break; } // if @@ -105,14 +105,14 @@ if (bnode->leaf != true) cout << "leafnode!=true" << endl; assert(inode); - if (strcmp(inode->name, bnode->keys[curSlot = 0]) < 0) + if (strcmp(key, bnode->keys[curSlot = 0]) < 0) tmpInode = bnode->head[curSlot].iPtr; else - if (strcmp(inode->name, bnode->keys[(curSlot = bnode->used)-1]) >= 0) + if (strcmp(key, bnode->keys[(curSlot = bnode->used)-1]) >= 0) tmpInode = bnode->head[bnode->used].iPtr; else { for (curSlot = 1; curSlot < bnode->used; curSlot++) { - if (strcmp(inode->name, bnode->keys[curSlot]) < 0) { + if (strcmp(key, bnode->keys[curSlot]) < 0) { tmpInode = bnode->head[curSlot].iPtr; break; } // if @@ -149,7 +149,7 @@ /* * Add node to leaf page. Scan through to find where it goes. */ - if (strcmp(inode->name, bnode->head[curSlot].iPtr->name) < 0) + if (strcmp(key, bnode->head[curSlot].iPtr->name) < 0) { inode->next.iPtr = bnode->head[curSlot].iPtr; @@ -160,7 +160,7 @@ } else { - if (strcmp(inode->name, bnode->tail[curSlot].iPtr->name) > 0) { + if (strcmp(key, bnode->tail[curSlot].iPtr->name) > 0) { inode->prev.iPtr = bnode->tail[curSlot].iPtr; inode->next.iPtr = inode->prev.iPtr->next.iPtr; @@ -174,7 +174,7 @@ ubixfsInode * tmpInode = bnode->head[curSlot].iPtr; for (unsigned int i = 0; i < bnode->childCount[curSlot]; i++) { - if (strcmp(inode->name, tmpInode->name) < 0) { + if (strcmp(key, tmpInode->name) < 0) { inode->next.iPtr = tmpInode; inode->prev.iPtr = tmpInode->prev.iPtr; inode->next.iPtr->prev.iPtr = inode; @@ -403,7 +403,7 @@ bNode * bTree::allocEmptyNode(void) { - bNode * newNode = (bNode *)malloc(sizeof(bNode)); + bNode * newNode = new bNode; memset(newNode, 0, sizeof(bNode)); newNode->magic1 = B_NODE_MAGIC_1; @@ -630,10 +630,6 @@ ptr->present[i] = false; } // for i - cout << "fseeko() returned: " << fseeko(fd, myOffset, SEEK_SET) << endl; - - cout << "fwrite() returned: " << fwrite(ptr, sizeof(bNode), 1, fd) << endl; - if (node->leaf) { for (unsigned int i = 0; i <= node->used; i++) { @@ -660,7 +656,7 @@ FILE * fd = NULL; if ((fd = fopen(filename, "wb+")) == NULL) return false; -cout << "tags: " << tag; +cout << "tags: " << tag << endl; lseek(fileno(fd), tag * sizeof(bNode), SEEK_END); header.firstNodeOffset = sizeof(bNode); diff --git a/src/sys/ubixfsv2/btree.h b/src/sys/ubixfsv2/btree.h index b0d5c79..7a05100 100644 --- a/src/sys/ubixfsv2/btree.h +++ b/src/sys/ubixfsv2/btree.h @@ -3,8 +3,7 @@ #include -#include "superblock.h" -#include "inode.h" +#include "ubixfs.h" #include "btreeheader.h" #define B_NODE_MAGIC_1 0xDEADBEEF @@ -29,7 +28,7 @@ uInt32 childCount[B_MAX_KEYS+1] __attribute__ ((packed)); uInt32 magic2 __attribute__ ((packed)); bool leaf __attribute__ ((packed)); - char reserved[135] __attribute__ ((packed)); + char reserved[131] __attribute__ ((packed)); } bNode; // bNode struct ubixfsInode; @@ -48,7 +47,7 @@ void Print(bNode *); void saveNode(FILE *, bNode *, void *); public: - bTree(ubixfsInode *); + bTree(const char *, ubixfsInode *); bTree(void) : root(NULL) { }; ubixfsInode * Find(const char *); ubixfsInode * GetFirstNode(void); @@ -56,7 +55,7 @@ bool Delete(const char *); void Info(void); void Info(const bNode *); - bool Insert(ubixfsInode *); + bool Insert(const char *, ubixfsInode *); bool Save(const char *); bool Load(const char *); void Print(void); diff --git a/src/sys/ubixfsv2/fsAbstract.h b/src/sys/ubixfsv2/fsAbstract.h index becf79b..c0963e1 100644 --- a/src/sys/ubixfsv2/fsAbstract.h +++ b/src/sys/ubixfsv2/fsAbstract.h @@ -28,7 +28,7 @@ virtual int vfs_format(dev_t *) = 0; virtual int vfs_stop(void) = 0; virtual int vfs_sync(void) = 0; - virtual void * vfs_mknod(void) = 0; + virtual void * vfs_mknod(const char *, mode_t) = 0; /* Misc Functions */ virtual int vfs_unlink(const char *) = 0; diff --git a/src/sys/ubixfsv2/inode.h b/src/sys/ubixfsv2/inode.h deleted file mode 100644 index 66c7bd7..0000000 --- a/src/sys/ubixfsv2/inode.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef INODE_H -#define INODE_H - -#include "superblock.h" -#include "btree.h" - -#define INODE_IN_USE 0x00000001 -#define ATTR_INODE 0x00000004 -#define INODE_LOGGED 0x00000008 -#define INODE_DELETED 0x00000010 -#define PERMANENT_FLAGS 0x0000ffff -#define INODE_NO_CACHE 0x00010000 -#define INODE_WAS_WRITTEN 0x00020000 -#define NO_TRANSACTION 0x00040000 - -#define NUM_DIRECT_BLOCKS 64 -#define MAX_FILENAME_LENGTH 256 - -typedef struct dataStream { - struct blockRun direct[NUM_DIRECT_BLOCKS]; - off_t maxDirectRange; - struct blockRun indirect; - off_t maxIndirectRange; - struct blockRun double_indirect; - off_t maxDoubleIndirectRange; - off_t size; -} dataStream; - -struct ubixfsInode; -struct bNode; - -typedef union uPtr { - inodeAddr iAddr; - bNode * bPtr; - ubixfsInode * iPtr; - off_t offset; -}; - -typedef struct ubixfsInode { - int32 magic1 __attribute__ ((packed)); - inodeAddr inodeNum __attribute__ ((packed)); - char name[MAX_FILENAME_LENGTH] __attribute__ ((packed)); - int32 uid __attribute__ ((packed)); - int32 gid __attribute__ ((packed)); - int32 mode __attribute__ ((packed)); - int32 flags __attribute__ ((packed)); - // uInt64 createTime __attribute_ ((packed)); - // uInt64 lastModifiedTime __attribute__ (packed)); -// inodeAddr attributes __attribute__ ((packed)); - uInt32 type __attribute__ ((packed)); - int32 inodeSize __attribute__ ((packed)); - uPtr parent __attribute__ ((packed)); - uPtr next __attribute__ ((packed)); - uPtr prev __attribute__ ((packed)); -// binodeEtc *etc ?? - dataStream data __attribute__ ((packed)); - char smallData[3220] __attribute__ ((packed)); -} ubixfsInode; - -#endif diff --git a/src/sys/ubixfsv2/main.cpp b/src/sys/ubixfsv2/main.cpp index 0f69006..c76b28a 100644 --- a/src/sys/ubixfsv2/main.cpp +++ b/src/sys/ubixfsv2/main.cpp @@ -1,10 +1,9 @@ #include #include #include -#include "superblock.h" #include "vfs.h" #include "btree.h" -#include "inode.h" +#include "ubixfs.h" using namespace std; @@ -14,7 +13,7 @@ ubixfsInode * inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); memset(inode, 0, sizeof(ubixfsInode)); strcpy(inode -> name, "50"); - bTree * tree = new bTree(inode); + bTree * tree = new bTree(".", inode); for (i = 0; i < 100; i++) { // while (tree->Verify()) { @@ -27,112 +26,11 @@ inode->name[k] = (char)((random() % 26)+'a'); } // for k // tree->Insert(inode); - if (!tree->Insert(inode)) cout << "Insert(" << inode->name << ") failed" << endl; + if (!tree->Insert(inode->name, inode)) cout << "Insert(" << inode->name << ") failed" << endl; // ++i; } // for i // cout << "i made it to: " << i << endl; -#if 0 - for (a = 'a';a <= 'a';a++) { - for (aa = 'a';aa <= 'b';aa++) { - for (aaa = 'a';aaa <= 'z';aaa++) { - inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); - memset(inode,0x0,sizeof(ubixfsInode)); - inode->name[0] = a; - inode->name[1] = aa; - inode->name[2] = aaa; - if (!tree->Insert(inode)) cout << "Insert() failed" << endl; - } - } - } - for (a = 'c';a <= 'c';a++) { - for (aa = 'a';aa <= 'b';aa++) { - for (aaa = 'a';aaa <= 'z';aaa++) { - inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); - memset(inode,0x0,sizeof(ubixfsInode)); - inode->name[0] = a; - inode->name[1] = aa; - inode->name[2] = aaa; - if (!tree->Insert(inode)) cout << "Insert() failed" << endl; - } - } - } - for (a = 'b';a <= 'b';a++) { - for (aa = 'a';aa <= 'b';aa++) { - for (aaa = 'a';aaa <= 'z';aaa++) { - inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); - memset(inode,0x0,sizeof(ubixfsInode)); - inode->name[0] = a; - inode->name[1] = aa; - inode->name[2] = aaa; - if (!tree->Insert(inode)) cout << "Insert() failed" << endl; - } - } - } -#endif -#if 0 - inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); - memset(inode, 0, sizeof(ubixfsInode)); - strcpy(inode->name, "m"); - tree->Insert(inode); - - inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); - memset(inode, 0, sizeof(ubixfsInode)); - strcpy(inode->name, "a"); - tree->Insert(inode); - - inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); - memset(inode, 0, sizeof(ubixfsInode)); - strcpy(inode->name, "b"); - tree->Insert(inode); - - inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); - memset(inode, 0, sizeof(ubixfsInode)); - strcpy(inode->name, "c"); - tree->Insert(inode); - - inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); - memset(inode, 0, sizeof(ubixfsInode)); - strcpy(inode->name, "d"); - tree->Insert(inode); - - inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); - memset(inode, 0, sizeof(ubixfsInode)); - strcpy(inode->name, "e"); - tree->Insert(inode); - - inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); - memset(inode, 0, sizeof(ubixfsInode)); - strcpy(inode->name, "f"); - tree->Insert(inode); - - inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); - memset(inode, 0, sizeof(ubixfsInode)); - strcpy(inode->name, "j"); - tree->Insert(inode); - - inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); - memset(inode, 0, sizeof(ubixfsInode)); - strcpy(inode->name, "h"); - tree->Insert(inode); - - inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); - memset(inode, 0, sizeof(ubixfsInode)); - strcpy(inode->name, "eee"); - tree->Insert(inode); - - inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); - memset(inode, 0, sizeof(ubixfsInode)); - strcpy(inode->name, "ee"); - tree->Insert(inode); - - inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); - memset(inode, 0, sizeof(ubixfsInode)); - strcpy(inode->name, "n"); -cout << "---Inserting " << inode->name << "---" << endl; - tree->Insert(inode); -#endif - i = 0; ubixfsInode * tmpInode = tmpInode = tree->GetFirstNode(); if (tmpInode == NULL) cout << "GetFirstNode() returns null" << endl; diff --git a/src/sys/ubixfsv2/superblock.h b/src/sys/ubixfsv2/superblock.h deleted file mode 100644 index c778ca4..0000000 --- a/src/sys/ubixfsv2/superblock.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef SUPERBLOCK_H -#define SUPERBLOCK_H - -#include - -typedef struct blockRun { - int allocationGroup __attribute__ ((packed)); - unsigned short start __attribute__ ((packed)); - unsigned short len __attribute__ ((packed)); -} inodeAddr; - -// typedef unsigned long long off_t; -typedef signed char int8; -typedef unsigned char uInt8; -typedef unsigned int uInt32; -typedef int int32; -typedef unsigned long long uInt64; -typedef signed long long int64; - -typedef struct diskSuperBlock { - char name[32] __attribute__ ((packed)); - int32 magic1 __attribute__ ((packed)); - int32 fsByteOrder __attribute__ ((packed)); - -// blockSize on disk (4096 for UbixFS v2) - uInt32 blockSize __attribute__ ((packed)); - -// number of bits needed to shift a block number to get a byte address - uInt32 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)); - - 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)); - -// flags tells whether the FS is clean (0x434C454E) or dirty (0x44495954) - int32 flags __attribute__ ((packed)); - -// journal information - blockRun logBlocks __attribute__ ((packed)); - off_t logStart __attribute__ ((packed)); - off_t logEnd __attribute__ ((packed)); - - int32 magic3 __attribute__ ((packed)); - -// root dir of the SYS container - inodeAddr rootDir __attribute__ ((packed)); - -// indicies - inodeAddr indicies __attribute__ ((packed)); - - char pad[372] __attribute__ ((packed)); - -} diskSuperBlock; - -#endif // !SUPERBLOCK_H diff --git a/src/sys/ubixfsv2/ubixfs.cpp b/src/sys/ubixfsv2/ubixfs.cpp index e12b9bd..e44f21e 100644 --- a/src/sys/ubixfsv2/ubixfs.cpp +++ b/src/sys/ubixfsv2/ubixfs.cpp @@ -1,9 +1,9 @@ #include #include +#include + #include "ubixfs.h" #include "btree.h" -#include "inode.h" -#include "superblock.h" UbixFS::UbixFS(dev_t * dev) { device = dev; @@ -15,18 +15,22 @@ return 0; } // UbixFS::init -int32 +blockRun UbixFS::getFreeBlock(uInt32 AG) { // AG == AllocationGroup + blockRun br; signed char * ptr; int32 count; int32 subCount = 128; + br.allocationGroup = 0; + br.start = 0; + br.len = 0; // Check to make sure neither of these are null - if (device == NULL || freeBlockList == NULL || superBlock == NULL) return -1; + if (device == NULL || freeBlockList == NULL || superBlock == NULL) return br; // Are there any blocks available? - if (superBlock->numBlocks == superBlock->usedBlocks) return -1; + if (superBlock->numBlocks == superBlock->usedBlocks) return br; /* * count is the block from the base of the list. @@ -71,40 +75,51 @@ *ptr |= subCount; // mark this block as used ++superBlock->usedBlocks; // increment the number of used blocks - - return count; // return the allocated block number + + br.allocationGroup = count / superBlock->blocksPerAG; + br.start = count % superBlock->blocksPerAG; + br.len = 1; + return br; // return the allocated block number } // Ubixfs::getFreeBlock +uInt32 +UbixFS::getNextAG(void) { + + if (superBlock->lastUsedAG == superBlock->numAGs) + superBlock->lastUsedAG = 0; + else + superBlock->lastUsedAG++; + return superBlock->lastUsedAG; + +} // UbixFS::getNextAG + /* * UbixFS::getFreeBlock(void) * upon success returns a free block based on the next AG after the lastUsedAG * failure returns -1 */ -int32 +blockRun UbixFS::getFreeBlock(void) { - if (superBlock == NULL) return -1; - - if (superBlock->lastUsedAG == superBlock->numAGs) - superBlock->lastUsedAG = 0; - else - superBlock->lastUsedAG++; - - return getFreeBlock(superBlock->lastUsedAG); - + return getFreeBlock(getNextAG()); } // UbixFS::getFreeBlock -int32 +blockRun UbixFS::get8FreeBlocks(uInt32 AG) { // AG == AllocationGroup + blockRun br; signed char * ptr; signed char * endPtr; int32 count; - if (device == NULL || freeBlockList == NULL || superBlock == NULL) return -1; + br.allocationGroup = 0; + br.start = 0; + br.len = 0; + + if (device == NULL || freeBlockList == NULL || superBlock == NULL) return br; // Are there any blocks available? - if (superBlock->usedBlocks+8 > superBlock->numBlocks) return -1; + if (superBlock->usedBlocks+8 > superBlock->numBlocks) return br; /* * count is the block from the base of the list. @@ -125,7 +140,7 @@ count += 8; if (ptr == endPtr) { if (secondTime) - return -1; + return br; else secondTime = true; @@ -133,14 +148,54 @@ ptr = freeBlockList; } // if } // while - *ptr = -1; - return count; + + *ptr = -1; // mark 8 blocks as taken + + br.allocationGroup = count / superBlock->blocksPerAG; + br.start = count % superBlock->blocksPerAG; + br.len = 8; + return br; } // UbixFS::get8FreeBlocks void * -UbixFS::vfs_mknod(const char *path); - - return NULL; +UbixFS::mknod(const char *filename, ubixfsInode * parent) { + ubixfsInode * inode = NULL; + + inode = new ubixfsInode; + memset(inode, 0, sizeof(ubixfsInode)); + if (inode == NULL) return NULL; + // inode->magic1 = ; + if (parent == NULL) + inode->inodeNum = getFreeBlock(parent->inodeNum.allocationGroup); + else + inode->inodeNum = getFreeBlock(); + + strncpy(inode->name, filename, MAX_FILENAME_LENGTH); + + // inode->uid + // inode->gid + // inode->mode + // inode->flags + // inode->createTime + // inode->lastModifiedTime + // inode->type + inode->inodeSize = superBlock->inodeSize; + // inode->parent = + + /* + * next and prev are used in memory to hold pointers to the next/prev + * inodes in this dir. On disk they may have another value, but for + * now they should be set to null. + */ + + inode->next.offset = 0; + inode->prev.offset = 0; + return inode; +} // UbixFS::mknod + +void * +UbixFS::vfs_mknod(const char *path, mode_t mode) { + return mknod(path, 0); } // UbixFS::mknod int diff --git a/src/sys/ubixfsv2/ubixfs.h b/src/sys/ubixfsv2/ubixfs.h index ee649da..eb58ab1 100644 --- a/src/sys/ubixfsv2/ubixfs.h +++ b/src/sys/ubixfsv2/ubixfs.h @@ -1,21 +1,132 @@ #ifndef UBIXFS_H #define UBIXFS_H -#include "superblock.h" #include "fsAbstract.h" +#include + +typedef struct blockRun { + int allocationGroup __attribute__ ((packed)); + unsigned short start __attribute__ ((packed)); + unsigned short len __attribute__ ((packed)); +} inodeAddr; + +// typedef unsigned long long off_t; +typedef signed char int8; +typedef unsigned char uInt8; +typedef unsigned int uInt32; +typedef int int32; +typedef unsigned long long uInt64; +typedef signed long long int64; + +typedef struct diskSuperBlock { + char name[32] __attribute__ ((packed)); + int32 magic1 __attribute__ ((packed)); + int32 fsByteOrder __attribute__ ((packed)); + +// blockSize on disk (4096 for UbixFS v2) + uInt32 blockSize __attribute__ ((packed)); + +// number of bits needed to shift a block number to get a byte address + uInt32 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)); + + 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)); +// flags tells whether the FS is clean (0x434C454E) or dirty (0x44495954) + int32 flags __attribute__ ((packed)); + +// journal information + blockRun logBlocks __attribute__ ((packed)); + off_t logStart __attribute__ ((packed)); + off_t logEnd __attribute__ ((packed)); + + int32 magic3 __attribute__ ((packed)); + +// root dir of the SYS container + inodeAddr rootDir __attribute__ ((packed)); + +// indicies + inodeAddr indicies __attribute__ ((packed)); + + char pad[372] __attribute__ ((packed)); + +} diskSuperBlock; + +#define INODE_IN_USE 0x00000001 +#define ATTR_INODE 0x00000004 +#define INODE_LOGGED 0x00000008 +#define INODE_DELETED 0x00000010 +#define PERMANENT_FLAGS 0x0000ffff +#define INODE_NO_CACHE 0x00010000 +#define INODE_WAS_WRITTEN 0x00020000 +#define NO_TRANSACTION 0x00040000 + +#define NUM_DIRECT_BLOCKS 64 +#define MAX_FILENAME_LENGTH 256 + +typedef struct dataStream { + struct blockRun direct[NUM_DIRECT_BLOCKS]; + off_t maxDirectRange; + struct blockRun indirect; + off_t maxIndirectRange; + struct blockRun double_indirect; + off_t maxDoubleIndirectRange; + off_t size; +} dataStream; + +struct ubixfsInode; +struct bNode; + +typedef union uPtr { + inodeAddr iAddr; + bNode * bPtr; + ubixfsInode * iPtr; + off_t offset; +}; + +typedef struct ubixfsInode { + int32 magic1 __attribute__ ((packed)); + inodeAddr inodeNum __attribute__ ((packed)); + char name[MAX_FILENAME_LENGTH] __attribute__ ((packed)); + int32 uid __attribute__ ((packed)); + int32 gid __attribute__ ((packed)); + int32 mode __attribute__ ((packed)); + int32 flags __attribute__ ((packed)); + // uInt64 createTime __attribute_ ((packed)); + // uInt64 lastModifiedTime __attribute__ (packed)); +// inodeAddr attributes __attribute__ ((packed)); + uInt32 type __attribute__ ((packed)); + int32 inodeSize __attribute__ ((packed)); + uPtr parent __attribute__ ((packed)); + uPtr next __attribute__ ((packed)); + uPtr prev __attribute__ ((packed)); +// binodeEtc *etc ?? + dataStream data __attribute__ ((packed)); + char smallData[3220] __attribute__ ((packed)); +} ubixfsInode; class UbixFS : public vfs_abstract { protected: signed char * freeBlockList; diskSuperBlock * superBlock; - int32 getFreeBlock(uInt32); - int32 getFreeBlock(void); - int32 get8FreeBlocks(uInt32); + blockRun getFreeBlock(uInt32); + blockRun getFreeBlock(void); + blockRun get8FreeBlocks(uInt32); + void * mknod(const char *, ubixfsInode *); + uInt32 getNextAG(void); public: UbixFS(dev_t *); virtual int vfs_init(void); virtual int vfs_format(dev_t *); - virtual void * vfs_mknod(void); + virtual void * vfs_mknod(const char *, mode_t); virtual ~UbixFS(void); }; // UbixFS