1228753Smm/*- 2228753Smm * Copyright (c) 2003-2007 Tim Kientzle 3228753Smm * All rights reserved. 4228753Smm * 5228753Smm * Based on libarchive/test/test_read_format_isorr_bz2.c with 6228753Smm * bugs introduced by Andreas Henriksson <andreas@fatal.se> for 7228753Smm * testing ISO9660 image with Joliet extension. 8228753Smm * 9228753Smm * Redistribution and use in source and binary forms, with or without 10228753Smm * modification, are permitted provided that the following conditions 11228753Smm * are met: 12228753Smm * 1. Redistributions of source code must retain the above copyright 13228753Smm * notice, this list of conditions and the following disclaimer. 14228753Smm * 2. Redistributions in binary form must reproduce the above copyright 15228753Smm * notice, this list of conditions and the following disclaimer in the 16228753Smm * documentation and/or other materials provided with the distribution. 17228753Smm * 18228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 19228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 22228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28228753Smm */ 29228753Smm#include "test.h" 30228763Smm__FBSDID("$FreeBSD$"); 31228753Smm 32228753Smm/* 33228753SmmExecute the following to rebuild the data for this program: 34228753Smm tail -n +35 test_read_format_isojoliet_rr.c | /bin/sh 35228753Smm 36228753Smmrm -rf /tmp/iso 37228753Smmmkdir /tmp/iso 38228753Smmmkdir /tmp/iso/dir 39228753Smmfile="long-joliet-file-name.textfile" 40228753Smmecho "hello" >/tmp/iso/$file 41228753Smmln /tmp/iso/$file /tmp/iso/hardlink 42228753Smm(cd /tmp/iso; ln -s $file symlink) 43228753Smmif [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h 44228753SmmTZ=utc touch -afm -t 197001020000.01 /tmp/iso/hardlink /tmp/iso/$file /tmp/iso/dir 45228753SmmTZ=utc touch -afm -t 197001030000.02 /tmp/iso/symlink 46228753SmmTZ=utc touch -afm -t 197001020000.01 /tmp/iso 47228753Smmelse 48228753SmmTZ=utc touch -afhm -t 197001020000.01 /tmp/iso/hardlink /tmp/iso/$file /tmp/iso/dir 49228753SmmTZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink 50228753SmmTZ=utc touch -afhm -t 197001020000.01 /tmp/iso 51228753Smmfi 52228753SmmF=test_read_format_iso_joliet_rockridge.iso.Z 53228753Smmmkhybrid -J -uid 1 -gid 2 /tmp/iso | compress > $F 54228753Smmuuencode $F $F > $F.uu 55228753Smmexit 1 56228753Smm */ 57228753Smm 58228753SmmDEFINE_TEST(test_read_format_isojoliet_rr) 59228753Smm{ 60228753Smm const char *refname = "test_read_format_iso_joliet_rockridge.iso.Z"; 61228753Smm struct archive_entry *ae; 62228753Smm struct archive *a; 63228753Smm const void *p; 64228753Smm size_t size; 65232153Smm int64_t offset; 66228753Smm 67228753Smm extract_reference_file(refname); 68228753Smm assert((a = archive_read_new()) != NULL); 69232153Smm assertEqualInt(0, archive_read_support_filter_all(a)); 70228753Smm assertEqualInt(0, archive_read_support_format_all(a)); 71228753Smm assertEqualInt(ARCHIVE_OK, 72228753Smm archive_read_open_filename(a, refname, 10240)); 73228753Smm 74228753Smm /* First entry is '.' root directory. */ 75228753Smm assertEqualInt(0, archive_read_next_header(a, &ae)); 76228753Smm assertEqualString(".", archive_entry_pathname(ae)); 77228753Smm assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 78228753Smm assertEqualInt(2048, archive_entry_size(ae)); 79228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 80228753Smm assertEqualInt(0, archive_entry_mtime_nsec(ae)); 81228753Smm assertEqualInt(3, archive_entry_stat(ae)->st_nlink); 82228753Smm assertEqualInt(1, archive_entry_uid(ae)); 83228753Smm assertEqualIntA(a, ARCHIVE_EOF, 84228753Smm archive_read_data_block(a, &p, &size, &offset)); 85228753Smm assertEqualInt((int)size, 0); 86302001Smm assertEqualInt(archive_entry_is_encrypted(ae), 0); 87302001Smm assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 88228753Smm 89228753Smm /* A directory. */ 90228753Smm assertEqualInt(0, archive_read_next_header(a, &ae)); 91228753Smm assertEqualString("dir", archive_entry_pathname(ae)); 92228753Smm assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 93228753Smm assertEqualInt(2048, archive_entry_size(ae)); 94228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 95228753Smm assertEqualInt(86401, archive_entry_atime(ae)); 96228753Smm assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 97228753Smm assertEqualInt(1, archive_entry_uid(ae)); 98228753Smm assertEqualInt(2, archive_entry_gid(ae)); 99302001Smm assertEqualInt(archive_entry_is_encrypted(ae), 0); 100302001Smm assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 101228753Smm 102228753Smm /* A regular file with two names ("hardlink" gets returned 103228753Smm * first, so it's not marked as a hardlink). */ 104228753Smm assertEqualInt(0, archive_read_next_header(a, &ae)); 105228753Smm assertEqualString("hardlink", 106228753Smm archive_entry_pathname(ae)); 107228753Smm assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 108228753Smm assert(archive_entry_hardlink(ae) == NULL); 109228753Smm assertEqualInt(6, archive_entry_size(ae)); 110228753Smm assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset)); 111228753Smm assertEqualInt(6, (int)size); 112228753Smm assertEqualInt(0, offset); 113232153Smm assertEqualMem(p, "hello\n", 6); 114228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 115228753Smm /* mkisofs records their access time. */ 116228753Smm /*assertEqualInt(86401, archive_entry_atime(ae));*/ 117228753Smm /* TODO: Actually, libarchive should be able to 118228753Smm * compute nlinks correctly even without RR 119228753Smm * extensions. See comments in libarchive source. */ 120228753Smm assertEqualInt(2, archive_entry_nlink(ae)); 121228753Smm assertEqualInt(1, archive_entry_uid(ae)); 122228753Smm assertEqualInt(2, archive_entry_gid(ae)); 123302001Smm assertEqualInt(archive_entry_is_encrypted(ae), 0); 124302001Smm assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 125228753Smm 126228753Smm /* Second name for the same regular file (this happens to be 127228753Smm * returned second, so does get marked as a hardlink). */ 128228753Smm assertEqualInt(0, archive_read_next_header(a, &ae)); 129228753Smm assertEqualString("long-joliet-file-name.textfile", 130228753Smm archive_entry_pathname(ae)); 131228753Smm assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 132228753Smm assertEqualString("hardlink", 133228753Smm archive_entry_hardlink(ae)); 134228753Smm assert(!archive_entry_size_is_set(ae)); 135228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 136228753Smm assertEqualInt(86401, archive_entry_atime(ae)); 137228753Smm /* TODO: See above. */ 138228753Smm assertEqualInt(2, archive_entry_nlink(ae)); 139228753Smm assertEqualInt(1, archive_entry_uid(ae)); 140228753Smm assertEqualInt(2, archive_entry_gid(ae)); 141302001Smm assertEqualInt(archive_entry_is_encrypted(ae), 0); 142302001Smm assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 143228753Smm 144228753Smm /* A symlink to the regular file. */ 145228753Smm assertEqualInt(0, archive_read_next_header(a, &ae)); 146228753Smm assertEqualString("symlink", archive_entry_pathname(ae)); 147228753Smm assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 148228753Smm assertEqualString("long-joliet-file-name.textfile", 149228753Smm archive_entry_symlink(ae)); 150228753Smm assertEqualInt(0, archive_entry_size(ae)); 151228753Smm assertEqualInt(172802, archive_entry_mtime(ae)); 152228753Smm assertEqualInt(172802, archive_entry_atime(ae)); 153228753Smm assertEqualInt(1, archive_entry_nlink(ae)); 154228753Smm assertEqualInt(1, archive_entry_uid(ae)); 155228753Smm assertEqualInt(2, archive_entry_gid(ae)); 156302001Smm assertEqualInt(archive_entry_is_encrypted(ae), 0); 157302001Smm assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 158228753Smm 159228753Smm /* End of archive. */ 160228753Smm assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); 161228753Smm 162228753Smm /* Verify archive format. */ 163248616Smm assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS); 164228753Smm assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); 165228753Smm 166228753Smm /* Close the archive. */ 167232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); 168232153Smm assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 169228753Smm} 170228753Smm 171