57 #include <sys/types.h>  
   65 #ifdef MODULE_NANOCOAP_FS 
   66 #include "net/sock/config.h" 
   74 #define restrict __restrict__ 
   84 #define MAX7(a, b, c, d, e, f, g) MAX(MAX(MAX(MAX(MAX((a), (b)), MAX((c), (d))), (e)), (f)), (g)) 
   91 #ifdef MODULE_FATFS_VFS 
   95 #    define _FATFS_FILE_CACHE              (0) 
   97 #    define _FATFS_FILE_CACHE              FF_MAX_SS 
  101 #    if (__SIZEOF_POINTER__ == 8) 
  102 #      define _FATFS_FILE_SEEK_PTR         (8) 
  104 #      define _FATFS_FILE_SEEK_PTR         (4) 
  107 #    define _FATFS_FILE_SEEK_PTR           (0) 
  111 #    define _FATFS_FILE_EXFAT              (48) 
  112 #    define _FATFS_DIR_EXFAT               (32) 
  114 #    define _FATFS_FILE_EXFAT              (0) 
  115 #    define _FATFS_DIR_EXFAT               (0) 
  119 #    if (__SIZEOF_POINTER__ == 8) 
  120 #      define _FATFS_DIR_LFN               (8) 
  122 #      define _FATFS_DIR_LFN               (4) 
  125 #    define _FATFS_DIR_LFN                 (0) 
  128 #  if (__SIZEOF_POINTER__ == 8) 
  129 #    define FATFS_VFS_DIR_BUFFER_SIZE      (64 + _FATFS_DIR_LFN + _FATFS_DIR_EXFAT) 
  130 #    define FATFS_VFS_FILE_BUFFER_SIZE     (64 + VFS_NAME_MAX + _FATFS_FILE_CACHE + \ 
  131                                            _FATFS_FILE_SEEK_PTR + _FATFS_FILE_EXFAT) 
  133 #    define FATFS_VFS_DIR_BUFFER_SIZE      (44 + _FATFS_DIR_LFN + _FATFS_DIR_EXFAT) 
  134 #    define FATFS_VFS_FILE_BUFFER_SIZE     (44 + VFS_NAME_MAX + _FATFS_FILE_CACHE + \ 
  135                                            _FATFS_FILE_SEEK_PTR + _FATFS_FILE_EXFAT) 
  138 #  define FATFS_VFS_DIR_BUFFER_SIZE        (1) 
  139 #  define FATFS_VFS_FILE_BUFFER_SIZE       (1) 
  147 #ifdef MODULE_LITTLEFS 
  148 #  if (__SIZEOF_POINTER__ == 8) 
  149 #    define LITTLEFS_VFS_DIR_BUFFER_SIZE   (48) 
  150 #    define LITTLEFS_VFS_FILE_BUFFER_SIZE  (72) 
  152 #    define LITTLEFS_VFS_DIR_BUFFER_SIZE   (44) 
  153 #    define LITTLEFS_VFS_FILE_BUFFER_SIZE  (56) 
  156 #  define LITTLEFS_VFS_DIR_BUFFER_SIZE     (1) 
  157 #  define LITTLEFS_VFS_FILE_BUFFER_SIZE    (1) 
  165 #ifdef MODULE_LITTLEFS2 
  166 #  if (__SIZEOF_POINTER__ == 8) 
  167 #    define LITTLEFS2_VFS_DIR_BUFFER_SIZE  (56) 
  168 #    define LITTLEFS2_VFS_FILE_BUFFER_SIZE (104) 
  170 #    define LITTLEFS2_VFS_DIR_BUFFER_SIZE  (52) 
  171 #    define LITTLEFS2_VFS_FILE_BUFFER_SIZE (84) 
  174 #  define LITTLEFS2_VFS_DIR_BUFFER_SIZE    (1) 
  175 #  define LITTLEFS2_VFS_FILE_BUFFER_SIZE   (1) 
  184 #  define SPIFFS_VFS_DIR_BUFFER_SIZE       (12) 
  185 #  define SPIFFS_VFS_FILE_BUFFER_SIZE      (1) 
  187 #  define SPIFFS_VFS_DIR_BUFFER_SIZE       (1) 
  188 #  define SPIFFS_VFS_FILE_BUFFER_SIZE      (1) 
  196 #if defined(MODULE_LWEXT4) || DOXYGEN 
  197 #  define LWEXT4_VFS_DIR_BUFFER_SIZE       (308)    
  198 #  define LWEXT4_VFS_FILE_BUFFER_SIZE      (32)     
  200 #  define LWEXT4_VFS_DIR_BUFFER_SIZE       (1) 
  201 #  define LWEXT4_VFS_FILE_BUFFER_SIZE      (1) 
  209 #if defined(MODULE_NANOCOAP_FS) || DOXYGEN 
  210 #  define NANOCOAP_FS_VFS_DIR_BUFFER_SIZE  \ 
  211           (4 + CONFIG_SOCK_URLPATH_MAXLEN)  
  212 #  define NANOCOAP_FS_VFS_FILE_BUFFER_SIZE \ 
  213           (4 + CONFIG_SOCK_URLPATH_MAXLEN)  
  215 #  define NANOCOAP_FS_VFS_DIR_BUFFER_SIZE   (1) 
  216 #  define NANOCOAP_FS_VFS_FILE_BUFFER_SIZE  (1) 
  224 #if defined(MODULE_XIPFS) || DOXYGEN 
  225 #  define XIPFS_VFS_DIR_BUFFER_SIZE        (68)  
  226 #  define XIPFS_VFS_FILE_BUFFER_SIZE       (12)  
  228 #  define XIPFS_VFS_DIR_BUFFER_SIZE        (1) 
  229 #  define XIPFS_VFS_FILE_BUFFER_SIZE       (1) 
  233 #ifndef VFS_MAX_OPEN_FILES 
  237 #define VFS_MAX_OPEN_FILES (16) 
  240 #ifndef VFS_DIR_BUFFER_SIZE 
  268 #define VFS_DIR_BUFFER_SIZE MAX7(FATFS_VFS_DIR_BUFFER_SIZE,       \ 
  269                                  LITTLEFS_VFS_DIR_BUFFER_SIZE,    \ 
  270                                  LITTLEFS2_VFS_DIR_BUFFER_SIZE,   \ 
  271                                  SPIFFS_VFS_DIR_BUFFER_SIZE,      \ 
  272                                  LWEXT4_VFS_DIR_BUFFER_SIZE,      \ 
  273                                  NANOCOAP_FS_VFS_DIR_BUFFER_SIZE, \ 
  274                                  XIPFS_VFS_DIR_BUFFER_SIZE        \ 
  278 #ifndef VFS_FILE_BUFFER_SIZE 
  298 #define VFS_FILE_BUFFER_SIZE MAX7(FATFS_VFS_FILE_BUFFER_SIZE,       \ 
  299                                   LITTLEFS_VFS_FILE_BUFFER_SIZE,    \ 
  300                                   LITTLEFS2_VFS_FILE_BUFFER_SIZE,   \ 
  301                                   SPIFFS_VFS_FILE_BUFFER_SIZE,      \ 
  302                                   LWEXT4_VFS_FILE_BUFFER_SIZE,      \ 
  303                                   NANOCOAP_FS_VFS_FILE_BUFFER_SIZE, \ 
  304                                   XIPFS_VFS_FILE_BUFFER_SIZE        \ 
  316 #define VFS_NAME_MAX (31) 
  322 #define VFS_ANY_FD (-1) 
  329 #define VFS_MTD(mtd) { .dev = &mtd.base } 
  344 #define VFS_AUTO_MOUNT(type, mtd, path, idx)        \ 
  345     static type ## _desc_t fs_desc_ ## idx = mtd;   \ 
  347     XFA(vfs_mount_t, vfs_mountpoints_xfa, 0)        \ 
  348     _mount_mtd_ ## idx = {                          \ 
  349         .fs = &type ## _file_system,                \ 
  350         .mount_point = path,                        \ 
  351         .private_data = &fs_desc_ ## idx,           \ 
  384 #define VFS_FS_FLAG_WANT_ABS_PATH   (1 << 0) 
  853 int vfs_open(
const char *name, 
int flags, mode_t mode);
 
  868 ssize_t 
