-/* $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 $ */
/*
*/
#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 <sys/param.h>
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;
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));
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);
}
*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;
}
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;
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);
}
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? */