swissChili | 8efa492 | 2021-03-02 16:34:49 -0800 | [diff] [blame] | 1 | #include "vfs.h" |
| 2 | |
| 3 | uint fs_read(struct fs_node *node, size_t offset, size_t size, uchar *buffer) |
| 4 | { |
| 5 | if (!node || !node->vtable || !node->vtable->read) |
| 6 | return 0; |
| 7 | |
| 8 | return node->vtable->read(node, offset, size, buffer); |
| 9 | } |
| 10 | |
| 11 | uint fs_write(struct fs_node *node, size_t offset, size_t size, uchar *buffer) |
| 12 | { |
| 13 | if (!node || !node->vtable || !node->vtable->write) |
| 14 | return 0; |
| 15 | |
| 16 | return node->vtable->write(node, offset, size, buffer); |
| 17 | } |
| 18 | |
| 19 | void fs_open(struct fs_node *node) |
| 20 | { |
| 21 | if (!node || !node->vtable || !node->vtable->open) |
| 22 | return; |
| 23 | |
| 24 | node->vtable->open(node); |
| 25 | } |
| 26 | |
| 27 | void fs_close(struct fs_node *node) |
| 28 | { |
| 29 | if (!node || !node->vtable || !node->vtable->close) |
| 30 | return; |
| 31 | |
| 32 | node->vtable->close(node); |
| 33 | } |
| 34 | |
| 35 | struct fs_dirent *fs_readdir(struct fs_node *node, uint index) |
| 36 | { |
| 37 | if (!node || !node->vtable || !node->vtable->readdir || (node->flags & 7) != FS_DIRECTORY) |
| 38 | return NULL; |
| 39 | |
| 40 | return node->vtable->readdir(node, index); |
| 41 | } |
| 42 | |
| 43 | struct fs_node *fs_finddir(struct fs_node *node, char *name) |
| 44 | { |
| 45 | if (!node || !node->vtable || !node->vtable->finddir || (node->flags & 7) != FS_DIRECTORY) |
| 46 | return NULL; |
| 47 | |
| 48 | return node->vtable->finddir(node, name); |
| 49 | } |