Fennix  1.0.0
Full Documentation
Loading...
Searching...
No Matches
fs.h File Reference

Go to the source code of this file.

Data Structures

struct  kstat
 
struct  kdirent
 
struct  Inode
 
struct  InodeOperations
 
struct  SuperBlockOperations
 
struct  FileSystemInfo
 

Macros

#define SEEK_SET   0
 
#define SEEK_CUR   1
 
#define SEEK_END   2
 
#define S_IFMT32   037777600000
 
#define S_IFMT   0170000
 
#define S_IFWHT   0160000
 
#define S_IFSOCK   0140000
 
#define S_IFLNK   0120000
 
#define S_IFREG   0100000
 
#define S_IFBLK   0060000
 
#define S_IFDIR   0040000
 
#define S_IFCHR   0020000
 
#define S_IFIFO   0010000
 
#define S_ISUID   04000
 
#define S_ISGID   02000
 
#define S_ISVTX   01000
 
#define S_IRWXU   0700
 
#define S_IRUSR   0400
 
#define S_IWUSR   0200
 
#define S_IXUSR   0100
 
#define S_IRWXG   0070
 
#define S_IRGRP   0040
 
#define S_IWGRP   0020
 
#define S_IXGRP   0010
 
#define S_IRWXO   0007
 
#define S_IROTH   0004
 
#define S_IWOTH   0002
 
#define S_IXOTH   0001
 
#define S_ISDIR(mode)   (((mode) & S_IFMT) == S_IFDIR)
 
#define S_ISCHR(mode)   (((mode) & S_IFMT) == S_IFCHR)
 
#define S_ISBLK(mode)   (((mode) & S_IFMT) == S_IFBLK)
 
#define S_ISREG(mode)   (((mode) & S_IFMT) == S_IFREG)
 
#define S_ISFIFO(mode)   (((mode) & S_IFMT) == S_IFIFO)
 
#define S_ISLNK(mode)   (((mode) & S_IFMT) == S_IFLNK)
 
#define S_ISSOCK(mode)   (((mode) & S_IFMT) == S_IFSOCK)
 
#define DT_UNKNOWN   0x0
 
#define DT_FIFO   0x1
 
#define DT_CHR   0x2
 
#define DT_DIR   0x4
 
#define DT_BLK   0x6
 
#define DT_REG   0x8
 
#define DT_LNK   0xA
 
#define DT_SOCK   0xC
 
#define DT_WHT   0xE
 
#define IFTODT(x)   ((x) >> 12 & 0xF)
 
#define DTTOIF(x)   ((x) << 12)
 
#define SYMLOOP_MAX   40
 
#define static_assert   _Static_assert
 
#define INODE_MAKEDEV(major, minor)
 
#define INODE_MAJOR(rdev)    ((int)(((rdev) >> 8) & 0xFFF))
 
#define INODE_MINOR(rdev)    ((int)((rdev) & 0xFF))
 
#define I_FLAG_ROOT   0x1
 
#define I_FLAG_MOUNTPOINT   0x2
 
#define I_FLAG_CACHE_KEEP   0x4
 

Functions

struct InodeOperations __attribute__ ((packed))
 
dev_t RegisterFileSystem (struct FileSystemInfo *Info, struct Inode *Root)
 
int UnregisterFileSystem (dev_t Device)
 

Variables

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)
 
int(* Remove )(struct Inode *Parent, const char *Name)
 
int(* Rename )(struct Inode *Parent, const char *OldName, const char *NewName)
 
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(* Truncate )(struct Inode *Node, off_t Size)
 
int(* Open )(struct Inode *Node, int Flags, mode_t Mode)
 
int(* Close )(struct Inode *Node)
 
int(* Ioctl )(struct Inode *Node, unsigned long Request, void *Argp)
 
ssize_t(* ReadDir )(struct Inode *Node, struct kdirent *Buffer, size_t Size, off_t Offset, off_t Entries)
 
int(* MkDir )(struct Inode *Parent, const char *Name, mode_t Mode, struct Inode **Result)
 
int(* RmDir )(struct Inode *Parent, const char *Name)
 
