fix(kernel/vfs): fully implement ustar driver implementation + mounting system

This commit is contained in:
2025-05-18 11:38:42 +00:00
parent 70a08e46bd
commit f06c0b19fa
7 changed files with 1209 additions and 120 deletions

View File

@ -128,25 +128,25 @@ namespace vfs
/**
* @brief Read directory entries
*
*
* @note This function includes "." and ".."
*
* @param Target
* @param Buffer
* @param Size
* @param Offset
* @param Entries
* @return
*
* @param Target
* @param Buffer
* @param Size
* @param Offset
* @param Entries
* @return
*/
ssize_t ReadDirectory(Node &Target, kdirent *Buffer, size_t Size, off_t Offset, off_t Entries);
/**
* @brief Read directory entries
*
*
* @note This function does NOT include "." and ".."
*
* @param Target
* @return
*
* @param Target
* @return
*/
std::list<Node> ReadDirectory(Node &Target);
@ -165,8 +165,76 @@ namespace vfs
#pragma region Mounting
FileSystemInfo *Probe(FileSystemDevice *Device);
FileSystemInfo *Probe(Node &node)
{
FileSystemDevice dev;
dev.inode.node = node->inode;
dev.inode.ops = &node->fsi->Ops;
dev.Block = nullptr;
return this->Probe(&dev);
}
FileSystemInfo *Probe(BlockDevice *Device)
{
FileSystemDevice dev;
dev.inode.node = nullptr;
dev.inode.ops = nullptr;
dev.Block = Device;
return this->Probe(&dev);
}
/**
* @brief Mount a filesystem
*
*
*
* @param Parent Parent Node
* @param inode Inode from the filesystem as root of the mount point
* @param Name Name of the mount point
* @param fsi FileSystemInfo structure
* @return eNode{Node, errno}
*/
eNode Mount(Node &Parent, Inode *inode, std::string Name, FileSystemInfo *fsi);
/**
* @brief Mount a filesystem
*
*
*
* @param Parent Parent Node
* @param Name Name of the mount point
* @param fsi FileSystemInfo structure
* @param Device Device to mount
* @return eNode{Node, errno}
*/
eNode Mount(Node &Parent, std::string Name, FileSystemInfo *fsi, FileSystemDevice *Device);
/**
* Wrapper for Mount(Node &Parent, std::string Name, FileSystemInfo *fsi, FileSystemDevice *Device)
*/
eNode Mount(Node &Parent, std::string Name, FileSystemInfo *fsi, Node Device)
{
FileSystemDevice dev;
dev.inode.node = Device->inode;
dev.inode.ops = &Device->fsi->Ops;
dev.Block = nullptr;
return this->Mount(Parent, Name, fsi, &dev);
}
/**
* Wrapper for Mount(Node &Parent, std::string Name, FileSystemInfo *fsi, FileSystemDevice *Device)
*/
eNode Mount(Node &Parent, std::string Name, FileSystemInfo *fsi, BlockDevice *Device)
{
FileSystemDevice dev;
dev.inode.node = nullptr;
dev.inode.ops = nullptr;
dev.Block = Device;
return this->Mount(Parent, Name, fsi, &dev);
}
int Umount(Node &node);
int Umount(Node &Parent, std::string Name);

View File

@ -323,6 +323,28 @@ struct InodeOperations
} __attribute__((packed));
struct FileSystemInfo;
struct FileSystemDevice
{
struct
{
/**
* @brief Inode
*
* If the device is a block device, this will be NULL.
*/
struct Inode *node;
struct InodeOperations *ops;
} inode;
/**
* @brief Block Device
*
* If the device is a block device, this will be non-NULL.
*/
struct BlockDevice *Block;
};
struct SuperBlockOperations
{
int (*AllocateInode)(struct FileSystemInfo *Info, struct Inode **Result);
@ -360,7 +382,7 @@ struct SuperBlockOperations
*
* @return Zero on success, otherwise an error code.
*/
int (*Probe)(void *Device);
int (*Probe)(struct FileSystemDevice *Device);
/**
* Mount the filesystem.
@ -369,11 +391,11 @@ struct SuperBlockOperations
*
* @param FS Filesystem to mount.
* @param Root Pointer to the root inode.
* @param Device Device to mount.
* @param Device Device to mount. This pointer will be undefined after the function returns!
*
* @return Zero on success, otherwise an error code.
*/
int (*Mount)(struct FileSystemInfo *FS, struct Inode **Root, void *Device);
int (*Mount)(struct FileSystemInfo *FS, struct Inode **Root, struct FileSystemDevice *Device);
/**
* Unmount the filesystem.