Lines Matching refs:out
72 int (*write_data_chunk)(struct output_file* out, uint64_t len, void* data);
73 int (*write_fill_chunk)(struct output_file* out, uint64_t len, uint32_t fill_val);
74 int (*write_skip_chunk)(struct output_file* out, uint64_t len);
75 int (*write_end_chunk)(struct output_file* out);
76 int (*write_fd_chunk)(struct output_file* out, uint64_t len, int fd, int64_t offset);
94 struct output_file out; member
98 #define to_output_file_gz(_o) container_of((_o), struct output_file_gz, out)
101 struct output_file out; member
105 #define to_output_file_normal(_o) container_of((_o), struct output_file_normal, out)
108 struct output_file out; member
113 #define to_output_file_callback(_o) container_of((_o), struct output_file_callback, out)
115 static int file_open(struct output_file* out, int fd) { in file_open() argument
116 struct output_file_normal* outn = to_output_file_normal(out); in file_open()
122 static int file_skip(struct output_file* out, int64_t cnt) { in file_skip() argument
124 struct output_file_normal* outn = to_output_file_normal(out); in file_skip()
134 static int file_pad(struct output_file* out, int64_t len) { in file_pad() argument
136 struct output_file_normal* outn = to_output_file_normal(out); in file_pad()
146 static int file_write(struct output_file* out, void* data, size_t len) { in file_write() argument
148 struct output_file_normal* outn = to_output_file_normal(out); in file_write()
167 static void file_close(struct output_file* out) { in file_close() argument
168 struct output_file_normal* outn = to_output_file_normal(out); in file_close()
181 static int gz_file_open(struct output_file* out, int fd) { in gz_file_open() argument
182 struct output_file_gz* outgz = to_output_file_gz(out); in gz_file_open()
193 static int gz_file_skip(struct output_file* out, int64_t cnt) { in gz_file_skip() argument
195 struct output_file_gz* outgz = to_output_file_gz(out); in gz_file_skip()
205 static int gz_file_pad(struct output_file* out, int64_t len) { in gz_file_pad() argument
207 struct output_file_gz* outgz = to_output_file_gz(out); in gz_file_pad()
228 static int gz_file_write(struct output_file* out, void* data, size_t len) { in gz_file_write() argument
230 struct output_file_gz* outgz = to_output_file_gz(out); in gz_file_write()
245 static void gz_file_close(struct output_file* out) { in gz_file_close() argument
246 struct output_file_gz* outgz = to_output_file_gz(out); in gz_file_close()
260 static int callback_file_open(struct output_file* out __unused, int fd __unused) { in callback_file_open()
264 static int callback_file_skip(struct output_file* out, int64_t off) { in callback_file_skip() argument
265 struct output_file_callback* outc = to_output_file_callback(out); in callback_file_skip()
281 static int callback_file_pad(struct output_file* out __unused, int64_t len __unused) { in callback_file_pad()
285 static int callback_file_write(struct output_file* out, void* data, size_t len) { in callback_file_write() argument
286 struct output_file_callback* outc = to_output_file_callback(out); in callback_file_write()
291 static void callback_file_close(struct output_file* out) { in callback_file_close() argument
292 struct output_file_callback* outc = to_output_file_callback(out); in callback_file_close()
344 static int write_sparse_skip_chunk(struct output_file* out, uint64_t skip_len) { in write_sparse_skip_chunk() argument
348 if (skip_len % out->block_size) { in write_sparse_skip_chunk()
350 out->block_size); in write_sparse_skip_chunk()
357 chunk_header.chunk_sz = skip_len / out->block_size; in write_sparse_skip_chunk()
359 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header)); in write_sparse_skip_chunk()
362 out->cur_out_ptr += skip_len; in write_sparse_skip_chunk()
363 out->chunk_cnt++; in write_sparse_skip_chunk()
368 static int write_sparse_fill_chunk(struct output_file* out, uint64_t len, uint32_t fill_val) { in write_sparse_fill_chunk() argument
375 rnd_up_len = ALIGN(len, out->block_size); in write_sparse_fill_chunk()
380 chunk_header.chunk_sz = rnd_up_len / out->block_size; in write_sparse_fill_chunk()
382 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header)); in write_sparse_fill_chunk()
385 ret = out->ops->write(out, &fill_val, sizeof(fill_val)); in write_sparse_fill_chunk()
388 if (out->use_crc) { in write_sparse_fill_chunk()
389 count = out->block_size / sizeof(uint32_t); in write_sparse_fill_chunk()
390 while (count--) out->crc32 = sparse_crc32(out->crc32, &fill_val, sizeof(uint32_t)); in write_sparse_fill_chunk()
393 out->cur_out_ptr += rnd_up_len; in write_sparse_fill_chunk()
394 out->chunk_cnt++; in write_sparse_fill_chunk()
399 static int write_sparse_data_chunk(struct output_file* out, uint64_t len, void* data) { in write_sparse_data_chunk() argument
405 rnd_up_len = ALIGN(len, out->block_size); in write_sparse_data_chunk()
411 chunk_header.chunk_sz = rnd_up_len / out->block_size; in write_sparse_data_chunk()
413 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header)); in write_sparse_data_chunk()
416 ret = out->ops->write(out, data, len); in write_sparse_data_chunk()
423 ret = out->ops->write(out, out->zero_buf, write_len); in write_sparse_data_chunk()
431 if (out->use_crc) { in write_sparse_data_chunk()
432 out->crc32 = sparse_crc32(out->crc32, data, len); in write_sparse_data_chunk()
438 out->crc32 = sparse_crc32(out->crc32, out->zero_buf, write_len); in write_sparse_data_chunk()
444 out->cur_out_ptr += rnd_up_len; in write_sparse_data_chunk()
445 out->chunk_cnt++; in write_sparse_data_chunk()
450 static int write_sparse_fd_chunk(struct output_file* out, uint64_t len, int fd, int64_t offset) { in write_sparse_fd_chunk() argument
456 rnd_up_len = ALIGN(len, out->block_size); in write_sparse_fd_chunk()
462 chunk_header.chunk_sz = rnd_up_len / out->block_size; in write_sparse_fd_chunk()
464 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header)); in write_sparse_fd_chunk()
467 bool ok = write_fd_chunk_range(fd, offset, len, [&ret, out](char* data, size_t size) -> bool { in write_sparse_fd_chunk()
468 ret = out->ops->write(out, data, size); in write_sparse_fd_chunk()
470 if (out->use_crc) { in write_sparse_fd_chunk()
471 out->crc32 = sparse_crc32(out->crc32, data, size); in write_sparse_fd_chunk()
481 ret = out->ops->write(out, out->zero_buf, write_len); in write_sparse_fd_chunk()
488 if (out->use_crc) { in write_sparse_fd_chunk()
493 out->crc32 = sparse_crc32(out->crc32, out->zero_buf, write_len); in write_sparse_fd_chunk()
499 out->cur_out_ptr += rnd_up_len; in write_sparse_fd_chunk()
500 out->chunk_cnt++; in write_sparse_fd_chunk()
505 int write_sparse_end_chunk(struct output_file* out) { in write_sparse_end_chunk() argument
509 if (out->use_crc) { in write_sparse_end_chunk()
515 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header)); in write_sparse_end_chunk()
519 out->ops->write(out, &out->crc32, 4); in write_sparse_end_chunk()
524 out->chunk_cnt++; in write_sparse_end_chunk()
538 static int write_normal_data_chunk(struct output_file* out, uint64_t len, void* data) { in write_normal_data_chunk() argument
540 uint64_t rnd_up_len = ALIGN(len, out->block_size); in write_normal_data_chunk()
542 ret = out->ops->write(out, data, len); in write_normal_data_chunk()
548 ret = out->ops->skip(out, rnd_up_len - len); in write_normal_data_chunk()
554 static int write_normal_fill_chunk(struct output_file* out, uint64_t len, uint32_t fill_val) { in write_normal_fill_chunk() argument
561 out->fill_buf[i] = fill_val; in write_normal_fill_chunk()
566 ret = out->ops->write(out, out->fill_buf, write_len); in write_normal_fill_chunk()
577 static int write_normal_fd_chunk(struct output_file* out, uint64_t len, int fd, int64_t offset) { in write_normal_fd_chunk() argument
579 uint64_t rnd_up_len = ALIGN(len, out->block_size); in write_normal_fd_chunk()
581 bool ok = write_fd_chunk_range(fd, offset, len, [&ret, out](char* data, size_t size) -> bool { in write_normal_fd_chunk()
582 ret = out->ops->write(out, data, size); in write_normal_fd_chunk()
588 ret = out->ops->skip(out, rnd_up_len - len); in write_normal_fd_chunk()
594 static int write_normal_skip_chunk(struct output_file* out, uint64_t len) { in write_normal_skip_chunk() argument
595 return out->ops->skip(out, len); in write_normal_skip_chunk()
598 int write_normal_end_chunk(struct output_file* out) { in write_normal_end_chunk() argument
599 return out->ops->pad(out, out->len); in write_normal_end_chunk()
610 void output_file_close(struct output_file* out) { in output_file_close() argument
611 out->sparse_ops->write_end_chunk(out); in output_file_close()
612 free(out->zero_buf); in output_file_close()
613 free(out->fill_buf); in output_file_close()
614 out->zero_buf = nullptr; in output_file_close()
615 out->fill_buf = nullptr; in output_file_close()
616 out->ops->close(out); in output_file_close()
619 static int output_file_init(struct output_file* out, int block_size, int64_t len, bool sparse, in output_file_init() argument
623 out->len = len; in output_file_init()
624 out->block_size = block_size; in output_file_init()
625 out->cur_out_ptr = 0LL; in output_file_init()
626 out->chunk_cnt = 0; in output_file_init()
627 out->crc32 = 0; in output_file_init()
628 out->use_crc = crc; in output_file_init()
631 out->zero_buf = reinterpret_cast<char*>(calloc(FILL_ZERO_BUFSIZE, 1)); in output_file_init()
632 if (!out->zero_buf) { in output_file_init()
638 out->fill_buf = reinterpret_cast<uint32_t*>(calloc(FILL_ZERO_BUFSIZE, 1)); in output_file_init()
639 if (!out->fill_buf) { in output_file_init()
646 out->sparse_ops = &sparse_file_ops; in output_file_init()
648 out->sparse_ops = &normal_file_ops; in output_file_init()
658 .blk_sz = out->block_size, in output_file_init()
659 .total_blks = static_cast<unsigned>(DIV_ROUND_UP(out->len, out->block_size)), in output_file_init()
663 if (out->use_crc) { in output_file_init()
667 ret = out->ops->write(out, &sparse_header, sizeof(sparse_header)); in output_file_init()
676 free(out->fill_buf); in output_file_init()
678 free(out->zero_buf); in output_file_init()
690 outgz->out.ops = &gz_file_ops; in output_file_new_gz()
692 return &outgz->out; in output_file_new_gz()
703 outn->out.ops = &file_ops; in output_file_new_normal()
705 return &outn->out; in output_file_new_normal()
721 outc->out.ops = &callback_file_ops; in output_file_open_callback()
725 ret = output_file_init(&outc->out, block_size, len, sparse, chunks, crc); in output_file_open_callback()
731 return &outc->out; in output_file_open_callback()
737 struct output_file* out; in output_file_open_fd() local
740 out = output_file_new_gz(); in output_file_open_fd()
742 out = output_file_new_normal(); in output_file_open_fd()
744 if (!out) { in output_file_open_fd()
748 out->ops->open(out, fd); in output_file_open_fd()
750 ret = output_file_init(out, block_size, len, sparse, chunks, crc); in output_file_open_fd()
752 free(out); in output_file_open_fd()
756 return out; in output_file_open_fd()
760 int write_data_chunk(struct output_file* out, uint64_t len, void* data) { in write_data_chunk() argument
761 return out->sparse_ops->write_data_chunk(out, len, data); in write_data_chunk()
765 int write_fill_chunk(struct output_file* out, uint64_t len, uint32_t fill_val) { in write_fill_chunk() argument
766 return out->sparse_ops->write_fill_chunk(out, len, fill_val); in write_fill_chunk()
769 int write_fd_chunk(struct output_file* out, uint64_t len, int fd, int64_t offset) { in write_fd_chunk() argument
770 return out->sparse_ops->write_fd_chunk(out, len, fd, offset); in write_fd_chunk()
774 int write_file_chunk(struct output_file* out, uint64_t len, const char* file, int64_t offset) { in write_file_chunk() argument
782 ret = write_fd_chunk(out, len, file_fd, offset); in write_file_chunk()
789 int write_skip_chunk(struct output_file* out, uint64_t len) { in write_skip_chunk() argument
790 return out->sparse_ops->write_skip_chunk(out, len); in write_skip_chunk()