1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
/* ----------------------------------------------------------------------- *
*
* Copyright 2009 Pierre-Alexandre Meyer - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* -----------------------------------------------------------------------
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <disk/geom.h>
#include <disk/read.h>
#include <disk/error.h>
#include <disk/swsusp.h>
#include "hdt-cli.h"
#include "hdt-common.h"
#include "hdt-util.h"
static void process_br(struct driveinfo *drive_info, struct part_entry *ptab, int start, struct part_entry *ptab_root);
/**
* show_partition_information - print information about a partition
* @ptab: part_entry describing the partition
* @i: Partition number (UI purposes only)
* @ptab_root: part_entry describing the root partition (extended only)
* @drive_info: driveinfo struct describing the drive on which the partition
* is
*
* Note on offsets (from hpa, see chain.c32):
*
* To make things extra confusing: data partition offsets are relative to where
* the data partition record is stored, whereas extended partition offsets
* are relative to the beginning of the extended partition all the way back
* at the MBR... but still not absolute!
**/
static void show_partition_information(struct part_entry *ptab, int i,
struct part_entry *ptab_root,
struct driveinfo *drive_info)
{
char size[8];
char *parttype;
int error = 0;
char *error_buffer;
int start;
if (ptab_root)
start = ptab->start_lba + ptab_root->start_lba;
else
start = ptab->start_lba;
if (ptab->length > 0)
sectors_to_size(ptab->length, size);
else
memset(size, 0, sizeof size);
get_label(ptab->ostype, &parttype);
more_printf(" %d %s %8d %8d %s %02X %s",
i, (ptab->active_flag == 0x80) ? " x " : " ",
start,
start + ptab->length,
size,
ptab->ostype, parttype);
/* Extra info */
if (ptab->ostype == 0x82 && swsusp_check(drive_info, ptab, &error)) {
more_printf("%s", " (Swsusp sig. detected)");
} else if (error) {
get_error(error, &error_buffer);
more_printf("%s\n", error_buffer);
free(error_buffer);
}
more_printf("\n");
free(parttype);
}
/**
* process_ebr - print information for partitions contained in an ebr
* @drive_info: driveinfo struct describing the drive
* @ptab_root: part_entry struct describing the root partition (pointing to the ebr)
* @ebr_seen: Number of ebr processed (UI purposes only)
**/
static void process_ebr(struct driveinfo *drive_info, struct part_entry *ptab_root,
int ebr_seen)
{
int error;
char *error_buffer;
/* The ebr is located at the first sector of the extended partition */
char* ebr = read_sectors(drive_info, ptab_root->start_lba, 1, &error);
if (!ebr) {
more_printf("Unable to read the ebr:\n");
get_error(error, &error_buffer);
more_printf("%s\n", error_buffer);
free(error_buffer);
return;
}
struct part_entry *ptab_child = (struct part_entry *)(ebr + PARTITION_TABLES_OFFSET);
return process_br(drive_info, ptab_child, ebr_seen, ptab_root);
}
/**
* process_br - print information for partitions contained in an {m,e}br
* @drive_info: driveinfo struct describing the drive
* @ptab_root: part_entry struct describing the root partition
* (pointing to the {m,e}br)
* @ebr_seen: Number of ebr processed (UI purposes only)
**/
static void process_br(struct driveinfo *drive_info, struct part_entry *ptab,
int ebr_seen, struct part_entry *ptab_root)
{
for (int i = 0; i < 4; i++) {
if (ptab[i].ostype) {
show_partition_information(&ptab[i],
ebr_seen * 4 + i + 1,
ptab_root,
drive_info);
/* 3 types for extended partitions */
if ( ptab[i].ostype == 0x05 ||
ptab[i].ostype == 0x0f ||
ptab[i].ostype == 0x85)
process_ebr(drive_info, &ptab[i], ebr_seen + 1);
}
}
}
void main_show_disk(int argc __unused, char **argv __unused,
struct s_hardware *hardware)
{
int i = -1;
int error;
char *error_buffer;
detect_disks(hardware);
for (int drive = 0x80; drive < 0xff; drive++) {
i++;
if (!hardware->disk_info[i].cbios)
continue; /* Invalid geometry */
struct driveinfo *d = &hardware->disk_info[i];
more_printf("DISK 0x%X:\n", d->disk);
more_printf(" C/H/S: %d heads, %d cylinders\n",
d->legacy_max_head + 1, d->legacy_max_cylinder + 1);
more_printf(" %d sectors/track, %d drives\n",
d->legacy_sectors_per_track, d->legacy_max_drive);
more_printf(" EDD: ebios=%d, EDD version: %X\n",
d->ebios, d->edd_version);
more_printf(" %d heads, %d cylinders\n",
(int) d->edd_params.heads, (int) d->edd_params.cylinders);
more_printf(" %d sectors, %d bytes/sector, %d sectors/track\n",
(int) d->edd_params.sectors, (int) d->edd_params.bytes_per_sector,
(int) d->edd_params.sectors_per_track);
more_printf(" Host bus: %s, Interface type: %s\n\n",
d->edd_params.host_bus_type, d->edd_params.interface_type);
char *mbr = read_mbr(d->disk, &error);
if (!mbr) {
more_printf("Unable to read the mbr.");
get_error(error, &error_buffer);
more_printf("%s\n", error_buffer);
free(error_buffer);
continue;
}
more_printf(" # Boot Start End Size Id Type\n");
struct part_entry *ptab = (struct part_entry *)(mbr + PARTITION_TABLES_OFFSET);
process_br(d, ptab, 0, NULL);
}
}
struct cli_module_descr disk_show_modules = {
.modules = NULL,
.default_callback = main_show_disk,
};
struct cli_mode_descr disk_mode = {
.mode = DISK_MODE,
.name = CLI_DISK,
.default_modules = NULL,
.show_modules = &disk_show_modules,
.set_modules = NULL,
};
|