vfs_read(
int fd, 
void *dest, 
size_t count);
 
  897 ssize_t 
vfs_write(
int fd, 
const void *src, 
size_t count);
 
 1107 int vfs_stat(
const char *restrict path, 
struct stat *restrict buf);
 
 1220         const char *restrict path,
 
 1221         struct stat *restrict buf);
 
int16_t kernel_pid_t
Unique process identifier.
 
#define VFS_DIR_BUFFER_SIZE
Size of buffer space in vfs_DIR.
 
int vfs_mount(vfs_mount_t *mountp)
Mount a file system.
 
int vfs_normalize_path(char *buf, const char *path, size_t buflen)
Normalize a path.
 
int vfs_open(const char *name, int flags, mode_t mode)
Open a file.
 
int vfs_statvfs(const char *restrict path, struct statvfs *restrict buf)
Get file system status.
 
ssize_t vfs_write(int fd, const void *src, size_t count)
Write bytes to an open file.
 
int vfs_mkdir(const char *name, mode_t mode)
Create a directory on the file system.
 
int vfs_umount(vfs_mount_t *mountp, bool force)
Unmount a mounted file system.
 
int vfs_close(int fd)
Close an open file.
 
#define VFS_FILE_BUFFER_SIZE
Size of buffer space in vfs_file_t.
 
