Adding upstream version 6.02~pre8+dfsg.
[syslinux-debian/hramrach.git] / com32 / hdt / hdt-cli-disk.c
blob10c95d7d75feb33cdb6252edbe10b97da119e533
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2009 Pierre-Alexandre Meyer - All Rights Reserved
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following
12 * conditions:
14 * The above copyright notice and this permission notice shall
15 * be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
26 * -----------------------------------------------------------------------
29 #include <stdio.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <errno.h>
34 #include "hdt-cli.h"
35 #include "hdt-common.h"
36 #include "hdt-util.h"
38 /**
39 * show_partition_information - print information about a partition
40 * @ptab: part_entry describing the partition
41 * @i: Partition number (UI purposes only)
42 * @ptab_root: part_entry describing the root partition (extended only)
43 * @drive_info: driveinfo struct describing the drive on which the partition
44 * is
46 * Note on offsets (from hpa, see chain.c32):
48 * To make things extra confusing: data partition offsets are relative to where
49 * the data partition record is stored, whereas extended partition offsets
50 * are relative to the beginning of the extended partition all the way back
51 * at the MBR... but still not absolute!
52 **/
53 static void show_partition_information(struct driveinfo *drive_info,
54 struct part_entry *ptab,
55 int partition_offset,
56 int nb_partitions_seen)
58 char size[11];
59 char bootloader_name[9];
60 char *parttype;
61 unsigned int start, end;
63 int i = nb_partitions_seen;
65 reset_more_printf();
67 start = partition_offset;
68 end = start + ptab->length - 1;
70 if (ptab->length > 0)
71 sectors_to_size(ptab->length, size);
72 else
73 memset(size, 0, sizeof size);
75 if (i == 1)
76 more_printf(" # B Start End Size Id Type\n");
78 get_label(ptab->ostype, &parttype);
79 more_printf("%2d %s %11d %11d %s %02X %s",
80 i, (ptab->active_flag == 0x80) ? "x" : " ",
81 start, end, size, ptab->ostype, parttype);
83 /* Extra info */
84 if (ptab->ostype == 0x82 && swsusp_check(drive_info, ptab))
85 more_printf("%s", " (Swsusp sig. detected)");
87 if (get_bootloader_string(drive_info, ptab, bootloader_name, 9) == 0)
88 more_printf("%-46s %s %s", " ", "Bootloader:", bootloader_name);
90 more_printf("\n");
92 free(parttype);
95 void main_show_disk(int argc, char **argv, struct s_hardware *hardware)
97 if (!argc) {
98 more_printf("Which disk?\n");
99 return;
102 int drive = strtol(argv[0], (char **)NULL, 16);
104 if (drive < 0x80 || drive >= 0xff) {
105 more_printf("Invalid disk: %d.\n", drive);
106 return;
109 int i = drive - 0x80;
110 struct driveinfo *d = &hardware->disk_info[i];
111 char disk_size[11];
112 char mbr_name[50];
114 reset_more_printf();
116 if (!hardware->disk_info[i].cbios) {
117 more_printf("No disk found\n");
118 return; /* Invalid geometry */
121 get_mbr_string(hardware->mbr_ids[i], &mbr_name, 50);
123 if ((int)d->edd_params.sectors > 0)
124 sectors_to_size((int)d->edd_params.sectors, disk_size);
125 else
126 memset(disk_size, 0, sizeof disk_size);
128 more_printf("DISK 0x%X:\n"
129 " C/H/S: %d cylinders, %d heads, %d sectors/track\n"
130 " EDD: Version: %X\n"
131 " Size: %s, %d bytes/sector, %d sectors/track\n"
132 " Host bus: %s, Interface type: %s\n"
133 " MBR: %s (id 0x%X)\n\n",
134 d->disk,
135 d->legacy_max_cylinder + 1, d->legacy_max_head + 1,
136 d->legacy_sectors_per_track, d->edd_version, disk_size,
137 (int)d->edd_params.bytes_per_sector,
138 (int)d->edd_params.sectors_per_track,
139 remove_spaces((char *)d->edd_params.host_bus_type),
140 remove_spaces((char *)d->edd_params.interface_type), mbr_name,
141 hardware->mbr_ids[i]);
142 display_line_nb += 6;
144 if (parse_partition_table(d, &show_partition_information)) {
145 if (errno_disk) {
146 fprintf(stderr, "I/O error parsing disk 0x%X\n", d->disk);
147 get_error("parse_partition_table");
148 } else {
149 fprintf(stderr, "Disk 0x%X: unrecognized partition layout\n",
150 d->disk);
152 fprintf(stderr, "\n");
155 more_printf("\n");
158 void main_show_disks(int argc __unused, char **argv __unused,
159 struct s_hardware *hardware)
161 bool found = false;
162 reset_more_printf();
164 int first_one = 0;
165 for (int drive = 0x80; drive < 0xff; drive++) {
166 if (hardware->disk_info[drive - 0x80].cbios) {
167 found = true;
168 if (!first_one) {
169 first_one = 1;
170 } else {
171 pause_printf();
173 char buf[5] = "";
174 sprintf(buf, "0x%x", drive);
175 char *argv[1] = { buf };
176 main_show_disk(1, argv, hardware);
180 if (found == false)
181 more_printf("No disk found\n");
184 void disks_summary(int argc __unused, char **argv __unused,
185 struct s_hardware *hardware)
187 int i = -1;
188 bool found = false;
190 reset_more_printf();
192 for (int drive = 0x80; drive < 0xff; drive++) {
193 i++;
194 if (!hardware->disk_info[i].cbios)
195 continue; /* Invalid geometry */
197 found = true;
198 struct driveinfo *d = &hardware->disk_info[i];
199 char disk_size[11];
201 if ((int)d->edd_params.sectors > 0)
202 sectors_to_size((int)d->edd_params.sectors, disk_size);
203 else
204 memset(disk_size, 0, sizeof disk_size);
206 more_printf("DISK 0x%X:\n", d->disk);
207 more_printf(" C/H/S: %d cylinders, %d heads, %d sectors/track\n",
208 d->legacy_max_cylinder + 1, d->legacy_max_head + 1,
209 d->legacy_sectors_per_track);
210 more_printf(" EDD: Version: %X, size: %s\n", d->edd_version,
211 disk_size);
213 /* Do not print Host Bus & Interface if EDD isn't 3.0 or more */
214 if (d->edd_version >= 0x30)
215 more_printf(" Host bus: %s, Interface type: %s\n\n",
216 remove_spaces((char *)d->edd_params.host_bus_type),
217 remove_spaces((char *)d->edd_params.interface_type));
220 if (found == false)
221 more_printf("No disk found\n");
224 struct cli_callback_descr list_disk_show_modules[] = {
226 .name = "disks",
227 .exec = main_show_disks,
228 .nomodule = false,
231 .name = "disk",
232 .exec = main_show_disk,
233 .nomodule = false,
236 .name = NULL,
237 .exec = NULL,
238 .nomodule = false,
242 struct cli_module_descr disk_show_modules = {
243 .modules = list_disk_show_modules,
244 .default_callback = disks_summary,
247 struct cli_mode_descr disk_mode = {
248 .mode = DISK_MODE,
249 .name = CLI_DISK,
250 .default_modules = NULL,
251 .show_modules = &disk_show_modules,
252 .set_modules = NULL,