unarchive.h 4.6 KB

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