2 * Copyright (c) 2011 Michihiro NAKAJIMA
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
26 __FBSDID("$FreeBSD$");
29 * Verify our ability to read sample files created by Solaris pax for
33 test_compat_solaris_pax_sparse_1(void)
35 char name[] = "test_compat_solaris_pax_sparse_1.pax.Z";
36 struct archive_entry *ae;
38 int64_t offset, length;
44 assert((a = archive_read_new()) != NULL);
45 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
46 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
47 extract_reference_file(name);
48 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
50 /* Read first entry. */
51 assertEqualIntA(a, ARCHIVE_OK, r = archive_read_next_header(a, &ae));
52 if (r != ARCHIVE_OK) {
56 assertEqualString("hole", archive_entry_pathname(ae));
57 assertEqualInt(1310411683, archive_entry_mtime(ae));
58 assertEqualInt(101, archive_entry_uid(ae));
59 assertEqualString("cue", archive_entry_uname(ae));
60 assertEqualInt(10, archive_entry_gid(ae));
61 assertEqualString("staff", archive_entry_gname(ae));
62 assertEqualInt(0100644, archive_entry_mode(ae));
64 /* Verify the sparse information. */
65 failure("This sparse file should have tree data blocks");
66 assertEqualInt(3, archive_entry_sparse_reset(ae));
67 assertEqualInt(ARCHIVE_OK,
68 archive_entry_sparse_next(ae, &offset, &length));
69 assertEqualInt(0, offset);
70 assertEqualInt(131072, length);
71 assertEqualInt(ARCHIVE_OK,
72 archive_entry_sparse_next(ae, &offset, &length));
73 assertEqualInt(393216, offset);
74 assertEqualInt(131072, length);
75 assertEqualInt(ARCHIVE_OK,
76 archive_entry_sparse_next(ae, &offset, &length));
77 assertEqualInt(786432, offset);
78 assertEqualInt(32775, length);
80 archive_read_data_block(a, &buff, &bytes_read, &offset)) {
81 failure("The data blocks should not include the hole");
82 assert((offset >= 0 && offset + bytes_read <= 131072) ||
83 (offset >= 393216 && offset + bytes_read <= 393216+131072) ||
84 (offset >= 786432 && offset + bytes_read <= 786432+32775));
85 if (offset == 0 && bytes_read >= 1024*8) {
86 memset(data, 'a', sizeof(data));
87 failure("First data block should be 8K bytes of 'a'");
88 assertEqualMem(buff, data, sizeof(data));
89 } else if (offset + bytes_read == 819207 && bytes_read >= 7) {
90 const char *last = buff;
91 last += bytes_read - 7;
93 failure("Last seven bytes should be all 'c'");
94 assertEqualMem(last, data, 7);
98 /* Verify the end-of-archive. */
99 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
101 /* Verify that the format detection worked. */
102 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
103 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE);
105 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
106 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
110 * Verify our ability to read sample files created by Solaris pax for
111 * a sparse file which begin with hole.
114 test_compat_solaris_pax_sparse_2(void)
116 char name[] = "test_compat_solaris_pax_sparse_2.pax.Z";
117 struct archive_entry *ae;
119 int64_t offset, length;
124 assert((a = archive_read_new()) != NULL);
125 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
126 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
127 extract_reference_file(name);
128 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
130 /* Read first entry. */
131 assertEqualIntA(a, ARCHIVE_OK, r = archive_read_next_header(a, &ae));
132 if (r != ARCHIVE_OK) {
133 archive_read_free(a);
136 assertEqualString("hole", archive_entry_pathname(ae));
137 assertEqualInt(1310416789, archive_entry_mtime(ae));
138 assertEqualInt(101, archive_entry_uid(ae));
139 assertEqualString("cue", archive_entry_uname(ae));
140 assertEqualInt(10, archive_entry_gid(ae));
141 assertEqualString("staff", archive_entry_gname(ae));
142 assertEqualInt(0100644, archive_entry_mode(ae));
144 /* Verify the sparse information. */
145 failure("This sparse file should have two data blocks");
146 assertEqualInt(2, archive_entry_sparse_reset(ae));
147 assertEqualInt(ARCHIVE_OK,
148 archive_entry_sparse_next(ae, &offset, &length));
149 assertEqualInt(393216, offset);
150 assertEqualInt(131072, length);
151 assertEqualInt(ARCHIVE_OK,
152 archive_entry_sparse_next(ae, &offset, &length));
153 assertEqualInt(786432, offset);
154 assertEqualInt(32799, length);
156 archive_read_data_block(a, &buff, &bytes_read, &offset)) {
157 failure("The data blocks should not include the hole");
158 assert((offset >= 393216 && offset + bytes_read <= 393216+131072) ||
159 (offset >= 786432 && offset + bytes_read <= 786432+32799));
160 if (offset + bytes_read == 819231 && bytes_read >= 31) {
162 const char *last = buff;
163 last += bytes_read - 31;
164 memset(data, 'c', 31);
165 failure("Last 31 bytes should be all 'c'");
166 assertEqualMem(last, data, 31);
170 /* Verify the end-of-archive. */
171 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
173 /* Verify that the format detection worked. */
174 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
175 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE);
177 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
178 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
182 DEFINE_TEST(test_compat_solaris_pax_sparse)
184 test_compat_solaris_pax_sparse_1();
185 test_compat_solaris_pax_sparse_2();