31#ifndef HOME_CORE_VFS_H
32#define HOME_CORE_VFS_H
34#if defined(__cplusplus)
85#define VFS_SNAPSHOT_CAPACITY 32
87#define VFS_PATH_CAPACITY 128
116 int (*write)(
vfs_node_t *node,
const void *buf,
unsigned len);
135 int (*snapshot)(
vfs_node_t *node,
char *buf,
unsigned capacity);
477 int (*open)(
void *fs,
const char *path,
int flags,
void **file);
479 int (*close)(
void *fs,
void *file);
481 int (*read)(
void *fs,
void *file,
void *buf,
unsigned len);
483 int (*write)(
void *fs,
void *file,
const void *buf,
unsigned len);
485 int (*lseek)(
void *fs,
void *file,
int offset,
int whence);
491 int (*mkdir)(
void *fs,
const char *path);
493 int (*rmdir)(
void *fs,
const char *path);
495 int (*unlink)(
void *fs,
const char *path);
522#if defined(__cplusplus)
int vfs_resolve_path(const char *base, const char *path, char result[VFS_PATH_CAPACITY])
Resolve a path against an explicit base directory.
struct vfs_node vfs_node_t
VFS node; see struct vfs_node.
Definition vfs.h:94
int vfs_stat(const char *path, vfs_stat_t *stat)
Report the type and size of a path.
int(* vfs_directory_visitor_t)(const char *name, bool is_directory, void *context)
Visitor called for each directory entry by vfs_list().
Definition vfs.h:277
void vfs_register_node(vfs_node_t *node)
Add a node to the namespace.
vfs_node_t * vfs_fd_node(int fd)
Get the node behind an open descriptor.
int vfs_fstat(int fd, vfs_stat_t *stat)
Report the type and size of an open descriptor.
int vfs_close(int fd)
Release a descriptor.
int vfs_unlink(const char *path)
Remove a file: a RAM file, whose contents are freed, or a file on a mounted filesystem.
#define VFS_PATH_CAPACITY
Path buffer size including the terminator; paths hold at most 127 bytes.
Definition vfs.h:87
int vfs_rmdir(const char *path)
Remove an empty directory created by vfs_mkdir().
int vfs_lseek(int fd, int offset, int whence)
Move a descriptor's position.
vfs_node_t * vfs_find_node(const char *name)
Look up a node by path.
int vfs_mkdir(const char *path)
Create an empty directory.
int vfs_mount(const char *path, const vfs_fs_ops_t *ops, void *fs)
Attach a filesystem at a new mount point.
int vfs_list(const char *path, vfs_directory_visitor_t visitor, void *context)
Visit the direct children of a directory.
int vfs_read(int fd, void *buf, unsigned len)
Read from a descriptor.
int vfs_write(int fd, const void *buf, unsigned len)
Write to a descriptor.
int vfs_open(const char *name, int flags)
Open a node and allocate the lowest free descriptor.
void vfs_init(void)
Obsolete initializer; currently does nothing.
int vfs_ioctl(int fd, unsigned request, void *arg)
Forward a control request to a device.
Operations a mounted filesystem provides; every one is required.
Definition vfs.h:475
int(* stat)(void *fs, const char *path, vfs_stat_t *stat)
Report a path's type and size; ENOENT if it does not exist.
Definition vfs.h:489
Named entry in the VFS namespace.
Definition vfs.h:145
void * driver_data
Driver-private state.
Definition vfs.h:151
bool is_owned
The VFS allocated the node and frees it on removal.
Definition vfs.h:159
const char * name
Canonical absolute path, such as /dev/uart0.
Definition vfs.h:147
vfs_ops_t ops
Device operations.
Definition vfs.h:149
vfs_node_t * next
Namespace list link, managed by the VFS.
Definition vfs.h:153
bool is_regular
The node is a RAM file managed by the VFS.
Definition vfs.h:157
unsigned size
RAM file length in bytes.
Definition vfs.h:161
bool is_directory
The node is a directory.
Definition vfs.h:155
Device operations.
Definition vfs.h:104
File type and size reported by vfs_stat() and vfs_fstat().
Definition vfs.h:424
bool is_directory
The path is a directory, including a mount point.
Definition vfs.h:426
bool is_regular
The path is a regular file: a RAM file or a file on a mounted filesystem.
Definition vfs.h:428
unsigned size
File length in bytes; 0 for directories and devices.
Definition vfs.h:430