-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpar2.h
151 lines (125 loc) · 3.08 KB
/
par2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#ifndef SPAR_PAR2_H
#define SPAR_PAR2_H
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "spar2_version.h"
#include "diskfile.h"
#include "common.h"
#define SET_MD5(a,b) ({ \
for ( int _i = 0; _i < 16; _i++ ) \
((unsigned char*)(a))[_i] = ((unsigned char*)(b))[_i]; \
})
#define SET_HEADER(hdr, recid, ptype, plength) ({ \
for ( int _i = 0; _i < 8; _i++ ) \
hdr->magic[_i] = PAR2_MAGIC[_i]; \
\
for ( int _i = 0; _i < 16; _i++ ) \
hdr->type[_i] = ptype[_i]; \
\
for ( int _i = 0; _i < 16; _i++ ) \
hdr->packet_md5[_i] = 0; \
\
SET_MD5(hdr->recovery_id, recid); \
\
hdr->length = plength; \
})
#define SET_CREATOR(a,s,n) ({ \
for ( int _i = 0; _i < (n); _i++ ) \
(a)[_i] = s[_i]; \
})
/********** PACKET STRINGS **********/
char PACKET_MAIN[] = "PAR 2.0\0Main\0\0\0\0";
char PACKET_FILEDESC[] = "PAR 2.0\0FileDesc";
char PACKET_IFSC[] = "PAR 2.0\0IFSC\0\0\0\0";
char PACKET_RECVSLIC[] = "PAR 2.0\0RecvSlic";
char PACKET_CREATOR[] = "PAR 2.0\0Creator\0";
char PAR2_MAGIC[] = "PAR2\0PKT";
char PAR2_CREATOR[] = "Created by Simple Par (spar2) revision \"" SPAR_VERSION "\"\0";
char PAR2_PAR2CMDLINE[] = "Created by par2cmdline version 0.4.\0";
/************* PACKETS **************/
#pragma pack(1)
// Packet Header
typedef struct {
char magic[8];
uint64_t length;
md5_t packet_md5;
md5_t recovery_id;
char type[16];
} pkt_header_t;
// Main Packet
typedef struct
{
pkt_header_t header;
uint64_t slice_size;
uint32_t n_files;
//md5_t *fid_recovery;
//md5_t *fid_non_recovery;
} pkt_main_t;
// File Description Packet
typedef struct
{
pkt_header_t header;
md5_t fid;
md5_t hash_full;
md5_t hash_16k;
uint64_t flength;
//char *fname; // ?*4 bytes long
} pkt_filedesc_t;
// Input File Slice Checksum packet
typedef struct
{
pkt_header_t header;
md5_t fid;
//checksum_t *slice_checksums;
} pkt_ifsc_t;
// Recovery Slice Packet
typedef struct
{
pkt_header_t header;
uint32_t exponent;
//char *data; // ?*4 bytes long
} pkt_recvslice_t;
// Creator Packet
typedef struct
{
pkt_header_t header;
//char creator[]; // ?*4 bytes long
} pkt_creator_t;
#pragma pack()
/************* MAIN STRUCT **************/
typedef struct
{
// Input Files
diskfile_t *input_files;
int n_input_files;
uint16_t n_input_slices;
size_t largest_filesize;
// Program Options
float redundancy;
uint64_t blocksize;
md5_t recovery_id;
uint16_t n_recovery_blocks;
uint16_t max_blocks_per_file;
int n_threads;
int blocks_per_thread;
size_t memory_max;
// Par2 File Output
int mimic; // Mimic par2cmdline's creator packet?
char par2_fnformat[300];
char *basename;
int n_recovery_files;
char **recovery_filenames;
int n_critical_packets;
pkt_header_t **critical_packets; // Array of pointers to the critical packets
} spar_t;
typedef struct
{
spar_t *h;
int block_start;
int block_end; // Inclusive
pthread_t thread;
uint16_t **recv_data;
progress_t *progress;
} thread_t;
#endif