hio/lib/hio-tar.h

139 lines
3.7 KiB
C
Raw Normal View History

2022-10-25 22:47:40 +00:00
#ifndef _HIO_TAR_H_
#define _HIO_TAR_H_
#include <hio.h>
2022-12-04 16:51:10 +00:00
#include <hio-ecs.h>
2022-10-25 22:47:40 +00:00
/* tar Header Block, from POSIX 1003.1-1990. */
struct hio_tar_hdr_t
{ /* byte offset */
char name[100]; /* 0 */
char mode[8]; /* 100 */
char uid[8]; /* 108 */
char gid[8]; /* 116 */
2022-11-14 23:21:42 +00:00
char size[12]; /* 124 - file size in an ascii octal string */
2022-10-25 22:47:40 +00:00
char mtime[12]; /* 136 */
char chksum[8]; /* 148 */
char typeflag; /* 156 */
char linkname[100]; /* 157 */
2022-11-14 23:21:42 +00:00
char magic[6]; /* 257 - ustar indicator */
char version[2]; /* 263 - ustar version */
2022-10-25 22:47:40 +00:00
char uname[32]; /* 265 */
char gname[32]; /* 297 */
char devmajor[8]; /* 329 */
char devminor[8]; /* 337 */
char prefix[155]; /* 345 */
char padding[12]; /* 500 */
#if 0
char *gnu_longname;
char *gnu_longlink;
#endif
};
typedef struct hio_tar_hdr_t hio_tar_hdr_t;
#define HIO_TAR_MAGIC "ustar" /* ustar and a null */
#define HIO_TAR_MAGLEN 6
#define HIO_TAR_VERSION "00" /* 00 and no null */
#define HIO_TAR_VERSLEN 2
/* Values used in typeflag field. */
#define HIO_TAR_REGTYPE '0' /* regular file */
#define HIO_TAR_AREGTYPE '\0' /* regular file */
#define HIO_TAR_LNKTYPE '1' /* link */
#define HIO_TAR_SYMTYPE '2' /* reserved */
#define HIO_TAR_CHRTYPE '3' /* character special */
#define HIO_TAR_BLKTYPE '4' /* block special */
#define HIO_TAR_DIRTYPE '5' /* directory */
#define HIO_TAR_FIFOTYPE '6' /* FIFO special */
#define HIO_TAR_CONTTYPE '7' /* reserved */
#define HIO_TAR_XHDTYPE 'x' /* Extended header referring to the next file in the archive */
#define HIO_TAR_XGLTYPE 'g' /* Global extended header */
/* Bits used in the mode field, values in octal. */
#define HIO_TAR_SUID 04000 /* set UID on execution */
#define HIO_TAR_SGID 02000 /* set GID on execution */
#define HIO_TAR_SVTX 01000 /* reserved */
/* file permissions */
#define HIO_TAR_UREAD 00400 /* read by owner */
#define HIO_TAR_UWRITE 00200 /* write by owner */
#define HIO_TAR_UEXEC 00100 /* execute/search by owner */
#define HIO_TAR_GREAD 00040 /* read by group */
#define HIO_TAR_GWRITE 00020 /* write by group */
#define HIO_TAR_GEXEC 00010 /* execute/search by group */
#define HIO_TAR_OREAD 00004 /* read by other */
#define HIO_TAR_OWRITE 00002 /* write by other */
#define HIO_TAR_OEXEC 00001 /* execute/search by other */
#define HIO_TAR_BLKSIZE (512)
enum hio_tar_state_t
{
HIO_TAR_STATE_START,
HIO_TAR_STATE_FILE,
2022-12-05 16:04:11 +00:00
HIO_TAR_STATE_END_1,
HIO_TAR_STATE_END_2
2022-10-25 22:47:40 +00:00
};
typedef enum hio_tar_state_t hio_tar_state_t;
struct hio_tar_t
{
hio_t* hio;
hio_tar_state_t state;
struct
{
hio_uint8_t buf[HIO_TAR_BLKSIZE];
hio_oow_t len;
} blk;
2022-11-14 23:21:42 +00:00
struct
{
hio_uintmax_t filesize;
2022-11-29 16:23:53 +00:00
hio_uintmax_t filemode;
2022-12-04 16:51:10 +00:00
hio_becs_t filename;
2022-11-14 23:21:42 +00:00
void* fp;
} hi;
2022-10-25 22:47:40 +00:00
};
typedef struct hio_tar_t hio_tar_t;
#if defined(__cplusplus)
extern "C" {
#endif
2022-11-14 23:21:42 +00:00
HIO_EXPORT hio_tar_t* hio_tar_open (
2022-10-25 22:47:40 +00:00
hio_t* hio,
hio_oow_t xtnsize
);
2022-11-14 23:21:42 +00:00
HIO_EXPORT void hio_tar_close (
2022-10-25 22:47:40 +00:00
hio_tar_t* tar
);
2022-11-14 23:21:42 +00:00
HIO_EXPORT int hio_tar_init (
2022-12-04 16:51:10 +00:00
hio_tar_t* tar,
hio_t* hio
2022-10-25 22:47:40 +00:00
);
2022-11-14 23:21:42 +00:00
HIO_EXPORT void hio_tar_fini (
2022-10-25 22:47:40 +00:00
hio_tar_t* tar
);
2022-11-14 23:21:42 +00:00
#define hio_tar_endfeed(tar) hio_tar_feed(tar, HIO_NULL, 0)
HIO_EXPORT int hio_tar_feed (
hio_tar_t* tar,
const void* ptr,
hio_oow_t len
);
2022-10-25 22:47:40 +00:00
#if defined(__cplusplus)
}
#endif
#endif