lib: fs: add library for implementing a filesystem service

This commit is contained in:
2026-03-06 20:17:23 +00:00
parent c4fd252f86
commit 5658e27445
15 changed files with 1506 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
#ifndef FS_ALLOCATOR_H_
#define FS_ALLOCATOR_H_
#include <stddef.h>
struct fs_allocator {
void *fs_arg;
void *(*fs_alloc)(struct fs_allocator *, size_t);
void *(*fs_calloc)(struct fs_allocator *, size_t, size_t);
void *(*fs_realloc)(struct fs_allocator *, void *, size_t);
void (*fs_free)(struct fs_allocator *, void *);
};
extern void *fs_alloc(struct fs_allocator *alloc, size_t count);
extern void *fs_calloc(struct fs_allocator *alloc, size_t count, size_t sz);
extern void *fs_realloc(struct fs_allocator *alloc, void *p, size_t count);
extern void fs_free(struct fs_allocator *alloc, void *p);
#endif

View File

@@ -0,0 +1,31 @@
#ifndef FS_CONTEXT_H_
#define FS_CONTEXT_H_
#include <rosetta/fs.h>
struct fs_file;
struct fs_context;
struct fs_allocator;
struct fs_superblock;
extern struct fs_context *fs_context_create(
struct fs_allocator *alloc,
struct fs_superblock *sb);
extern void fs_context_destroy(struct fs_context *ctx);
extern struct fs_file *fs_context_open_file(
struct fs_context *ctx,
unsigned long id);
extern void fs_context_close_file(struct fs_context *ctx, struct fs_file *f);
extern struct fs_dentry *fs_context_resolve_path(
struct fs_context *ctx,
const char *path);
extern kern_status_t fs_context_dispatch_msg(
struct fs_context *ctx,
kern_handle_t channel,
struct msg_endpoint *sender,
struct msg_header *hdr);
#endif

View File

@@ -0,0 +1,18 @@
#ifndef FS_DENTRY_H_
#define FS_DENTRY_H_
struct fs_inode;
struct fs_superblock;
struct fs_dentry_ops {
};
struct fs_dentry {
struct fs_inode *d_inode;
struct fs_dentry *d_parent;
struct fs_superblock *d_sb;
const struct fs_dentry_ops *d_ops;
void *d_fsdata;
};
#endif

View File

@@ -0,0 +1,15 @@
#ifndef FS_FILE_H_
#define FS_FILE_H_
#include <mango/types.h>
#include <stddef.h>
struct fs_file;
struct fs_file_ops {
ssize_t (*f_read)(struct fs_file *, void *, size_t);
ssize_t (*f_write)(struct fs_file *, const void *, size_t);
off_t (*f_seek)(struct fs_file *, off_t, int);
};
#endif

View File

@@ -0,0 +1,17 @@
#ifndef FS_INODE_H_
#define FS_INODE_H_
struct fs_inode;
struct fs_dentry;
struct fs_superblock;
struct fs_inode_ops {
int (*i_lookup)(struct fs_inode *, struct fs_dentry *);
};
struct fs_inode {
struct fs_superblock *i_sb;
const struct fs_inode_ops *i_ops;
};
#endif

View File

@@ -0,0 +1,20 @@
#ifndef FS_SUPERBLOCK_H_
#define FS_SUPERBLOCK_H_
struct fs_inode;
struct fs_dentry;
struct fs_superblock;
struct fs_superblock_ops {
struct fs_inode *(*s_alloc_inode)(struct fs_superblock *);
};
struct fs_superblock {
const struct fs_superblock_ops *s_ops;
struct fs_dentry *s_root;
};
extern struct fs_inode *fs_superblock_alloc_inode(struct fs_superblock *sb);
#endif