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

@ -20,174 +20,178 @@
#include <types.h>
#define ARCH_SET_GS 0x1001
#define ARCH_SET_FS 0x1002
#define ARCH_GET_FS 0x1003
#define ARCH_GET_GS 0x1004
#define linux_SEEK_SET 0
#define linux_SEEK_CUR 1
#define linux_SEEK_END 2
#define ARCH_GET_CPUID 0x1011
#define ARCH_SET_CPUID 0x1012
#define linux_ARCH_SET_GS 0x1001
#define linux_ARCH_SET_FS 0x1002
#define linux_ARCH_GET_FS 0x1003
#define linux_ARCH_GET_GS 0x1004
#define ARCH_GET_XCOMP_SUPP 0x1021
#define ARCH_GET_XCOMP_PERM 0x1022
#define ARCH_REQ_XCOMP_PERM 0x1023
#define ARCH_GET_XCOMP_GUEST_PERM 0x1024
#define ARCH_REQ_XCOMP_GUEST_PERM 0x1025
#define linux_ARCH_GET_CPUID 0x1011
#define linux_ARCH_SET_CPUID 0x1012
#define ARCH_XCOMP_TILECFG 17
#define ARCH_XCOMP_TILEDATA 18
#define linux_ARCH_GET_XCOMP_SUPP 0x1021
#define linux_ARCH_GET_XCOMP_PERM 0x1022
#define linux_ARCH_REQ_XCOMP_PERM 0x1023
#define linux_ARCH_GET_XCOMP_GUEST_PERM 0x1024
#define linux_ARCH_REQ_XCOMP_GUEST_PERM 0x1025
#define ARCH_MAP_VDSO_X32 0x2001
#define ARCH_MAP_VDSO_32 0x2002
#define ARCH_MAP_VDSO_64 0x2003
#define linux_ARCH_XCOMP_TILECFG 17
#define linux_ARCH_XCOMP_TILEDATA 18
#define ARCH_GET_UNTAG_MASK 0x4001
#define ARCH_ENABLE_TAGGED_ADDR 0x4002
#define ARCH_GET_MAX_TAG_BITS 0x4003
#define ARCH_FORCE_TAGGED_SVA 0x4004
#define linux_ARCH_MAP_VDSO_X32 0x2001
#define linux_ARCH_MAP_VDSO_32 0x2002
#define linux_ARCH_MAP_VDSO_64 0x2003
#define PROT_NONE 0
#define PROT_READ 1
#define PROT_WRITE 2
#define PROT_EXEC 4
#define PROT_GROWSDOWN 0x01000000
#define PROT_GROWSUP 0x02000000
#define linux_ARCH_GET_UNTAG_MASK 0x4001
#define linux_ARCH_ENABLE_TAGGED_ADDR 0x4002
#define linux_ARCH_GET_MAX_TAG_BITS 0x4003
#define linux_ARCH_FORCE_TAGGED_SVA 0x4004
#define MAP_TYPE 0x0f
#define linux_PROT_NONE 0
#define linux_PROT_READ 1
#define linux_PROT_WRITE 2
#define linux_PROT_EXEC 4
#define linux_PROT_GROWSDOWN 0x01000000
#define linux_PROT_GROWSUP 0x02000000
#define MAP_FILE 0
#define MAP_SHARED 0x01
#define MAP_PRIVATE 0x02
#define MAP_SHARED_VALIDATE 0x03
#define MAP_FIXED 0x10
#define MAP_ANONYMOUS 0x20
#define MAP_NORESERVE 0x4000
#define MAP_GROWSDOWN 0x0100
#define MAP_DENYWRITE 0x0800
#define MAP_EXECUTABLE 0x1000
#define MAP_LOCKED 0x2000
#define MAP_POPULATE 0x8000
#define MAP_NONBLOCK 0x10000
#define MAP_STACK 0x20000
#define MAP_HUGETLB 0x40000
#define MAP_SYNC 0x80000
#define MAP_FIXED_NOREPLACE 0x100000
#define linux_MAP_TYPE 0x0f
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1
#define CLOCK_PROCESS_CPUTIME_ID 2
#define CLOCK_THREAD_CPUTIME_ID 3
#define CLOCK_MONOTONIC_RAW 4
#define CLOCK_REALTIME_COARSE 5
#define CLOCK_MONOTONIC_COARSE 6
#define CLOCK_BOOTTIME 7
#define CLOCK_REALTIME_ALARM 8
#define CLOCK_BOOTTIME_ALARM 9
#define CLOCK_SGI_CYCLE 10
#define CLOCK_TAI 11
#define linux_MAP_FILE 0
#define linux_MAP_SHARED 0x01
#define linux_MAP_PRIVATE 0x02
#define linux_MAP_SHARED_VALIDATE 0x03
#define linux_MAP_FIXED 0x10
#define linux_MAP_ANONYMOUS 0x20
#define linux_MAP_NORESERVE 0x4000
#define linux_MAP_GROWSDOWN 0x0100
#define linux_MAP_DENYWRITE 0x0800
#define linux_MAP_EXECUTABLE 0x1000
#define linux_MAP_LOCKED 0x2000
#define linux_MAP_POPULATE 0x8000
#define linux_MAP_NONBLOCK 0x10000
#define linux_MAP_STACK 0x20000
#define linux_MAP_HUGETLB 0x40000
#define linux_MAP_SYNC 0x80000
#define linux_MAP_FIXED_NOREPLACE 0x100000
#define GRND_NONBLOCK 0x1
#define GRND_RANDOM 0x2
#define GRND_INSECURE 0x4
#define linux_CLOCK_REALTIME 0
#define linux_CLOCK_MONOTONIC 1
#define linux_CLOCK_PROCESS_CPUTIME_ID 2
#define linux_CLOCK_THREAD_CPUTIME_ID 3
#define linux_CLOCK_MONOTONIC_RAW 4
#define linux_CLOCK_REALTIME_COARSE 5
#define linux_CLOCK_MONOTONIC_COARSE 6
#define linux_CLOCK_BOOTTIME 7
#define linux_CLOCK_REALTIME_ALARM 8
#define linux_CLOCK_BOOTTIME_ALARM 9
#define linux_CLOCK_SGI_CYCLE 10
#define linux_CLOCK_TAI 11
#define RLIMIT_CPU 0
#define RLIMIT_FSIZE 1
#define RLIMIT_DATA 2
#define RLIMIT_STACK 3
#define RLIMIT_CORE 4
#define RLIMIT_RSS 5
#define RLIMIT_NPROC 6
#define RLIMIT_NOFILE 7
#define RLIMIT_MEMLOCK 8
#define RLIMIT_AS 9
#define RLIMIT_LOCKS 10
#define RLIMIT_SIGPENDING 11
#define RLIMIT_MSGQUEUE 12
#define RLIMIT_NICE 13
#define RLIMIT_RTPRIO 14
#define RLIMIT_RTTIME 15
#define RLIMIT_NLIMITS 16
#define linux_GRND_NONBLOCK 0x1
#define linux_GRND_RANDOM 0x2
#define linux_GRND_INSECURE 0x4
#define F_DUPFD 0
#define F_GETFD 1
#define F_SETFD 2
#define F_GETFL 3
#define F_SETFL 4
#define linux_RLIMIT_CPU 0
#define linux_RLIMIT_FSIZE 1
#define linux_RLIMIT_DATA 2
#define linux_RLIMIT_STACK 3
#define linux_RLIMIT_CORE 4
#define linux_RLIMIT_RSS 5
#define linux_RLIMIT_NPROC 6
#define linux_RLIMIT_NOFILE 7
#define linux_RLIMIT_MEMLOCK 8
#define linux_RLIMIT_AS 9
#define linux_RLIMIT_LOCKS 10
#define linux_RLIMIT_SIGPENDING 11
#define linux_RLIMIT_MSGQUEUE 12
#define linux_RLIMIT_NICE 13
#define linux_RLIMIT_RTPRIO 14
#define linux_RLIMIT_RTTIME 15
#define linux_RLIMIT_NLIMITS 16
#define F_SETOWN 8
#define F_GETOWN 9
#define F_SETSIG 10
#define F_GETSIG 11
#define linux_F_DUPFD 0
#define linux_F_GETFD 1
#define linux_F_SETFD 2
#define linux_F_GETFL 3
#define linux_F_SETFL 4
#define linux_F_SETOWN 8
#define linux_F_GETOWN 9
#define linux_F_SETSIG 10
#define linux_F_GETSIG 11
#if __LONG_MAX == 0x7fffffffL
#define F_GETLK 12
#define F_SETLK 13
#define F_SETLKW 14
#define linux_F_GETLK 12
#define linux_F_SETLK 13
#define linux_F_SETLKW 14
#else
#define F_GETLK 5
#define F_SETLK 6
#define F_SETLKW 7
#define linux_F_GETLK 5
#define linux_F_SETLK 6
#define linux_F_SETLKW 7
#endif
#define F_SETOWN_EX 15
#define F_GETOWN_EX 16
#define F_GETOWNER_UIDS 17
#define linux_F_SETOWN_EX 15
#define linux_F_GETOWN_EX 16
#define linux_F_GETOWNER_UIDS 17
#define F_OFD_GETLK 36
#define F_OFD_SETLK 37
#define F_OFD_SETLKW 38
#define linux_F_OFD_GETLK 36
#define linux_F_OFD_SETLK 37
#define linux_F_OFD_SETLKW 38
#define F_DUPFD_CLOEXEC 1030
#define linux_F_DUPFD_CLOEXEC 1030
#define FD_CLOEXEC 1
#define linux_FD_CLOEXEC 1
#define DT_UNKNOWN 0
#define DT_FIFO 1
#define DT_CHR 2
#define DT_DIR 4
#define DT_BLK 6
#define DT_REG 8
#define DT_LNK 10
#define DT_SOCK 12
#define DT_WHT 14
#define linux_DT_UNKNOWN 0
#define linux_DT_FIFO 1
#define linux_DT_CHR 2
#define linux_DT_DIR 4
#define linux_DT_BLK 6
#define linux_DT_REG 8
#define linux_DT_LNK 10
#define linux_DT_SOCK 12
#define linux_DT_WHT 14
#define AT_FDCWD (-100)
#define AT_SYMLINK_NOFOLLOW 0x100
#define AT_REMOVEDIR 0x200
#define AT_SYMLINK_FOLLOW 0x400
#define AT_EACCESS 0x200
#define AT_NO_AUTOMOUNT 0x800
#define AT_EMPTY_PATH 0x1000
#define AT_STATX_SYNC_TYPE 0x6000
#define AT_STATX_SYNC_AS_STAT 0x0000
#define AT_STATX_FORCE_SYNC 0x2000
#define AT_STATX_DONT_SYNC 0x4000
#define AT_RECURSIVE 0x8000
#define linux_AT_FDCWD (-100)
#define linux_AT_SYMLINK_NOFOLLOW 0x100
#define linux_AT_REMOVEDIR 0x200
#define linux_AT_SYMLINK_FOLLOW 0x400
#define linux_AT_EACCESS 0x200
#define linux_AT_NO_AUTOMOUNT 0x800
#define linux_AT_EMPTY_PATH 0x1000
#define linux_AT_STATX_SYNC_TYPE 0x6000
#define linux_AT_STATX_SYNC_AS_STAT 0x0000
#define linux_AT_STATX_FORCE_SYNC 0x2000
#define linux_AT_STATX_DONT_SYNC 0x4000
#define linux_AT_RECURSIVE 0x8000
#define LINUX_REBOOT_MAGIC1 0xfee1dead
#define LINUX_REBOOT_MAGIC2 0x28121969
#define LINUX_REBOOT_MAGIC2A 0x05121996
#define LINUX_REBOOT_MAGIC2B 0x16041998
#define LINUX_REBOOT_MAGIC2C 0x20112000
#define linux_LINUX_REBOOT_MAGIC1 0xfee1dead
#define linux_LINUX_REBOOT_MAGIC2 0x28121969
#define linux_LINUX_REBOOT_MAGIC2A 0x05121996
#define linux_LINUX_REBOOT_MAGIC2B 0x16041998
#define linux_LINUX_REBOOT_MAGIC2C 0x20112000
#define LINUX_REBOOT_CMD_RESTART 0x01234567
#define LINUX_REBOOT_CMD_HALT 0xCDEF0123
#define LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF
#define LINUX_REBOOT_CMD_CAD_OFF 0x00000000
#define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC
#define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
#define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
#define LINUX_REBOOT_CMD_KEXEC 0x45584543
#define linux_LINUX_REBOOT_CMD_RESTART 0x01234567
#define linux_LINUX_REBOOT_CMD_HALT 0xCDEF0123
#define linux_LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF
#define linux_LINUX_REBOOT_CMD_CAD_OFF 0x00000000
#define linux_LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC
#define linux_LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
#define linux_LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
#define linux_LINUX_REBOOT_CMD_KEXEC 0x45584543
#define SA_IMMUTABLE 0x00800000
#define linux_SA_IMMUTABLE 0x00800000
#define ITIMER_REAL 0
#define ITIMER_VIRTUAL 1
#define ITIMER_PROF 2
#define linux_ITIMER_REAL 0
#define linux_ITIMER_VIRTUAL 1
#define linux_ITIMER_PROF 2
#define RUSAGE_SELF 0
#define RUSAGE_CHILDREN (-1)
#define RUSAGE_THREAD 1
#define linux_RUSAGE_SELF 0
#define linux_RUSAGE_CHILDREN (-1)
#define linux_RUSAGE_THREAD 1
typedef long __kernel_long_t;
typedef unsigned long __kernel_ulong_t;
@ -249,19 +253,24 @@ struct rusage
struct linux_dirent
{
unsigned long d_ino; /* Inode number */
unsigned long d_off; /* Offset to next linux_dirent */
unsigned short d_reclen; /* Length of this linux_dirent */
char d_name[]; /* Filename (null-terminated) */
unsigned long d_ino;
unsigned long d_off;
unsigned short d_reclen;
char d_name[];
/**
* Getting d_type is not the same as linux_dirent64:
* https://github.com/torvalds/linux/blob/bfa8f18691ed2e978e4dd51190569c434f93e268/fs/readdir.c#L296
* "man 2 getdents" also is helpful
*/
};
struct linux_dirent64
{
ino64_t d_ino; /* 64-bit inode number */
off64_t d_off; /* 64-bit offset to next structure */
unsigned short d_reclen; /* Size of this dirent */
unsigned char d_type; /* File type */
char d_name[]; /* Filename (null-terminated) */
uint64_t d_ino;
int64_t d_off;
unsigned short d_reclen;
unsigned char d_type;
char d_name[];
};
struct linux_kstat

