* \brief Dereferences (and removes if needed) a node from the cache
* \param Handle A handle returned by Inode_GetHandle()
* \param Inode Value of the Inode field of the ::tVFS_Node you want to remove
+ * \return -1: Error (not present), 0: Not freed, 1: Freed
*/
-extern void Inode_UncacheNode(int Handle, Uint64 Inode);
+extern int Inode_UncacheNode(int Handle, Uint64 Inode);
/**
* \fn void Inode_ClearCache(int Handle)
* \brief Clears the cache for a handle
/*
- * AcessMicro VFS
- * - File IO Passthru's
+ * Acess2 Kernel
+ * - By John Hodge (thePowersGang)
+ *
+ * vfs/nodecache.c
+ * - VFS Node Caching facility
*/
+#define DEBUG 0
#include <acess.h>
#include "vfs.h"
#include "vfs_int.h"
gVFS_InodeCache = ent;
SHORTREL( &glVFS_InodeCache );
- return gVFS_NextInodeHandle-1;
+ return ent->Handle;
}
/**
newEnt->Next = ent;
memcpy(&newEnt->Node, Node, sizeof(tVFS_Node));
prev->Next = newEnt;
-
+ newEnt->Node.ReferenceCount = 1;
+
+ LOG("Cached %llx as %p", Node->Inode, &newEnt->Node);
+
return &newEnt->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;
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)
+ {
+ prev->Next = ent->Next;
+ if(ent->Node.Inode == cache->MaxCached)
{
- 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);
+ if(ent != cache->FirstNode)
+ 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 ;
}
/**