Adding upstream version 4.00~pre61+dfsg.
[syslinux-debian/hramrach.git] / com32 / hdt / hdt-cli-disk.c
blobc43b7ca7e7c0ef6ba0d1dfae0a479186a29d7600
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 detect_disks(hardware);
115 reset_more_printf();
117 if (!hardware->disk_info[i].cbios) {
118 more_printf("No disk found\n");
119 return; /* Invalid geometry */
122 get_mbr_string(hardware->mbr_ids[i], &mbr_name, 50);
124 if ((int)d->edd_params.sectors > 0)
125 sectors_to_size((int)d->edd_params.sectors, disk_size);
126 else
127 memset(disk_size, 0, sizeof disk_size);
129 more_printf("DISK 0x%X:\n"
130 " C/H/S: %d cylinders, %d heads, %d sectors/track\n"
131 " EDD: Version: %X\n"
132 " Size: %s, %d bytes/sector, %d sectors/track\n"
133 " Host bus: %s, Interface type: %s\n"
134 " MBR: %s (id 0x%X)\n\n",
135 d->disk,
136 d->legacy_max_cylinder + 1, d->legacy_max_head + 1,
137 d->legacy_sectors_per_track, d->edd_version, disk_size,
138 (int)d->edd_params.bytes_per_sector,
139 (int)d->edd_params.sectors_per_track,
140 remove_spaces((char *)d->edd_params.host_bus_type),
141 remove_spaces((char *)d->edd_params.interface_type), mbr_name,
142 hardware->mbr_ids[i]);
143 display_line_nb += 6;
145 if (parse_partition_table(d, &show_partition_information)) {
146 if (errno_disk) {
147 fprintf(stderr, "I/O error parsing disk 0x%X\n", d->disk);
148 get_error("parse_partition_table");
149 } else {
150 fprintf(stderr, "Disk 0x%X: unrecognized partition layout\n",
151 d->disk);
153 fprintf(stderr, "\n");
156 more_printf("\n");
159 void main_show_disks(int argc __unused, char **argv __unused,
160 struct s_hardware *hardware)
162 bool found = false;
163 reset_more_printf();
164 detect_disks(hardware);
166 int first_one = 0;
167 for (int drive = 0x80; drive < 0xff; drive++) {
168 if (hardware->disk_info[drive - 0x80].cbios) {
169 found = true;
170 if (!first_one) {
171 first_one = 1;
172 } else {
173 pause_printf();
175 char buf[5] = "";
176 sprintf(buf, "0x%x", drive);
177 char *argv[1] = { buf };
178 main_show_disk(1, argv, hardware);
182 if (found == false)
183 more_printf("No disk found\n");
186 void disks_summary(int argc __unused, char **argv __unused,
187 struct s_hardware *hardware)
189 int i = -1;
190 bool found = false;
192 detect_disks(hardware);
193 reset_more_printf();
195 for (int drive = 0x80; drive < 0xff; drive++) {
196 i++;
197 if (!hardware->disk_info[i].cbios)
198 continue; /* Invalid geometry */
200 found = true;
201 struct driveinfo *d = &hardware->disk_info[i];
202 char disk_size[11];
204 if ((int)d->edd_params.sectors > 0)
205 sectors_to_size((int)d->edd_params.sectors, disk_size);
206 else
207 memset(disk_size, 0, sizeof disk_size);
209 more_printf("DISK 0x%X:\n", d->disk);
210 more_printf(" C/H/S: %d cylinders, %d heads, %d sectors/track\n",
211 d->legacy_max_cylinder + 1, d->legacy_max_head + 1,
212 d->legacy_sectors_per_track);
213 more_printf(" EDD: Version: %X, size: %s\n", d->edd_version,
214 disk_size);
216 /* Do not print Host Bus & Interface if EDD isn't 3.0 or more */
217 if (d->edd_version >= 0x30)
218 more_printf(" Host bus: %s, Interface type: %s\n\n",
219 remove_spaces((char *)d->edd_params.host_bus_type),
220 remove_spaces((char *)d->edd_params.interface_type));
223 if (found == false)
224 more_printf("No disk found\n");
227 struct cli_callback_descr list_disk_show_modules[] = {
229 .name = "disks",
230 .exec = main_show_disks,
233 .name = "disk",
234 .exec = main_show_disk,
237 .name = NULL,
238 .exec = NULL,
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,