archive_write_private.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*-
  2. * Copyright (c) 2003-2007 Tim Kientzle
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. *
  25. * $FreeBSD: head/lib/libarchive/archive_write_private.h 201155 2009-12-29 05:20:12Z kientzle $
  26. */
  27. #ifndef __LIBARCHIVE_BUILD
  28. #error This header is only to be used internally to libarchive.
  29. #endif
  30. #ifndef ARCHIVE_WRITE_PRIVATE_H_INCLUDED
  31. #define ARCHIVE_WRITE_PRIVATE_H_INCLUDED
  32. #include "archive.h"
  33. #include "archive_string.h"
  34. #include "archive_private.h"
  35. struct archive_write;
  36. struct archive_write_filter {
  37. int64_t bytes_written;
  38. struct archive *archive; /* Associated archive. */
  39. struct archive_write_filter *next_filter; /* Who I write to. */
  40. int (*options)(struct archive_write_filter *,
  41. const char *key, const char *value);
  42. int (*open)(struct archive_write_filter *);
  43. int (*write)(struct archive_write_filter *, const void *, size_t);
  44. int (*close)(struct archive_write_filter *);
  45. int (*free)(struct archive_write_filter *);
  46. void *data;
  47. const char *name;
  48. int code;
  49. int bytes_per_block;
  50. int bytes_in_last_block;
  51. };
  52. #if ARCHIVE_VERSION < 4000000
  53. void __archive_write_filters_free(struct archive *);
  54. #endif
  55. struct archive_write_filter *__archive_write_allocate_filter(struct archive *);
  56. int __archive_write_output(struct archive_write *, const void *, size_t);
  57. int __archive_write_nulls(struct archive_write *, size_t);
  58. int __archive_write_filter(struct archive_write_filter *, const void *, size_t);
  59. int __archive_write_open_filter(struct archive_write_filter *);
  60. int __archive_write_close_filter(struct archive_write_filter *);
  61. struct archive_write {
  62. struct archive archive;
  63. /* Dev/ino of the archive being written. */
  64. int skip_file_set;
  65. int64_t skip_file_dev;
  66. int64_t skip_file_ino;
  67. /* Utility: Pointer to a block of nulls. */
  68. const unsigned char *nulls;
  69. size_t null_length;
  70. /* Callbacks to open/read/write/close archive stream. */
  71. archive_open_callback *client_opener;
  72. archive_write_callback *client_writer;
  73. archive_close_callback *client_closer;
  74. void *client_data;
  75. /*
  76. * Blocking information. Note that bytes_in_last_block is
  77. * misleadingly named; I should find a better name. These
  78. * control the final output from all compressors, including
  79. * compression_none.
  80. */
  81. int bytes_per_block;
  82. int bytes_in_last_block;
  83. /*
  84. * First and last write filters in the pipeline.
  85. */
  86. struct archive_write_filter *filter_first;
  87. struct archive_write_filter *filter_last;
  88. /*
  89. * Pointers to format-specific functions for writing. They're
  90. * initialized by archive_write_set_format_XXX() calls.
  91. */
  92. void *format_data;
  93. const char *format_name;
  94. int (*format_init)(struct archive_write *);
  95. int (*format_options)(struct archive_write *,
  96. const char *key, const char *value);
  97. int (*format_finish_entry)(struct archive_write *);
  98. int (*format_write_header)(struct archive_write *,
  99. struct archive_entry *);
  100. ssize_t (*format_write_data)(struct archive_write *,
  101. const void *buff, size_t);
  102. int (*format_close)(struct archive_write *);
  103. int (*format_free)(struct archive_write *);
  104. };
  105. /*
  106. * Utility function to format a USTAR header into a buffer. If
  107. * "strict" is set, this tries to create the absolutely most portable
  108. * version of a ustar header. If "strict" is set to 0, then it will
  109. * relax certain requirements.
  110. *
  111. * Generally, format-specific declarations don't belong in this
  112. * header; this is a rare example of a function that is shared by
  113. * two very similar formats (ustar and pax).
  114. */
  115. int
  116. __archive_write_format_header_ustar(struct archive_write *, char buff[512],
  117. struct archive_entry *, int tartype, int strict,
  118. struct archive_string_conv *);
  119. struct archive_write_program_data;
  120. struct archive_write_program_data * __archive_write_program_allocate(void);
  121. int __archive_write_program_free(struct archive_write_program_data *);
  122. int __archive_write_program_open(struct archive_write_filter *,
  123. struct archive_write_program_data *, const char *);
  124. int __archive_write_program_close(struct archive_write_filter *,
  125. struct archive_write_program_data *);
  126. int __archive_write_program_write(struct archive_write_filter *,
  127. struct archive_write_program_data *, const void *, size_t);
  128. #endif