* corresponds to.
* \{
*/
- Uint64 Inode; //!< Inode ID (Essentially another ImplInt)
+ Uint64 Inode; //!< Inode ID - Must identify the node uniquely if tVFS_Driver.GetNodeFromINode is non-NULL
Uint ImplInt; //!< Implementation Usable Integer
void *ImplPtr; //!< Implementation Usable Pointer
/**
*/
typedef struct sVFS_Driver
{
- //! \brief Unique Identifier for this filesystem type
+ /**
+ * \brief Unique Identifier for this filesystem type
+ */
const char *Name;
- //! \brief Flags applying to this driver
+ /**
+ * \brief Flags applying to this driver
+ */
Uint Flags;
- //! \brief Callback to mount a device
+ /**
+ * \brief Callback to mount a device
+ */
tVFS_Node *(*InitDevice)(const char *Device, const char **Options);
- //! \brief Callback to unmount a device
+ /**
+ * \brief Callback to unmount a device
+ */
void (*Unmount)(tVFS_Node *Node);
- //! \brief Used internally (next driver in the chain)
+ /**
+ * \brief Retrieve a VFS node from an inode
+ */
+ tVFS_Node *(*GetNodeFromINode)(tVFS_Node *RootNode, Uint64 InodeValue);
+ /**
+ * \brief Used internally (next driver in the chain)
+ */
struct sVFS_Driver *Next;
} tVFS_Driver;
/**
* \brief Opens a file via an open directory
* \note The file to open must be a direct child of the parent
- * \param Errno Error number
* \param FD Parent Directory
* \param Name Child name
* \param Mode Open mode
* \return File handle (same as returned from VFS_Open)
*/
-extern int VFS_OpenChild(Uint *Errno, int FD, const char *Name, Uint Mode);
+extern int VFS_OpenChild(int FD, const char *Name, Uint Mode);
+/**
+ * \brief Opens a file given a mount ID and an inode number
+ * \param Mount Mount ID returned by FInfo
+ * \param Inode Inode number from FInfo
+ * \param Mode Open mode (see VFS_Open)
+ * \return File handle (same as VFS_Open)
+ */
+extern int VFS_OpenInode(Uint32 Mount, Uint64 Inode, int Mode);
/**
* \brief Wait for an aciton on a file descriptor
* \param MaxHandle Maximum set handle in \a *Handles
/**
* \brief Map a file into memory
- * \param ErrNo Error status pointer
* \param DestHint Suggested place for read data
* \param Length Size of area to map
* \param Protection Protection type (see `man mmap`)
extern tVFS_Mount *gVFS_RootMount;
extern int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode);
+// === PROTOTYPES ===
+ int VFS_int_CreateHandle( tVFS_Node *Node, int Mode );
+
// === CODE ===
/**
* \fn char *VFS_GetAbsPath(const char *Path)
return tmpNode;
}
+/**
+ * \brief Create and return a handle number for the given node and mode
+ */
+int VFS_int_CreateHandle( tVFS_Node *Node, int Mode )
+{
+ int i;
+ i = 0;
+ i |= (Mode & VFS_OPENFLAG_EXEC) ? VFS_PERM_EXECUTE : 0;
+ i |= (Mode & VFS_OPENFLAG_READ) ? VFS_PERM_READ : 0;
+ i |= (Mode & VFS_OPENFLAG_WRITE) ? VFS_PERM_WRITE : 0;
+
+ LOG("i = 0b%b", i);
+
+ // Permissions Check
+ if( !VFS_CheckACL(Node, i) ) {
+ if(Node->Close) Node->Close( Node );
+ Log_Log("VFS", "VFS_int_CreateHandle: Permissions Failed");
+ errno = EACCES;
+ LEAVE_RET('i', -1);
+ }
+
+ i = VFS_AllocHandle( !!(Mode & VFS_OPENFLAG_USER), Node, Mode );
+ if( i < 0 ) {
+ Log_Notice("VFS", "VFS_int_CreateHandle: Out of handles");
+ errno = ENFILE;
+ LEAVE_RET('i', -1);
+ }
+
+ LEAVE_RET('x', i);
+}
+
/**
* \fn int VFS_Open(const char *Path, Uint Mode)
* \brief Open a file
{
tVFS_Node *node;
char *absPath;
- int i;
ENTER("sPath xMode", Path, Mode);
if(!node) {
LOG("Cannot find node");
+ errno = ENOENT;
LEAVE_RET('i', -1);
}
node = VFS_ParsePath(tmppath, NULL);
if(!node) {
LOG("Cannot find symlink target node (%s)", tmppath);
+ errno = ENOENT;
LEAVE_RET('i', -1);
}
}
- i = 0;
- i |= (Mode & VFS_OPENFLAG_EXEC) ? VFS_PERM_EXECUTE : 0;
- i |= (Mode & VFS_OPENFLAG_READ) ? VFS_PERM_READ : 0;
- i |= (Mode & VFS_OPENFLAG_WRITE) ? VFS_PERM_WRITE : 0;
-
- LOG("i = 0b%b", i);
-
- // Permissions Check
- if( !VFS_CheckACL(node, i) ) {
- if(node->Close) node->Close( node );
- Log_Log("VFS", "VFS_Open: Permissions Failed");
- LEAVE_RET('i', -1);
- }
-
- i = VFS_AllocHandle( !!(Mode & VFS_OPENFLAG_USER), node, Mode );
- if( i < 0 ) {
- Log_Notice("VFS", "VFS_Open: Out of handles");
- LEAVE_RET('i', -1);
- }
-
- LEAVE_RET('x', i);
+ LEAVE_RET('x', VFS_int_CreateHandle(node, Mode));
}
/**
* \brief Open a file from an open directory
*/
-int VFS_OpenChild(Uint *Errno, int FD, const char *Name, Uint Mode)
+int VFS_OpenChild(int FD, const char *Name, Uint Mode)
{
tVFS_Handle *h;
tVFS_Node *node;
- int i;
+ ENTER("xFD sName xMode", FD, Name, Mode);
+
// Get handle
h = VFS_GetHandle(FD);
if(h == NULL) {
Log_Warning("VFS", "VFS_OpenChild - Invalid file handle 0x%x", FD);
- if(Errno) *Errno = EINVAL;
+ errno = EINVAL;
LEAVE_RET('i', -1);
}
// Check for directory
if( !(h->Node->Flags & VFS_FFLAG_DIRECTORY) ) {
Log_Warning("VFS", "VFS_OpenChild - Passed handle is not a directory", FD);
- if(Errno) *Errno = ENOTDIR;
+ errno = ENOTDIR;
LEAVE_RET('i', -1);
}
// Find Child
node = h->Node->FindDir(h->Node, Name);
if(!node) {
- if(Errno) *Errno = ENOENT;
+ errno = ENOENT;
LEAVE_RET('i', -1);
}
+
+ LEAVE_RET('x', VFS_int_CreateHandle(node, Mode));
+}
+
+int VFS_OpenInode(Uint32 Mount, Uint64 Inode, int Mode)
+{
+ tVFS_Mount *mnt;
+ tVFS_Node *node;
+
+ ENTER("iMount iInode xMode", Mount, Inode, Mode);
- i = 0;
- i |= (Mode & VFS_OPENFLAG_EXEC) ? VFS_PERM_EXECUTE : 0;
- i |= (Mode & VFS_OPENFLAG_READ) ? VFS_PERM_READ : 0;
- i |= (Mode & VFS_OPENFLAG_WRITE) ? VFS_PERM_WRITE : 0;
-
- // Permissions Check
- if( !VFS_CheckACL(node, i) ) {
- if(node->Close) node->Close( node );
- Log_Notice("VFS", "VFS_OpenChild - Permissions Failed");
- if(Errno) *Errno = EACCES;
+ // Get mount point
+ mnt = VFS_GetMountByIdent(Mount);
+ if( !mnt ) {
+ LOG("Mount point ident invalid");
+ errno = ENOENT;
LEAVE_RET('i', -1);
}
- i = VFS_AllocHandle( !!(Mode & VFS_OPENFLAG_USER), node, Mode );
- if( i >= 0 ) {
- LEAVE_RET('x', i);
+ // Does the filesystem support this?
+ if( !mnt->Filesystem->GetNodeFromINode ) {
+ errno = ENOENT;
+ LEAVE_RET('i', -1);
+ }
+
+ // Get node
+ node = mnt->Filesystem->GetNodeFromINode(mnt->RootNode, Inode);
+ if( !node ) {
+ errno = ENOENT;
+ LEAVE_RET('i', -1);
}
- Log_Error("VFS", "VFS_OpenChild - Out of handles");
- if(Errno) *Errno = ENFILE;
- LEAVE_RET('i', -1);
+ LEAVE_RET('x', VFS_int_CreateHandle(node, Mode));
}
/**