ref: 303fb4968634b7fd16815d4c16777dba0bf97f13
parent: a3c2819c5044db35e9c679157ec622f55c3268da
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Dec 5 18:44:43 EST 2017
disk/edisk: allow printing and readonly inspection of hybrid MBR/GPT disks (thanks aiju) dumping hybrid MBR/GPT disks is fine, which can sometimes be found on USB sticks. but prohibit editing. however, always barf on disks with dos partitions and missing protecive MBR partition entry.
--- a/sys/src/cmd/disk/prep/edisk.c
+++ b/sys/src/cmd/disk/prep/edisk.c
@@ -713,6 +713,7 @@
static uchar*
readmbr(Disk *disk)
{
+ int dosparts, protected;
uchar *mbr, *magic;
Tentry *t;
int i;
@@ -722,16 +723,24 @@
if(magic[0] != 0x55 || magic[1] != 0xAA)
sysfatal("did not find master boot record");
+ dosparts = protected = 0;
for(i=0; i<NTentry; i++){
t = (Tentry*)&mbr[disk->secsize - 2 - (i+1)*Tentrysiz];
switch(t->type){
case 0xEE:
+ protected = 1;
case 0xEF:
case 0x00:
continue;
}
- sysfatal("dos partition table in use");
+ dosparts++;
}
+
+ if(dosparts && protected && !(printflag || rdonly))
+ sysfatal("potential hybrid MBR/GPT detected, not editing");
+
+ if(dosparts && !protected)
+ sysfatal("dos partition table in use and no protective partition found");
return mbr;
}