unarchive.h 5.8 KB

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