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
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 * -----------------------------------------------------------------------
35 #include "hdt-common.h"
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
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!
53 static void show_partition_information(struct driveinfo
*drive_info
,
54 struct part_entry
*ptab
,
56 int nb_partitions_seen
)
59 char bootloader_name
[9];
61 unsigned int start
, end
;
63 int i
= nb_partitions_seen
;
67 start
= partition_offset
;
68 end
= start
+ ptab
->length
- 1;
71 sectors_to_size(ptab
->length
, size
);
73 memset(size
, 0, sizeof size
);
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
);
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
);
95 void main_show_disk(int argc
, char **argv
, struct s_hardware
*hardware
)
98 more_printf("Which disk?\n");
102 int drive
= strtol(argv
[0], (char **)NULL
, 16);
104 if (drive
< 0x80 || drive
>= 0xff) {
105 more_printf("Invalid disk: %d.\n", drive
);
109 int i
= drive
- 0x80;
110 struct driveinfo
*d
= &hardware
->disk_info
[i
];
114 detect_disks(hardware
);
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
);
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",
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
)) {
147 fprintf(stderr
, "I/O error parsing disk 0x%X\n", d
->disk
);
148 get_error("parse_partition_table");
150 fprintf(stderr
, "Disk 0x%X: unrecognized partition layout\n",
153 fprintf(stderr
, "\n");
159 void main_show_disks(int argc __unused
, char **argv __unused
,
160 struct s_hardware
*hardware
)
164 detect_disks(hardware
);
167 for (int drive
= 0x80; drive
< 0xff; drive
++) {
168 if (hardware
->disk_info
[drive
- 0x80].cbios
) {
176 sprintf(buf
, "0x%x", drive
);
177 char *argv
[1] = { buf
};
178 main_show_disk(1, argv
, hardware
);
183 more_printf("No disk found\n");
186 void disks_summary(int argc __unused
, char **argv __unused
,
187 struct s_hardware
*hardware
)
192 detect_disks(hardware
);
195 for (int drive
= 0x80; drive
< 0xff; drive
++) {
197 if (!hardware
->disk_info
[i
].cbios
)
198 continue; /* Invalid geometry */
201 struct driveinfo
*d
= &hardware
->disk_info
[i
];
204 if ((int)d
->edd_params
.sectors
> 0)
205 sectors_to_size((int)d
->edd_params
.sectors
, disk_size
);
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
,
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
));
224 more_printf("No disk found\n");
227 struct cli_callback_descr list_disk_show_modules
[] = {
230 .exec
= main_show_disks
,
234 .exec
= main_show_disk
,
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
= {
250 .default_modules
= NULL
,
251 .show_modules
= &disk_show_modules
,