Lines Matching refs:ctx

46 void image_init(image *ctx)  in image_init()  argument
48 memset(ctx, 0, sizeof(*ctx)); in image_init()
51 void image_free(image *ctx) in image_free() argument
53 assert(ctx->input == ctx->output); in image_free()
55 if (ctx->input) { in image_free()
56 delete[] ctx->input; in image_free()
59 if (ctx->fec) { in image_free()
60 delete[] ctx->fec; in image_free()
63 image_init(ctx); in image_free()
66 static void calculate_rounds(uint64_t size, image *ctx) in calculate_rounds() argument
75 ctx->inp_size = size; in calculate_rounds()
76 ctx->blocks = fec_div_round_up(ctx->inp_size, FEC_BLOCKSIZE); in calculate_rounds()
77 ctx->rounds = fec_div_round_up(ctx->blocks, ctx->rs_n); in calculate_rounds()
82 image *ctx = (image *)priv; in process_chunk() local
86 memcpy(&ctx->input[ctx->pos], data, len); in process_chunk()
89 ctx->pos += len; in process_chunk()
93 static void file_image_load(const std::vector<int>& fds, image *ctx) in file_image_load() argument
102 if (ctx->sparse) { in file_image_load()
105 file = sparse_file_import_auto(fd, false, ctx->verbose); in file_image_load()
109 FATAL("failed to read file %s\n", ctx->fec_filename); in file_image_load()
118 calculate_rounds(size, ctx); in file_image_load()
120 if (ctx->verbose) { in file_image_load()
121 INFO("allocating %" PRIu64 " bytes of memory\n", ctx->inp_size); in file_image_load()
124 ctx->input = new uint8_t[ctx->inp_size]; in file_image_load()
126 if (!ctx->input) { in file_image_load()
130 memset(ctx->input, 0, ctx->inp_size); in file_image_load()
131 ctx->output = ctx->input; in file_image_load()
132 ctx->pos = 0; in file_image_load()
135 sparse_file_callback(file, false, false, process_chunk, ctx); in file_image_load()
144 bool image_load(const std::vector<std::string>& filenames, image *ctx) in image_load() argument
146 assert(ctx->roots > 0 && ctx->roots < FEC_RSM); in image_load()
147 ctx->rs_n = FEC_RSM - ctx->roots; in image_load()
151 if (ctx->inplace) { in image_load()
167 file_image_load(fds, ctx); in image_load()
172 bool image_save(const std::string& filename, image *ctx) in image_save() argument
183 if (!android::base::WriteFully(fd, ctx->output, ctx->inp_size)) { in image_save()
191 bool image_ecc_new(const std::string& filename, image *ctx) in image_ecc_new() argument
193 assert(ctx->rounds > 0); /* image_load should be called first */ in image_ecc_new()
195 ctx->fec_filename = filename.c_str(); in image_ecc_new()
196 ctx->fec_size = ctx->rounds * ctx->roots * FEC_BLOCKSIZE; in image_ecc_new()
198 if (ctx->verbose) { in image_ecc_new()
199 INFO("allocating %u bytes of memory\n", ctx->fec_size); in image_ecc_new()
202 ctx->fec = new uint8_t[ctx->fec_size]; in image_ecc_new()
204 if (!ctx->fec) { in image_ecc_new()
205 FATAL("failed to allocate %u bytes\n", ctx->fec_size); in image_ecc_new()
211 bool image_ecc_load(const std::string& filename, image *ctx) in image_ecc_load() argument
257 ctx->roots = (int)p->roots; in image_ecc_load()
258 ctx->rs_n = FEC_RSM - ctx->roots; in image_ecc_load()
260 calculate_rounds(p->inp_size, ctx); in image_ecc_load()
262 if (!image_ecc_new(filename, ctx)) { in image_ecc_load()
266 if (p->fec_size != ctx->fec_size) { in image_ecc_load()
274 if (!android::base::ReadFully(fd, ctx->fec, ctx->fec_size)) { in image_ecc_load()
275 FATAL("failed to read %u bytes from '%s': %s\n", ctx->fec_size, in image_ecc_load()
282 SHA256(ctx->fec, ctx->fec_size, hash); in image_ecc_load()
291 bool image_ecc_save(image *ctx) in image_ecc_save() argument
302 f->roots = ctx->roots; in image_ecc_save()
303 f->fec_size = ctx->fec_size; in image_ecc_save()
304 f->inp_size = ctx->inp_size; in image_ecc_save()
306 SHA256(ctx->fec, ctx->fec_size, f->hash); in image_ecc_save()
312 assert(ctx->fec_filename); in image_ecc_save()
314 int fd = TEMP_FAILURE_RETRY(open(ctx->fec_filename, in image_ecc_save()
318 FATAL("failed to open file '%s': %s\n", ctx->fec_filename, in image_ecc_save()
322 if (!android::base::WriteFully(fd, ctx->fec, ctx->fec_size)) { in image_ecc_save()
326 if (ctx->padding > 0) { in image_ecc_save()
329 for (uint32_t i = 0; i < ctx->padding; i += FEC_BLOCKSIZE) { in image_ecc_save()
347 image_proc_ctx *ctx = (image_proc_ctx *)cookie; in process() local
348 ctx->func(ctx); in process()
352 bool image_process(image_proc_func func, image *ctx) in image_process() argument
354 int threads = ctx->threads; in image_process()
364 assert(ctx->rounds > 0); in image_process()
366 if ((uint64_t)threads > ctx->rounds) { in image_process()
367 threads = (int)ctx->rounds; in image_process()
373 if (ctx->verbose) { in image_process()
375 ctx->rs_n); in image_process()
382 uint64_t end = ctx->rounds * ctx->rs_n * FEC_BLOCKSIZE; in image_process()
384 fec_div_round_up(ctx->rounds * FEC_BLOCKSIZE, threads); in image_process()
386 if (ctx->verbose) { in image_process()
393 args[i].ctx = ctx; in image_process()
395 args[i].fec_pos = current * ctx->roots; in image_process()
396 args[i].start = current * ctx->rs_n; in image_process()
397 args[i].end = (current + rs_blocks_per_thread) * ctx->rs_n; in image_process()
399 args[i].rs = init_rs_char(FEC_PARAMS(ctx->roots)); in image_process()
408 ctx->rs_n > end) { in image_process()
412 if (ctx->verbose) { in image_process()
418 assert((args[i].end - args[i].start) % ctx->rs_n == 0); in image_process()
427 ctx->rv = 0; in image_process()
434 ctx->rv += args[i].rv; in image_process()