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 __FBSDID("$FreeBSD$");
28 
29 /*
30 Execute the following to rebuild the data for this program:
31    tail -n +35 test_read_format_isojoliet_long.c | /bin/sh
32 
33 rm -rf /tmp/iso
34 mkdir /tmp/iso
35 num=0
36 file="";
37 while [ $num -lt 100 ]
38 do
39   num=$((num+10))
40   file="${file}1234567890"
41 done
42 dir="${file}dir"
43 mkdir /tmp/iso/${dir}
44 file="${file}123"
45 echo "hello" > /tmp/iso/${file}
46 ln /tmp/iso/${file} /tmp/iso/hardlink
47 if [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h
48 TZ=utc touch -afm -t 197001020000.01 /tmp/iso /tmp/iso/${file} /tmp/iso/${dir}
49 else
50 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/${file} /tmp/iso/${dir}
51 fi
52 F=test_read_format_iso_joliet_long.iso.Z
53 mkhybrid -J -joliet-long -uid 1 -gid 2 /tmp/iso | compress > $F
54 uuencode $F $F > $F.uu
55 rm -rf /tmp/iso
56 exit 1
57  */
58 
59 DEFINE_TEST(test_read_format_isojoliet_long)
60 {
61 	const char *refname = "test_read_format_iso_joliet_long.iso.Z";
62 	char pathname[104];
63 	struct archive_entry *ae;
64 	struct archive *a;
65 	const void *p;
66 	size_t size;
67 	int64_t offset;
68 	int i;
69 
70 	for (i = 0; i < 100; i++)
71 		pathname[i] = '0' + ((i+1) % 10);
72 	extract_reference_file(refname);
73 	assert((a = archive_read_new()) != NULL);
74 	assertEqualInt(0, archive_read_support_filter_all(a));
75 	assertEqualInt(0, archive_read_support_format_all(a));
76 	assertEqualInt(ARCHIVE_OK,
77 	    archive_read_set_options(a, "iso9660:!rockridge"));
78 	assertEqualInt(ARCHIVE_OK,
79 	    archive_read_open_filename(a, refname, 10240));
80 
81 	/* First entry is '.' root directory. */
82 	assertEqualInt(0, archive_read_next_header(a, &ae));
83 	assertEqualString(".", archive_entry_pathname(ae));
84 	assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
85 	assertEqualInt(2048, archive_entry_size(ae));
86 	assertEqualInt(86401, archive_entry_mtime(ae));
87 	assertEqualInt(0, archive_entry_mtime_nsec(ae));
88 	assertEqualInt(86401, archive_entry_ctime(ae));
89 	assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
90 	assertEqualInt(0, archive_entry_uid(ae));
91 	assertEqualIntA(a, ARCHIVE_EOF,
92 	    archive_read_data_block(a, &p, &size, &offset));
93 	assertEqualInt((int)size, 0);
94 
95 	/* A directory. */
96 	pathname[100] = 'd';
97 	pathname[101] = 'i';
98 	pathname[102] = 'r';
99 	pathname[103] = '\0';
100 	assertEqualInt(0, archive_read_next_header(a, &ae));
101 	assertEqualString(pathname, archive_entry_pathname(ae));
102 	assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
103 	assertEqualInt(2048, archive_entry_size(ae));
104 	assertEqualInt(86401, archive_entry_mtime(ae));
105 	assertEqualInt(86401, archive_entry_atime(ae));
106 
107 	/* A regular file with two names (pathname gets returned
108 	 * first, so it's not marked as a hardlink). */
109 	pathname[100] = '1';
110 	pathname[101] = '2';
111 	pathname[102] = '3';
112 	pathname[103] = '\0';
113 	assertEqualInt(0, archive_read_next_header(a, &ae));
114 	assertEqualString("hardlink", archive_entry_pathname(ae));
115 	assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
116 	assert(archive_entry_hardlink(ae) == NULL);
117 	assertEqualInt(6, archive_entry_size(ae));
118 	assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset));
119 	assertEqualInt(6, (int)size);
120 	assertEqualInt(0, offset);
121 	assertEqualMem(p, "hello\n", 6);
122 
123 	/* Second name for the same regular file (this happens to be
124 	 * returned second, so does get marked as a hardlink). */
125 	assertEqualInt(0, archive_read_next_header(a, &ae));
126 	assertEqualString(pathname, archive_entry_pathname(ae));
127 	assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
128 	assertEqualString("hardlink", archive_entry_hardlink(ae));
129 	assert(!archive_entry_size_is_set(ae));
130 
131 	/* End of archive. */
132 	assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
133 
134 	/* Verify archive format. */
135 	assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
136 
137 	/* Close the archive. */
138 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
139 	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
140 }
141 
142