Index: stable/12/usr.sbin/makefs/cd9660/cd9660_eltorito.c =================================================================== --- stable/12/usr.sbin/makefs/cd9660/cd9660_eltorito.c (revision 366580) +++ stable/12/usr.sbin/makefs/cd9660/cd9660_eltorito.c (revision 366581) @@ -1,742 +1,744 @@ /* $NetBSD: cd9660_eltorito.c,v 1.23 2018/03/28 06:48:55 nonaka Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan * Perez-Rathke and Ram Vedam. All rights reserved. * * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys, * Alan Perez-Rathke and Ram Vedam. * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * THIS SOFTWARE IS PROVIDED BY DANIEL WATT, WALTER DEIGNAN, RYAN * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. */ #include "cd9660.h" #include "cd9660_eltorito.h" #include #include __FBSDID("$FreeBSD$"); #ifdef DEBUG #define ELTORITO_DPRINTF(__x) printf __x #else #define ELTORITO_DPRINTF(__x) #endif #include static struct boot_catalog_entry *cd9660_init_boot_catalog_entry(void); static struct boot_catalog_entry *cd9660_boot_setup_validation_entry(char); static struct boot_catalog_entry *cd9660_boot_setup_default_entry( struct cd9660_boot_image *); static struct boot_catalog_entry *cd9660_boot_setup_section_head(char); #if 0 static u_char cd9660_boot_get_system_type(struct cd9660_boot_image *); #endif static struct cd9660_boot_image *default_boot_image; int cd9660_add_boot_disk(iso9660_disk *diskStructure, const char *boot_info) { struct stat stbuf; const char *mode_msg; char *temp; char *sysname; char *filename; struct cd9660_boot_image *new_image, *tmp_image; assert(boot_info != NULL); if (*boot_info == '\0') { warnx("Error: Boot disk information must be in the " "format 'system;filename'"); return 0; } /* First decode the boot information */ temp = estrdup(boot_info); sysname = temp; filename = strchr(sysname, ';'); if (filename == NULL) { warnx("supply boot disk information in the format " "'system;filename'"); free(temp); return 0; } *filename++ = '\0'; if (diskStructure->verbose_level > 0) { printf("Found bootdisk with system %s, and filename %s\n", sysname, filename); } new_image = ecalloc(1, sizeof(*new_image)); new_image->loadSegment = 0; /* default for now */ /* Decode System */ if (strcmp(sysname, "i386") == 0) new_image->system = ET_SYS_X86; else if (strcmp(sysname, "powerpc") == 0) new_image->system = ET_SYS_PPC; else if (strcmp(sysname, "macppc") == 0 || strcmp(sysname, "mac68k") == 0) new_image->system = ET_SYS_MAC; + else if (strcmp(sysname, "efi") == 0) + new_image->system = ET_SYS_EFI; else { warnx("boot disk system must be " - "i386, powerpc, macppc, or mac68k"); + "i386, powerpc, macppc, mac68k, or efi"); free(temp); free(new_image); return 0; } new_image->filename = estrdup(filename); free(temp); /* Get information about the file */ if (lstat(new_image->filename, &stbuf) == -1) err(EXIT_FAILURE, "%s: lstat(\"%s\")", __func__, new_image->filename); switch (stbuf.st_size) { case 1440 * 1024: new_image->targetMode = ET_MEDIA_144FDD; mode_msg = "Assigned boot image to 1.44 emulation mode"; break; case 1200 * 1024: new_image->targetMode = ET_MEDIA_12FDD; mode_msg = "Assigned boot image to 1.2 emulation mode"; break; case 2880 * 1024: new_image->targetMode = ET_MEDIA_288FDD; mode_msg = "Assigned boot image to 2.88 emulation mode"; break; default: new_image->targetMode = ET_MEDIA_NOEM; mode_msg = "Assigned boot image to no emulation mode"; break; } if (diskStructure->verbose_level > 0) printf("%s\n", mode_msg); new_image->size = stbuf.st_size; new_image->num_sectors = howmany(new_image->size, diskStructure->sectorSize) * howmany(diskStructure->sectorSize, 512); if (diskStructure->verbose_level > 0) { printf("New image has size %d, uses %d 512-byte sectors\n", new_image->size, new_image->num_sectors); } new_image->sector = -1; /* Bootable by default */ new_image->bootable = ET_BOOTABLE; /* Add boot disk */ /* Group images for the same platform together. */ TAILQ_FOREACH(tmp_image, &diskStructure->boot_images, image_list) { if (tmp_image->system != new_image->system) break; } if (tmp_image == NULL) { TAILQ_INSERT_HEAD(&diskStructure->boot_images, new_image, image_list); } else TAILQ_INSERT_BEFORE(tmp_image, new_image, image_list); new_image->serialno = diskStructure->image_serialno++; new_image->platform_id = new_image->system; /* TODO : Need to do anything about the boot image in the tree? */ diskStructure->is_bootable = 1; /* First boot image is initial/default entry. */ if (default_boot_image == NULL) default_boot_image = new_image; return 1; } int cd9660_eltorito_add_boot_option(iso9660_disk *diskStructure, const char *option_string, const char *value) { char *eptr; struct cd9660_boot_image *image; assert(option_string != NULL); /* Find the last image added */ TAILQ_FOREACH(image, &diskStructure->boot_images, image_list) { if (image->serialno + 1 == diskStructure->image_serialno) break; } if (image == NULL) errx(EXIT_FAILURE, "Attempted to add boot option, " "but no boot images have been specified"); if (strcmp(option_string, "no-emul-boot") == 0) { image->targetMode = ET_MEDIA_NOEM; } else if (strcmp(option_string, "no-boot") == 0) { image->bootable = ET_NOT_BOOTABLE; } else if (strcmp(option_string, "hard-disk-boot") == 0) { image->targetMode = ET_MEDIA_HDD; } else if (strcmp(option_string, "boot-load-segment") == 0) { image->loadSegment = strtoul(value, &eptr, 16); if (eptr == value || *eptr != '\0' || errno != ERANGE) { warn("%s: strtoul", __func__); return 0; } } else if (strcmp(option_string, "platformid") == 0) { if (strcmp(value, "efi") == 0) image->platform_id = ET_SYS_EFI; else { warn("%s: unknown platform: %s", __func__, value); return 0; } } else { return 0; } return 1; } static struct boot_catalog_entry * cd9660_init_boot_catalog_entry(void) { return ecalloc(1, sizeof(struct boot_catalog_entry)); } static struct boot_catalog_entry * cd9660_boot_setup_validation_entry(char sys) { struct boot_catalog_entry *entry; boot_catalog_validation_entry *ve; int16_t checksum; unsigned char *csptr; size_t i; entry = cd9660_init_boot_catalog_entry(); entry->entry_type = ET_ENTRY_VE; ve = &entry->entry_data.VE; ve->header_id[0] = 1; ve->platform_id[0] = sys; ve->key[0] = 0x55; ve->key[1] = 0xAA; /* Calculate checksum */ checksum = 0; cd9660_721(0, ve->checksum); csptr = (unsigned char*)ve; for (i = 0; i < sizeof(*ve); i += 2) { checksum += (int16_t)csptr[i]; checksum += 256 * (int16_t)csptr[i + 1]; } checksum = -checksum; cd9660_721(checksum, ve->checksum); ELTORITO_DPRINTF(("%s: header_id %d, platform_id %d, key[0] %d, key[1] %d, " "checksum %04x\n", __func__, ve->header_id[0], ve->platform_id[0], ve->key[0], ve->key[1], checksum)); return entry; } static struct boot_catalog_entry * cd9660_boot_setup_default_entry(struct cd9660_boot_image *disk) { struct boot_catalog_entry *default_entry; boot_catalog_initial_entry *ie; default_entry = cd9660_init_boot_catalog_entry(); if (default_entry == NULL) return NULL; default_entry->entry_type = ET_ENTRY_IE; ie = &default_entry->entry_data.IE; ie->boot_indicator[0] = disk->bootable; ie->media_type[0] = disk->targetMode; cd9660_721(disk->loadSegment, ie->load_segment); ie->system_type[0] = disk->system; cd9660_721(disk->num_sectors, ie->sector_count); cd9660_731(disk->sector, ie->load_rba); ELTORITO_DPRINTF(("%s: boot indicator %d, media type %d, " "load segment %04x, system type %d, sector count %d, " "load rba %d\n", __func__, ie->boot_indicator[0], ie->media_type[0], disk->loadSegment, ie->system_type[0], disk->num_sectors, disk->sector)); return default_entry; } static struct boot_catalog_entry * cd9660_boot_setup_section_head(char platform) { struct boot_catalog_entry *entry; boot_catalog_section_header *sh; entry = cd9660_init_boot_catalog_entry(); if (entry == NULL) return NULL; entry->entry_type = ET_ENTRY_SH; sh = &entry->entry_data.SH; /* * More by default. * The last one will manually be set to ET_SECTION_HEADER_LAST */ sh->header_indicator[0] = ET_SECTION_HEADER_MORE; sh->platform_id[0] = platform; sh->num_section_entries[0] = 0; return entry; } static struct boot_catalog_entry * cd9660_boot_setup_section_entry(struct cd9660_boot_image *disk) { struct boot_catalog_entry *entry; boot_catalog_section_entry *se; if ((entry = cd9660_init_boot_catalog_entry()) == NULL) return NULL; entry->entry_type = ET_ENTRY_SE; se = &entry->entry_data.SE; se->boot_indicator[0] = ET_BOOTABLE; se->media_type[0] = disk->targetMode; cd9660_721(disk->loadSegment, se->load_segment); cd9660_721(disk->num_sectors, se->sector_count); cd9660_731(disk->sector, se->load_rba); return entry; } #if 0 static u_char cd9660_boot_get_system_type(struct cd9660_boot_image *disk) { /* For hard drive booting, we need to examine the MBR to figure out what the partition type is */ return 0; } #endif /* * Set up the BVD, Boot catalog, and the boot entries, but do no writing */ int cd9660_setup_boot(iso9660_disk *diskStructure, int first_sector) { int sector; int used_sectors; int num_entries = 0; int catalog_sectors; struct boot_catalog_entry *x86_head, *mac_head, *ppc_head, *efi_head, *valid_entry, *default_entry, *temp, *head, **headp, *next; struct cd9660_boot_image *tmp_disk; headp = NULL; x86_head = mac_head = ppc_head = efi_head = NULL; /* If there are no boot disks, don't bother building boot information */ if (TAILQ_EMPTY(&diskStructure->boot_images)) return 0; /* Point to catalog: For now assume it consumes one sector */ ELTORITO_DPRINTF(("Boot catalog will go in sector %d\n", first_sector)); diskStructure->boot_catalog_sector = first_sector; cd9660_bothendian_dword(first_sector, diskStructure->boot_descriptor->boot_catalog_pointer); /* Step 1: Generate boot catalog */ /* Step 1a: Validation entry */ valid_entry = cd9660_boot_setup_validation_entry(ET_SYS_X86); if (valid_entry == NULL) return -1; /* * Count how many boot images there are, * and how many sectors they consume. */ num_entries = 1; used_sectors = 0; TAILQ_FOREACH(tmp_disk, &diskStructure->boot_images, image_list) { used_sectors += tmp_disk->num_sectors; /* One default entry per image */ num_entries++; } catalog_sectors = howmany(num_entries * 0x20, diskStructure->sectorSize); used_sectors += catalog_sectors; if (diskStructure->verbose_level > 0) { printf("%s: there will be %i entries consuming %i sectors. " "Catalog is %i sectors\n", __func__, num_entries, used_sectors, catalog_sectors); } /* Populate sector numbers */ sector = first_sector + catalog_sectors; TAILQ_FOREACH(tmp_disk, &diskStructure->boot_images, image_list) { tmp_disk->sector = sector; sector += tmp_disk->num_sectors / (diskStructure->sectorSize / 512); } LIST_INSERT_HEAD(&diskStructure->boot_entries, valid_entry, ll_struct); /* Step 1b: Initial/default entry */ /* TODO : PARAM */ if (default_boot_image != NULL) { struct cd9660_boot_image *tcbi; TAILQ_FOREACH(tcbi, &diskStructure->boot_images, image_list) { if (tcbi == default_boot_image) { tmp_disk = tcbi; break; } } } if (tmp_disk == NULL) tmp_disk = TAILQ_FIRST(&diskStructure->boot_images); default_entry = cd9660_boot_setup_default_entry(tmp_disk); if (default_entry == NULL) { warnx("Error: memory allocation failed in cd9660_setup_boot"); return -1; } LIST_INSERT_AFTER(valid_entry, default_entry, ll_struct); /* Todo: multiple default entries? */ tmp_disk = TAILQ_FIRST(&diskStructure->boot_images); head = NULL; temp = default_entry; /* If multiple boot images are given : */ for (; tmp_disk != NULL; tmp_disk = TAILQ_NEXT(tmp_disk, image_list)) { if (tmp_disk == default_boot_image) continue; /* Step 2: Section header */ switch (tmp_disk->platform_id) { case ET_SYS_X86: headp = &x86_head; break; case ET_SYS_PPC: headp = &ppc_head; break; case ET_SYS_MAC: headp = &mac_head; break; case ET_SYS_EFI: headp = &efi_head; break; default: warnx("%s: internal error: unknown system type", __func__); return -1; } if (*headp == NULL) { head = cd9660_boot_setup_section_head(tmp_disk->platform_id); if (head == NULL) { warnx("Error: memory allocation failed in " "cd9660_setup_boot"); return -1; } LIST_INSERT_AFTER(default_entry, head, ll_struct); *headp = head; } else head = *headp; head->entry_data.SH.num_section_entries[0]++; /* Step 2a: Section entry and extensions */ temp = cd9660_boot_setup_section_entry(tmp_disk); if (temp == NULL) { warn("%s: cd9660_boot_setup_section_entry", __func__); return -1; } while ((next = LIST_NEXT(head, ll_struct)) != NULL && next->entry_type == ET_ENTRY_SE) head = next; LIST_INSERT_AFTER(head, temp, ll_struct); } /* Find the last Section Header entry and mark it as the last. */ head = NULL; LIST_FOREACH(next, &diskStructure->boot_entries, ll_struct) { if (next->entry_type == ET_ENTRY_SH) head = next; } if (head != NULL) head->entry_data.SH.header_indicator[0] = ET_SECTION_HEADER_LAST; /* TODO: Remaining boot disks when implemented */ return first_sector + used_sectors; } int cd9660_setup_boot_volume_descriptor(iso9660_disk *diskStructure, volume_descriptor *bvd) { boot_volume_descriptor *bvdData = (boot_volume_descriptor*)bvd->volumeDescriptorData; bvdData->boot_record_indicator[0] = ISO_VOLUME_DESCRIPTOR_BOOT; memcpy(bvdData->identifier, ISO_VOLUME_DESCRIPTOR_STANDARD_ID, 5); bvdData->version[0] = 1; memcpy(bvdData->boot_system_identifier, ET_ID, 23); memcpy(bvdData->identifier, ISO_VOLUME_DESCRIPTOR_STANDARD_ID, 5); diskStructure->boot_descriptor = (boot_volume_descriptor*) bvd->volumeDescriptorData; return 1; } static int cd9660_write_mbr_partition_entry(FILE *fd, int idx, off_t sector_start, off_t nsectors, int type) { uint8_t val; uint32_t lba; if (fseeko(fd, (off_t)(idx) * 16 + 0x1be, SEEK_SET) == -1) err(1, "fseeko"); val = 0x80; /* Bootable */ fwrite(&val, sizeof(val), 1, fd); val = 0xff; /* CHS begin */ fwrite(&val, sizeof(val), 1, fd); fwrite(&val, sizeof(val), 1, fd); fwrite(&val, sizeof(val), 1, fd); val = type; /* Part type */ fwrite(&val, sizeof(val), 1, fd); val = 0xff; /* CHS end */ fwrite(&val, sizeof(val), 1, fd); fwrite(&val, sizeof(val), 1, fd); fwrite(&val, sizeof(val), 1, fd); /* LBA extent */ lba = htole32(sector_start); fwrite(&lba, sizeof(lba), 1, fd); lba = htole32(nsectors); fwrite(&lba, sizeof(lba), 1, fd); return 0; } static int cd9660_write_apm_partition_entry(FILE *fd, int idx, 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, part_status; uint16_t apm16; /* See Apple Tech Note 1189 for the details about the pmPartStatus * flags. * Below the flags which are default: * - IsValid 0x01 * - IsAllocated 0x02 * - IsReadable 0x10 * - IsWritable 0x20 */ part_status = 0x01 | 0x02 | 0x10 | 0x20; if (fseeko(fd, (off_t)(idx + 1) * sector_size, SEEK_SET) == -1) err(1, "fseeko"); /* Signature */ apm16 = htobe16(0x504d); fwrite(&apm16, sizeof(apm16), 1, fd); apm16 = 0; fwrite(&apm16, sizeof(apm16), 1, fd); /* Total number of partitions */ apm32 = htobe32(total_partitions); fwrite(&apm32, sizeof(apm32), 1, fd); /* Bounds */ apm32 = htobe32(sector_start); fwrite(&apm32, sizeof(apm32), 1, fd); apm32 = htobe32(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); fseek(fd, 32 - strlen(part_type) - 1, SEEK_CUR); apm32 = 0; /* pmLgDataStart */ fwrite(&apm32, sizeof(apm32), 1, fd); /* pmDataCnt */ apm32 = htobe32(nsectors); fwrite(&apm32, sizeof(apm32), 1, fd); /* pmPartStatus */ apm32 = htobe32(part_status); fwrite(&apm32, sizeof(apm32), 1, fd); return 0; } int cd9660_write_boot(iso9660_disk *diskStructure, FILE *fd) { struct boot_catalog_entry *e; struct cd9660_boot_image *t; int apm_partitions = 0; int mbr_partitions = 0; /* write boot catalog */ if (fseeko(fd, (off_t)diskStructure->boot_catalog_sector * diskStructure->sectorSize, SEEK_SET) == -1) err(1, "fseeko"); if (diskStructure->verbose_level > 0) { printf("Writing boot catalog to sector %" PRId64 "\n", diskStructure->boot_catalog_sector); } LIST_FOREACH(e, &diskStructure->boot_entries, ll_struct) { if (diskStructure->verbose_level > 0) { printf("Writing catalog entry of type %d\n", e->entry_type); } /* * It doesn't matter which one gets written * since they are the same size */ fwrite(&(e->entry_data.VE), 1, 32, fd); } if (diskStructure->verbose_level > 0) printf("Finished writing boot catalog\n"); /* copy boot images */ TAILQ_FOREACH(t, &diskStructure->boot_images, image_list) { if (diskStructure->verbose_level > 0) { printf("Writing boot image from %s to sectors %d\n", t->filename, t->sector); } cd9660_copy_file(diskStructure, fd, t->sector, t->filename); if (t->system == ET_SYS_MAC) apm_partitions++; if (t->system == ET_SYS_PPC) mbr_partitions++; } /* some systems need partition tables as well */ if (mbr_partitions > 0 || diskStructure->chrp_boot) { uint16_t sig; fseek(fd, 0x1fe, SEEK_SET); sig = htole16(0xaa55); fwrite(&sig, sizeof(sig), 1, fd); mbr_partitions = 0; /* Write ISO9660 descriptor, enclosing the whole disk */ if (diskStructure->chrp_boot) cd9660_write_mbr_partition_entry(fd, mbr_partitions++, 0, diskStructure->totalSectors * (diskStructure->sectorSize / 512), 0x96); /* Write all partition entries */ TAILQ_FOREACH(t, &diskStructure->boot_images, image_list) { if (t->system != ET_SYS_PPC) continue; cd9660_write_mbr_partition_entry(fd, mbr_partitions++, t->sector * (diskStructure->sectorSize / 512), t->num_sectors * (diskStructure->sectorSize / 512), 0x41 /* PReP Boot */); } } 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 = htobe16(0x4552); fwrite(&apm16, sizeof(apm16), 1, fd); /* Device block size */ apm16 = htobe16(512); fwrite(&apm16, sizeof(apm16), 1, fd); /* Device block count */ apm32 = htobe32(diskStructure->totalSectors * (diskStructure->sectorSize / 512)); fwrite(&apm32, sizeof(apm32), 1, fd); /* Device type/id */ apm16 = htobe16(1); fwrite(&apm16, sizeof(apm16), 1, fd); fwrite(&apm16, sizeof(apm16), 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, 512, "Apple", "Apple_partition_map"); /* 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, 1 + apm_partitions++, total_parts, t->sector * (diskStructure->sectorSize / 512), t->num_sectors * (diskStructure->sectorSize / 512), 512, "CD Boot", "Apple_Bootstrap"); } /* Write ISO9660 descriptor, enclosing the whole disk */ cd9660_write_apm_partition_entry(fd, 2 + apm_partitions, total_parts, 0, diskStructure->totalSectors * (diskStructure->sectorSize / 512), 512, "ISO9660", "CD_ROM_Mode_1"); } return 0; } Index: stable/12/usr.sbin/makefs/makefs.8 =================================================================== --- stable/12/usr.sbin/makefs/makefs.8 (revision 366580) +++ stable/12/usr.sbin/makefs/makefs.8 (revision 366581) @@ -1,517 +1,518 @@ .\" $NetBSD: makefs.8,v 1.33 2011/05/22 21:51:39 christos Exp $ .\" .\" Copyright (c) 2001-2003 Wasabi Systems, Inc. .\" All rights reserved. .\" .\" Written by Luke Mewburn for Wasabi Systems, Inc. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed for the NetBSD Project by .\" Wasabi Systems, Inc. .\" 4. The name of Wasabi Systems, Inc. may not be used to endorse .\" or promote products derived from this software without specific prior .\" written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd August 20, 2019 +.Dd September 17, 2020 .Dt MAKEFS 8 .Os .Sh NAME .Nm makefs .Nd create a file system image from a directory tree or a mtree manifest .Sh SYNOPSIS .Nm .Op Fl DxZ .Op Fl B Ar endian .Op Fl b Ar free-blocks .Op Fl d Ar debug-mask .Op Fl F Ar mtree-specfile .Op Fl f Ar free-files .Op Fl M Ar minimum-size .Op Fl m Ar maximum-size .Op Fl N Ar userdb-dir .Op Fl O Ar offset .Op Fl o Ar fs-options .Op Fl R Ar roundup-size .Op Fl S Ar sector-size .Op Fl s Ar image-size .Op Fl T Ar timestamp .Op Fl t Ar fs-type .Ar image-file .Ar directory | manifest .Op Ar extra-directory ... .Sh DESCRIPTION The utility .Nm creates a file system image into .Ar image-file from the directory tree .Ar directory or from the mtree manifest .Ar manifest . If any optional directory trees are passed in the .Ar extra-directory arguments, then the directory tree of each argument will be merged into the .Ar directory or .Ar manifest first before creating .Ar image-file . No special devices or privileges are required to perform this task. .Pp The options are as follows: .Bl -tag -width flag .It Fl B Ar endian Set the byte order of the image to .Ar endian . Valid byte orders are .Ql 4321 , .Ql big , or .Ql be for big endian, and .Ql 1234 , .Ql little , or .Ql le for little endian. Some file systems may have a fixed byte order; in those cases this argument will be ignored. .It Fl b Ar free-blocks Ensure that a minimum of .Ar free-blocks free blocks exist in the image. An optional .Ql % suffix may be provided to indicate that .Ar free-blocks indicates a percentage of the calculated image size. .It Fl D Treat duplicate paths in an mtree manifest as warnings not error. .It Fl d Ar debug-mask Enable various levels of debugging, depending upon which bits are set in .Ar debug-mask . XXX: document these .It Fl F Ar mtree-specfile .Em This is almost certainly not the option you are looking for. To create an image from a list of files in an mtree format manifest, specify it as the last argument on the command line, not as a the argument to .Fl F . .Pp Use .Ar mtree-specfile as an .Xr mtree 8 .Sq specfile specification. This option has no effect when the image is created from a mtree manifest rather than a directory. .Pp If a specfile entry exists in the underlying file system, its permissions and modification time will be used unless specifically overridden by the specfile. An error will be raised if the type of entry in the specfile conflicts with that of an existing entry. .Pp In the opposite case (where a specfile entry does not have an entry in the underlying file system) the following occurs: If the specfile entry is marked .Sy optional , the specfile entry is ignored. Otherwise, the entry will be created in the image, and it is necessary to specify at least the following parameters in the specfile: .Sy type , .Sy mode , .Sy gname , or .Sy gid , and .Sy uname or .Sy uid , and .Sy link (in the case of symbolic links). If .Sy time is not provided, the current time will be used. If .Sy flags is not provided, the current file flags will be used. Missing regular file entries will be created as zero-length files. .It Fl f Ar free-files Ensure that a minimum of .Ar free-files free files (inodes) exist in the image. An optional .Ql % suffix may be provided to indicate that .Ar free-files indicates a percentage of the calculated image size. .It Fl M Ar minimum-size Set the minimum size of the file system image to .Ar minimum-size . .It Fl m Ar maximum-size Set the maximum size of the file system image to .Ar maximum-size . An error will be raised if the target file system needs to be larger than this to accommodate the provided directory tree. .It Fl N Ar userdb-dir Use the user database text file .Pa master.passwd and group database text file .Pa group from .Ar userdb-dir , rather than using the results from the system's .Xr getpwnam 3 and .Xr getgrnam 3 (and related) library calls. .It Fl O Ar offset Instead of creating the filesystem at the beginning of the file, start at offset. Valid only for .Sy ffs and .Sy msdos . .It Fl o Ar fs-options Set file system specific options. .Ar fs-options is a comma separated list of options. Valid file system specific options are detailed below. .It Fl p Deprecated. See the .Fl Z flag. .It Fl R Ar roundup-size Round the image up to .Ar roundup-size . .Ar roundup-size should be a multiple of the file system block size. This option only applies to the .Sy ffs file system type. .It Fl S Ar sector-size Set the file system sector size to .Ar sector-size . .\" XXX: next line also true for cd9660? Defaults to 512. .It Fl s Ar image-size Set the size of the file system image to .Ar image-size . This is equivalent to setting both the minimum .Fl ( M ) and the maximum .Fl ( m ) sizes to the same value. For .Sy ffs and .Sy msdos the .Ar image-size does not include the .Ar offset . .Ar offset is not included in that size. .It Fl T Ar timestamp Specify a timestamp to be set for all filesystem files and directories created so that repeatable builds are possible. The .Ar timestamp can be a .Pa pathname , where the timestamps are derived from that file, or an integer value interpreted as the number of seconds from the Epoch. Note that timestamps specified in an .Xr mtree 5 spec file, override the default timestamp. .It Fl t Ar fs-type Create an .Ar fs-type file system image. The following file system types are supported: .Bl -tag -width cd9660 -offset indent .It Sy ffs BSD fast file system (default). .It Sy cd9660 ISO 9660 file system. .It Sy msdos FAT12, FAT16, or FAT32 file system. .El .It Fl x Exclude file system nodes not explicitly listed in the specfile. .It Fl Z Create a sparse file for .Sy ffs . This is useful for virtual machine images. .El .Pp Where sizes are specified, a decimal number of bytes is expected. Two or more numbers may be separated by an .Dq x to indicate a product. Each number may have one of the following optional suffixes: .Bl -tag -width 3n -offset indent -compact .It b Block; multiply by 512 .It k Kibi; multiply by 1024 (1 KiB) .It m Mebi; multiply by 1048576 (1 MiB) .It g Gibi; multiply by 1073741824 (1 GiB) .It t Tebi; multiply by 1099511627776 (1 TiB) .It w Word; multiply by the number of bytes in an integer .El .\" .\" .Ss FFS-specific options .Sy ffs images have ffs-specific optional parameters that may be provided. Each of the options consists of a keyword, an equal sign .Pq Ql = , and a value. The following keywords are supported: .Pp .Bl -tag -width optimization -offset indent -compact .It Sy avgfilesize Expected average file size. .It Sy avgfpdir Expected number of files per directory. .It Sy bsize Block size. .It Sy density Bytes per inode. .It Sy fsize Fragment size. .It Sy label Label name of the image. .It Sy maxbpg Maximum blocks per file in a cylinder group. .It Sy minfree Minimum % free. .It Sy optimization Optimization preference; one of .Ql space or .Ql time . .It Sy extent Maximum extent size. .It Sy maxbpcg Maximum total number of blocks in a cylinder group. .It Sy version UFS version. 1 for FFS (default), 2 for UFS2. .It Sy softupdates 0 for disable (default), 1 for enable .El .Ss CD9660-specific options .Sy cd9660 images have ISO9660-specific optional parameters that may be provided. The arguments consist of a keyword and, optionally, an equal sign .Pq Ql = , and a value. The following keywords are supported: .Pp .Bl -tag -width omit-trailing-period -offset indent -compact .It Sy allow-deep-trees Allow the directory structure to exceed the maximum specified in the spec. .It Sy allow-illegal-chars Allow illegal characters in filenames. This option is not implemented. .It Sy allow-lowercase Allow lowercase characters in filenames. This option is not implemented. .It Sy allow-max-name Allow 37 instead of 33 characters for filenames by omitting the version id. .It Sy allow-multidot Allow multiple dots in a filename. .It Sy applicationid Application ID of the image. .It Sy archimedes Use the .Ql ARCHIMEDES extension to encode .Tn RISC OS metadata. .It Sy bootimagedir Boot image directory. This option is not implemented. .It Sy chrp-boot Write an MBR partition table to the image to allow older CHRP hardware to boot. .It Sy boot-load-segment Set load segment for the boot image. .It Sy bootimage Filename of a boot image in the format .Dq sysid;filename , where .Dq sysid is one of .Ql i386 , .Ql mac68k , .Ql macppc , +.Ql powerpc , or -.Ql powerpc . +.Ql efi . .It Sy generic-bootimage Load a generic boot image into the first 32K of the cd9660 image. .It Sy hard-disk-boot Boot image is a hard disk image. .It Sy isolevel An integer representing the ISO 9660 interchange level where .Dq level is either .Ql 1 or .Ql 2 . .Dq level .Ql 3 is not implemented. .It Sy keep-bad-images Do not discard images whose write was aborted due to an error. For debugging purposes. .It Sy label Label name of the image. .It Sy no-boot Boot image is not bootable. .It Sy no-emul-boot Boot image is a .Dq no emulation ElTorito image. .It Sy no-trailing-padding Do not pad the image (apparently Linux needs the padding). .It Sy omit-trailing-period Omit trailing periods in filenames. .It Sy platformid Set platform ID of section header entry of the boot image. .It Sy preparer Preparer ID of the image. .It Sy publisher Publisher ID of the image. .It Sy rockridge Use RockRidge extensions (for longer filenames, etc.). .It Sy verbose Turns on verbose output. .It Sy volumeid Volume set identifier of the image. .El .Ss msdos-specific options .Sy msdos images have MS-DOS-specific optional parameters that may be provided. The arguments consist of a keyword, an equal sign .Pq Ql = , and a value. The following keywords are supported (see .Xr newfs_msdos 8 for more details): .Pp .Bl -tag -width omit-trailing-period -offset indent -compact .It Cm backup_sector Location of the backup boot sector. .It Cm block_size Block size. .It Cm bootstrap Bootstrap file. .It Cm bytes_per_sector Bytes per sector. .It Cm create_size Create file size. .It Cm directory_entries Directory entries. .It Cm drive_heads Drive heads. .It Cm fat_type FAT type (12, 16, or 32). .It Cm floppy Preset drive parameters for standard format floppy disks (160, 180, 320, 360, 640, 720, 1200, 1232, 1440, or 2880). .It Cm hidden_sectors Hidden sectors. .It Cm info_sector Location of the info sector. .It Cm media_descriptor Media descriptor. .It Cm num_FAT Number of FATs. .It Cm OEM_string OEM string. .It Cm offset Offset in device. This option will be ignored if .Fl O is set to a positive number. .It Cm reserved_sectors Reserved sectors. .It Cm sectors_per_cluster Sectors per cluster. .It Cm sectors_per_fat Sectors per FAT. .It Cm sectors_per_track Sectors per track. .It Cm size File System size. .It Cm volume_id Volume ID. .It Cm volume_label Volume Label. .El .Sh SEE ALSO .Xr mtree 5 , .Xr mtree 8 , .Xr newfs 8 .Sh HISTORY The .Nm utility appeared in .Nx 1.6 . It was ported to .Fx and first appeared in .Fx 8.0 . .Sh AUTHORS .An Luke Mewburn .Aq Mt lukem@NetBSD.org (original program), .An Daniel Watt , .An Walter Deignan , .An Ryan Gabrys , .An Alan Perez-Rathke , .An Ram Vedam (cd9660 support), .An Christos Zoulas (msdos support). Index: stable/12 =================================================================== --- stable/12 (revision 366580) +++ stable/12 (revision 366581) Property changes on: stable/12 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r365847