HomeCore 0.1.3 (07b5544)
Bare-metal personal computer firmware for Cortex-M
Loading...
Searching...
No Matches
vfs.h File Reference

Virtual file system: device nodes, RAM files and directories, mounted filesystems, paths, and descriptors. More...

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
Include dependency graph for vfs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  vfs_ops_t
 Device operations. More...
 
struct  vfs_node
 Named entry in the VFS namespace. More...
 
struct  vfs_stat_t
 File type and size reported by vfs_stat() and vfs_fstat(). More...
 
struct  vfs_fs_ops_t
 Operations a mounted filesystem provides; every one is required. More...
 

Macros

Limits
#define VFS_SNAPSHOT_CAPACITY   32
 Maximum content size of a snapshot device, in bytes.
 
#define VFS_PATH_CAPACITY   128
 Path buffer size including the terminator; paths hold at most 127 bytes.
 

Functions

Descriptor operations
int vfs_open (const char *name, int flags)
 Open a node and allocate the lowest free descriptor.
 
int vfs_close (int fd)
 Release a descriptor.
 
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_ioctl (int fd, unsigned request, void *arg)
 Forward a control request to a device.
 
int vfs_lseek (int fd, int offset, int whence)
 Move a descriptor's position.
 
vfs_node_t * vfs_fd_node (int fd)
 Get the node behind an open descriptor.
 
int vfs_stat (const char *path, vfs_stat_t *stat)
 Report the type and size of a path.
 
int vfs_fstat (int fd, vfs_stat_t *stat)
 Report the type and size of an open descriptor.
 
Mounted filesystems

A mounted filesystem owns everything below its mount point.

Paths passed to its operations are relative to the mount point and always start with / (the mount point itself is /). Operations return 0 or a byte count on success and -1 with errno set on failure, like the corresponding vfs_* functions. The VFS resolves . and .., rejects reads and writes the access mode forbids, zero-length transfers, and NULL buffers, and allocates the descriptor; the filesystem handles O_CREAT, O_EXCL, O_TRUNC, and O_APPEND. Descriptors on mounted files do not support vfs_ioctl() (ENOTTY).

int vfs_mount (const char *path, const vfs_fs_ops_t *ops, void *fs)
 Attach a filesystem at a new mount point.
 

Nodes and drivers

typedef struct vfs_node vfs_node_t
 VFS node; see struct vfs_node.
 
void vfs_init (void)
 Obsolete initializer; currently does nothing.
 
void vfs_register_node (vfs_node_t *node)
 Add a node to the namespace.
 
vfs_node_t * vfs_find_node (const char *name)
 Look up a node by path.
 

Namespace operations

typedef int(* vfs_directory_visitor_t) (const char *name, bool is_directory, void *context)
 Visitor called for each directory entry by vfs_list().
 
int vfs_resolve_path (const char *base, const char *path, char result[VFS_PATH_CAPACITY])
 Resolve a path against an explicit base directory.
 
int vfs_mkdir (const char *path)
 Create an empty directory.
 
int vfs_rmdir (const char *path)
 Remove an empty directory created by vfs_mkdir().
 
int vfs_unlink (const char *path)
 Remove a file: a RAM file, whose contents are freed, or a file on a mounted filesystem.
 
int vfs_list (const char *path, vfs_directory_visitor_t visitor, void *context)
 Visit the direct children of a directory.
 

Detailed Description

Virtual file system: device nodes, RAM files and directories, mounted filesystems, paths, and descriptors.