Lines Matching refs:out

78 	int (*write_data_chunk)(struct output_file *out, unsigned int len,
80 int (*write_fill_chunk)(struct output_file *out, unsigned int len,
82 int (*write_skip_chunk)(struct output_file *out, int64_t len);
83 int (*write_end_chunk)(struct output_file *out);
101 struct output_file out;
106 container_of((_o), struct output_file_gz, out)
109 struct output_file out;
114 container_of((_o), struct output_file_normal, out)
117 struct output_file out;
123 container_of((_o), struct output_file_callback, out)
125 static int file_open(struct output_file *out, int fd)
127 struct output_file_normal *outn = to_output_file_normal(out);
133 static int file_skip(struct output_file *out, int64_t cnt)
136 struct output_file_normal *outn = to_output_file_normal(out);
146 static int file_pad(struct output_file *out, int64_t len)
149 struct output_file_normal *outn = to_output_file_normal(out);
159 static int file_write(struct output_file *out, void *data, int len)
162 struct output_file_normal *outn = to_output_file_normal(out);
176 static void file_close(struct output_file *out)
178 struct output_file_normal *outn = to_output_file_normal(out);
191 static int gz_file_open(struct output_file *out, int fd)
193 struct output_file_gz *outgz = to_output_file_gz(out);
205 static int gz_file_skip(struct output_file *out, int64_t cnt)
208 struct output_file_gz *outgz = to_output_file_gz(out);
218 static int gz_file_pad(struct output_file *out, int64_t len)
221 struct output_file_gz *outgz = to_output_file_gz(out);
242 static int gz_file_write(struct output_file *out, void *data, int len)
245 struct output_file_gz *outgz = to_output_file_gz(out);
259 static void gz_file_close(struct output_file *out)
261 struct output_file_gz *outgz = to_output_file_gz(out);
275 static int callback_file_open(struct output_file *out, int fd)
280 static int callback_file_skip(struct output_file *out, int64_t off)
282 struct output_file_callback *outc = to_output_file_callback(out);
298 static int callback_file_pad(struct output_file *out, int64_t len)
303 static int callback_file_write(struct output_file *out, void *data, int len)
306 struct output_file_callback *outc = to_output_file_callback(out);
311 static void callback_file_close(struct output_file *out)
313 struct output_file_callback *outc = to_output_file_callback(out);
348 static int write_sparse_skip_chunk(struct output_file *out, int64_t skip_len)
353 if (skip_len % out->block_size) {
355 skip_len, out->block_size);
362 chunk_header.chunk_sz = skip_len / out->block_size;
364 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header));
368 out->cur_out_ptr += skip_len;
369 out->chunk_cnt++;
374 static int write_sparse_fill_chunk(struct output_file *out, unsigned int len,
383 rnd_up_len = ALIGN(len, out->block_size);
388 chunk_header.chunk_sz = rnd_up_len / out->block_size;
390 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header));
394 ret = out->ops->write(out, &fill_val, sizeof(fill_val));
398 if (out->use_crc) {
399 count = out->block_size / sizeof(uint32_t);
401 out->crc32 = sparse_crc32(out->crc32, &fill_val, sizeof(uint32_t));
404 out->cur_out_ptr += rnd_up_len;
405 out->chunk_cnt++;
410 static int write_sparse_data_chunk(struct output_file *out, unsigned int len,
418 rnd_up_len = ALIGN(len, out->block_size);
424 chunk_header.chunk_sz = rnd_up_len / out->block_size;
426 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header));
430 ret = out->ops->write(out, data, len);
434 ret = out->ops->write(out, out->zero_buf, zero_len);
439 if (out->use_crc) {
440 out->crc32 = sparse_crc32(out->crc32, data, len);
442 out->crc32 = sparse_crc32(out->crc32, out->zero_buf, zero_len);
445 out->cur_out_ptr += rnd_up_len;
446 out->chunk_cnt++;
451 int write_sparse_end_chunk(struct output_file *out)
456 if (out->use_crc) {
462 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header));
466 out->ops->write(out, &out->crc32, 4);
471 out->chunk_cnt++;
484 static int write_normal_data_chunk(struct output_file *out, unsigned int len,
488 unsigned int rnd_up_len = ALIGN(len, out->block_size);
490 ret = out->ops->write(out, data, len);
496 ret = out->ops->skip(out, rnd_up_len - len);
502 static int write_normal_fill_chunk(struct output_file *out, unsigned int len,
510 for (i = 0; i < out->block_size / sizeof(uint32_t); i++) {
511 out->fill_buf[i] = fill_val;
515 write_len = min(len, out->block_size);
516 ret = out->ops->write(out, out->fill_buf, write_len);
527 static int write_normal_skip_chunk(struct output_file *out, int64_t len)
529 return out->ops->skip(out, len);
532 int write_normal_end_chunk(struct output_file *out)
534 return out->ops->pad(out, out->len);
544 void output_file_close(struct output_file *out)
548 out->sparse_ops->write_end_chunk(out);
549 out->ops->close(out);
552 static int output_file_init(struct output_file *out, int block_size,
557 out->len = len;
558 out->block_size = block_size;
559 out->cur_out_ptr = 0ll;
560 out->chunk_cnt = 0;
561 out->crc32 = 0;
562 out->use_crc = crc;
564 out->zero_buf = calloc(block_size, 1);
565 if (!out->zero_buf) {
570 out->fill_buf = calloc(block_size, 1);
571 if (!out->fill_buf) {
578 out->sparse_ops = &sparse_file_ops;
580 out->sparse_ops = &normal_file_ops;
590 .blk_sz = out->block_size,
591 .total_blks = out->len / out->block_size,
596 if (out->use_crc) {
600 ret = out->ops->write(out, &sparse_header, sizeof(sparse_header));
609 free(out->fill_buf);
611 free(out->zero_buf);
623 outgz->out.ops = &gz_file_ops;
625 return &outgz->out;
636 outn->out.ops = &file_ops;
638 return &outn->out;
654 outc->out.ops = &callback_file_ops;
658 ret = output_file_init(&outc->out, block_size, len, sparse, chunks, crc);
664 return &outc->out;
671 struct output_file *out;
674 out = output_file_new_gz();
676 out = output_file_new_normal();
679 out->ops->open(out, fd);
681 ret = output_file_init(out, block_size, len, sparse, chunks, crc);
683 free(out);
687 return out;
691 int write_data_chunk(struct output_file *out, unsigned int len, void *data)
693 return out->sparse_ops->write_data_chunk(out, len, data);
697 int write_fill_chunk(struct output_file *out, unsigned int len,
700 return out->sparse_ops->write_fill_chunk(out, len, fill_val);
703 int write_fd_chunk(struct output_file *out, unsigned int len,
740 ret = out->sparse_ops->write_data_chunk(out, len, ptr);
752 int write_file_chunk(struct output_file *out, unsigned int len,
762 ret = write_fd_chunk(out, len, file_fd, offset);
769 int write_skip_chunk(struct output_file *out, int64_t len)
771 return out->sparse_ops->write_skip_chunk(out, len);