aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErwan Velu <erwanaliasr1@gmail.com>2011-03-25 22:36:28 +0100
committerErwan Velu <erwanaliasr1@gmail.com>2011-03-25 22:36:28 +0100
commit3fd82f86c1484f61d91669a3e9b407ff4de50918 (patch)
treeeb998e9ca86205e7e277d01f02f9b69237040f3a
parent4654721af3253ac3e33d8563d7057aafca29ed8b (diff)
downloadsyslinux-3fd82f86c1484f61d91669a3e9b407ff4de50918.tar.gz
syslinux-3fd82f86c1484f61d91669a3e9b407ff4de50918.tar.xz
syslinux-3fd82f86c1484f61d91669a3e9b407ff4de50918.zip
hdt: Dumping disks partitions
-rw-r--r--com32/hdt/hdt-dump-disks.c83
-rw-r--r--com32/hdt/hdt-dump.h10
2 files changed, 75 insertions, 18 deletions
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) {
diff --git a/com32/hdt/hdt-dump.h b/com32/hdt/hdt-dump.h
index c8eeaebd..577edba5 100644
--- a/com32/hdt/hdt-dump.h
+++ b/com32/hdt/hdt-dump.h
@@ -34,12 +34,14 @@
#include <zzjson/zzjson.h>
#include "hdt-common.h"
-#define ADD_I(value) zzjson_create_number_i(config,value)
-#define ADD_S(value) zzjson_create_string(config,value)
-#define add_ai(name,value) *item = zzjson_array_append(config, *item, zzjson_object_append(config, *item, name, zzjson_create_number_i(config, value)))
+#define APPEND_ARRAY ZZJSON *temp_array; temp_array = zzjson_array_append(config, *item, zzjson_create_object(config,
+#define CREATE_ARRAY *item = zzjson_create_array(config, zzjson_create_object(config,
+#define add_ai(name,value) name,zzjson_create_number_i(config,value),
+#define add_as(name,value) name,zzjson_create_string(config,value),
+#define END_OF_ARRAY NULL),NULL)
+#define END_OF_APPEND NULL)); *item=temp_array;
#define add_i(name,value) *item = zzjson_object_append(config, *item, name, zzjson_create_number_i(config, value))
#define add_s(name,value) *item = zzjson_object_append(config, *item, name, zzjson_create_string(config, value))
-#define add_as(name,value) *item = zzjson_array_append(config, *item, zzjson_object_append(config, *item, name, zzjson_create_string(config, value)))
#define add_bool_true(name) *item = zzjson_object_append(config, *item, (char *)name, zzjson_create_true(config))
#define add_bool_false(name) *item = zzjson_object_append(config, *item, (char*)name, zzjson_create_false(config))
#define add_hi(value) add_i(#value,hardware->value)