1 /* ----------------------------------------------------------------------- *
3 * Copyright 2009 Erwan Velu - 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 * -----------------------------------------------------------------------
36 static void show_partition_information(struct driveinfo
*drive_info
,
37 struct part_entry
*ptab __unused
,
38 int partition_offset __unused
,
39 int nb_partitions_seen
)
41 char menu_title
[MENULEN
+ 1];
42 char menu_title_ref
[MENULEN
+ 1];
44 if (nb_partitions_seen
== 1)
47 memset(menu_title
, 0, sizeof menu_title
);
48 memset(menu_title_ref
, 0, sizeof menu_title_ref
);
49 snprintf(menu_title_ref
, sizeof menu_title_ref
, "disk_%x_part_%d",
50 drive_info
[dn
].disk
, nb_partitions_seen
);
51 snprintf(menu_title
, sizeof menu_title
, "Partition %d", nb_partitions_seen
);
54 "Partition information (start, end, length, type, ...)",
55 OPT_SUBMENU
, menu_title_ref
, 0);
59 * compute_partition_information - print information about a partition
60 * @ptab: part_entry describing the partition
61 * @i: Partition number (UI purposes only)
62 * @ptab_root: part_entry describing the root partition (extended only)
63 * @drive_info: driveinfo struct describing the drive on which the partition
66 * Note on offsets (from hpa, see chain.c32):
68 * To make things extra confusing: data partition offsets are relative to where
69 * the data partition record is stored, whereas extended partition offsets
70 * are relative to the beginning of the extended partition all the way back
71 * at the MBR... but still not absolute!
73 static void compute_partition_information(struct driveinfo
*drive_info
,
74 struct part_entry
*ptab
,
76 int nb_partitions_seen
)
79 char bootloader_name
[9];
81 unsigned int start
, end
;
82 char buffer
[SUBMENULEN
+ 1];
83 char statbuffer
[STATLEN
+ 1];
84 char menu_title
[MENULEN
+ 1];
85 char menu_title_ref
[MENULEN
+ 1];
87 memset(buffer
, 0, sizeof buffer
);
88 memset(statbuffer
, 0, sizeof statbuffer
);
89 memset(menu_title
, 0, sizeof menu_title
);
90 memset(menu_title_ref
, 0, sizeof menu_title_ref
);
91 snprintf(menu_title_ref
, sizeof menu_title_ref
, "disk_%x_part_%d",
92 drive_info
[dn
].disk
, nb_partitions_seen
);
93 snprintf(menu_title
, sizeof menu_title
, "Partition %d", nb_partitions_seen
);
95 add_named_menu(menu_title_ref
, menu_title
, -1);
96 set_menu_pos(SUBMENU_Y
, SUBMENU_X
);
98 start
= partition_offset
;
99 end
= start
+ ptab
->length
- 1;
101 if (ptab
->length
> 0)
102 sectors_to_size(ptab
->length
, size
);
104 memset(size
, 0, sizeof size
);
106 get_label(ptab
->ostype
, &parttype
);
108 snprintf(buffer
, sizeof buffer
, "Size : %s", remove_spaces(size
));
109 snprintf(statbuffer
, sizeof statbuffer
, "Size : %s", remove_spaces(size
));
110 add_item(buffer
, statbuffer
, OPT_INACTIVE
, NULL
, 0);
112 snprintf(buffer
, sizeof buffer
, "Type : %s", parttype
);
113 snprintf(statbuffer
, sizeof statbuffer
, "Type: %s", parttype
);
114 add_item(buffer
, statbuffer
, OPT_INACTIVE
, NULL
, 0);
116 if (get_bootloader_string(drive_info
, ptab
, bootloader_name
, 9) == 0) {
117 snprintf(buffer
, sizeof buffer
, "Bootloader : %s", bootloader_name
);
118 snprintf(statbuffer
, sizeof statbuffer
, "Bootloader: %s",
120 add_item(buffer
, statbuffer
, OPT_INACTIVE
, NULL
, 0);
123 snprintf(buffer
, sizeof buffer
, "Bootable : %s",
124 (ptab
->active_flag
== 0x80) ? "Yes" : "No");
125 snprintf(statbuffer
, sizeof statbuffer
, "Bootable: %s",
126 (ptab
->active_flag
== 0x80) ? "Yes" : "No");
127 add_item(buffer
, statbuffer
, OPT_INACTIVE
, NULL
, 0);
129 snprintf(buffer
, sizeof buffer
, "Start : %d", start
);
130 snprintf(statbuffer
, sizeof statbuffer
, "Start: %d", start
);
131 add_item(buffer
, statbuffer
, OPT_INACTIVE
, NULL
, 0);
133 snprintf(buffer
, sizeof buffer
, "End : %d", end
);
134 snprintf(statbuffer
, sizeof statbuffer
, "End: %d", end
);
135 add_item(buffer
, statbuffer
, OPT_INACTIVE
, NULL
, 0);
137 snprintf(buffer
, sizeof buffer
, "Id : %X", ptab
->ostype
);
138 snprintf(statbuffer
, sizeof statbuffer
, "Id: %X", ptab
->ostype
);
139 add_item(buffer
, statbuffer
, OPT_INACTIVE
, NULL
, 0);
144 if (ptab
->ostype
== 0x82 && swsusp_check(drive_info
, ptab
) != -1) {
145 snprintf(buffer
, sizeof buffer
, "%s", "Swsusp sig : detected");
146 snprintf(statbuffer
, sizeof statbuffer
, "%s", "Swsusp sig : detected");
147 add_item(buffer
, statbuffer
, OPT_INACTIVE
, NULL
, 0);
151 /* Compute the disk submenu */
152 static int compute_disk_module(struct s_my_menu
*menu
, int nb_sub_disk_menu
,
153 const struct s_hardware
*hardware
,
156 char buffer
[MENULEN
+ 1];
157 char statbuffer
[STATLEN
+ 1];
159 struct driveinfo
*d
= (struct driveinfo
*)hardware
->disk_info
;
161 snprintf(buffer
, sizeof buffer
, " Disk <0x%X> (EDD %X)",
162 d
[disk_number
].disk
, d
[disk_number
].edd_version
);
163 menu
[nb_sub_disk_menu
].menu
= add_menu(buffer
, -1);
164 menu
[nb_sub_disk_menu
].items_count
= 0;
166 int previous_size
, size
;
167 char previous_unit
[3], unit
[3]; // GB
168 char size_iec
[11]; // GiB
169 char size_dec
[11]; // GB
170 sectors_to_size_dec(previous_unit
, &previous_size
, unit
, &size
,
171 d
[disk_number
].edd_params
.sectors
);
172 sectors_to_size(d
[disk_number
].edd_params
.sectors
, size_iec
);
173 sectors_to_size_dec2(d
[disk_number
].edd_params
.sectors
, size_dec
);
175 snprintf(buffer
, sizeof buffer
, "Size : %s/%s (%d %s)",
176 remove_spaces(size_iec
), remove_spaces(size_dec
), previous_size
,
178 snprintf(statbuffer
, sizeof statbuffer
, "Size: %s/%s (%d %s)",
179 remove_spaces(size_iec
), remove_spaces(size_dec
), previous_size
,
181 add_item(buffer
, statbuffer
, OPT_INACTIVE
, NULL
, 0);
182 menu
[nb_sub_disk_menu
].items_count
++;
184 /* Do not print Host Bus & Interface if EDD isn't 3.0 or more */
185 if (d
[disk_number
].edd_version
>= 0x30) {
186 snprintf(buffer
, sizeof buffer
, "Host Bus/Interface: %s / %s",
187 remove_spaces((char *)d
[disk_number
].edd_params
.host_bus_type
),
188 d
[disk_number
].edd_params
.interface_type
);
189 snprintf(statbuffer
, sizeof statbuffer
, "Host Bus / Interface: %s / %s",
190 remove_spaces((char *)d
[disk_number
].edd_params
.host_bus_type
),
191 d
[disk_number
].edd_params
.interface_type
);
192 add_item(buffer
, statbuffer
, OPT_INACTIVE
, NULL
, 0);
193 menu
[nb_sub_disk_menu
].items_count
++;
196 snprintf(buffer
, sizeof buffer
, "C / H / S : %d / %d / %d",
197 d
[disk_number
].legacy_max_cylinder
+ 1,
198 d
[disk_number
].legacy_max_head
+ 1,
199 (int)d
[disk_number
].edd_params
.sectors
);
200 snprintf(statbuffer
, sizeof statbuffer
,
201 "Cylinders / Heads / Sectors: %d / %d / %d",
202 d
[disk_number
].legacy_max_cylinder
+ 1,
203 d
[disk_number
].legacy_max_head
+ 1,
204 (int)d
[disk_number
].edd_params
.sectors
);
205 add_item(buffer
, statbuffer
, OPT_INACTIVE
, NULL
, 0);
206 menu
[nb_sub_disk_menu
].items_count
++;
208 snprintf(buffer
, sizeof buffer
, "Sectors/Track : %d",
209 d
[disk_number
].legacy_sectors_per_track
);
210 snprintf(statbuffer
, sizeof statbuffer
, "Sectors per Track: %d",
211 d
[disk_number
].legacy_sectors_per_track
);
212 add_item(buffer
, statbuffer
, OPT_INACTIVE
, NULL
, 0);
213 menu
[nb_sub_disk_menu
].items_count
++;
215 get_mbr_string(hardware
->mbr_ids
[disk_number
], &mbr_name
, 50);
217 snprintf(buffer
, sizeof buffer
, "MBR : %s (0x%X)",
218 remove_spaces(mbr_name
), hardware
->mbr_ids
[disk_number
]);
219 snprintf(statbuffer
, sizeof statbuffer
, "MBR: %s (id 0x%X)",
220 remove_spaces(mbr_name
), hardware
->mbr_ids
[disk_number
]);
221 add_item(buffer
, statbuffer
, OPT_INACTIVE
, NULL
, 0);
222 menu
[nb_sub_disk_menu
].items_count
++;
226 parse_partition_table(&d
[disk_number
], &show_partition_information
);
227 if (!parse_partition_table(&d
[disk_number
], &compute_partition_information
)) {
228 get_error("parse_partition_table");
229 menu
[nb_sub_disk_menu
].items_count
++;
235 /* Compute the Disks menu */
236 void compute_disks(struct s_hdt_menu
*menu
, struct s_hardware
*hardware
)
238 char buffer
[MENULEN
+ 1];
239 int nb_sub_disk_menu
= 0;
241 /* No need to compute that menu if no disks were detected */
242 menu
->disk_menu
.items_count
= 0;
243 if (hardware
->disks_count
== 0)
246 for (int i
= 0; i
< hardware
->disks_count
; i
++) {
247 if (!hardware
->disk_info
[i
].cbios
)
248 continue; /* Invalid geometry */
250 ((struct s_my_menu
*)&(menu
->disk_sub_menu
), nb_sub_disk_menu
,
255 menu
->disk_menu
.menu
= add_menu(" Disks ", -1);
257 for (int i
= 0; i
< nb_sub_disk_menu
; i
++) {
258 snprintf(buffer
, sizeof buffer
, " Disk <%d> ", i
+ 1);
259 add_item(buffer
, "Disk", OPT_SUBMENU
, NULL
,
260 menu
->disk_sub_menu
[i
].menu
);
261 menu
->disk_menu
.items_count
++;
263 printf("MENU: Disks menu done (%d items)\n", menu
->disk_menu
.items_count
);