VFS

group VFS

The virtual file-system driver provides support for accessing a Volume/partition/dirctory/file in a flash. The following mounting points are available:

  • Read-only file system.

  • Little FS (lfs)

  • Directory of lfs

  • File in readFS or in lfs

The virtual file-system driver provides support for accessing a Volume/partition/dirctory/file in a flash. The following mounting points are available:

  • Volume

  • Read-only file system.

  • Little FS (lfs)

  • Directory of lfs

  • File in readFS or in lfs

Defines

pi_vfs_remove

Typedefs

typedef enum pi_vfs_fs_entry_type pi_vfs_fs_entry_type_e
typedef struct pi_vfs_fpv2 pi_vfs_fpv2_t
typedef struct pi_vfs_entry pi_vfs_entry_t
typedef struct pi_vfs_conf pi_vfs_conf_t
typedef struct pi_vfs_part pi_vfs_part_t
typedef struct pi_vfs pi_vfs_t
typedef pi_fs_file_t pi_vfs_file_t
typedef pi_fs_info_t pi_vfs_info_t
typedef enum pi_vfs_entry_type pi_vfs_entry_type_e
typedef enum pi_vfs_fs_entry_type pi_vfs_fs_entry_type_e
typedef struct pi_vfs_fpv2 pi_vfs_fpv2_t
typedef struct pi_vfs_entry pi_vfs_entry_t
typedef struct pi_vfs_conf pi_vfs_conf_t
typedef struct pi_vfs pi_vfs_t
typedef pi_fs_file_t pi_vfs_file_t
typedef pi_fs_info_t pi_vfs_info_t

Enums

enum pi_vfs_fs_entry_type

Values:

enumerator PI_FS_READFS = 1

Identifier for read only file system.

enumerator PI_FS_LITTLEFS

Identifier for LittleFS file system.

enumerator PI_FS_HOSTFS

Base identifier for hostFS (TODO).

enumerator PI_FS_RAW

Base identifier for RAW .

enumerator PI_FS_WRITEFS

Base identifier for WriteFS

enumerator PI_FS_READFS = 1

Identifier for read only file system.

enumerator PI_FS_LITTLEFS

Identifier for LittleFS file system.

enumerator PI_FS_HOSTFS

Base identifier for hostFS (TODO).

enumerator PI_FS_RAW

Base identifier for RAW .

enumerator PI_FS_WRITEFS

Base identifier for WriteFS

enum pi_vfs_entry_type

Values:

enumerator PI_VFS_ENTRY_VOLUME = 1

Identifier for a Volume entry

enumerator PI_VFS_ENTRY_PARTITION = 2

Identifier for a partition entry

enumerator PI_VFS_ENTRY_DIR = 3

Identifier for directory entry

enum pi_vfs_fs_entry_type

Values:

enumerator PI_FS_READFS = 1

Identifier for read only file system.

enumerator PI_FS_LITTLEFS

Identifier for LittleFS file system.

enumerator PI_FS_HOSTFS

Base identifier for hostFS (TODO).

enumerator PI_FS_RAW

Base identifier for RAW .

enumerator PI_FS_WRITEFS

Base identifier for WriteFS

enumerator PI_FS_READFS = 1

Identifier for read only file system.

enumerator PI_FS_LITTLEFS

Identifier for LittleFS file system.

enumerator PI_FS_HOSTFS

Base identifier for hostFS (TODO).

enumerator PI_FS_RAW

Base identifier for RAW .

enumerator PI_FS_WRITEFS

Base identifier for WriteFS

Functions

void pi_vfs_conf_init(pi_vfs_conf_t *vfs_conf)

Prepare configuration to mount a virtual FS by PATH.

Parameters:
  • vfs_conf – A pointer to the device configuration.

void pi_vfs_part_init(pi_vfs_part_t *part, const char *path, pi_vfs_part_t *next)

Prepare a vfs partition to be mounted.

