ref: 7fff1f8dbafde3b4c4de7bc176800577c45a32dc
parent: 68c77bf4a6aa932a7f31d8d84a378656542c80c2
author: cinap_lenrek <[email protected]>
date: Sun May 6 09:51:53 EDT 2012
disk/format: choose default cluster size if not given
--- a/sys/src/cmd/disk/format.c
+++ b/sys/src/cmd/disk/format.c
@@ -364,6 +364,23 @@
return tot;
}
+int
+defcluster(vlong n)
+{
+ int i;
+
+ i = n / 32768;
+ if(i <= 1)
+ return 1;
+ if(i >= 128)
+ return 128;
+ i--;
+ i |= i >> 1;
+ i |= i >> 2;
+ i |= i >> 4;
+ return i+1;
+}
+
void
dosfs(int dofat, int dopbs, Disk *disk, char *label, int argc, char *argv[], int commit)
{
@@ -388,6 +405,7 @@
t->sectors = disk->s;
t->heads = disk->h;
t->tracks = disk->c;
+ t->cluster = defcluster(disk->secs);
}
if(t->sectors == 0 && dofat)
@@ -490,6 +508,8 @@
if(clustersize == 0)
clustersize = t->cluster;
+if(chatty) print("clustersize %d\n", clustersize);
+
/*
* the number of fat bits depends on how much disk is left
* over after you subtract out the space taken up by the fat tables.
@@ -519,7 +539,8 @@
break;
clusters = newclusters;
if(i > 10)
- fatal("can't decide how many clusters to use (%d? %d?)", clusters, newclusters);
+ fatal("can't decide how many clusters to use (%d? %d?)",
+ clusters, newclusters);
if(chatty) print("clusters %d\n", clusters);
}
@@ -786,7 +807,7 @@
d = (Dosdir*)entry;
putname(s, d);
- if(strcmp(s, "9load") == 0)
+ if(cistrcmp(s, "9load") == 0 || cistrncmp(s, "9boot", 5) == 0)
d->attr = DSYSTEM;
else
d->attr = 0;