tarfn.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * tarfn.h - tar archive extraction functions
  4. *
  5. * Copyright © 1995 Bruce Perens
  6. * Copyright © 2009-2014 Guillem Jover <guillem@debian.org>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. #ifndef LIBDPKG_TARFN_H
  22. #define LIBDPKG_TARFN_H
  23. #include <sys/types.h>
  24. #include <dpkg/file.h>
  25. /**
  26. * @defgroup tar Tar archive handling
  27. * @ingroup dpkg-public
  28. * @{
  29. */
  30. #define TARBLKSZ 512
  31. enum tar_format {
  32. TAR_FORMAT_OLD,
  33. TAR_FORMAT_GNU,
  34. TAR_FORMAT_USTAR,
  35. TAR_FORMAT_PAX,
  36. };
  37. enum tar_filetype {
  38. /** For compatibility with decades-old bug. */
  39. TAR_FILETYPE_FILE0 = '\0',
  40. TAR_FILETYPE_FILE = '0',
  41. TAR_FILETYPE_HARDLINK = '1',
  42. TAR_FILETYPE_SYMLINK = '2',
  43. TAR_FILETYPE_CHARDEV = '3',
  44. TAR_FILETYPE_BLOCKDEV = '4',
  45. TAR_FILETYPE_DIR = '5',
  46. TAR_FILETYPE_FIFO = '6',
  47. TAR_FILETYPE_GNU_LONGLINK = 'K',
  48. TAR_FILETYPE_GNU_LONGNAME = 'L',
  49. };
  50. struct tar_entry {
  51. /** Tar archive format. */
  52. enum tar_format format;
  53. /** File type. */
  54. enum tar_filetype type;
  55. /** File name. */
  56. char *name;
  57. /** Symlink or hardlink name. */
  58. char *linkname;
  59. /** File size. */
  60. off_t size;
  61. /** Last-modified time. */
  62. time_t mtime;
  63. /** Special device for mknod(). */
  64. dev_t dev;
  65. struct file_stat stat;
  66. };
  67. typedef int tar_read_func(void *ctx, char *buffer, int length);
  68. typedef int tar_make_func(void *ctx, struct tar_entry *h);
  69. struct tar_operations {
  70. tar_read_func *read;
  71. tar_make_func *extract_file;
  72. tar_make_func *link;
  73. tar_make_func *symlink;
  74. tar_make_func *mkdir;
  75. tar_make_func *mknod;
  76. };
  77. int tar_extractor(void *ctx, const struct tar_operations *ops);
  78. /** @} */
  79. #endif