Parameters:
  • part – The partition handle to mount in vfs.

  • path – The path of the partition to mount. Path is relative to the volume given when mounting the vfs. It can then contain:

    • partition

    • partition/dir

  • next – The partition to link next.

int32_t pi_vfs_mount(pi_device_t *vfs, const char *vol_name, pi_vfs_part_t *part)

Mount a virtual FS by PATH.

It will mount a volume, a partition (a type of FS or raw), a directory (if supported) according to the PATH and entry type.

Parameters:
  • vfs – A pointer to the device (vfs) to be opend.

  • vol_name – The volume name to mount.

  • part – First partition of the linked-list of partitions to mount.

Returns:

PI_OK if mount is a success PI_FAIL otherwise

int32_t pi_vfs_unmount(pi_device_t *vfs)

Unmount a mounted virtual file-system.

This function can be called to close a mounted virtual file-system once it is not needed anymore, in order to free all allocated resources. Once this function is called, the mounting point is not accessible anymore and must be mounted again before being used.

Parameters:
  • vfs – The device structure of the VFS to unmount.

static inline pi_vfs_file_t *pi_vfs_open(pi_vfs_part_t *part, const char *file, int flags)

Opens a file in the virtual filesystem.

This function opens a file in the specified virtual filesystem.

Parameters:
  • part – The partition handle mounted in a virtual filesystem.

  • file – The name of the file to open.

  • flags – File open flags (refer to pi_fs_open for details).

Returns:

A pointer to the opened file, or NULL on failure.

static inline void pi_vfs_close(pi_vfs_file_t *file)

Closes a file in the virtual filesystem.

This function closes a file that was previously opened.

Parameters:
  • file – The file handle to close.

static inline int32_t pi_vfs_ls(pi_vfs_part_t *part, const char *path)

Lists files in a directory.

This function lists the files in the specified directory.

Parameters:
  • part – The partition handle mounted in a virtual filesystem.

  • path – The path to the directory to list.

Returns:

0 on success, negative value on error.

static inline int32_t pi_vfs_mkdir(pi_vfs_part_t *part, const char *path)

Creates a directory in the virtual filesystem.

This function creates a new directory in the specified path.

Parameters:
  • part – The partition handle mounted in a virtual filesystem.

  • path – The path to the directory to create.

Returns:

0 on success, negative value on error.

static inline int32_t pi_vfs_rm(pi_vfs_part_t *part, const char *path)

Removes a file or directory in the virtual filesystem.

This function removes a file or directory from the filesystem.

Parameters:
  • part – The partition handle mounted in a virtual filesystem.

  • path – The path to the file or directory to remove.

Returns:

0 on success, negative value on error.

static inline pi_vfs_file_t *pi_vfs_dir_open(pi_vfs_part_t *part, const char *path)

Opens a directory in the virtual filesystem.

This function opens a directory in the specified virtual filesystem.

Parameters:
  • part – The partition handle where the directory is into.

  • path – The path to the directory to open.

Returns:

A pointer to the opened directory, or NULL on failure.

static inline void pi_vfs_dir_close(pi_vfs_part_t *part)

Closes a directory in the virtual filesystem.

This function closes a directory that was previously opened.

Parameters:
  • part – The partition handle where the directory is into.

static inline int32_t pi_vfs_dir_read(pi_vfs_part_t *part, pi_vfs_info_t *info)

Reads an entry from a directory.

This function reads the next entry from an open directory.

Parameters:
  • part – The partition handle where the directory is into.

  • info – Pointer to a structure to store the directory entry information.

Returns:

0 on success, negative value on error.

static inline int32_t pi_vfs_write_async(pi_vfs_file_t *file, void *buffer, uint32_t size, pi_evt_t *event)

Writes data to a file asynchronously.

This function writes data to a file asynchronously.

