1.. _file_system_api:
2
3File Systems
4############
5
6Zephyr RTOS Virtual Filesystem Switch (VFS) allows applications to mount multiple
7file systems at different mount points (e.g., ``/fatfs`` and ``/lfs``). The
8mount point data structure contains all the necessary information required
9to instantiate, mount, and operate on a file system. The File system Switch
10decouples the applications from directly accessing an individual file system's
11specific API or internal functions by introducing file system registration
12mechanisms.
13
14In Zephyr, any file system implementation or library can be plugged into or
15pulled out through a file system registration API.  Each file system
16implementation must have a globally unique integer identifier; use
17:c:enumerator:`FS_TYPE_EXTERNAL_BASE` to avoid clashes with in-tree identifiers.
18
19.. code-block:: c
20
21        int fs_register(int type, const struct fs_file_system_t *fs);
22
23        int fs_unregister(int type, const struct fs_file_system_t *fs);
24
25Zephyr RTOS supports multiple instances of a file system by making use of
26the mount point as the disk volume name, which is used by the file system library
27while formatting or mounting a disk.
28
29A file system is declared as:
30
31.. code-block:: c
32
33	static struct fs_mount_t mp = {
34	.type = FS_FATFS,
35	.mnt_point = FATFS_MNTP,
36	.fs_data = &fat_fs,
37	};
38
39where
40
41- ``FS_FATFS`` is the file system type like FATFS or LittleFS.
42- ``FATFS_MNTP`` is the mount point where the file system will be mounted.
43- ``fat_fs`` is the file system data which will be used by fs_mount() API.
44
45
46
47Samples
48*******
49
50Samples for the VFS are mainly supplied in ``samples/subsys/fs``, although various examples of the
51VFS usage are provided as important functionalities in samples for different subsystems.
52Here is the list of samples worth looking at:
53
54- ``samples/subsys/fs/fat_fs`` is an example of FAT file system usage with SDHC media;
55- ``samples/subsys/shell/fs`` is an example of Shell fs subsystem, using internal flash partition
56	formatted to LittleFS;
57- ``samples/subsys/usb/mass/`` example of USB Mass Storage device that uses FAT FS driver with RAM
58	or SPI connected FLASH, or LittleFS in flash, depending on the sample configuration.
59
60API Reference
61*************
62
63.. doxygengroup:: file_system_api
64