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
|
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/*
* block_processor.c
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
#define SQFS_BUILDING_DLL
#include "internal.h"
sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
sqfs_compressor_t *cmp,
unsigned int num_workers,
size_t max_backlog,
size_t devblksz,
sqfs_file_t *file)
{
sqfs_block_processor_t *proc;
(void)num_workers;
(void)max_backlog;
proc = alloc_flex(sizeof(*proc), 1, max_block_size);
if (proc == NULL)
return NULL;
proc->max_block_size = max_block_size;
proc->cmp = cmp;
proc->devblksz = devblksz;
proc->file = file;
proc->max_blocks = INIT_BLOCK_COUNT;
proc->frag_list_max = INIT_BLOCK_COUNT;
proc->blocks = alloc_array(sizeof(proc->blocks[0]), proc->max_blocks);
if (proc->blocks == NULL) {
free(proc);
return NULL;
}
proc->frag_list = alloc_array(sizeof(proc->frag_list[0]),
proc->frag_list_max);
if (proc->frag_list == NULL) {
free(proc->blocks);
free(proc);
return NULL;
}
return proc;
}
void sqfs_block_processor_destroy(sqfs_block_processor_t *proc)
{
free(proc->frag_block);
free(proc->frag_list);
free(proc->fragments);
free(proc->blocks);
free(proc);
}
int sqfs_block_processor_enqueue(sqfs_block_processor_t *proc,
sqfs_block_t *block)
{
sqfs_block_t *fragblk = NULL;
if (proc->status != 0) {
free(block);
return proc->status;
}
if (block->flags & ~SQFS_BLK_USER_SETTABLE_FLAGS) {
proc->status = SQFS_ERROR_UNSUPPORTED;
free(block);
return proc->status;
}
if (block->flags & SQFS_BLK_IS_FRAGMENT) {
block->checksum = crc32(0, block->data, block->size);
proc->status = handle_fragment(proc, block, &fragblk);
free(block);
if (proc->status != 0) {
free(fragblk);
return proc->status;
}
if (fragblk == NULL)
return 0;
block = fragblk;
}
proc->status = sqfs_block_process(block, proc->cmp, proc->scratch,
proc->max_block_size);
if (proc->status == 0)
proc->status = process_completed_block(proc, block);
free(block);
return proc->status;
}
int sqfs_block_processor_finish(sqfs_block_processor_t *proc)
{
if (proc->status != 0 || proc->frag_block == NULL)
return proc->status;
proc->status = sqfs_block_process(proc->frag_block, proc->cmp,
proc->scratch, proc->max_block_size);
if (proc->status == 0)
proc->status = process_completed_block(proc, proc->frag_block);
free(proc->frag_block);
proc->frag_block = NULL;
return proc->status;
}
|