mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-11 15:29:15 +00:00
Merge remote-tracking branch 'Kernel/master'
This commit is contained in:
91
Kernel/include/filesystem/ext2.hpp
Normal file
91
Kernel/include/filesystem/ext2.hpp
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
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_EXT2_H__
|
||||
#define __FENNIX_KERNEL_FILESYSTEM_EXT2_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#include <filesystem.hpp>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
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__
|
48
Kernel/include/filesystem/initrd.hpp
Normal file
48
Kernel/include/filesystem/initrd.hpp
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
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_INITRD_H__
|
||||
#define __FENNIX_KERNEL_FILESYSTEM_INITRD_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#include <filesystem.hpp>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class Initrd
|
||||
{
|
||||
public:
|
||||
struct InitrdHeader
|
||||
{
|
||||
uint32_t nfiles;
|
||||
};
|
||||
|
||||
struct InitrdFileHeader
|
||||
{
|
||||
uint8_t magic;
|
||||
char name[64];
|
||||
uint32_t offset;
|
||||
uint32_t length;
|
||||
};
|
||||
|
||||
Initrd(uintptr_t Address);
|
||||
~Initrd();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_FILESYSTEM_INITRD_H__
|
77
Kernel/include/filesystem/ioctl.hpp
Normal file
77
Kernel/include/filesystem/ioctl.hpp
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
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_IOCTL_H__
|
||||
#define __FENNIX_KERNEL_FILESYSTEM_IOCTL_H__
|
||||
|
||||
#include <types.h>
|
||||
#include <stropts.h>
|
||||
#include <termios.h>
|
||||
|
||||
#define _IOC_NRBITS 8
|
||||
#define _IOC_TYPEBITS 8
|
||||
#define _IOC_SIZEBITS 14
|
||||
#define _IOC_DIRBITS 2
|
||||
|
||||
#define _IOC_NRMASK \
|
||||
((1 << _IOC_NRBITS) - 1)
|
||||
#define _IOC_TYPEMASK \
|
||||
((1 << _IOC_TYPEBITS) - 1)
|
||||
#define _IOC_SIZEMASK \
|
||||
((1 << _IOC_SIZEBITS) - 1)
|
||||
#define _IOC_DIRMASK \
|
||||
((1 << _IOC_DIRBITS) - 1)
|
||||
|
||||
#define _IOC_NRSHIFT 0
|
||||
#define _IOC_TYPESHIFT \
|
||||
(_IOC_NRSHIFT + _IOC_NRBITS)
|
||||
#define _IOC_SIZESHIFT \
|
||||
(_IOC_TYPESHIFT + _IOC_TYPEBITS)
|
||||
#define _IOC_DIRSHIFT \
|
||||
(_IOC_SIZESHIFT + _IOC_SIZEBITS)
|
||||
|
||||
#define _IOC(dir, type, nr, size) \
|
||||
(((dir) << _IOC_DIRSHIFT) | \
|
||||
((type) << _IOC_TYPESHIFT) | \
|
||||
((nr) << _IOC_NRSHIFT) | \
|
||||
((size) << _IOC_SIZESHIFT))
|
||||
|
||||
#define _IOC_NONE 0U
|
||||
#define _IOC_WRITE 1U
|
||||
#define _IOC_READ 2U
|
||||
|
||||
#define _IOC_TYPECHECK(t) (sizeof(t))
|
||||
|
||||
#define _IO(type, nr) \
|
||||
_IOC(_IOC_NONE, (type), (nr), 0)
|
||||
#define _IOR(type, nr, size) \
|
||||
_IOC(_IOC_READ, (type), (nr), (_IOC_TYPECHECK(size)))
|
||||
#define _IOW(type, nr, size) \
|
||||
_IOC(_IOC_WRITE, (type), (nr), (_IOC_TYPECHECK(size)))
|
||||
#define _IOWR(type, nr, size) \
|
||||
_IOC(_IOC_READ | _IOC_WRITE, (type), (nr), (_IOC_TYPECHECK(size)))
|
||||
#define _IOR_BAD(type, nr, size) \
|
||||
_IOC(_IOC_READ, (type), (nr), sizeof(size))
|
||||
#define _IOW_BAD(type, nr, size) \
|
||||
_IOC(_IOC_WRITE, (type), (nr), sizeof(size))
|
||||
#define _IOWR_BAD(type, nr, size) \
|
||||
_IOC(_IOC_READ | _IOC_WRITE, (type), (nr), sizeof(size))
|
||||
|
||||
#define TIOCGPTN _IOR('T', 0x30, unsigned int)
|
||||
#define TIOCSPTLCK _IOW('T', 0x31, int)
|
||||
|
||||
#endif // !__FENNIX_KERNEL_FILESYSTEM_IOCTL_H__
|
137
Kernel/include/filesystem/ustar.hpp
Normal file
137
Kernel/include/filesystem/ustar.hpp
Normal file
@ -0,0 +1,137 @@
|
||||
/*
|
||||
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_USTAR_H__
|
||||
#define __FENNIX_KERNEL_FILESYSTEM_USTAR_H__
|
||||
|
||||
#include <filesystem.hpp>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class USTAR
|
||||
{
|
||||
public:
|
||||
enum TypeFlag
|
||||
{
|
||||
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
|
||||
{
|
||||
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];
|
||||
};
|
||||
|
||||
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;
|
||||
while (*String)
|
||||
{
|
||||
ret *= 8;
|
||||
ret += *String - '0';
|
||||
String++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline int StringToInt(const char *String)
|
||||
{
|
||||
int ret = 0;
|
||||
for (int i = 0; String[i] != '\0'; ++i)
|
||||
ret = ret * 10 + String[i] - '0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
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, 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