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
|
2023-08-07 23:37:47 -04:00
|
|
|
#define HAGGIS_H 1
|
2023-07-19 23:42:04 -04:00
|
|
|
|
2023-08-07 18:55:47 -04:00
|
|
|
#include "linklist.h"
|
2023-08-07 19:15:20 -04:00
|
|
|
#include <stdint.h> // uint<x>_t
|
|
|
|
#include <stdio.h> // FILE
|
2023-07-19 23:42:04 -04:00
|
|
|
|
2023-07-20 18:20:04 -04:00
|
|
|
typedef uint8_t u8;
|
|
|
|
|
2023-07-29 18:18:11 -04:00
|
|
|
typedef union {
|
2023-07-22 11:37:11 -04:00
|
|
|
uint16_t val;
|
|
|
|
u8 bytes[2];
|
2023-07-29 18:18:11 -04:00
|
|
|
} u16;
|
2023-07-22 11:37:11 -04:00
|
|
|
|
2023-07-29 18:18:11 -04:00
|
|
|
typedef union {
|
2023-07-22 11:37:11 -04:00
|
|
|
uint32_t val;
|
|
|
|
u8 bytes[4];
|
2023-07-29 18:18:11 -04:00
|
|
|
} u32;
|
2023-07-22 11:37:11 -04:00
|
|
|
|
2023-07-29 18:18:11 -04:00
|
|
|
typedef union {
|
2023-07-22 11:37:11 -04:00
|
|
|
uint64_t val;
|
|
|
|
u8 bytes[8];
|
2023-07-29 18:18:11 -04:00
|
|
|
} u64;
|
2023-07-22 11:37:11 -04:00
|
|
|
|
2023-07-28 18:39:30 -04:00
|
|
|
typedef struct {
|
|
|
|
u32 major;
|
|
|
|
u32 minor;
|
|
|
|
} haggis_device;
|
2023-07-19 23:42:04 -04:00
|
|
|
|
2023-07-28 18:39:30 -04:00
|
|
|
typedef enum {
|
2023-07-19 23:42:04 -04:00
|
|
|
md5,
|
|
|
|
sha1,
|
|
|
|
sha256,
|
|
|
|
skip,
|
2023-07-28 18:39:30 -04:00
|
|
|
} haggis_algorithm;
|
2023-07-19 23:42:04 -04:00
|
|
|
|
2023-07-28 18:39:30 -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;
|
2023-07-28 18:39:30 -04:00
|
|
|
} haggis_checksum;
|
2023-07-19 23:42:04 -04:00
|
|
|
|
2023-07-28 18:39:30 -04:00
|
|
|
typedef struct {
|
|
|
|
u64 len;
|
2023-08-07 23:37:47 -04:00
|
|
|
haggis_checksum cksum;
|
2023-07-23 23:42:51 -04:00
|
|
|
u8 *data;
|
2023-07-28 18:39:30 -04:00
|
|
|
} haggis_file;
|
2023-07-22 11:37:11 -04:00
|
|
|
|
2023-07-28 18:39:30 -04:00
|
|
|
typedef struct {
|
|
|
|
u16 len;
|
2023-07-23 23:42:51 -04:00
|
|
|
char *name;
|
2023-07-28 18:39:30 -04:00
|
|
|
} haggis_filename;
|
2023-07-19 23:42:04 -04:00
|
|
|
|
2023-07-28 18:39:30 -04:00
|
|
|
typedef enum {
|
2023-07-19 23:42:04 -04:00
|
|
|
normal,
|
|
|
|
hardlink,
|
|
|
|
softlink,
|
|
|
|
directory,
|
|
|
|
character,
|
|
|
|
block,
|
|
|
|
fifo,
|
|
|
|
eof,
|
2023-07-28 18:39:30 -04:00
|
|
|
} 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;
|
2023-07-28 18:39:30 -04:00
|
|
|
} haggis_filetype;
|
|
|
|
|
|
|
|
typedef struct {
|
2023-08-08 01:25:15 -04:00
|
|
|
haggis_filename name;
|
2023-07-28 18:39:30 -04:00
|
|
|
u32 uid;
|
|
|
|
u32 gid;
|
|
|
|
u64 mtime;
|
|
|
|
u16 mode;
|
2023-08-08 01:25:15 -04:00
|
|
|
haggis_filetype filetype;
|
2023-07-28 18:39:30 -04:00
|
|
|
} haggis_node;
|
|
|
|
|
2023-08-07 23:37:47 -04:00
|
|
|
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);
|
2023-07-28 18:39:30 -04:00
|
|
|
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-24 18:56:04 -04:00
|
|
|
|
2023-07-19 23:42:04 -04:00
|
|
|
#endif // !HAGGIS_H
|