diff options
author | marcel <marcel@FreeBSD.org> | 2004-10-25 03:27:31 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2004-10-25 03:27:31 +0000 |
commit | b9db7730bbbc1a0dc8130a6df4f3b46e14d43037 (patch) | |
tree | 574f77edc6d52ea43a9c84c97e3cc01aac768e42 /sbin | |
parent | 6f55e2c3d17821cb93370cd0e64ae8b0ee81b2c2 (diff) | |
download | FreeBSD-src-b9db7730bbbc1a0dc8130a6df4f3b46e14d43037.zip FreeBSD-src-b9db7730bbbc1a0dc8130a6df4f3b46e14d43037.tar.gz |
Catch up with the BSD label changes. The partition offsets are relative
to the partition now. While here, make sure we skip unused partition
entries.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/gpt/migrate.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/sbin/gpt/migrate.c b/sbin/gpt/migrate.c index 115f171..497d3f4 100644 --- a/sbin/gpt/migrate.c +++ b/sbin/gpt/migrate.c @@ -67,6 +67,7 @@ migrate_disklabel(int fd, off_t start, struct gpt_ent *ent) { char *buf; struct disklabel *dl; + off_t ofs, rawofs; int i; buf = gpt_read(fd, start + LABELSECTOR, 1); @@ -79,8 +80,22 @@ migrate_disklabel(int fd, off_t start, struct gpt_ent *ent) return (ent); } + rawofs = le32toh(dl->d_partitions[RAW_PART].p_offset) * + le32toh(dl->d_secsize); + for (i = 0; i < le16toh(dl->d_npartitions); i++) { + if (dl->d_partitions[i].p_fstype == FS_UNUSED) + continue; + ofs = le32toh(dl->d_partitions[i].p_offset) * + le32toh(dl->d_secsize); + if (ofs < rawofs) + rawofs = 0; + } + rawofs /= secsz; + for (i = 0; i < le16toh(dl->d_npartitions); i++) { switch (dl->d_partitions[i].p_fstype) { + case FS_UNUSED: + continue; case FS_SWAP: { uuid_t swap = GPT_ENT_TYPE_FREEBSD_SWAP; le_uuid_enc(&ent->ent_type, &swap); @@ -108,9 +123,11 @@ migrate_disklabel(int fd, off_t start, struct gpt_ent *ent) continue; } - ent->ent_lba_start = - htole64(le32toh(dl->d_partitions[i].p_offset)); - ent->ent_lba_end = htole64(le64toh(ent->ent_lba_start) + + ofs = (le32toh(dl->d_partitions[i].p_offset) * + le32toh(dl->d_secsize)) / secsz; + ofs = (ofs > 0) ? ofs - rawofs : 0; + ent->ent_lba_start = htole64(start + ofs); + ent->ent_lba_end = htole64(start + ofs + le32toh(dl->d_partitions[i].p_size) - 1LL); ent++; } |