Skip to content

File syn_vfs.h

FileList > src > syntropic > storage > syn_vfs.h

Go to the source code of this file

Virtual File System (VFS) abstraction layer.

  • #include "../common/syn_defs.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_VfsDir
Open directory descriptor.
struct SYN_VfsDirEnt
Directory entry returned by syn_vfs_readdir() .
struct SYN_VfsFile
Open file descriptor.
struct SYN_VfsMount
Mount point binding a path prefix to a filesystem.
struct SYN_VfsOps
VFS operations structure. Implement these for your filesystem (e.g. LittleFS).

Public Functions

Type Name
int syn_vfs_close (int fd)
Close an open file descriptor.
int syn_vfs_closedir (int dd)
Close an open directory descriptor.
void syn_vfs_init (void)
Initialize the VFS registry. Clears all mounts and descriptors.
int syn_vfs_mkdir (const char * path)
Create a directory.
SYN_Status syn_vfs_mount (const char * prefix, const SYN_VfsOps * ops, void * fs_data)
Mount a filesystem at a path prefix.
int syn_vfs_open (const char * path, int flags)
Open a file.
int syn_vfs_opendir (const char * path)
Open a directory for iteration.
int syn_vfs_read (int fd, void * buf, size_t len)
Read from an open file.
int syn_vfs_readdir (int dd, SYN_VfsDirEnt * ent)
Read the next directory entry.
int syn_vfs_rename (const char * old_path, const char * new_path)
Rename or move a file.
int32_t syn_vfs_seek (int fd, int32_t offset, int whence)
Seek in an open file.
int syn_vfs_stat (const char * path, SYN_VfsDirEnt * ent)
Get status information for a file or directory.
int32_t syn_vfs_tell (int fd)
Get current position in an open file.
int syn_vfs_unlink (const char * path)
Delete a file.
SYN_Status syn_vfs_unmount (const char * prefix)
Unmount a filesystem by path prefix.
int syn_vfs_write (int fd, const void * buf, size_t len)
Write to an open file.

Public Functions Documentation

function syn_vfs_close

Close an open file descriptor.

int syn_vfs_close (
    int fd
) 

Parameters:

Returns:

0 on success, or negative error code.


function syn_vfs_closedir

Close an open directory descriptor.

int syn_vfs_closedir (
    int dd
) 

Parameters:

  • dd Directory descriptor.

Returns:

0 on success, or negative error code.


function syn_vfs_init

Initialize the VFS registry. Clears all mounts and descriptors.

void syn_vfs_init (
    void
) 


function syn_vfs_mkdir

Create a directory.

int syn_vfs_mkdir (
    const char * path
) 

Parameters:

  • path Absolute path including mount prefix.

Returns:

0 on success, or negative error code.


function syn_vfs_mount

Mount a filesystem at a path prefix.

SYN_Status syn_vfs_mount (
    const char * prefix,
    const SYN_VfsOps * ops,
    void * fs_data
) 

Parameters:

  • prefix Mount path prefix (e.g. "/flash").
  • ops Filesystem operations vtable.
  • fs_data Opaque filesystem context (e.g. lfs_t *).

Returns:

SYN_OK on success, SYN_ERROR if table is full or prefix exists.


function syn_vfs_open

Open a file.

int syn_vfs_open (
    const char * path,
    int flags
) 

Parameters:

  • path Absolute path including mount prefix.
  • flags Combination of SYN_O_* flags.

Returns:

File descriptor (>= 0) on success, or negative error code.


function syn_vfs_opendir

Open a directory for iteration.

int syn_vfs_opendir (
    const char * path
) 

Parameters:

  • path Absolute path including mount prefix.

Returns:

Directory descriptor (>= 0) on success, or negative error code.


function syn_vfs_read

Read from an open file.

int syn_vfs_read (
    int fd,
    void * buf,
    size_t len
) 

Parameters:

  • fd File descriptor.
  • buf Destination buffer.
  • len Maximum bytes to read.

Returns:

Bytes read on success, or negative error code.


function syn_vfs_readdir

Read the next directory entry.

int syn_vfs_readdir (
    int dd,
    SYN_VfsDirEnt * ent
) 

Parameters:

  • dd Directory descriptor returned by syn_vfs_opendir().
  • ent [out] Filled with the next entry.

Returns:

1 if an entry was read, 0 at end-of-directory, or negative error.


function syn_vfs_rename

Rename or move a file.

int syn_vfs_rename (
    const char * old_path,
    const char * new_path
) 

Parameters:

  • old_path Absolute source path.
  • new_path Absolute destination path.

Returns:

0 on success, or negative error code.


function syn_vfs_seek

Seek in an open file.

int32_t syn_vfs_seek (
    int fd,
    int32_t offset,
    int whence
) 

Parameters:

  • fd File descriptor.
  • offset Byte offset.
  • whence SYN_SEEK_SET, SYN_SEEK_CUR, or SYN_SEEK_END.

Returns:

New absolute offset on success, or negative error code.


function syn_vfs_stat

Get status information for a file or directory.

int syn_vfs_stat (
    const char * path,
    SYN_VfsDirEnt * ent
) 

Parameters:

  • path Absolute path including mount prefix.
  • ent [out] Status information.

Returns:

0 on success, or negative error code.


function syn_vfs_tell

Get current position in an open file.

int32_t syn_vfs_tell (
    int fd
) 

Parameters:

  • fd File descriptor.

Returns:

Current offset, or negative error code.


Delete a file.

int syn_vfs_unlink (
    const char * path
) 

Parameters:

  • path Absolute path including mount prefix.

Returns:

0 on success, or negative error code.


function syn_vfs_unmount

Unmount a filesystem by path prefix.

SYN_Status syn_vfs_unmount (
    const char * prefix
) 

Parameters:

  • prefix Mount path prefix.

Returns:

SYN_OK on success, SYN_ERROR if not found or busy.


function syn_vfs_write

Write to an open file.

int syn_vfs_write (
    int fd,
    const void * buf,
    size_t len
) 

Parameters:

  • fd File descriptor.
  • buf Source buffer.
  • len Bytes to write.

Returns:

Bytes written on success, or negative error code.



The documentation for this class was generated from the following file src/syntropic/storage/syn_vfs.h