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 verion 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 if (strcmp(".", archive_entry_pathname(ae)) == 0) {
78 /* '.' root directory. */
79 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
80 assertEqualInt(2048, archive_entry_size(ae));
81 /* Now, we read timestamp recorded by RRIP "TF". */
82 assertEqualInt(86401, archive_entry_mtime(ae));
83 assertEqualInt(0, archive_entry_mtime_nsec(ae));
84 /* Now, we read links recorded by RRIP "PX". */
85 assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
86 assertEqualInt(1, archive_entry_uid(ae));
87 assertEqualIntA(a, ARCHIVE_EOF,
88 archive_read_data_block(a, &p, &size, &offset));
89 assertEqualInt((int)size, 0);
90 } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) {
92 assertEqualString("dir", archive_entry_pathname(ae));
93 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
94 assertEqualInt(2048, archive_entry_size(ae));
95 assertEqualInt(86401, archive_entry_mtime(ae));
96 assertEqualInt(86401, archive_entry_atime(ae));
97 assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
98 assertEqualInt(1, archive_entry_uid(ae));
99 assertEqualInt(2, archive_entry_gid(ae));
100 } else if (strcmp("file", archive_entry_pathname(ae)) == 0) {
101 /* A regular file. */
102 assertEqualString("file", archive_entry_pathname(ae));
103 assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
104 assertEqualInt(12345684, archive_entry_size(ae));
106 archive_read_data_block(a, &p, &size, &offset));
107 assertEqualInt(0, offset);
108 assertEqualMem(p, "hello\n", 6);
109 assertEqualInt(86401, archive_entry_mtime(ae));
110 assertEqualInt(86401, archive_entry_atime(ae));
111 assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
112 assertEqualInt(1, archive_entry_uid(ae));
113 assertEqualInt(2, archive_entry_gid(ae));
114 } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) {
115 /* A hardlink to the regular file. */
116 /* Note: If "hardlink" gets returned before "file",
117 * then "hardlink" will get returned as a regular file
118 * and "file" will get returned as the hardlink.
119 * This test should tolerate that, since it's a
120 * perfectly permissible thing for libarchive to do. */
121 assertEqualString("hardlink", archive_entry_pathname(ae));
122 assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
123 assertEqualString("file", archive_entry_hardlink(ae));
124 assertEqualInt(0, archive_entry_size_is_set(ae));
125 assertEqualInt(0, archive_entry_size(ae));
126 assertEqualInt(86401, archive_entry_mtime(ae));
127 assertEqualInt(86401, archive_entry_atime(ae));
128 assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
129 assertEqualInt(1, archive_entry_uid(ae));
130 assertEqualInt(2, archive_entry_gid(ae));
131 } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) {
132 /* A symlink to the regular file. */
133 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
134 assertEqualString("file", archive_entry_symlink(ae));
135 assertEqualInt(0, archive_entry_size(ae));
136 assertEqualInt(172802, archive_entry_mtime(ae));
137 assertEqualInt(172802, archive_entry_atime(ae));
138 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
139 assertEqualInt(1, archive_entry_uid(ae));
140 assertEqualInt(2, archive_entry_gid(ae));
141 } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) {
142 /* A symlink to /tmp (an absolute path) */
143 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
144 assertEqualString("/tmp", archive_entry_symlink(ae));
145 assertEqualInt(0, archive_entry_size(ae));
146 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
147 assertEqualInt(1, archive_entry_uid(ae));
148 assertEqualInt(2, archive_entry_gid(ae));
149 } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) {
150 /* A symlink to /tmp/.. (with a ".." component) */
151 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
152 assertEqualString("/tmp/..", archive_entry_symlink(ae));
153 assertEqualInt(0, archive_entry_size(ae));
154 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
155 assertEqualInt(1, archive_entry_uid(ae));
156 assertEqualInt(2, archive_entry_gid(ae));
157 } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) {
158 /* A symlink to a path with ".." and "." components */
159 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
160 assertEqualString(".././../tmp",
161 archive_entry_symlink(ae));
162 assertEqualInt(0, archive_entry_size(ae));
163 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
164 assertEqualInt(1, archive_entry_uid(ae));
165 assertEqualInt(2, archive_entry_gid(ae));
166 } else if (strcmp("symlink5", archive_entry_pathname(ae)) == 0) {
167 /* A symlink to the regular file with "/" components. */
168 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
169 assertEqualString(".///file", archive_entry_symlink(ae));
170 assertEqualInt(0, archive_entry_size(ae));
171 assertEqualInt(172802, archive_entry_mtime(ae));
172 assertEqualInt(172802, archive_entry_atime(ae));
173 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
174 assertEqualInt(1, archive_entry_uid(ae));
175 assertEqualInt(2, archive_entry_gid(ae));
176 } else if (strcmp("symlink6", archive_entry_pathname(ae)) == 0) {
177 /* A symlink to /tmp//..
178 * (with "/" and ".." components) */
179 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
180 assertEqualString("/tmp//..", archive_entry_symlink(ae));
181 assertEqualInt(0, archive_entry_size(ae));
182 assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
183 assertEqualInt(1, archive_entry_uid(ae));
184 assertEqualInt(2, archive_entry_gid(ae));
186 failure("Saw a file that shouldn't have been there");
187 assertEqualString(archive_entry_pathname(ae), "");
191 /* End of archive. */
192 assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
194 /* Verify archive format. */
195 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
196 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
198 /* Close the archive. */
199 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
200 assertEqualInt(ARCHIVE_OK, archive_read_free(a));