unarchive.h 4.5 KB

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