test_read_format_isorr_ce.c revision 299529
1/*-
2 * Copyright (c) 2003-2007 Tim Kientzle
3 * Copyright (c) 2009 Michihiro NAKAJIMA
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#include "test.h"
27__FBSDID("$FreeBSD: head/contrib/libarchive/libarchive/test/test_read_format_isorr_ce.c 299529 2016-05-12 10:16:16Z mm $");
28
29/*
30Execute the following command to rebuild the data for this program:
31   tail -n +32 test_read_format_isorr_ce.c | /bin/sh
32
33dirname=/tmp/iso
34#
35rm -rf $dirname
36mkdir $dirname
37#
38num=0
39file=""
40while [ $num -lt 150 ]
41do
42  num=$((num+1))
43  file="a$file"
44done
45#
46num=0
47while [ $num -lt 3 ]
48do
49  num=$((num+1))
50  file="a$file"
51  echo "hello $((num+150))" > $dirname/$file
52  dd if=/dev/zero count=1 bs=4080 >> $dirname/$file
53  (cd $dirname; ln -s $file sym$num)
54done
55#
56mkdir $dirname/dir
57#
58time1="197001020000.01"
59time2="197001030000.02"
60TZ=utc touch -afhm -t $time1 $dirname/dir $dirname/aaaa*
61TZ=utc touch -afhm -t $time2 $dirname/sym*
62TZ=utc touch -afhm -t $time1 $dirname
63#
64F=test_read_format_iso_rockridge_ce.iso.Z
65mkisofs -R -uid 1 -gid 2 $dirname | compress > $F
66uuencode $F $F > $F.uu
67rm -rf $dirname
68exit 1
69 */
70
71/*
72 * Test reading SUSP "CE" extension is works fine.
73 */
74
75static void
76mkpath(char *p, int len)
77{
78	int i;
79
80	for (i = 0; i < len; i++)
81		p[i] = 'a';
82	p[len] = '\0';
83}
84
85DEFINE_TEST(test_read_format_isorr_ce)
86{
87	const char *refname = "test_read_format_iso_rockridge_ce.iso.Z";
88	char path1[160];
89	char path2[160];
90	char path3[160];
91	struct archive_entry *ae;
92	struct archive *a;
93	const void *p;
94	size_t size;
95	int64_t offset;
96	int i;
97
98	mkpath(path1, 151);
99	mkpath(path2, 152);
100	mkpath(path3, 153);
101	extract_reference_file(refname);
102	assert((a = archive_read_new()) != NULL);
103	assertEqualInt(0, archive_read_support_filter_all(a));
104	assertEqualInt(0, archive_read_support_format_all(a));
105	assertEqualInt(ARCHIVE_OK,
106	    archive_read_open_filename(a, refname, 10240));
107
108	/* Retrieve each of the 8 files on the ISO image and
109	 * verify that each one is what we expect. */
110	for (i = 0; i < 8; ++i) {
111		assertEqualInt(0, archive_read_next_header(a, &ae));
112
113		assertEqualInt(archive_entry_is_encrypted(ae), 0);
114		assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
115
116		if (strcmp(".", archive_entry_pathname(ae)) == 0) {
117			/* '.' root directory. */
118			assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
119			assertEqualInt(2048, archive_entry_size(ae));
120			/* Now, we read timestamp recorded by RRIP "TF". */
121			assertEqualInt(86401, archive_entry_mtime(ae));
122			assertEqualInt(0, archive_entry_mtime_nsec(ae));
123			/* Now, we read links recorded by RRIP "PX". */
124			assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
125			assertEqualInt(1, archive_entry_uid(ae));
126			assertEqualIntA(a, ARCHIVE_EOF,
127			    archive_read_data_block(a, &p, &size, &offset));
128			assertEqualInt((int)size, 0);
129		} else if (strcmp("dir", archive_entry_pathname(ae)) == 0) {
130			/* A directory. */
131			assertEqualString("dir", archive_entry_pathname(ae));
132			assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
133			assertEqualInt(2048, archive_entry_size(ae));
134			assertEqualInt(86401, archive_entry_mtime(ae));
135			assertEqualInt(86401, archive_entry_atime(ae));
136			assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
137			assertEqualInt(1, archive_entry_uid(ae));
138			assertEqualInt(2, archive_entry_gid(ae));
139		} else if (strcmp(path1, archive_entry_pathname(ae)) == 0) {
140			/* A regular file. */
141			assertEqualString(path1, archive_entry_pathname(ae));
142			assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
143			assertEqualInt(4090, archive_entry_size(ae));
144			assertEqualInt(0,
145			    archive_read_data_block(a, &p, &size, &offset));
146			assertEqualInt(0, offset);
147			assertEqualMem(p, "hello 151\n", 10);
148			assertEqualInt(86401, archive_entry_mtime(ae));
149			assertEqualInt(86401, archive_entry_atime(ae));
150			assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
151			assertEqualInt(1, archive_entry_uid(ae));
152			assertEqualInt(2, archive_entry_gid(ae));
153		} else if (strcmp(path2, archive_entry_pathname(ae)) == 0) {
154			/* A regular file. */
155			assertEqualString(path2, archive_entry_pathname(ae));
156			assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
157			assertEqualInt(4090, archive_entry_size(ae));
158			assertEqualInt(0,
159			    archive_read_data_block(a, &p, &size, &offset));
160			assertEqualInt(0, offset);
161			assertEqualMem(p, "hello 152\n", 10);
162			assertEqualInt(86401, archive_entry_mtime(ae));
163			assertEqualInt(86401, archive_entry_atime(ae));
164			assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
165			assertEqualInt(1, archive_entry_uid(ae));
166			assertEqualInt(2, archive_entry_gid(ae));
167		} else if (strcmp(path3, archive_entry_pathname(ae)) == 0) {
168			/* A regular file. */
169			assertEqualString(path3, archive_entry_pathname(ae));
170			assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
171			assertEqualInt(4090, archive_entry_size(ae));
172			assertEqualInt(0,
173			    archive_read_data_block(a, &p, &size, &offset));
174			assertEqualInt(0, offset);
175			assertEqualMem(p, "hello 153\n", 10);
176			assertEqualInt(86401, archive_entry_mtime(ae));
177			assertEqualInt(86401, archive_entry_atime(ae));
178			assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
179			assertEqualInt(1, archive_entry_uid(ae));
180			assertEqualInt(2, archive_entry_gid(ae));
181		} else if (strcmp("sym1", archive_entry_pathname(ae)) == 0) {
182			/* A symlink to the regular file. */
183			assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
184			assertEqualString(path1, archive_entry_symlink(ae));
185			assertEqualInt(0, archive_entry_size(ae));
186			assertEqualInt(172802, archive_entry_mtime(ae));
187			assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
188			assertEqualInt(1, archive_entry_uid(ae));
189			assertEqualInt(2, archive_entry_gid(ae));
190		} else if (strcmp("sym2", archive_entry_pathname(ae)) == 0) {
191			/* A symlink to the regular file. */
192			assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
193			assertEqualString(path2, archive_entry_symlink(ae));
194			assertEqualInt(0, archive_entry_size(ae));
195			assertEqualInt(172802, archive_entry_mtime(ae));
196			assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
197			assertEqualInt(1, archive_entry_uid(ae));
198			assertEqualInt(2, archive_entry_gid(ae));
199		} else if (strcmp("sym3", archive_entry_pathname(ae)) == 0) {
200			/* A symlink to the regular file. */
201			assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
202			assertEqualString(path3, archive_entry_symlink(ae));
203			assertEqualInt(0, archive_entry_size(ae));
204			assertEqualInt(172802, archive_entry_mtime(ae));
205			assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
206			assertEqualInt(1, archive_entry_uid(ae));
207			assertEqualInt(2, archive_entry_gid(ae));
208		} else {
209			failure("Saw a file that shouldn't have been there");
210			assertEqualString(archive_entry_pathname(ae), "");
211		}
212	}
213
214	/* End of archive. */
215	assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
216
217	/* Verify archive format. */
218	assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
219	assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
220
221	/* Close the archive. */
222	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
223	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
224}
225
226
227