aboutsummaryrefslogtreecommitdiffstats
path: root/com32/hdt/hdt-cli-disk.c
diff options
context:
space:
mode:
authorPierre-Alexandre Meyer <pierre@mouraf.org>2009-04-20 17:19:26 -0700
committerPierre-Alexandre Meyer <pierre@mouraf.org>2009-04-20 17:19:26 -0700
commitc2853e856c694259d0e93509db6d99d6bd0bfc8f (patch)
treee1bdd97007832a9028100f7e2e6824e40597da9b /com32/hdt/hdt-cli-disk.c
parentf5e4aea6089b93a52e4cee1bdca33d27721b11e9 (diff)
downloadhdt-c2853e856c694259d0e93509db6d99d6bd0bfc8f.tar.gz
hdt-c2853e856c694259d0e93509db6d99d6bd0bfc8f.tar.xz
hdt-c2853e856c694259d0e93509db6d99d6bd0bfc8f.zip
hdt: Process extended partitions (CLI)
Print information about extended partitions in the CLI. Note: the offsets reported are the offsets found in the EBR. We may want to adjust it with the offset in the MBR. Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Diffstat (limited to 'com32/hdt/hdt-cli-disk.c')
-rw-r--r--com32/hdt/hdt-cli-disk.c82
1 files changed, 70 insertions, 12 deletions
diff --git a/com32/hdt/hdt-cli-disk.c b/com32/hdt/hdt-cli-disk.c
index 01db50ba..c71ea510 100644
--- a/com32/hdt/hdt-cli-disk.c
+++ b/com32/hdt/hdt-cli-disk.c
@@ -38,6 +38,75 @@
#include "hdt-cli.h"
#include "hdt-common.h"
+static void process_br(struct driveinfo *drive_info, struct part_entry *ptab, int start);
+
+/**
+ * show_partition_information - print information about a partition
+ * @ptab: part_entry describing the partition
+ * @i: Partition number (UI purposes only)
+ *
+ * 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)
+{
+ char *parttype;
+ get_label(ptab->ostype, &parttype);
+ more_printf(" %d %s %8d %8d %8d %02X %s\n",
+ i, (ptab->active_flag == 0x80) ? " x " : " ",
+ ptab->start_lba,
+ ptab->start_lba + ptab->length, ptab->length,
+ ptab->ostype, parttype);
+ 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)
+{
+ /* The ebr is located at the first sector of the extended partition */
+ char* ebr = read_sectors(drive_info, ptab_root->start_lba, 1);
+ if (!ebr) {
+ more_printf("Unable to read the ebr.");
+ return;
+ }
+
+ struct part_entry *ptab_child = (struct part_entry *)(ebr + PARTITION_TABLES_OFFSET);
+ return process_br(drive_info, ptab_child, ebr_seen);
+}
+
+/**
+ * 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)
+{
+ for (int i = 0; i < 4; i++) {
+ if (ptab[i].ostype) {
+ show_partition_information(&ptab[i], ebr_seen * 4 + i + 1);
+
+ /* 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)
{
@@ -74,18 +143,7 @@ void main_show_disk(int argc __unused, char **argv __unused,
more_printf(" # Boot Start End Blocks Id Type\n");
struct part_entry *ptab = (struct part_entry *)(mbr + PARTITION_TABLES_OFFSET);
- for (int i = 0; i < 4; i++) {
- char *parttype;
- if (ptab[i].ostype) {
- get_label(ptab[i].ostype, &parttype);
- more_printf(" %d %s %8d %8d %8d %02X %s\n",
- i, (ptab[i].active_flag == 0x80) ? " x " : " ",
- ptab[i].start_lba,
- ptab[i].start_lba + ptab[i].length, ptab[i].length,
- ptab[i].ostype, parttype);
- free(parttype);
- }
- }
+ process_br(d, ptab, 0);
}
}