TARFS 0.1.5
Read-only TAR filesystem for ESP32
Loading...
Searching...
No Matches
inode.h File Reference
#include <stdint.h>
#include <time.h>
#include "tar.h"

Go to the source code of this file.

Data Structures

struct  tarfs_inode_t
 TARFS inode structure, 12..20 bytes per inode; 1000 files require ~16KiB of RAM to store the filesystem index. More...

Functions

tart_t inode_getinfo (struct tarfs_inode const *const *index, int idx, size_t *size, time_t *mtime)
 Get information about an inode.
tart_t inode_type (struct tarfs_inode const *ino)
tart_t inode_rawtype (struct tarfs_inode const *ino)
 Return raw inode type: TART_HARDLINK, TART_SYMLINK, TART_DIR, TART_FILE or TART_BAD.
bool inode_islink (struct tarfs_inode const *ino)
int inode_lookup (struct tarfs_inode const *const *index, size_t num_inodes, const char *path)
 Find an inode by pathname.
struct tarfs_inode ** inode_alloc (size_t count)
 Allocate an inode index.
void inode_free (struct tarfs_inode **index, size_t count, uintptr_t tar_start, size_t tar_length)
 Destroy an inode index.
void inode_unmount (struct tarfs_fs *fs, const void *tar_start, size_t tar_size)
 Unmount a TAR image.
int inode_mount (struct tarfs_fs *fs, const unsigned char *buf, size_t size, const char *rebase_link, const char *path_rebase)
 Build an inode index for a TAR image.
void inode_dumphash_sorted (struct tarfs_inode const *const *index, size_t count)
 Dump the inode hash table in sorted order.
void inode_dumppath_sorted (struct tarfs_inode const *root)
 Dump the directory tree sorted by pathname.

Function Documentation

◆ inode_alloc()

struct tarfs_inode ** inode_alloc ( size_t count)

Allocate an inode index.

Returns an array of pointers to tarfs_inode structures.

Allocates an array of inode pointers capable of holding count entries.

Parameters
countNumber of inode pointers to allocate.
Returns
Newly allocated inode index, or NULL on failure.

Allocate an inode index.

Inodes are allocated and initialized to all zeros, array of pointers is allocated in populated with pointers to individual inodes Memory layout, single chunk: 0x3fc00000 .. [[index][inodes]] ..3fcxxxxx ---> memory grows this way

Definition at line 303 of file inode.c.

References log, and tarfs_calloc().

Referenced by inode_mount().

◆ inode_dumphash_sorted()

void inode_dumphash_sorted ( struct tarfs_inode const *const * index,
size_t count )

Dump the inode hash table in sorted order.

Displays inodes sorted by hash.

Debug helper used to inspect the inode index.

Parameters
indexInode index.
countNumber of entries.

Dump the inode hash table in sorted order.

Definition at line 1032 of file inode.c.

References inode_getinfo().

◆ inode_dumppath_sorted()

void inode_dumppath_sorted ( struct tarfs_inode const * root)

Dump the directory tree sorted by pathname.

Displays inodes sorted by path.

Debug helper that recursively prints the filesystem hierarchy.

Parameters
rootRoot inode.

Dump the directory tree sorted by pathname.

Definition at line 1057 of file inode.c.

◆ inode_free()

void inode_free ( struct tarfs_inode ** index,
size_t count,
uintptr_t tar_start,
size_t tar_length )

Destroy an inode index.

Free inodes.

Frees an inode index previously created by inode_alloc() together with all associated inode objects.

Parameters
indexInode index.
countNumber of entries in the index.
tar_startStart address of the mounted TAR image.
tar_lengthTAR image size in bytes.

Destroy an inode index.

All memory associated with inodes is freed: inodes and index array. Some inodes may have allocated names. There is no way to distiguish allocated name from a TAR name, except for checking pointer address to NOT BE in the mmaped TAR file

Definition at line 342 of file inode.c.

References tarfs_os_free().

Referenced by inode_unmount().

◆ inode_getinfo()

tart_t inode_getinfo ( struct tarfs_inode const *const * index,
int idx,
size_t * size,
time_t * mtime )

Get information about an inode.

inode_getinfo() : get inode's Type, Size and Mtime These are not precached and must be calculated every time.

