Added filesystem

This commit is contained in:
Alex
2022-10-28 08:50:14 +03:00
parent 74a4685ba9
commit c8e5ce1d36
12 changed files with 1129 additions and 205 deletions

View File

@ -0,0 +1,74 @@
#ifndef __FENNIX_KERNEL_FILESYSTEM_EXT2_H__
#define __FENNIX_KERNEL_FILESYSTEM_EXT2_H__
#include <types.h>
#include <filesystem.hpp>
namespace FileSystem
{
class EXT2
{
public:
struct SuperBlock
{
uint32_t Inodes;
uint32_t Blocks;
uint32_t ReservedBlocks;
uint32_t FreeBlock;
uint32_t FreeInodes;
uint32_t FirstDataBlock;
uint32_t LogBlockSize;
uint32_t LogFragSize;
uint32_t BlocksPerGroup;
uint32_t FragsPerGroup;
uint32_t InodesPerGroup;
uint32_t LastMountTime;
uint32_t LastWrittenTime;
uint16_t MountedTimes;
uint16_t MaximumMountedTimes;
uint16_t Magic;
uint16_t State;
uint16_t Errors;
uint16_t MinorRevLevel;
uint32_t LastCheck;
uint32_t CheckInternval;
uint32_t SystemID;
uint32_t RevLevel;
uint16_t ReservedBlocksUserID;
uint16_t ReservedBlocksGroupID;
uint32_t FirstInode;
uint16_t InodeSize;
uint16_t BlockGroups;
uint32_t FeatureCompatibility;
uint32_t FeatureIncompatibility;
uint32_t FeatureRoCompatibility;
uint8_t UUID[16];
char VolumeName[16];
char LastMounted[64];
uint32_t BitmapAlogrithm;
uint8_t PreallocatedBlocks;
uint8_t PreallocatedDirectoryBlocks;
uint16_t Padding;
uint8_t JournalUUID[16];
uint32_t JournalInum;
uint32_t JournalDev;
uint32_t LastOrphan;
uint32_t HashSeed[4];
uint8_t DefHashVersion;
uint8_t ReservedCharPad;
uint16_t ReservedWordPad;
uint32_t DefaultMountOptions;
uint32_t FirstMetaBg;
uint32_t Reserved[190];
};
EXT2(void *partition);
~EXT2();
};
}
#endif // !__FENNIX_KERNEL_FILESYSTEM_EXT2_H__

View File

