TARFS 0.1.5
Read-only TAR filesystem for ESP32
Loading...
Searching...
No Matches
tar.h File Reference
#include "config.h"

Go to the source code of this file.

Data Structures

struct  tarhdr_t
 For TAR files with modified PADDING field (see tarsum.c TARFS Checksum Utility): The type and meaning of the last 8 bytes of the padding field. More...

Functions

enum __attribute__ ((packed))
 "TART" == "TAR Type" tarfile entry (header) types, 1-byte wide.
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.
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)
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 Bad blocks are skipped; inodes_count = number_of_links + number_files + number_of_directoris.
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.
uint32_t tar_hdrsum (const tarhdr_t *hdr)
bool tar_baddata (struct tarhdr const *hdr, size_t size)
 Verify CRC64 checksums stored in a TAR archive, if present.

Variables

 tart_t
const char name [100]
const char mode [8]
const char uid [8]
const char gid [8]
const char size [12]
const char mtime [12]
char checksum [8]
const tart_t type
const char link_name [100]
const char magic [6]
const char version [2]
const char user [32]
const char group [32]
const char major [8]
const char minor [8]
const char prefix [155]
char zero
const char pad [11]

Function Documentation

◆ __attribute__()

struct tarhdr __attribute__ ( (packed) )

"TART" == "TAR Type" tarfile entry (header) types, 1-byte wide.

The same type is used throughout the filesystem code as the main type for inodes, tar record etc

< file, old format

< file, common format

< hard link

< symbolic link

< directory

< PaxHeader

< character device

< block device

< fifo / named pipe

< contigous file, whatever that means

< PaxGlobalHeader

Definition at line 1 of file tar.h.

◆ tar_baddata()

bool tar_baddata ( struct tarhdr const * hdr,
size_t size )

Verify CRC64 checksums stored in a TAR archive, if present.

Verify CRC64 checksum stored in a TAR archive, if present.

hdr must pass tar_badhdr() check!!

Verify CRC64 checksums 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().

◆ tar_badhdr()

bool tar_badhdr ( tarhdr_t const * hdr)

Validate a TAR header.

Checks:

  • entry type is supported/recognized;
  • reserved padding byte is zero;
  • checksum field contains only valid TAR characters;
  • header checksum matches the calculated value.
  • entry size is within the mmaped memory range.
Parameters
hdrPointer to a TAR header.
Returns
true if the header is invalid, corrupted, or unsupported. In this case no inode should be created for this entry.

Checks:

  • entry type is supported/recognized;
  • reserved padding byte is zero;
  • checksum field contains only valid TAR characters;
  • header checksum matches the calculated value.
Parameters
hdrPointer to a TAR header.
Returns
true if the header is invalid, corrupted, or unsupported. In this case no inode should be created for this entry.

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().

◆ tar_getnino()

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 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.

Parameters
tar_startAddress where the TAR archive is mapped.
tar_lengthSize of the mapped archive.
Returns
Number of inodes required for this filesystem

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

Definition at line 306 of file tar.c.

References log, size, tar_badhdr(), and tar_octal().

Referenced by inode_mount().

◆ tar_hdrsum()

uint32_t tar_hdrsum ( const tarhdr_t * hdr)

Definition at line 221 of file tar.c.

Referenced by tar_badhdr().

◆ tar_octal()

uint32_t tar_octal ( const char * p,
size_t max_len )

◆ tar_rootdir()

bool tar_rootdir ( const uint8_t * tar_start,
size_t tar_length,
char * base_dir,
size_t out_len )

Detect the archive root directory.

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:

  • the first directory entry (type 5) is the archive root;
  • all archive entries reside under that directory.

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.

Parameters
tar_startAddress where the TAR archive is mapped.
tar_lengthSize of the mapped archive.
base_dirOutput buffer receiving the detected root directory.
base_dir_lenOutput buffer size. Recommended size is 100 bytes
Returns
true if a root directory was found.

