From fb4d6d8676700caf861d164003339fb1609e05db Mon Sep 17 00:00:00 2001 From: Eygene Ryabinkin Date: Sat, 11 Jul 2009 14:53:11 +0400 Subject: [PATCH] bsdlabel: obtain slice offset from the disklabel itself Don't use offset from MBR that is obtained by the geom(4): not any system has MBR and so on ;)) Partition 'c' holds offset, so it is used -- this corresponds to the current kernel behaviour. Signed-off-by: Eygene Ryabinkin --- sbin/bsdlabel/bsdlabel.c | 28 ++++++++-------------------- 1 files changed, 8 insertions(+), 20 deletions(-) diff --git a/sbin/bsdlabel/bsdlabel.c b/sbin/bsdlabel/bsdlabel.c index 1cb9995..5aa97df 100644 --- a/sbin/bsdlabel/bsdlabel.c +++ b/sbin/bsdlabel/bsdlabel.c @@ -118,7 +118,6 @@ static int installboot; /* non-zero if we should install a boot program */ static int allfields; /* present all fields in edit */ static char const *xxboot; /* primary boot */ -static off_t mbroffset; #ifndef LABELSECTOR #define LABELSECTOR -1 #endif @@ -388,6 +387,7 @@ writelabel(void) struct gctl_req *grq; char const *errstr; struct disklabel *lp = &lab; + off_t sliceoffset; if (disable_write) { warnx("write to disk label supressed - label was as follows:"); @@ -401,9 +401,10 @@ writelabel(void) lp->d_checksum = dkcksum(lp); if (installboot) readboot(); + sliceoffset = lab.d_partitions[RAW_PART].p_offset; for (i = 0; i < lab.d_npartitions; i++) if (lab.d_partitions[i].p_size) - lab.d_partitions[i].p_offset += mbroffset; + lab.d_partitions[i].p_offset += sliceoffset; bsd_disklabel_le_enc(bootarea + labeloffset + labelsoffset * secsize, lp); if (alphacksum) { @@ -481,8 +482,7 @@ readlabel(int flag) { int f, i; int error; - struct gctl_req *grq; - char const *errstr; + off_t sliceoffset; f = open(specname, O_RDONLY); if (f < 0) @@ -510,22 +510,10 @@ readlabel(int flag) if (is_file) return(0); - grq = gctl_get_handle(); - gctl_ro_param(grq, "verb", -1, "read mbroffset"); - gctl_ro_param(grq, "class", -1, "BSD"); - gctl_ro_param(grq, "geom", -1, pname); - gctl_rw_param(grq, "mbroffset", sizeof(mbroffset), &mbroffset); - errstr = gctl_issue(grq); - if (errstr != NULL) { - mbroffset = 0; - gctl_free(grq); - return (error); - } - mbroffset /= lab.d_secsize; - if (lab.d_partitions[RAW_PART].p_offset == mbroffset) - for (i = 0; i < lab.d_npartitions; i++) - if (lab.d_partitions[i].p_size) - lab.d_partitions[i].p_offset -= mbroffset; + sliceoffset = lab.d_partitions[RAW_PART].p_offset; + for (i = 0; i < lab.d_npartitions; i++) + if (lab.d_partitions[i].p_size) + lab.d_partitions[i].p_offset -= sliceoffset; return (error); } -- 1.6.3.1