|
TARFS 0.1.5
Read-only TAR filesystem for ESP32
|
#include <stddef.h>#include <stdint.h>#include <stdlib.h>#include <stdio.h>#include <stdbool.h>#include <stdatomic.h>#include <string.h>#include <time.h>#include <unistd.h>#include <errno.h>#include "config.h"#include "os.h"#include "tar.h"#include "fs.h"#include "hash.h"#include "inode.h"Go to the source code of this file.
Functions | |
| void | inode_sort (struct tarfs_inode **iarr, size_t count) |
| Sort inode indicies. | |
| struct tarfs_inode * | inode_alphasort (struct tarfs_inode *array, size_t count) |
| Sort inodes alphabetically: we do not move inodes. | |
| struct tarfs_inode ** | inode_alloc (size_t count) |
| Returns an array of pointers to tarfs_inode structures. | |
| void | inode_free (struct tarfs_inode **index, size_t count, uintptr_t tar_start, size_t tar_length) |
| Free inodes. | |
| int | inode_lookup (struct tarfs_inode const *const *index, size_t num_inodes, const char *path) |
| Find an inode that corresponds to given path name. | |
| tart_t | inode_getinfo (struct tarfs_inode const *const *index, int idx, size_t *size, time_t *mtime) |
| inode_getinfo() : get inode's Type, Size and Mtime These are not precached and must be calculated every time. | |
| 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) |
| time_t | inode_mtime (struct tarfs_fs *fs, int idx, size_t *size) |
| int | inode_resolve (struct tarfs_inode **index, size_t count) |
| size_t | inode_populate (struct tarfs_inode *inodes, size_t nino, const uint8_t *tar_start, size_t tar_length, const char *link_rebase, const char *root_folder, struct tarfs_stats *st) |
| Populate inodes. | |
| 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 *base_dir) |
| Build an inode index for a TAR image. | |
| void | inode_dumphash_sorted (struct tarfs_inode const *const *index, size_t count) |
| Displays inodes sorted by hash. | |
| void | inode_dumppath_sorted (struct tarfs_inode const *root) |
| Displays inodes sorted by path. | |
| struct tarfs_inode ** inode_alloc | ( | size_t | count | ) |
Returns an array of pointers to tarfs_inode structures.
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
Returns an array of pointers to tarfs_inode structures.
Allocates an array of inode pointers capable of holding count entries.
| count | Number of inode pointers to allocate. |
NULL on failure. Definition at line 303 of file inode.c.
References log, and tarfs_calloc().
Referenced by inode_mount().
| struct tarfs_inode * inode_alphasort | ( | struct tarfs_inode * | array, |
| size_t | count ) |
Sort inodes alphabetically: we do not move inodes.
we do not move inode's indices. Instead we use inode's in_next field to link all inodes in alphabetical order. This way we can have our inodes sorted by a hash AND sorted by its path
Definition at line 279 of file inode.c.
Referenced by inode_mount().
| void inode_dumphash_sorted | ( | struct tarfs_inode const *const * | index, |
| size_t | count ) |
Displays inodes sorted by hash.
Dump the inode hash table in sorted order.
Displays inodes sorted by hash.
Debug helper used to inspect the inode index.
| index | Inode index. |
| count | Number of entries. |
Definition at line 1032 of file inode.c.
References inode_getinfo().
| void inode_dumppath_sorted | ( | struct tarfs_inode const * | root | ) |
| void inode_free | ( | struct tarfs_inode ** | index, |
| size_t | count, | ||
| uintptr_t | tar_start, | ||
| size_t | tar_length ) |
Free inodes.
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
Free inodes.
Frees an inode index previously created by inode_alloc() together with all associated inode objects.
| index | Inode index. |
| count | Number of entries in the index. |
| tar_start | Start address of the mounted TAR image. |
| tar_length | TAR image size in bytes. |
Definition at line 342 of file inode.c.
References tarfs_os_free().
Referenced by inode_unmount().
| tart_t inode_getinfo | ( | struct tarfs_inode const *const * | index, |
| int | idx, | ||
| size_t * | size, | ||
| time_t * | mtime ) |
inode_getinfo() : get inode's Type, Size and Mtime These are not precached and must be calculated every time.
Get information about an inode.
Having this information in the tarfs_inode will increase the size of inode list dramatically
| fs | a pointer to mounted FS |
| idx | inode of intereset (inode index) |
| size | if not NULL, provides the location to store the entry size |
| mtime | if not NULL, provides the location to store the entry mtime |
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.
| index | Inode index. |
| idx | Inode number within the index. |
| size | Optional output for file size. |
| mtime | Optional output for modification time. |
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().
| bool inode_islink | ( | struct tarfs_inode const * | ino | ) |
Definition at line 521 of file inode.c.
References tarhdr_t::type.
| int inode_lookup | ( | struct tarfs_inode const *const * | index, |
| size_t | num_inodes, | ||
| const char * | path ) |
Find an inode that corresponds to given path name.
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
Find an inode that corresponds to given path name.
Performs a pathname lookup in the inode index.
| index | Inode index. |
| num_inodes | Number of entries in the index. |
| path | Absolute path to search for. |
< Init vector for 32bit hash
Definition at line 399 of file inode.c.
References hash32(), HASH32_IV, and log.
Referenced by inode_resolve(), and tarf_open().
| 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.
| fs | Filesystem instance. |
| buf | Start address of the TAR image. |
| size | TAR image size in bytes. |
| rebase_link | Optional path prefix substracted from symbolic links. |
| path_rebase | Optional 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 |
| 0 | Success. |
| -1 | Mount 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().
| time_t inode_mtime | ( | struct tarfs_fs * | fs, |
| int | idx, | ||
| size_t * | size ) |
Definition at line 535 of file inode.c.
References tarfs_fs::fs_ino, size, tarhdr_t::size, tar_octal(), and tarhdr_t::type.
| size_t inode_populate | ( | struct tarfs_inode * | inodes, |
| size_t | nino, | ||
| const uint8_t * | tar_start, | ||
| size_t | tar_length, | ||
| const char * | link_rebase, | ||
| const char * | root_folder, | ||
| struct tarfs_stats * | st ) |
Populate inodes.
Inodes must be allocated, and the allocation size must match real amount of inodes, which can be obtained through tar_getnino
< Init vector for 32bit hash
Definition at line 655 of file inode.c.
References tarfs_stats::badblocks, tarfs_stats::dirs, tarfs_stats::files, hash32(), HASH32_IV, tarfs_stats::links, log, tarfs_stats::ram, size, tar_baddata(), tar_badhdr(), tar_octal(), tar_strdup1(), tar_strlen(), tarfs_integrity(), and tarfs_strdup().
Referenced by inode_mount().
| 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.
| int inode_resolve | ( | struct tarfs_inode ** | index, |
| size_t | count ) |
Definition at line 561 of file inode.c.
References inode_getinfo(), inode_lookup(), link_name, log, tarfs_os_free(), tart_t, and type.
Referenced by inode_mount().
| void inode_sort | ( | struct tarfs_inode ** | iarr, |
| size_t | count ) |
Sort inode indicies.
Sorting is done by ->in_hash member
Definition at line 192 of file inode.c.
Referenced by inode_mount().
| 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().
| 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.
| fs | Filesystem instance. |
| tar_start | Start address of the mounted TAR image. |
| tar_size | TAR 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.