From 9ad2132174c3dfb02c61071416fe020abe58cd8c Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Mon, 21 Apr 2003 20:36:44 +0000 Subject: [PATCH] Update libdisk to use the explicing encoding function for sunlabel data structures. --- lib/libdisk/Makefile | 2 ++ lib/libdisk/write_sparc64_disk.c | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/libdisk/Makefile b/lib/libdisk/Makefile index e0faefac3df5..f3c560b9d2e0 100644 --- a/lib/libdisk/Makefile +++ b/lib/libdisk/Makefile @@ -7,6 +7,8 @@ INCS= libdisk.h WARNS= 2 +CFLAGS+= -I${.CURDIR}/../../sys/geom + .if ${MACHINE} == "pc98" CFLAGS+= -DPC98 .endif diff --git a/lib/libdisk/write_sparc64_disk.c b/lib/libdisk/write_sparc64_disk.c index 06681418c86f..686e7510ccc1 100644 --- a/lib/libdisk/write_sparc64_disk.c +++ b/lib/libdisk/write_sparc64_disk.c @@ -24,6 +24,8 @@ __FBSDID("$FreeBSD$"); #include #include "libdisk.h" +#include "geom_sunlabel_enc.c" + int Write_Disk(const struct disk *d1) { @@ -34,6 +36,7 @@ Write_Disk(const struct disk *d1) u_long secpercyl; u_short *sp1, *sp2, cksum; char device[64]; + u_char buf[SUN_SIZE]; int fd; strcpy(device, _PATH_DEV); @@ -74,9 +77,11 @@ Write_Disk(const struct disk *d1) p = c1->name; p += strlen(p); p--; - if (*p < 'a' || *p > 'h') + if (*p < 'a') continue; i = *p - 'a'; + if (i >= SUN_NPART) + continue; sl->sl_part[i].sdkp_cyloffset = c1->offset / secpercyl; sl->sl_part[i].sdkp_nsectors = c1->size; for (i = 1; i < 16; i++) { @@ -90,17 +95,12 @@ Write_Disk(const struct disk *d1) * seems to indicate that this covers the "obviously" visible part * of the disk, ie: sl->sl_ncylinders. */ - sl->sl_part[2].sdkp_cyloffset = 0; - sl->sl_part[2].sdkp_nsectors = sl->sl_ncylinders * secpercyl; + sl->sl_part[SUN_RAWPART].sdkp_cyloffset = 0; + sl->sl_part[SUN_RAWPART].sdkp_nsectors = sl->sl_ncylinders * secpercyl; - sp1 = (u_short *)sl; - sp2 = (u_short *)(sl + 1); - sl->sl_cksum = cksum = 0; - while (sp1 < sp2) - cksum ^= *sp1++; - sl->sl_cksum = cksum; - - write_block(fd, 0, sl, sizeof *sl); + memset(buf, 0, sizeof buf); + sunlabel_enc(buf, &sl); + write_block(fd, 0, buf, sizeof buf); close(fd); return 0;