dpkg (1.18.25) stretch; urgency=medium
[dpkg] / lib / dpkg / tarfn.h
CommitLineData
1479465f
GJ
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, 2017 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
22#ifndef LIBDPKG_TARFN_H
23#define LIBDPKG_TARFN_H
24
25#include <sys/types.h>
26
27#include <stdint.h>
28
29#include <dpkg/file.h>
30
31/**
32 * @defgroup tar Tar archive handling
33 * @ingroup dpkg-public
34 * @{
35 */
36
37#define TARBLKSZ 512
38
39enum tar_format {
40 TAR_FORMAT_OLD,
41 TAR_FORMAT_GNU,
42 TAR_FORMAT_USTAR,
43 TAR_FORMAT_PAX,
44};
45
46enum tar_filetype {
47 /** For compatibility with decades-old bug. */
48 TAR_FILETYPE_FILE0 = '\0',
49 TAR_FILETYPE_FILE = '0',
50 TAR_FILETYPE_HARDLINK = '1',
51 TAR_FILETYPE_SYMLINK = '2',
52 TAR_FILETYPE_CHARDEV = '3',
53 TAR_FILETYPE_BLOCKDEV = '4',
54 TAR_FILETYPE_DIR = '5',
55 TAR_FILETYPE_FIFO = '6',
56 TAR_FILETYPE_GNU_LONGLINK = 'K',
57 TAR_FILETYPE_GNU_LONGNAME = 'L',
58};
59
60struct tar_entry {
61 /** Tar archive format. */
62 enum tar_format format;
63 /** File type. */
64 enum tar_filetype type;
65 /** File name. */
66 char *name;
67 /** Symlink or hardlink name. */
68 char *linkname;
69 /** File size. */
70 off_t size;
71 /** Last-modified time. */
72 time_t mtime;
73 /** Special device for mknod(). */
74 dev_t dev;
75
76 struct file_stat stat;
77};
78
79typedef int tar_read_func(void *ctx, char *buffer, int length);
80typedef int tar_make_func(void *ctx, struct tar_entry *h);
81
82struct tar_operations {
83 tar_read_func *read;
84
85 tar_make_func *extract_file;
86 tar_make_func *link;
87 tar_make_func *symlink;
88 tar_make_func *mkdir;
89 tar_make_func *mknod;
90};
91
92uintmax_t
93tar_atoul(const char *s, size_t size, uintmax_t max);
94intmax_t
95tar_atosl(const char *s, size_t size, intmax_t min, intmax_t max);
96
97void
98tar_entry_update_from_system(struct tar_entry *te);
99
100int tar_extractor(void *ctx, const struct tar_operations *ops);
101
102/** @} */
103
104#endif