unarchive.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #ifndef __UNARCHIVE_H__
  2. #define __UNARCHIVE_H__
  3. #define ARCHIVE_PRESERVE_DATE 1
  4. #define ARCHIVE_CREATE_LEADING_DIRS 2
  5. #define ARCHIVE_EXTRACT_UNCONDITIONAL 4
  6. #define ARCHIVE_EXTRACT_QUIET 8
  7. #define ARCHIVE_EXTRACT_NEWER 16
  8. #define ARCHIVE_NOPRESERVE_OWN 32
  9. #define ARCHIVE_NOPRESERVE_PERM 64
  10. #include <sys/types.h>
  11. #include <stdio.h>
  12. #include "libbb.h"
  13. typedef struct file_headers_s {
  14. char *name;
  15. char *link_name;
  16. off_t size;
  17. uid_t uid;
  18. gid_t gid;
  19. mode_t mode;
  20. time_t mtime;
  21. dev_t device;
  22. } file_header_t;
  23. typedef struct archive_handle_s {
  24. /* define if the header and data compenent should processed */
  25. char (*filter)(struct archive_handle_s *);
  26. llist_t *accept;
  27. llist_t *reject;
  28. llist_t *passed; /* List of files that have successfully been worked on */
  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_s *);
  35. /* How to process any sub archive, e.g. get_header_tar_gz */
  36. char (*action_data_subarchive)(struct archive_handle_s *);
  37. /* Contains the handle to a sub archive */
  38. struct archive_handle_s *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_s *archive_handle, const unsigned int amount);
  45. /* Temporary storage */
  46. char *buffer;
  47. /* 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 void check_header_gzip(int src_fd);
  64. extern char get_header_ar(archive_handle_t *archive_handle);
  65. extern char get_header_cpio(archive_handle_t *archive_handle);
  66. extern char get_header_tar(archive_handle_t *archive_handle);
  67. extern char get_header_tar_bz2(archive_handle_t *archive_handle);
  68. extern char get_header_tar_lzma(archive_handle_t *archive_handle);
  69. extern char get_header_tar_gz(archive_handle_t *archive_handle);
  70. extern void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amount);
  71. extern void seek_by_char(const archive_handle_t *archive_handle, const unsigned int amount);
  72. extern void archive_xread_all(const archive_handle_t *archive_handle, void *buf, const size_t count);
  73. extern ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned char *buf, size_t count);
  74. extern void data_align(archive_handle_t *archive_handle, const unsigned short boundary);
  75. extern const llist_t *find_list_entry(const llist_t *list, const char *filename);
  76. extern int uncompressStream(int src_fd, int dst_fd);
  77. extern void inflate_init(unsigned int bufsize);
  78. extern void inflate_cleanup(void);
  79. extern int inflate_unzip(int in, int out);
  80. extern int inflate_gunzip(int in, int out);
  81. extern int unlzma(int src_fd, int dst_fd);
  82. extern int open_transformer(int src_fd, int (*transformer)(int src_fd, int dst_fd));
  83. #endif