Skip to content

File syn_vfs.c

FileList > src > syntropic > storage > syn_vfs.c

Go to the source code of this file

Virtual File System (VFS) abstraction implementation.

  • #include "../util/syn_assert.h"
  • #include "syn_vfs.h"
  • #include <string.h>

Public Static Attributes

Type Name
SYN_VfsDir g_dirs
SYN_VfsFile g_files
size_t g_mount_count = 0
SYN_VfsMount g_mounts

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 Static Functions

Type Name
const SYN_VfsMount * find_mount (const char * path, const char ** rel_path)
Find the mount point for a given path.

Public Static Attributes Documentation

variable g_dirs

SYN_VfsDir g_dirs[SYN_VFS_MAX_OPEN_DIRS];

Open directory handles.


variable g_files

SYN_VfsFile g_files[SYN_VFS_MAX_OPEN_FILES];

Open file handles.


variable g_mount_count

size_t g_mount_count;

Number of active mounts.


variable g_mounts

SYN_VfsMount g_mounts[SYN_VFS_MAX_MOUNTS];

Mount table.


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.


Public Static Functions Documentation

function find_mount

Find the mount point for a given path.

static const SYN_VfsMount * find_mount (
    const char * path,
    const char ** rel_path
) 

Parameters:

  • path Absolute path.
  • rel_path [out] Relative path within the mount.

Returns:

Matching mount, or NULL.



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