VSF Documented
esp_vfs_fat.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2026 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18/*
19 * esp_vfs_fat.h -- mount/unmount helpers binding a FAT volume stored in an
20 * ESP-IDF partition to a POSIX path prefix.
21 *
22 * Differences from upstream ESP-IDF worth calling out:
23 *
24 * - wl_handle_t is returned as an opaque id (>= 0) for API shape
25 * compatibility. VSF does not implement a wear-levelling layer yet,
26 * so _rw_wl is functionally equivalent to a raw FAT volume directly
27 * on top of the partition. Erase wear is the caller's responsibility.
28 * The handle is accepted by _unmount_rw_wl() for symmetry.
29 *
30 * - The SD-card variants (esp_vfs_fat_sdmmc_*) are intentionally not
31 * provided here; they depend on Stage 4 peripheral drivers.
32 *
33 * Threading: all APIs MUST be invoked from a vsf_thread_t context. The
34 * underlying vk_fs_mount / open / read / write peda sub-calls complete
35 * synchronously on return only when the caller is a thread.
36 */
37
38#ifndef __VSF_ESPIDF_ESP_VFS_FAT_H__
39#define __VSF_ESPIDF_ESP_VFS_FAT_H__
40
41/*============================ INCLUDES ======================================*/
42
43#include "esp_err.h"
44#include "esp_vfs.h"
45
46#include <stdint.h>
47#include <stddef.h>
48#include <stdbool.h>
49
50#ifdef __cplusplus
51extern "C" {
52#endif
53
54/*============================ TYPES =========================================*/
55
56// Opaque wear-levelling handle. Values >= 0 are valid; WL_INVALID_HANDLE
57// (-1) means "no wear levelling bound" and is returned when the caller
58// supplied NULL for the handle output.
60#define WL_INVALID_HANDLE (-1)
61
62// Matches ESP-IDF layout. Fields not used by the VSF backend are still
63// present so that struct initialisers compile unchanged.
71
72/*============================ PROTOTYPES ====================================*/
73
74/*
75 * Mount a FAT volume read/write on top of the partition identified by
76 * partition_label, exposed at base_path (e.g. "/spiflash").
77 *
78 * Parameters
79 * base_path Mount point, e.g. "/spiflash". Must start with '/'.
80 * partition_label Target partition label, as registered in the
81 * vsf_espidf_partition_cfg_t entries table.
82 * mount_config Behavioural knobs. May be NULL for defaults.
83 * wl_handle Output. Receives a non-negative id on success; the
84 * same id must be passed to _unmount_rw_wl().
85 * May be NULL if the caller has no use for it.
86 *
87 * Returns ESP_OK on success, otherwise:
88 * ESP_ERR_INVALID_ARG base_path / partition_label invalid.
89 * ESP_ERR_NOT_FOUND partition_label does not match any entry.
90 * ESP_ERR_NO_MEM out-of-memory for fs info / cache allocation.
91 * ESP_ERR_INVALID_STATE base_path already occupied or mount failed
92 * (and format_if_mount_failed was false).
93 * ESP_FAIL underlying vk_fs_mount returned an error.
94 */
96 const char *base_path,
97 const char *partition_label,
98 const esp_vfs_fat_mount_config_t *mount_config,
99 wl_handle_t *wl_handle);
100
101/* Read-only mount. No format/rewrite is ever attempted. */
103 const char *base_path,
104 const char *partition_label,
105 const esp_vfs_fat_mount_config_t *mount_config);
106
107/* Tear down a mount created by _mount_rw_wl. wl_handle must match the
108 * value returned by the paired mount call (or WL_INVALID_HANDLE if the
109 * caller passed NULL into the mount). */
111 const char *base_path,
112 wl_handle_t wl_handle);
113
114/* Tear down a read-only mount created by _mount_ro. */
116 const char *base_path,
117 const char *partition_label);
118
119/* Format the FAT volume at the given partition, without mounting it.
120 * A subsequent _mount_* call will see a freshly-formatted volume. */
122 const char *base_path,
123 const char *partition_label);
124
125#ifdef __cplusplus
126}
127#endif
128
129#endif // __VSF_ESPIDF_ESP_VFS_FAT_H__
int esp_err_t
Definition esp_err.h:41
esp_err_t esp_vfs_fat_spiflash_format_rw_wl(const char *base_path, const char *partition_label)
Definition esp_vfs_fat_port.c:286
int32_t wl_handle_t
Definition esp_vfs_fat.h:59
esp_err_t esp_vfs_fat_spiflash_unmount_ro(const char *base_path, const char *partition_label)
Definition esp_vfs_fat_port.c:269
esp_err_t esp_vfs_fat_spiflash_unmount_rw_wl(const char *base_path, wl_handle_t wl_handle)
Definition esp_vfs_fat_port.c:251
esp_err_t esp_vfs_fat_spiflash_mount_rw_wl(const char *base_path, const char *partition_label, const esp_vfs_fat_mount_config_t *mount_config, wl_handle_t *wl_handle)
Definition esp_vfs_fat_port.c:221
esp_err_t esp_vfs_fat_spiflash_mount_ro(const char *base_path, const char *partition_label, const esp_vfs_fat_mount_config_t *mount_config)
Definition esp_vfs_fat_port.c:242
int int32_t
Definition stdint.h:8
Definition esp_vfs_fat.h:64
bool format_if_mount_failed
Definition esp_vfs_fat.h:65
size_t allocation_unit_size
Definition esp_vfs_fat.h:67
bool use_one_fat
Definition esp_vfs_fat.h:69
int max_files
Definition esp_vfs_fat.h:66
bool disk_status_check_enable
Definition esp_vfs_fat.h:68
Generated from commit: vsfteam/vsf@015f4d1