int(* SymLink )(struct Inode *Parent, const char *Name, const char *Target, struct Inode **Result)
 
ssize_t(* ReadLink )(struct Inode *Node, char *Buffer, size_t Size)
 
off_t(* Seek )(struct Inode *Node, off_t Offset)
 
int(* Stat )(struct Inode *Node, struct kstat *Stat)
 
int(* AllocateInode )(struct FileSystemInfo *Info, struct Inode **Result)
 
int(* DeleteInode )(struct FileSystemInfo *Info, struct Inode *Node)
 
int(* Synchronize )(struct FileSystemInfo *Info, struct Inode *Node)
 
int(* Destroy )(struct FileSystemInfo *Info)
 
const char * Name
 
const char * RootName
 
int Flags
 
struct SuperBlockOperations SuperOps
 
struct InodeOperations Ops
 
void * PrivateData
 

Data Structure Documentation

◆ kstat

struct kstat

Definition at line 151 of file fs.h.

Data Fields
time_t AccessTime

Time of last access.

mode_t Attribute

Additional file attributes.

blkcnt_t Blocks

Number of blocks allocated.

blksize_t BlockSize

Optimal I/O block size.

time_t ChangeTime

Time of last status change.

dev_t Device

Device ID of the file.

gid_t GroupID

Group ID of the file's owner.

nlink_t HardLinks

Number of hard links.

ino_t Index

Inode number.

mode_t Mode

File type and mode.

time_t ModifyTime

Time of last modification.

dev_t RawDevice

Device ID for special files.

off_t Size

Size of the file in bytes.

uid_t UserID

User ID of the file's owner.

◆ kdirent

struct kdirent

Definition at line 235 of file fs.h.

Data Fields
ino_t d_ino
char d_name[]
off_t d_off
unsigned short d_reclen
unsigned char d_type

◆ Inode

struct Inode

Definition at line 244 of file fs.h.

Data Fields
dev_t Device
uint32_t Flags
ino_t Index
uintptr_t KernelData
mode_t Mode
off_t Offset
void * PrivateData
dev_t RawDevice

◆ FileSystemInfo

struct FileSystemInfo

Definition at line 359 of file fs.h.

Data Fields
int Flags
const char * Name
struct InodeOperations Ops
void * PrivateData
const char * RootName
struct SuperBlockOperations SuperOps

Macro Definition Documentation

◆ DT_BLK

#define DT_BLK   0x6

Definition at line 110 of file fs.h.

◆ DT_CHR

#define DT_CHR   0x2

Definition at line 108 of file fs.h.

◆ DT_DIR

#define DT_DIR   0x4

Definition at line 109 of file fs.h.

◆ DT_FIFO

#define DT_FIFO   0x1

Definition at line 107 of file fs.h.

◆ DT_LNK

#define DT_LNK   0xA

Definition at line 112 of file fs.h.

◆ DT_REG

#define DT_REG   0x8

Definition at line 111 of file fs.h.

◆ DT_SOCK

#define DT_SOCK   0xC

Definition at line 113 of file fs.h.

◆ DT_UNKNOWN

#define DT_UNKNOWN   0x0

Definition at line 106 of file fs.h.

◆ DT_WHT

#define DT_WHT   0xE

Definition at line 114 of file fs.h.

◆ DTTOIF

#define DTTOIF (   x)    ((x) << 12)

Definition at line 117 of file fs.h.

◆ I_FLAG_CACHE_KEEP

#define I_FLAG_CACHE_KEEP   0x4

Definition at line 327 of file fs.h.

◆ I_FLAG_MOUNTPOINT

#define I_FLAG_MOUNTPOINT   0x2

Definition at line 326 of file fs.h.

◆ I_FLAG_ROOT

#define I_FLAG_ROOT   0x1

Definition at line 325 of file fs.h.

◆ IFTODT

#define IFTODT (   x)    ((x) >> 12 & 0xF)

Definition at line 116 of file fs.h.

◆ INODE_MAJOR

#define INODE_MAJOR (   rdev)     ((int)(((rdev) >> 8) & 0xFFF))

Definition at line 295 of file fs.h.

