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:
Volume
Read-only file system.
Little FS (lfs)
Directory of lfs
File in readFS or in lfs
Typedefs
-
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 pi_fs_file_t pi_vfs_file_t
-
typedef pi_fs_info_t pi_vfs_info_t
Enums
-
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
-
enumerator PI_VFS_ENTRY_VOLUME = 1
-
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
Functions
-
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
-
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.
-
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_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 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 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.
-
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(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.
-
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.
-
struct pi_vfs_fpv2
- #include <vfs.h>
Flash partition management descriptor.
This structure will be used for store all the pointers of partition management descriptors.
-
struct pi_vfs_entry
- #include <vfs.h>
VFS Mounting descriptor.
This structure contains all the info of vfs mounting point.
Public Members
-
pi_vfs_entry_type_e type
Mounting type.
-
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
-
struct pi_vfs_conf
- #include <vfs.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.
-
uint8_t auto_format
-
struct pi_vfs
- #include <vfs.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_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.
-
pi_vfs_fpv2_t fpv2_ctrl