56#include "freertos/FreeRTOS.h"
57#include "freertos/task.h"
58#include "freertos/semphr.h"
61#include "esp_partition.h"
62#include "esp_rom_spiflash.h"
87#if CONFIG_VFS_SUPPORT_DIR
89static const esp_vfs_dir_ops_t s_tarfs_dir = {
100# warning "Dir support is disabled in VFS"
107static const esp_vfs_fs_ops_t s_tarfs_fs = {
118#if CONFIG_VFS_SUPPORT_DIR
141static SemaphoreHandle_t s_lock = NULL;
150 s_lock = xSemaphoreCreateRecursiveMutex();
158 if (s_lock != NULL)
do {
160 }
while (pdFALSE == xSemaphoreTake(s_lock, portMAX_DELAY));
169 xSemaphoreGive(s_lock);
177 return sizeof(((esp_partition_t *)0)->label) - 1;
191#if CONFIG_TARFS_EXTMEM
193 ptr = heap_caps_malloc(
size, MALLOC_CAP_SPIRAM);
198 ptr = heap_caps_malloc(
size, MALLOC_CAP_DEFAULT);
210 heap_caps_free(buffer);
224 esp_partition_iterator_t i;
225 esp_partition_mmap_handle_t handle;
226 const esp_partition_t *part;
230 if (label == NULL || os_handle_out == NULL) {
231 log(
"ESP32: invalid arguments\r\n");
237 i = esp_partition_find(ESP_PARTITION_TYPE_DATA,
238 ESP_PARTITION_SUBTYPE_ANY,
241 log(
"ESP32: partition not found '%s'\r\n", label);
246 part = esp_partition_get(i);
247 esp_partition_iterator_release(i);
251 log(
"esp_partition_get() returned NULL, this must not happen!\r\n");
256 if (ESP_OK == esp_partition_mmap(part,0,part->size,ESP_PARTITION_MMAP_DATA,&map,&handle)) {
257 *os_handle_out = (
void *)handle;
259 *size_out = part->size;
261 log(
"ESP32: partition '%s' -> vaddr=%p, size=%u\r\n", label, map, (
unsigned int)part->size);
266 log(
"esp_partition_mmap() failed\r\n");
282 esp_partition_munmap((esp_partition_mmap_handle_t)os_handle);
308 return ESP_OK == esp_vfs_unregister_fs(
prefix);
321 return ESP_OK == esp_vfs_register_fs(
prefix,
323 ESP_VFS_FLAG_CONTEXT_PTR |
324 ESP_VFS_FLAG_STATIC |
325 ESP_VFS_FLAG_READONLY_FS,
long tard_telldir(void *ctx, DIR *pdir)
Return the current directory position.
int tard_closedir(void *ctx, DIR *pdir)
Close a directory stream.
struct dirent * tard_readdir(void *ctx, DIR *pdir)
Read the next directory entry.
DIR * tard_opendir(void *ctx, const char *name)
Open a directory for reading.
void tard_seekdir(void *ctx, DIR *pdir, long offset)
Reposition a directory stream.
int tarf_stat(void *ctx, const char *path, struct stat *st)
stat() system call
off_t tarf_lseek(void *ctx, int fd, off_t offset, int whence)
lseek()
int tarf_close(void *ctx, int fd)
int tarf_access(void *ctx, const char *path, int amode)
Check the accessibility of a file or directory in the TarFS filesystem.
int tarf_fstat(void *ctx, int fd, struct stat *st)
Get file status information.
ssize_t tarf_pread(void *ctx, int fd, void *dst, size_t size, off_t offset)
Read data from an open TARFS file at a specified offset.
int tarf_ioctl(void *ctx, int fd, int cmd, va_list args)
Perform TARFS-specific I/O control operations.
ssize_t tarf_read(void *ctx, int fd, void *dst, size_t size)
Read data from an open TARFS file.
int tarf_fcntl(void *ctx, int fd, int cmd, int arg)
Perform file descriptor control operations.
int tarf_open(void *ctx, const char *path0, int flags, int mode)
Open a TARFS file or directory.
int tarf_fsync(void *ctx, int fd)
Synchronize file contents.
size_t tarfs_os_mp_maxlen()
Return the maximum mount point name length supported by the platform.
bool tarfs_os_register_fs(const char *prefix, void *context)
Tell the VFS that TARFS is now handle all the paths starting from 'prefix'.
void * tarfs_os_malloc(size_t size)
Memory allocation backend.
void tarfs_os_unmap_tarfile(void *os_handle, const void *map, size_t size)
Opposite of tarfs_os_map_tarfile().
@ ESP_PARTITION_SUBTYPE_DATA_TARFS
@ ESP_PARTITION_SUBTYPE_DATA_TARFS2
@ ESP_PARTITION_SUBTYPE_DATA_TARFS1
void tarfs_os_free(void *buffer)
bool tarfs_os_unregister_fs(const char *prefix)
Tell the VFS that path 'prefix' is not handled by tarfs anymore.
void tarfs_os_release_mutex()
Unlock access to s_tarfs[] table and to the s_numfs counter only.
void tarfs_os_init()
Create a recursive sync object.
void tarfs_os_acquire_mutex()
Lock access to s_tarfs[] table and to the s_numfs counter only.
void const * tarfs_os_map_tarfile(const char *label, void **os_handle_out, size_t *size_out)
Map a ESP32 flash partition to a virtual address space.