From aa658d1c5b35fe48e7bb5632ca62e36f63f90bba Mon Sep 17 00:00:00 2001 From: rahnds Date: Mon, 27 Jan 1997 21:57:34 +0000 Subject: [PATCH] Support fdisk on bigendian systems. Does the necessary byte swabbing to read and write the fdisk label. Added powerpc to systems to build this for. Currently uses local functions getshort, putshort, getlong, and putlong. These functions probably should be moved and renamed. Something like htoles, letohs, htolel, letohl, or htole16, htole32 should be used instead. --- sbin/Makefile | 4 +-- sbin/fdisk/fdisk.c | 81 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 20 deletions(-) diff --git a/sbin/Makefile b/sbin/Makefile index b9ab59942ce..fb7b4d77d52 100644 --- a/sbin/Makefile +++ b/sbin/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.22 1997/01/26 02:26:03 millert Exp $ +# $OpenBSD: Makefile,v 1.23 1997/01/27 21:57:34 rahnds Exp $ # $NetBSD: Makefile,v 1.29 1996/05/14 17:39:21 ws Exp $ # Not ported: XNSrouted enpload scsiformat startslip @@ -32,7 +32,7 @@ SUBDIR+= bim config_slot edlabel fdisk pcmcia_cntrl SUBDIR+= config_slot SUBDIR+= fdisk SUBDIR+= pcmcia_cntrl -.elif ${MACHINE} == "arc" +.elif (${MACHINE} == "arc") || (${MACHINE} == "powerpc") SUBDIR+= fdisk .elif ${MACHINE} == "pc532" SUBDIR+= bim diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index f27c81edfa1..b720591921b 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdisk.c,v 1.10 1997/01/10 19:09:58 jkatz Exp $ */ +/* $OpenBSD: fdisk.c,v 1.11 1997/01/27 21:57:36 rahnds Exp $ */ /* $NetBSD: fdisk.c,v 1.11 1995/10/04 23:11:19 ghudson Exp $ */ /* @@ -28,7 +28,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: fdisk.c,v 1.10 1997/01/10 19:09:58 jkatz Exp $"; +static char rcsid[] = "$OpenBSD: fdisk.c,v 1.11 1997/01/27 21:57:36 rahnds Exp $"; #endif /* not lint */ #include @@ -266,6 +266,49 @@ print_s0(which) static struct dos_partition mtpart = { 0 }; +static inline unsigned short +getshort(p) + void *p; +{ + unsigned char *cp = p; + + return cp[0] | (cp[1] << 8); +} + +static inline void +putshort(p, l) + void *p; + unsigned short l; +{ + unsigned char *cp = p; + + *cp++ = l; + *cp++ = l >> 8; +} + +static inline unsigned long +getlong(p) + void *p; +{ + unsigned char *cp = p; + + return cp[0] | (cp[1] << 8) | (cp[2] << 16) | (cp[3] << 24); +} + +static inline void +putlong(p, l) + void *p; + unsigned long l; +{ + unsigned char *cp = p; + + *cp++ = l; + *cp++ = l >> 8; + *cp++ = l >> 16; + *cp++ = l >> 24; +} + + void print_part(part) int part; @@ -281,8 +324,8 @@ print_part(part) printf("sysid %d=0x%02x (%s)\n", partp->dp_typ, partp->dp_typ, get_type(partp->dp_typ)); printf(" start %d, size %d (%d MB), flag 0x%02x\n", - partp->dp_start, partp->dp_size, - partp->dp_size * 512 / (1024 * 1024), partp->dp_flag); + getlong(&partp->dp_start), getlong(&partp->dp_size), + getlong(&partp->dp_size) * 512 / (1024 * 1024), partp->dp_flag); printf(" beg: cylinder %4d, head %3d, sector %2d\n", DPCYL(partp->dp_scyl, partp->dp_ssect), partp->dp_shd, DPSECT(partp->dp_ssect)); @@ -306,17 +349,17 @@ init_sector0(start) err(1, "reading %s", mbrname); fclose(f); - mboot.signature = BOOT_MAGIC; + putshort(&mboot.signature, BOOT_MAGIC); partp = &mboot.parts[3]; partp->dp_typ = DOSPTYP_OPENBSD; partp->dp_flag = ACTIVE; - partp->dp_start = start; - partp->dp_size = disksectors - start; + putlong(&partp->dp_start, start); + putlong(&partp->dp_size,disksectors - start); - dos(partp->dp_start, + dos(getlong(&partp->dp_start), &partp->dp_scyl, &partp->dp_shd, &partp->dp_ssect); - dos(partp->dp_start + partp->dp_size - 1, + dos(getlong(&partp->dp_start) + getlong(&partp->dp_size) - 1, &partp->dp_ecyl, &partp->dp_ehd, &partp->dp_esect); } @@ -422,12 +465,13 @@ get_mapping(i, cylinder, head, sector, absolute) *cylinder = DPCYL(part->dp_scyl, part->dp_ssect); *head = part->dp_shd; *sector = DPSECT(part->dp_ssect) - 1; - *absolute = part->dp_start; + *absolute = getlong(&part->dp_start); } else { *cylinder = DPCYL(part->dp_ecyl, part->dp_esect); *head = part->dp_ehd; *sector = DPSECT(part->dp_esect) - 1; - *absolute = part->dp_start + part->dp_size - 1; + *absolute = getlong(&part->dp_start) + + getlong(&part->dp_size) - 1; } return 0; } @@ -454,14 +498,14 @@ change_part(part) do { sysid = partp->dp_typ, - start = partp->dp_start, - size = partp->dp_size; + start = getlong(&partp->dp_start), + size = getlong(&partp->dp_size); decimal("sysid", &sysid); decimal("start", &start); decimal("size", &size); partp->dp_typ = sysid; - partp->dp_start = start; - partp->dp_size = size; + putlong(&partp->dp_start, start); + putlong(&partp->dp_size, size); if (yesno("Explicitly specify beg/end address?")) { int tsector, tcylinder, thead; @@ -486,9 +530,10 @@ change_part(part) partp->dp_ehd = thead; partp->dp_esect = DOSSECT(tsector, tcylinder); } else { - dos(partp->dp_start, + dos(getlong(&partp->dp_start), &partp->dp_scyl, &partp->dp_shd, &partp->dp_ssect); - dos(partp->dp_start + partp->dp_size - 1, + dos(getlong(&partp->dp_start) + + getlong(&partp->dp_size) - 1, &partp->dp_ecyl, &partp->dp_ehd, &partp->dp_esect); } @@ -648,7 +693,7 @@ read_s0() warn("can't read fdisk partition table"); return (-1); } - if (mboot.signature != BOOT_MAGIC) { + if (getshort(&mboot.signature) != BOOT_MAGIC) { fprintf(stderr, "warning: invalid fdisk partition table found!\n"); /* So should we initialize things? */ -- 2.20.1