|
TARFS 0.1.5
Read-only TAR filesystem for ESP32
|
#include <stdint.h>#include <stdio.h>#include <stddef.h>#include <string.h>#include <stdlib.h>#include <stdbool.h>#include "os.h"#include "fs.h"#include "tar.h"#include "hash.h"Go to the source code of this file.
Functions | |
| int | tar_strcmp (const char *s1, const char *s1_end, const char *s2) |
| Compare an UTS/CTS to a CTS. | |
| int | tar_strncmp (const char *s1, const char *s2, size_t len) |
| int | tar_strlen (const char *s1, const char *s1_end) |
| Return the length of a TAR string. | |
| void | tar_strcpy (char *dst, const char *src) |
| char * | tar_strdup1 (const char *s1, const char *s1_end) |
| Duplicate a TAR string as a regular NUL-terminated C string. | |
| uint32_t | tar_octal (const char *p, size_t max_len) |
| uint32_t | tar_hdrsum (tarhdr_t const *hdr) |
| bool | tar_badhdr (tarhdr_t const *hdr) |
| Validate a TAR header. | |
| int | tar_getnino (const uint8_t *tar_start, size_t tar_length) |
| Quick run through the tarfile to count number of inodes we have to create. | |
| bool | tar_rootdir (const uint8_t *tar_start, size_t tar_length, char *base_dir, size_t out_len) |
| Detect the archive root directory. | |
| bool | tar_baddata (struct tarhdr const *hdr, size_t size) |
| Verify CRC64 checksum stored in a TAR archive, if present. | |
| bool tar_baddata | ( | struct tarhdr const * | hdr, |
| size_t | size ) |
Verify CRC64 checksum stored in a TAR archive, if present.
Verify CRC64 checksums stored in a TAR archive, if present.
hdr must pass tar_badhdr() check!!
Verify CRC64 checksum stored in a TAR archive, if present.
hdr must pass tar_badhdr() check!!
Definition at line 529 of file tar.c.
References hash64(), and size.
Referenced by inode_populate(), tarf_open(), and tarfs_fsck().
| bool tar_badhdr | ( | tarhdr_t const * | hdr | ) |
Validate a TAR header.
Checks:
| hdr | Pointer to a TAR header. |
Checks:
| hdr | Pointer to a TAR header. |
Definition at line 249 of file tar.c.
References tar_hdrsum(), and tar_octal().
Referenced by inode_populate(), tar_getnino(), tar_rootdir(), and tarfs_fsck().
| int tar_getnino | ( | const uint8_t * | tar_start, |
| size_t | tar_length ) |
Quick run through the tarfile to count number of inodes we have to create.
Quick run through the tarfile to count number of inodes we have to create Bad blocks are skipped; inodes_count = number_of_links + number_files + number_of_directoris.
Bad blocks are skipped; inodes_count = number_of_links + number_files + number_of_directoris
Quick run through the tarfile to count number of inodes we have to create.
| tar_start | Address where the TAR archive is mapped. |
| tar_length | Size of the mapped archive. |
Definition at line 306 of file tar.c.
References log, size, tar_badhdr(), and tar_octal().
Referenced by inode_mount().
| uint32_t tar_hdrsum | ( | tarhdr_t const * | hdr | ) |
Definition at line 221 of file tar.c.
Referenced by tar_badhdr().
| uint32_t tar_octal | ( | const char * | p, |
| size_t | max_len ) |
Definition at line 193 of file tar.c.
Referenced by inode_getinfo(), inode_mount(), inode_mtime(), inode_populate(), tar_badhdr(), tar_getnino(), tar_rootdir(), and tarfs_fsck().
| bool tar_rootdir | ( | const uint8_t * | tar_start, |
| size_t | tar_length, | ||
| char * | base_dir, | ||
| size_t | base_dir_len ) |
Detect the archive root directory.
This function may choose wrong directory name if filesystem is damaged
The detected directory is used both as the filesystem mount point and as the path prefix to strip from every inode. For example, if the archive contains:
my_archive/ my_archive/file.txt my_archive/dir/test.txt
then the filesystem will expose:
/file.txt /dir/test.txt
Detection relies on the following assumptions:
These assumptions are not verified. It is the caller's responsibility to provide a well-formed TAR archive.
Since the root directory becomes the mount point, it must satisfy the ESP-IDF mount-point limitations (currently no more than 16 characters, excluding the terminating NUL).
The root directory name always fits into tarhdr->name, so it is guaranteed to be NUL-terminated and never uses the TAR 'prefix' field.
| tar_start | Address where the TAR archive is mapped. |
| tar_length | Size of the mapped archive. |
| base_dir | Output buffer receiving the detected root directory. |
| base_dir_len | Output buffer size. Recommended size is 100 bytes |
Definition at line 372 of file tar.c.
References log, size, tar_badhdr(), tar_octal(), tar_strlen(), and tarfs_os_mp_maxlen().
Referenced by tarfs_mount_memory().
| int tar_strcmp | ( | const char * | s1, |
| const char * | s1_end, | ||
| const char * | s2 ) |
Compare an UTS/CTS to a CTS.
TAR string fields are not required to be NUL-terminated. A string ends at the first '\0', '\r' or '
', or at s1_end if no terminator appears before that point.
| s1 | TAR string. |
| s1_end | Pointer to the byte immediately following the last valid character in s1, or NULL if s1 is guaranteed to contain a TAR string terminator. |
| s2 | Regular NUL-terminated C string. |
Definition at line 48 of file tar.c.
Referenced by merge().
| char * tar_strdup1 | ( | const char * | s1, |
| const char * | s1_end ) |
Duplicate a TAR string as a regular NUL-terminated C string.
The returned buffer contains one additional byte after the terminating NUL, allowing a single character (typically '/') to be appended without reallocating. This is used during link resolution.
string\0\0 ^_— Here one could append one character to extend a string by one character
| s1 | TAR string. |
| s1_end | Pointer to the byte immediately following the last valid character in s1, or NULL if s1 contains a TAR string terminator. |
Definition at line 171 of file tar.c.
References tar_strlen(), and tarfs_os_malloc().
Referenced by inode_populate(), tard_fdopendir(), and tarf_open().
| int tar_strlen | ( | const char * | s1, |
| const char * | s1_end ) |
Return the length of a TAR string.
A TAR string ends at the first '\0', '\r' or '
'. If none of these characters is present before s1_end, then s1_end is treated as the end of the string.
| s1 | TAR string. |
| s1_end | Pointer to the byte immediately following the last valid character in s1, or NULL if s1 contains a TAR string terminator. |
Definition at line 131 of file tar.c.
Referenced by inode_populate(), tar_rootdir(), tar_strdup1(), and tard_readdir().
| int tar_strncmp | ( | const char * | s1, |
| const char * | s2, | ||
| size_t | len ) |
Definition at line 90 of file tar.c.
Referenced by is_direct_child().