summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2017-12-05 23:44:43 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2017-12-05 23:44:43 +0100
commit303fb4968634b7fd16815d4c16777dba0bf97f13 (patch)
treea6ee3911de3916eeda952f3aff35f614d84719e7 /sys
parenta3c2819c5044db35e9c679157ec622f55c3268da (diff)
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.
Diffstat (limited to 'sys')
-rw-r--r--sys/src/cmd/disk/prep/edisk.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/sys/src/cmd/disk/prep/edisk.c b/sys/src/cmd/disk/prep/edisk.c
index 3aa8048da..9fee86c02 100644
--- a/sys/src/cmd/disk/prep/edisk.c
+++ b/sys/src/cmd/disk/prep/edisk.c
@@ -713,6 +713,7 @@ enum {
static uchar*
readmbr(Disk *disk)
{
+ int dosparts, protected;
uchar *mbr, *magic;
Tentry *t;
int i;
@@ -722,17 +723,25 @@ readmbr(Disk *disk)
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;
}