|
TARFS 0.1.5
Read-only TAR filesystem for ESP32
|
#include <stdint.h>#include <stdlib.h>#include <stdio.h>#include <stdbool.h>#include <stdatomic.h>#include <unistd.h>#include <dirent.h>#include <sys/errno.h>#include <sys/ioctl.h>#include <sys/socket.h>#include <sys/types.h>#include "config.h"#include "os.h"#include "fs.h"#include "file.h"#include "inode.h"#include "tar.h"#include "dir.h"#include "posix.h"Go to the source code of this file.
Functions | |
| void * | mmap (void *addr, size_t length, int prot, int flags, int fd, off_t offset) |
| Subset of POSIX functions. | |
| int | munmap (void *addr, size_t length) |
| POSIX munmap(). | |
| int | dupfd (int fd) |
| Create an independent duplicate of a file descriptor. | |
| DIR * | fdopendir (int fd) |
| Associate an open directory file descriptor with a directory stream. | |
| int | statvfs (const char *path, struct statvfs *st) |
| Obtain filesystem statistics. | |
| ssize_t | sendfile (int out_fd, int in_fd, off_t *offset, size_t count) |
| Zero-overhead, no-buffer file-to-socket tranfer. | |
| int dupfd | ( | int | fd | ) |
Create an independent duplicate of a file descriptor.
This function is similar to POSIX dup(), but the file position is not shared. The new descriptor has its own independent file offset, initialized to the current position of the original descriptor.
< Convert global fd number to local fd number. arg=&int
Definition at line 107 of file posix.c.
References ioctl_req::fd, FIOGETFD, ioctl_req::fs_idx, and tarf_dupfd().
| DIR * fdopendir | ( | int | fd | ) |
Associate an open directory file descriptor with a directory stream.
Creates a directory stream from an existing directory file descriptor. After a successful call, the file descriptor is owned by the returned directory stream and must not be closed directly. It will be closed automatically by tard_closedir().
< Convert global fd number to local fd number. arg=&int
Definition at line 133 of file posix.c.
References ioctl_req::fd, FIOGETFD, ioctl_req::fs_idx, and tard_fdopendir().
| void * mmap | ( | void * | addr, |
| size_t | length, | ||
| int | prot, | ||
| int | flags, | ||
| int | fd, | ||
| off_t | offset ) |
Subset of POSIX functions.
Map a file into the process address space.
Mimic POSIX mmap().
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. |
< 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 ) |
POSIX munmap().
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. |
< 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(), tarfs_lock(), TARFS_MAX_FS, and tarfs_unlock().
| ssize_t sendfile | ( | int | out_fd, |
| int | in_fd, | ||
| off_t * | offset, | ||
| size_t | count ) |
Zero-overhead, no-buffer file-to-socket tranfer.
File descriptor must be a TARFS file descriptor
This function transfers data directly from in_fd to out_fd without requiring an intermediate user buffer, without read()/pread()
| out_fd | Destination file descriptor. Must be a socket. |
| in_fd | Source file descriptor. A tarfs descriptor |
| offset | Optional starting offset in the input file. If NULL, the current file position is used and advanced. Otherwise, the value pointed to by offset is used and updated, while the file position of in_fd remains unchanged. |
| count | Maximum number of bytes to transfer. |
< Convert global fd number to local fd number. arg=&int
Definition at line 196 of file posix.c.
References ioctl_req::fd, FIOGETFD, ioctl_req::fs_idx, and tarf_sendfile().
| int statvfs | ( | const char * | path, |
| struct statvfs * | st ) |
Obtain filesystem statistics.
Fills a POSIX statvfs structure with information about the mounted filesystem. Since TARFS is a read-only filesystem, the number of available blocks and inodes is always reported as zero.
| path | Pointer to the path |
| st | Pointer to the statvfs structure to fill. |
Definition at line 163 of file posix.c.
References ioctl_req::fs_idx, tarfs_fsindex(), and tarfs_statvfs().