xref: /freebsd/contrib/libarchive/libarchive/test/test_read_format_isojoliet_rr.c (revision b9128a37faafede823eb456aa65a11ac69997284)
1 /*-
2  * Copyright (c) 2003-2007 Tim Kientzle
3  * All rights reserved.
4  *
5  * Based on libarchive/test/test_read_format_isorr_bz2.c with
6  * bugs introduced by Andreas Henriksson <andreas@fatal.se> for
7  * testing ISO9660 image with Joliet extension.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 #include "test.h"
30 
31 /*
32 Execute the following to rebuild the data for this program:
33    tail -n +35 test_read_format_isojoliet_rr.c | /bin/sh
34 
35 rm -rf /tmp/iso
36 mkdir /tmp/iso
37 mkdir /tmp/iso/dir
38 file="long-joliet-file-name.textfile"
39 echo "hello" >/tmp/iso/$file
40 ln /tmp/iso/$file /tmp/iso/hardlink
41 (cd /tmp/iso; ln -s $file symlink)
42 if [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h
43 TZ=utc touch -afm -t 197001020000.01 /tmp/iso/hardlink /tmp/iso/$file /tmp/iso/dir
44 TZ=utc touch -afm -t 197001030000.02 /tmp/iso/symlink
45 TZ=utc touch -afm -t 197001020000.01 /tmp/iso
46 else
47 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso/hardlink /tmp/iso/$file /tmp/iso/dir
48 TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink
49 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso
50 fi
51 F=test_read_format_iso_joliet_rockridge.iso.Z
52 mkhybrid -J -uid 1 -gid 2 /tmp/iso | compress > $F
53 uuencode $F $F > $F.uu
54 exit 1
55  */
56 
57 DEFINE_TEST(test_read_format_isojoliet_rr)
58 {
59 	const char *refname = "test_read_format_iso_joliet_rockridge.iso.Z";
60 	struct archive_entry *ae;
61 	struct archive *a;
62 	const void *p;
63 	size_t size;
64 	int64_t offset;
65 
66 	extract_reference_file(refname);
67 	assert((a = archive_read_new()) != NULL);
68 	assertEqualInt(0, archive_read_support_filter_all(a));
69 	assertEqualInt(0, archive_read_support_format_all(a));
70 	assertEqualInt(ARCHIVE_OK,
71 	    archive_read_open_filename(a, refname, 10240));
72 
73 	/* First entry is '.' root directory. */
74 	assertEqualInt(0, archive_read_next_header(a, &ae));
75 	assertEqualString(".", archive_entry_pathname(ae));
76 	assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
77 	assertEqualInt(2048, archive_entry_size(ae));
78 	assertEqualInt(86401, archive_entry_mtime(ae));
79 	assertEqualInt(0, archive_entry_mtime_nsec(ae));
80 	assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
81 	assertEqualInt(1, archive_entry_uid(ae));
82 	assertEqualIntA(a, ARCHIVE_EOF,
83 	    archive_read_data_block(a, &p, &size, &offset));
84 	assertEqualInt((int)size, 0);
85 	assertEqualInt(archive_entry_is_encrypted(ae), 0);
86 	assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
87 
88 	/* A directory. */
89 	assertEqualInt(0, archive_read_next_header(a, &ae));
90 	assertEqualString("dir", archive_entry_pathname(ae));
91 	assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
92 	assertEqualInt(2048, archive_entry_size(ae));
93 	assertEqualInt(86401, archive_entry_mtime(ae));
94 	assertEqualInt(86401, archive_entry_atime(ae));
95 	assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
96 	assertEqualInt(1, archive_entry_uid(ae));
97 	assertEqualInt(2, archive_entry_gid(ae));
98 	assertEqualInt(archive_entry_is_encrypted(ae), 0);
99 	assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
100 
101 	/* A regular file with two names ("hardlink" gets returned
102 	 * first, so it's not marked as a hardlink). */
103 	assertEqualInt(0, archive_read_next_header(a, &ae));
104 	assertEqualString("hardlink",
105 	    archive_entry_pathname(ae));
106 	assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
107 	assert(archive_entry_hardlink(ae) == NULL);
108 	assertEqualInt(6, archive_entry_size(ae));
109 	assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset));
110 	assertEqualInt(6, (int)size);
111 	assertEqualInt(0, offset);
112 	assertEqualMem(p, "hello\n", 6);
113 	assertEqualInt(86401, archive_entry_mtime(ae));
114 	/* mkisofs records their access time. */
115 	/*assertEqualInt(86401, archive_entry_atime(ae));*/
116 	/* TODO: Actually, libarchive should be able to
117 	 * compute nlinks correctly even without RR
118 	 * extensions. See comments in libarchive source. */
119 	assertEqualInt(2, archive_entry_nlink(ae));
120 	assertEqualInt(1, archive_entry_uid(ae));
121 	assertEqualInt(2, archive_entry_gid(ae));
122 	assertEqualInt(archive_entry_is_encrypted(ae), 0);
123 	assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
124 
125 	/* Second name for the same regular file (this happens to be
126 	 * returned second, so does get marked as a hardlink). */
127 	assertEqualInt(0, archive_read_next_header(a, &ae));
128 	assertEqualString("long-joliet-file-name.textfile",
129 	    archive_entry_pathname(ae));
130 	assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
131 	assertEqualString("hardlink",
132 	    archive_entry_hardlink(ae));
133 	assert(!archive_entry_size_is_set(ae));
134 	assertEqualInt(86401, archive_entry_mtime(ae));
135 	assertEqualInt(86401, archive_entry_atime(ae));
136 	/* TODO: See above. */
137 	assertEqualInt(2, archive_entry_nlink(ae));
138 	assertEqualInt(1, archive_entry_uid(ae));
139 	assertEqualInt(2, archive_entry_gid(ae));
140 	assertEqualInt(archive_entry_is_encrypted(ae), 0);
141 	assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
142 
143 	/* A symlink to the regular file. */
144 	assertEqualInt(0, archive_read_next_header(a, &ae));
145 	assertEqualString("symlink", archive_entry_pathname(ae));
146 	assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
147 	assertEqualString("long-joliet-file-name.textfile",
148 	    archive_entry_symlink(ae));
149 	assertEqualInt(0, archive_entry_size(ae));
150 	assertEqualInt(172802, archive_entry_mtime(ae));
151 	assertEqualInt(172802, archive_entry_atime(ae));
152 	assertEqualInt(1, archive_entry_nlink(ae));
153 	assertEqualInt(1, archive_entry_uid(ae));
154 	assertEqualInt(2, archive_entry_gid(ae));
155 	assertEqualInt(archive_entry_is_encrypted(ae), 0);
156 	assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
157 
158 	/* End of archive. */
159 	assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
160 
161 	/* Verify archive format. */
162 	assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
163 	assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
164 
165 	/* Close the archive. */
166 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
167 	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
168 }
169 
170