seahag/include/haggis.h

125 lines
3.3 KiB
C
Raw Normal View History

2023-07-19 23:42:04 -04:00
/* _,.---._ .-._ .--.-. ,--.--------.
* _,..---._ ,-.' , - `. /==/ \ .-._/==/ //==/, - , -\
* /==/, - \ /==/_, , - \|==|, \/ /, |==\ -\\==\.-. - ,-./
* |==| _ _\==| .=. |==|- \| | \==\- \`--`\==\- \
* |==| .=. |==|_ : ;=: - |==| , | -| `--`-' \==\_ \
* |==|,| | -|==| , '=' |==| - _ | |==|- |
* |==| '=' /\==\ - ,_ /|==| /\ , | |==|, |
* |==|-, _`/ '.='. - .' /==/, | |- | /==/ -/
* `-.`.____.' `--`--'' `--`./ `--` `--`--`
* _ __ ,---. .-._ .=-.-. _,.----.
* .-`.' ,`..--.' \ /==/ \ .-._ /==/_ /.' .' - \
* /==/, - \==\-/\ \ |==|, \/ /, /==|, |/==/ , ,-'
* |==| _ .=. /==/-|_\ | |==|- \| ||==| ||==|- | .
* |==| , '=',\==\, - \ |==| , | -||==|- ||==|_ `-' \
* |==|- '..'/==/ - ,| |==| - _ ||==| ,||==| _ , |
* |==|, | /==/- /\ - \|==| /\ , ||==|- |\==\. /
* /==/ - | \==\ _.\=\.-'/==/, | |- |/==/. / `-.`.___.-'
* `--`---' `--` `--`./ `--``--`-`
*
* @(#)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 1
2023-07-19 23:42:04 -04:00
2023-08-07 18:55:47 -04:00
#include "linklist.h"
#include <stdint.h> // uint<x>_t
#include <stdio.h> // FILE
2023-07-19 23:42:04 -04:00
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;
2023-07-19 23:42:04 -04:00
typedef enum {
2023-07-19 23:42:04 -04:00
md5,
sha1,
sha256,
skip,
} haggis_algorithm;
2023-07-19 23:42:04 -04:00
typedef struct {
haggis_algorithm tag;
2023-08-08 01:40:21 -04:00
union {
u8 md5[16];
u8 sha1[20];
u8 sha256[32];
} sum;
} haggis_checksum;
2023-07-19 23:42:04 -04:00
typedef struct {
u64 len;
haggis_checksum cksum;
2023-07-23 23:42:51 -04:00
u8 *data;
} haggis_file;
typedef struct {
u16 len;
2023-07-23 23:42:51 -04:00
char *name;
} haggis_filename;
2023-07-19 23:42:04 -04:00
typedef enum {
2023-07-19 23:42:04 -04:00
normal,
hardlink,
softlink,
directory,
character,
block,
fifo,
eof,
} haggis_typeflag;
typedef struct {
haggis_typeflag tag;
2023-08-08 01:40:21 -04:00
union {
haggis_file file;
haggis_filename target;
haggis_device dev;
} f_type;
} haggis_filetype;
typedef struct {
haggis_filename name;
u32 uid;
u32 gid;
u64 mtime;
u16 mode;
haggis_filetype filetype;
} haggis_node;
void haggis_node_deinit(haggis_node *node);
2023-08-07 18:55:47 -04:00
haggis_node* haggis_create_node(char *file, haggis_hardlink_list *list);
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);
2023-07-19 23:42:04 -04:00
#endif // !HAGGIS_H