Skip to content

Commit f3559f1

Browse files
committed
show boot info table information
1 parent f26d18b commit f3559f1

File tree

6 files changed

+105
-13
lines changed

6 files changed

+105
-13
lines changed

disk.h

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ typedef struct {
1616
uint64_t size_in_bytes;
1717
unsigned chunk_size;
1818
unsigned block_size;
19+
unsigned grub_used:1;
20+
unsigned isolinux_used:1;
1921
disk_data_t *data;
2022
json_object *json_disk;
2123
json_object *json_current;

eltorito.c

+73-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
// set to 0 or 2
1919
#define BLK_FIX 2
2020

21+
static void dump_bootinfo(disk_t *disk, uint64_t sector);
22+
2123
void dump_eltorito(disk_t *disk)
2224
{
2325
int i, j;
@@ -132,7 +134,7 @@ void dump_eltorito(disk_t *disk)
132134
le16toh(el->entry.size),
133135
BLK_FIX ? "" : "/4"
134136
);
135-
if((s = iso_block_to_name(disk, le32toh(el->entry.start) << 2))) {
137+
if((s = iso_block_to_name(disk, le32toh(el->entry.start) << 2, NULL))) {
136138
json_object_object_add(json_entry, "file_name", json_object_new_string(s));
137139
log_info(", \"%s\"", s);
138140
}
@@ -143,6 +145,7 @@ void dump_eltorito(disk_t *disk)
143145
disk->json_current = json_entry;
144146
unsigned old_block_size = disk->block_size;
145147
disk->block_size = 512;
148+
dump_bootinfo(disk, le32toh(el->entry.start) << BLK_FIX);
146149
dump_fs(disk, 7, le32toh(el->entry.start) << BLK_FIX);
147150
disk->block_size = old_block_size;
148151
disk->json_current = disk->json_disk;
@@ -174,6 +177,74 @@ void dump_eltorito(disk_t *disk)
174177
}
175178
}
176179
}
177-
#undef BLK_FIX
178180

179181

182+
static void dump_bootinfo(disk_t *disk, uint64_t sector)
183+
{
184+
unsigned char buf[disk->block_size];
185+
unsigned char pvd[disk->block_size];
186+
unsigned char grub_info[disk->block_size];
187+
188+
if(disk->block_size < 0x200) return;
189+
190+
if(disk_read(disk, buf, sector, 1)) return;
191+
192+
unsigned bi_pvd = read_dword_le(buf + 8) << BLK_FIX;
193+
unsigned bi_start = read_dword_le(buf + 12) << BLK_FIX;
194+
unsigned bi_size = read_dword_le(buf + 16);
195+
unsigned bi_crc = read_dword_le(buf + 20);
196+
197+
if((uint64_t) bi_pvd * disk->block_size > disk->size_in_bytes + disk->block_size) return;
198+
if(disk_read(disk, pvd, bi_pvd, 1)) return;
199+
if(memcmp(pvd, ISO_MAGIC, sizeof ISO_MAGIC - 1)) return;
200+
201+
unsigned file_size = -1u;
202+
iso_block_to_name(disk, sector, &file_size);
203+
204+
unsigned crc = 0;
205+
206+
if(file_size == bi_size) {
207+
for(unsigned u = 64, block_nr = sector; u < file_size; u += 4) {
208+
if(u && !(u % disk->block_size)) {
209+
if(disk_read(disk, buf, ++block_nr, 1)) break;
210+
}
211+
crc += read_dword_le(buf + u % disk->block_size);
212+
}
213+
}
214+
215+
uint64_t grub_lba = 0;
216+
217+
if(disk->grub_used && !disk_read(disk, grub_info, sector + 4, 1)) {
218+
grub_lba = read_qword_le(grub_info + 0x1f4);
219+
}
220+
221+
log_info(" boot info table:\n");
222+
log_info(" volume descriptor %u\n", bi_pvd);
223+
log_info(" start %u (%s)\n", bi_start, bi_start == sector ? "ok" : "wrong");
224+
log_info(" size %u (%s)\n", bi_size, bi_size == file_size ? "ok" : "wrong");
225+
log_info(" crc 0x%08x (%s)\n", bi_crc, bi_crc == crc ? "ok" : "wrong");
226+
if(disk->grub_used) {
227+
log_info(" grub start %"PRIu64" (%s)\n", grub_lba, grub_lba == sector + 5 ? "ok" : "wrong");
228+
}
229+
230+
json_object *json_fs = json_object_new_object();
231+
json_object_object_add(disk->json_current, "boot_info_table", json_fs);
232+
233+
json_object_object_add(json_fs, "volume_descriptor_lba", json_object_new_int64(bi_pvd));
234+
json_object_object_add(json_fs, "file_lba", json_object_new_int64(bi_start));
235+
json_object_object_add(json_fs, "file_lba_ok", json_object_new_boolean(bi_start == sector));
236+
json_object_object_add(json_fs, "file_size", json_object_new_int64(bi_size));
237+
json_object_object_add(json_fs, "file_size_ok", json_object_new_boolean(bi_size == file_size));
238+
if(disk->grub_used) {
239+
json_object_object_add(json_fs, "grub_lba", json_object_new_int64(grub_lba));
240+
json_object_object_add(json_fs, "grub_lba_ok", json_object_new_boolean(grub_lba == sector + 5));
241+
}
242+
243+
json_object *json_crc = json_object_new_object();
244+
json_object_object_add(json_fs, "crc", json_crc);
245+
json_object_object_add(json_crc, "stored", json_object_new_format("0x%08x", bi_crc));
246+
json_object_object_add(json_crc, "calculated", json_object_new_format("0x%08x", crc));
247+
json_object_object_add(json_crc, "ok", json_object_new_boolean(bi_crc == crc));
248+
}
249+
250+
#undef BLK_FIX