int vfs_sysop_stat_from_fstat(vfs_mount_t *mountp, const char *restrict path, struct stat *restrict buf)
Implementation of stat using fstat
 
#define VFS_NAME_MAX
Maximum length of the name in a vfs_dirent_t (not including terminating null)
 
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.
 
off_t vfs_lseek(int fd, off_t off, int whence)
Seek to position in file.
 
int vfs_format(vfs_mount_t *mountp)
Format a file system.
 
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 vfs_format_by_path(const char *path)
Format a file system.
 
int vfs_rename(const char *from_path, const char *to_path)
Rename a file.
 
ssize_t vfs_write_iol(int fd, const iolist_t *iolist)
Write bytes from an iolist to an open file.
 
int vfs_stat(const char *restrict path, struct stat *restrict buf)
Get file status.
 
void vfs_bind_stdio(void)
Allocate and bind file descriptors for STDIN, STDERR, and STDOUT.
 
ssize_t vfs_readline(int fd, char *dest, size_t count)
Read a line from an open text file.
 
const vfs_file_t * vfs_file_get(int fd)
Get information about the file for internal purposes.
 
int vfs_unlink(const char *name)
Unlink (delete) a file from a mounted file system.
 
int vfs_fsync(int fd)
Synchronize a file on storage Any pending writes are written out to storage.
 
int vfs_opendir(vfs_DIR *dirp, const char *dirname)
Open a directory for reading with readdir.
 
const vfs_file_ops_t mtd_vfs_ops
MTD driver for VFS.
 
int vfs_dstatvfs(vfs_DIR *dirp, struct statvfs *buf)
Get file system status of the file system containing an open directory.
 
int vfs_rmdir(const char *name)
Remove a directory from the file system.
 
int vfs_fcntl(int fd, int cmd, int arg)
Query/set options on an open file.
 
int vfs_fstat(int fd, struct stat *buf)
Get status of an open file.
 
ssize_t vfs_read(int fd, void *dest, size_t count)
Read bytes from an open file.
 
bool vfs_iterate_mount_dirs(vfs_DIR *dir)
Iterate through all mounted file systems by their root directories.
 
