Handle the raw partition of the BSD and VTOC schemes.

This commit is contained in:
marcel 2014-03-29 03:14:00 +00:00
parent 650a8b44e4
commit 50a0b74b99
2 changed files with 20 additions and 15 deletions

13
bsd.c
View File

@ -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
};

22
vtoc8.c
View File

@ -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
};