304{
305 int (*Lookup)(struct Inode *Parent, const char *Name, struct Inode **Result);
306 int (*Create)(struct Inode *Parent, const char *Name, mode_t Mode, struct Inode **Result);
307 int (*Remove)(struct Inode *Parent, const char *Name);
308 int (*Rename)(struct Inode *Parent, const char *OldName, const char *NewName);
309 ssize_t (*Read)(struct Inode *Node, void *Buffer, size_t Size, off_t Offset);
310 ssize_t (*Write)(struct Inode *Node, const void *Buffer, size_t Size, off_t Offset);
311 int (*Truncate)(struct Inode *Node, off_t Size);
312 int (*Open)(struct Inode *Node, int Flags, mode_t Mode);
313 int (*Close)(struct Inode *Node);
314 int (*Ioctl)(struct Inode *Node, unsigned long Request, void *Argp);
315 ssize_t (*ReadDir)(struct Inode *Node, struct kdirent *Buffer, size_t Size, off_t Offset, off_t Entries);
316 int (*MkDir)(struct Inode *Parent, const char *Name, mode_t Mode, struct Inode **Result);
317 int (*RmDir)(struct Inode *Parent, const char *Name);
318 int (*SymLink)(struct Inode *Parent, const char *Name, const char *Target, struct Inode **Result);
319 ssize_t (*ReadLink)(struct Inode *Node, char *Buffer, size_t Size);
320 off_t (*Seek)(struct Inode *Node, off_t Offset);
321 int (*Stat)(struct Inode *Node, struct kstat *Stat);
322} __attribute__((packed));
323
324#define I_FLAG_ROOT 0x1
325#define I_FLAG_MOUNTPOINT 0x2
326#define I_FLAG_CACHE_KEEP 0x4
327
328struct FileSystemInfo;
330{
331 int (*AllocateInode)(struct FileSystemInfo *Info, struct Inode **Result);
332 int (*DeleteInode)(struct FileSystemInfo *Info, struct Inode *Node);
333
344 int (*Synchronize)(struct FileSystemInfo *Info, struct Inode *Node);
345
355 int (*Destroy)(struct FileSystemInfo *Info);
356} __attribute__((packed));
357
358struct FileSystemInfo
359{
360 const char *Name;
361 const char *RootName;
362 int Flags;
364 struct InodeOperations Ops;
365
366 void *PrivateData;
367} __attribute__((packed));
368
369#ifndef __kernel__
370dev_t RegisterFileSystem(struct FileSystemInfo *Info, struct Inode *Root);
371int UnregisterFileSystem(dev_t Device);
372#endif // !__kernel__
373
374#endif // !__FENNIX_API_FILESYSTEM_H__
int(* Close)(struct Inode *Node)
Definition fs.h:8
ssize_t(* ReadLink)(struct Inode *Node, char *Buffer, size_t Size)
Definition fs.h:14
ssize_t(* ReadDir)(struct Inode *Node, struct kdirent *Buffer, size_t Size, off_t Offset, off_t Entries)
Definition fs.h:10
int(* Ioctl)(struct Inode *Node, unsigned long Request, void *Argp)
Definition fs.h:9
struct SuperBlockOperations SuperOps
Definition fs.h:364
struct InodeOperations Ops
Definition fs.h:365
int(* Create)(struct Inode *Parent, const char *Name, mode_t Mode, struct Inode **Result)
Definition fs.h:1
int(* RmDir)(struct Inode *Parent, const char *Name)
Definition fs.h:12
int Flags
Definition fs.h:363
int(* Open)(struct Inode *Node, int Flags, mode_t Mode)
Definition fs.h:7
int(* MkDir)(struct Inode *Parent, const char *Name, mode_t Mode, struct Inode **Result)
Definition fs.h:11
int UnregisterFileSystem(dev_t Device)
const char * Name
Definition fs.h:361
ssize_t(* Write)(struct Inode *Node, const void *Buffer, size_t Size, off_t Offset)
Definition fs.h:5
mode_t Mode
Definition fs.h:248
dev_t RegisterFileSystem(struct FileSystemInfo *Info, struct Inode *Root)
const char * Name
Definition fs.h:0
int(* Rename)(struct Inode *Parent, const char *OldName, const char *NewName)
Definition fs.h:3
int(* Stat)(struct Inode *Node, struct kstat *Stat)
Definition fs.h:16
int(* SymLink)(struct Inode *Parent, const char *Name, const char *Target, struct Inode **Result)
Definition fs.h:13
int(* Truncate)(struct Inode *Node, off_t Size)
Definition fs.h:6
const char * RootName
Definition fs.h:362
int Flags
Definition fs.h:2
ssize_t(* Read)(struct Inode *Node, void *Buffer, size_t Size, off_t Offset)
Definition fs.h:4
int(* Lookup)(struct Inode *Parent, const char *Name, struct Inode **Result)
Definition fs.h:0
off_t Offset
Definition fs.h:250
int(* Remove)(struct Inode *Parent, const char *Name)
Definition fs.h:2
off_t(* Seek)(struct Inode *Node, off_t Offset)
Definition fs.h:15
void * PrivateData
Definition fs.h:367
Definition fs.h:152
Definition fs.h:245
Definition fs.h:236
int(* DeleteInode)(struct FileSystemInfo *Info, struct Inode *Node)
Definition fs.h:333
int(* AllocateInode)(struct FileSystemInfo *Info, struct Inode **Result)
Definition fs.h:332
int(* Synchronize)(struct FileSystemInfo *Info, struct Inode *Node)
Definition fs.h:345
int(* Destroy)(struct FileSystemInfo *Info)
Definition fs.h:356