View File

@ -0,0 +1,408 @@
/*
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_LINUX_ERRNO_H__
#define __FENNIX_KERNEL_LINUX_ERRNO_H__
/** Operation not permitted */
#define linux_EPERM 1
/** No such file or directory */
#define linux_ENOENT 2
/** No such process */
#define linux_ESRCH 3
/** Interrupted system call */
#define linux_EINTR 4
/** I/O error */
#define linux_EIO 5
/** No such device or address */
#define linux_ENXIO 6
/** Argument list too long */
#define linux_E2BIG 7
/** Exec format error */
#define linux_ENOEXEC 8
/** Bad file number */
#define linux_EBADF 9
/** No child processes */
#define linux_ECHILD 10
/** Try again */
#define linux_EAGAIN 11
/** Out of memory */
#define linux_ENOMEM 12
/** Permission denied */
#define linux_EACCES 13
/** Bad address */
#define linux_EFAULT 14
/** Block device required */
#define linux_ENOTBLK 15
/** Device or resource busy */
#define linux_EBUSY 16
/** File exists */
#define linux_EEXIST 17
/** Cross-device link */
#define linux_EXDEV 18
/** No such device */
#define linux_ENODEV 19
/** Not a directory */
#define linux_ENOTDIR 20
/** Is a directory */
#define linux_EISDIR 21
/** Invalid argument */
#define linux_EINVAL 22
/** File table overflow */
#define linux_ENFILE 23
/** Too many open files */
#define linux_EMFILE 24
/** Not a typewriter */
#define linux_ENOTTY 25
/** Text file busy */
#define linux_ETXTBSY 26
/** File too large */
#define linux_EFBIG 27
/** No space left on device */
#define linux_ENOSPC 28
/** Illegal seek */
#define linux_ESPIPE 29
/** Read-only file system */
#define linux_EROFS 30
/** Too many links */
#define linux_EMLINK 31
/** Broken pipe */
#define linux_EPIPE 32
/** Math argument out of domain of func */
#define linux_EDOM 33
/** Math result not representable */
#define linux_ERANGE 34
/** Resource deadlock would occur */
#define linux_EDEADLK 35
/** File name too long */
#define linux_ENAMETOOLONG 36
/** No record locks available */
#define linux_ENOLCK 37
/** Function not implemented */
#define linux_ENOSYS 38
/** Directory not empty */
#define linux_ENOTEMPTY 39
/** Too many symbolic links encountered */
#define linux_ELOOP 40
/** No message of desired type */
#define linux_ENOMSG 42
/** Identifier removed */
#define linux_EIDRM 43
/** Channel number out of range */
#define linux_ECHRNG 44
/** Level 2 not synchronized */
#define linux_EL2NSYNC 45
/** Level 3 halted */
#define linux_EL3HLT 46
/** Level 3 reset */
#define linux_EL3RST 47
/** Link number out of range */
#define linux_ELNRNG 48
/** Protocol driver not attached */
#define linux_EUNATCH 49
/** No CSI structure available */
#define linux_ENOCSI 50
/** Level 2 halted */
#define linux_EL2HLT 51
/** Invalid exchange */
#define linux_EBADE 52
/** Invalid request descriptor */
#define linux_EBADR 53
/** Exchange full */
#define linux_EXFULL 54
/** No anode */
#define linux_ENOANO 55
/** Invalid request code */
#define linux_EBADRQC 56
/** Invalid slot */
#define linux_EBADSLT 57
/** Bad font file format */
#define linux_EBFONT 59
/** Device not a stream */
#define linux_ENOSTR 60
/** No data available */
#define linux_ENODATA 61
/** Timer expired */
#define linux_ETIME 62
/** Out of streams resources */
#define linux_ENOSR 63
/** Machine is not on the network */
#define linux_ENONET 64
/** Package not installed */
#define linux_ENOPKG 65
/** Object is remote */
#define linux_EREMOTE 66
/** Link has been severed */
#define linux_ENOLINK 67
/** Advertise error */
#define linux_EADV 68
/** Srmount error */
#define linux_ESRMNT 69
/** Communication error on send */
#define linux_ECOMM 70
/** Protocol error */
#define linux_EPROTO 71
/** Multihop attempted */
#define linux_EMULTIHOP 72
/** RFS specific error */
#define linux_EDOTDOT 73
/** Not a data message */
#define linux_EBADMSG 74
/** Value too large for defined data type */
#define linux_EOVERFLOW 75
/** Name not unique on network */
#define linux_ENOTUNIQ 76
/** File descriptor in bad state */
#define linux_EBADFD 77
/** Remote address changed */
#define linux_EREMCHG 78
/** Can not access a needed shared library */
#define linux_ELIBACC 79
/** Accessing a corrupted shared library */
#define linux_ELIBBAD 80
/** .lib section in a.out corrupted */
#define linux_ELIBSCN 81
/** Attempting to link in too many shared libraries */
#define linux_ELIBMAX 82
/** Cannot exec a shared library directly */
#define linux_ELIBEXEC 83
/** Illegal byte sequence */
#define linux_EILSEQ 84
/** Interrupted system call should be restarted */
#define linux_ERESTART 85
/** Streams pipe error */
#define linux_ESTRPIPE 86
/** Too many users */
#define linux_EUSERS 87
/** Socket operation on non-socket */
#define linux_ENOTSOCK 88
/** Destination address required */
#define linux_EDESTADDRREQ 89
/** Message too long */
#define linux_EMSGSIZE 90
/** Protocol wrong type for socket */
#define linux_EPROTOTYPE 91
/** Protocol not available */
#define linux_ENOPROTOOPT 92
/** Protocol not supported */
#define linux_EPROTONOSUPPORT 93
/** Socket type not supported */
#define linux_ESOCKTNOSUPPORT 94
/** Operation not supported on transport endpoint */
#define linux_EOPNOTSUPP 95
/** Protocol family not supported */
#define linux_EPFNOSUPPORT 96
/** Address family not supported by protocol */
#define linux_EAFNOSUPPORT 97
/** Address already in use */
#define linux_EADDRINUSE 98
/** Cannot assign requested address */
#define linux_EADDRNOTAVAIL 99
/** Network is down */
#define linux_ENETDOWN 100
/** Network is unreachable */
#define linux_ENETUNREACH 101
/** Network dropped connection because of reset */
#define linux_ENETRESET 102
/** Software caused connection abort */
#define linux_ECONNABORTED 103
/** Connection reset by peer */
#define linux_ECONNRESET 104
/** No buffer space available */
#define linux_ENOBUFS 105
/** Transport endpoint is already connected */
#define linux_EISCONN 106
/** Transport endpoint is not connected */
#define linux_ENOTCONN 107
/** Cannot send after transport endpoint shutdown */
#define linux_ESHUTDOWN 108
/** Too many references: cannot splice */
#define linux_ETOOMANYREFS 109
/** Connection timed out */
#define linux_ETIMEDOUT 110
/** Connection refused */
#define linux_ECONNREFUSED 111
/** Host is down */
#define linux_EHOSTDOWN 112
/** No route to host */
#define linux_EHOSTUNREACH 113
/** Operation already in progress */
#define linux_EALREADY 114
/** Operation now in progress */
#define linux_EINPROGRESS 115
/** Stale NFS file handle */
#define linux_ESTALE 116
/** Structure needs cleaning */
#define linux_EUCLEAN 117
/** Not a XENIX named type file */
#define linux_ENOTNAM 118
/** No XENIX semaphores available */
#define linux_ENAVAIL 119
/** Is a named type file */
#define linux_EISNAM 120
/** Remote I/O error */
#define linux_EREMOTEIO 121
/** Quota exceeded */
#define linux_EDQUOT 122
/** No medium found */
#define linux_ENOMEDIUM 123
/** Wrong medium type */
#define linux_EMEDIUMTYPE 124
/** Operation Canceled */
#define linux_ECANCELED 125
/** Required key not available */
#define linux_ENOKEY 126
/** Key has expired */
#define linux_EKEYEXPIRED 127
/** Key has been revoked */
#define linux_EKEYREVOKED 128
/** Key was rejected by service */
#define linux_EKEYREJECTED 129
/** Owner died */
#define linux_EOWNERDEAD 130
/** State not recoverable */
#define linux_ENOTRECOVERABLE 131
#endif // !__FENNIX_KERNEL_LINUX_ERRNO_H__