3
0

unarchive.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. /* Info struct unpackers can fill out to inform users of thing like
  64. * timestamps of unpacked files */
  65. typedef struct unpack_info_t {
  66. time_t mtime;
  67. } unpack_info_t;
  68. extern archive_handle_t *init_handle(void) FAST_FUNC;
  69. extern char filter_accept_all(archive_handle_t *archive_handle) FAST_FUNC;
  70. extern char filter_accept_list(archive_handle_t *archive_handle) FAST_FUNC;
  71. extern char filter_accept_list_reassign(archive_handle_t *archive_handle) FAST_FUNC;
  72. extern char filter_accept_reject_list(archive_handle_t *archive_handle) FAST_FUNC;
  73. extern void unpack_ar_archive(archive_handle_t *ar_archive) FAST_FUNC;
  74. extern void data_skip(archive_handle_t *archive_handle) FAST_FUNC;
  75. extern void data_extract_all(archive_handle_t *archive_handle) FAST_FUNC;
  76. extern void data_extract_to_stdout(archive_handle_t *archive_handle) FAST_FUNC;
  77. extern void data_extract_to_buffer(archive_handle_t *archive_handle) FAST_FUNC;
  78. extern void header_skip(const file_header_t *file_header) FAST_FUNC;
  79. extern void header_list(const file_header_t *file_header) FAST_FUNC;
  80. extern void header_verbose_list(const file_header_t *file_header) FAST_FUNC;
  81. extern char get_header_ar(archive_handle_t *archive_handle) FAST_FUNC;
  82. extern char get_header_cpio(archive_handle_t *archive_handle) FAST_FUNC;
  83. extern char get_header_tar(archive_handle_t *archive_handle) FAST_FUNC;
  84. extern char get_header_tar_gz(archive_handle_t *archive_handle) FAST_FUNC;
  85. extern char get_header_tar_bz2(archive_handle_t *archive_handle) FAST_FUNC;
  86. extern char get_header_tar_lzma(archive_handle_t *archive_handle) FAST_FUNC;
  87. extern void seek_by_jump(const archive_handle_t *archive_handle, unsigned amount) FAST_FUNC;
  88. extern void seek_by_read(const archive_handle_t *archive_handle, unsigned amount) FAST_FUNC;
  89. extern void data_align(archive_handle_t *archive_handle, unsigned boundary) FAST_FUNC;
  90. extern const llist_t *find_list_entry(const llist_t *list, const char *filename) FAST_FUNC;
  91. extern const llist_t *find_list_entry2(const llist_t *list, const char *filename) FAST_FUNC;
  92. /* A bit of bunzip2 internals are exposed for compressed help support: */
  93. typedef struct bunzip_data bunzip_data;
  94. int start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *inbuf, int len) FAST_FUNC;
  95. int read_bunzip(bunzip_data *bd, char *outbuf, int len) FAST_FUNC;
  96. void dealloc_bunzip(bunzip_data *bd) FAST_FUNC;
  97. typedef struct inflate_unzip_result {
  98. off_t bytes_out;
  99. uint32_t crc;
  100. } inflate_unzip_result;
  101. USE_DESKTOP(long long) int inflate_unzip(inflate_unzip_result *res, off_t compr_size, int src_fd, int dst_fd) FAST_FUNC;
  102. /* lzma unpacker takes .lzma stream from offset 0 */
  103. USE_DESKTOP(long long) int unpack_lzma_stream(int src_fd, int dst_fd) FAST_FUNC;
  104. /* the rest wants 2 first bytes already skipped by the caller */
  105. USE_DESKTOP(long long) int unpack_bz2_stream(int src_fd, int dst_fd) FAST_FUNC;
  106. USE_DESKTOP(long long) int unpack_gz_stream(int src_fd, int dst_fd) FAST_FUNC;
  107. USE_DESKTOP(long long) int unpack_gz_stream_with_info(int src_fd, int dst_fd, unpack_info_t *info) FAST_FUNC;
  108. USE_DESKTOP(long long) int unpack_Z_stream(int fd_in, int fd_out) FAST_FUNC;
  109. /* wrapper which checks first two bytes to be "BZ" */
  110. USE_DESKTOP(long long) int unpack_bz2_stream_prime(int src_fd, int dst_fd) FAST_FUNC;
  111. int bbunpack(char **argv,
  112. char* (*make_new_name)(char *filename),
  113. USE_DESKTOP(long long) int (*unpacker)(unpack_info_t *info)) FAST_FUNC;
  114. #if BB_MMU
  115. void open_transformer(int fd,
  116. USE_DESKTOP(long long) int FAST_FUNC (*transformer)(int src_fd, int dst_fd)) FAST_FUNC;
  117. #define open_transformer(fd, transformer, transform_prog) open_transformer(fd, transformer)
  118. #else
  119. void open_transformer(int src_fd, const char *transform_prog) FAST_FUNC;
  120. #define open_transformer(fd, transformer, transform_prog) open_transformer(fd, transform_prog)
  121. #endif
  122. #if __GNUC_PREREQ(4,1)
  123. # pragma GCC visibility pop
  124. #endif
  125. #endif