Go to the documentation of this file.
63 #include <stdatomic.h>
66 #include <sys/types.h>
76 #define restrict __restrict__
87 #define _MAX(a, b) ((a) > (b) ? (a) : (b))
90 #define MAX4(a, b, c, d) _MAX(_MAX((a), (b)), _MAX((c),(d)))
98 #ifdef MODULE_FATFS_VFS
99 #define FATFS_VFS_DIR_BUFFER_SIZE (44)
100 #define FATFS_VFS_FILE_BUFFER_SIZE (72)
102 #define FATFS_VFS_DIR_BUFFER_SIZE (1)
103 #define FATFS_VFS_FILE_BUFFER_SIZE (1)
111 #ifdef MODULE_LITTLEFS
112 #define LITTLEFS_VFS_DIR_BUFFER_SIZE (44)
113 #define LITTLEFS_VFS_FILE_BUFFER_SIZE (56)
115 #define LITTLEFS_VFS_DIR_BUFFER_SIZE (1)
116 #define LITTLEFS_VFS_FILE_BUFFER_SIZE (1)
124 #ifdef MODULE_LITTLEFS2
125 #define LITTLEFS2_VFS_DIR_BUFFER_SIZE (52)
126 #define LITTLEFS2_VFS_FILE_BUFFER_SIZE (84)
128 #define LITTLEFS2_VFS_DIR_BUFFER_SIZE (1)
129 #define LITTLEFS2_VFS_FILE_BUFFER_SIZE (1)
138 #define SPIFFS_VFS_DIR_BUFFER_SIZE (12)
139 #define SPIFFS_VFS_FILE_BUFFER_SIZE (1)
141 #define SPIFFS_VFS_DIR_BUFFER_SIZE (1)
142 #define SPIFFS_VFS_FILE_BUFFER_SIZE (1)
146 #ifndef VFS_MAX_OPEN_FILES
150 #define VFS_MAX_OPEN_FILES (16)
153 #ifndef VFS_DIR_BUFFER_SIZE
181 #define VFS_DIR_BUFFER_SIZE MAX4(FATFS_VFS_DIR_BUFFER_SIZE, \
182 LITTLEFS_VFS_DIR_BUFFER_SIZE, \
183 LITTLEFS2_VFS_DIR_BUFFER_SIZE, \
184 SPIFFS_VFS_DIR_BUFFER_SIZE \
188 #ifndef VFS_FILE_BUFFER_SIZE
208 #define VFS_FILE_BUFFER_SIZE MAX4(FATFS_VFS_FILE_BUFFER_SIZE, \
209 LITTLEFS_VFS_FILE_BUFFER_SIZE, \
210 LITTLEFS2_VFS_FILE_BUFFER_SIZE,\
211 SPIFFS_VFS_FILE_BUFFER_SIZE \
223 #define VFS_NAME_MAX (31)
229 #define VFS_ANY_FD (-1)
418 int (*
open) (
vfs_file_t *filp,
const char *name,
int flags, mode_t mode,
const char *abs_path);
704 off_t
vfs_lseek(
int fd, off_t off,
int whence);
716 int vfs_open(
const char *name,
int flags, mode_t mode);
728 ssize_t
vfs_read(
int fd,
void *dest,
size_t count);
740 ssize_t
vfs_write(
int fd,
const void *src,
size_t count);
828 int vfs_rename(
const char *from_path,
const char *to_path);
861 int vfs_mkdir(
const char *name, mode_t mode);
884 int vfs_stat(
const char *restrict path,
struct stat *restrict buf);
983 const char *restrict path,
984 struct stat *restrict buf);
int16_t kernel_pid_t
Unique process identifier.
ino_t d_ino
file serial number, unique for the file system ("inode" in Linux)
int vfs_fstat(int fd, struct stat *buf)
Get status of an open file.
vfs_mount_t * mp
Pointer to mount table entry.
const vfs_dir_ops_t * d_op
Directory operations table.
Type with the same alignment and size as atomic_int
ssize_t(* write)(vfs_file_t *filp, const void *src, size_t nbytes)
Write bytes to an open file.
int vfs_rename(const char *from_path, const char *to_path)
Rename a file.
const vfs_mount_t * vfs_iterate_mounts(const vfs_mount_t *cur)
Iterate through all mounted file systems.
int vfs_bind(int fd, int flags, const vfs_file_ops_t *f_op, void *private_data)
Allocate a new file descriptor and give it file operations.
int(* stat)(vfs_mount_t *mountp, const char *restrict path, struct stat *restrict buf)
Get file status.
int vfs_fstatvfs(int fd, struct statvfs *buf)
Get file system status of the file system containing an open file.
int vfs_sysop_stat_from_fstat(vfs_mount_t *mountp, const char *restrict path, struct stat *restrict buf)
Implementation of stat using fstat
kernel_pid_t pid
PID of the process that opened the file.
clist_node_t list_entry
List entry for the _vfs_mount_list list.
int(* mkdir)(vfs_mount_t *mountp, const char *name, mode_t mode)
Create a directory on the file system.
ssize_t vfs_write(int fd, const void *src, size_t count)
Write bytes to an open file.
User facing directory entry.
void * private_data
File system driver private data, implementation defined.
const vfs_file_ops_t * f_op
File operations table.
Scheduler API definition.
int vfs_normalize_path(char *buf, const char *path, size_t buflen)
Normalize a path.
int vfs_mkdir(const char *name, mode_t mode)
Create a directory on the file system.
int vfs_readdir(vfs_DIR *dirp, vfs_dirent_t *entry)
Read a single entry from the open directory dirp and advance the read position by one.
#define VFS_DIR_BUFFER_SIZE
Size of buffer space in vfs_DIR.
POSIX compatible sys/statvfs.h definitions.
void vfs_bind_stdio(void)
Allocate and bind file descriptors for STDIN, STDERR, and STDOUT.
int(* opendir)(vfs_DIR *dirp, const char *dirname, const char *abs_path)
Open a directory for reading with readdir.
int vfs_unlink(const char *name)
Unlink (delete) a file from a mounted file system.
int vfs_close(int fd)
Close an open file.
int(* rename)(vfs_mount_t *mountp, const char *from_path, const char *to_path)
Rename a file.
Information about an open file.
int(* unlink)(vfs_mount_t *mountp, const char *name)
Unlink (delete) a file from the file system.
int vfs_statvfs(const char *restrict path, struct statvfs *restrict buf)
Get file system status.
int(* fstat)(vfs_file_t *filp, struct stat *buf)
Get status of an open file.
const char * mount_point
Mount point, e.g.
int(* readdir)(vfs_DIR *dirp, vfs_dirent_t *entry)
Read a single entry from the open directory dirp and advance the read position by one.
Internal representation of a file system directory entry.
int(* mount)(vfs_mount_t *mountp)
Perform any extra processing needed after mounting a file system.
int vfs_rmdir(const char *name)
Remove a directory from the file system.
const vfs_file_t * vfs_file_get(int fd)
Get information about the file for internal purposes.
void * ptr
pointer to private data
vfs_mount_t * mp
Pointer to mount table entry.
const vfs_file_system_ops_t * fs_op
File system operations table.
int vfs_opendir(vfs_DIR *dirp, const char *dirname)
Open a directory for reading with readdir.
ssize_t(* read)(vfs_file_t *filp, void *dest, size_t nbytes)
Read bytes from an open file.
int(* closedir)(vfs_DIR *dirp)
Close an open directory.
C++ compatibility of default C11 atomics types.
const vfs_file_system_t * fs
The file system driver for the mount point.
int value
alternatively, you can use private_data as an int
const vfs_file_ops_t * f_op
File operations table.
int vfs_stat(const char *restrict path, struct stat *restrict buf)
Get file status.
int(* rmdir)(vfs_mount_t *mountp, const char *name)
Remove a directory from the file system.
int(* open)(vfs_file_t *filp, const char *name, int flags, mode_t mode, const char *abs_path)
Attempt to open a file in the file system at rel_path.
atomic_int open_files
Number of currently open files.
const vfs_dir_ops_t * d_op
Directory operations table.
int vfs_fcntl(int fd, int cmd, int arg)
Query/set options on an open file.
int(* fcntl)(vfs_file_t *filp, int cmd, int arg)
Query/set options on an open file.
void * ptr
pointer to private data
int(* format)(vfs_mount_t *mountp)
Format the file system on the given mount point.
int(* close)(vfs_file_t *filp)
Close an open file.
int vfs_open(const char *name, int flags, mode_t mode)
Open a file.
off_t pos
Current position in the file.
#define VFS_NAME_MAX
Maximum length of the name in a vfs_dirent_t (not including terminating null)
int(* fstatvfs)(vfs_mount_t *mountp, vfs_file_t *filp, struct statvfs *buf)
Get file system status of an open file.
ssize_t vfs_read(int fd, void *dest, size_t count)
Read bytes from an open file.
Operations on open files.
int vfs_closedir(vfs_DIR *dirp)
Close an open directory.
int value
alternatively, you can use private_data as an int
size_t mount_point_len
Length of mount_point string (set by vfs_mount)
int vfs_mount(vfs_mount_t *mountp)
Mount a file system.
off_t(* lseek)(vfs_file_t *filp, off_t off, int whence)
Seek to position in file.
int(* umount)(vfs_mount_t *mountp)
Perform the necessary clean up for unmounting a file system.
int vfs_format(vfs_mount_t *mountp)
Format a file system.
off_t vfs_lseek(int fd, off_t off, int whence)
Seek to position in file.
#define VFS_FILE_BUFFER_SIZE
Size of buffer space in vfs_file_t.
Operations on open directories.
Operations on mounted file systems.
int vfs_umount(vfs_mount_t *mountp)
Unmount a mounted file system.