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

Device operations. More...

#include <homecore/vfs/vfs.h>

Data Fields

int(* open )(vfs_node_t *node, int flags)
 Called by vfs_open() after a descriptor is reserved.
 
int(* close )(vfs_node_t *node)
 Called by vfs_close(), which returns its result.
 
int(* read )(vfs_node_t *node, void *buf, unsigned len)
 Stream read.
 
int(* write )(vfs_node_t *node, const void *buf, unsigned len)
 Stream write.
 
int(* ioctl )(vfs_node_t *node, unsigned request, void *arg)
 Device-specific control request, forwarded unchanged by vfs_ioctl().
 
int(* lseek )(vfs_node_t *node, int offset, int whence)
 Stream seek, forwarded unchanged by vfs_lseek().
 
int(* snapshot )(vfs_node_t *node, char *buf, unsigned capacity)
 Optional snapshot generated at open.
 

Detailed Description

Device operations.

Every operation is optional; leave unused ones NULL. A missing stream operation makes the matching descriptor call return -1 without setting errno. The VFS implements RAM files itself and ignores these operations for them.

Field Documentation

◆ open

int(* vfs_ops_t::open) (vfs_node_t *node, int flags)

Called by vfs_open() after a descriptor is reserved.

A negative result releases the descriptor and is returned by vfs_open().

◆ close

int(* vfs_ops_t::close) (vfs_node_t *node)

Called by vfs_close(), which returns its result.

The descriptor is released anyway.

◆ read

int(* vfs_ops_t::read) (vfs_node_t *node, void *buf, unsigned len)

Stream read.

Return the byte count, 0 at end of file, or -1 with errno set.

◆ write

int(* vfs_ops_t::write) (vfs_node_t *node, const void *buf, unsigned len)

Stream write.

Return the byte count, or -1 with errno set.

◆ snapshot

int(* vfs_ops_t::snapshot) (vfs_node_t *node, char *buf, unsigned capacity)

Optional snapshot generated at open.

Write at most capacity bytes into buf and return the length, or -1 if the content does not fit. The VFS then handles partial reads, end of file, and seeking independently for each descriptor, and ignores read and lseek. Without a write operation, snapshot nodes can be opened only with O_RDONLY and no creation, truncation, or append flags. With one, they also accept write access, each vfs_write() is forwarded to write, and O_CREAT, O_TRUNC, and O_APPEND have no effect; the snapshot still reflects the state at open. The LED files use this.


The documentation for this struct was generated from the following file: