2 * Copyright (c) 2003-2007 Tim Kientzle
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.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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.
30 __FBSDID("$FreeBSD$");
33 Execute the following to rebuild the data for this program:
34 tail -n +35 test_read_format_isojoliet_rr.c | /bin/sh
39 file="long-joliet-file-name.textfile"
40 echo "hello" >/tmp/iso/$file
41 ln /tmp/iso/$file /tmp/iso/hardlink
42 (cd /tmp/iso; ln -s $file symlink)
43 if [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h
44 TZ=utc touch -afm -t 197001020000.01 /tmp/iso/hardlink /tmp/iso/$file /tmp/iso/dir
45 TZ=utc touch -afm -t 197001030000.02 /tmp/iso/symlink
46 TZ=utc touch -afm -t 197001020000.01 /tmp/iso
48 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso/hardlink /tmp/iso/$file /tmp/iso/dir
49 TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink
50 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso
52 F=test_read_format_iso_joliet_rockridge.iso.Z
53 mkhybrid -J -uid 1 -gid 2 /tmp/iso | compress > $F
54 uuencode $F $F > $F.uu
58 DEFINE_TEST(test_read_format_isojoliet_rr)
60 const char *refname = "test_read_format_iso_joliet_rockridge.iso.Z";
61 struct archive_entry *ae;
67 extract_reference_file(refname);
68 assert((a = archive_read_new()) != NULL);
69 assertEqualInt(0, archive_read_support_compression_all(a));
70 assertEqualInt(0, archive_read_support_format_all(a));
71 assertEqualInt(ARCHIVE_OK,
72 archive_read_open_filename(a, refname, 10240));
74 /* First entry is '.' root directory. */
75 assertEqualInt(0, archive_read_next_header(a, &ae));
76 assertEqualString(".", archive_entry_pathname(ae));
77 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
78 assertEqualInt(2048, archive_entry_size(ae));
79 assertEqualInt(86401, archive_entry_mtime(ae));
80 assertEqualInt(0, archive_entry_mtime_nsec(ae));
81 assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
82 assertEqualInt(1, archive_entry_uid(ae));
83 assertEqualIntA(a, ARCHIVE_EOF,
84 archive_read_data_block(a, &p, &size, &offset));
85 assertEqualInt((int)size, 0);
88 assertEqualInt(0, archive_read_next_header(a, &ae));
89 assertEqualString("dir", archive_entry_pathname(ae));
90 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
91 assertEqualInt(2048, archive_entry_size(ae));
92 assertEqualInt(86401, archive_entry_mtime(ae));
93 assertEqualInt(86401, archive_entry_atime(ae));
94 assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
95 assertEqualInt(1, archive_entry_uid(ae));
96 assertEqualInt(2, archive_entry_gid(ae));
98 /* A regular file with two names ("hardlink" gets returned
99 * first, so it's not marked as a hardlink). */
100 assertEqualInt(0, archive_read_next_header(a, &ae));
101 assertEqualString("hardlink",
102 archive_entry_pathname(ae));
103 assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
104 assert(archive_entry_hardlink(ae) == NULL);
105 assertEqualInt(6, archive_entry_size(ae));
106 assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset));
107 assertEqualInt(6, (int)size);
108 assertEqualInt(0, offset);
109 assertEqualInt(0, memcmp(p, "hello\n", 6));
110 assertEqualInt(86401, archive_entry_mtime(ae));
111 /* mkisofs records their access time. */
112 /*assertEqualInt(86401, archive_entry_atime(ae));*/
113 /* TODO: Actually, libarchive should be able to
114 * compute nlinks correctly even without RR
115 * extensions. See comments in libarchive source. */
116 assertEqualInt(2, archive_entry_nlink(ae));
117 assertEqualInt(1, archive_entry_uid(ae));
118 assertEqualInt(2, archive_entry_gid(ae));
120 /* Second name for the same regular file (this happens to be
121 * returned second, so does get marked as a hardlink). */
122 assertEqualInt(0, archive_read_next_header(a, &ae));
123 assertEqualString("long-joliet-file-name.textfile",
124 archive_entry_pathname(ae));
125 assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
126 assertEqualString("hardlink",
127 archive_entry_hardlink(ae));
128 assert(!archive_entry_size_is_set(ae));
129 assertEqualInt(86401, archive_entry_mtime(ae));
130 assertEqualInt(86401, archive_entry_atime(ae));
131 /* TODO: See above. */
132 assertEqualInt(2, archive_entry_nlink(ae));
133 assertEqualInt(1, archive_entry_uid(ae));
134 assertEqualInt(2, archive_entry_gid(ae));
136 /* A symlink to the regular file. */
137 assertEqualInt(0, archive_read_next_header(a, &ae));
138 assertEqualString("symlink", archive_entry_pathname(ae));
139 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
140 assertEqualString("long-joliet-file-name.textfile",
141 archive_entry_symlink(ae));
142 assertEqualInt(0, archive_entry_size(ae));
143 assertEqualInt(172802, archive_entry_mtime(ae));
144 assertEqualInt(172802, archive_entry_atime(ae));
145 assertEqualInt(1, archive_entry_nlink(ae));
146 assertEqualInt(1, archive_entry_uid(ae));
147 assertEqualInt(2, archive_entry_gid(ae));
149 /* End of archive. */
150 assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
152 /* Verify archive format. */
153 assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS);
154 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
156 /* Close the archive. */
157 assertEqualInt(0, archive_read_close(a));
158 assertEqualInt(0, archive_read_finish(a));