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
85 memcpy(&ctx->input[ctx->pos], data, len); in process_chunk()
88 ctx->pos += len; in process_chunk()
92 static void file_image_load(const std::vector<int>& fds, image *ctx) in file_image_load() argument
101 if (ctx->sparse) { in file_image_load()
104 file = sparse_file_import_auto(fd, false, ctx->verbose); in file_image_load()
108 FATAL("failed to read file %s\n", ctx->fec_filename); in file_image_load()
117 calculate_rounds(size, ctx); in file_image_load()
119 if (ctx->verbose) { in file_image_load()
120 INFO("allocating %" PRIu64 " bytes of memory\n", ctx->inp_size); in file_image_load()
123 ctx->input = new uint8_t[ctx->inp_size]; in file_image_load()
125 if (!ctx->input) { in file_image_load()
129 memset(ctx->input, 0, ctx->inp_size); in file_image_load()
130 ctx->output = ctx->input; in file_image_load()
131 ctx->pos = 0; in file_image_load()
134 sparse_file_callback(file, false, false, process_chunk, ctx); in file_image_load()
138 assert(ctx->pos % FEC_BLOCKSIZE == 0); in file_image_load()
145 bool image_load(const std::vector<std::string>& filenames, image *ctx) in image_load() argument
147 assert(ctx->roots > 0 && ctx->roots < FEC_RSM); in image_load()
148 ctx->rs_n = FEC_RSM - ctx->roots; in image_load()
152 if (ctx->inplace) { in image_load()
168 file_image_load(fds, ctx); in image_load()
173 bool image_save(const std::string& filename, image *ctx) in image_save() argument
184 if (!android::base::WriteFully(fd, ctx->output, ctx->inp_size)) { in image_save()
192 bool image_ecc_new(const std::string& filename, image *ctx) in image_ecc_new() argument
194 assert(ctx->rounds > 0); /* image_load should be called first */ in image_ecc_new()
196 ctx->fec_filename = filename.c_str(); in image_ecc_new()
197 ctx->fec_size = ctx->rounds * ctx->roots * FEC_BLOCKSIZE; in image_ecc_new()
199 if (ctx->verbose) { in image_ecc_new()
200 INFO("allocating %u bytes of memory\n", ctx->fec_size); in image_ecc_new()
203 ctx->fec = new uint8_t[ctx->fec_size]; in image_ecc_new()
205 if (!ctx->fec) { in image_ecc_new()
206 FATAL("failed to allocate %u bytes\n", ctx->fec_size); in image_ecc_new()
212 bool image_ecc_load(const std::string& filename, image *ctx) in image_ecc_load() argument
258 ctx->roots = (int)p->roots; in image_ecc_load()
259 ctx->rs_n = FEC_RSM - ctx->roots; in image_ecc_load()
261 calculate_rounds(p->inp_size, ctx); in image_ecc_load()
263 if (!image_ecc_new(filename, ctx)) { in image_ecc_load()
267 if (p->fec_size != ctx->fec_size) { in image_ecc_load()
275 if (!android::base::ReadFully(fd, ctx->fec, ctx->fec_size)) { in image_ecc_load()
276 FATAL("failed to read %u bytes from '%s': %s\n", ctx->fec_size, in image_ecc_load()
283 SHA256(ctx->fec, ctx->fec_size, hash); in image_ecc_load()
292 bool image_ecc_save(image *ctx) in image_ecc_save() argument
303 f->roots = ctx->roots; in image_ecc_save()
304 f->fec_size = ctx->fec_size; in image_ecc_save()
305 f->inp_size = ctx->inp_size; in image_ecc_save()
307 SHA256(ctx->fec, ctx->fec_size, f->hash); in image_ecc_save()
313 assert(ctx->fec_filename); in image_ecc_save()
315 int fd = TEMP_FAILURE_RETRY(open(ctx->fec_filename, in image_ecc_save()
319 FATAL("failed to open file '%s': %s\n", ctx->fec_filename, in image_ecc_save()
323 if (!android::base::WriteFully(fd, ctx->fec, ctx->fec_size)) { in image_ecc_save()
327 if (ctx->padding > 0) { in image_ecc_save()
330 for (uint32_t i = 0; i < ctx->padding; i += FEC_BLOCKSIZE) { in image_ecc_save()
348 image_proc_ctx *ctx = (image_proc_ctx *)cookie; in process() local
349 ctx->func(ctx); in process()
353 bool image_process(image_proc_func func, image *ctx) in image_process() argument
355 int threads = ctx->threads; in image_process()
365 assert(ctx->rounds > 0); in image_process()
367 if ((uint64_t)threads > ctx->rounds) { in image_process()
368 threads = (int)ctx->rounds; in image_process()
374 if (ctx->verbose) { in image_process()
376 ctx->rs_n); in image_process()
383 uint64_t end = ctx->rounds * ctx->rs_n * FEC_BLOCKSIZE; in image_process()
385 fec_div_round_up(ctx->rounds * FEC_BLOCKSIZE, threads); in image_process()
387 if (ctx->verbose) { in image_process()
394 args[i].ctx = ctx; in image_process()
396 args[i].fec_pos = current * ctx->roots; in image_process()
397 args[i].start = current * ctx->rs_n; in image_process()
398 args[i].end = (current + rs_blocks_per_thread) * ctx->rs_n; in image_process()
400 args[i].rs = init_rs_char(FEC_PARAMS(ctx->roots)); in image_process()
409 ctx->rs_n > end) { in image_process()
413 if (ctx->verbose) { in image_process()
419 assert((args[i].end - args[i].start) % ctx->rs_n == 0); in image_process()
428 ctx->rv = 0; in image_process()
435 ctx->rv += args[i].rv; in image_process()