int vfs_closedir(vfs_DIR *dirp)
Close an open directory.
 
int vfs_fstatvfs(int fd, struct statvfs *buf)
Get file system status of the file system containing an open file.
 
int vfs_mount_by_path(const char *path)
Mount a file system with a pre-configured mount path.
 
int vfs_unmount_by_path(const char *path, bool force)
Unmount a file system with a pre-configured mount path.
 
iolist scatter / gather IO
 
Scheduler API definition.
 
POSIX compatible sys/statvfs.h definitions.
 
iolist structure definition
 
Internal representation of a file system directory entry.
 
const vfs_dir_ops_t * d_op
Directory operations table.
 
int value
alternatively, you can use private_data as an int
 
vfs_mount_t * mp
Pointer to mount table entry.
 
void * ptr
pointer to private data
 
Operations on open directories.
 
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.
 
int(* opendir)(vfs_DIR *dirp, const char *dirname)
Open a directory for reading with readdir.
 
int(* closedir)(vfs_DIR *dirp)
Close an open directory.
 
User facing directory entry.
 
ino_t d_ino
file serial number, unique for the file system ("inode" in Linux)
 
Operations on open files.
 
int(* fcntl)(vfs_file_t *filp, int cmd, int arg)
Query/set options on an open file.
 
int(* close)(vfs_file_t *filp)
Close an open file.
 
int(* fstat)(vfs_file_t *filp, struct stat *buf)
Get status of an open file.
 
int(* fsync)(vfs_file_t *filp)
Synchronize a file on storage Any pending writes are written out to storage.
 
off_t(* lseek)(vfs_file_t *filp, off_t off, int whence)
Seek to position in file.
 
int(* open)(vfs_file_t *filp, const char *name, int flags, mode_t mode)
Attempt to open a file in the file system at rel_path.
 
ssize_t(* read)(vfs_file_t *filp, void *dest, size_t nbytes)
Read bytes from an open file.
 
ssize_t(* write)(vfs_file_t *filp, const void *src, size_t nbytes)
Write bytes to an open file.
 
Operations on mounted file systems.
 
int(* mount)(vfs_mount_t *mountp)
Perform any extra processing needed after mounting a file system.
 
int(* unlink)(vfs_mount_t *mountp, const char *name)
Unlink (delete) a file from the file system.
 
int(* rename)(vfs_mount_t *mountp, const char *from_path, const char *to_path)
Rename a file.
 
int(* stat)(vfs_mount_t *mountp, const char *restrict path, struct stat *restrict buf)
Get file status.
 
int(* mkdir)(vfs_mount_t *mountp, const char *name, mode_t mode)
Create a directory on the file system.
 
int(* format)(vfs_mount_t *mountp)
Format the file system on the given mount point.
 
int(* rmdir)(vfs_mount_t *mountp, const char *name)
Remove a directory from the file system.
 
int(* umount)(vfs_mount_t *mountp)
Perform the necessary clean up for unmounting a file system.
 
const vfs_file_system_ops_t * fs_op
File system operations table.
 
const vfs_dir_ops_t * d_op
Directory operations table.
 
const vfs_file_ops_t * f_op
File operations table.
 
const uint32_t flags
File system flags.
 
Information about an open file.
 
void * ptr
pointer to private data
 
vfs_mount_t * mp
Pointer to mount table entry.
 
kernel_pid_t pid
PID of the process that opened the file.
 
int value
alternatively, you can use private_data as an int
 
const vfs_file_ops_t * f_op
File operations table.
 
off_t pos
Current position in the file.
 
const vfs_file_system_t * fs
The file system driver for the mount point.
 
clist_node_t list_entry
List entry for the _vfs_mount_list list.
 
size_t mount_point_len
Length of mount_point string (set by vfs_mount)
 
uint16_t open_files
Number of currently open files and directories.
 
void * private_data
File system driver private data, implementation defined.
 
const char * mount_point
Mount point, e.g.