xref: /illumos-gate/usr/src/cmd/etdump/output_text.c (revision 916bf6b9)
1c0455f33SToomas Soome /*
2c0455f33SToomas Soome  * Copyright (c) 2018 iXsystems, Inc.
3c0455f33SToomas Soome  * All rights reserved.
4c0455f33SToomas Soome  *
5c0455f33SToomas Soome  * Redistribution and use in source and binary forms, with or without
6c0455f33SToomas Soome  * modification, are permitted provided that the following conditions
7c0455f33SToomas Soome  * are met:
8c0455f33SToomas Soome  * 1. Redistributions of source code must retain the above copyright
9c0455f33SToomas Soome  *    notice, this list of conditions and the following disclaimer.
10c0455f33SToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
11c0455f33SToomas Soome  *    notice, this list of conditions and the following disclaimer in the
12c0455f33SToomas Soome  *    documentation and/or other materials provided with the distribution.
13c0455f33SToomas Soome  *
14c0455f33SToomas Soome  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15c0455f33SToomas Soome  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16c0455f33SToomas Soome  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17c0455f33SToomas Soome  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18c0455f33SToomas Soome  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19c0455f33SToomas Soome  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20c0455f33SToomas Soome  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21c0455f33SToomas Soome  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22c0455f33SToomas Soome  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23c0455f33SToomas Soome  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24c0455f33SToomas Soome  * SUCH DAMAGE.
25c0455f33SToomas Soome  */
26c0455f33SToomas Soome 
27c0455f33SToomas Soome #include <stdbool.h>
28c0455f33SToomas Soome #include <stdio.h>
29*916bf6b9SToomas Soome #include <inttypes.h>
30c0455f33SToomas Soome 
31c0455f33SToomas Soome #include "cd9660_eltorito.h"
32c0455f33SToomas Soome #include "etdump.h"
33c0455f33SToomas Soome 
34c0455f33SToomas Soome static void
output_image(FILE * outfile,const char * filename,boot_volume_descriptor * bvd __unused)35c0455f33SToomas Soome output_image(FILE *outfile, const char *filename,
36c0455f33SToomas Soome     boot_volume_descriptor *bvd __unused)
37c0455f33SToomas Soome {
38c0455f33SToomas Soome 
39c0455f33SToomas Soome 	fprintf(outfile, "Image in %s\n", filename);
40c0455f33SToomas Soome }
41c0455f33SToomas Soome 
42c0455f33SToomas Soome static void
output_section(FILE * outfile,const char * filename __unused,boot_catalog_section_header * bcsh)43c0455f33SToomas Soome output_section(FILE *outfile, const char *filename __unused,
44c0455f33SToomas Soome     boot_catalog_section_header *bcsh)
45c0455f33SToomas Soome {
46c0455f33SToomas Soome 
47c0455f33SToomas Soome 	fprintf(outfile, "\nSection header: %s",
48c0455f33SToomas Soome 	    system_id_string(bcsh->platform_id[0]));
49c0455f33SToomas Soome 
50c0455f33SToomas Soome 	if (bcsh->header_indicator[0] == ET_SECTION_HEADER_LAST)
51c0455f33SToomas Soome 		fprintf(outfile, ", final\n");
52c0455f33SToomas Soome 	else
53c0455f33SToomas Soome 		fprintf(outfile, "\n");
54c0455f33SToomas Soome }
55c0455f33SToomas Soome 
56c0455f33SToomas Soome static void
output_entry(FILE * outfile,const char * filename __unused,boot_catalog_section_entry * bcse,uchar_t platform_id __unused,bool initial)57c0455f33SToomas Soome output_entry(FILE *outfile, const char *filename __unused,
58c0455f33SToomas Soome     boot_catalog_section_entry *bcse, uchar_t platform_id __unused,
59c0455f33SToomas Soome     bool initial)
60c0455f33SToomas Soome {
61c0455f33SToomas Soome 	const char *indent;
62c0455f33SToomas Soome 
63c0455f33SToomas Soome 	switch (bcse->boot_indicator[0]) {
64c0455f33SToomas Soome 	case ET_BOOTABLE:
65c0455f33SToomas Soome 		break;
66c0455f33SToomas Soome 	case ET_NOT_BOOTABLE:
67c0455f33SToomas Soome 	default:
68c0455f33SToomas Soome 		return;
69c0455f33SToomas Soome 	}
70c0455f33SToomas Soome 
71c0455f33SToomas Soome 	if (initial) {
72c0455f33SToomas Soome 		fprintf(outfile, "Default entry\n");
73c0455f33SToomas Soome 		indent = "\t";
74c0455f33SToomas Soome 	} else {
75c0455f33SToomas Soome 		fprintf(outfile, "\tSection entry\n");
76c0455f33SToomas Soome 		indent = "\t\t";
77c0455f33SToomas Soome 	}
78c0455f33SToomas Soome 
79c0455f33SToomas Soome 	fprintf(outfile, "%sSystem %s\n", indent,
80c0455f33SToomas Soome 	    system_id_string(bcse->system_type[0]));
81*916bf6b9SToomas Soome 	fprintf(outfile, "%sStart LBA %" PRIu32 " (0x%" PRIx32
82*916bf6b9SToomas Soome 	    "), sector count %" PRIu16 " (0x%" PRIx16 ")\n",
83c0455f33SToomas Soome 	    indent, isonum_731(bcse->load_rba), isonum_731(bcse->load_rba),
84c0455f33SToomas Soome 	    isonum_721(bcse->sector_count), isonum_721(bcse->sector_count));
85c0455f33SToomas Soome 	fprintf(outfile, "%sMedia type: %s\n", indent,
86c0455f33SToomas Soome 	    media_type_string(bcse->media_type[0]));
87c0455f33SToomas Soome }
88c0455f33SToomas Soome 
89c0455f33SToomas Soome static struct outputter _output_text = {
90c0455f33SToomas Soome 	.output_image = output_image,
91c0455f33SToomas Soome 	.output_section = output_section,
92c0455f33SToomas Soome 	.output_entry = output_entry,
93c0455f33SToomas Soome };
94c0455f33SToomas Soome 
95c0455f33SToomas Soome struct outputter *output_text = &_output_text;
96