◆ INODE_MAKEDEV

#define INODE_MAKEDEV (   major,
  minor 
)
Value:
((dev_t)(((major & 0xFFF) << 8) | \
(minor & 0xFF)))

Definition at line 291 of file fs.h.

◆ INODE_MINOR

#define INODE_MINOR (   rdev)     ((int)((rdev) & 0xFF))

Definition at line 298 of file fs.h.

◆ S_IFBLK

#define S_IFBLK   0060000

Definition at line 59 of file fs.h.

◆ S_IFCHR

#define S_IFCHR   0020000

Definition at line 63 of file fs.h.

◆ S_IFDIR

#define S_IFDIR   0040000

Definition at line 61 of file fs.h.

◆ S_IFIFO

#define S_IFIFO   0010000

Definition at line 65 of file fs.h.

◆ S_IFLNK

#define S_IFLNK   0120000

Definition at line 55 of file fs.h.

◆ S_IFMT

#define S_IFMT   0170000

File type mask.

This mask is used to extract the file type from the mode field of a stat structure.

Doing bitwise AND with this mask will return the file type. Example: st_mode & S_IFMT

Doing bitwise negation and AND with this mask will return the permissions. Example: st_mode & ~S_IFMT

Definition at line 48 of file fs.h.

◆ S_IFMT32

#define S_IFMT32   037777600000

File type mask for the upper 32 bits of mode_t.

Note
Maybe it will be used in the future.

Definition at line 32 of file fs.h.

◆ S_IFREG

#define S_IFREG   0100000

Definition at line 57 of file fs.h.

◆ S_IFSOCK

#define S_IFSOCK   0140000

Definition at line 53 of file fs.h.

◆ S_IFWHT

#define S_IFWHT   0160000

Definition at line 51 of file fs.h.

◆ S_IRGRP

#define S_IRGRP   0040

Group: R

Definition at line 83 of file fs.h.

◆ S_IROTH

#define S_IROTH   0004

Other: R

Definition at line 92 of file fs.h.

◆ S_IRUSR

#define S_IRUSR   0400

Owner: R

Definition at line 74 of file fs.h.

◆ S_IRWXG

#define S_IRWXG   0070

Group: RWX

Definition at line 81 of file fs.h.

◆ S_IRWXO

#define S_IRWXO   0007

Other: RWX

Definition at line 90 of file fs.h.

◆ S_IRWXU

#define S_IRWXU   0700

Owner: RWX

Definition at line 72 of file fs.h.

◆ S_ISBLK

#define S_ISBLK (   mode)    (((mode) & S_IFMT) == S_IFBLK)

Definition at line 100 of file fs.h.