filesystem.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ int dump_fs(disk_t *disk, int indent, uint64_t sector)
260260
log_info(", uuid \"%s\"", fs_detail.uuid);
261261
}
262262

263-
if((s = iso_block_to_name(disk, (sector * disk->block_size) >> 9))) {
263+
if((s = iso_block_to_name(disk, (sector * disk->block_size) >> 9, NULL))) {
264264
json_object_object_add(json_fs, "file_name", json_object_new_string(s));
265265
log_info(", \"%s\"", s);
266266
}
@@ -275,7 +275,7 @@ int dump_fs(disk_t *disk, int indent, uint64_t sector)
275275
/*
276276
* block is in 512 byte units
277277
*/
278-
char *iso_block_to_name(disk_t *disk, unsigned block)
278+
char *iso_block_to_name(disk_t *disk, unsigned block, unsigned *len)
279279
{
280280
static char *buf = NULL;
281281
file_start_t *fs;
@@ -288,6 +288,7 @@ char *iso_block_to_name(disk_t *disk, unsigned block)
288288
}
289289

290290
if(fs) {
291+
if(len) *len = fs->len;
291292
if(block == fs->block) {
292293
name = fs->name;
293294
}

filesystem.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
int dump_fs(disk_t *disk, int indent, uint64_t sector);
2-
char *iso_block_to_name(disk_t *disk, unsigned block);
2+
char *iso_block_to_name(disk_t *disk, unsigned block, unsigned *len);

ptable_mbr.c

+24-6
Original file line numberDiff line numberDiff line change
@@ -301,19 +301,37 @@ void dump_mbr_ptable(disk_t *disk)
301301

302302
json_object_object_add(json_mbr, "id", json_object_new_format("0x%08x", id));
303303

304-
if(memmem(buf, disk->block_size, "isolinux.bin", sizeof "isolinux.bin" - 1)) {
304+
// 32 or 64 bit?
305+
//
306+
// Tools that write the value claim 64 bit.
307+
// isolinux actually uses 32 bit when loading.
308+
// And no Legacy BIOS handles 64 bit correctly anyway.
309+
uint64_t bi_start = le64toh(*(uint64_t *) (buf + 0x1b0));
310+
311+
if(bi_start) {
305312
char *s;
306-
unsigned start = le32toh(*(uint32_t *) (buf + 0x1b0));
307-
log_info(" isolinux: %u", start);
308-
if((s = iso_block_to_name(disk, start))) {
313+
char *bi_type = "bootinfo";
314+
if(memmem(buf, disk->block_size, "isolinux.bin", sizeof "isolinux.bin" - 1)) {
315+
bi_type = "isolinux";
316+
disk->isolinux_used = 1;
317+
}
318+
else if(memmem(buf, disk->block_size, "GRUB", sizeof "GRUB" - 1)) {
319+
bi_type = "grub";
320+
disk->grub_used = 1;
321+
// grub stores offset to image + 4 blocks
322+
bi_start -= 4;
323+
}
324+
325+
log_info(" %s: %"PRIu64, bi_type, bi_start);
326+
if((s = iso_block_to_name(disk, bi_start, NULL))) {
309327
log_info(", \"%s\"", s);
310328
}
311329
log_info("\n");
312330

313331
json_object *json_isolinux = json_object_new_object();
314-
json_object_object_add(json_mbr, "isolinux", json_isolinux);
332+
json_object_object_add(json_mbr, bi_type, json_isolinux);
315333

316-
json_object_object_add(json_isolinux, "first_lba", json_object_new_int64(start));
334+
json_object_object_add(json_isolinux, "first_lba", json_object_new_int64(bi_start));
317335
if(s) json_object_object_add(json_isolinux, "file_name", json_object_new_string(s));
318336
}
319337

zipl.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void dump_zipl_components(disk_t *disk, uint64_t sec)
6969
len2
7070
);
7171
if(size2 != disk->block_size || opt.show.raw) log_info(", blksize %d", size2);
72-
if((s = iso_block_to_name(disk, start2))) {
72+
if((s = iso_block_to_name(disk, start2, NULL))) {
7373
log_info(", \"%s\"", s);
7474
}
7575
log_info("\n");
@@ -170,7 +170,7 @@ void dump_zipl(disk_t *disk)
170170

171171
log_info(" program table: %llu", (unsigned long long) pt_sec);
172172
if(size != disk->block_size || opt.show.raw) log_info(", blksize %u", size);
173-
if((s = iso_block_to_name(disk, pt_sec))) {
173+
if((s = iso_block_to_name(disk, pt_sec, NULL))) {
174174
log_info(", \"%s\"", s);
175175
}
176176
log_info("\n");

0 commit comments

Comments
 (0)