Lines Matching defs:out
71 int (*write_data_chunk)(struct output_file *out, unsigned int len,
73 int (*write_fill_chunk)(struct output_file *out, unsigned int len,
75 int (*write_skip_chunk)(struct output_file *out, int64_t len);
76 int (*write_end_chunk)(struct output_file *out);
94 struct output_file out;
99 container_of((_o), struct output_file_gz, out)
102 struct output_file out;
107 container_of((_o), struct output_file_normal, out)
110 struct output_file out;
116 container_of((_o), struct output_file_callback, out)
118 static int file_open(struct output_file *out, int fd)
120 struct output_file_normal *outn = to_output_file_normal(out);
126 static int file_skip(struct output_file *out, int64_t cnt)
129 struct output_file_normal *outn = to_output_file_normal(out);
139 static int file_pad(struct output_file *out, int64_t len)
142 struct output_file_normal *outn = to_output_file_normal(out);
152 static int file_write(struct output_file *out, void *data, int len)
155 struct output_file_normal *outn = to_output_file_normal(out);
169 static void file_close(struct output_file *out)
171 struct output_file_normal *outn = to_output_file_normal(out);
184 static int gz_file_open(struct output_file *out, int fd)
186 struct output_file_gz *outgz = to_output_file_gz(out);
198 static int gz_file_skip(struct output_file *out, int64_t cnt)
201 struct output_file_gz *outgz = to_output_file_gz(out);
211 static int gz_file_pad(struct output_file *out, int64_t len)
214 struct output_file_gz *outgz = to_output_file_gz(out);
235 static int gz_file_write(struct output_file *out, void *data, int len)
238 struct output_file_gz *outgz = to_output_file_gz(out);
252 static void gz_file_close(struct output_file *out)
254 struct output_file_gz *outgz = to_output_file_gz(out);
268 static int callback_file_open(struct output_file *out __unused, int fd __unused)
273 static int callback_file_skip(struct output_file *out, int64_t off)
275 struct output_file_callback *outc = to_output_file_callback(out);
291 static int callback_file_pad(struct output_file *out __unused, int64_t len __unused)
296 static int callback_file_write(struct output_file *out, void *data, int len)
298 struct output_file_callback *outc = to_output_file_callback(out);
303 static void callback_file_close(struct output_file *out)
305 struct output_file_callback *outc = to_output_file_callback(out);
340 static int write_sparse_skip_chunk(struct output_file *out, int64_t skip_len)
345 if (skip_len % out->block_size) {
347 skip_len, out->block_size);
354 chunk_header.chunk_sz = skip_len / out->block_size;
356 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header));
360 out->cur_out_ptr += skip_len;
361 out->chunk_cnt++;
366 static int write_sparse_fill_chunk(struct output_file *out, unsigned int len,
374 rnd_up_len = ALIGN(len, out->block_size);
379 chunk_header.chunk_sz = rnd_up_len / out->block_size;
381 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header));
385 ret = out->ops->write(out, &fill_val, sizeof(fill_val));
389 if (out->use_crc) {
390 count = out->block_size / sizeof(uint32_t);
392 out->crc32 = sparse_crc32(out->crc32, &fill_val, sizeof(uint32_t));
395 out->cur_out_ptr += rnd_up_len;
396 out->chunk_cnt++;
401 static int write_sparse_data_chunk(struct output_file *out, unsigned int len,
409 rnd_up_len = ALIGN(len, out->block_size);
415 chunk_header.chunk_sz = rnd_up_len / out->block_size;
417 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header));
421 ret = out->ops->write(out, data, len);
425 ret = out->ops->write(out, out->zero_buf, zero_len);
430 if (out->use_crc) {
431 out->crc32 = sparse_crc32(out->crc32, data, len);
433 out->crc32 = sparse_crc32(out->crc32, out->zero_buf, zero_len);
436 out->cur_out_ptr += rnd_up_len;
437 out->chunk_cnt++;
442 int write_sparse_end_chunk(struct output_file *out)
447 if (out->use_crc) {
453 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header));
457 out->ops->write(out, &out->crc32, 4);
462 out->chunk_cnt++;
475 static int write_normal_data_chunk(struct output_file *out, unsigned int len,
479 unsigned int rnd_up_len = ALIGN(len, out->block_size);
481 ret = out->ops->write(out, data, len);
487 ret = out->ops->skip(out, rnd_up_len - len);
493 static int write_normal_fill_chunk(struct output_file *out, unsigned int len,
501 for (i = 0; i < out->block_size / sizeof(uint32_t); i++) {
502 out->fill_buf[i] = fill_val;
506 write_len = min(len, out->block_size);
507 ret = out->ops->write(out, out->fill_buf, write_len);
518 static int write_normal_skip_chunk(struct output_file *out, int64_t len)
520 return out->ops->skip(out, len);
523 int write_normal_end_chunk(struct output_file *out)
525 return out->ops->pad(out, out->len);
535 void output_file_close(struct output_file *out)
537 out->sparse_ops->write_end_chunk(out);
538 out->ops->close(out);
541 static int output_file_init(struct output_file *out, int block_size,
546 out->len = len;
547 out->block_size = block_size;
548 out->cur_out_ptr = 0ll;
549 out->chunk_cnt = 0;
550 out->crc32 = 0;
551 out->use_crc = crc;
553 out->zero_buf = calloc(block_size, 1);
554 if (!out->zero_buf) {
559 out->fill_buf = calloc(block_size, 1);
560 if (!out->fill_buf) {
567 out->sparse_ops = &sparse_file_ops;
569 out->sparse_ops = &normal_file_ops;
579 .blk_sz = out->block_size,
580 .total_blks = out->len / out->block_size,
585 if (out->use_crc) {
589 ret = out->ops->write(out, &sparse_header, sizeof(sparse_header));
598 free(out->fill_buf);
600 free(out->zero_buf);
612 outgz->out.ops = &gz_file_ops;
614 return &outgz->out;
625 outn->out.ops = &file_ops;
627 return &outn->out;
643 outc->out.ops = &callback_file_ops;
647 ret = output_file_init(&outc->out, block_size, len, sparse, chunks, crc);
653 return &outc->out;
660 struct output_file *out;
663 out = output_file_new_gz();
665 out = output_file_new_normal();
667 if (!out) {
671 out->ops->open(out, fd);
673 ret = output_file_init(out, block_size, len, sparse, chunks, crc);
675 free(out);
679 return out;
683 int write_data_chunk(struct output_file *out, unsigned int len, void *data)
685 return out->sparse_ops->write_data_chunk(out, len, data);
689 int write_fill_chunk(struct output_file *out, unsigned int len,
692 return out->sparse_ops->write_fill_chunk(out, len, fill_val);
695 int write_fd_chunk(struct output_file *out, unsigned int len,
734 ret = out->sparse_ops->write_data_chunk(out, len, ptr);
746 int write_file_chunk(struct output_file *out, unsigned int len,
756 ret = write_fd_chunk(out, len, file_fd, offset);
763 int write_skip_chunk(struct output_file *out, int64_t len)
765 return outout, len);