unarchive.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* vi: set sw=4 ts=4: */
  2. #ifndef __UNARCHIVE_H__
  3. #define __UNARCHIVE_H__
  4. #if __GNUC_PREREQ(4,1)
  5. # pragma GCC visibility push(hidden)
  6. #endif
  7. #define ARCHIVE_PRESERVE_DATE 1
  8. #define ARCHIVE_CREATE_LEADING_DIRS 2
  9. #define ARCHIVE_EXTRACT_UNCONDITIONAL 4
  10. #define ARCHIVE_EXTRACT_QUIET 8
  11. #define ARCHIVE_EXTRACT_NEWER 16
  12. #define ARCHIVE_NOPRESERVE_OWN 32
  13. #define ARCHIVE_NOPRESERVE_PERM 64
  14. typedef struct file_header_t {
  15. char *name;
  16. char *link_target;
  17. #if ENABLE_FEATURE_TAR_UNAME_GNAME
  18. char *uname;
  19. char *gname;
  20. #endif
  21. off_t size;
  22. uid_t uid;
  23. gid_t gid;
  24. mode_t mode;
  25. time_t mtime;
  26. dev_t device;
  27. } file_header_t;
  28. typedef struct archive_handle_t {
  29. /* Define if the header and data component should be processed */
  30. char FAST_FUNC (*filter)(struct archive_handle_t *);
  31. llist_t *accept;
  32. /* List of files that have been rejected */
  33. llist_t *reject;
  34. /* List of files that have successfully been worked on */
  35. llist_t *passed;
  36. /* Contains the processed header entry */
  37. file_header_t *file_header;
  38. /* Process the header component, e.g. tar -t */
  39. void FAST_FUNC (*action_header)(const file_header_t *);
  40. /* Process the data component, e.g. extract to filesystem */
  41. void FAST_FUNC (*action_data)(struct archive_handle_t *);
  42. #if ENABLE_DPKG || ENABLE_DPKG_DEB
  43. /* "subarchive" is used only by dpkg[-deb] applets */
  44. /* How to process any sub archive, e.g. get_header_tar_gz */
  45. char FAST_FUNC (*action_data_subarchive)(struct archive_handle_t *);
  46. /* Contains the handle to a sub archive */
  47. struct archive_handle_t *sub_archive;
  48. #endif
  49. /* The raw stream as read from disk or stdin */
  50. int src_fd;
  51. /* Count the number of bytes processed */
  52. off_t offset;
  53. /* Function that skips data: read_by_char or read_by_skip */
  54. void FAST_FUNC (*seek)(const struct archive_handle_t *archive_handle, const unsigned amount);
  55. /* Temporary storage */
  56. char *buffer;
  57. /* Flags and misc. stuff */
  58. unsigned char ah_flags;
  59. /* "Private" storage for archivers */
  60. // unsigned char ah_priv_inited;
  61. void *ah_priv[8];
  62. } archive_handle_t;
  63. extern archive_handle_t *init_handle(void) FAST_FUNC;
  64. extern char filter_accept_all(archive_handle_t *archive_handle) FAST_FUNC;
  65. extern char filter_accept_list(archive_handle_t *archive_handle) FAST_FUNC;
  66. extern char filter_accept_list_reassign(archive_handle_t *archive_handle) FAST_FUNC;
  67. extern char filter_accept_reject_list(archive_handle_t *archive_handle) FAST_FUNC;
  68. extern void unpack_ar_archive(archive_handle_t *ar_archive) FAST_FUNC;
  69. extern void data_skip(archive_handle_t *archive_handle) FAST_FUNC;
  70. extern void data_extract_all(archive_handle_t *archive_handle) FAST_FUNC;
  71. extern void data_extract_to_stdout(archive_handle_t *archive_handle) FAST_FUNC;
  72. extern void data_extract_to_buffer(archive_handle_t *archive_handle) FAST_FUNC;
  73. extern void header_skip(const file_header_t *file_header) FAST_FUNC;
  74. extern void header_list(const file_header_t *file_header) FAST_FUNC;
  75. extern void header_verbose_list(const file_header_t *file_header) FAST_FUNC;
  76. extern char get_header_ar(archive_handle_t *archive_handle) FAST_FUNC;
  77. extern char get_header_cpio(archive_handle_t *archive_handle) FAST_FUNC;
  78. extern char get_header_tar(archive_handle_t *archive_handle) FAST_FUNC;
  79. extern char get_header_tar_gz(archive_handle_t *archive_handle) FAST_FUNC;
  80. extern char get_header_tar_bz2(archive_handle_t *archive_handle) FAST_FUNC;
  81. extern char get_header_tar_lzma(archive_handle_t *archive_handle) FAST_FUNC;
  82. extern void seek_by_jump(const archive_handle_t *archive_handle, unsigned amount) FAST_FUNC;
  83. extern void seek_by_read(const archive_handle_t *archive_handle, unsigned amount) FAST_FUNC;
  84. extern void data_align(archive_handle_t *archive_handle, unsigned boundary) FAST_FUNC;
  85. extern const llist_t *find_list_entry(const llist_t *list, const char *filename) FAST_FUNC;
  86. extern const llist_t *find_list_entry2(const llist_t *list, const char *filename) FAST_FUNC;
  87. /* A bit of bunzip2 internals are exposed for compressed help support: */
  88. typedef struct bunzip_data bunzip_data;
  89. int start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *inbuf, int len) FAST_FUNC;
  90. int read_bunzip(bunzip_data *bd, char *outbuf, int len) FAST_FUNC;
  91. void dealloc_bunzip(bunzip_data *bd) FAST_FUNC;
  92. typedef struct inflate_unzip_result {
  93. off_t bytes_out;
  94. uint32_t crc;
  95. } inflate_unzip_result;
  96. USE_DESKTOP(long long) int inflate_unzip(inflate_unzip_result *res, off_t compr_size, int src_fd, int dst_fd) FAST_FUNC;
  97. /* lzma unpacker takes .lzma stream from offset 0 */
  98. USE_DESKTOP(long long) int unpack_lzma_stream(int src_fd, int dst_fd) FAST_FUNC;
  99. /* the rest wants 2 first bytes already skipped by the caller */
  100. USE_DESKTOP(long long) int unpack_bz2_stream(int src_fd, int dst_fd) FAST_FUNC;
  101. USE_DESKTOP(long long) int unpack_gz_stream(int src_fd, int dst_fd) FAST_FUNC;
  102. USE_DESKTOP(long long) int unpack_Z_stream(int fd_in, int fd_out) FAST_FUNC;
  103. /* wrapper which checks first two bytes to be "BZ" */
  104. USE_DESKTOP(long long) int unpack_bz2_stream_prime(int src_fd, int dst_fd) FAST_FUNC;
  105. #if BB_MMU
  106. void open_transformer(int fd,
  107. USE_DESKTOP(long long) int FAST_FUNC (*transformer)(int src_fd, int dst_fd)) FAST_FUNC;
  108. #define open_transformer(fd, transformer, transform_prog) open_transformer(fd, transformer)
  109. #else
  110. void open_transformer(int src_fd, const char *transform_prog) FAST_FUNC;
  111. #define open_transformer(fd, transformer, transform_prog) open_transformer(fd, transform_prog)
  112. #endif
  113. #if __GNUC_PREREQ(4,1)
  114. # pragma GCC visibility pop
  115. #endif
  116. #endif