Retrieves metadata for the inode referenced by an inode index entry. Either size or mtime may be NULL if the corresponding value is not required.

Parameters
indexInode index.
idxInode number within the index.
sizeOptional output for file size.
mtimeOptional output for modification time.
Returns
TAR entry type.

Get information about an inode.

Having this information in the tarfs_inode will increase the size of inode list dramatically

Parameters
fsa pointer to mounted FS
idxinode of intereset (inode index)
sizeif not NULL, provides the location to store the entry size
mtimeif not NULL, provides the location to store the entry mtime
Returns
Entry type (e.g. TART_FILE or TART_DIR etc). If return value is TART_BAD, then this is an indication of an invalid/unusable inode

Definition at line 466 of file inode.c.

References mtime, tarhdr_t::mtime, size, tarhdr_t::size, tar_octal(), tart_t, and tarhdr_t::type.

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

◆ inode_islink()

bool inode_islink ( struct tarfs_inode const * ino)

Definition at line 521 of file inode.c.

References tarhdr_t::type.

◆ inode_lookup()

int inode_lookup ( struct tarfs_inode const *const * index,
size_t num_inodes,
const char * path )

Find an inode by pathname.

Find an inode that corresponds to given path name.

Performs a pathname lookup in the inode index.

Parameters
indexInode index.
num_inodesNumber of entries in the index.
pathAbsolute path to search for.
Returns
Inode index on success, or -1 if not found.

Find an inode by pathname.

Performs a binary search in the array of pointers to struct tarfs_inode (index array). The array is sorted by ->in_hash

Inode pointer can be retrieved as node_ptr = index[i] where i is node index as returned by inode_lookup()

Returns inode index (>=0) or -errno

< Init vector for 32bit hash

Definition at line 399 of file inode.c.

References hash32(), HASH32_IV, inode_pathcmp(), and log.

Referenced by inode_resolve(), and tarf_open().

◆ inode_mount()

int inode_mount ( struct tarfs_fs * fs,
const unsigned char * buf,
size_t size,
const char * rebase_link,
const char * path_rebase )

Build an inode index for a TAR image.

Scans the TAR archive, creates the inode index and initializes the filesystem state.

Parameters
fsFilesystem instance.
bufStart address of the TAR image.
sizeTAR image size in bytes.
rebase_linkOptional path prefix substracted from symbolic links.
path_rebaseOptional path prefix substracted from every TAR entry. Normally this one is autodetected (the very first directory in the archive becomes the 'path_rebase' parameter) and then substracted from every path in the archive, so archive gets "/" entry
Return values
0Success.
-1Mount failed.

< Hash32 value of a single-character C-string "/". NOTE: must be recomputed if hash32 algo is changed!

Definition at line 932 of file inode.c.

References tarfs_fs::fs_dsize, tarfs_fs::fs_ino, tarfs_fs::fs_mtime, tarfs_fs::fs_nino, tarfs_fs::fs_root, tarfs_fs::fs_size, tarfs_fs::fs_stats, tarfs_fs::fs_vaddr, HASH32_SLASH, inode_alloc(), inode_alphasort(), inode_populate(), inode_resolve(), inode_sort(), log, mtime, tarhdr_t::mtime, size, tar_getnino(), and tar_octal().

Referenced by tarfs_mount_memory().

◆ inode_rawtype()

tart_t inode_rawtype ( struct tarfs_inode const * ino)

Return raw inode type: TART_HARDLINK, TART_SYMLINK, TART_DIR, TART_FILE or TART_BAD.

Definition at line 506 of file inode.c.

References tart_t, and tarhdr_t::type.

◆ inode_type()

tart_t inode_type ( struct tarfs_inode const * ino)

Definition at line 490 of file inode.c.

References tart_t, and tarhdr_t::type.

Referenced by tard_readdir().

◆ inode_unmount()

void inode_unmount ( struct tarfs_fs * fs,
const void * tar_start,
size_t tar_size )

Unmount a TAR image.

Releases all in-memory data structures associated with a mounted TARFS instance.

Parameters
fsFilesystem instance.
tar_startStart address of the mounted TAR image.
tar_sizeTAR image size in bytes.

Definition at line 921 of file inode.c.

References tarfs_fs::fs_ino, tarfs_fs::fs_nino, inode_free(), and log.

Referenced by commit_unmount().