*TruePath = malloc( gVFS_RootMount->MountPointLen+1 );
strcpy(*TruePath, gVFS_RootMount->MountPoint);
}
+ gVFS_RootMount->OpenHandleCount ++;
if(MountPoint) *MountPoint = gVFS_RootMount;
LEAVE('p', gVFS_RootMount->RootNode);
return gVFS_RootMount->RootNode;
// Find Mountpoint
longestMount = gVFS_RootMount;
+ RWLock_AcquireRead( &glVFS_MountList );
for(mnt = gVFS_Mounts; mnt; mnt = mnt->Next)
{
// Quick Check
if(mnt->MountPointLen < longestMount->MountPointLen) continue;
// String Compare
cmp = strncmp(Path, mnt->MountPoint, mnt->MountPointLen);
+ // Not a match, continue
+ if(cmp != 0) continue;
#if OPEN_MOUNT_ROOT
// Fast Break - Request Mount Root
}
if(MountPoint)
*MountPoint = mnt;
+ RWLock_Release( &glVFS_MountList );
+ LOG("Mount %p root", mnt);
LEAVE('p', mnt->RootNode);
return mnt->RootNode;
}
#endif
- // Not a match, continue
- if(cmp != 0) continue;
longestMount = mnt;
}
+ longestMount->OpenHandleCount ++; // Increment assuimg it worked
+ RWLock_Release( &glVFS_MountList );
// Save to shorter variable
mnt = longestMount;
}
// Check if the node has a FindDir method
+ if( !curNode->Type )
+ {
+ LOG("Finddir failure on '%s' - No type", Path);
+ Log_Error("VFS", "Node at '%s' has no type (mount %s:%s)",
+ Path, mnt->Filesystem->Name, mnt->MountPoint);
+ goto _error;
+ }
if( !curNode->Type->FindDir )
{
- LOG("Finddir failure on '%s'", Path);
+ LOG("Finddir failure on '%s' - No FindDir method in %s", Path, curNode->Type->TypeName);
goto _error;
}
LOG("FindDir{=%p}(%p, '%s')", curNode->Type->FindDir, curNode, pathEle);
path_buffer[ curNode->Size ] = '\0';
LOG("path_buffer = '%s'", path_buffer);
strcat(path_buffer, Path + ofs+nextSlash);
+ // TODO: Pass to VFS_GetAbsPath to handle ../. in the symlink
Path = path_buffer;
// Log_Debug("VFS", "VFS_ParsePath: Symlink translated to '%s'", Path);
// EVIL: Goto :)
LOG("Symlink -> '%s', restart", Path);
+ mnt->OpenHandleCount --; // Not in this mountpoint
goto restart_parse;
}
LOG("tmpNode = %p", tmpNode);
// Check if file was found
if(!tmpNode) {
- LOG("Node '%s' not found in dir '%s'", &Path[ofs], Path);
+ LOG("Node '%s' not found in dir '%.*s'", &Path[ofs], ofs, Path);
goto _error;
}
_CloseNode( curNode );
*MountPoint = mnt;
}
+ // Leave the mointpoint's count increased
+
LEAVE('p', tmpNode);
return tmpNode;
free(*TruePath);
*TruePath = NULL;
}
+ // Open failed, so decrement the open handle count
+ mnt->OpenHandleCount --;
+
LEAVE('n');
return NULL;
}
if( !node && (Flags & VFS_OPENFLAG_CREATE) )
{
// TODO: Translate `Mode` into ACL and node flags
- // Get parent, create node
- if( VFS_MkNod(absPath, 0) ) {
+ Uint new_flags = 0;
+
+ // Split path at final separator
+ char *file = strrchr(absPath, '/');
+ *file = '\0';
+ file ++;
+
+ // Get parent node
+ tVFS_Mount *pmnt;
+ tVFS_Node *pnode = VFS_ParsePath(absPath, NULL, &pmnt);
+ if(!pnode) {
+ LOG("Unable to open parent '%s'", absPath);
free(absPath);
+ errno = ENOENT;
+ LEAVE_RET('i', -1);
+ }
+
+ // TODO: Check ACLs on the parent
+ if( !VFS_CheckACL(pnode, VFS_PERM_EXECUTE|VFS_PERM_WRITE) ) {
+ _CloseNode(pnode);
+ pmnt->OpenHandleCount --;
+ free(absPath);
+ LEAVE('i', -1);
return -1;
}
- node = VFS_ParsePath(absPath, NULL, &mnt);
+
+ // Check that there's a MkNod method
+ if( !pnode->Type || !pnode->Type->MkNod ) {
+ Log_Warning("VFS", "VFS_Open - Directory has no MkNod method");
+ errno = EINVAL;
+ LEAVE_RET('i', -1);
+ }
+
+ node = pnode->Type->MkNod(pnode, file, new_flags);
+ // Fall through on error check
+
+ _CloseNode(pnode);
+ pmnt->OpenHandleCount --;
}
// Free generated path
LEAVE_RET('i', -1);
}
+ // Increment open handle count, no problems with the mount going away as `h` is already open on it
+ h->Mount->OpenHandleCount ++;
+
LEAVE_RET('x', VFS_int_CreateHandle(node, h->Mount, Mode));
}
#endif
_CloseNode(h->Node);
-
+
+ if( h->Mount )
+ h->Mount->OpenHandleCount --;
+
h->Node = NULL;
}
*cwdptr = buf;
}
- Log("Updated CWD to '%s'", buf);
+ Log_Debug("VFS", "Updated CWD to '%s'", buf);
return 1;
}