libarchive-static 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/Makefile +6 -0
- data/ext/extconf.rb +61 -0
- data/ext/libarchive-0.1.1/COPYING.libarchive +60 -0
- data/ext/libarchive-0.1.1/LICENSE.libbzip2 +42 -0
- data/ext/libarchive-0.1.1/README.txt +143 -0
- data/ext/libarchive-0.1.1/ext/Makefile.in +0 -0
- data/ext/libarchive-0.1.1/ext/archive_read_support_compression.c +31 -0
- data/ext/libarchive-0.1.1/ext/archive_read_support_compression.h +6 -0
- data/ext/libarchive-0.1.1/ext/archive_read_support_format.c +32 -0
- data/ext/libarchive-0.1.1/ext/archive_read_support_format.h +6 -0
- data/ext/libarchive-0.1.1/ext/archive_write_open_rb_str.c +29 -0
- data/ext/libarchive-0.1.1/ext/archive_write_open_rb_str.h +6 -0
- data/ext/libarchive-0.1.1/ext/archive_write_set_compression.c +32 -0
- data/ext/libarchive-0.1.1/ext/archive_write_set_compression.h +6 -0
- data/ext/libarchive-0.1.1/ext/config.h.in +22 -0
- data/ext/libarchive-0.1.1/ext/configure +3904 -0
- data/ext/libarchive-0.1.1/ext/configure.in +11 -0
- data/ext/libarchive-0.1.1/ext/depend +19 -0
- data/ext/libarchive-0.1.1/ext/extconf.rb +6 -0
- data/ext/libarchive-0.1.1/ext/install-sh +250 -0
- data/ext/libarchive-0.1.1/ext/libarchive.c +89 -0
- data/ext/libarchive-0.1.1/ext/libarchive_archive.c +84 -0
- data/ext/libarchive-0.1.1/ext/libarchive_entry.c +1015 -0
- data/ext/libarchive-0.1.1/ext/libarchive_internal.h +155 -0
- data/ext/libarchive-0.1.1/ext/libarchive_reader.c +328 -0
- data/ext/libarchive-0.1.1/ext/libarchive_win32.h +52 -0
- data/ext/libarchive-0.1.1/ext/libarchive_writer.c +246 -0
- data/ext/libarchive-0.1.1/libarchive.c +1762 -0
- data/ext/libarchive-2.8.4/Makefile.in +7076 -0
- data/ext/libarchive-2.8.4/build/autoconf/check_stdcall_func.m4 +51 -0
- data/ext/libarchive-2.8.4/build/autoconf/compile +143 -0
- data/ext/libarchive-2.8.4/build/autoconf/config.guess +1502 -0
- data/ext/libarchive-2.8.4/build/autoconf/config.sub +1708 -0
- data/ext/libarchive-2.8.4/build/autoconf/depcomp +630 -0
- data/ext/libarchive-2.8.4/build/autoconf/install-sh +291 -0
- data/ext/libarchive-2.8.4/build/autoconf/la_uid_t.m4 +20 -0
- data/ext/libarchive-2.8.4/build/autoconf/ltmain.sh +8406 -0
- data/ext/libarchive-2.8.4/build/autoconf/missing +376 -0
- data/ext/libarchive-2.8.4/build/pkgconfig/libarchive.pc.in +10 -0
- data/ext/libarchive-2.8.4/config.h.in +772 -0
- data/ext/libarchive-2.8.4/configure +17916 -0
- data/ext/libarchive-2.8.4/libarchive/archive.h +741 -0
- data/ext/libarchive-2.8.4/libarchive/archive_check_magic.c +134 -0
- data/ext/libarchive-2.8.4/libarchive/archive_crc32.h +66 -0
- data/ext/libarchive-2.8.4/libarchive/archive_endian.h +162 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry.c +2202 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry.h +524 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_copy_bhfi.c +74 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_copy_stat.c +77 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_link_resolver.c +405 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_private.h +184 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_stat.c +118 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_strmode.c +87 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_xattr.c +158 -0
- data/ext/libarchive-2.8.4/libarchive/archive_hash.h +281 -0
- data/ext/libarchive-2.8.4/libarchive/archive_platform.h +165 -0
- data/ext/libarchive-2.8.4/libarchive/archive_private.h +124 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read.c +1249 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_data_into_fd.c +93 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_disk.c +198 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_disk_entry_from_file.c +570 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_disk_private.h +62 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_disk_set_standard_lookup.c +303 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_extract.c +182 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_open_fd.c +190 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_open_file.c +165 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_open_filename.c +272 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_open_memory.c +156 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_private.h +199 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_all.c +60 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_bzip2.c +353 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_compress.c +444 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_gzip.c +465 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_none.c +40 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_program.c +459 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_rpm.c +287 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_uu.c +627 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_xz.c +708 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_all.c +43 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_ar.c +584 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_cpio.c +777 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_empty.c +93 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_iso9660.c +2830 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_mtree.c +1304 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_raw.c +185 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_tar.c +2418 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_xar.c +3151 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_zip.c +903 -0
- data/ext/libarchive-2.8.4/libarchive/archive_string.c +453 -0
- data/ext/libarchive-2.8.4/libarchive/archive_string.h +148 -0
- data/ext/libarchive-2.8.4/libarchive/archive_string_sprintf.c +164 -0
- data/ext/libarchive-2.8.4/libarchive/archive_util.c +391 -0
- data/ext/libarchive-2.8.4/libarchive/archive_virtual.c +94 -0
- data/ext/libarchive-2.8.4/libarchive/archive_windows.c +1236 -0
- data/ext/libarchive-2.8.4/libarchive/archive_windows.h +347 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write.c +466 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_disk.c +2628 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_disk_private.h +38 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_disk_set_standard_lookup.c +262 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_open_fd.c +141 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_open_file.c +105 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_open_filename.c +162 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_open_memory.c +126 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_private.h +122 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_bzip2.c +408 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_compress.c +492 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_gzip.c +477 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_none.c +257 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_program.c +347 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_xz.c +438 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format.c +72 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_ar.c +550 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_by_name.c +76 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_cpio.c +344 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_cpio_newc.c +295 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_mtree.c +1050 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_pax.c +1386 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_shar.c +626 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_ustar.c +587 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_zip.c +667 -0
- data/ext/libarchive-2.8.4/libarchive/config_freebsd.h +154 -0
- data/ext/libarchive-2.8.4/libarchive/filter_fork.c +161 -0
- data/ext/libarchive-2.8.4/libarchive/filter_fork.h +41 -0
- data/ext/libarchive-2.8.4/libarchive/filter_fork_windows.c +113 -0
- data/ext/libarchive-static-makefile +80 -0
- data/ext/libarchive-static-wrapper-makefile +22 -0
- data/ext/zlib-1.2.5/Makefile.in +257 -0
- data/ext/zlib-1.2.5/adler32.c +169 -0
- data/ext/zlib-1.2.5/compress.c +80 -0
- data/ext/zlib-1.2.5/configure +596 -0
- data/ext/zlib-1.2.5/crc32.c +442 -0
- data/ext/zlib-1.2.5/crc32.h +441 -0
- data/ext/zlib-1.2.5/deflate.c +1834 -0
- data/ext/zlib-1.2.5/deflate.h +342 -0
- data/ext/zlib-1.2.5/example.c +565 -0
- data/ext/zlib-1.2.5/gzclose.c +25 -0
- data/ext/zlib-1.2.5/gzguts.h +132 -0
- data/ext/zlib-1.2.5/gzlib.c +537 -0
- data/ext/zlib-1.2.5/gzread.c +653 -0
- data/ext/zlib-1.2.5/gzwrite.c +531 -0
- data/ext/zlib-1.2.5/infback.c +632 -0
- data/ext/zlib-1.2.5/inffast.c +340 -0
- data/ext/zlib-1.2.5/inffast.h +11 -0
- data/ext/zlib-1.2.5/inffixed.h +94 -0
- data/ext/zlib-1.2.5/inflate.c +1480 -0
- data/ext/zlib-1.2.5/inflate.h +122 -0
- data/ext/zlib-1.2.5/inftrees.c +330 -0
- data/ext/zlib-1.2.5/inftrees.h +62 -0
- data/ext/zlib-1.2.5/minigzip.c +440 -0
- data/ext/zlib-1.2.5/trees.c +1244 -0
- data/ext/zlib-1.2.5/trees.h +128 -0
- data/ext/zlib-1.2.5/uncompr.c +59 -0
- data/ext/zlib-1.2.5/zconf.h +428 -0
- data/ext/zlib-1.2.5/zlib.h +1613 -0
- data/ext/zlib-1.2.5/zutil.c +318 -0
- data/ext/zlib-1.2.5/zutil.h +274 -0
- metadata +211 -0
@@ -0,0 +1,344 @@
|
|
1
|
+
/*-
|
2
|
+
* Copyright (c) 2003-2007 Tim Kientzle
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
6
|
+
* modification, are permitted provided that the following conditions
|
7
|
+
* are met:
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer in the
|
12
|
+
* documentation and/or other materials provided with the distribution.
|
13
|
+
*
|
14
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
15
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
16
|
+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
17
|
+
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
18
|
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
19
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
20
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
21
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
22
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
23
|
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
*/
|
25
|
+
|
26
|
+
#include "archive_platform.h"
|
27
|
+
__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_cpio.c 201170 2009-12-29 06:34:23Z kientzle $");
|
28
|
+
|
29
|
+
#ifdef HAVE_ERRNO_H
|
30
|
+
#include <errno.h>
|
31
|
+
#endif
|
32
|
+
#include <stdio.h>
|
33
|
+
#ifdef HAVE_STDLIB_H
|
34
|
+
#include <stdlib.h>
|
35
|
+
#endif
|
36
|
+
#ifdef HAVE_STRING_H
|
37
|
+
#include <string.h>
|
38
|
+
#endif
|
39
|
+
|
40
|
+
#include "archive.h"
|
41
|
+
#include "archive_entry.h"
|
42
|
+
#include "archive_private.h"
|
43
|
+
#include "archive_write_private.h"
|
44
|
+
|
45
|
+
static ssize_t archive_write_cpio_data(struct archive_write *,
|
46
|
+
const void *buff, size_t s);
|
47
|
+
static int archive_write_cpio_finish(struct archive_write *);
|
48
|
+
static int archive_write_cpio_destroy(struct archive_write *);
|
49
|
+
static int archive_write_cpio_finish_entry(struct archive_write *);
|
50
|
+
static int archive_write_cpio_header(struct archive_write *,
|
51
|
+
struct archive_entry *);
|
52
|
+
static int format_octal(int64_t, void *, int);
|
53
|
+
static int64_t format_octal_recursive(int64_t, char *, int);
|
54
|
+
|
55
|
+
struct cpio {
|
56
|
+
uint64_t entry_bytes_remaining;
|
57
|
+
|
58
|
+
int64_t ino_next;
|
59
|
+
|
60
|
+
struct { int64_t old; int new;} *ino_list;
|
61
|
+
size_t ino_list_size;
|
62
|
+
size_t ino_list_next;
|
63
|
+
};
|
64
|
+
|
65
|
+
struct cpio_header {
|
66
|
+
char c_magic[6];
|
67
|
+
char c_dev[6];
|
68
|
+
char c_ino[6];
|
69
|
+
char c_mode[6];
|
70
|
+
char c_uid[6];
|
71
|
+
char c_gid[6];
|
72
|
+
char c_nlink[6];
|
73
|
+
char c_rdev[6];
|
74
|
+
char c_mtime[11];
|
75
|
+
char c_namesize[6];
|
76
|
+
char c_filesize[11];
|
77
|
+
};
|
78
|
+
|
79
|
+
/*
|
80
|
+
* Set output format to 'cpio' format.
|
81
|
+
*/
|
82
|
+
int
|
83
|
+
archive_write_set_format_cpio(struct archive *_a)
|
84
|
+
{
|
85
|
+
struct archive_write *a = (struct archive_write *)_a;
|
86
|
+
struct cpio *cpio;
|
87
|
+
|
88
|
+
/* If someone else was already registered, unregister them. */
|
89
|
+
if (a->format_destroy != NULL)
|
90
|
+
(a->format_destroy)(a);
|
91
|
+
|
92
|
+
cpio = (struct cpio *)malloc(sizeof(*cpio));
|
93
|
+
if (cpio == NULL) {
|
94
|
+
archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data");
|
95
|
+
return (ARCHIVE_FATAL);
|
96
|
+
}
|
97
|
+
memset(cpio, 0, sizeof(*cpio));
|
98
|
+
a->format_data = cpio;
|
99
|
+
|
100
|
+
a->pad_uncompressed = 1;
|
101
|
+
a->format_name = "cpio";
|
102
|
+
a->format_write_header = archive_write_cpio_header;
|
103
|
+
a->format_write_data = archive_write_cpio_data;
|
104
|
+
a->format_finish_entry = archive_write_cpio_finish_entry;
|
105
|
+
a->format_finish = archive_write_cpio_finish;
|
106
|
+
a->format_destroy = archive_write_cpio_destroy;
|
107
|
+
a->archive.archive_format = ARCHIVE_FORMAT_CPIO_POSIX;
|
108
|
+
a->archive.archive_format_name = "POSIX cpio";
|
109
|
+
return (ARCHIVE_OK);
|
110
|
+
}
|
111
|
+
|
112
|
+
/*
|
113
|
+
* Ino values are as long as 64 bits on some systems; cpio format
|
114
|
+
* only allows 18 bits and relies on the ino values to identify hardlinked
|
115
|
+
* files. So, we can't merely "hash" the ino numbers since collisions
|
116
|
+
* would corrupt the archive. Instead, we generate synthetic ino values
|
117
|
+
* to store in the archive and maintain a map of original ino values to
|
118
|
+
* synthetic ones so we can preserve hardlink information.
|
119
|
+
*
|
120
|
+
* TODO: Make this more efficient. It's not as bad as it looks (most
|
121
|
+
* files don't have any hardlinks and we don't do any work here for those),
|
122
|
+
* but it wouldn't be hard to do better.
|
123
|
+
*
|
124
|
+
* TODO: Work with dev/ino pairs here instead of just ino values.
|
125
|
+
*/
|
126
|
+
static int
|
127
|
+
synthesize_ino_value(struct cpio *cpio, struct archive_entry *entry)
|
128
|
+
{
|
129
|
+
int64_t ino = archive_entry_ino64(entry);
|
130
|
+
int ino_new;
|
131
|
+
size_t i;
|
132
|
+
|
133
|
+
/*
|
134
|
+
* If no index number was given, don't assign one. In
|
135
|
+
* particular, this handles the end-of-archive marker
|
136
|
+
* correctly by giving it a zero index value. (This is also
|
137
|
+
* why we start our synthetic index numbers with one below.)
|
138
|
+
*/
|
139
|
+
if (ino == 0)
|
140
|
+
return (0);
|
141
|
+
|
142
|
+
/* Don't store a mapping if we don't need to. */
|
143
|
+
if (archive_entry_nlink(entry) < 2) {
|
144
|
+
return ++cpio->ino_next;
|
145
|
+
}
|
146
|
+
|
147
|
+
/* Look up old ino; if we have it, this is a hardlink
|
148
|
+
* and we reuse the same value. */
|
149
|
+
for (i = 0; i < cpio->ino_list_next; ++i) {
|
150
|
+
if (cpio->ino_list[i].old == ino)
|
151
|
+
return (cpio->ino_list[i].new);
|
152
|
+
}
|
153
|
+
|
154
|
+
/* Assign a new index number. */
|
155
|
+
ino_new = ++cpio->ino_next;
|
156
|
+
|
157
|
+
/* Ensure space for the new mapping. */
|
158
|
+
if (cpio->ino_list_size <= cpio->ino_list_next) {
|
159
|
+
size_t newsize = cpio->ino_list_size < 512
|
160
|
+
? 512 : cpio->ino_list_size * 2;
|
161
|
+
void *newlist = realloc(cpio->ino_list,
|
162
|
+
sizeof(cpio->ino_list[0]) * newsize);
|
163
|
+
if (newlist == NULL)
|
164
|
+
return (-1);
|
165
|
+
|
166
|
+
cpio->ino_list_size = newsize;
|
167
|
+
cpio->ino_list = newlist;
|
168
|
+
}
|
169
|
+
|
170
|
+
/* Record and return the new value. */
|
171
|
+
cpio->ino_list[cpio->ino_list_next].old = ino;
|
172
|
+
cpio->ino_list[cpio->ino_list_next].new = ino_new;
|
173
|
+
++cpio->ino_list_next;
|
174
|
+
return (ino_new);
|
175
|
+
}
|
176
|
+
|
177
|
+
static int
|
178
|
+
archive_write_cpio_header(struct archive_write *a, struct archive_entry *entry)
|
179
|
+
{
|
180
|
+
struct cpio *cpio;
|
181
|
+
const char *p, *path;
|
182
|
+
int pathlength, ret, ret2;
|
183
|
+
int64_t ino;
|
184
|
+
struct cpio_header h;
|
185
|
+
|
186
|
+
cpio = (struct cpio *)a->format_data;
|
187
|
+
ret2 = ARCHIVE_OK;
|
188
|
+
|
189
|
+
path = archive_entry_pathname(entry);
|
190
|
+
pathlength = (int)strlen(path) + 1; /* Include trailing null. */
|
191
|
+
|
192
|
+
memset(&h, 0, sizeof(h));
|
193
|
+
format_octal(070707, &h.c_magic, sizeof(h.c_magic));
|
194
|
+
format_octal(archive_entry_dev(entry), &h.c_dev, sizeof(h.c_dev));
|
195
|
+
|
196
|
+
ino = synthesize_ino_value(cpio, entry);
|
197
|
+
if (ino < 0) {
|
198
|
+
archive_set_error(&a->archive, ENOMEM,
|
199
|
+
"No memory for ino translation table");
|
200
|
+
return (ARCHIVE_FATAL);
|
201
|
+
} else if (ino > 0777777) {
|
202
|
+
archive_set_error(&a->archive, ERANGE,
|
203
|
+
"Too many files for this cpio format");
|
204
|
+
return (ARCHIVE_FATAL);
|
205
|
+
}
|
206
|
+
format_octal(ino & 0777777, &h.c_ino, sizeof(h.c_ino));
|
207
|
+
|
208
|
+
format_octal(archive_entry_mode(entry), &h.c_mode, sizeof(h.c_mode));
|
209
|
+
format_octal(archive_entry_uid(entry), &h.c_uid, sizeof(h.c_uid));
|
210
|
+
format_octal(archive_entry_gid(entry), &h.c_gid, sizeof(h.c_gid));
|
211
|
+
format_octal(archive_entry_nlink(entry), &h.c_nlink, sizeof(h.c_nlink));
|
212
|
+
if (archive_entry_filetype(entry) == AE_IFBLK
|
213
|
+
|| archive_entry_filetype(entry) == AE_IFCHR)
|
214
|
+
format_octal(archive_entry_dev(entry), &h.c_rdev, sizeof(h.c_rdev));
|
215
|
+
else
|
216
|
+
format_octal(0, &h.c_rdev, sizeof(h.c_rdev));
|
217
|
+
format_octal(archive_entry_mtime(entry), &h.c_mtime, sizeof(h.c_mtime));
|
218
|
+
format_octal(pathlength, &h.c_namesize, sizeof(h.c_namesize));
|
219
|
+
|
220
|
+
/* Non-regular files don't store bodies. */
|
221
|
+
if (archive_entry_filetype(entry) != AE_IFREG)
|
222
|
+
archive_entry_set_size(entry, 0);
|
223
|
+
|
224
|
+
/* Symlinks get the link written as the body of the entry. */
|
225
|
+
p = archive_entry_symlink(entry);
|
226
|
+
if (p != NULL && *p != '\0')
|
227
|
+
format_octal(strlen(p), &h.c_filesize, sizeof(h.c_filesize));
|
228
|
+
else
|
229
|
+
format_octal(archive_entry_size(entry),
|
230
|
+
&h.c_filesize, sizeof(h.c_filesize));
|
231
|
+
|
232
|
+
ret = (a->compressor.write)(a, &h, sizeof(h));
|
233
|
+
if (ret != ARCHIVE_OK)
|
234
|
+
return (ARCHIVE_FATAL);
|
235
|
+
|
236
|
+
ret = (a->compressor.write)(a, path, pathlength);
|
237
|
+
if (ret != ARCHIVE_OK)
|
238
|
+
return (ARCHIVE_FATAL);
|
239
|
+
|
240
|
+
cpio->entry_bytes_remaining = archive_entry_size(entry);
|
241
|
+
|
242
|
+
/* Write the symlink now. */
|
243
|
+
if (p != NULL && *p != '\0')
|
244
|
+
ret = (a->compressor.write)(a, p, strlen(p));
|
245
|
+
|
246
|
+
if (ret == ARCHIVE_OK)
|
247
|
+
ret = ret2;
|
248
|
+
return (ret);
|
249
|
+
}
|
250
|
+
|
251
|
+
static ssize_t
|
252
|
+
archive_write_cpio_data(struct archive_write *a, const void *buff, size_t s)
|
253
|
+
{
|
254
|
+
struct cpio *cpio;
|
255
|
+
int ret;
|
256
|
+
|
257
|
+
cpio = (struct cpio *)a->format_data;
|
258
|
+
if (s > cpio->entry_bytes_remaining)
|
259
|
+
s = cpio->entry_bytes_remaining;
|
260
|
+
|
261
|
+
ret = (a->compressor.write)(a, buff, s);
|
262
|
+
cpio->entry_bytes_remaining -= s;
|
263
|
+
if (ret >= 0)
|
264
|
+
return (s);
|
265
|
+
else
|
266
|
+
return (ret);
|
267
|
+
}
|
268
|
+
|
269
|
+
/*
|
270
|
+
* Format a number into the specified field.
|
271
|
+
*/
|
272
|
+
static int
|
273
|
+
format_octal(int64_t v, void *p, int digits)
|
274
|
+
{
|
275
|
+
int64_t max;
|
276
|
+
int ret;
|
277
|
+
|
278
|
+
max = (((int64_t)1) << (digits * 3)) - 1;
|
279
|
+
if (v >= 0 && v <= max) {
|
280
|
+
format_octal_recursive(v, (char *)p, digits);
|
281
|
+
ret = 0;
|
282
|
+
} else {
|
283
|
+
format_octal_recursive(max, (char *)p, digits);
|
284
|
+
ret = -1;
|
285
|
+
}
|
286
|
+
return (ret);
|
287
|
+
}
|
288
|
+
|
289
|
+
static int64_t
|
290
|
+
format_octal_recursive(int64_t v, char *p, int s)
|
291
|
+
{
|
292
|
+
if (s == 0)
|
293
|
+
return (v);
|
294
|
+
v = format_octal_recursive(v, p+1, s-1);
|
295
|
+
*p = '0' + (v & 7);
|
296
|
+
return (v >> 3);
|
297
|
+
}
|
298
|
+
|
299
|
+
static int
|
300
|
+
archive_write_cpio_finish(struct archive_write *a)
|
301
|
+
{
|
302
|
+
int er;
|
303
|
+
struct archive_entry *trailer;
|
304
|
+
|
305
|
+
trailer = archive_entry_new();
|
306
|
+
/* nlink = 1 here for GNU cpio compat. */
|
307
|
+
archive_entry_set_nlink(trailer, 1);
|
308
|
+
archive_entry_set_pathname(trailer, "TRAILER!!!");
|
309
|
+
er = archive_write_cpio_header(a, trailer);
|
310
|
+
archive_entry_free(trailer);
|
311
|
+
return (er);
|
312
|
+
}
|
313
|
+
|
314
|
+
static int
|
315
|
+
archive_write_cpio_destroy(struct archive_write *a)
|
316
|
+
{
|
317
|
+
struct cpio *cpio;
|
318
|
+
|
319
|
+
cpio = (struct cpio *)a->format_data;
|
320
|
+
free(cpio->ino_list);
|
321
|
+
free(cpio);
|
322
|
+
a->format_data = NULL;
|
323
|
+
return (ARCHIVE_OK);
|
324
|
+
}
|
325
|
+
|
326
|
+
static int
|
327
|
+
archive_write_cpio_finish_entry(struct archive_write *a)
|
328
|
+
{
|
329
|
+
struct cpio *cpio;
|
330
|
+
size_t to_write;
|
331
|
+
int ret;
|
332
|
+
|
333
|
+
cpio = (struct cpio *)a->format_data;
|
334
|
+
ret = ARCHIVE_OK;
|
335
|
+
while (cpio->entry_bytes_remaining > 0) {
|
336
|
+
to_write = cpio->entry_bytes_remaining < a->null_length ?
|
337
|
+
cpio->entry_bytes_remaining : a->null_length;
|
338
|
+
ret = (a->compressor.write)(a, a->nulls, to_write);
|
339
|
+
if (ret != ARCHIVE_OK)
|
340
|
+
return (ret);
|
341
|
+
cpio->entry_bytes_remaining -= to_write;
|
342
|
+
}
|
343
|
+
return (ret);
|
344
|
+
}
|
@@ -0,0 +1,295 @@
|
|
1
|
+
/*-
|
2
|
+
* Copyright (c) 2003-2007 Tim Kientzle
|
3
|
+
* Copyright (c) 2006 Rudolf Marek SYSGO s.r.o.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions
|
8
|
+
* are met:
|
9
|
+
* 1. Redistributions of source code must retain the above copyright
|
10
|
+
* notice, this list of conditions and the following disclaimer.
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in the
|
13
|
+
* documentation and/or other materials provided with the distribution.
|
14
|
+
*
|
15
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
16
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
17
|
+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
18
|
+
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
19
|
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
20
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
21
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
22
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
24
|
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
*/
|
26
|
+
|
27
|
+
#include "archive_platform.h"
|
28
|
+
__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_cpio_newc.c 201160 2009-12-29 05:41:57Z kientzle $");
|
29
|
+
|
30
|
+
#ifdef HAVE_ERRNO_H
|
31
|
+
#include <errno.h>
|
32
|
+
#endif
|
33
|
+
#include <stdio.h>
|
34
|
+
#ifdef HAVE_STDLIB_H
|
35
|
+
#include <stdlib.h>
|
36
|
+
#endif
|
37
|
+
#ifdef HAVE_STRING_H
|
38
|
+
#include <string.h>
|
39
|
+
#endif
|
40
|
+
|
41
|
+
#include "archive.h"
|
42
|
+
#include "archive_entry.h"
|
43
|
+
#include "archive_private.h"
|
44
|
+
#include "archive_write_private.h"
|
45
|
+
|
46
|
+
static ssize_t archive_write_newc_data(struct archive_write *,
|
47
|
+
const void *buff, size_t s);
|
48
|
+
static int archive_write_newc_finish(struct archive_write *);
|
49
|
+
static int archive_write_newc_destroy(struct archive_write *);
|
50
|
+
static int archive_write_newc_finish_entry(struct archive_write *);
|
51
|
+
static int archive_write_newc_header(struct archive_write *,
|
52
|
+
struct archive_entry *);
|
53
|
+
static int format_hex(int64_t, void *, int);
|
54
|
+
static int64_t format_hex_recursive(int64_t, char *, int);
|
55
|
+
|
56
|
+
struct cpio {
|
57
|
+
uint64_t entry_bytes_remaining;
|
58
|
+
int padding;
|
59
|
+
};
|
60
|
+
|
61
|
+
struct cpio_header_newc {
|
62
|
+
char c_magic[6];
|
63
|
+
char c_ino[8];
|
64
|
+
char c_mode[8];
|
65
|
+
char c_uid[8];
|
66
|
+
char c_gid[8];
|
67
|
+
char c_nlink[8];
|
68
|
+
char c_mtime[8];
|
69
|
+
char c_filesize[8];
|
70
|
+
char c_devmajor[8];
|
71
|
+
char c_devminor[8];
|
72
|
+
char c_rdevmajor[8];
|
73
|
+
char c_rdevminor[8];
|
74
|
+
char c_namesize[8];
|
75
|
+
char c_checksum[8];
|
76
|
+
};
|
77
|
+
|
78
|
+
/* Logic trick: difference between 'n' and next multiple of 4 */
|
79
|
+
#define PAD4(n) (3 & (1 + ~(n)))
|
80
|
+
|
81
|
+
/*
|
82
|
+
* Set output format to 'cpio' format.
|
83
|
+
*/
|
84
|
+
int
|
85
|
+
archive_write_set_format_cpio_newc(struct archive *_a)
|
86
|
+
{
|
87
|
+
struct archive_write *a = (struct archive_write *)_a;
|
88
|
+
struct cpio *cpio;
|
89
|
+
|
90
|
+
/* If someone else was already registered, unregister them. */
|
91
|
+
if (a->format_destroy != NULL)
|
92
|
+
(a->format_destroy)(a);
|
93
|
+
|
94
|
+
cpio = (struct cpio *)malloc(sizeof(*cpio));
|
95
|
+
if (cpio == NULL) {
|
96
|
+
archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data");
|
97
|
+
return (ARCHIVE_FATAL);
|
98
|
+
}
|
99
|
+
memset(cpio, 0, sizeof(*cpio));
|
100
|
+
a->format_data = cpio;
|
101
|
+
|
102
|
+
a->pad_uncompressed = 1;
|
103
|
+
a->format_name = "cpio";
|
104
|
+
a->format_write_header = archive_write_newc_header;
|
105
|
+
a->format_write_data = archive_write_newc_data;
|
106
|
+
a->format_finish_entry = archive_write_newc_finish_entry;
|
107
|
+
a->format_finish = archive_write_newc_finish;
|
108
|
+
a->format_destroy = archive_write_newc_destroy;
|
109
|
+
a->archive.archive_format = ARCHIVE_FORMAT_CPIO_SVR4_NOCRC;
|
110
|
+
a->archive.archive_format_name = "SVR4 cpio nocrc";
|
111
|
+
return (ARCHIVE_OK);
|
112
|
+
}
|
113
|
+
|
114
|
+
static int
|
115
|
+
archive_write_newc_header(struct archive_write *a, struct archive_entry *entry)
|
116
|
+
{
|
117
|
+
int64_t ino;
|
118
|
+
struct cpio *cpio;
|
119
|
+
const char *p, *path;
|
120
|
+
int pathlength, ret, ret2;
|
121
|
+
struct cpio_header_newc h;
|
122
|
+
int pad;
|
123
|
+
|
124
|
+
cpio = (struct cpio *)a->format_data;
|
125
|
+
ret2 = ARCHIVE_OK;
|
126
|
+
|
127
|
+
path = archive_entry_pathname(entry);
|
128
|
+
pathlength = (int)strlen(path) + 1; /* Include trailing null. */
|
129
|
+
|
130
|
+
memset(&h, 0, sizeof(h));
|
131
|
+
format_hex(0x070701, &h.c_magic, sizeof(h.c_magic));
|
132
|
+
format_hex(archive_entry_devmajor(entry), &h.c_devmajor,
|
133
|
+
sizeof(h.c_devmajor));
|
134
|
+
format_hex(archive_entry_devminor(entry), &h.c_devminor,
|
135
|
+
sizeof(h.c_devminor));
|
136
|
+
|
137
|
+
ino = archive_entry_ino64(entry);
|
138
|
+
if (ino > 0xffffffff) {
|
139
|
+
archive_set_error(&a->archive, ERANGE,
|
140
|
+
"large inode number truncated");
|
141
|
+
ret2 = ARCHIVE_WARN;
|
142
|
+
}
|
143
|
+
|
144
|
+
format_hex(ino & 0xffffffff, &h.c_ino, sizeof(h.c_ino));
|
145
|
+
format_hex(archive_entry_mode(entry), &h.c_mode, sizeof(h.c_mode));
|
146
|
+
format_hex(archive_entry_uid(entry), &h.c_uid, sizeof(h.c_uid));
|
147
|
+
format_hex(archive_entry_gid(entry), &h.c_gid, sizeof(h.c_gid));
|
148
|
+
format_hex(archive_entry_nlink(entry), &h.c_nlink, sizeof(h.c_nlink));
|
149
|
+
if (archive_entry_filetype(entry) == AE_IFBLK
|
150
|
+
|| archive_entry_filetype(entry) == AE_IFCHR) {
|
151
|
+
format_hex(archive_entry_rdevmajor(entry), &h.c_rdevmajor, sizeof(h.c_rdevmajor));
|
152
|
+
format_hex(archive_entry_rdevminor(entry), &h.c_rdevminor, sizeof(h.c_rdevminor));
|
153
|
+
} else {
|
154
|
+
format_hex(0, &h.c_rdevmajor, sizeof(h.c_rdevmajor));
|
155
|
+
format_hex(0, &h.c_rdevminor, sizeof(h.c_rdevminor));
|
156
|
+
}
|
157
|
+
format_hex(archive_entry_mtime(entry), &h.c_mtime, sizeof(h.c_mtime));
|
158
|
+
format_hex(pathlength, &h.c_namesize, sizeof(h.c_namesize));
|
159
|
+
format_hex(0, &h.c_checksum, sizeof(h.c_checksum));
|
160
|
+
|
161
|
+
/* Non-regular files don't store bodies. */
|
162
|
+
if (archive_entry_filetype(entry) != AE_IFREG)
|
163
|
+
archive_entry_set_size(entry, 0);
|
164
|
+
|
165
|
+
/* Symlinks get the link written as the body of the entry. */
|
166
|
+
p = archive_entry_symlink(entry);
|
167
|
+
if (p != NULL && *p != '\0')
|
168
|
+
format_hex(strlen(p), &h.c_filesize, sizeof(h.c_filesize));
|
169
|
+
else
|
170
|
+
format_hex(archive_entry_size(entry),
|
171
|
+
&h.c_filesize, sizeof(h.c_filesize));
|
172
|
+
|
173
|
+
ret = (a->compressor.write)(a, &h, sizeof(h));
|
174
|
+
if (ret != ARCHIVE_OK)
|
175
|
+
return (ARCHIVE_FATAL);
|
176
|
+
|
177
|
+
/* Pad pathname to even length. */
|
178
|
+
ret = (a->compressor.write)(a, path, pathlength);
|
179
|
+
if (ret != ARCHIVE_OK)
|
180
|
+
return (ARCHIVE_FATAL);
|
181
|
+
pad = PAD4(pathlength + sizeof(struct cpio_header_newc));
|
182
|
+
if (pad)
|
183
|
+
ret = (a->compressor.write)(a, "\0\0\0", pad);
|
184
|
+
if (ret != ARCHIVE_OK)
|
185
|
+
return (ARCHIVE_FATAL);
|
186
|
+
|
187
|
+
cpio->entry_bytes_remaining = archive_entry_size(entry);
|
188
|
+
cpio->padding = PAD4(cpio->entry_bytes_remaining);
|
189
|
+
|
190
|
+
/* Write the symlink now. */
|
191
|
+
if (p != NULL && *p != '\0') {
|
192
|
+
ret = (a->compressor.write)(a, p, strlen(p));
|
193
|
+
if (ret != ARCHIVE_OK)
|
194
|
+
return (ARCHIVE_FATAL);
|
195
|
+
pad = PAD4(strlen(p));
|
196
|
+
ret = (a->compressor.write)(a, "\0\0\0", pad);
|
197
|
+
}
|
198
|
+
|
199
|
+
if (ret == ARCHIVE_OK)
|
200
|
+
ret = ret2;
|
201
|
+
return (ret);
|
202
|
+
}
|
203
|
+
|
204
|
+
static ssize_t
|
205
|
+
archive_write_newc_data(struct archive_write *a, const void *buff, size_t s)
|
206
|
+
{
|
207
|
+
struct cpio *cpio;
|
208
|
+
int ret;
|
209
|
+
|
210
|
+
cpio = (struct cpio *)a->format_data;
|
211
|
+
if (s > cpio->entry_bytes_remaining)
|
212
|
+
s = cpio->entry_bytes_remaining;
|
213
|
+
|
214
|
+
ret = (a->compressor.write)(a, buff, s);
|
215
|
+
cpio->entry_bytes_remaining -= s;
|
216
|
+
if (ret >= 0)
|
217
|
+
return (s);
|
218
|
+
else
|
219
|
+
return (ret);
|
220
|
+
}
|
221
|
+
|
222
|
+
/*
|
223
|
+
* Format a number into the specified field.
|
224
|
+
*/
|
225
|
+
static int
|
226
|
+
format_hex(int64_t v, void *p, int digits)
|
227
|
+
{
|
228
|
+
int64_t max;
|
229
|
+
int ret;
|
230
|
+
|
231
|
+
max = (((int64_t)1) << (digits * 4)) - 1;
|
232
|
+
if (v >= 0 && v <= max) {
|
233
|
+
format_hex_recursive(v, (char *)p, digits);
|
234
|
+
ret = 0;
|
235
|
+
} else {
|
236
|
+
format_hex_recursive(max, (char *)p, digits);
|
237
|
+
ret = -1;
|
238
|
+
}
|
239
|
+
return (ret);
|
240
|
+
}
|
241
|
+
|
242
|
+
static int64_t
|
243
|
+
format_hex_recursive(int64_t v, char *p, int s)
|
244
|
+
{
|
245
|
+
if (s == 0)
|
246
|
+
return (v);
|
247
|
+
v = format_hex_recursive(v, p+1, s-1);
|
248
|
+
*p = "0123456789abcdef"[v & 0xf];
|
249
|
+
return (v >> 4);
|
250
|
+
}
|
251
|
+
|
252
|
+
static int
|
253
|
+
archive_write_newc_finish(struct archive_write *a)
|
254
|
+
{
|
255
|
+
int er;
|
256
|
+
struct archive_entry *trailer;
|
257
|
+
|
258
|
+
trailer = archive_entry_new();
|
259
|
+
archive_entry_set_nlink(trailer, 1);
|
260
|
+
archive_entry_set_pathname(trailer, "TRAILER!!!");
|
261
|
+
er = archive_write_newc_header(a, trailer);
|
262
|
+
archive_entry_free(trailer);
|
263
|
+
return (er);
|
264
|
+
}
|
265
|
+
|
266
|
+
static int
|
267
|
+
archive_write_newc_destroy(struct archive_write *a)
|
268
|
+
{
|
269
|
+
struct cpio *cpio;
|
270
|
+
|
271
|
+
cpio = (struct cpio *)a->format_data;
|
272
|
+
free(cpio);
|
273
|
+
a->format_data = NULL;
|
274
|
+
return (ARCHIVE_OK);
|
275
|
+
}
|
276
|
+
|
277
|
+
static int
|
278
|
+
archive_write_newc_finish_entry(struct archive_write *a)
|
279
|
+
{
|
280
|
+
struct cpio *cpio;
|
281
|
+
size_t to_write;
|
282
|
+
int ret;
|
283
|
+
|
284
|
+
cpio = (struct cpio *)a->format_data;
|
285
|
+
while (cpio->entry_bytes_remaining > 0) {
|
286
|
+
to_write = cpio->entry_bytes_remaining < a->null_length ?
|
287
|
+
cpio->entry_bytes_remaining : a->null_length;
|
288
|
+
ret = (a->compressor.write)(a, a->nulls, to_write);
|
289
|
+
if (ret != ARCHIVE_OK)
|
290
|
+
return (ret);
|
291
|
+
cpio->entry_bytes_remaining -= to_write;
|
292
|
+
}
|
293
|
+
ret = (a->compressor.write)(a, a->nulls, cpio->padding);
|
294
|
+
return (ret);
|
295
|
+
}
|