Parameters:
  • file – The file handle.

  • buffer – The data to write.

  • size – The size of the data to write.

  • event – The event to signal when the write is complete.

Returns:

0 on success, negative value on error.

static inline int32_t pi_vfs_write(pi_vfs_file_t *file, void *buffer, uint32_t size)

Writes data to a file.

This function writes data to a file.

Parameters:
  • file – The file handle.

  • buffer – The data to write.

  • size – The size of the data to write.

Returns:

The number of bytes written, or negative value on error.

static inline int32_t pi_vfs_read_async(pi_vfs_file_t *file, void *buffer, uint32_t size, pi_evt_t *event)

Reads data from a file asynchronously.

This function reads data from a file asynchronously.

Parameters:
  • file – The file handle.

  • buffer – The buffer to store the read data.

  • size – The number of bytes to read.

  • event – The event to signal when the read is complete.

Returns:

0 on success, negative value on error.

static inline int32_t pi_vfs_read(pi_vfs_file_t *file, void *buffer, uint32_t size)

Reads data from a file.

This function reads data from a file.

Parameters:
  • file – The file handle.

  • buffer – The buffer to store the read data.

  • size – The number of bytes to read.

Returns:

The number of bytes read, or negative value on error.

void *pi_vfs_mount(pi_device_t *vfs, const char *path)

Mount a virtual FS by PATH.

It will mount a volume, a partition (a type of FS or raw), a directory (if supported) according to the PATH and entry type.

Parameters:
  • vfs – A pointer to the device (vfs) to be opend.

  • path – The path to be mounted in string. path should alwasy start with /volume, then depends on the need it can be:

    • level 1: /volume

    • level 2: /volume/partition

    • level >=3: /volume/partition/dir

Returns:

NULL if there was an error (pi_fpv2_volume_desc_t *) if mount a volume (pi_vfs_t *) if mount a partition (a FS or a RAW partition) (pi_fs_file_t *) if mount a dir

static inline pi_vfs_file_t *pi_vfs_open(pi_vfs_t *vfs, const char *file, int flags)

Opens a file in the virtual filesystem.

This function opens a file in the specified virtual filesystem.

Parameters:
  • vfs – The virtual filesystem handle.

  • file – The name of the file to open.

  • flags – File open flags (refer to pi_fs_open for details).

Returns:

A pointer to the opened file, or NULL on failure.

static inline pi_vfs_file_t *pi_vfs_dir_open(pi_vfs_t *vfs, const char *path)

Opens a directory in the virtual filesystem.

This function opens a directory in the specified virtual filesystem.

Parameters:
  • vfs – The virtual filesystem handle.

  • path – The path to the directory to open.

Returns:

A pointer to the opened directory, or NULL on failure.

static inline void pi_vfs_dir_close(pi_vfs_file_t *dir)

Closes a directory in the virtual filesystem.

This function closes a directory that was previously opened.

Parameters:
  • dir – The directory handle to close.

static inline int32_t pi_vfs_ls(pi_vfs_t *vfs, const char *path)

Lists files in a directory.

This function lists the files in the specified directory.

Parameters:
  • vfs – The virtual filesystem handle.

  • path – The path to the directory to list.

Returns:

0 on success, negative value on error.

static inline int32_t pi_vfs_mkdir(pi_vfs_t *vfs, const char *path)

Creates a directory in the virtual filesystem.

This function creates a new directory in the specified path.

Parameters:
  • vfs – The virtual filesystem handle.

  • path – The path to the directory to create.

Returns:

0 on success, negative value on error.

static inline int32_t pi_vfs_remove(pi_vfs_t *vfs, const char *path)

Removes a file or directory in the virtual filesystem.

This function removes a file or directory from the filesystem.

Parameters:
  • vfs – The virtual filesystem handle.

  • path – The path to the file or directory to remove.

Returns:

0 on success, negative value on error.

static inline int32_t pi_vfs_dir_read(const pi_vfs_file_t *file, pi_vfs_info_t *info)

