1 /*- 2 * Copyright (c) 2011 Michihiro NAKAJIMA 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 13 * 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. 24 */ 25 #include "test.h" 26 27 /* 28 Execute the following command to rebuild the data for this program: 29 tail -n +32 test_read_format_iso_xorriso.c | /bin/sh 30 # 31 rm -rf /tmp/iso 32 mkdir /tmp/iso 33 mkdir /tmp/iso/dir 34 mkdir /tmp/iso/dir2 35 echo "hello" >/tmp/iso/file 36 ln /tmp/iso/file /tmp/iso/hardlink 37 (cd /tmp/iso; ln -s file symlink) 38 TZ=utc touch -afm -t 197001020000.01 /tmp/iso/empty 39 echo "hello2" >/tmp/iso/dir/file2 40 echo "hello3" >/tmp/iso/dir/file3 41 echo "hello4" >/tmp/iso/dir2/file4 42 43 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso/dir/file2 /tmp/iso/dir/file3 44 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso/dir2/file4 45 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir 46 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso/dir2 47 TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink 48 F=test_read_format_iso_xorriso.iso 49 xorriso -outdev - -map /tmp/iso / > $F 50 compress $F 51 uuencode $F.Z $F.Z > $F.Z.uu 52 rm $F.Z 53 exit 1 54 */ 55 56 /* 57 * A test for the iso images made by xorriso which versions are 58 * from 0.6.5 to 1.0.1. 59 * The xorriso set 0 to the location of empty files(include symlink 60 * files) that caused our iso reader could not read following directory 61 * entries at all. 62 * 63 */ 64 65 DEFINE_TEST(test_read_format_iso_xorriso) 66 { 67 const char *refname = "test_read_format_iso_xorriso.iso.Z"; 68 struct archive_entry *ae; 69 struct archive *a; 70 const void *p; 71 size_t size; 72 int64_t offset; 73 int i; 74 75 extract_reference_file(refname); 76 assert((a = archive_read_new()) != NULL); 77 assertEqualInt(0, archive_read_support_filter_all(a)); 78 assertEqualInt(0, archive_read_support_format_all(a)); 79 assertEqualInt(ARCHIVE_OK, 80 archive_read_open_filename(a, refname, 10240)); 81 82 /* Retrieve each of the 10 files on the ISO image and 83 * verify that each one is what we expect. */ 84 for (i = 0; i < 10; ++i) { 85 assertEqualInt(0, archive_read_next_header(a, &ae)); 86 87 assertEqualInt(archive_entry_is_encrypted(ae), 0); 88 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 89 90 if (strcmp(".", archive_entry_pathname(ae)) == 0) { 91 /* '.' root directory. */ 92 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 93 assertEqualInt(2048, archive_entry_size(ae)); 94 /* Now, we read timestamp recorded by RRIP "TF". */ 95 assertEqualInt(86401, archive_entry_mtime(ae)); 96 assertEqualInt(0, archive_entry_mtime_nsec(ae)); 97 /* Now, we read links recorded by RRIP "PX". */ 98 assertEqualInt(4, archive_entry_nlink(ae)); 99 assertEqualIntA(a, ARCHIVE_EOF, 100 archive_read_data_block(a, &p, &size, &offset)); 101 assertEqualInt((int)size, 0); 102 } else if (strcmp("./dir", archive_entry_pathname(ae)) == 0) { 103 /* A directory. */ 104 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 105 assertEqualInt(2048, archive_entry_size(ae)); 106 assertEqualInt(86401, archive_entry_mtime(ae)); 107 assertEqualInt(86401, archive_entry_atime(ae)); 108 assertEqualInt(2, archive_entry_nlink(ae)); 109 } else if (strcmp("./dir2", archive_entry_pathname(ae)) == 0) { 110 /* A directory. */ 111 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 112 assertEqualInt(2048, archive_entry_size(ae)); 113 assertEqualInt(86401, archive_entry_mtime(ae)); 114 assertEqualInt(86401, archive_entry_atime(ae)); 115 assertEqualInt(2, archive_entry_nlink(ae)); 116 } else if (strcmp("./file", 117 archive_entry_pathname(ae)) == 0) { 118 /* A regular file. */ 119 assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 120 assertEqualInt(6, archive_entry_size(ae)); 121 assertEqualInt(0, 122 archive_read_data_block(a, &p, &size, &offset)); 123 assertEqualInt(0, offset); 124 assertEqualMem(p, "hello\n", 6); 125 assertEqualInt(86401, archive_entry_mtime(ae)); 126 assertEqualInt(86401, archive_entry_atime(ae)); 127 assertEqualInt(2, archive_entry_nlink(ae)); 128 } else if (strcmp("./hardlink", 129 archive_entry_pathname(ae)) == 0) { 130 /* A hardlink to the regular file. */ 131 /* Note: If "hardlink" gets returned before "file", 132 * then "hardlink" will get returned as a regular file 133 * and "file" will get returned as the hardlink. 134 * This test should tolerate that, since it's a 135 * perfectly permissible thing for libarchive to do. */ 136 assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 137 assertEqualString("./file", archive_entry_hardlink(ae)); 138 assertEqualInt(0, archive_entry_size_is_set(ae)); 139 assertEqualInt(0, archive_entry_size(ae)); 140 assertEqualInt(86401, archive_entry_mtime(ae)); 141 assertEqualInt(86401, archive_entry_atime(ae)); 142 assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 143 } else if (strcmp("./symlink", 144 archive_entry_pathname(ae)) == 0) { 145 /* A symlink to the regular file. */ 146 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 147 assertEqualString("file", archive_entry_symlink(ae)); 148 assertEqualInt(0, archive_entry_size(ae)); 149 assertEqualInt(172802, archive_entry_mtime(ae)); 150 assertEqualInt(172802, archive_entry_atime(ae)); 151 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 152 } else if (strcmp("./empty", 153 archive_entry_pathname(ae)) == 0) { 154 /* A empty file. */ 155 assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 156 assertEqualInt(0, archive_entry_size(ae)); 157 assertEqualInt(86401, archive_entry_mtime(ae)); 158 assertEqualInt(86401, archive_entry_atime(ae)); 159 assertEqualInt(1, archive_entry_nlink(ae)); 160 } else if (strcmp("./dir/file2", 161 archive_entry_pathname(ae)) == 0) { 162 /* A regular file. */ 163 assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 164 assertEqualInt(7, archive_entry_size(ae)); 165 assertEqualInt(0, 166 archive_read_data_block(a, &p, &size, &offset)); 167 assertEqualInt(0, offset); 168 assertEqualMem(p, "hello2\n", 7); 169 assertEqualInt(86401, archive_entry_mtime(ae)); 170 assertEqualInt(86401, archive_entry_atime(ae)); 171 assertEqualInt(1, archive_entry_nlink(ae)); 172 } else if (strcmp("./dir/file3", 173 archive_entry_pathname(ae)) == 0) { 174 /* A regular file. */ 175 assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 176 assertEqualInt(7, archive_entry_size(ae)); 177 assertEqualInt(0, 178 archive_read_data_block(a, &p, &size, &offset)); 179 assertEqualInt(0, offset); 180 assertEqualMem(p, "hello3\n", 7); 181 assertEqualInt(86401, archive_entry_mtime(ae)); 182 assertEqualInt(86401, archive_entry_atime(ae)); 183 assertEqualInt(1, archive_entry_nlink(ae)); 184 } else if (strcmp("./dir2/file4", 185 archive_entry_pathname(ae)) == 0) { 186 /* A regular file. */ 187 assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 188 assertEqualInt(7, archive_entry_size(ae)); 189 assertEqualInt(0, 190 archive_read_data_block(a, &p, &size, &offset)); 191 assertEqualInt(0, offset); 192 assertEqualMem(p, "hello4\n", 7); 193 assertEqualInt(86401, archive_entry_mtime(ae)); 194 assertEqualInt(86401, archive_entry_atime(ae)); 195 assertEqualInt(1, archive_entry_nlink(ae)); 196 } else { 197 failure("Saw a file that shouldn't have been there"); 198 assertEqualString(archive_entry_pathname(ae), ""); 199 } 200 } 201 202 /* End of archive. */ 203 assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); 204 205 /* Verify archive format. */ 206 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS); 207 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); 208 209 /* Close the archive. */ 210 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); 211 assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 212 } 213 214 215