seahag/include/haggis.h

126 lines
3.2 KiB
C

/* _,.---._ .-._ .--.-. ,--.--------.
* _,..---._ ,-.' , - `. /==/ \ .-._/==/ //==/, - , -\
* /==/, - \ /==/_, , - \|==|, \/ /, |==\ -\\==\.-. - ,-./
* |==| _ _\==| .=. |==|- \| | \==\- \`--`\==\- \
* |==| .=. |==|_ : ;=: - |==| , | -| `--`-' \==\_ \
* |==|,| | -|==| , '=' |==| - _ | |==|- |
* |==| '=' /\==\ - ,_ /|==| /\ , | |==|, |
* |==|-, _`/ '.='. - .' /==/, | |- | /==/ -/
* `-.`.____.' `--`--'' `--`./ `--` `--`--`
* _ __ ,---. .-._ .=-.-. _,.----.
* .-`.' ,`..--.' \ /==/ \ .-._ /==/_ /.' .' - \
* /==/, - \==\-/\ \ |==|, \/ /, /==|, |/==/ , ,-'
* |==| _ .=. /==/-|_\ | |==|- \| ||==| ||==|- | .
* |==| , '=',\==\, - \ |==| , | -||==|- ||==|_ `-' \
* |==|- '..'/==/ - ,| |==| - _ ||==| ,||==| _ , |
* |==|, | /==/- /\ - \|==| /\ , ||==|- |\==\. /
* /==/ - | \==\ _.\=\.-'/==/, | |- |/==/. / `-.`.___.-'
* `--`---' `--` `--`./ `--``--`-`
*
* @(#)Copyright (c) 2023, Nathan D. Fisher.
*
* This is free software. It comes with NO WARRANTY.
* Permission to use, modify and distribute this source code
* is granted subject to the following conditions.
* 1/ that the above copyright notice and this notice
* are preserved in all copies and that due credit be given
* to the author.
* 2/ that any changes to this code are clearly commented
* as such so that the author does not get blamed for bugs
* other than his own.
*/
#ifndef HAGGIS_H
#define HAGGIS_H
#include <stdint.h>
#include <stdio.h>
typedef uint8_t u8;
typedef union {
uint16_t val;
u8 bytes[2];
} u16;
typedef union {
uint32_t val;
u8 bytes[4];
} u32;
typedef union {
uint64_t val;
u8 bytes[8];
} u64;
typedef struct {
u32 major;
u32 minor;
} haggis_device;
typedef enum {
md5,
sha1,
sha256,
skip,
} haggis_algorithm;
typedef union {
u8 md5[16];
u8 sha1[20];
u8 sha256[32];
} haggis_sum;
typedef struct {
haggis_algorithm tag;
haggis_sum *sum;
} haggis_checksum;
typedef struct {
u64 len;
haggis_checksum *cksum;
u8 *data;
} haggis_file;
typedef struct {
u16 len;
char *name;
} haggis_filename;
typedef enum {
normal,
hardlink,
softlink,
directory,
character,
block,
fifo,
eof,
} haggis_typeflag;
typedef union {
haggis_file *file;
haggis_filename *target;
haggis_device *dev;
} haggis_ft;
typedef struct {
haggis_typeflag tag;
haggis_ft *f_type;
} haggis_filetype;
typedef struct {
haggis_filename *name;
u32 uid;
u32 gid;
u64 mtime;
u16 mode;
haggis_filetype *filetype;
} haggis_node;
haggis_node* haggis_create_node(char *file);
int haggis_extract_node(FILE *stram, haggis_node *node);
int haggis_load_node(FILE *stream, haggis_node *node);
int haggis_store_node(FILE *stream, haggis_node *node);
#endif // !HAGGIS_H