diff --git a/src/sys/include/ubixfs/dirCache.h b/src/sys/include/ubixfs/dirCache.h index 759b607..3c0b8d2 100644 --- a/src/sys/include/ubixfs/dirCache.h +++ b/src/sys/include/ubixfs/dirCache.h @@ -11,10 +11,12 @@ struct cacheNode * fileListHead; struct cacheNode * fileListTail; void * info; - uInt16 attributes; - int dirListEntryCount; + int size; + int present; int dirty; - unsigned int dirBlock; + uInt32 startCluster; + uInt16 attributes; + uInt16 permissions; }; /* cacheNode */ struct cacheNode * ubixfs_cacheFind(struct cacheNode *, char *); diff --git a/src/sys/ubixfs/dirCache.c b/src/sys/ubixfs/dirCache.c index 60d0d5d..738361d 100644 --- a/src/sys/ubixfs/dirCache.c +++ b/src/sys/ubixfs/dirCache.c @@ -33,6 +33,16 @@ #include #include +static +struct directoryEntry * +ubixfs_findName(struct directoryEntry * dirList, char * name) { + int i; + if (dirList == NULL || name == NULL) return NULL; + for (i = 0; dirList[i].fileName != NULL; i++) { + if (strcmp(dirList[i].fileName, name) == 0) return &dirList[i]; + } /* for */ + return NULL; +} /* ubixfs_findName */ struct cacheNode * ubixfs_cacheFind(struct cacheNode * head, char * name) { @@ -41,7 +51,10 @@ unsigned int i = 0x0; char dirName[256]; char * nextDir = NULL; - +kprintf("looking for %s\n", name); +assert(name); +assert(head); +assert(*name); if (name == NULL || head == NULL) return NULL; if (*name == '\0') return NULL; @@ -72,25 +85,24 @@ if (*nextDir != '\0') { while (tmp != NULL) { - if (strcmp(tmp->name, dirName) == 0) - return ubixfs_cacheFind(tmp->fileListHead, nextDir); + if (strcmp(tmp->name, dirName) == 0) { + if (tmp->fileListHead == NULL) { + /* if we're here, then there are no subdirs cached to look through */ + dirList = ubixfs_findName((struct directoryEntry *)head->info,nextDir); + if (dirList == NULL) return NULL; +kprintf("creating new node %s", dirList->fileName); + tmp = ubixfs_cacheAdd(tmp, ubixfs_cacheNew(dirList->fileName)); + tmp->attributes = dirList->attributes; + tmp->permissions = dirList->permissions; + tmp->size = dirList->size; +kprintf(" size: %d\n", tmp->size); + tmp->startCluster = dirList->startCluster; + tmp->present = 0; + return tmp; + } else return ubixfs_cacheFind(tmp->fileListHead, nextDir); + } /* if */ tmp = tmp->next; } /* while */ - /* if we're here, then one level of the dir isn't cached */ - - tmp = tmp->parent; - assert(tmp->info); - dirList = (struct directoryEntry *)tmp->info; - - for (i = 0; i < tmp->dirListEntryCount; i++) { - if (strcmp(dirList[i].fileName, nextDir) == 0) { -kprintf("creating new node %s\n", dirList[i].fileName); - tmp = ubixfs_cacheAdd(tmp, ubixfs_cacheNew(dirList[i].fileName)); - tmp->attributes = dirList[i].attributes; - return tmp; - } /* if */ - } /* for */ - return NULL; } /* if */ @@ -124,8 +136,24 @@ } /* if */ tmp = tmp->next; } /* while */ + /* if we're here, then one level of the dir isn't cached */ + tmp = head->parent; + assert(tmp->info); + dirList = ubixfs_findName((struct directoryEntry *)tmp->info, name); + if (dirList == NULL) return NULL; +kprintf("creating new node %s", dirList->fileName); + tmp = ubixfs_cacheAdd(tmp, ubixfs_cacheNew(dirList->fileName)); + tmp->attributes = dirList->attributes; + tmp->permissions = dirList->permissions; + tmp->size = dirList->size; +kprintf(" size: %d\n", tmp->size); + tmp->startCluster = dirList->startCluster; + tmp->present = 0; + return tmp; +#if 0 return NULL; /* couldn't find it */ +#endif } /* ubixfs_cacheFind */ struct cacheNode * @@ -135,8 +163,8 @@ tmp->parent = tmp; tmp->prev = tmp->next = tmp->fileListHead = tmp->fileListTail = NULL; tmp->info = NULL; - tmp->dirListEntryCount = tmp->dirty = tmp->dirBlock = 0; - tmp->attributes = 0; + tmp->size = tmp->present = tmp->dirty = tmp->startCluster = 0; + tmp->attributes = tmp->permissions = 0; tmp->name = (char *)kmalloc(strlen(name)); strcpy(tmp->name, name); return tmp; @@ -202,6 +230,9 @@ /*** $Log$ + Revision 1.15 2004/07/21 22:43:18 flameshadow + one more try + Revision 1.14 2004/07/21 22:42:25 flameshadow try it now @@ -227,6 +258,9 @@ Revision 1.5 2004/07/20 19:21:30 reddawg You like leaving out $Log$ + You like leaving out Revision 1.15 2004/07/21 22:43:18 flameshadow + You like leaving out one more try + You like leaving out You like leaving out Revision 1.14 2004/07/21 22:42:25 flameshadow You like leaving out try it now You like leaving out diff --git a/src/sys/ubixfs/ubixfs.c b/src/sys/ubixfs/ubixfs.c index 7cb464e..46c6723 100644 --- a/src/sys/ubixfs/ubixfs.c +++ b/src/sys/ubixfs/ubixfs.c @@ -111,6 +111,10 @@ /* mji */ fsInfo->dirCache = ubixfs_cacheNew("/"); assert(fsInfo->dirCache); + fsInfo->dirCache->present = 1; + fsInfo->dirCache->size = 0x4000; + fsInfo->dirCache->startCluster = fsInfo->rootDir; + /* mji */ fsInfo->dirCache->info = (struct directoryEntry *)kmalloc(0x4000); /* allocate root dir */ kprintf("\ncaching root dir [%i]\n",fsInfo->rootDir); @@ -138,23 +142,52 @@ openFileUbixFS(char *file, fileDescriptor *fd) { int x = 0; /* mji struct directoryEntry *dirEntry = (struct directoryEntry *)kmalloc(0x4000); */ - struct cacheNode * rootDirCacheNode = NULL; + struct cacheNode * cacheNode = NULL; struct directoryEntry * dirEntry = NULL; struct ubixFSInfo *fsInfo = fd->mp->fsInfo; kprintf("openFileUbixFS(%s), cwd: %s\n", file, _current->oInfo.cwd); +if (fsInfo->dirCache == NULL) kprintf("dirCache is null!\n"); assert(fd); assert(fd->mp); assert(fd->mp->device); assert(fd->mp->device->devInfo); assert(fd->mp->device->devInfo->read); + assert(fsInfo); + assert(fsInfo->dirCache); + cacheNode = ubixfs_cacheFind(fsInfo->dirCache, file); +assert(cacheNode); + if (cacheNode == NULL) return 0; - + dirEntry = (struct directoryEntry *)cacheNode->info; + + if ((fd->mode & fileRead) == fileRead) { + fd->start = cacheNode->startCluster; + fd->size = cacheNode->size; + fd->perms = cacheNode->permissions; + fd->dirBlock = 0x0; /* Directory Start Sector */ + return 1; + } + else + if ((fd->mode & fileWrite) == fileWrite) { +kprintf("Ouch! in filewrite!\n"); +#if 0 + fd->start = dirEntry->startCluster; + fd->size = dirEntry->size; + fd->perms = dirEntry->permissions; + fd->dirBlock = 0x0; /* Directory Start Sector */ +#endif + return(0x1); + } + + return 0; +/* mji --- */ +#if 0 if (file[0] == '/' && file[1] != '\0') file++; /*mji rootDirCacheNode = ubixfs_dirCacheFind(fsInfo->dirCache, "/"); */ - rootDirCacheNode = fsInfo->dirCache; - assert(rootDirCacheNode); + cacheNode = fsInfo->dirCache; + assert(cacheNode); dirEntry = (struct directoryEntry *)rootDirCacheNode->info; assert(dirEntry); /* mji @@ -169,7 +202,6 @@ fd->size = dirEntry[x].size; fd->perms = dirEntry[x].permissions; fd->dirBlock = 0x0; /* Directory Start Sector */ - /* mji kfree(dirEntry); */ return((int)1); } } @@ -181,7 +213,6 @@ fd->size = dirEntry[x].size; fd->perms = dirEntry[x].permissions; fd->dirBlock = 0x0; /* Directory Start Sector */ - /* mji kfree(dirEntry); */ return(0x1); } if (dirEntry[x].attributes == 0x0) { @@ -194,13 +225,12 @@ fd->start = dirEntry[x].startCluster; fd->dirBlock = 0x0; fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,dirEntry,(fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[fsInfo->rootDir].realSector),8); -/* mji kfree(dirEntry); */ return(0x1); } } } -/* mji kfree(dirEntry); */ return(0); +#endif } int @@ -429,6 +459,9 @@ /*** $Log$ + Revision 1.28 2004/07/21 22:07:18 flameshadow + chg: renamed caching functions (again) + Revision 1.27 2004/07/21 21:08:05 flameshadow add: added provisions for file caching