aboutsummaryrefslogtreecommitdiffstats
path: root/src/new.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/new.c')
-rw-r--r--src/new.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/new.c b/src/new.c
new file mode 100644
index 0000000..d8c177f
--- /dev/null
+++ b/src/new.c
@@ -0,0 +1,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);
+
+}
+