From owner-svn-src-head@FreeBSD.ORG Tue May 3 15:12:02 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 25E5D106566C; Tue, 3 May 2011 15:12:02 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1239F8FC0C; Tue, 3 May 2011 15:12:02 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p43FC1SW099142; Tue, 3 May 2011 15:12:01 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p43FC1Jr099140; Tue, 3 May 2011 15:12:01 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <201105031512.p43FC1Jr099140@svn.freebsd.org> From: Nathan Whitehorn Date: Tue, 3 May 2011 15:12:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r221387 - head/usr.sbin/makefs/cd9660 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 May 2011 15:12:02 -0000 Author: nwhitehorn Date: Tue May 3 15:12:01 2011 New Revision: 221387 URL: http://svn.freebsd.org/changeset/base/221387 Log: Add support for synthesizing an APM partition map to map Mac PowerPC bootstrap partitions from the ISO9660 boot catalog. This preserves OS X's ability to mount the CD, while allowing us a way to provide HFS-ified bootstrap code for Open Firmware. Modified: head/usr.sbin/makefs/cd9660/cd9660_eltorito.c Modified: head/usr.sbin/makefs/cd9660/cd9660_eltorito.c ============================================================================== --- head/usr.sbin/makefs/cd9660/cd9660_eltorito.c Tue May 3 14:43:16 2011 (r221386) +++ head/usr.sbin/makefs/cd9660/cd9660_eltorito.c Tue May 3 15:12:01 2011 (r221387) @@ -31,6 +31,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. */ + +#include + #include "cd9660.h" #include "cd9660_eltorito.h" @@ -497,11 +500,43 @@ cd9660_setup_boot_volume_descriptor(volu return 1; } +static int +cd9660_write_apm_partition_entry(FILE *fd, int index, int total_partitions, + off_t sector_start, off_t nsectors, off_t sector_size, + const char *part_name, const char *part_type) { + uint32_t apm32; + uint16_t apm16; + + fseeko(fd, (off_t)(index + 1) * sector_size, SEEK_SET); + + /* Signature */ + apm16 = htons(0x504d); + fwrite(&apm16, sizeof(apm16), 1, fd); + apm16 = 0; + fwrite(&apm16, sizeof(apm16), 1, fd); + + /* Total number of partitions */ + apm32 = htonl(total_partitions); + fwrite(&apm32, sizeof(apm32), 1, fd); + /* Bounds */ + apm32 = htonl(sector_start); + fwrite(&apm32, sizeof(apm32), 1, fd); + apm32 = htonl(nsectors); + fwrite(&apm32, sizeof(apm32), 1, fd); + + fwrite(part_name, strlen(part_name) + 1, 1, fd); + fseek(fd, 32 - strlen(part_name) - 1, SEEK_CUR); + fwrite(part_type, strlen(part_type) + 1, 1, fd); + + return 0; +} + int cd9660_write_boot(FILE *fd) { struct boot_catalog_entry *e; struct cd9660_boot_image *t; + int apm_partitions = 0; /* write boot catalog */ if (fseeko(fd, (off_t)diskStructure.boot_catalog_sector * @@ -533,7 +568,51 @@ cd9660_write_boot(FILE *fd) t->filename, t->sector); } cd9660_copy_file(fd, t->sector, t->filename); + + if (t->system == ET_SYS_MAC) + apm_partitions++; + } + + if (apm_partitions > 0) { + /* Write DDR and global APM info */ + uint32_t apm32; + uint16_t apm16; + int total_parts; + + fseek(fd, 0, SEEK_SET); + apm16 = htons(0x4552); + fwrite(&apm16, sizeof(apm16), 1, fd); + apm16 = htons(diskStructure.sectorSize); + fwrite(&apm16, sizeof(apm16), 1, fd); + apm32 = htonl(diskStructure.totalSectors); + fwrite(&apm32, sizeof(apm32), 1, fd); + + /* Count total needed entries */ + total_parts = 2 + apm_partitions; /* Self + ISO9660 */ + + /* Write self-descriptor */ + cd9660_write_apm_partition_entry(fd, 0, + total_parts, 1, total_parts, diskStructure.sectorSize, + "Apple", "Apple_partition_map"); + + /* Write ISO9660 descriptor, enclosing the whole disk */ + cd9660_write_apm_partition_entry(fd, 1, + total_parts, 0, diskStructure.totalSectors, + diskStructure.sectorSize, "", "CD_ROM_Mode_1"); + + /* Write all partition entries */ + apm_partitions = 0; + TAILQ_FOREACH(t, &diskStructure.boot_images, image_list) { + if (t->system != ET_SYS_MAC) + continue; + + cd9660_write_apm_partition_entry(fd, + 2 + apm_partitions++, total_parts, + t->sector, t->num_sectors, diskStructure.sectorSize, + "CD Boot", "Apple_Bootstrap"); + } } return 0; } +