Refactor filesystem & stl code

This commit is contained in:
EnderIce2
2024-05-18 07:42:01 +03:00
parent 77a291d08b
commit 6801475243
186 changed files with 15784 additions and 9746 deletions

View File

@ -1,117 +0,0 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_KERNEL_FILESYSTEM_FAT_H__
#define __FENNIX_KERNEL_FILESYSTEM_FAT_H__
#include <types.h>
#include <filesystem.hpp>
namespace vfs
{
class FAT
{
public:
enum FatType
{
Unknown,
FAT12,
FAT16,
FAT32
};
/* https://wiki.osdev.org/FAT */
struct BIOSParameterBlock
{
/** The first three bytes EB 3C 90 disassemble to JMP SHORT 3C NOP.
* (The 3C value may be different.) The reason for this is to jump
* over the disk format information (the BPB and EBPB). Since the
* first sector of the disk is loaded into ram at location
* 0x0000:0x7c00 and executed, without this jump, the processor
* would attempt to execute data that isn't code. Even for
* non-bootable volumes, code matching this pattern (or using the
* E9 jump opcode) is required to be present by both Windows and
* OS X. To fulfil this requirement, an infinite loop can be placed
* here with the bytes EB FE 90. */
uint8_t JumpBoot[3];
/** OEM identifier. The first 8 Bytes (3 - 10) is the version of DOS
* being used. The next eight Bytes 29 3A 63 7E 2D 49 48 and 43 read
* out the name of the version. The official FAT Specification from
* Microsoft says that this field is really meaningless and is ignored
* by MS FAT Modules, however it does recommend the value "MSWIN4.1"
* as some 3rd party drivers supposedly check it and expect it to
* have that value. Older versions of dos also report MSDOS5.1,
* linux-formatted floppy will likely to carry "mkdosfs" here, and
* FreeDOS formatted disks have been observed to have "FRDOS5.1" here.
* If the string is less than 8 bytes, it is padded with spaces. */
uint8_t OEM[8];
/** The number of Bytes per sector (remember, all numbers are in the
* little-endian format). */
uint16_t BytesPerSector;
/** Number of sectors per cluster. */
uint8_t SectorsPerCluster;
/** Number of reserved sectors. The boot record sectors are included
* in this value. */
uint16_t ReservedSectors;
/** Number of File Allocation Tables (FAT's) on the storage media.
* Often this value is 2. */
uint8_t NumberOfFATs;
/** Number of root directory entries (must be set so that the root
* directory occupies entire sectors). */
uint16_t RootDirectoryEntries;
/** The total sectors in the logical volume. If this value is 0, it
* means there are more than 65535 sectors in the volume, and the
* actual count is stored in the Large Sector Count entry at 0x20. */
uint16_t Sectors16;
/** This Byte indicates the media descriptor type. */
uint8_t Media;
/** Number of sectors per FAT. FAT12/FAT16 only. */
uint16_t SectorsPerFAT;
/** Number of sectors per track. */
uint16_t SectorsPerTrack;
/** Number of heads or sides on the storage media. */
uint16_t NumberOfHeads;
/** Number of hidden sectors. (i.e. the LBA of the beginning of
* the partition). */
uint32_t HiddenSectors;
/** Large sector count. This field is set if there are more than
* 65535 sectors in the volume, resulting in a value which does not
* fit in the Number of Sectors entry at 0x13. */
uint32_t Sectors32;
} __packed;
FatType GetFATType(BIOSParameterBlock *bpb);
FAT(void *partition);
~FAT();
};
}
#endif // !__FENNIX_KERNEL_FILESYSTEM_FAT_H__

View File

@ -20,7 +20,7 @@
#include <types.h>
#include <stropts.h>
#include <filesystem/termios.hpp>
#include <termios.h>
#define _IOC_NRBITS 8
#define _IOC_TYPEBITS 8

View File

