test_read_format_isorr_new_bz2.c revision 228761
1/*- 2 * Copyright (c) 2003-2007 Tim Kientzle 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__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_isorr_new_bz2.c 201247 2009-12-30 05:59:21Z kientzle $"); 27 28 29/* 30PLEASE use latest cdrtools at least mkisofs version is 2.01.01a63 or later. 31Old version mkisofs made wrong "SL" System Use Entry of RRIP. 32 33Execute the following command to rebuild the data for this program: 34 tail -n +34 test_read_format_isorr_new_bz2.c | /bin/sh 35 36rm -rf /tmp/iso 37mkdir /tmp/iso 38mkdir /tmp/iso/dir 39echo "hello" >/tmp/iso/file 40dd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file 41ln /tmp/iso/file /tmp/iso/hardlink 42(cd /tmp/iso; ln -s file symlink) 43(cd /tmp/iso; ln -s /tmp/ symlink2) 44(cd /tmp/iso; ln -s /tmp/../ symlink3) 45(cd /tmp/iso; ln -s .././../tmp/ symlink4) 46(cd /tmp/iso; ln -s .///file symlink5) 47(cd /tmp/iso; ln -s /tmp//../ symlink6) 48TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir 49TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink 50F=test_read_format_iso_rockridge_new.iso.Z 51mkhybrid -R -uid 1 -gid 2 /tmp/iso | compress > $F 52uuencode $F $F > $F.uu 53exit 1 54 */ 55 56DEFINE_TEST(test_read_format_isorr_new_bz2) 57{ 58 const char *refname = "test_read_format_iso_rockridge_new.iso.Z"; 59 struct archive_entry *ae; 60 struct archive *a; 61 const void *p; 62 size_t size; 63 off_t offset; 64 int i; 65 66 extract_reference_file(refname); 67 assert((a = archive_read_new()) != NULL); 68 assertEqualInt(0, archive_read_support_compression_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 /* Retrieve each of the 8 files on the ISO image and 74 * verify that each one is what we expect. */ 75 for (i = 0; i < 10; ++i) { 76 assertEqualInt(0, archive_read_next_header(a, &ae)); 77 78 if (strcmp(".", archive_entry_pathname(ae)) == 0) { 79 /* '.' root directory. */ 80 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 81 assertEqualInt(2048, archive_entry_size(ae)); 82 /* Now, we read timestamp recorded by RRIP "TF". */ 83 assertEqualInt(86401, archive_entry_mtime(ae)); 84 assertEqualInt(0, archive_entry_mtime_nsec(ae)); 85 /* Now, we read links recorded by RRIP "PX". */ 86 assertEqualInt(3, archive_entry_stat(ae)->st_nlink); 87 assertEqualInt(1, archive_entry_uid(ae)); 88 assertEqualIntA(a, ARCHIVE_EOF, 89 archive_read_data_block(a, &p, &size, &offset)); 90 assertEqualInt((int)size, 0); 91 } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { 92 /* A directory. */ 93 assertEqualString("dir", archive_entry_pathname(ae)); 94 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 95 assertEqualInt(2048, archive_entry_size(ae)); 96 assertEqualInt(86401, archive_entry_mtime(ae)); 97 assertEqualInt(86401, archive_entry_atime(ae)); 98 assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 99 assertEqualInt(1, archive_entry_uid(ae)); 100 assertEqualInt(2, archive_entry_gid(ae)); 101 } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { 102 /* A regular file. */ 103 assertEqualString("file", archive_entry_pathname(ae)); 104 assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 105 assertEqualInt(12345684, archive_entry_size(ae)); 106 assertEqualInt(0, 107 archive_read_data_block(a, &p, &size, &offset)); 108 assertEqualInt(0, offset); 109 assertEqualMem(p, "hello\n", 6); 110 assertEqualInt(86401, archive_entry_mtime(ae)); 111 assertEqualInt(86401, archive_entry_atime(ae)); 112 assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 113 assertEqualInt(1, archive_entry_uid(ae)); 114 assertEqualInt(2, archive_entry_gid(ae)); 115 } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) { 116 /* A hardlink to the regular file. */ 117 /* Note: If "hardlink" gets returned before "file", 118 * then "hardlink" will get returned as a regular file 119 * and "file" will get returned as the hardlink. 120 * This test should tolerate that, since it's a 121 * perfectly permissible thing for libarchive to do. */ 122 assertEqualString("hardlink", archive_entry_pathname(ae)); 123 assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 124 assertEqualString("file", archive_entry_hardlink(ae)); 125 assertEqualInt(0, archive_entry_size_is_set(ae)); 126 assertEqualInt(0, archive_entry_size(ae)); 127 assertEqualInt(86401, archive_entry_mtime(ae)); 128 assertEqualInt(86401, archive_entry_atime(ae)); 129 assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 130 assertEqualInt(1, archive_entry_uid(ae)); 131 assertEqualInt(2, archive_entry_gid(ae)); 132 } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) { 133 /* A symlink to the regular file. */ 134 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 135 assertEqualString("file", archive_entry_symlink(ae)); 136 assertEqualInt(0, archive_entry_size(ae)); 137 assertEqualInt(172802, archive_entry_mtime(ae)); 138 assertEqualInt(172802, archive_entry_atime(ae)); 139 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 140 assertEqualInt(1, archive_entry_uid(ae)); 141 assertEqualInt(2, archive_entry_gid(ae)); 142 } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) { 143 /* A symlink to /tmp/ (an absolute path) */ 144 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 145 assertEqualString("/tmp/", archive_entry_symlink(ae)); 146 assertEqualInt(0, archive_entry_size(ae)); 147 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 148 assertEqualInt(1, archive_entry_uid(ae)); 149 assertEqualInt(2, archive_entry_gid(ae)); 150 } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) { 151 /* A symlink to /tmp/../ (with a ".." component) */ 152 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 153 assertEqualString("/tmp/../", archive_entry_symlink(ae)); 154 assertEqualInt(0, archive_entry_size(ae)); 155 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 156 assertEqualInt(1, archive_entry_uid(ae)); 157 assertEqualInt(2, archive_entry_gid(ae)); 158 } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) { 159 /* A symlink to a path with ".." and "." components */ 160 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 161 assertEqualString(".././../tmp/", 162 archive_entry_symlink(ae)); 163 assertEqualInt(0, archive_entry_size(ae)); 164 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 165 assertEqualInt(1, archive_entry_uid(ae)); 166 assertEqualInt(2, archive_entry_gid(ae)); 167 } else if (strcmp("symlink5", archive_entry_pathname(ae)) == 0) { 168 /* A symlink to the regular file with "/" components. */ 169 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 170 assertEqualString(".///file", archive_entry_symlink(ae)); 171 assertEqualInt(0, archive_entry_size(ae)); 172 assertEqualInt(172802, archive_entry_mtime(ae)); 173 assertEqualInt(172802, archive_entry_atime(ae)); 174 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 175 assertEqualInt(1, archive_entry_uid(ae)); 176 assertEqualInt(2, archive_entry_gid(ae)); 177 } else if (strcmp("symlink6", archive_entry_pathname(ae)) == 0) { 178 /* A symlink to /tmp//../ 179 * (with "/" and ".." components) */ 180 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 181 assertEqualString("/tmp//../", archive_entry_symlink(ae)); 182 assertEqualInt(0, archive_entry_size(ae)); 183 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 184 assertEqualInt(1, archive_entry_uid(ae)); 185 assertEqualInt(2, archive_entry_gid(ae)); 186 } else { 187 failure("Saw a file that shouldn't have been there"); 188 assertEqualString(archive_entry_pathname(ae), ""); 189 } 190 } 191 192 /* End of archive. */ 193 assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); 194 195 /* Verify archive format. */ 196 assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); 197 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); 198 199 /* Close the archive. */ 200 assertEqualInt(0, archive_read_close(a)); 201 assertEqualInt(0, archive_read_finish(a)); 202} 203 204 205