From 4654721af3253ac3e33d8563d7057aafca29ed8b Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Thu, 24 Mar 2011 23:00:35 +0100 Subject: hdt: Initial work for dumping disks More work is necessary to export partition' configuration --- com32/hdt/hdt-dump-disks.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 com32/hdt/hdt-dump-disks.c (limited to 'com32/hdt/hdt-dump-disks.c') diff --git a/com32/hdt/hdt-dump-disks.c b/com32/hdt/hdt-dump-disks.c new file mode 100644 index 00000000..ad729b28 --- /dev/null +++ b/com32/hdt/hdt-dump-disks.c @@ -0,0 +1,84 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2011 Erwan Velu - 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 "hdt-common.h" +#include "hdt-dump.h" +#include "hdt-util.h" + +void show_disk(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item, int drive) { + int i = drive - 0x80; + struct driveinfo *d = &hardware->disk_info[i]; + char mbr_name[50]={0}; + char disk_size[11]={0}; + + get_mbr_string(hardware->mbr_ids[i], &mbr_name,sizeof(mbr_name)); + if ((int)d->edd_params.sectors > 0) + sectors_to_size((int)d->edd_params.sectors, disk_size); + + char disk[5]={0}; + char edd_version[5]={0}; + snprintf(disk,sizeof(disk),"0x%X",d->disk); + snprintf(edd_version,sizeof(edd_version),"%X",d->edd_version); + zzjson_print(config, *item); + zzjson_free(config, *item); + + *item = zzjson_create_object(config, NULL); /* empty object */ + add_s("disk->number", disk); + add_i("disk->cylinders",d->legacy_max_cylinder + 1); + add_i("disk->heads",d->legacy_max_head + 1); + add_i("disk->sectors_per_track",d->legacy_sectors_per_track); + add_s("disk->edd_version",edd_version); + add_s("disk->size",disk_size); + add_i("disk->bytes_per_sector",(int)d->edd_params.bytes_per_sector); + add_i("disk->sectors_per_track",(int)d->edd_params.sectors_per_track); + add_s("disk->host_bus",remove_spaces((char *)d->edd_params.host_bus_type)); + add_s("disk->interface_type",remove_spaces((char *)d->edd_params.interface_type)); + add_s("disk->mbr_name",mbr_name); + add_i("disk->mbr_id",hardware->mbr_ids[i]); + +} + +void dump_disks(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + bool found=false; + for (int drive = 0x80; drive < 0xff; drive++) { + if (hardware->disk_info[drive - 0x80].cbios) { + if (found==false) { + *item = zzjson_create_object(config, NULL); /* empty object */ + add_b("disks->is_valid",true); + found=true; + } + show_disk(hardware, config, item, drive); + } + } + + if (found==false) { + *item = zzjson_create_object(config, NULL); /* empty object */ + add_b("disks->is_valid",false); + } + flush("disks",config,item); +} -- cgit v1.2.1 From 3fd82f86c1484f61d91669a3e9b407ff4de50918 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Fri, 25 Mar 2011 22:36:28 +0100 Subject: hdt: Dumping disks partitions --- com32/hdt/hdt-dump-disks.c | 83 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 14 deletions(-) (limited to 'com32/hdt/hdt-dump-disks.c') diff --git a/com32/hdt/hdt-dump-disks.c b/com32/hdt/hdt-dump-disks.c index ad729b28..a8e856ff 100644 --- a/com32/hdt/hdt-dump-disks.c +++ b/com32/hdt/hdt-dump-disks.c @@ -30,7 +30,50 @@ #include "hdt-dump.h" #include "hdt-util.h" -void show_disk(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item, int drive) { +ZZJSON_CONFIG *config; +ZZJSON **item; + +static void show_partition_information(struct driveinfo *drive_info, + struct part_entry *ptab, + int partition_offset, + int nb_partitions_seen) { + char size[11] = {0}; + char bootloader_name[9] = {0}; + char ostype[64]={0}; + char *parttype; + unsigned int start, end; + bool bootable = false; + + int i = nb_partitions_seen; + start = partition_offset; + end = start + ptab->length - 1; + + if (ptab->length > 0) + sectors_to_size(ptab->length, size); + + get_label(ptab->ostype, &parttype); + get_bootloader_string(drive_info, ptab, bootloader_name, 9); + if (ptab->active_flag == 0x80) + bootable=true; + + snprintf(ostype,sizeof(ostype),"%02X",ptab->ostype); + + APPEND_ARRAY + add_ai("partition->number",i) + add_ai("partition->sector_start",start) + add_ai("partition->sector_end",end) + add_as("partition->size",size) + add_as("partition->type",parttype) + add_as("partition->os_type",ostype) + END_OF_APPEND; + free(parttype); +} + + + +void show_disk(struct s_hardware *hardware, ZZJSON_CONFIG *conf, ZZJSON **it, int drive) { + config=conf; + item=it; int i = drive - 0x80; struct driveinfo *d = &hardware->disk_info[i]; char mbr_name[50]={0}; @@ -47,20 +90,32 @@ void show_disk(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item zzjson_print(config, *item); zzjson_free(config, *item); - *item = zzjson_create_object(config, NULL); /* empty object */ - add_s("disk->number", disk); - add_i("disk->cylinders",d->legacy_max_cylinder + 1); - add_i("disk->heads",d->legacy_max_head + 1); - add_i("disk->sectors_per_track",d->legacy_sectors_per_track); - add_s("disk->edd_version",edd_version); - add_s("disk->size",disk_size); - add_i("disk->bytes_per_sector",(int)d->edd_params.bytes_per_sector); - add_i("disk->sectors_per_track",(int)d->edd_params.sectors_per_track); - add_s("disk->host_bus",remove_spaces((char *)d->edd_params.host_bus_type)); - add_s("disk->interface_type",remove_spaces((char *)d->edd_params.interface_type)); - add_s("disk->mbr_name",mbr_name); - add_i("disk->mbr_id",hardware->mbr_ids[i]); + CREATE_ARRAY + add_as("disk->number",disk) + add_ai("disk->cylinders",d->legacy_max_cylinder +1) + add_ai("disk->heads",d->legacy_max_head +1) + add_ai("disk->sectors_per_track",d->legacy_sectors_per_track) + add_as("disk->edd_version",edd_version) + add_as("disk->size",disk_size) + add_ai("disk->bytes_per_sector",(int)d->edd_params.bytes_per_sector) + add_ai("disk->sectors_per_track",(int)d->edd_params.sectors_per_track) + add_as("disk->host_bus",remove_spaces((char *)d->edd_params.host_bus_type)) + add_as("disk->interface_type",remove_spaces((char *)d->edd_params.interface_type)) + add_as("disk->mbr_name",mbr_name) + add_ai("disk->mbr_id",hardware->mbr_ids[i]) + END_OF_ARRAY; + if (parse_partition_table(d, &show_partition_information)) { + if (errno_disk) { + APPEND_ARRAY + add_as("disk->error", "IO Error") + END_OF_APPEND; + } else { + APPEND_ARRAY + add_as("disk->error", "Unrecognized Partition Layout") + END_OF_APPEND; + } + } } void dump_disks(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { -- cgit v1.2.1 From b0ca086f7b98cdb92355c7adfddd3d976b7c94fc Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Sun, 3 Apr 2011 20:59:34 +0200 Subject: hdt: Making dumping code easier to use A set of CREATE_NEW_OBJECT / FLUSH is enough for a simple dump. --- com32/hdt/hdt-dump-disks.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'com32/hdt/hdt-dump-disks.c') diff --git a/com32/hdt/hdt-dump-disks.c b/com32/hdt/hdt-dump-disks.c index a8e856ff..ed2aea36 100644 --- a/com32/hdt/hdt-dump-disks.c +++ b/com32/hdt/hdt-dump-disks.c @@ -123,7 +123,7 @@ void dump_disks(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **ite for (int drive = 0x80; drive < 0xff; drive++) { if (hardware->disk_info[drive - 0x80].cbios) { if (found==false) { - *item = zzjson_create_object(config, NULL); /* empty object */ + CREATE_NEW_OBJECT; add_b("disks->is_valid",true); found=true; } @@ -132,8 +132,9 @@ void dump_disks(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **ite } if (found==false) { - *item = zzjson_create_object(config, NULL); /* empty object */ + CREATE_NEW_OBJECT; add_b("disks->is_valid",false); + FLUSH_OBJECT; } - flush("disks",config,item); + to_cpio("disks"); } -- cgit v1.2.1 From 842d7e35ccd8cd89105faf0266497e838d96c8b3 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 25 Apr 2011 17:00:22 -0700 Subject: hdt: remove set-but-unused variable Remove a set but unused variable in HDT, which prevents building with gcc 4.6. This is probably a bug; presumably the active flag should be presented to the user, too. Signed-off-by: H. Peter Anvin --- com32/hdt/hdt-dump-disks.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'com32/hdt/hdt-dump-disks.c') diff --git a/com32/hdt/hdt-dump-disks.c b/com32/hdt/hdt-dump-disks.c index ed2aea36..dcbcaa9e 100644 --- a/com32/hdt/hdt-dump-disks.c +++ b/com32/hdt/hdt-dump-disks.c @@ -42,7 +42,6 @@ static void show_partition_information(struct driveinfo *drive_info, char ostype[64]={0}; char *parttype; unsigned int start, end; - bool bootable = false; int i = nb_partitions_seen; start = partition_offset; @@ -53,8 +52,6 @@ static void show_partition_information(struct driveinfo *drive_info, get_label(ptab->ostype, &parttype); get_bootloader_string(drive_info, ptab, bootloader_name, 9); - if (ptab->active_flag == 0x80) - bootable=true; snprintf(ostype,sizeof(ostype),"%02X",ptab->ostype); -- cgit v1.2.1 From b7291d4a98bafb4ac3f1a2ff7df37037f91ad04e Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Tue, 26 Apr 2011 19:32:01 +0200 Subject: Revert "hdt: remove set-but-unused variable" This reverts commit 842d7e35ccd8cd89105faf0266497e838d96c8b3. In fact, you found a real bug. I missed at dumping some information. So I revert this commit and then add the missing code. --- com32/hdt/hdt-dump-disks.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'com32/hdt/hdt-dump-disks.c') diff --git a/com32/hdt/hdt-dump-disks.c b/com32/hdt/hdt-dump-disks.c index dcbcaa9e..ed2aea36 100644 --- a/com32/hdt/hdt-dump-disks.c +++ b/com32/hdt/hdt-dump-disks.c @@ -42,6 +42,7 @@ static void show_partition_information(struct driveinfo *drive_info, char ostype[64]={0}; char *parttype; unsigned int start, end; + bool bootable = false; int i = nb_partitions_seen; start = partition_offset; @@ -52,6 +53,8 @@ static void show_partition_information(struct driveinfo *drive_info, get_label(ptab->ostype, &parttype); get_bootloader_string(drive_info, ptab, bootloader_name, 9); + if (ptab->active_flag == 0x80) + bootable=true; snprintf(ostype,sizeof(ostype),"%02X",ptab->ostype); -- cgit v1.2.1 From d2403b39ce86b8a98ec144d74c566fc05fce2d53 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Tue, 26 Apr 2011 19:39:49 +0200 Subject: hdt: dumping boot flag status If the boot flag is set on a partition, let's dump this information. --- com32/hdt/hdt-dump-disks.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'com32/hdt/hdt-dump-disks.c') diff --git a/com32/hdt/hdt-dump-disks.c b/com32/hdt/hdt-dump-disks.c index ed2aea36..d851bf87 100644 --- a/com32/hdt/hdt-dump-disks.c +++ b/com32/hdt/hdt-dump-disks.c @@ -42,7 +42,7 @@ static void show_partition_information(struct driveinfo *drive_info, char ostype[64]={0}; char *parttype; unsigned int start, end; - bool bootable = false; + char bootable[5] = {0}; int i = nb_partitions_seen; start = partition_offset; @@ -54,7 +54,9 @@ static void show_partition_information(struct driveinfo *drive_info, get_label(ptab->ostype, &parttype); get_bootloader_string(drive_info, ptab, bootloader_name, 9); if (ptab->active_flag == 0x80) - bootable=true; + snprintf(bootable,sizeof(bootable),"%s","true"); + else + snprintf(bootable,sizeof(bootable),"%s","false"); snprintf(ostype,sizeof(ostype),"%02X",ptab->ostype); @@ -65,6 +67,7 @@ static void show_partition_information(struct driveinfo *drive_info, add_as("partition->size",size) add_as("partition->type",parttype) add_as("partition->os_type",ostype) + add_as("partition->boot_flag",bootable) END_OF_APPEND; free(parttype); } -- cgit v1.2.1 From 2d754907b6e824088b74a156b0dc2017323a2013 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Mon, 11 Jul 2011 22:10:34 +0200 Subject: hdt: Fixing array size Bootable flags shall be 6 char to let one NULL terminating char. Thx Gerth for reporting this. --- com32/hdt/hdt-dump-disks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'com32/hdt/hdt-dump-disks.c') diff --git a/com32/hdt/hdt-dump-disks.c b/com32/hdt/hdt-dump-disks.c index d851bf87..ef8cf220 100644 --- a/com32/hdt/hdt-dump-disks.c +++ b/com32/hdt/hdt-dump-disks.c @@ -42,7 +42,7 @@ static void show_partition_information(struct driveinfo *drive_info, char ostype[64]={0}; char *parttype; unsigned int start, end; - char bootable[5] = {0}; + char bootable[6] = {0}; int i = nb_partitions_seen; start = partition_offset; -- cgit v1.2.1 From 51431d2c9992a99f58378056523256757edb0fb3 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Wed, 21 Sep 2011 21:44:47 +0200 Subject: hdt: Dumping disk failed when disk are present When physical disks were present, the computed items were not flushed and so not present on the disk file. Thanks to pscheie for reporting this. --- com32/hdt/hdt-dump-disks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'com32/hdt/hdt-dump-disks.c') diff --git a/com32/hdt/hdt-dump-disks.c b/com32/hdt/hdt-dump-disks.c index ef8cf220..bde04d2a 100644 --- a/com32/hdt/hdt-dump-disks.c +++ b/com32/hdt/hdt-dump-disks.c @@ -137,7 +137,7 @@ void dump_disks(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **ite if (found==false) { CREATE_NEW_OBJECT; add_b("disks->is_valid",false); - FLUSH_OBJECT; } + FLUSH_OBJECT; to_cpio("disks"); } -- cgit v1.2.1 From 6e5e4d01cefda41da506c0c184f54e78796b37d1 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Thu, 22 Sep 2011 20:52:49 +0200 Subject: hdt: Don't search HDDs when no HDD got detected --- com32/hdt/hdt-dump-disks.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'com32/hdt/hdt-dump-disks.c') diff --git a/com32/hdt/hdt-dump-disks.c b/com32/hdt/hdt-dump-disks.c index bde04d2a..ff744b30 100644 --- a/com32/hdt/hdt-dump-disks.c +++ b/com32/hdt/hdt-dump-disks.c @@ -123,7 +123,9 @@ void show_disk(struct s_hardware *hardware, ZZJSON_CONFIG *conf, ZZJSON **it, in void dump_disks(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { bool found=false; - for (int drive = 0x80; drive < 0xff; drive++) { + + if (hardware->disks_count > 0) + for (int drive = 0x80; drive < 0xff; drive++) { if (hardware->disk_info[drive - 0x80].cbios) { if (found==false) { CREATE_NEW_OBJECT; -- cgit v1.2.1