Home | History | Annotate | Download | only in libsparse

Lines Matching refs: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, size_t len)
155 struct output_file_normal *outn = to_output_file_normal(out);
174 static void file_close(struct output_file *out)
176 struct output_file_normal *outn = to_output_file_normal(out);
189 static int gz_file_open(struct output_file *out, int fd)
191 struct output_file_gz *outgz = to_output_file_gz(out);
203 static int gz_file_skip(struct output_file *out, int64_t cnt)
206 struct output_file_gz *outgz = to_output_file_gz(out);
216 static int gz_file_pad(struct output_file *out, int64_t len)
219 struct output_file_gz *outgz = to_output_file_gz(out);
240 static int gz_file_write(struct output_file *out, void *data, size_t len)
243 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 __unused, int fd __unused)
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 __unused, int64_t len __unused)
303 static int callback_file_write(struct output_file *out, void *data, size_t len)
305 struct output_file_callback *outc = to_output_file_callback(out);
310 static void callback_file_close(struct output_file *out)
312 struct output_file_callback *outc = to_output_file_callback(out);
347 static int write_sparse_skip_chunk(struct output_file *out, int64_t skip_len)
352 if (skip_len % out->block_size) {
354 skip_len, out->block_size);
361 chunk_header.chunk_sz = skip_len / out->block_size;
363 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header));
367 out->cur_out_ptr += skip_len;
368 out->chunk_cnt++;
373 static int write_sparse_fill_chunk(struct output_file *out, unsigned int len,
381 rnd_up_len = ALIGN(len, out->block_size);
386 chunk_header.chunk_sz = rnd_up_len / out->block_size;
388 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header));
392 ret = out->ops->write(out, &fill_val, sizeof(fill_val));
396 if (out->use_crc) {
397 count = out->block_size / sizeof(uint32_t);
399 out->crc32 = sparse_crc32(out->crc32, &fill_val, sizeof(uint32_t));
402 out->cur_out_ptr += rnd_up_len;
403 out->chunk_cnt++;
408 static int write_sparse_data_chunk(struct output_file *out, unsigned int len,
416 rnd_up_len = ALIGN(len, out->block_size);
422 chunk_header.chunk_sz = rnd_up_len / out->block_size;
424 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header));
428 ret = out->ops->write(out, data, len);
432 ret = out->ops->write(out, out->zero_buf, zero_len);
437 if (out->use_crc) {
438 out->crc32 = sparse_crc32(out->crc32, data, len);
440 out->crc32 = sparse_crc32(out->crc32, out->zero_buf, zero_len);
443 out->cur_out_ptr += rnd_up_len;
444 out->chunk_cnt++;
449 int write_sparse_end_chunk(struct output_file *out)
454 if (out->use_crc) {
460 ret = out->ops->write(out, &chunk_header, sizeof(chunk_header));
464 out->ops->write(out, &out->crc32, 4);
469 out->chunk_cnt++;
482 static int write_normal_data_chunk(struct output_file *out, unsigned int len,
486 unsigned int rnd_up_len = ALIGN(len, out->block_size);
488 ret = out->ops->write(out, data, len);
494 ret = out->ops->skip(out, rnd_up_len - len);
500 static int write_normal_fill_chunk(struct output_file *out, unsigned int len,
508 for (i = 0; i < out->block_size / sizeof(uint32_t); i++) {
509 out->fill_buf[i] = fill_val;
513 write_len = min(len, out->block_size);
514 ret = out->ops->write(out, out->fill_buf, write_len);
525 static int write_normal_skip_chunk(struct output_file *out, int64_t len)
527 return out->ops->skip(out, len);
530 int write_normal_end_chunk(struct output_file *out)
532 return out->ops->pad(out, out->len);
542 void output_file_close(struct output_file *out)
544 out->sparse_ops->write_end_chunk(out);
545 out->ops->close(out);
548 static int output_file_init(struct output_file *out, int block_size,
553 out->len = len;
554 out->block_size = block_size;
555 out->cur_out_ptr = 0ll;
556 out->chunk_cnt = 0;
557 out->crc32 = 0;
558 out->use_crc = crc;
560 out->zero_buf = calloc(block_size, 1);
561 if (!out->zero_buf) {
566 out->fill_buf = calloc(block_size, 1);
567 if (!out->fill_buf) {
574 out->sparse_ops = &sparse_file_ops;
576 out->sparse_ops = &normal_file_ops;
586 .blk_sz = out->block_size,
587 .total_blks = DIV_ROUND_UP(out->len, out->block_size),
592 if (out->use_crc) {
596 ret = out->ops->write(out, &sparse_header, sizeof(sparse_header));
605 free(out->fill_buf);
607 free(out->zero_buf);
619 outgz->out.ops = &gz_file_ops;
621 return &outgz->out;
632 outn->out.ops = &file_ops;
634 return &outn->out;
650 outc->out.ops = &callback_file_ops;
654 ret = output_file_init(&outc->out, block_size, len, sparse, chunks, crc);
660 return &outc->out;
667 struct output_file *out;
670 out = output_file_new_gz();
672 out = output_file_new_normal();
674 if (!out) {
678 out->ops->open(out, fd);
680 ret = output_file_init(out, block_size, len, sparse, chunks, crc);
682 free(out);
686 return out;
690 int write_data_chunk(struct output_file *out, unsigned int len, void *data)
692 return out->sparse_ops->write_data_chunk(out, len, data);
696 int write_fill_chunk(struct output_file *out, unsigned int len,
699 return out->sparse_ops->write_fill_chunk(out, len, fill_val);
702 int write_fd_chunk(struct output_file *out, unsigned int len,
743 ret = out->sparse_ops->write_data_chunk(out, len, ptr);
755 int write_file_chunk(struct output_file *out, unsigned int len,
765 ret = write_fd_chunk(out, len, file_fd, offset);
772 int write_skip_chunk(struct output_file *out, int64_t len)
774 return out->sparse_ops->write_skip_chunk(out, len);