+/* POSIX tar Header Block, from POSIX 1003.1-1990 */
+struct TarHeader
+{
+ /* byte offset */
+ char name[100]; /* 0-99 */
+ char mode[8]; /* 100-107 */
+ char uid[8]; /* 108-115 */
+ char gid[8]; /* 116-123 */
+ char size[12]; /* 124-135 */
+ char mtime[12]; /* 136-147 */
+ char chksum[8]; /* 148-155 */
+ char typeflag; /* 156-156 */
+ char linkname[100]; /* 157-256 */
+ char magic[6]; /* 257-262 */
+ char version[2]; /* 263-264 */
+ char uname[32]; /* 265-296 */
+ char gname[32]; /* 297-328 */
+ char devmajor[8]; /* 329-336 */
+ char devminor[8]; /* 337-344 */
+ char prefix[155]; /* 345-499 */
+ char padding[12]; /* 500-512 (pad to exactly the TAR_BLOCK_SIZE) */
+};
+typedef struct TarHeader TarHeader;
+
+
+/* A few useful constants */
+#define TAR_MAGIC "ustar" /* ustar and a null */
+#define TAR_VERSION " " /* Be compatable with GNU tar format */
+#define TAR_MAGIC_LEN 6
+#define TAR_VERSION_LEN 2
+#define TAR_BLOCK_SIZE 512
+
+/* A nice enum with all the possible tar file content types */
+enum TarFileType
+{
+ REGTYPE = '0', /* regular file */
+ REGTYPE0 = '\0', /* regular file (ancient bug compat)*/
+ LNKTYPE = '1', /* hard link */
+ SYMTYPE = '2', /* symbolic link */
+ CHRTYPE = '3', /* character special */
+ BLKTYPE = '4', /* block special */
+ DIRTYPE = '5', /* directory */
+ FIFOTYPE = '6', /* FIFO special */
+ CONTTYPE = '7', /* reserved */
+};
+typedef enum TarFileType TarFileType;
+
+/* This struct ignores magic, non-numeric user name,
+ * non-numeric group name, and the checksum, since
+ * these are all ignored by BusyBox tar. */
+struct TarInfo
+{
+ int tarFd; /* An open file descriptor for reading from the tarball */
+ char * name; /* File name */
+ mode_t mode; /* Unix mode, including device bits. */
+ uid_t uid; /* Numeric UID */
+ gid_t gid; /* Numeric GID */
+ size_t size; /* Size of file */
+ time_t mtime; /* Last-modified time */
+ enum TarFileType type; /* Regular, directory, link, etc */
+ char * linkname; /* Name for symbolic and hard links */
+ long devmajor; /* Major number for special device */
+ long devminor; /* Minor number for special device */
+};
+typedef struct TarInfo TarInfo;
+
+/* Local procedures to restore files from a tar file. */
+static int readTarFile(const char* tarName, int extractFlag, int listFlag,
+ int tostdoutFlag, int verboseFlag, char** excludeList);