|
HomeCore 0.1.3 (07b5544)
Bare-metal personal computer firmware for Cortex-M
|
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. | |
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.
| 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().
| int(* vfs_ops_t::close) (vfs_node_t *node) |
Called by vfs_close(), which returns its result.
The descriptor is released anyway.
| 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.
| 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.
| 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.