Skip to content

VFS

TODO

flags on file creation

struct vfs_stat (8 fields) source
§ mode_t mode
§ uint64_t size
§ uint64_t inode

inode number

§ uint64_t atime

access time

§ uint64_t mtime

modification time

§ uint64_t ctime

creation time

§ uint16_t present_mask

what fields here are actually real

struct vfs_dirent (4 fields) source
§ char name[VFS_NAME_MAX]
§ mode_t mode
§ struct vfs_node *node
§ void *dirent_data
struct vfs_ops (23 fields) source
§ enum err (*read)(struct vfs_node *node, void *buf, uint64_t size, uint64_t offset)

read data from file

§ enum err (*write)(struct vfs_node *node, const void *buf, uint64_t size, uint64_t offset)

write data to file

§ enum err (*open)(struct vfs_node *node, uint32_t flags)

open file with flags

§ enum err (*close)(struct vfs_node *node)

close file

§ enum err (*create)(struct vfs_node *parent, const char *name, mode_t mode)

create file with given name

§ enum err (*mknod)(struct vfs_node *parent, const char *name, mode_t mode, uint32_t dev)

make node - special devices

§ enum err (*mount)(struct vfs_node *mountpoint, struct vfs_node *target, const char *name)

mount filesystem at mountpoint

§ enum err (*unmount)(struct vfs_mount *mountpoint)

unmount filesystem at mountpoint

§ enum err (*stat)(struct vfs_node *node, struct vfs_stat *out)

get file metadata

§ enum err (*readdir)(struct vfs_node *node, struct vfs_dirent *out, uint64_t index)

read directory entry at index

§ enum err (*mkdir)(struct vfs_node *parent, const char *name, mode_t mode)

create directory

§ enum err (*rmdir)(struct vfs_node *parent, const char *name)

remove directory

§ enum err (*rename)(struct vfs_node *old_parent, const char *old_name, struct vfs_node *new_parent, const char *new_name)

rename/move file or directory

§ enum err (*truncate)(struct vfs_node *node, uint64_t length)

resize file to given length

§ enum err (*chmod)(struct vfs_node *node, mode_t mode)

change file permissions

§ enum err (*chown)(struct vfs_node *node, uid_t uid, gid_t gid)

change file ownership

§ enum err (*utime)(struct vfs_node *node, uint64_t atime, uint64_t mtime)

update access times, unix time

§ enum err (*destroy)(struct vfs_node *node)

deallocate node

§ enum err (*finddir)(struct vfs_node *node, const char *name, struct vfs_dirent *out)

find node by name

struct vfs_mount (6 fields) source
§ struct vfs_node *mount_point

vfs_node of the mountpoint

§ struct vfs_mount *mount_mount

mount representing mountpoint

§ struct vfs_node *root

root of the mounted filesystem

§ const struct vfs_ops *ops

filesystem operation interface

§ char name[256]
§ void *fs_data

optional filesystem driver data

struct vfs_node (14 fields) source
§ enum fs_type fs_type

filesystem type

§ uint64_t open_handles

how many things have this open

§ uint64_t unique_id

exclusively unique ID - one per node

§ uint32_t flags
§ mode_t mode
§ uint64_t size
§ uid_t uid
§ gid_t gid
§ uint64_t mtime
§ uint64_t atime
§ void *fs_data

optional filesystem driver data

§ void *fs_node_data

optional filesystem driver data

§ struct vfs_mount *child_mount

NULL if no child is mounted

§ const struct vfs_ops *ops
enum vfs_node_flags : uint32_t (15 variants) source

clang-format off

§ VFS_NODE_NONE = 0x0000

No flags

§ VFS_NODE_MOUNTPOINT = 0x0001

This node is a mountpoint

§ VFS_NODE_HIDDEN = 0x0004

Should be hidden from directory listings

§ VFS_NODE_DEVICE = 0x0008

This node represents a device (char/block)

§ VFS_NODE_PIPE = 0x0010

Pipe or FIFO

§ VFS_NODE_SOCKET = 0x0020

Unix domain socket

§ VFS_NODE_SYNC = 0x0030
§ VFS_NODE_TEMPORARY = 0x0040

Temporary/in-memory (e.g., tmpfs)

§ VFS_NODE_NOATIME = 0x0080

Access time updates disabled

§ VFS_NODE_APPENDONLY = 0x0100

Only allows appending

§ VFS_NODE_IMMUTABLE = 0x0200

Cannot be modified

§ VFS_NODE_NOFOLLOW = 0x0400

Symlink should not be followed

§ VFS_NODE_IN_USE = 0x0800

Open count > 0 (used internally)

§ VFS_NODE_DIRSYNC = 0x1000
enum vfs_open_opts : uint32_t (12 variants) source
§ VFS_OPEN_READ = 0x01

Open for reading

§ VFS_OPEN_WRITE = 0x02

Open for writing

§ VFS_OPEN_RDWR = VFS_OPEN_READ | VFS_OPEN_WRITE
§ VFS_OPEN_APPEND = 0x04

Writes go to end of file

§ VFS_OPEN_CREAT = 0x08

Create if it doesn’t exist

§ VFS_OPEN_TRUNC = 0x10

Truncate to 0 size if it exists

§ VFS_OPEN_EXCL = 0x20

Fail if file exists (with CREAT)

§ VFS_OPEN_DIR = 0x40

Must be a directory

§ VFS_OPEN_NONBLOCK = 0x100

Non-blocking I/O (device nodes/pipes)

§ VFS_OPEN_SYNC = 0x200

Synchronous writes

§ VFS_OPEN_NOATIME = 0x400

Don’t update access time

void vfs_node_print(const struct vfs_node *node)
source
enum err vfs_mount(
    struct vfs_node *mountpoint,
    struct vfs_node *target,
    const char *name
)
source
enum err vfs_unmount(struct vfs_mount *mountpoint)
source
struct vfs_node * vfs_finddir(
    struct vfs_node *node,
    const char *fname
)
source
void vfs_clear_mounts(void)
source
#define VFS_NAME_MAX 256
source

this because of ext2

#define VFS_MODE_FILE 0x8000U
source

mode stuff

1000 << 12

#define VFS_MODE_DIR 0x4000U
source

0100 << 12

#define VFS_MODE_SYMLINK 0xA000U
source

1010 << 12

#define VFS_MODE_CHARDEV 0x2000U
source

0010 << 12

#define VFS_MODE_BLOCKDEV 0x6000U
source

0110 << 12

#define VFS_MODE_PIPE 0x1000U
source

0001 << 12

#define VFS_MODE_SOCKET 0xC000U
source

1100 << 12

#define VFS_MODE_O_READ 0x0100U
source
0400 (bit 8)
#define VFS_MODE_O_WRITE 0x0080U
source
0200 (bit 7)
#define VFS_MODE_O_EXEC 0x0040U
source
0100 (bit 6)
#define VFS_MODE_G_READ 0x0020U
source
0040 (bit 5)
#define VFS_MODE_G_WRITE 0x0010U
source
0020 (bit 4)
#define VFS_MODE_G_EXEC 0x0008U
source
0010 (bit 3)
#define VFS_MODE_R_READ 0x0004U
source
0004 (bit 2)
#define VFS_MODE_R_WRITE 0x0002U
source
0002 (bit 1)
#define VFS_MODE_R_EXEC 0x0001U
source
0001 (bit 0)
#define VFS_MODE_TYPE_MASK 0xF000U
source