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-18 12:37:24 -04:00
|
|
|
#include <pthread.h> // pthread_mutex_t
|
2023-08-07 19:15:20 -04:00
|
|
|
#include <stdint.h> // uint<x>_t
|
|
|
|
#include <stdio.h> // FILE
|
2023-08-18 12:37:24 -04:00
|
|
|
#include <sys/types.h> // ino_t
|
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;
|
2024-02-11 01:09:21 -05:00
|
|
|
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;
|
2024-02-11 01:09:21 -05:00
|
|
|
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;
|
2024-02-11 01:09:21 -05:00
|
|
|
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 {
|
2024-02-11 01:09:21 -05:00
|
|
|
u8 md5[16];
|
|
|
|
u8 sha1[20];
|
|
|
|
u8 sha256[32];
|
|
|
|
};
|
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 {
|
2024-02-11 01:09:21 -05:00
|
|
|
u64 len;
|
|
|
|
haggis_checksum cksum;
|
|
|
|
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 {
|
2024-02-11 01:09:21 -05:00
|
|
|
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 {
|
2024-02-11 01:09:21 -05:00
|
|
|
haggis_typeflag tag;
|
2023-08-08 01:40:21 -04:00
|
|
|
union {
|
2024-02-11 01:09:21 -05:00
|
|
|
haggis_file file;
|
2023-08-08 01:40:21 -04:00
|
|
|
haggis_filename target;
|
2024-02-11 01:09:21 -05:00
|
|
|
haggis_device dev;
|
|
|
|
};
|
2023-07-28 18:39:30 -04:00
|
|
|
} haggis_filetype;
|
|
|
|
|
|
|
|
typedef struct {
|
2023-08-08 01:25:15 -04:00
|
|
|
haggis_filename name;
|
2024-02-11 01:09:21 -05: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-18 12:37:24 -04:00
|
|
|
#define HAGGIS_BUCKETS_BASE 64
|
|
|
|
|
|
|
|
typedef struct __bucket {
|
|
|
|
union {
|
2024-02-11 01:09:21 -05:00
|
|
|
ino_t val;
|
2023-08-18 12:37:24 -04:00
|
|
|
uint8_t bytes[sizeof(ino_t)];
|
2024-02-11 01:09:21 -05:00
|
|
|
} key;
|
|
|
|
uint64_t hash;
|
|
|
|
char *path;
|
2023-08-18 12:37:24 -04:00
|
|
|
} haggis_bucket;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
pthread_mutex_t mutex;
|
2024-02-11 01:09:21 -05:00
|
|
|
size_t len;
|
|
|
|
size_t capacity;
|
|
|
|
haggis_bucket *buckets;
|
2023-08-18 12:37:24 -04:00
|
|
|
} haggis_linkmap;
|
|
|
|
|
2023-09-19 00:34:27 -04:00
|
|
|
typedef enum {
|
2023-10-03 13:16:25 -04:00
|
|
|
DevNodeSkipped,
|
2023-09-19 00:34:27 -04:00
|
|
|
NodeCreated,
|
|
|
|
NodeExtracted,
|
|
|
|
EndOfArchive,
|
|
|
|
ArchiveError,
|
|
|
|
} haggis_message_type;
|
|
|
|
|
|
|
|
typedef union {
|
|
|
|
char *f_name;
|
2024-02-11 01:09:21 -05:00
|
|
|
int err;
|
2023-09-19 00:34:27 -04:00
|
|
|
} haggis_message_body;
|
|
|
|
|
|
|
|
struct _mq_node {
|
2024-02-11 01:09:21 -05:00
|
|
|
struct _mq_node *prev;
|
|
|
|
struct _mq_node *next;
|
2023-09-19 00:34:27 -04:00
|
|
|
haggis_message_type tag;
|
|
|
|
haggis_message_body body;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _mq_node haggis_msg;
|
|
|
|
|
|
|
|
typedef struct {
|
2024-02-11 01:09:21 -05:00
|
|
|
pthread_cond_t cond;
|
|
|
|
size_t count;
|
|
|
|
pthread_mutex_t mutex;
|
|
|
|
haggis_msg *head;
|
|
|
|
haggis_msg *tail;
|
2023-09-19 00:34:27 -04:00
|
|
|
} haggis_mq;
|
|
|
|
|
2024-02-11 01:09:21 -05:00
|
|
|
haggis_linkmap* haggis_linkmap_init ();
|
|
|
|
void haggis_linkmap_deinit (haggis_linkmap *self);
|
|
|
|
char* haggis_linkmap_get_or_add(haggis_linkmap *self, ino_t inode, char *path);
|
|
|
|
void haggis_node_deinit (haggis_node *self);
|
|
|
|
haggis_node* haggis_create_node (char *file, haggis_algorithm a, haggis_linkmap *map,
|
|
|
|
haggis_mq *mq);
|
|
|
|
int haggis_extract_node (haggis_node *self, char *basedir, haggis_mq *mq);
|
|
|
|
int haggis_load_node (haggis_node *self, FILE *stream);
|
|
|
|
int haggis_store_node (haggis_node *self, FILE *stream);
|
2023-07-24 18:56:04 -04:00
|
|
|
|
2023-07-19 23:42:04 -04:00
|
|
|
#endif // !HAGGIS_H
|