18 #ifndef __FENNIX_API_FILESYSTEM_H__
19 #define __FENNIX_API_FILESYSTEM_H__
32 #define S_IFMT32 037777600000
48 #define S_IFMT 0170000
51 #define S_IFWHT 0160000
53 #define S_IFSOCK 0140000
55 #define S_IFLNK 0120000
57 #define S_IFREG 0100000
59 #define S_IFBLK 0060000
61 #define S_IFDIR 0040000
63 #define S_IFCHR 0020000
65 #define S_IFIFO 0010000
103 #define O_TRUNC 01000
104 #define O_APPEND 02000
105 #define O_NOFOLLOW 0400000
106 #define O_CLOEXEC 02000000
108 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
109 #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
110 #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
111 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
112 #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
113 #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
114 #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
116 #define DT_UNKNOWN 0x0
126 #define IFTODT(x) ((x) >> 12 & 0xF)
127 #define DTTOIF(x) ((x) << 12)
129 #define SYMLOOP_MAX 40
132 #define static_assert _Static_assert
138 static_assert(
sizeof(mode_t) == 4,
"mode_t must be 32 bits");
139 static_assert(
sizeof(nlink_t) == 4,
"nlink_t must be 32 bits");
143 static_assert(
sizeof(time_t) == 8,
"time_t must be 64 bits");
144 static_assert(
sizeof(blksize_t) == 8,
"blksize_t must be 64 bits");
145 static_assert(
sizeof(blkcnt_t) == 8,
"blkcnt_t must be 64 bits");
149 static_assert(
sizeof(mode_t) == 2,
"mode_t must be 16 bits");
150 static_assert(
sizeof(nlink_t) == 2,
"nlink_t must be 16 bits");
154 static_assert(
sizeof(time_t) == 4,
"time_t must be 32 bits");
155 static_assert(
sizeof(blksize_t) == 4,
"blksize_t must be 32 bits");
207 dev_t MakeDevice(
int Major,
int Minor)
209 return ((Major & 0xFFF) << 8) |
215 return ((
unsigned int)(
Device) >> 8) & 0xFFF;
223 void SetFileType(mode_t Type)
229 mode_t GetFileType() {
return Mode &
S_IFMT; }
231 bool IsType(mode_t Type) {
return (
Mode &
S_IFMT) == Type; }
233 void SetPermissions(mode_t Permissions)
239 mode_t GetPermissions() {
return Mode & ~
S_IFMT; }
269 void SetDevice(
int Major,
int Minor)
271 this->RawDevice = ((Major & 0xFFF) << 8) |
277 return ((
unsigned int)(this->RawDevice) >> 8) & 0xFFF;
282 return this->RawDevice & 0xFF;
301 #define INODE_MAKEDEV(major, minor) \
302 ((dev_t)(((major & 0xFFF) << 8) | \
305 #define INODE_MAJOR(rdev) \
306 ((int)(((rdev) >> 8) & 0xFFF))
308 #define INODE_MINOR(rdev) \
309 ((int)((rdev) & 0xFF))
319 int (*
Rename)(
struct Inode *Parent,
const char *OldName,
const char *NewName);
325 int (*
Ioctl)(
struct Inode *Node,
unsigned long Request,
void *Argp);
335 #define I_FLAG_ROOT 0x1
336 #define I_FLAG_MOUNTPOINT 0x2
337 #define I_FLAG_CACHE_KEEP 0x4
struct SuperBlockOperations SuperOps
struct InodeOperations Ops
int UnregisterFileSystem(dev_t Device)
dev_t RegisterFileSystem(struct FileSystemInfo *Info, struct Inode *Root)
struct InodeOperations __attribute__((packed))
ssize_t(* ReadDir)(struct Inode *Node, struct kdirent *Buffer, size_t Size, off_t Offset, off_t Entries)
int(* Ioctl)(struct Inode *Node, unsigned long Request, void *Argp)
int(* Truncate)(struct Inode *Node, off_t Size)
ssize_t(* Read)(struct Inode *Node, void *Buffer, size_t Size, off_t Offset)
int(* Remove)(struct Inode *Parent, const char *Name)
int(* MkDir)(struct Inode *Parent, const char *Name, mode_t Mode, struct Inode **Result)
int(* SymLink)(struct Inode *Parent, const char *Name, const char *Target, struct Inode **Result)
int(* Rename)(struct Inode *Parent, const char *OldName, const char *NewName)
int(* Lookup)(struct Inode *Parent, const char *Name, struct Inode **Result)
int(* Open)(struct Inode *Node, int Flags, mode_t Mode)
int(* Close)(struct Inode *Node)
int(* Create)(struct Inode *Parent, const char *Name, mode_t Mode, struct Inode **Result)
ssize_t(* ReadLink)(struct Inode *Node, char *Buffer, size_t Size)
int(* Stat)(struct Inode *Node, struct kstat *Stat)
ssize_t(* Write)(struct Inode *Node, const void *Buffer, size_t Size, off_t Offset)
off_t(* Seek)(struct Inode *Node, off_t Offset)
int(* RmDir)(struct Inode *Parent, const char *Name)
int(* DeleteInode)(struct FileSystemInfo *Info, struct Inode *Node)
int(* AllocateInode)(struct FileSystemInfo *Info, struct Inode **Result)
int(* Synchronize)(struct FileSystemInfo *Info, struct Inode *Node)
int(* Destroy)(struct FileSystemInfo *Info)