Reads an entry from a directory.

This function reads the next entry from an open directory.

Parameters:
  • file – The directory file handle.

  • info – Pointer to a structure to store the directory entry information.

Returns:

0 on success, negative value on error.

Variables

pi_device_e fpv2_flash
pi_fpv2_vtable_desc_t *vtable_desc

Volume table descriptor.

pi_fpv2_ptable_desc_t *ptable_desc

Partition table descriptor.

pi_vfs_fs_entry_type_e subtype

Subtype of this partition.

size_t partition_size

Size of partition, NULL if the mounting point is a volume.

uint32_t partition_offset

Partition offset.

uint8_t auto_format

If set, mount will create the FS if it’s not initialized

uint8_t pre_erase

For compatible FS: consider the device has been pre-erased. Ignored otherwise.

uint8_t force_init

For compatible FS: Reinit the partition. Honors pre_erase flag. Ignored for non compatible FS.

uint32_t align

For compatible FS: Define alignment properties. Ignored for non compatible FS.

char *path
struct pi_vfs_part *next
pi_vfs_entry_t entry

Descriptor of mounting point.

pi_device_t *fs

Filesystem mounted via partition.

pi_device_t *fs_flash

Flash used by the partition.

pi_device_e fs_flash_ref
pi_fs_file_t *dir

Dir if mounting point is a dir. Null otherwise.

pi_vfs_fpv2_t fpv2_ctrl

Flash partition management controler.

pi_vfs_part_t *part

Partitions mounted via VFS.

uint8_t part_nb

Nb of partitions mounted.

uint8_t auto_format
uint8_t id
uint8_t pre_erase
uint8_t force_init
uint32_t align
struct pi_vfs_fpv2
#include <vfs-v2.h>

Flash partition management descriptor.

This structure will be used for store all the pointers of partition management descriptors.

Public Members

pi_fpv2_vtable_desc_t *vtable_desc

Volume table descriptor.

pi_fpv2_ptable_desc_t *ptable_desc

Partition table descriptor.

struct pi_vfs_entry
#include <vfs-v2.h>

VFS Mounting descriptor.

This structure contains all the info of vfs mounting point.

Public Members

pi_vfs_fs_entry_type_e subtype

Subtype of this partition.

size_t partition_size

Size of partition, NULL if the mounting point is a volume.

uint32_t partition_offset

Partition offset.

pi_vfs_entry_type_e type

Mounting type.

struct pi_vfs_conf
#include <vfs-v2.h>

VFS descriptor configuration.

Public Members

uint8_t auto_format

If set, mount will create the FS if it’s not initialized

uint8_t pre_erase

For compatible FS: consider the device has been pre-erased. Ignored otherwise.

uint8_t force_init

For compatible FS: Reinit the partition. Honors pre_erase flag. Ignored for non compatible FS.

uint32_t align

For compatible FS: Define alignment properties. Ignored for non compatible FS.

struct pi_vfs_part
#include <vfs-v2.h>

VFS partition descriptor.

Descriptor of a partition to mount in a VFS

Public Members

pi_vfs_entry_t entry

Descriptor of mounting point.

pi_device_t *fs

Filesystem mounted via partition.

pi_device_t *fs_flash

Flash used by the partition.

pi_fs_file_t *dir

Dir if mounting point is a dir. Null otherwise.

struct pi_vfs
#include <vfs-v2.h>

VFS descriptor.

Top descriptor of vfs, which contains all the descriptors for a VFS

Public Members

pi_vfs_fpv2_t fpv2_ctrl

Flash partition management controler.

pi_vfs_part_t *part

Partitions mounted via VFS.

uint8_t part_nb

Nb of partitions mounted.

pi_vfs_entry_t entry

Descriptor of mounting point.

pi_device_t *fs

Filesystem mounted via VFS.

pi_device_t *fs_flash

Flash used by the FS.