shithub: riscv

Download patch

ref: 1613fd9f526dc5a5703bbeb1d84e59980db0845e
parent: bbc35cc01b3632fe345244a5a366dd5e80755265
author: cinap_lenrek <[email protected]>
date: Fri Jun 5 17:57:08 EDT 2015

disk/edisk: create esp partition in addition to plan9 partition in auto mode

--- a/sys/src/cmd/disk/prep/edisk.c
+++ b/sys/src/cmd/disk/prep/edisk.c
@@ -90,8 +90,6 @@
 static uchar	devid[16];
 static uchar	zeros[16];
 
-static Type	*type9;
-
 /* RFC4122, but in little endian format */
 #define UU(a,b,c,d,e) { \
 	(a)&255,((a)>>8)&255,((a)>>16)&255,((a)>>24)&255, \
@@ -256,8 +254,6 @@
 
 	initcrc32();
 
-	type9 = gettype(nil, "plan9");
-
 	secsize = 0;
 	ARGBEGIN{
 	case 'a':
@@ -895,18 +891,20 @@
 }
 
 static void
-autopart(Edit *edit)
+autopart1(Edit *edit, Type *type, uvlong attr, vlong maxsize)
 {
 	vlong start, bigstart, bigsize;
 	Gptpart *p;
 	int i;
 
+	maxsize /= edit->disk->secsize;
+
 	bigsize = 0;
 	bigstart = 0;
 	start = partoff;
 	for(i=0; i<edit->npart; i++){
 		p = (Gptpart*)edit->part[i];
-		if(p->type == type9)
+		if(p->type == type)
 			return;
 		if(p->start > start && (p->start - start) > bigsize){
 			bigsize = p->start - start;
@@ -922,16 +920,25 @@
 		fprint(2, "couldn't find space for plan 9 partition\n");
 		return;
 	}
+	if(maxsize && bigsize > maxsize)
+		bigsize = maxsize;
 	for(i=0; i<nparts; i++){
 		p = &parts[i];
 		if(p->type == nil){
-			newpart(edit, p, bigstart, bigstart+bigsize, type9, 0);
+			newpart(edit, p, bigstart, bigstart+bigsize, type, attr);
 			return;
 		}
 	}
-	fprint(2, "couldn't find free slot for plan 9 partition\n");
+	fprint(2, "couldn't find free slot for %s partition\n", type->name);
 }
 
+static void
+autopart(Edit *edit)
+{
+	autopart1(edit, gettype(nil, "esp"), 4, 550*MB);
+	autopart1(edit, gettype(nil, "plan9"), 0, 0);
+}
+
 typedef struct Name Name;
 struct Name {
 	char *name;
@@ -1072,7 +1079,7 @@
 	slot = atoi(name+1)-1;
 	if(slot < 0 || slot >= nparts)
 		return "partition number out of range";
-	return newpart(edit, &parts[slot], start, end, type9, 0);
+	return newpart(edit, &parts[slot], start, end, gettype(nil, "plan9"), 0);
 }
 
 static char*