@ -20,184 +20,53 @@
#include <types.h>
#include <filesystem/termios.hpp>
#include <filesystem.hpp>
#include <bitmap.hpp>
#include <task.hpp>
#include <termios.h>
#include <lock.hpp>
#include <vector>
namespace vfs
{
class vfsRoot : public Node
{
public:
vfsRoot(const char *Name, Virtual *vfs_ctx);
~vfsRoot() {}
};
class NullDevice : public Node
{
public:
size_t read(uint8_t *Buffer,
size_t Size,
off_t Offset) final;
size_t write(uint8_t *Buffer,
size_t Size,
off_t Offset) final;
NullDevice();
~NullDevice();
};
class RandomDevice : public Node
{
public:
size_t read(uint8_t *Buffer,
size_t Size,
off_t Offset) final;
size_t write(uint8_t *Buffer,
size_t Size,
off_t Offset) final;
RandomDevice();
~RandomDevice();
};
class ZeroDevice : public Node
{
public:
size_t read(uint8_t *Buffer,
size_t Size,
off_t Offset) final;
size_t write(uint8_t *Buffer,
size_t Size,
off_t Offset) final;
ZeroDevice();
~ZeroDevice();
};
class KConDevice : public Node
{
public:
size_t read(uint8_t *Buffer,
size_t Size,
off_t Offset) final;
size_t write(uint8_t *Buffer,
size_t Size,
off_t Offset) final;
int ioctl(unsigned long Request,
void *Argp) final;
termios term{};
winsize termSize{};
KConDevice();
~KConDevice();
};
class TTYDevice : public Node
{
public:
size_t write(uint8_t *Buffer,
size_t Size,
off_t Offset) final;
int ioctl(unsigned long Request,
void *Argp) final;
TTYDevice();
~TTYDevice();
};
class MasterPTY
{
NewLock(PTYLock);
public:
size_t read(uint8_t *Buffer,
size_t Size,
off_t Offset);
size_t write(uint8_t *Buffer,
size_t Size,
off_t Offset);
MasterPTY();
~MasterPTY();
};
class SlavePTY
{
NewLock(PTYLock);
public:
size_t read(uint8_t *Buffer,
size_t Size,
off_t Offset);
size_t write(uint8_t *Buffer,
size_t Size,
off_t Offset);
SlavePTY();
~SlavePTY();
};
class PTYDevice : public Node
class PTYDevice
{
private:
Node *pts;
Inode *pts;
int id;
int fildes;
bool isMaster;
termios term{};
winsize termSize{};
MasterPTY *MasterDev;
SlavePTY *SlaveDev;
class PTYSlave
{
};
class PTYMaster
{
};
public:
decltype(id) &ptyId = id;
decltype(fildes) &fd = fildes;
int open(int Flags, mode_t Mode) final;
int close() final;
size_t read(uint8_t *Buffer,
size_t Size,
off_t Offset) final;
size_t write(uint8_t *Buffer,
size_t Size,
off_t Offset) final;
int ioctl(unsigned long Request,
void *Argp) final;
ssize_t Read(struct Inode *Node, void *Buffer, size_t Size, off_t Offset);
ssize_t Write(struct Inode *Node, const void *Buffer, size_t Size, off_t Offset);
int Ioctl(struct Inode *Node, unsigned long Request, void *Argp);
int OpenMaster(int Flags, mode_t Mode);
PTYDevice(Node *pts, int id);
PTYDevice(Inode *pts, int id);
~PTYDevice();
};
class PTMXDevice : public Node
class PTMXDevice
{
private:
NewLock(PTMXLock);
Node *pts;
FileNode *ptmx;
FileNode *pts;
Bitmap ptysId;
std::vector<PTYDevice *> ptysList;
std::unordered_map<size_t, PTYDevice *> ptysList;
public:
int open(int Flags, mode_t Mode) final;
/**
* Remove a PTY from the list
*
* @param fd The file descriptor of the PTY
* @param pcb The process that owns the PTY
*
* @note if pcb is nullptr, the current process
* will be used.
*
*/
void RemovePTY(int fd, Tasking::PCB *pcb = nullptr);
int Open(struct Inode *Node, int Flags, mode_t Mode, struct Inode *Result);
int Close(struct Inode *Node);
PTMXDevice();
~PTMXDevice();

View File

@ -1,160 +0,0 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_KERNEL_TERMIOS_BITS_H__
#define __FENNIX_KERNEL_TERMIOS_BITS_H__
/* c_cc */
#define VINTR 0
#define VQUIT 1
#define VERASE 2
#define VKILL 3
#define VEOF 4
#define VTIME 5
#define VMIN 6
#define VSWTC 7
#define VSTART 8
#define VSTOP 9
#define VSUSP 10
#define VEOL 11
#define VREPRINT 12
#define VDISCARD 13
#define VWERASE 14
#define VLNEXT 15
#define VEOL2 16
/* c_iflag */
#define IGNBRK 0000001
#define BRKINT 0000002
#define IGNPAR 0000004
#define PARMRK 0000010
#define INPCK 0000020
#define ISTRIP 0000040
#define INLCR 0000100
#define IGNCR 0000200
#define ICRNL 0000400
#define IUCLC 0001000
#define IXON 0002000
#define IXANY 0004000
#define IXOFF 0010000
#define IMAXBEL 0020000
#define IUTF8 0040000
/* c_lflag */
#define ISIG 0000001
#define ICANON 0000002
#define XCASE 0000004
#define ECHO 0000010
#define ECHOE 0000020
#define ECHOK 0000040
#define ECHONL 0000100
#define NOFLSH 0000200
#define TOSTOP 0000400
#define ECHOCTL 0001000
#define ECHOPRT 0002000
#define ECHOKE 0004000
#define FLUSHO 0010000
#define PENDIN 0040000
#define IEXTEN 0100000
#define EXTPROC 0200000
/* c_oflag */
#define OPOST 0000001
#define OLCUC 0000002
#define ONLCR 0000004
#define OCRNL 0000010
#define ONOCR 0000020
#define ONLRET 0000040
#define OFILL 0000100
#define OFDEL 0000200
#define NLDLY 0000400
#define NL0 0000000
#define NL1 0000400
#define CRDLY 0003000
#define _CR0 0000000
#define _CR1 0001000
#define _CR2 0002000
#define _CR3 0003000
#define TABDLY 0014000
#define TAB0 0000000
#define TAB1 0004000
#define TAB2 0010000
#define TAB3 0014000
#define XTABS 0014000
#define BSDLY 0020000
#define BS0 0000000
#define BS1 0020000
#define VTDLY 0040000
#define VT0 0000000
#define VT1 0040000
#define FFDLY 0100000
#define FF0 0000000
#define FF1 0100000
/* c_cflag */
#define CBAUD 0010017
#define _B0 0000000
#define B50 0000001
#define B75 0000002
#define B110 0000003
#define B134 0000004
#define B150 0000005
#define B200 0000006
#define B300 0000007
#define B600 0000010
#define B1200 0000011
#define B1800 0000012
#define B2400 0000013
#define B4800 0000014
#define B9600 0000015
#define B19200 0000016
#define B38400 0000017
#define EXTA B19200
#define EXTB B38400
#define CSIZE 0000060
#define CS5 0000000
#define CS6 0000020
#define CS7 0000040
#define CS8 0000060
#define CSTOPB 0000100
#define CREAD 0000200
#define PARENB 0000400
#define PARODD 0001000
#define HUPCL 0002000
#define CLOCAL 0004000
#define CBAUDEX 0010000
#define BOTHER 0010000
#define B57600 0010001
#define B115200 0010002
#define B230400 0010003
#define B460800 0010004
#define B500000 0010005
#define B576000 0010006
#define B921600 0010007
#define B1000000 0010010
#define B1152000 0010011
#define B1500000 0010012
#define B2000000 0010013
#define B2500000 0010014
#define B3000000 0010015
#define B3500000 0010016
#define B4000000 0010017
#define CIBAUD 002003600000
#define CMSPAR 010000000000
#define CRTSCTS 020000000000
#endif // !__FENNIX_KERNEL_TERMIOS_BITS_H__

View File

@ -1,49 +0,0 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_KERNEL_TERMIOS_H__
#define __FENNIX_KERNEL_TERMIOS_H__
#include <types.h>
#include <filesystem/termios-bits.hpp>
typedef unsigned char cc_t;
typedef unsigned int speed_t;
typedef unsigned int tcflag_t;
#define NCCS 32
struct termios
{
tcflag_t c_iflag;
tcflag_t c_oflag;
tcflag_t c_cflag;
tcflag_t c_lflag;
cc_t c_line;
cc_t c_cc[NCCS];
speed_t c_ispeed;
speed_t c_ospeed;
};
struct winsize
{
unsigned short ws_row;
unsigned short ws_col;
unsigned short ws_xpixel;
unsigned short ws_ypixel;
};
#endif // !__FENNIX_KERNEL_TERMIOS_H__

View File

@ -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__