1228753Smm/*- 2228753Smm * Copyright (c) 2003-2007 Tim Kientzle 3228753Smm * Copyright (c) 2009 Michihiro NAKAJIMA 4228753Smm * All rights reserved. 5228753Smm * 6228753Smm * Redistribution and use in source and binary forms, with or without 7228753Smm * modification, are permitted provided that the following conditions 8228753Smm * are met: 9228753Smm * 1. Redistributions of source code must retain the above copyright 10228753Smm * notice, this list of conditions and the following disclaimer. 11228753Smm * 2. Redistributions in binary form must reproduce the above copyright 12228753Smm * notice, this list of conditions and the following disclaimer in the 13228753Smm * documentation and/or other materials provided with the distribution. 14228753Smm * 15228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 16228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 19228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25228753Smm */ 26228753Smm#include "test.h" 27228763Smm__FBSDID("$FreeBSD$"); 28228753Smm 29228753Smm/* 30228753SmmExecute the following command to rebuild the data for this program: 31228753Smm tail -n +32 test_read_format_isorr_ce.c | /bin/sh 32228753Smm 33228753Smmdirname=/tmp/iso 34228753Smm# 35228753Smmrm -rf $dirname 36228753Smmmkdir $dirname 37228753Smm# 38228753Smmnum=0 39228753Smmfile="" 40228753Smmwhile [ $num -lt 150 ] 41228753Smmdo 42228753Smm num=$((num+1)) 43228753Smm file="a$file" 44228753Smmdone 45228753Smm# 46228753Smmnum=0 47228753Smmwhile [ $num -lt 3 ] 48228753Smmdo 49228753Smm num=$((num+1)) 50228753Smm file="a$file" 51228753Smm echo "hello $((num+150))" > $dirname/$file 52228753Smm dd if=/dev/zero count=1 bs=4080 >> $dirname/$file 53228753Smm (cd $dirname; ln -s $file sym$num) 54228753Smmdone 55228753Smm# 56228753Smmmkdir $dirname/dir 57228753Smm# 58228753Smmtime1="197001020000.01" 59228753Smmtime2="197001030000.02" 60228753SmmTZ=utc touch -afhm -t $time1 $dirname/dir $dirname/aaaa* 61228753SmmTZ=utc touch -afhm -t $time2 $dirname/sym* 62228753SmmTZ=utc touch -afhm -t $time1 $dirname 63228753Smm# 64228753SmmF=test_read_format_iso_rockridge_ce.iso.Z 65228753Smmmkisofs -R -uid 1 -gid 2 $dirname | compress > $F 66228753Smmuuencode $F $F > $F.uu 67228753Smmrm -rf $dirname 68228753Smmexit 1 69228753Smm */ 70228753Smm 71228753Smm/* 72228753Smm * Test reading SUSP "CE" extension is works fine. 73228753Smm */ 74228753Smm 75228753Smmstatic void 76228753Smmmkpath(char *p, int len) 77228753Smm{ 78228753Smm int i; 79228753Smm 80228753Smm for (i = 0; i < len; i++) 81228753Smm p[i] = 'a'; 82228753Smm p[len] = '\0'; 83228753Smm} 84228753Smm 85228753SmmDEFINE_TEST(test_read_format_isorr_ce) 86228753Smm{ 87228753Smm const char *refname = "test_read_format_iso_rockridge_ce.iso.Z"; 88228753Smm char path1[160]; 89228753Smm char path2[160]; 90228753Smm char path3[160]; 91228753Smm struct archive_entry *ae; 92228753Smm struct archive *a; 93228753Smm const void *p; 94228753Smm size_t size; 95232153Smm int64_t offset; 96228753Smm int i; 97228753Smm 98228753Smm mkpath(path1, 151); 99228753Smm mkpath(path2, 152); 100228753Smm mkpath(path3, 153); 101228753Smm extract_reference_file(refname); 102228753Smm assert((a = archive_read_new()) != NULL); 103232153Smm assertEqualInt(0, archive_read_support_filter_all(a)); 104228753Smm assertEqualInt(0, archive_read_support_format_all(a)); 105228753Smm assertEqualInt(ARCHIVE_OK, 106228753Smm archive_read_open_filename(a, refname, 10240)); 107228753Smm 108228753Smm /* Retrieve each of the 8 files on the ISO image and 109228753Smm * verify that each one is what we expect. */ 110228753Smm for (i = 0; i < 8; ++i) { 111228753Smm assertEqualInt(0, archive_read_next_header(a, &ae)); 112299529Smm 113299529Smm assertEqualInt(archive_entry_is_encrypted(ae), 0); 114299529Smm assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 115228753Smm 116228753Smm if (strcmp(".", archive_entry_pathname(ae)) == 0) { 117228753Smm /* '.' root directory. */ 118228753Smm assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 119228753Smm assertEqualInt(2048, archive_entry_size(ae)); 120228753Smm /* Now, we read timestamp recorded by RRIP "TF". */ 121228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 122228753Smm assertEqualInt(0, archive_entry_mtime_nsec(ae)); 123228753Smm /* Now, we read links recorded by RRIP "PX". */ 124228753Smm assertEqualInt(3, archive_entry_stat(ae)->st_nlink); 125228753Smm assertEqualInt(1, archive_entry_uid(ae)); 126228753Smm assertEqualIntA(a, ARCHIVE_EOF, 127228753Smm archive_read_data_block(a, &p, &size, &offset)); 128228753Smm assertEqualInt((int)size, 0); 129228753Smm } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { 130228753Smm /* A directory. */ 131228753Smm assertEqualString("dir", archive_entry_pathname(ae)); 132228753Smm assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 133228753Smm assertEqualInt(2048, archive_entry_size(ae)); 134228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 135228753Smm assertEqualInt(86401, archive_entry_atime(ae)); 136228753Smm assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 137228753Smm assertEqualInt(1, archive_entry_uid(ae)); 138228753Smm assertEqualInt(2, archive_entry_gid(ae)); 139228753Smm } else if (strcmp(path1, archive_entry_pathname(ae)) == 0) { 140228753Smm /* A regular file. */ 141228753Smm assertEqualString(path1, archive_entry_pathname(ae)); 142228753Smm assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 143228753Smm assertEqualInt(4090, archive_entry_size(ae)); 144228753Smm assertEqualInt(0, 145228753Smm archive_read_data_block(a, &p, &size, &offset)); 146228753Smm assertEqualInt(0, offset); 147228753Smm assertEqualMem(p, "hello 151\n", 10); 148228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 149228753Smm assertEqualInt(86401, archive_entry_atime(ae)); 150228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 151228753Smm assertEqualInt(1, archive_entry_uid(ae)); 152228753Smm assertEqualInt(2, archive_entry_gid(ae)); 153228753Smm } else if (strcmp(path2, archive_entry_pathname(ae)) == 0) { 154228753Smm /* A regular file. */ 155228753Smm assertEqualString(path2, archive_entry_pathname(ae)); 156228753Smm assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 157228753Smm assertEqualInt(4090, archive_entry_size(ae)); 158228753Smm assertEqualInt(0, 159228753Smm archive_read_data_block(a, &p, &size, &offset)); 160228753Smm assertEqualInt(0, offset); 161228753Smm assertEqualMem(p, "hello 152\n", 10); 162228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 163228753Smm assertEqualInt(86401, archive_entry_atime(ae)); 164228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 165228753Smm assertEqualInt(1, archive_entry_uid(ae)); 166228753Smm assertEqualInt(2, archive_entry_gid(ae)); 167228753Smm } else if (strcmp(path3, archive_entry_pathname(ae)) == 0) { 168228753Smm /* A regular file. */ 169228753Smm assertEqualString(path3, archive_entry_pathname(ae)); 170228753Smm assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 171228753Smm assertEqualInt(4090, archive_entry_size(ae)); 172228753Smm assertEqualInt(0, 173228753Smm archive_read_data_block(a, &p, &size, &offset)); 174228753Smm assertEqualInt(0, offset); 175228753Smm assertEqualMem(p, "hello 153\n", 10); 176228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 177228753Smm assertEqualInt(86401, archive_entry_atime(ae)); 178228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 179228753Smm assertEqualInt(1, archive_entry_uid(ae)); 180228753Smm assertEqualInt(2, archive_entry_gid(ae)); 181228753Smm } else if (strcmp("sym1", archive_entry_pathname(ae)) == 0) { 182228753Smm /* A symlink to the regular file. */ 183228753Smm assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 184228753Smm assertEqualString(path1, archive_entry_symlink(ae)); 185228753Smm assertEqualInt(0, archive_entry_size(ae)); 186228753Smm assertEqualInt(172802, archive_entry_mtime(ae)); 187228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 188228753Smm assertEqualInt(1, archive_entry_uid(ae)); 189228753Smm assertEqualInt(2, archive_entry_gid(ae)); 190228753Smm } else if (strcmp("sym2", archive_entry_pathname(ae)) == 0) { 191228753Smm /* A symlink to the regular file. */ 192228753Smm assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 193228753Smm assertEqualString(path2, archive_entry_symlink(ae)); 194228753Smm assertEqualInt(0, archive_entry_size(ae)); 195228753Smm assertEqualInt(172802, archive_entry_mtime(ae)); 196228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 197228753Smm assertEqualInt(1, archive_entry_uid(ae)); 198228753Smm assertEqualInt(2, archive_entry_gid(ae)); 199228753Smm } else if (strcmp("sym3", archive_entry_pathname(ae)) == 0) { 200228753Smm /* A symlink to the regular file. */ 201228753Smm assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 202228753Smm assertEqualString(path3, archive_entry_symlink(ae)); 203228753Smm assertEqualInt(0, archive_entry_size(ae)); 204228753Smm assertEqualInt(172802, archive_entry_mtime(ae)); 205228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 206228753Smm assertEqualInt(1, archive_entry_uid(ae)); 207228753Smm assertEqualInt(2, archive_entry_gid(ae)); 208228753Smm } else { 209228753Smm failure("Saw a file that shouldn't have been there"); 210228753Smm assertEqualString(archive_entry_pathname(ae), ""); 211228753Smm } 212228753Smm } 213228753Smm 214228753Smm /* End of archive. */ 215228753Smm assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); 216228753Smm 217228753Smm /* Verify archive format. */ 218248616Smm assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS); 219228753Smm assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); 220228753Smm 221228753Smm /* Close the archive. */ 222232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); 223232153Smm assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 224228753Smm} 225228753Smm 226228753Smm 227