1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#include "project.h"
void
new (DISK * d)
{
uint8_t buf[SECTOR_SIZE];
MBR m;
GPT_header h, alt_h;
GPT_entry e = { 0 };
GUID disk_guid;
uint64_t lbas;
int n;
lbas = disk_lbas (d);
disk_guid = guid_random ();
m = mbr_new (lbas);
memcpy (buf, &m, sizeof (m));
disk_write (d, buf, 0, 1);
h = header_new (disk_guid, lbas, 0);
alt_h = header_new (disk_guid, lbas, 1);
for (n = 0; n < h.n_partition_entries; ++n)
{
entry_write (d, &h, n, &e);
entry_write (d, &alt_h, n, &e);
}
h.partition_entry_crc = header_calc_ent_crc (d, &h);
alt_h.partition_entry_crc = header_calc_ent_crc (d, &alt_h);
header_calc_crc (&h);
header_calc_crc (&alt_h);
memcpy (buf, &h, sizeof (h));
disk_write (d, buf, h.my_lba, 1);
memcpy (buf, &alt_h, sizeof (alt_h));
disk_write (d, buf, alt_h.my_lba, 1);
}
|