# # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright 2019 Toomas Soome # Copyright (c) 2019, Joyent, Inc. # PROG= etdump OBJS= etdump.o output_shell.o output_text.o SRCS= $(OBJS:%.o=%.c) include ../Makefile.cmd # comes from FreeBSD upstream SMOFF += all_func_returns .KEEP_STATE: all: $(PROG) install: all $(ROOTPROG) clean: $(RM) $(OBJS) $(PROG): $(OBJS) $(LINK.c) $(OBJS) -o $@ $(LDLIBS) $(POST_PROCESS) lint: include ../Makefile.targ cd9660_eltorito.h: cd9660_conversion.c: /* * 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. */ etdump.h: etdump.c: etdump.1: output_shell.c: output_text.c: /* * Copyright (c) 2018 iXsystems, Inc. * All rights reserved. * * 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 THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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. */ etdump utility command /* * $NetBSD: cd9660_eltorito.h,v 1.6 2017/01/24 11:22:43 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. */ #ifndef _CD9660_ELTORITO_H_ #define _CD9660_ELTORITO_H_ #include #include /* Boot defines */ #define ET_ID "EL TORITO SPECIFICATION" #define ET_SYS_X86 0 #define ET_SYS_PPC 1 #define ET_SYS_MAC 2 #define ET_SYS_EFI 0xef /* Platform ID at section header entry */ #define ET_BOOT_ENTRY_SIZE 0x20 #define ET_BOOTABLE 0x88 #define ET_NOT_BOOTABLE 0 #define ET_MEDIA_NOEM 0 #define ET_MEDIA_12FDD 1 #define ET_MEDIA_144FDD 2 #define ET_MEDIA_288FDD 3 #define ET_MEDIA_HDD 4 #define ET_INDICATOR_HEADERMORE 0x90 #define ET_INDICATOR_HEADERLAST 0x91 #define ET_INDICATOR_EXTENSION 0x44 /* Boot Structures */ #define ISODCL(from, to) (to - from + 1) typedef struct _boot_volume_descriptor { uchar_t boot_record_indicator [ISODCL(0x00, 0x00)]; uchar_t identifier [ISODCL(0x01, 0x05)]; uchar_t version [ISODCL(0x06, 0x06)]; uchar_t boot_system_identifier [ISODCL(0x07, 0x26)]; uchar_t unused1 [ISODCL(0x27, 0x46)]; uchar_t boot_catalog_pointer [ISODCL(0x47, 0x4A)]; uchar_t unused2 [ISODCL(0x4B, 0x7FF)]; } boot_volume_descriptor; typedef struct _boot_catalog_validation_entry { uchar_t header_id [ISODCL(0x00, 0x00)]; uchar_t platform_id [ISODCL(0x01, 0x01)]; uchar_t reserved1 [ISODCL(0x02, 0x03)]; uchar_t manufacturer [ISODCL(0x04, 0x1B)]; uchar_t checksum [ISODCL(0x1C, 0x1D)]; uchar_t key [ISODCL(0x1E, 0x1F)]; } boot_catalog_validation_entry; typedef struct _boot_catalog_initial_entry { uchar_t boot_indicator [ISODCL(0x00, 0x00)]; uchar_t media_type [ISODCL(0x01, 0x01)]; uchar_t load_segment [ISODCL(0x02, 0x03)]; uchar_t system_type [ISODCL(0x04, 0x04)]; uchar_t unused_1 [ISODCL(0x05, 0x05)]; uchar_t sector_count [ISODCL(0x06, 0x07)]; uchar_t load_rba [ISODCL(0x08, 0x0B)]; uchar_t unused_2 [ISODCL(0x0C, 0x1F)]; } boot_catalog_initial_entry; #define ET_SECTION_HEADER_MORE 0x90 #define ET_SECTION_HEADER_LAST 0x91 typedef struct _boot_catalog_section_header { uchar_t header_indicator [ISODCL(0x00, 0x00)]; uchar_t platform_id [ISODCL(0x01, 0x01)]; uchar_t num_section_entries [ISODCL(0x02, 0x03)]; uchar_t id_string [ISODCL(0x04, 0x1F)]; } boot_catalog_section_header; typedef struct _boot_catalog_section_entry { uchar_t boot_indicator [ISODCL(0x00, 0x00)]; uchar_t media_type [ISODCL(0x01, 0x01)]; uchar_t load_segment [ISODCL(0x02, 0x03)]; uchar_t system_type [ISODCL(0x04, 0x04)]; uchar_t unused_1 [ISODCL(0x05, 0x05)]; uchar_t sector_count [ISODCL(0x06, 0x07)]; uchar_t load_rba [ISODCL(0x08, 0x0B)]; uchar_t selection_criteria [ISODCL(0x0C, 0x0C)]; uchar_t vendor_criteria [ISODCL(0x0D, 0x1F)]; } boot_catalog_section_entry; typedef struct _boot_catalog_section_entry_extension { uchar_t extension_indicator [ISODCL(0x00, 0x00)]; uchar_t flags [ISODCL(0x01, 0x01)]; uchar_t vendor_criteria [ISODCL(0x02, 0x1F)]; } boot_catalog_section_entry_extension; #define ET_ENTRY_VE 1 #define ET_ENTRY_IE 2 #define ET_ENTRY_SH 3 #define ET_ENTRY_SE 4 #define ET_ENTRY_EX 5 struct boot_catalog_entry { char entry_type; union { boot_catalog_validation_entry VE; boot_catalog_initial_entry IE; boot_catalog_section_header SH; boot_catalog_section_entry SE; boot_catalog_section_entry_extension EX; } entry_data; LIST_ENTRY(boot_catalog_entry) ll_struct; }; /* Temporary structure */ struct cd9660_boot_image { char *filename; int size; int sector; /* copied to LoadRBA */ int num_sectors; unsigned int loadSegment; uchar_t targetMode; uchar_t system; uchar_t bootable; uchar_t platform_id; /* for section header entry */ /* * If the boot image exists in the filesystem * already, this is a pointer to that node. For the sake * of simplicity in future versions, this pointer is only * to the node in the primary volume. This SHOULD be done * via a hashtable lookup. */ struct _cd9660node *boot_image_node; TAILQ_ENTRY(cd9660_boot_image) image_list; int serialno; }; void cd9660_721(uint16_t, unsigned char *); static __inline uint16_t isonum_721(const unsigned char *p) { return (p[0] | p[1] << 8); } static __inline uint32_t isonum_731(const unsigned char *p) { return (p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24); } #endif /* _CD9660_ELTORITO_H_ */ /* * Copyright (c) 2018 iXsystems, Inc. * All rights reserved. * * 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 THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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 #include #include #include #include #include #include #include #include #include #include #include "cd9660_eltorito.h" #include "etdump.h" #define ISO_DEFAULT_BLOCK_SHIFT 11 #define ISO_DEFAULT_BLOCK_SIZE (1 << ISO_DEFAULT_BLOCK_SHIFT) /* Little endian */ void cd9660_721(uint16_t w, unsigned char *twochar) { #if BYTE_ORDER == BIG_ENDIAN w = htole16(w); #endif memcpy(twochar, &w, 2); } const char * system_id_string(uchar_t system_id) { switch (system_id) { case ET_SYS_X86: return ("i386"); case ET_SYS_PPC: return ("powerpc"); case ET_SYS_MAC: return ("mac"); case ET_SYS_EFI: return ("efi"); default: return ("invalid"); } } const char * media_type_string(uchar_t media_type) { switch (media_type) { case ET_MEDIA_NOEM: return ("no emulation"); case ET_MEDIA_12FDD: return ("1.2MB FDD"); case ET_MEDIA_144FDD: return ("1.44MB FDD"); case ET_MEDIA_288FDD: return ("2.88MB FDD"); case ET_MEDIA_HDD: return ("HDD"); default: return ("invalid"); } } static int read_sector(FILE *iso, daddr_t sector, char *buffer) { fseek(iso, sector * ISO_DEFAULT_BLOCK_SIZE, SEEK_SET); if (fread(buffer, ISO_DEFAULT_BLOCK_SIZE, 1, iso) != 1) { return (errno); } return (0); } static bool boot_catalog_valid(char *entry) { boot_catalog_validation_entry *ve; int16_t checksum, sum; unsigned char *csptr; size_t i; ve = (boot_catalog_validation_entry *)entry; checksum = isonum_721(ve->checksum); cd9660_721(0, ve->checksum); csptr = (unsigned char *)ve; for (i = sum = 0; i < sizeof (*ve); i += 2) { sum += (int16_t)csptr[i]; sum += 256 * (int16_t)csptr[i + 1]; } if (sum + checksum != 0) { return (false); } cd9660_721(checksum, ve->checksum); return (true); } static int dump_section(char *buffer, size_t offset, FILE *outfile, const char *filename, struct outputter *outputter) { boot_catalog_section_header *sh; uchar_t platform_id; int i; size_t entry_offset; boot_catalog_section_entry *entry; sh = (boot_catalog_section_header *)&buffer[offset]; if (outputter->output_section != NULL) { outputter->output_section(outfile, filename, sh); } platform_id = sh->platform_id[0]; if (outputter->output_entry != NULL) { for (i = 1; i <= (int)sh->num_section_entries[0]; i++) { entry_offset = offset + i * ET_BOOT_ENTRY_SIZE; entry = (boot_catalog_section_entry *)&buffer[entry_offset]; outputter->output_entry(outfile, filename, entry, platform_id, false); } } return (1 + (int)sh->num_section_entries[0]); } static void dump_eltorito(FILE *iso, const char *filename, FILE *outfile, struct outputter *outputter) { char buffer[ISO_DEFAULT_BLOCK_SIZE], *entry; boot_volume_descriptor *bvd; daddr_t boot_catalog; size_t offset; int entry_count; if (read_sector(iso, 17, buffer) != 0) err(1, "failed to read from image"); bvd = (boot_volume_descriptor *)buffer; if (memcmp(bvd->identifier, ISO_ID_STRING, 5) != 0) warnx("%s: not a valid ISO", filename); if (bvd->boot_record_indicator[0] != ISO_VD_BOOT) warnx("%s: not an El Torito bootable ISO", filename); if (memcmp(bvd->boot_system_identifier, ET_ID, 23) != 0) warnx("%s: not an El Torito bootable ISO", filename); boot_catalog = isonum_731(bvd->boot_catalog_pointer); if (read_sector(iso, boot_catalog, buffer) != 0) err(1, "failed to read from image"); entry = buffer; offset = 0; if (!boot_catalog_valid(entry)) warnx("%s: boot catalog checksum is invalid", filename); if (outputter->output_image != NULL) outputter->output_image(outfile, filename, bvd); offset += ET_BOOT_ENTRY_SIZE; entry = &buffer[offset]; if (outputter->output_entry != NULL) outputter->output_entry(outfile, filename, (boot_catalog_section_entry *)entry, 0, true); offset += ET_BOOT_ENTRY_SIZE; while (offset < ISO_DEFAULT_BLOCK_SIZE) { entry = &buffer[offset]; if ((uint8_t)entry[0] != ET_SECTION_HEADER_MORE && (uint8_t)entry[0] != ET_SECTION_HEADER_LAST) break; entry_count = dump_section(buffer, offset, outfile, filename, outputter); offset += entry_count * ET_BOOT_ENTRY_SIZE; } } static void usage(const char *progname) { char *path; path = strdup(progname); fprintf(stderr, "usage: %s [-f format] [-o filename] filename [...]\n", basename(path)); fprintf(stderr, "\tsupported output formats: shell, text\n"); exit(1); } int main(int argc, char **argv) { int ch, i; FILE *outfile, *iso; struct outputter *outputter; outfile = stdout; outputter = output_text; static struct option longopts[] = { { "format", required_argument, NULL, 'f' }, { "output", required_argument, NULL, 'o' }, { NULL, 0, NULL, 0 }, }; while ((ch = getopt_long(argc, argv, "f:o:", longopts, NULL)) != -1) { switch (ch) { case 'f': if (strcmp(optarg, "shell") == 0) outputter = output_shell; else if (strcmp(optarg, "text") == 0) outputter = output_text; else usage(argv[0]); break; case 'o': if (strcmp(optarg, "-") == 0) { outfile = stdout; } else if ((outfile = fopen(optarg, "w")) == NULL) { err(1, "unable to open %s for output", optarg); } break; default: usage(argv[0]); } } argc -= optind; argv += optind; for (i = 0; i < argc; i++) { if (strcmp(argv[i], "-") == 0) { iso = stdin; } else { iso = fopen(argv[i], "r"); if (iso == NULL) err(1, "could not open %s", argv[1]); } dump_eltorito(iso, argv[i], outfile, outputter); } return (0); } /* * Copyright (c) 2018 iXsystems, Inc. * All rights reserved. * * 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 THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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: head/usr.bin/etdump/etdump.h 331949 2018-04-03 21:08:10Z benno $ */ #ifndef _ETDUMP_H_ #define _ETDUMP_H_ struct outputter { void (*output_image)(FILE *outfile, const char *filename, boot_volume_descriptor *bvd); void (*output_section)(FILE *outfile, const char *filename, boot_catalog_section_header *bcsh); void (*output_entry)(FILE *outfile, const char *filename, boot_catalog_section_entry *bcse, uchar_t platform_id, bool initial); }; extern struct outputter *output_text; extern struct outputter *output_shell; const char *system_id_string(uchar_t system_id); const char *media_type_string(uchar_t media_type); #endif /* _ETDUMP_H_ */ /* * Copyright (c) 2018 iXsystems, Inc. * All rights reserved. * * 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 THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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 #include #include #include "cd9660_eltorito.h" #include "etdump.h" static void output_entry(FILE *outfile, const char *filename __unused, boot_catalog_section_entry *bcse, uchar_t platform_id, bool initial) { const char *platform; switch (bcse->boot_indicator[0]) { case ET_BOOTABLE: break; case ET_NOT_BOOTABLE: default: return; } if (initial) platform = "default"; else platform = system_id_string(platform_id); fprintf(outfile, "et_platform=%s;et_system=%s;et_lba=%" PRIu32 ";et_sectors=%" PRIu16 "\n", platform, system_id_string(bcse->system_type[0]), isonum_731(bcse->load_rba), isonum_721(bcse->sector_count)); } static struct outputter _output_shell = { .output_image = NULL, .output_section = NULL, .output_entry = output_entry, }; struct outputter *output_shell = &_output_shell; /* * Copyright (c) 2018 iXsystems, Inc. * All rights reserved. * * 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 THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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 #include #include #include "cd9660_eltorito.h" #include "etdump.h" static void output_image(FILE *outfile, const char *filename, boot_volume_descriptor *bvd __unused) { fprintf(outfile, "Image in %s\n", filename); } static void output_section(FILE *outfile, const char *filename __unused, boot_catalog_section_header *bcsh) { fprintf(outfile, "\nSection header: %s", system_id_string(bcsh->platform_id[0])); if (bcsh->header_indicator[0] == ET_SECTION_HEADER_LAST) fprintf(outfile, ", final\n"); else fprintf(outfile, "\n"); } static void output_entry(FILE *outfile, const char *filename __unused, boot_catalog_section_entry *bcse, uchar_t platform_id __unused, bool initial) { const char *indent; switch (bcse->boot_indicator[0]) { case ET_BOOTABLE: break; case ET_NOT_BOOTABLE: default: return; } if (initial) { fprintf(outfile, "Default entry\n"); indent = "\t"; } else { fprintf(outfile, "\tSection entry\n"); indent = "\t\t"; } fprintf(outfile, "%sSystem %s\n", indent, system_id_string(bcse->system_type[0])); fprintf(outfile, "%sStart LBA %" PRIu32 " (0x%" PRIx32 "), sector count %" PRIu16 " (0x%" PRIx16 ")\n", indent, isonum_731(bcse->load_rba), isonum_731(bcse->load_rba), isonum_721(bcse->sector_count), isonum_721(bcse->sector_count)); fprintf(outfile, "%sMedia type: %s\n", indent, media_type_string(bcse->media_type[0])); } static struct outputter _output_text = { .output_image = output_image, .output_section = output_section, .output_entry = output_entry, }; struct outputter *output_text = &_output_text;