mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 07:19:20 +00:00
Refactor filesystem & stl code
This commit is contained in:
@ -18,38 +18,40 @@
|
||||
#ifndef __FENNIX_KERNEL_FILESYSTEM_USTAR_H__
|
||||
#define __FENNIX_KERNEL_FILESYSTEM_USTAR_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#include <filesystem.hpp>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class USTARNode : public Node
|
||||
{
|
||||
private:
|
||||
uintptr_t Address;
|
||||
|
||||
public:
|
||||
size_t read(uint8_t *Buffer, size_t Size, off_t Offset) final;
|
||||
|
||||
USTARNode(uintptr_t Address, const char *Name, NodeType Type,
|
||||
Virtual *vfs_ctx);
|
||||
|
||||
~USTARNode();
|
||||
};
|
||||
|
||||
class USTAR
|
||||
{
|
||||
|
||||
enum FileType
|
||||
public:
|
||||
enum TypeFlag
|
||||
{
|
||||
REGULAR_FILE = '0',
|
||||
HARDLINK = '1',
|
||||
SYMLINK = '2',
|
||||
CHARDEV = '3',
|
||||
BLOCKDEV = '4',
|
||||
DIRECTORY = '5',
|
||||
FIFO = '6'
|
||||
AREGTYPE = '\0',
|
||||
REGTYPE = '0',
|
||||
LNKTYPE = '1',
|
||||
SYMTYPE = '2',
|
||||
CHRTYPE = '3',
|
||||
BLKTYPE = '4',
|
||||
DIRTYPE = '5',
|
||||
FIFOTYPE = '6',
|
||||
CONTTYPE = '7'
|
||||
};
|
||||
|
||||
enum ModeFlag
|
||||
{
|
||||
TSUID = 04000,
|
||||
TSGID = 02000,
|
||||
TSVTX = 01000,
|
||||
TUREAD = 00400,
|
||||
TUWRITE = 00200,
|
||||
TUEXEC = 00100,
|
||||
TGREAD = 00040,
|
||||
TGWRITE = 00020,
|
||||
TGEXEC = 00010,
|
||||
TOREAD = 00004,
|
||||
TOWRITE = 00002,
|
||||
TOEXEC = 00001,
|
||||
};
|
||||
|
||||
struct FileHeader
|
||||
@ -73,7 +75,23 @@ namespace vfs
|
||||
char pad[12];
|
||||
};
|
||||
|
||||
constexpr static int INODE_CHECKSUM = 0x7757A4;
|
||||
|
||||
struct USTARInode
|
||||
{
|
||||
struct Inode Node;
|
||||
FileHeader *Header;
|
||||
USTARInode *Parent;
|
||||
std::string Name;
|
||||
std::string Path;
|
||||
std::vector<USTARInode *> Children;
|
||||
bool Deleted;
|
||||
int Checksum;
|
||||
};
|
||||
|
||||
private:
|
||||
std::unordered_map<ino_t, USTARInode *> Files;
|
||||
|
||||
inline uint32_t GetSize(const char *String)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
@ -95,11 +113,25 @@ namespace vfs
|
||||
}
|
||||
|
||||
public:
|
||||
dev_t DeviceID = -1;
|
||||
ino_t NextInode = 0;
|
||||
|
||||
int Lookup(struct Inode *Parent, const char *Name, struct Inode **Result);
|
||||
int Create(struct Inode *Parent, const char *Name, mode_t Mode, struct Inode **Result);
|
||||
ssize_t Read(struct Inode *Node, void *Buffer, size_t Size, off_t Offset);
|
||||
ssize_t ReadDir(struct Inode *Node, struct kdirent *Buffer, size_t Size, off_t Offset, off_t Entries);
|
||||
int SymLink(struct Inode *Node, const char *Name, const char *Target, struct Inode **Result);
|
||||
ssize_t ReadLink(struct Inode *Node, char *Buffer, size_t Size);
|
||||
int Stat(struct Inode *Node, struct kstat *Stat);
|
||||
|
||||
bool TestArchive(uintptr_t Address);
|
||||
void ReadArchive(uintptr_t Address, Virtual *vfs_ctx);
|
||||
USTAR();
|
||||
~USTAR();
|
||||
void ReadArchive(uintptr_t Address, size_t Size);
|
||||
|
||||
USTAR(){};
|
||||
~USTAR(){};
|
||||
};
|
||||
}
|
||||
|
||||
bool TestAndInitializeUSTAR(uintptr_t Address, size_t Size);
|
||||
|
||||
#endif // !__FENNIX_KERNEL_FILESYSTEM_USTAR_H__
|
||||
|
Reference in New Issue
Block a user