2 * Copyright (c) 2003-2007 Tim Kientzle
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 PLEASE use old cdrtools; mkisofs version is 2.01.
30 This version mkisofs made wrong "SL" System Use Entry of RRIP.
32 Execute the following command to rebuild the data for this program:
33 tail -n +34 test_read_format_isorr_bz2.c | /bin/sh
38 echo "hello" >/tmp/iso/file
39 dd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file
40 ln /tmp/iso/file /tmp/iso/hardlink
41 (cd /tmp/iso; ln -s file symlink)
42 (cd /tmp/iso; ln -s /tmp/ symlink2)
43 (cd /tmp/iso; ln -s /tmp/../ symlink3)
44 (cd /tmp/iso; ln -s .././../tmp/ symlink4)
45 (cd /tmp/iso; ln -s .///file symlink5)
46 (cd /tmp/iso; ln -s /tmp//../ symlink6)
47 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir
48 TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink /tmp/iso/symlink5
49 F=test_read_format_iso_rockridge.iso.Z
50 mkhybrid -R -uid 1 -gid 2 /tmp/iso | compress > $F
51 uuencode $F $F > $F.uu
55 DEFINE_TEST(test_read_format_isorr_bz2)
57 const char *refname = "test_read_format_iso_rockridge.iso.Z";
58 struct archive_entry *ae;
65 extract_reference_file(refname);
66 assert((a = archive_read_new()) != NULL);
67 assertEqualInt(0, archive_read_support_filter_all(a));
68 assertEqualInt(0, archive_read_support_format_all(a));
69 assertEqualInt(ARCHIVE_OK,
70 archive_read_open_filename(a, refname, 10240));
72 /* Retrieve each of the 8 files on the ISO image and
73 * verify that each one is what we expect. */
74 for (i = 0; i < 10; ++i) {
75 assertEqualInt(0, archive_read_next_header(a, &ae));
77 assertEqualInt(archive_entry_is_encrypted(ae), 0);
78 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
80 if (strcmp(".", archive_entry_pathname(ae)) == 0) {
81 /* '.' root directory. */
82 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
83 assertEqualInt(2048, archive_entry_size(ae));
84 /* Now, we read timestamp recorded by RRIP "TF". */
85 assertEqualInt(86401, archive_entry_mtime(ae));
86 assertEqualInt(0, archive_entry_mtime_nsec(ae));
87 /* Now, we read links recorded by RRIP "PX". */
88 assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
89 assertEqualInt(1, archive_entry_uid(ae));
90 assertEqualIntA(a, ARCHIVE_EOF,
91 archive_read_data_block(a, &p, &size, &offset));
92 assertEqualInt((int)size, 0);
93 } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) {
95 assertEqualString("dir", archive_entry_pathname(ae));
96 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
97 assertEqualInt(2048, archive_entry_size(ae));
98 assertEqualInt(86401, archive_entry_mtime(ae));
99 assertEqualInt(86401, archive_entry_atime(ae));
100 assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
101 assertEqualInt(1, archive_entry_uid(ae));
102 assertEqualInt(2, archive_entry_gid(ae));
103 } else if (strcmp("file", archive_entry_pathname(ae)) == 0) {
104 /* A regular file. */
105 assertEqualString("file", archive_entry_pathname(ae));
106 assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
107 assertEqualInt(12345684, archive_entry_size(ae));
109 archive_read_data_block(a, &p, &size, &offset));
110 assertEqualInt(0, offset);
111 assertEqualMem(p, "hello\n", 6);
112 assertEqualInt(86401, archive_entry_mtime(ae));
113 assertEqualInt(86401, archive_entry_atime(ae));
114 assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
115 assertEqualInt(1, archive_entry_uid(ae));
116 assertEqualInt(2, archive_entry_gid(ae));
117 } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) {
118 /* A hardlink to the regular file. */
119 /* Note: If "hardlink" gets returned before "file",
120 * then "hardlink" will get returned as a regular file
121 * and "file" will get returned as the hardlink.
122 * This test should tolerate that, since it's a
123 * perfectly permissible thing for libarchive to do. */
124 assertEqualString("hardlink", archive_entry_pathname(ae));
125 assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
126 assertEqualString("file", archive_entry_hardlink(ae));
127 assertEqualInt(0, archive_entry_size_is_set(ae));
128 assertEqualInt(0, archive_entry_size(ae));
129 assertEqualInt(86401, archive_entry_mtime(ae));
130 assertEqualInt(86401, archive_entry_atime(ae));
131 assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
132 assertEqualInt(1, archive_entry_uid(ae));
133 assertEqualInt(2, archive_entry_gid(ae));
134 } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) {
135 /* A symlink to the regular file. */
136 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
137 assertEqualString("file", archive_entry_symlink(ae));
138 assertEqualInt(0, archive_entry_size(ae));
139 assertEqualInt(172802, archive_entry_mtime(ae));
140 assertEqualInt(172802, archive_entry_atime(ae));
141 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
142 assertEqualInt(1, archive_entry_uid(ae));
143 assertEqualInt(2, archive_entry_gid(ae));
144 } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) {
145 /* A symlink to /tmp (an absolute path) */
146 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
147 assertEqualString("/tmp", archive_entry_symlink(ae));
148 assertEqualInt(0, archive_entry_size(ae));
149 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
150 assertEqualInt(1, archive_entry_uid(ae));
151 assertEqualInt(2, archive_entry_gid(ae));
152 } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) {
153 /* A symlink to /tmp/.. (with a ".." component) */
154 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
155 assertEqualString("/tmp/..", archive_entry_symlink(ae));
156 assertEqualInt(0, archive_entry_size(ae));
157 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
158 assertEqualInt(1, archive_entry_uid(ae));
159 assertEqualInt(2, archive_entry_gid(ae));
160 } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) {
161 /* A symlink to a path with ".." and "." components */
162 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
163 assertEqualString(".././../tmp",
164 archive_entry_symlink(ae));
165 assertEqualInt(0, archive_entry_size(ae));
166 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
167 assertEqualInt(1, archive_entry_uid(ae));
168 assertEqualInt(2, archive_entry_gid(ae));
169 } else if (strcmp("symlink5", archive_entry_pathname(ae)) == 0) {
170 /* A symlink to the regular file with "/" components. */
171 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
172 assertEqualString(".///file", archive_entry_symlink(ae));
173 assertEqualInt(0, archive_entry_size(ae));
174 assertEqualInt(172802, archive_entry_mtime(ae));
175 assertEqualInt(172802, archive_entry_atime(ae));
176 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
177 assertEqualInt(1, archive_entry_uid(ae));
178 assertEqualInt(2, archive_entry_gid(ae));
179 } else if (strcmp("symlink6", archive_entry_pathname(ae)) == 0) {
180 /* A symlink to /tmp//..
181 * (with "/" and ".." components) */
182 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
183 assertEqualString("/tmp//..", archive_entry_symlink(ae));
184 assertEqualInt(0, archive_entry_size(ae));
185 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
186 assertEqualInt(1, archive_entry_uid(ae));
187 assertEqualInt(2, archive_entry_gid(ae));
189 failure("Saw a file that shouldn't have been there");
190 assertEqualString(archive_entry_pathname(ae), "");
194 /* End of archive. */
195 assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
197 /* Verify archive format. */
198 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
199 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
201 /* Close the archive. */
202 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
203 assertEqualInt(ARCHIVE_OK, archive_read_free(a));