◆ S_ISCHR

#define S_ISCHR (   mode)    (((mode) & S_IFMT) == S_IFCHR)

Definition at line 99 of file fs.h.

◆ S_ISDIR

#define S_ISDIR (   mode)    (((mode) & S_IFMT) == S_IFDIR)

Definition at line 98 of file fs.h.

◆ S_ISFIFO

#define S_ISFIFO (   mode)    (((mode) & S_IFMT) == S_IFIFO)

Definition at line 102 of file fs.h.

◆ S_ISGID

#define S_ISGID   02000

Definition at line 68 of file fs.h.

◆ S_ISLNK

#define S_ISLNK (   mode)    (((mode) & S_IFMT) == S_IFLNK)

Definition at line 103 of file fs.h.

◆ S_ISREG

#define S_ISREG (   mode)    (((mode) & S_IFMT) == S_IFREG)

Definition at line 101 of file fs.h.

◆ S_ISSOCK

#define S_ISSOCK (   mode)    (((mode) & S_IFMT) == S_IFSOCK)

Definition at line 104 of file fs.h.

◆ S_ISUID

#define S_ISUID   04000

Definition at line 67 of file fs.h.

◆ S_ISVTX

#define S_ISVTX   01000

Definition at line 69 of file fs.h.

◆ S_IWGRP

#define S_IWGRP   0020

Group: W

Definition at line 85 of file fs.h.

◆ S_IWOTH

#define S_IWOTH   0002

Other: W

Definition at line 94 of file fs.h.

◆ S_IWUSR

#define S_IWUSR   0200

Owner: W

Definition at line 76 of file fs.h.

◆ S_IXGRP

#define S_IXGRP   0010

Group: X

Definition at line 87 of file fs.h.

◆ S_IXOTH

#define S_IXOTH   0001

Other: X

Definition at line 96 of file fs.h.

◆ S_IXUSR

#define S_IXUSR   0100

Owner: X

Definition at line 78 of file fs.h.

◆ SEEK_CUR

#define SEEK_CUR   1

Definition at line 24 of file fs.h.

◆ SEEK_END

#define SEEK_END   2

Definition at line 25 of file fs.h.

◆ SEEK_SET

#define SEEK_SET   0

Definition at line 23 of file fs.h.

◆ static_assert

#define static_assert   _Static_assert

Definition at line 122 of file fs.h.

◆ SYMLOOP_MAX

#define SYMLOOP_MAX   40

Definition at line 119 of file fs.h.

Function Documentation

◆ __attribute__()

struct FileSystemInfo __attribute__ ( (packed)  )

◆ RegisterFileSystem()

dev_t RegisterFileSystem ( struct FileSystemInfo Info,
struct Inode Root 
)

◆ UnregisterFileSystem()

int UnregisterFileSystem ( dev_t  Device)

Variable Documentation

◆ AllocateInode

int(* AllocateInode) (struct FileSystemInfo *Info, struct Inode **Result) ( struct FileSystemInfo Info,
struct Inode **  Result 
)

Definition at line 0 of file fs.h.

◆ Close

int(* Close) (struct Inode *Node) ( struct Inode Node)

Definition at line 8 of file fs.h.

◆ Create

int(* Create) (struct Inode *Parent, const char *Name, mode_t Mode, struct Inode **Result) ( struct Inode Parent,
const char *  Name,
mode_t  Mode,
struct Inode **  Result 
)

Definition at line 1 of file fs.h.

◆ DeleteInode

int(* DeleteInode) (struct FileSystemInfo *Info, struct Inode *Node) ( struct FileSystemInfo Info,
struct Inode Node 
)

Definition at line 1 of file fs.h.

◆ Destroy

int(* Destroy) (struct FileSystemInfo *Info) ( struct FileSystemInfo Info)

Destroy the filesystem.

Unregister the filesystem and free all resources.

Parameters
InfoFilesystem to destroy.
Returns
Zero on success, otherwise an error code.

Definition at line 24 of file fs.h.

◆ Flags

int Flags

Definition at line 2 of file fs.h.

◆ Ioctl

