X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=KernelLand%2FKernel%2Fvfs%2Fnodecache.c;h=b2cc57faddb6ae55389d1cffbb92590796c674f1;hb=097d17ad093701091b0925aa7b13378cb9aed9df;hp=d2796c1b9d3420d5edb737d739bcee72867a0f63;hpb=51ab5f489bc356940c95cc936fd0508e8f07ea97;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/vfs/nodecache.c b/KernelLand/Kernel/vfs/nodecache.c index d2796c1b..b2cc57fa 100644 --- a/KernelLand/Kernel/vfs/nodecache.c +++ b/KernelLand/Kernel/vfs/nodecache.c @@ -1,7 +1,11 @@ /* - * AcessMicro VFS - * - File IO Passthru's + * Acess2 Kernel + * - By John Hodge (thePowersGang) + * + * vfs/nodecache.c + * - VFS Node Caching facility */ +#define DEBUG 0 #include #include "vfs.h" #include "vfs_int.h" @@ -45,7 +49,7 @@ int Inode_GetHandle() gVFS_InodeCache = ent; SHORTREL( &glVFS_InodeCache ); - return gVFS_NextInodeHandle-1; + return ent->Handle; } /** @@ -81,7 +85,7 @@ tVFS_Node *Inode_GetCache(int Handle, Uint64 Inode) tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node) { tInodeCache *cache; - tCachedInode *newEnt, *ent, *prev; + tCachedInode *newEnt, *ent, *prev = NULL; cache = Inode_int_GetFSCache(Handle); if(!cache) return NULL; @@ -91,7 +95,6 @@ tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node) // Search Cache ent = cache->FirstNode; - prev = (tCachedInode*) &cache->FirstNode; for( ; ent; prev = ent, ent = ent->Next ) { if(ent->Node.Inode < Node->Inode) continue; @@ -106,8 +109,14 @@ tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node) newEnt = malloc(sizeof(tCachedInode)); newEnt->Next = ent; memcpy(&newEnt->Node, Node, sizeof(tVFS_Node)); - prev->Next = newEnt; - + if( prev ) + prev->Next = newEnt; + else + cache->FirstNode = newEnt; + newEnt->Node.ReferenceCount = 1; + + LOG("Cached %llx as %p", Node->Inode, &newEnt->Node); + return &newEnt->Node; } @@ -115,42 +124,72 @@ tVFS_Node *Inode_CacheNode(int Handle, tVFS_Node *Node) * \fn void Inode_UncacheNode(int Handle, Uint64 Inode) * \brief Dereferences/Removes a cached node */ -void Inode_UncacheNode(int Handle, Uint64 Inode) +int Inode_UncacheNode(int Handle, Uint64 Inode) { tInodeCache *cache; tCachedInode *ent, *prev; cache = Inode_int_GetFSCache(Handle); - if(!cache) return ; - - if(Inode > cache->MaxCached) return ; + if(!cache) { + Log_Notice("Inode", "Invalid cache handle %i used", Handle); + return -1; + } + + ENTER("iHandle XInode", Handle, Inode); + + if(Inode > cache->MaxCached) { + LEAVE('i', -1); + return -1; + } // Search Cache ent = cache->FirstNode; - prev = (tCachedInode*) &cache->FirstNode; // Special case removal + prev = NULL; for( ; ent; prev = ent, ent = ent->Next ) { if(ent->Node.Inode < Inode) continue; - if(ent->Node.Inode > Inode) return; - ent->Node.ReferenceCount --; - // Check if node needs to be freed - if(ent->Node.ReferenceCount == 0) - { + if(ent->Node.Inode > Inode) { + LEAVE('i', -1); + return -1; + } + break; + } + + LOG("ent = %p", ent); + + if( !ent ) { + LEAVE('i', -1); + return -1; + } + + ent->Node.ReferenceCount --; + // Check if node needs to be freed + if(ent->Node.ReferenceCount == 0) + { + if( prev ) prev->Next = ent->Next; - if(ent->Node.Inode == cache->MaxCached) - { - if(ent != cache->FirstNode) - cache->MaxCached = prev->Node.Inode; - else - cache->MaxCached = 0; - } - - free(ent); + else + cache->FirstNode = ent->Next; + if(ent->Node.Inode == cache->MaxCached) + { + if(ent != cache->FirstNode && prev) + cache->MaxCached = prev->Node.Inode; + else + cache->MaxCached = 0; } - return ; + + if(ent->Node.Data) + free(ent->Node.Data); + free(ent); + LOG("Freed"); + LEAVE('i', 1); + return 1; + } + else + { + LEAVE('i', 0); + return 0; } - - return ; } /**