@ -0,0 +1,60 @@
#ifndef __FENNIX_KERNEL_FILESYSTEM_FAT_H__
#define __FENNIX_KERNEL_FILESYSTEM_FAT_H__
#include <types.h>
#include <filesystem.hpp>
namespace FileSystem
{
class FAT
{
public:
enum FatType
{
Unknown,
FAT12,
FAT16,
FAT32
};
/* https://wiki.osdev.org/FAT */
struct BIOSParameterBlock
{
/** @brief 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];
/** @brief 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 Drivers, 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];
/** @brief The number of Bytes per sector (remember, all numbers are in the little-endian format). */
uint16_t BytesPerSector;
/** @brief Number of sectors per cluster. */
uint8_t SectorsPerCluster;
/** @brief Number of reserved sectors. The boot record sectors are included in this value. */
uint16_t ReservedSectors;
/** @brief Number of File Allocation Tables (FAT's) on the storage media. Often this value is 2. */
uint8_t NumberOfFATs;
/** @brief Number of root directory entries (must be set so that the root directory occupies entire sectors). */
uint16_t RootDirectoryEntries;
/** @brief 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;
/** @brief This Byte indicates the media descriptor type. */
uint8_t Media;
/** @brief Number of sectors per FAT. FAT12/FAT16 only. */
uint16_t SectorsPerFAT;
/** @brief Number of sectors per track. */
uint16_t SectorsPerTrack;
/** @brief Number of heads or sides on the storage media. */
uint16_t NumberOfHeads;
/** @brief Number of hidden sectors. (i.e. the LBA of the beginning of the partition). */
uint32_t HiddenSectors;
/** @brief 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;
} __attribute__((__packed__));
FatType GetFATType(BIOSParameterBlock *bpb);
FAT(void *partition);
~FAT();
};
}
#endif // !__FENNIX_KERNEL_FILESYSTEM_FAT_H__

View File

@ -0,0 +1,31 @@
#ifndef __FENNIX_KERNEL_FILESYSTEM_INITRD_H__
#define __FENNIX_KERNEL_FILESYSTEM_INITRD_H__
#include <types.h>
#include <filesystem.hpp>
namespace FileSystem
{
class Initrd
{
public:
struct InitrdHeader
{
uint32_t nfiles;
};
struct InitrdFileHeader
{
uint8_t magic;
char name[64];
uint32_t offset;
uint32_t length;
};
Initrd(uint64_t Address);
~Initrd();
};
}
#endif // !__FENNIX_KERNEL_FILESYSTEM_INITRD_H__

View File

@ -0,0 +1,97 @@
#ifndef __FENNIX_KERNEL_FILESYSTEM_DEV_H__
#define __FENNIX_KERNEL_FILESYSTEM_DEV_H__
#include <types.h>
#include <filesystem.hpp>
namespace FileSystem
{
/* Manage /system/dev */
class Device
{
public:
FileSystemNode *AddFileSystem(FileSystemOpeations *Operator, uint64_t Mode, const char *Name, int Flags);
Device();
~Device();
};
/* Manage /system/mnt */
class Mount
{
public:
FileSystemNode *MountFileSystem(FileSystemOpeations *Operator, uint64_t Mode, const char *Name);
void DetectAndMountFS(void *drive);
Mount();
~Mount();
};
/* Manage /system/prc */
class Process
{
public:
Process();
~Process();
};
/* Manage /system/drv */
class Driver
{
public:
FileSystemNode *AddDriver(struct FileSystemOpeations *Operator, uint64_t Mode, const char *Name, int Flags);
Driver();
~Driver();
};
/* Manage /system/net */
class Network
{
public:
FileSystemNode *AddNetworkCard(struct FileSystemOpeations *Operator, uint64_t Mode, const char *Name, int Flags);
Network();
~Network();
};
/* Manage /system/dev/serialX */
class Serial
{
public:
Serial();
~Serial();
};
/* Manage /system/dev/random */
class Random
{
public:
Random();
~Random();
};
/* Manage /system/dev/null */
class Null
{
public:
Null();
~Null();
};
/* Manage /system/dev/zero */
class Zero
{
public:
Zero();
~Zero();
};
/* Manage /system/dev/fbX */
class FB
{
public:
void SetFrameBufferData(uint64_t Address, uint64_t Size, uint32_t Width, uint32_t Height, uint32_t PixelsPerScanLine);
FB();
~FB();
};
}
#endif // !__FENNIX_KERNEL_FILESYSTEM_DEV_H__

View File

@ -0,0 +1,71 @@
#ifndef __FENNIX_KERNEL_FILESYSTEM_USTAR_H__
#define __FENNIX_KERNEL_FILESYSTEM_USTAR_H__
#include <types.h>
#include <filesystem.hpp>
namespace FileSystem
{
class USTAR
{
enum FileType
{
REGULAR_FILE = '0',
HARDLINK = '1',
SYMLINK = '2',
CHARDEV = '3',
BLOCKDEV = '4',
DIRECTORY = '5',
FIFO = '6'
};
struct FileHeader
{
char name[100];
char mode[8];
char uid[8];
char gid[8];
char size[12];
char mtime[12];
char chksum[8];
char typeflag[1];
char link[100];
char signature[6];
char version[2];
char owner[32];
char group[32];
char dev_maj[8];
char dev_min[8];
char prefix[155];
char pad[12];
};
private:
uint32_t getsize(const char *s)
{
uint64_t ret = 0;
while (*s)
{
ret *= 8;
ret += *s - '0';
s++;
}
return ret;
}
int string2int(const char *str)
{
int res = 0;
for (int i = 0; str[i] != '\0'; ++i)
res = res * 10 + str[i] - '0';
return res;
}
public:
USTAR(uint64_t Address, Virtual *vfs);
~USTAR();
};
}
#endif // !__FENNIX_KERNEL_FILESYSTEM_USTAR_H__