int(* Ioctl) (struct Inode *Node, unsigned long Request, void *Argp) ( struct Inode Node,
unsigned long  Request,
void *  Argp 
)

Definition at line 9 of file fs.h.

◆ Lookup

int(* Lookup) (struct Inode *Parent, const char *Name, struct Inode **Result) ( struct Inode Parent,
const char *  Name,
struct Inode **  Result 
)

Definition at line 0 of file fs.h.

◆ MkDir

int(* MkDir) (struct Inode *Parent, const char *Name, mode_t Mode, struct Inode **Result) ( struct Inode Parent,
const char *  Name,
mode_t  Mode,
struct Inode **  Result 
)

Definition at line 11 of file fs.h.

◆ Name

const char* Name

Definition at line 0 of file fs.h.

◆ Open

int(* Open) (struct Inode *Node, int Flags, mode_t Mode) ( struct Inode Node,
int  Flags,
mode_t  Mode 
)

Definition at line 7 of file fs.h.

◆ Ops

struct InodeOperations Ops

Definition at line 4 of file fs.h.

◆ PrivateData

void* PrivateData

Definition at line 6 of file fs.h.

◆ Read

ssize_t(* Read) (struct Inode *Node, void *Buffer, size_t Size, off_t Offset) ( struct Inode Node,
void *  Buffer,
size_t  Size,
off_t  Offset 
)

Definition at line 4 of file fs.h.

◆ ReadDir

ssize_t(* ReadDir) (struct Inode *Node, struct kdirent *Buffer, size_t Size, off_t Offset, off_t Entries) ( struct Inode Node,
struct kdirent Buffer,
size_t  Size,
off_t  Offset,
off_t  Entries 
)

Definition at line 10 of file fs.h.

◆ ReadLink

ssize_t(* ReadLink) (struct Inode *Node, char *Buffer, size_t Size) ( struct Inode Node,
char *  Buffer,
size_t  Size 
)

Definition at line 14 of file fs.h.

◆ Remove

int(* Remove) (struct Inode *Parent, const char *Name) ( struct Inode Parent,
const char *  Name 
)

Definition at line 2 of file fs.h.

◆ Rename

int(* Rename) (struct Inode *Parent, const char *OldName, const char *NewName) ( struct Inode Parent,
const char *  OldName,
const char *  NewName 
)

Definition at line 3 of file fs.h.

◆ RmDir

int(* RmDir) (struct Inode *Parent, const char *Name) ( struct Inode Parent,
const char *  Name 
)

Definition at line 12 of file fs.h.

◆ RootName

const char* RootName

Definition at line 1 of file fs.h.

◆ Seek

off_t(* Seek) (struct Inode *Node, off_t Offset) ( struct Inode Node,
off_t  Offset 
)

Definition at line 15 of file fs.h.

◆ Stat

int(* Stat) (struct Inode *Node, struct kstat *Stat) ( struct Inode Node,
struct kstat Stat 
)

Definition at line 16 of file fs.h.

◆ SuperOps

struct SuperBlockOperations SuperOps

Definition at line 3 of file fs.h.

◆ SymLink

int(* SymLink) (struct Inode *Parent, const char *Name, const char *Target, struct Inode **Result) ( struct Inode Parent,
const char *  Name,
const char *  Target,
struct Inode **  Result 
)

Definition at line 13 of file fs.h.

◆ Synchronize

int(* Synchronize) (struct FileSystemInfo *Info, struct Inode *Node) ( struct FileSystemInfo Info,
struct Inode Node 
)

Synchronize the filesystem.

Write all pending changes to the disk.

Parameters
InfoInode to synchronize. If NULL, synchronize all inodes.
NodeInode to synchronize.
Returns
Zero on success, otherwise an error code.

Definition at line 13 of file fs.h.

◆ Truncate

int(* Truncate) (struct Inode *Node, off_t Size) ( struct Inode Node,
off_t  Size 
)

Definition at line 6 of file fs.h.

◆ Write

ssize_t(* Write) (struct Inode *Node, const void *Buffer, size_t Size, off_t Offset) ( struct Inode Node,
const void *  Buffer,
size_t  Size,
off_t  Offset 
)

Definition at line 5 of file fs.h.