1 /* ----------------------------------------------------------------------- *
3 * Copyright 2011 Erwan Velu - All Rights Reserved
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following
14 * The above copyright notice and this permission notice shall
15 * be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
26 * -----------------------------------------------------------------------
29 #include "hdt-common.h"
33 ZZJSON_CONFIG
*config
;
36 static void show_partition_information(struct driveinfo
*drive_info
,
37 struct part_entry
*ptab
,
39 int nb_partitions_seen
) {
41 char bootloader_name
[9] = {0};
44 unsigned int start
, end
;
45 char bootable
[6] = {0};
47 int i
= nb_partitions_seen
;
48 start
= partition_offset
;
49 end
= start
+ ptab
->length
- 1;
52 sectors_to_size(ptab
->length
, size
);
54 get_label(ptab
->ostype
, &parttype
);
55 get_bootloader_string(drive_info
, ptab
, bootloader_name
, 9);
56 if (ptab
->active_flag
== 0x80)
57 snprintf(bootable
,sizeof(bootable
),"%s","true");
59 snprintf(bootable
,sizeof(bootable
),"%s","false");
61 snprintf(ostype
,sizeof(ostype
),"%02X",ptab
->ostype
);
64 add_ai("partition->number",i
)
65 add_ai("partition->sector_start",start
)
66 add_ai("partition->sector_end",end
)
67 add_as("partition->size",size
)
68 add_as("partition->type",parttype
)
69 add_as("partition->os_type",ostype
)
70 add_as("partition->boot_flag",bootable
)
77 void show_disk(struct s_hardware
*hardware
, ZZJSON_CONFIG
*conf
, ZZJSON
**it
, int drive
) {
81 struct driveinfo
*d
= &hardware
->disk_info
[i
];
82 char mbr_name
[50]={0};
83 char disk_size
[11]={0};
85 get_mbr_string(hardware
->mbr_ids
[i
], &mbr_name
,sizeof(mbr_name
));
86 if ((int)d
->edd_params
.sectors
> 0)
87 sectors_to_size((int)d
->edd_params
.sectors
, disk_size
);
90 char edd_version
[5]={0};
91 snprintf(disk
,sizeof(disk
),"0x%X",d
->disk
);
92 snprintf(edd_version
,sizeof(edd_version
),"%X",d
->edd_version
);
93 zzjson_print(config
, *item
);
94 zzjson_free(config
, *item
);
97 add_as("disk->number",disk
)
98 add_ai("disk->cylinders",d
->legacy_max_cylinder
+1)
99 add_ai("disk->heads",d
->legacy_max_head
+1)
100 add_ai("disk->sectors_per_track",d
->legacy_sectors_per_track
)
101 add_as("disk->edd_version",edd_version
)
102 add_as("disk->size",disk_size
)
103 add_ai("disk->bytes_per_sector",(int)d
->edd_params
.bytes_per_sector
)
104 add_ai("disk->sectors_per_track",(int)d
->edd_params
.sectors_per_track
)
105 add_as("disk->host_bus",remove_spaces((char *)d
->edd_params
.host_bus_type
))
106 add_as("disk->interface_type",remove_spaces((char *)d
->edd_params
.interface_type
))
107 add_as("disk->mbr_name",mbr_name
)
108 add_ai("disk->mbr_id",hardware
->mbr_ids
[i
])
111 if (parse_partition_table(d
, &show_partition_information
)) {
114 add_as("disk->error", "IO Error")
118 add_as("disk->error", "Unrecognized Partition Layout")
124 void dump_disks(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
127 if (hardware
->disks_count
> 0)
128 for (int drive
= 0x80; drive
< 0xff; drive
++) {
129 if (hardware
->disk_info
[drive
- 0x80].cbios
) {
132 add_b("disks->is_valid",true);
135 show_disk(hardware
, config
, item
, drive
);
141 add_b("disks->is_valid",false);