Chapter 2. API Reference
Paths
Each registered FS has a path prefix associated with it. This prefix can be considered as a "mount point"of this
partition.
In case when mount points are nested, the mount point with the longest matching path prefix is used when opening
the file. For instance, suppose that the following filesystems are registered in VFS:
• FS 1 on /data
• FS 2 on /data/static
Then:
• FS 1 will be used when opening a file called /data/log.txt
• FS 2 will be used when opening a file called /data/static/index.html
• Even if /index.html" does not exist in FS 2, FS 1 will not be searched for /static/index.html.
As a general rule, mount point names must start with the path separator (/) and must contain at least one character
after path separator. However, an empty mount point name is also supported and might be used in cases when an
application needs to provide a"fallback" filesystem or to override VFS functionality altogether. Such filesystem will
be used if no prefix matches the path given.
VFS does not handle dots (.) in path names in any special way. VFS does not treat .. as a reference to the parent
directory. In the above example, using a path /data/static/../log.txt will not result in a call to FS 1 to
open /log.txt. Specific FS drivers (such as FATFS) might handle dots in file names differently.
When opening files, the FS driver receives only relative paths to files. For example:
1. The myfs driver is registered with /data as a path prefix.
2. The application calls fopen("/data/config.json", ...).
3. The VFS component calls myfs_open("/config.json", ...).
4. The myfs driver opens the /config.json file.
VFS does not impose any limit on total file path length, but it does limit the FS path prefix to ESP_VFS_PATH_MAX
characters. Individual FS drivers may have their own filename length limitations.
File descriptors
File descriptors are small positive integers from 0 to FD_SETSIZE - 1, where FD_SETSIZE is defined in newlib'
s sys/types.h. The largest file descriptors (configured by CONFIG_LWIP_MAX_SOCKETS) are reserved for
sockets. The VFS component contains a lookup-table called s_fd_table for mapping global file descriptors to
VFS driver indexes registered in the s_vfs array.
Standard IO streams (stdin, stdout, stderr)
If the menuconfig option UART for console output is not set to None, then stdin, stdout, and stderr
are configured to read from, and write to, a UART. It is possible to use UART0 or UART1 for standard IO. By default,
UART0 is used with 115200 baud rate; TX pin is GPIO1; RX pin is GPIO3. These parameters can be changed in
menuconfig.
Writing to stdout or stderr will send characters to the UART transmit FIFO. Reading from stdin will retrieve
characters from the UART receive FIFO.
By default, VFS uses simple functions for reading from and writing to UART. Writes busy-wait until all data is put
into UART FIFO, and reads are non-blocking, returning only the data present in the FIFO. Due to this non-blocking
read behavior, higher level C library calls, such as fscanf("%d\n", &var);, might not have desired results.
Applications which use the UART driver can instruct VFS to use the driver' s interrupt driven, blocking read and write
functions instead. This can be done using a call to the esp_vfs_dev_uart_use_driver function. It is also
possible to revert to the basic non-blocking functions using a call to esp_vfs_dev_uart_use_nonblocking.
Espressif Systems
771
Submit Document Feedback
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?