
Link to libmd for cryptographic hash functions and implement comparing checksums when loading a file from an archive;
121 lines
3 KiB
C
121 lines
3 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;
|
|
|
|
union u16 {
|
|
uint16_t val;
|
|
u8 bytes[2];
|
|
};
|
|
|
|
union u32 {
|
|
uint32_t val;
|
|
u8 bytes[4];
|
|
};
|
|
|
|
union u64 {
|
|
uint64_t val;
|
|
u8 bytes[8];
|
|
};
|
|
|
|
struct haggis_device {
|
|
union u32 major;
|
|
union u32 minor;
|
|
};
|
|
|
|
enum haggis_algorithm {
|
|
md5,
|
|
sha1,
|
|
sha256,
|
|
skip,
|
|
};
|
|
|
|
union haggis_sum {
|
|
u8 md5[16];
|
|
u8 sha1[20];
|
|
u8 sha256[32];
|
|
};
|
|
|
|
struct haggis_checksum {
|
|
enum haggis_algorithm tag;
|
|
union haggis_sum *sum;
|
|
};
|
|
|
|
struct haggis_file {
|
|
union u64 len;
|
|
struct haggis_checksum *cksum;
|
|
u8 *data[];
|
|
};
|
|
|
|
struct haggis_filename {
|
|
union u16 len;
|
|
u8 name[4096];
|
|
};
|
|
|
|
enum haggis_typeflag {
|
|
normal,
|
|
hardlink,
|
|
softlink,
|
|
directory,
|
|
character,
|
|
block,
|
|
fifo,
|
|
eof,
|
|
};
|
|
|
|
union haggis_ft {
|
|
struct haggis_file *file;
|
|
struct haggis_filename *target;
|
|
struct haggis_device *dev;
|
|
};
|
|
|
|
struct haggis_filetype {
|
|
enum haggis_typeflag tag;
|
|
union haggis_ft *f_type;
|
|
};
|
|
|
|
struct haggis_node {
|
|
union u32 uid;
|
|
union u32 gid;
|
|
union u64 mtime;
|
|
union u16 mode;
|
|
struct haggis_filetype *filetype;
|
|
char *name[];
|
|
};
|
|
|
|
#endif // !HAGGIS_H
|