diff --git a/src/Makefile.inc b/src/Makefile.inc index 935fc6c..8a14d34 100644 --- a/src/Makefile.inc +++ b/src/Makefile.inc @@ -2,8 +2,8 @@ # Global 'Source' Options # allow you to change your default compiler without affecting your other work -CC = gcc -CXX = g++ +CC = gcc295 +CXX = g++295 LD = ld AR = ar REMOVE = rm -rf diff --git a/src/sys/include/ubixfs/dirCache.h b/src/sys/include/ubixfs/dirCache.h new file mode 100644 index 0000000..d4ff114 --- /dev/null +++ b/src/sys/include/ubixfs/dirCache.h @@ -0,0 +1,18 @@ +#ifndef DIRCACHE_H + +#include "ubixfs.h" + +struct cacheNode { + char * name; + struct cacheNode * prev; + struct cacheNode * next; + struct cacheNode * parent; + struct cacheNode * subDirsHead; + struct cacheNode * subDirsTail; + struct directoryEntry * dirList; + int dirListEntryCount; + int dirty; + unsigned int dirBlock; +}; /* cacheNode */ + +#endif /* !DIRCACHE_H */ diff --git a/src/sys/ubixfs/Makefile b/src/sys/ubixfs/Makefile index 9315315..2cf0990 100644 --- a/src/sys/ubixfs/Makefile +++ b/src/sys/ubixfs/Makefile @@ -6,7 +6,7 @@ include ../Makefile.inc # Objects -OBJS = thread.o ubixfs.o directory.o block.o +OBJS = thread.o ubixfs.o directory.o block.o dirCache.o all: $(OBJS) diff --git a/src/sys/ubixfs/dirCache.c b/src/sys/ubixfs/dirCache.c new file mode 100644 index 0000000..88dea13 --- /dev/null +++ b/src/sys/ubixfs/dirCache.c @@ -0,0 +1,161 @@ +#include +#include +#include +#include +#include + + +struct cacheNode * +findNode(struct cacheNode * head, char * name) { + struct cacheNode * tmp = head; + unsigned int i; + char dirName[256]; + char * nextDir = NULL; + + if (name == NULL || head == NULL) return NULL; + if (*name == '\0') return NULL; + + /* + * walk down the tree recursively until we find the node we're looking + * for + */ + i = 0; +/* + memset(dirName, 0, sizeof(dirName)); + strcpy(dirName, "/"); +*/ + while (name[i] != '\0' && name[i] != '/' && i < sizeof(dirName)) { + dirName[i] = name[i]; + i++; + } /* while */ + assert(i < sizeof(dirName)); + if (i == sizeof(dirName)) return NULL; + + if (i == 0) dirName[i++] = '/'; + + dirName[i] = '\0'; + + nextDir = &name[i]; + if (*nextDir == '/') nextDir++; + + /* + * nextDir points to the next dir + * name points to a null terminated directory name + * if nextDir isn't null, then make sure that this dir is present + */ + + if (*nextDir != '\0') { + while (tmp != NULL) { + if (strcmp(tmp->name, dirName) == 0) + return findNode(tmp->subDirsHead, nextDir); + tmp = tmp->next; + } /* while */ + /* if we're here, then one level of the dir isn't cached */ + return NULL; + } /* if */ + + /* + * if nextDir was null, then we're at the bottom level. Look for the + * dir listing here + */ + while (tmp != NULL) { + assert(tmp->name); +/* don't forget to check to see if it's a directory */ + if (strcmp(tmp->name, name) == 0) { + /* + * we found the node. Move it to the front of the list + * (if it isn't already) + */ + if (tmp != tmp->parent->subDirsHead) { + assert(tmp->parent); + + /* if we're the tail, point the tail to our prev */ + if (tmp == tmp->parent->subDirsTail) { + tmp->parent->subDirsTail = tmp->prev; + } /* if */ + + if (tmp->next != NULL) tmp->next->prev = tmp->prev; + if (tmp->prev != NULL) tmp->prev->next = tmp->next; + tmp->next = tmp->parent->subDirsHead; + tmp->prev = NULL; + tmp->parent->subDirsHead = tmp; + } /* if */ + return tmp; + } /* if */ + tmp = tmp->next; + } /* while */ + + return NULL; /* couldn't find it */ +} /* findNode */ + +struct cacheNode * +newNode(const char * name) { + struct cacheNode * tmp = kmalloc(sizeof(struct cacheNode)); + assert(tmp); + tmp->parent = tmp; + tmp->prev = tmp->next = tmp->subDirsHead = tmp->subDirsTail = NULL; + tmp->dirList = NULL; + tmp->dirListEntryCount = tmp->dirty = tmp->dirBlock = 0; + tmp->name = (char *)kmalloc(strlen(name)); + kstrcpy(tmp->name, name); + return tmp; +} /* newNode */ + +void +deleteNode(struct cacheNode ** head) { + struct cacheNode * tmp = NULL; + struct cacheNode * del = NULL; + + if (head == NULL) return; + if (*head == NULL) return; + + tmp = *head; + while (tmp != NULL) { + /* if there are any child nodes, delete them first */ + + /* + * the following commented out ``if'' statement is redundant, since it + * will be caught with the above checks + */ + /* if (tmp->subDirsHead != NULL) */ + deleteNode(&tmp->subDirsHead); + + kfree(tmp->dirList); + kfree(tmp->name); + del = tmp; + tmp = tmp->next; + kfree(del); + } /* while */ + *head = NULL; + return; +} /* deleteNode */ +#if 0 +void +addNode(struct cacheNode ** node, struct cacheNode * newNode) { + if (node == NULL) return; + newNode->next = *node; + if (*node != NULL) (*node)->prev = newNode; + newNode->prev = NULL; + *node = newNode; + return; +} /* addNode */ +#endif + +void +addChildNode(struct cacheNode *node, struct cacheNode * newNode) { + struct cacheNode * tmp; + + assert(node); + newNode->parent = node; + newNode->next = node->subDirsHead; + newNode->prev = NULL; + if (node->subDirsHead == NULL) + node->subDirsTail = newNode; + else + node->subDirsHead->prev = newNode; + + node->subDirsHead = newNode; + tmp = node->subDirsHead; + return; +} /* addChildNode */ + diff --git a/src/sys/ubixfs/ubixfs.c b/src/sys/ubixfs/ubixfs.c index 737ee5a..eef13a6 100644 --- a/src/sys/ubixfs/ubixfs.c +++ b/src/sys/ubixfs/ubixfs.c @@ -39,8 +39,8 @@ #include #include #include -#include #include +#include int ubixfs_init() { @@ -83,14 +83,11 @@ int size; assert(mp); + assert(mp->diskLabel); + assert(mp->diskLabel->partitions); mp->fsInfo = (struct ubixFSInfo *)kmalloc(sizeof(struct ubixFSInfo)); - if (mp->fsInfo == NULL || mp->diskLabel == NULL || - mp->diskLabel->partitions == NULL ) { - kprintf("\nAssertion error in %s:%d\n", __FILE__, __LINE__); - } - fsInfo = mp->fsInfo; fsInfo->rootDir = 0x0; //mp->diskLabel->partitions[mp->partition].pOffset -= 63; @@ -103,11 +100,13 @@ size = (mp->diskLabel->partitions[mp->partition].pBatSize*512) / sizeof(struct blockAllocationTableEntry); fsInfo->batEntries = size; + assert(mp->device->devInfo->read); + mp->device->devInfo->read(mp->device->devInfo->info, fsInfo->blockAllocationTable, mp->diskLabel->partitions[mp->partition].pOffset, mp->diskLabel->partitions[mp->partition].pBatSize); - kprintf("Offset: [%i], Partition: [%i]\n", + kprintf(" Offset: [%i], Partition: [%i]\n", mp->diskLabel->partitions[mp->partition].pOffset,mp->partition); kprintf("UbixFS Initialized\n"); } @@ -123,7 +122,7 @@ int openFileUbixFS(char *file, fileDescriptor *fd) { int x = 0; - long offsets, size; +/*mji long offsets, size; */ struct directoryEntry *dirEntry = (struct directoryEntry *)kmalloc(0x4000); struct ubixFSInfo *fsInfo = fd->mp->fsInfo; @@ -188,6 +187,7 @@ assert(fd); assert(fd->mp); + assert(fd->mp->diskLabel); batIndexPrev = fd->start; fsInfo = fd->mp->fsInfo; @@ -257,9 +257,18 @@ ************************************************************************/ int readUbixFS(fileDescriptor *fd,char *data,long offset,long size) { - int blockCount = 0x0,batIndex = fd->start; + int blockCount = 0x0; + int batIndex; long i = 0x0; - struct ubixFSInfo *fsInfo = fd->mp->fsInfo; + struct ubixFSInfo *fsInfo = NULL; + + assert(fd); + assert(fd->mp); + assert(fd->mp->fsInfo); + + fsInfo = fd->mp->fsInfo; + batIndex = fd->start; + blockCount = ((offset)/4096); /* Find The Starting Block */ for (i=1;i<=blockCount;i++) { @@ -271,7 +280,7 @@ } /* If The File Size Is Greater Then The Offset Lets Goto Work */ fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[batIndex].realSector,blockSize); - for (i=0x0;i fd->size) { /* Set File EOF If There Is Nothing To Do */ data[i] = '\0'; @@ -302,14 +311,22 @@ ************************************************************************/ int writeUbixFS(fileDescriptor *fd,char *data,long offset,long size) { uInt32 blockOffset = 0x0; - uInt32 blockIndex = fd->start; - uInt32 blockIndexPrev = fd->start; - uInt32 i = 0x0; - struct ubixFSInfo *fsInfo = fd->mp->fsInfo; + uInt32 blockIndex; + uInt32 blockIndexPrev; + uInt32 i = 0x0; + struct ubixFSInfo *fsInfo = NULL; struct directoryEntry *dirEntry = 0x0; - blockOffset = (offset/0x1000); + assert(fd); + assert(fd->mp); + assert(fd->mp->fsInfo); + assert(fd->mp->device); + assert(fd->mp->device->devInfo); + blockIndex = blockIndexPrev = fd->start; + fsInfo = fd->mp->fsInfo; + + blockOffset = (offset/0x1000); if (fd->size != 0x0) { for (i = 0x0;i < blockOffset;i++) { @@ -365,7 +382,8 @@ return(size); } -void ubixFSUnlink(char *path,struct mountPoints *mp) { +void +ubixFSUnlink(char *path,struct mountPoints *mp) { int x=0; struct directoryEntry *dirEntry = (struct directoryEntry *)kmalloc(0x1000); struct ubixFSInfo *fsInfo = mp->fsInfo; @@ -386,6 +404,9 @@ /*** $Log$ + Revision 1.18 2004/07/17 03:21:34 flameshadow + chg: cleaned up code; added assert() statements + Revision 1.15 2004/07/14 12:21:49 reddawg ubixfs: enableUbixFs to ubixfs_init Changed Startup Routines diff --git a/src/sys/vfs/vfs.c b/src/sys/vfs/vfs.c index 2c2a801..ead99bc 100644 --- a/src/sys/vfs/vfs.c +++ b/src/sys/vfs/vfs.c @@ -84,17 +84,21 @@ } /* Set Up FS Defaults */ -/* - tmpFs->vfsType = newFS.vfsType; - tmpFs->vfsInitFS = newFS.vfsInitFS; - tmpFs->vfsRead = newFS.vfsRead; - tmpFs->vfsWrite = newFS.vfsWrite; - tmpFs->vfsOpenFile = newFS.vfsOpenFile; - tmpFs->vfsUnlink = newFS.vfsUnlink; - tmpFs->vfsMakeDir = newFS.vfsMakeDir; - tmpFs->vfsRemDir = newFS.vfsRemDir; - tmpFs->vfsSync = newFS.vfsSync; + +/* 2004 7-16-2004 mji + * Old method: + * tmpFs->vfsType = newFS.vfsType; + * tmpFs->vfsInitFS = newFS.vfsInitFS; + * tmpFs->vfsRead = newFS.vfsRead; + * tmpFs->vfsWrite = newFS.vfsWrite; + * tmpFs->vfsOpenFile = newFS.vfsOpenFile; + * tmpFs->vfsUnlink = newFS.vfsUnlink; + * tmpFs->vfsMakeDir = newFS.vfsMakeDir; + * tmpFs->vfsRemDir = newFS.vfsRemDir; + * tmpFs->vfsSync = newFS.vfsSync; */ + /* new method: */ + memcpy(tmpFs, &newFS, sizeof(struct fileSystem)); if (!systemVitals->fileSystems) { tmpFs->prev = 0x0;