1/* @title: TMPFS */
2#pragma once
3#include <stdbool.h>
4#include <stddef.h>
5#include <stdint.h>
6#include <sync/mutex.h>
7#include <types/types.h>
8
9enum tmpfs_type {
10 TMPFS_FILE,
11 TMPFS_DIR,
12 TMPFS_SYMLINK,
13 // ...
14};
15
16struct tmpfs_node {
17 enum tmpfs_type type;
18 char *name;
19
20 void **pages; // array of page pointers
21 uint64_t num_pages; // number of allocated pages
22 uint64_t size; // total file size
23
24 char *symlink_target;
25 mode_t mode;
26 uid_t uid;
27 gid_t gid;
28 uint64_t mtime;
29 uint64_t atime;
30
31 struct tmpfs_node *parent;
32
33 struct tmpfs_node **children;
34 uint64_t child_count;
35 struct mutex lock;
36};
37
38struct tmpfs_fs {
39 struct tmpfs_node *root;
40};
41
42#define TMPFS_PAGE_SIZE 4096
43#define TMPFS_PAGE_SHIFT 12
44#define TMPFS_PAGE_MASK (TMPFS_PAGE_SIZE - 1)
45
46struct vfs_node *tmpfs_mkroot(const char *mount_point);
47