SayoriOS 0.3.3

mbr.c
1 #include "drv/disk/mbr.h"
2 #include "drv/disk/dpm.h"
3 #include "io/ports.h"
4 #include "debug/hexview.h"
5 #include "io/tty.h"
6
7 void ebr_recursive_dump(char disk, uint64_t abs_lba, uint64_t lba, int depth) {
8 struct mbr_parition w = {};
9
10 dpm_read(disk, 0, ((lba + abs_lba) * 512) + 446, sizeof(w), (uint8_t *)&w);
11
12 qemu_log("%*s Active: %d; [C: %d; H: %d; S: %d] Type: %d; [C: %d; H: %d; S: %d] Start LBA: %d; Num Sectors: %d\n",
13 depth + 3, "|--",
14 w.activity,
15 w.start_cylinder, w.start_head, w.start_sector,
16 w.type,
17 w.end_cylinder, w.end_head, w.end_sector,
18 w.start_sector_lba, w.num_sectors);
19
20 tty_printf("%*s A: %d; [%d:%d:%d] Type: %d; [%d:%d:%d] SLBA: %d; COUNT: %d\n",
21 depth + 3, "|--",
22 w.activity,
23 w.start_cylinder, w.start_head, w.start_sector,
24 w.type,
25 w.end_cylinder, w.end_head, w.end_sector,
26 w.start_sector_lba, w.num_sectors);
27
28 dpm_read(disk, 0, ((lba + abs_lba) * 512) + 446 + 16, sizeof(w), (uint8_t *)&w);
29
30 if(w.type == 5) {
31 ebr_recursive_dump(disk, abs_lba, w.start_sector_lba, depth);
32 }
33 }
34
35 void mbr_dump(char disk, uint64_t i) {
36 struct mbr_parition p = {};
37
38 dpm_read(disk, 0, 446 + (i * 16), sizeof(p), (uint8_t *)&p);
39
40 qemu_log("[%d] Active: %d; [C: %d; H: %d; S: %d] Type: %d; [C: %d; H: %d; S: %d] Start LBA: %d; Num Sectors: %d",
41 i,
42 p.activity,
43 p.start_cylinder, p.start_head, p.start_sector,
44 p.type,
45 p.end_cylinder, p.end_head, p.end_sector,
46 p.start_sector_lba, p.num_sectors);
47
48 tty_printf("[%d] A: %d; [%d:%d:%d] Type: %d; [%d:%d:%d] SLBA: %d; COUNT: %d\n",
49 i,
50 p.activity,
51 p.start_cylinder, p.start_head, p.start_sector,
52 p.type,
53 p.end_cylinder, p.end_head, p.end_sector,
54 p.start_sector_lba, p.num_sectors);
55
56 if(p.type == 5 || p.type == 15) {
57 ebr_recursive_dump(disk, p.start_sector_lba, 0, 1);
58 }
59 }
60
61 void mbr_dump_all(char disk) {
62 uint16_t p;
63
64 dpm_read(disk, 0, 510, 2, (uint8_t *)&p);
65
66 if(p == 0xaa55) {
67 mbr_dump(disk, 0);
68 mbr_dump(disk, 1);
69 mbr_dump(disk, 2);
70 mbr_dump(disk, 3);
71 tty_printf("\n");
72 }
73 }
dpm_read
size_t dpm_read(char Letter, uint64_t high_offset, uint64_t low_offset, size_t Size, void *Buffer)
[DPM] Считывание данных с диска
Definition: dpm.c:82
mbr_parition
Definition: mbr.h:9