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