vfs: Add devtmpfs + memfiles

This commit is contained in:
2026-10-25 18:45:38 +01:00
parent d14f895288
commit c0767b4631
7 changed files with 300 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: ISC
#pragma once
#include <zinnia/errno.h>
#include <zinnia/initgraph.h>
#include <zinnia/refcount.h>
#include <zinnia/types.h>
#include <zinnia/vfs.h>
#include <stdint.h>
static inline dev_t dev_make(uint32_t major, uint32_t minor) {
return (minor & 0xFF) | ((major & 0xFFF) << 8) | ((dev_t)(minor & ~0xFFU) << 12) | ((dev_t)(major & ~0xFFFU) << 32);
}
struct chardev;
struct chardev_ops {
errno_t (*open)(struct chardev* dev, struct vfs_file* file);
void (*destroy)(struct chardev* dev);
};
struct chardev {
struct refcount rc;
const struct chardev_ops* ops;
const struct vfs_file_ops* file_ops;
dev_t dev;
};
void chardev_init(
struct chardev* dev,
const struct chardev_ops* ops,
const struct vfs_file_ops* file_ops,
uint32_t major,
uint32_t minor
);
void chardev_ref(struct chardev* dev);
void chardev_unref(struct chardev* dev);
struct vfs_path devtmpfs_root();
errno_t devtmpfs_add_chardev(const char* name, struct chardev* dev, mode_t mode);
errno_t devtmpfs_mkdir(const char* name, mode_t mode);
errno_t devtmpfs_remove(const char* name);
errno_t devtmpfs_symlink(const char* name, const char* target);
INIT_EXTERN(devtmpfs_stage);