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;
// Search Cache
ent = cache->FirstNode;
- prev = (tCachedInode*) &cache->FirstNode;
for( ; ent; prev = ent, ent = ent->Next )
{
if(ent->Node.Inode < Node->Inode) continue;
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);
// 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;
// Check if node needs to be freed
if(ent->Node.ReferenceCount == 0)
{
- prev->Next = ent->Next;
+ if( prev )
+ prev->Next = ent->Next;
+ else
+ cache->FirstNode = ent->Next;
if(ent->Node.Inode == cache->MaxCached)
{
- if(ent != cache->FirstNode)
+ if(ent != cache->FirstNode && prev)
cache->MaxCached = prev->Node.Inode;
else
cache->MaxCached = 0;