Files
OPTA_CardController_mbed/include/webserver/untar.h
Martijn Scheepers baaab652ae refractor untar
2026-02-27 11:55:07 +01:00

50 lines
1.3 KiB
C++

#ifndef ACSUNTAR_h
#define ACSUNTAR_h
#include "mbed.h"
#include "FATFileSystem.h"
#define TAR_BLOCKSIZE 512
#define TAR_LARGE_BLOCKSIZE 4096
#define TAR_FILENAME_LENGTH 100
#define TAR_FILESIZE_OFFSET 124
#define TAR_FILESIZE_LENGTH 12
#define TAR_CHECKSUM_OFFSET 148
#define TAR_CHECKSUM_LENGTH 8
#define TAR_TYPEFLAG_OFFSET 156
/* Values used in typeflag field. */
#define REGTYPE '0' /* regular file */
#define AREGTYPE '\0' /* regular file */
#define LNKTYPE '1' /* link */
#define SYMTYPE '2' /* reserved */
#define CHRTYPE '3' /* character special */
#define BLKTYPE '4' /* block special */
#define DIRTYPE '5' /* directory */
#define FIFOTYPE '6' /* FIFO special */
#define CONTTYPE '7' /* reserved */
enum tar_state {
TAR_DONE,
TAR_SHORT_READ,
TAR_WRITE_ERROR,
TAR_FILE_ERROR,
TAR_SOURCE_EOF,
TAR_CHECKSUM_MISMATCH,
};
class Tar
{
public:
static tar_state extract(FIL *tarfile, const char *folder); // Extract a tar archive
private:
static int parseoct(const char *p, size_t n); // Parse an octal number, ignoring leading and trailing nonsense.
static int is_end_of_archive(const char *p); // Returns true if this is 512 zero bytes.
static int verify_checksum(const char *p); // Verify the tar checksum.
};
#endif