Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
bzip3_decoder_mt_z.c
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
3 #2023 X March 21 19:50 PM Brasília Time
4
5* *
6* Licensa de Copia (C) <2024> <Aurora Boreal> *
7* *
8* Este programa e software livre: voce pode redistribuir isto e/ou *
9* modificar isto sobre os termos do GNU Licensa Geral Pública como 25
10* publicado pela Fundacao de Software Livre, tanto a versão 3 da *
11* Licensa, ou (dependendo da sua opcao) qualquer versao posterior. *
12* *
13* Este programa e distribuido na esperanca que isto vai ser util, *
14* mas SEM QUALQUER GARANTIA; sem ate mesmo a implicada garantia de *
15* COMERCIALIZAcaO ou CABIMENTO PARA UM FIM PARTICULAR. Veja a *
16* Licensa Geral Publica para mais detalhes. *
17* *
18* Você deve ter recebido uma cópia da LICENSA GERAL PUBLICA e a GNU *
19* Licensa Publica Menor junto com este programa *
20* Se não, veja <http://www.gnu.org/licenses/>. *
21* *
22* Suporte: sourceforge.net github.com *
23* *
24* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
25
26* Pereira: arsoftware25@gmail.com ricardo@arsoftware.net.br *
27* xcx: arsoftware10@gmail.com charli@arsoftware.net.br *
28 Yasmin: yasmin@arsoftware.net.br *
29 pereira1001@users.sourceforge.net
30 */
31
32// #define CHUNK 131072 /* to never change again */
33
35 FILE *dest, my_thread_struct_z *amanda)
36{
37 __int64 totalbytes = 0;
38 ar_data ar = {
39 0,
40 };
41 bz_stream strm = {
42 0,
43 };
44 char sha512_temp_k[SHA512_DIGEST_LENGTH];
45 char signature_z[5] = "AR__";
46 char *buffer = malloc(CHUNK);
47 char *out = malloc(CHUNK);
48 char *sha512_ptr = NULL;
49 int done = 0;
50 int ret_arp;
51 int ret_z;
52 int retvalue = 0;
53 int writebytes;
54 int64_t remaining_z;
55
56 // exit(38);
57
58 pedro_dprintf(-1, "decoder multi-thread running\n");
59
60 assert(NULL == dest);
61
62 intcancelxcx = 0;
63 intpausexcx = 0;
64
65 signature_z[3] = '_' - 2; // bzip3 multi-thread signature...
66
67 ret_z = BZ2_bzDecompressInit(&strm, 0, 0);
68
69 if (BZ_OK != ret_z)
70 {
71 retvalue = 121;
72 goto saida_13_march_2021__12_12_12;
73 }
74
75 sha512_ptr = sha512_init_k_16();
76
77 amanda->size_of_input_file_copy_z = amanda->size_of_input_file_copy_z + sizeof(int64_t) + sizeof(ar);
79
81
82 remaining_z = amanda->size_of_input_file_z;
83
84 pedro_dprintf(-1, "seek to %lld\n", amanda->offset_z);
85
86 assert((int)0 <= (int)amanda->offset_z - (int)sizeof(int64_t) - (int)sizeof(ar));
87
88 if (
89 0 != _fseeki64(
90 amanda->input_file,
91 amanda->offset_z - sizeof(int64_t) - sizeof(ar),
92 SEEK_SET))
93 {
94 amanda->retvalue = 403; // File access error
95 goto saida_13_march_2021__12_12_12;
96 }
97
98 memset(&ar, 0, sizeof(ar));
99 ret_z = fread(&ar, 1, min(sizeof(ar), amanda->size_of_input_file_copy_z), amanda->input_file);
100
101 if (ret_z != sizeof(ar))
102 {
103
104 retvalue = 122;
105 goto saida_13_march_2021__12_12_12;
106 }
107 amanda->size_of_input_file_copy_z -= ret_z;
108 if (0 != memcmp(ar.string, signature_z, 4))
109 {
110
111 retvalue = 199;
112 goto saida_13_march_2021__12_12_12;
113 }
114
115 ret_z = fread(&remaining_z, 1, min(sizeof(remaining_z), amanda->size_of_input_file_copy_z), amanda->input_file);
116
117 if (sizeof(remaining_z) != ret_z)
118 {
119 retvalue = 122;
120 goto saida_13_march_2021__12_12_12;
121 }
122
124 ret_z;
125
126 if (0 > remaining_z)
127 {
128 retvalue = 500;
129 goto saida_13_march_2021__12_12_12;
130 }
131
132 if (amanda->size_of_input_file_copy_z != remaining_z)
133 {
134 retvalue = 500;
135 goto saida_13_march_2021__12_12_12;
136 }
137
138 for (;;)
139 {
140 while (*(amanda->intpausexcx))
141 {
142
143 Sleep(50);
144
145 if (*(amanda->intcancelxcx))
146 {
147 amanda->internal_error_arp = 119;
148 goto saida_13_march_2021__12_12_12;
149 }
150 }
151
152 if (*(amanda->intcancelxcx))
153 {
154 amanda->internal_error_arp = 119;
155 goto saida_13_march_2021__12_12_12;
156 }
157
158 ret_z = fread(buffer, 1, min(CHUNK, remaining_z /* só se for superior a int64_t max, isto nao vai acontecer */), amanda->input_file);
159 // ret = fread (buffer, 1, min(CHUNK, remaining_z), source);
160
161 if (0 > ret_z)
162 {
163 retvalue = 122;
164 goto saida_13_march_2021__12_12_12;
165 }
166
167 if ((0 == ret_z) || done)
168 {
169 goto saida_13_march_2021__12_12_12;
170 }
171 *(amanda->bytes_read_z) += ret_z;
172 remaining_z -= ret_z;
173 strm.next_in = buffer;
174 strm.avail_in = ret_z;
175
176 volta:
177
178 strm.next_out = out;
179 strm.avail_out = CHUNK;
180 ret_z = BZ2_bzDecompress(&strm);
181 writebytes = CHUNK - strm.avail_out;
182 if (writebytes > 0)
183 {
184 sha512_update_k_16(sha512_ptr, (unsigned char *)out, writebytes);
185 if (0 == (ret_arp = fwrite(out, 1, writebytes, amanda->dest)))
186 {
187 amanda->internal_error_arp = 6;
188 retvalue = 14;
189 goto saida_13_march_2021__12_12_12;
190 }
191 if (ret_arp != writebytes)
192 {
193 amanda->internal_error_arp = 6;
194 retvalue = 14;
195 goto saida_13_march_2021__12_12_12;
196 }
197 }
198 switch (ret_z)
199 {
200 case BZ_OK:
201
202 if (0 == strm.avail_out)
203 {
204 goto volta;
205 }
206
207 break;
208
209 case BZ_DATA_ERROR:
210
211 retvalue = 126;
212 goto saida_13_march_2021__12_12_12;
213 break;
214
215 case BZ_MEM_ERROR:
216#ifdef NPRINTF
217 dprintf("BZ_MEM_ERROR \n");
218#endif
219 retvalue = 125;
220 goto saida_13_march_2021__12_12_12;
221 break;
222
224 retvalue = 198;
225 goto saida_13_march_2021__12_12_12;
226 break;
227
228 case BZ_STREAM_END:
229
230 done = 1;
231 break;
232 default:
233 assert(0);
234 break;
235 }
236 }
237
238saida_13_march_2021__12_12_12:;
239
240 if ((0 == retvalue) && (totalbytes > (int64_t)sizeof(ar)))
241 {
242
243 sha512_final_k_16(sha512_ptr, (void *)sha512_temp_k); // only will be closed if no error occur,
244 // but if an error occur it need to finish the execution
245
246 if (0 != memcmp(sha512_temp_k, ar.digest_k, SHA512_DIGEST_LENGTH))
247 {
248 pedro_dprintf(-1, "erro 20");
249 retvalue = 300;
250 }
251 }
252
253 if (totalbytes > (int64_t)sizeof(ar))
254 {
255
256 if ((0 == done) && (0 == retvalue))
257 {
258
259 retvalue = 124; // who did it?....
260 }
261 }
262
264
265 if (*(amanda->intcancelxcx))
266 {
267 retvalue = 119;
268 }
269 *(amanda->bytes_read_z) = totalbytes_z;
270 free(buffer);
271 free(out);
272
273 pedro_dprintf(-1, "erro que deu interno %d\n", retvalue);
274
275 return retvalue;
276}
void pedro_dprintf(int amanda_level, char *format,...)
Definition pedro.c:43
void dprintf(char *format,...)
Definition dprintf.c:96
#define CHUNK
Definition brotli2.c:163
void * sha512_init_k_16(void)
Definition sha512_k.c:827
#define SHA512_DIGEST_LENGTH
Definition bzip3.c:41
void sha512_final_k_16(void *ctx, unsigned char *array_digest_64_bytes)
Definition sha512_k.c:852
int64_t totalbytes_z
Definition bzip3.c:586
void sha512_update_k_16(void *ctx, unsigned char *buffer_k, unsigned int len_k)
Definition sha512_k.c:844
int zuncompress_sha512_k_mt_decoding_multi_thread_z(__attribute__((unused)) FILE *source, FILE *dest, my_thread_struct_z *amanda)
Definition bzip3_decoder_mt_z.c:34
#define assert(condition)
Definition lz4.c:273
const char * source
Definition lz4.h:808
char * dest
Definition lz4.h:806
#define __attribute__(unused_ric_since_2004)
Definition main_cr.c:84
#define min(a, b)
Definition compress42.c:304
Definition stdio_v3.h:12
unsigned char digest_k[SHA512_DIGEST_LENGTH]
Definition bzip3_structs_z.h:15
char string[4]
Definition stdio_v3.h:13
Definition bzlib.h:49
char * next_in
Definition bzlib.h:50
unsigned int avail_in
Definition bzlib.h:51
char * next_out
Definition bzlib.h:55
unsigned int avail_out
Definition bzlib.h:56
Definition stdio_v3.h:23
int64_t offset_z
Definition stdio_v3.h:44
int64_t size_of_input_file_copy_z
Definition stdio_v3.h:46
int retvalue
Definition stdio_v3.h:39
int64_t * bytes_read_z
Definition stdio_v3.h:43
int * intcancelxcx
Definition bzip3_structs_z.h:58
int * intpausexcx
Definition bzip3_structs_z.h:57
FILE * dest
Definition stdio_v3.h:26
int internal_error_arp
Definition stdio_v3.h:36
FILE * input_file
Definition stdio_v3.h:35
int64_t size_of_input_file_z
Definition stdio_v3.h:47
BZ_EXTERN int BZ_API BZ2_bzDecompressInit(bz_stream *strm, int verbosity, int small)
Definition bzlib.c:556
#define BZ_MEM_ERROR
Definition bzlib.h:40
BZ_EXTERN int BZ_API BZ2_bzDecompressEnd(bz_stream *strm)
Definition bzlib.c:1060
#define BZ_DATA_ERROR_MAGIC
Definition bzlib.h:42
#define BZ_OK
Definition bzlib.h:33
BZ_EXTERN int BZ_API BZ2_bzDecompress(bz_stream *strm)
Definition bzlib.c:993
#define BZ_DATA_ERROR
Definition bzlib.h:41
#define BZ_STREAM_END
Definition bzlib.h:37
int intpausexcx
Definition bzip2dll.c:226
int intcancelxcx
Definition bzip2dll.c:227
#define SEEK_SET
Definition zconf.h:498
const lzma_allocator const uint8_t size_t uint8_t * out
Definition block.h:528
#define NULL
Definition getopt1.c:37
totalbytes
Definition zlib_interface.c:43
signature_z[3]
Definition zlib_interface.c:37