|
TARFS 0.1.5
Read-only TAR filesystem for ESP32
|
#include <stdint.h>#include <stdlib.h>#include <stddef.h>#include <stdio.h>#include <sys/types.h>Go to the source code of this file.
Macros | |
| #define | PROT_READ 1 |
| POSIX mmap()/munmap() support for TARFS. | |
| #define | PROT_WRITE 2 |
| #define | PROT_EXEC 4 |
| #define | MAP_FILE 0 |
| #define | MAP_SHARED 1 |
| #define | MAP_PRIVATE 2 |
| #define | MAP_FIXED 4 |
| #define | MAP_ANONYMOUS 8 |
| #define | MAP_ANON 8 |
| #define | MAP_FAILED ((void *)(-1)) |
Functions | |
| void * | mmap (void *addr, size_t length, int prot, int flags, int fd, off_t offset) |
| Map a file into the process address space. | |
| int | munmap (void *addr, size_t length) |
| Remove a previously created memory mapping. | |
| #define MAP_ANONYMOUS 8 |
| #define MAP_FAILED ((void *)(-1)) |
Definition at line 41 of file posix.h.
Referenced by mmap(), and tarf_mmap().
| #define MAP_FILE 0 |
| #define MAP_FIXED 4 |
Ignored, no legit use for this flag :)
Definition at line 36 of file posix.h.
Referenced by tarf_mmap().
| #define PROT_EXEC 4 |
| #define PROT_READ 1 |
| #define PROT_WRITE 2 |
Ignored, if used together with PROT_READ. Alone causes mmap() error (RO filesystem!)
Definition at line 29 of file posix.h.
Referenced by tarf_mmap().
| void * mmap | ( | void * | addr, |
| size_t | length, | ||
| int | prot, | ||
| int | flags, | ||
| int | fd, | ||
| off_t | offset ) |
Map a file into the process address space.
Subset of POSIX functions.
Typical usage:
The mapping remains valid after the file descriptor has been closed.
Since TARFS is a read-only filesystem, this implementation does not support the PROT_WRITE protection flag. MAP_ANONYMOUS is also not supported: mmap() is intended exclusively for mapping files.
There is no limit on the number of active mappings. Every file in TARFS may be mapped simultaneously, provided the underlying flash memory can hold it. Mappings do not consume any runtime resources. In contrast, each open file occupies one file descriptor until it is closed.
| addr | Must be NULL. Fixed-address mappings are not supported. |
| length | Number of bytes to map. |
| prot | Memory protection flags. Only PROT_READ is supported. |
| flags | Mapping flags. Use MAP_SHARED or MAP_PRIVATE. On a read-only filesystem both behave identically. |
| fd | Open file descriptor to map. |
| offset | File offset where the mapping begins. |
Map a file into the process address space.
Mimic POSIX mmap().
< Convert global fd number to local fd number. arg=&int
Definition at line 54 of file posix.c.
References ioctl_req::fd, FIOGETFD, ioctl_req::fs_idx, MAP_FAILED, and tarf_mmap().
| int munmap | ( | void * | addr, |
| size_t | length ) |
Remove a previously created memory mapping.
POSIX munmap().
Since mappings themselves do not allocate runtime resources, failing to call munmap() does not lead to resource leaks. However, an active mapping keeps the filesystem mounted, preventing it from being unmounted until the mapping is removed.
| addr | Address previously returned by mmap(). |
| length | Length of the mapped region. |
Remove a previously created memory mapping.
< Max number of mounted TARFS filesystems
Definition at line 72 of file posix.c.
References tarfs_fs::fs_size, tarfs_fs::fs_vaddr, log, tarf_munmap(), tarfs_getfs(), and TARFS_MAX_FS.