summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Alexandre Meyer <pierre@mouraf.org>2009-04-27 06:24:50 (GMT)
committerPierre-Alexandre Meyer <pierre@mouraf.org>2009-04-27 06:24:50 (GMT)
commit81910f64ece4b1ca9e7e1ff276d673ef2321b1ea (patch)
tree1f06f71597cc3f7d60388215f569f94c9d3d19a6
parent6240ecadc145ce1a7b9955e0de08d5faeedc45e5 (diff)
downloadhdt-81910f64ece4b1ca9e7e1ff276d673ef2321b1ea.zip
hdt-81910f64ece4b1ca9e7e1ff276d673ef2321b1ea.tar.gz
hdt-81910f64ece4b1ca9e7e1ff276d673ef2321b1ea.tar.bz2
hdt-81910f64ece4b1ca9e7e1ff276d673ef2321b1ea.tar.xz
hdt: Add disk callbacks (CLI)
In the hdt mode, `show disk' outputs a summary for all disks (C/H/S, EDD (version, size) and host/interface). In the disk mode, `show' outputs the same as above, `show disks' a full description for all disks (with partitions) and `show disk 0x80' detailed information for one disk only (0x80 in that example). Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
-rw-r--r--com32/hdt/hdt-cli-disk.c114
-rw-r--r--com32/hdt/hdt-cli-hdt.c2
-rw-r--r--com32/hdt/hdt-cli.h2
3 files changed, 94 insertions, 24 deletions
diff --git a/com32/hdt/hdt-cli-disk.c b/com32/hdt/hdt-cli-disk.c
index 506efba..3209c8b 100644
--- a/com32/hdt/hdt-cli-disk.c
+++ b/com32/hdt/hdt-cli-disk.c
@@ -100,12 +100,82 @@ static void show_partition_information(struct driveinfo *drive_info,
free(parttype);
}
-void main_show_disk(int argc __unused, char **argv __unused,
+void main_show_disk(int argc, char **argv,
struct s_hardware *hardware)
{
- int i = -1;
+ reset_more_printf();
+ if (!argc) {
+ more_printf("Which disk?\n");
+ return;
+ }
+
+ int drive = strtol(argv[0], (char**) NULL, 16);
+
+ if (drive < 0x80 || drive >= 0xff) {
+ more_printf("Invalid disk: %d.\n", drive);
+ return;
+ }
+
+ int i = drive - 0x80;
+ struct driveinfo *d = &hardware->disk_info[i];
int error;
char *error_buffer;
+ char disk_size[8];
+
+ detect_disks(hardware);
+ if (!hardware->disk_info[i].cbios)
+ return; /* Invalid geometry */
+
+ if ((int) d->edd_params.sectors > 0)
+ sectors_to_size((int) d->edd_params.sectors, disk_size);
+ else
+ memset(disk_size, 0, sizeof disk_size);
+
+ more_printf("DISK 0x%X:\n", d->disk);
+ more_printf(" C/H/S: %d cylinders, %d heads, %d sectors/track\n",
+ d->legacy_max_cylinder + 1, d->legacy_max_head + 1,
+ d->legacy_sectors_per_track);
+ more_printf(" EDD: Version: %X\n", d->edd_version);
+ more_printf(" Size: %s, %d bytes/sector, %d sectors/track\n",
+ disk_size,
+ (int) d->edd_params.bytes_per_sector,
+ (int) d->edd_params.sectors_per_track);
+ more_printf(" Host bus: %s, Interface type: %s\n\n",
+ remove_spaces(d->edd_params.host_bus_type),
+ remove_spaces(d->edd_params.interface_type));
+
+ more_printf(" # B Start End Size Id Type\n");
+ error = 0;
+ if (parse_partition_table(d, &show_partition_information, &error)) {
+ if (error) {
+ more_printf("I/O error: ");
+ get_error(error, &error_buffer);
+ more_printf("%s\n", error_buffer);
+ free(error_buffer);
+ } else
+ more_printf("An unknown error occured.\n");
+ return;
+ }
+}
+
+void main_show_disks(int argc __unused, char **argv __unused,
+ struct s_hardware *hardware)
+{
+ reset_more_printf();
+ detect_disks(hardware);
+
+ for (int drive = 0x80; drive < 0xff; drive++) {
+ char buf[5] = "";
+ sprintf(buf, "0x%x", drive);
+ char *argv[1] = { buf };
+ main_show_disk(1, argv, hardware);
+ }
+}
+
+void disks_summary(int argc __unused, char** argv __unused,
+ struct s_hardware *hardware)
+{
+ int i = -1;
detect_disks(hardware);
@@ -125,33 +195,33 @@ void main_show_disk(int argc __unused, char **argv __unused,
more_printf(" C/H/S: %d cylinders, %d heads, %d sectors/track\n",
d->legacy_max_cylinder + 1, d->legacy_max_head + 1,
d->legacy_sectors_per_track);
- more_printf(" EDD: Version: %X\n", d->edd_version);
- more_printf(" Size: %s, %d bytes/sector, %d sectors/track\n",
- disk_size,
- (int) d->edd_params.bytes_per_sector,
- (int) d->edd_params.sectors_per_track);
+ more_printf(" EDD: Version: %X, size: %s\n", d->edd_version,
+ disk_size);
more_printf(" Host bus: %s, Interface type: %s\n\n",
remove_spaces(d->edd_params.host_bus_type),
remove_spaces(d->edd_params.interface_type));
-
- more_printf(" # B Start End Size Id Type\n");
- error = 0;
- if (parse_partition_table(d, &show_partition_information, &error)) {
- if (error) {
- more_printf("I/O error: ");
- get_error(error, &error_buffer);
- more_printf("%s\n", error_buffer);
- free(error_buffer);
- } else
- more_printf("An unknown error occured.\n");
- continue;
- }
}
}
+struct cli_callback_descr list_disk_show_modules[] = {
+ {
+ .name = "disks",
+ .exec = main_show_disks,
+ },
+ {
+ .name = "disk",
+ .exec = main_show_disk,
+ },
+ {
+ .name = NULL,
+ .exec = NULL,
+ },
+};
+
+
struct cli_module_descr disk_show_modules = {
- .modules = NULL,
- .default_callback = main_show_disk,
+ .modules = list_disk_show_modules,
+ .default_callback = disks_summary,
};
struct cli_mode_descr disk_mode = {
diff --git a/com32/hdt/hdt-cli-hdt.c b/com32/hdt/hdt-cli-hdt.c
index 76785a7..df86e69 100644
--- a/com32/hdt/hdt-cli-hdt.c
+++ b/com32/hdt/hdt-cli-hdt.c
@@ -286,7 +286,7 @@ struct cli_callback_descr list_hdt_show_modules[] = {
},
{
.name = CLI_DISK,
- .exec = main_show_disk,
+ .exec = disks_summary,
},
{
.name = CLI_PXE,
diff --git a/com32/hdt/hdt-cli.h b/com32/hdt/hdt-cli.h
index 9a8e15d..73e7450 100644
--- a/com32/hdt/hdt-cli.h
+++ b/com32/hdt/hdt-cli.h
@@ -177,7 +177,7 @@ void cli_detect_pci(struct s_hardware *hardware);
void main_show_cpu(int argc, char **argv, struct s_hardware *hardware);
// DISK STUFF
-void main_show_disk(int argc, char **argv, struct s_hardware *hardware);
+void disks_summary(int argc, char **argv, struct s_hardware *hardware);
// PXE STUFF
void main_show_pxe(int argc, char **argv, struct s_hardware *hardware);