From 8ebf44dca970f200aabdbdeb8afda6a60df07da6 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Wed, 1 Apr 2026 18:57:59 +0100 Subject: [PATCH] libfs: add support for special files not backed by a filesystem --- lib/libfs/file.c | 5 +++++ lib/libfs/include/fs/file.h | 1 + lib/libfs/interface/seek.c | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/libfs/file.c b/lib/libfs/file.c index 9c927c5..3bb36de 100644 --- a/lib/libfs/file.c +++ b/lib/libfs/file.c @@ -1,5 +1,10 @@ #include "file.h" +void fs_file_set_ops(struct fs_file *f, const struct fs_file_ops *ops) +{ + f->f_ops = ops; +} + struct fs_inode *fs_file_get_inode(const struct fs_file *f) { return f->f_inode; diff --git a/lib/libfs/include/fs/file.h b/lib/libfs/include/fs/file.h index b28ed8c..4d796d8 100644 --- a/lib/libfs/include/fs/file.h +++ b/lib/libfs/include/fs/file.h @@ -23,6 +23,7 @@ struct fs_file_ops { *f_readdir)(struct fs_file *, struct xpc_buffer *, off_t *); }; +extern void fs_file_set_ops(struct fs_file *f, const struct fs_file_ops *ops); extern struct fs_inode *fs_file_get_inode(const struct fs_file *f); extern size_t fs_file_get_cursor(const struct fs_file *f); extern enum fs_status fs_file_read( diff --git a/lib/libfs/interface/seek.c b/lib/libfs/interface/seek.c index bc494f6..fe26af4 100644 --- a/lib/libfs/interface/seek.c +++ b/lib/libfs/interface/seek.c @@ -39,7 +39,7 @@ extern kern_status_t fs_msg_seek( return KERN_OK; } - if (new_offset > f->f_inode->i_size) { + if (f->f_inode && new_offset > f->f_inode->i_size) { *out_err = EINVAL; return KERN_OK; }