summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2014-03-29 03:14:00 +0000
committermarcel <marcel@FreeBSD.org>2014-03-29 03:14:00 +0000
commit50a0b74b99504e35c83df17770a62b072238fa08 (patch)
tree26a273438e150d059a98a1ecdb9a5d33c29c6cd9
parent650a8b44e4f91c25ba9e7d5d2272728dbe128b40 (diff)
downloadFreeBSD-src-50a0b74b99504e35c83df17770a62b072238fa08.zip
FreeBSD-src-50a0b74b99504e35c83df17770a62b072238fa08.tar.gz
Handle the raw partition of the BSD and VTOC schemes.
-rw-r--r--bsd.c13
-rw-r--r--vtoc8.c22
2 files changed, 20 insertions, 15 deletions
diff --git a/bsd.c b/bsd.c
index 7e28b9e..85d83e1 100644
--- a/bsd.c
+++ b/bsd.c
@@ -63,7 +63,7 @@ bsd_write(int fd, lba_t imgsz, void *bootcode)
struct disklabel *d;
struct partition *dp;
struct part *part;
- int error;
+ int error, n;
uint16_t checksum;
buf = malloc(BBSIZE);
@@ -88,17 +88,20 @@ bsd_write(int fd, lba_t imgsz, void *bootcode)
le32enc(&d->d_secperunit, imgsz);
le16enc(&d->d_rpm, 3600);
le32enc(&d->d_magic2, DISKMAGIC);
- le16enc(&d->d_npartitions, (8 > nparts) ? 8 : nparts);
+ le16enc(&d->d_npartitions, (8 > nparts + 1) ? 8 : nparts + 1);
le32enc(&d->d_bbsize, BBSIZE);
+ dp = &d->d_partitions[RAW_PART];
+ le32enc(&dp->p_size, imgsz);
STAILQ_FOREACH(part, &partlist, link) {
- dp = &d->d_partitions[part->index];
+ n = part->index + ((part->index >= RAW_PART) ? 1 : 0);
+ dp = &d->d_partitions[n];
le32enc(&dp->p_size, part->size);
le32enc(&dp->p_offset, part->block);
dp->p_fstype = ALIAS_TYPE2INT(part->type);
}
- dp = &d->d_partitions[nparts];
+ dp = &d->d_partitions[nparts + 1];
checksum = 0;
for (p = buf; p < (u_char *)dp; p += 2)
checksum ^= le16dec(p);
@@ -119,7 +122,7 @@ static struct mkimg_scheme bsd_scheme = {
.aliases = bsd_aliases,
.metadata = bsd_metadata,
.write = bsd_write,
- .nparts = 20,
+ .nparts = 19,
.bootcode = BBSIZE,
.maxsecsz = 512
};
diff --git a/vtoc8.c b/vtoc8.c
index 586337a..4363024 100644
--- a/vtoc8.c
+++ b/vtoc8.c
@@ -63,11 +63,14 @@ vtoc8_write(int fd, lba_t imgsz, void *bootcode __unused)
struct vtoc8 vtoc8;
struct part *part;
u_char *p;
- int error;
+ int error, n;
uint16_t ofs, sum;
+ imgsz = ncyls * nheads * nsecs;
+
memset(&vtoc8, 0, sizeof(vtoc8));
- sprintf(vtoc8.ascii, "FreeBSD%lldM", (long long)(imgsz / 2048));
+ sprintf(vtoc8.ascii, "FreeBSD%lldM",
+ (long long)(imgsz * secsz / 1048576));
be32enc(&vtoc8.version, VTOC_VERSION);
be16enc(&vtoc8.nparts, VTOC8_NPARTS);
be32enc(&vtoc8.sanity, VTOC_SANITY);
@@ -79,15 +82,14 @@ vtoc8_write(int fd, lba_t imgsz, void *bootcode __unused)
be16enc(&vtoc8.nsecs, nsecs);
be16enc(&vtoc8.magic, VTOC_MAGIC);
- ftruncate(fd, ncyls * nheads * nsecs *secsz);
+ ftruncate(fd, imgsz * secsz);
+ be32enc(&vtoc8.map[VTOC_RAW_PART].nblks, imgsz);
STAILQ_FOREACH(part, &partlist, link) {
- be16enc(&vtoc8.part[part->index].tag,
- ALIAS_TYPE2INT(part->type));
- be32enc(&vtoc8.map[part->index].cyl,
- part->block / (nsecs * nheads));
- be32enc(&vtoc8.map[part->index].nblks,
- part->size);
+ n = part->index + ((part->index >= VTOC_RAW_PART) ? 1 : 0);
+ be16enc(&vtoc8.part[n].tag, ALIAS_TYPE2INT(part->type));
+ be32enc(&vtoc8.map[n].cyl, part->block / (nsecs * nheads));
+ be32enc(&vtoc8.map[n].nblks, part->size);
}
/* Calculate checksum. */
@@ -111,7 +113,7 @@ static struct mkimg_scheme vtoc8_scheme = {
.aliases = vtoc8_aliases,
.metadata = vtoc8_metadata,
.write = vtoc8_write,
- .nparts = VTOC8_NPARTS,
+ .nparts = VTOC8_NPARTS - 1,
.maxsecsz = 512
};
OpenPOWER on IntegriCloud