This function may choose wrong directory name if filesystem is damaged

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().

◆ tar_strcmp()

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.

Parameters
s1TAR string.
s1_endPointer to the byte immediately following the last valid character in s1, or NULL if s1 is guaranteed to contain a TAR string terminator.
s2Regular NUL-terminated C string.
Returns
<0 if s1 is lexicographically less than s2, >0 if s1 is lexicographically greater than s2, 0 if both strings are equal.

Definition at line 48 of file tar.c.

Referenced by merge().

◆ tar_strdup1()

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

Parameters
s1TAR string.
s1_endPointer to the byte immediately following the last valid character in s1, or NULL if s1 contains a TAR string terminator.
Returns
Newly allocated NUL-NULL-terminated copy of the string, or NULL on allocation failure.

Definition at line 171 of file tar.c.

References tar_strlen(), and tarfs_os_malloc().

Referenced by inode_populate(), tard_fdopendir(), and tarf_open().

◆ tar_strlen()

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.

Parameters
s1TAR string.
s1_endPointer to the byte immediately following the last valid character in s1, or NULL if s1 contains a TAR string terminator.
Returns
Length of the string, excluding the terminator.

Definition at line 131 of file tar.c.

Referenced by inode_populate(), tar_rootdir(), tar_strdup1(), and tard_readdir().

◆ tar_strncmp()

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().

Variable Documentation

◆ checksum

char checksum[8]

Octal, ASCII

Definition at line 7 of file tar.h.

◆ gid

const char gid[8]

Ignored: VFS has no user/group concept

Definition at line 4 of file tar.h.

◆ group

const char group[32]

Ignored: VFS has no user/group concept

Definition at line 13 of file tar.h.

◆ link_name

const char link_name[100]

For records type#1 and #2 this field contains a name of the object

Definition at line 9 of file tar.h.

Referenced by inode_resolve().

◆ magic

const char magic[6]

"ustar\0" signature

Definition at line 10 of file tar.h.

◆ major

const char major[8]

Ignored: device files make no sence

Definition at line 14 of file tar.h.

◆ minor

const char minor[8]

Ignored: device files make no sence

Definition at line 15 of file tar.h.

◆ mode

const char mode[8]

Ignored: RWX, we are ROFS

Definition at line 2 of file tar.h.

Referenced by tarf_open().

◆ mtime

const char mtime[12]

All times are set at mount time and never change (ROFS)

Definition at line 6 of file tar.h.

Referenced by inode_getinfo(), inode_mount(), tarf_fstat(), and tarf_open().

◆ name

const char name[100]

First (if prefix[0] == 0) or Second part of the entry name

Definition at line 1 of file tar.h.

Referenced by tard_opendir().

◆ pad

const char pad[11]

Must be zero by the standart

Definition at line 23 of file tar.h.

◆ prefix

const char prefix[155]

First (if prefix[0] != 0) part of the entry name. A slash at the end does not exist but is assumed

Definition at line 16 of file tar.h.

Referenced by is_direct_child(), tarfs_os_register_fs(), and tarfs_os_unregister_fs().

◆ size

◆ tart_t

tart_t

Definition at line 46 of file tar.h.

Referenced by inode_getinfo(), inode_rawtype(), inode_resolve(), inode_type(), tarf_fstat(), and tarf_open().

◆ type

const tart_t type

Record type

Definition at line 8 of file tar.h.

Referenced by inode_resolve(), tarf_fstat(), and tarf_open().

◆ uid

const char uid[8]

Ignored: VFS has no user/group concept

Definition at line 3 of file tar.h.

◆ user

const char user[32]

Ignored: VFS has no user/group concept

Definition at line 12 of file tar.h.

◆ version

const char version[2]

"00"

Definition at line 11 of file tar.h.

◆ zero

char zero

Must be zero by the standart

Definition at line 17 of file tar.h.