summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2015-03-16 23:51:51 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2015-03-16 23:51:51 +0000
commit232a2f05d9f71e64ae425a3947b98559ba6d177b (patch)
treebd0b9f3be8084738fe30c2456c72182f1ec49836 /sbin
parent6bbc2077ce2790382a145103f44a5940ebb234e2 (diff)
Stop passing around a pointer to the stack variable 'disk' in main().
There is only one disk being worked on, so just make it a global. Fewer parameters, less confusion, no functional change.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/fdisk/cmd.c101
-rw-r--r--sbin/fdisk/cmd.h35
-rw-r--r--sbin/fdisk/disk.c33
-rw-r--r--sbin/fdisk/disk.h7
-rw-r--r--sbin/fdisk/fdisk.c17
-rw-r--r--sbin/fdisk/mbr.c41
-rw-r--r--sbin/fdisk/mbr.h8
-rw-r--r--sbin/fdisk/misc.c6
-rw-r--r--sbin/fdisk/misc.h4
-rw-r--r--sbin/fdisk/part.c20
-rw-r--r--sbin/fdisk/part.h8
-rw-r--r--sbin/fdisk/user.c20
-rw-r--r--sbin/fdisk/user.h6
13 files changed, 145 insertions, 161 deletions
diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c
index 23739451b6d..b7b43eaf4a5 100644
--- a/sbin/fdisk/cmd.c
+++ b/sbin/fdisk/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.75 2015/03/14 18:32:29 krw Exp $ */
+/* $OpenBSD: cmd.c,v 1.76 2015/03/16 23:51:50 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -37,16 +37,15 @@
int reinited;
int
-Xreinit(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
- int offset)
+Xreinit(char *args, struct mbr *mbr, struct mbr *tt, int offset)
{
struct dos_mbr dos_mbr;
/* Copy template MBR */
MBR_make(tt, &dos_mbr);
- MBR_parse(disk, &dos_mbr, mbr->offset, mbr->reloffset, mbr);
+ MBR_parse(&dos_mbr, mbr->offset, mbr->reloffset, mbr);
- MBR_init(disk, mbr);
+ MBR_init(mbr);
reinited = 1;
/* Tell em we did something */
@@ -59,15 +58,14 @@ Xreinit(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
}
int
-Xdisk(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
- int offset)
+Xdisk(char *args, struct mbr *mbr, struct mbr *tt, int offset)
{
int maxcyl = 1024;
int maxhead = 256;
int maxsec = 63;
/* Print out disk info */
- DISK_printgeometry(disk, args);
+ DISK_printgeometry(args);
#if defined (__powerpc__) || defined (__mips__)
maxcyl = 9999999;
@@ -77,22 +75,21 @@ Xdisk(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
/* Ask for new info */
if (ask_yn("Change disk geometry?")) {
- disk->cylinders = ask_num("BIOS Cylinders",
- disk->cylinders, 1, maxcyl);
- disk->heads = ask_num("BIOS Heads",
- disk->heads, 1, maxhead);
- disk->sectors = ask_num("BIOS Sectors",
- disk->sectors, 1, maxsec);
-
- disk->size = disk->cylinders * disk->heads * disk->sectors;
+ disk.cylinders = ask_num("BIOS Cylinders",
+ disk.cylinders, 1, maxcyl);
+ disk.heads = ask_num("BIOS Heads",
+ disk.heads, 1, maxhead);
+ disk.sectors = ask_num("BIOS Sectors",
+ disk.sectors, 1, maxsec);
+
+ disk.size = disk.cylinders * disk.heads * disk.sectors;
}
return (CMD_CONT);
}
int
-Xswap(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
- int offset)
+Xswap(char *args, struct mbr *mbr, struct mbr *tt, int offset)
{
const char *errstr;
char *from, *to;
@@ -131,8 +128,7 @@ Xswap(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
}
int
-Xedit(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
- int offset)
+Xedit(char *args, struct mbr *mbr, struct mbr *tt, int offset)
{
const char *errstr;
int pn, num, ret;
@@ -146,7 +142,7 @@ Xedit(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
pp = &mbr->part[pn];
/* Edit partition type */
- ret = Xsetpid(args, disk, mbr, tt, offset);
+ ret = Xsetpid(args, mbr, tt, offset);
/* Unused, so just zero out */
if (pp->id == DOSPTYP_UNUSED) {
@@ -160,9 +156,9 @@ Xedit(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
int maxcyl, maxhead, maxsect;
/* Shorter */
- maxcyl = disk->cylinders - 1;
- maxhead = disk->heads - 1;
- maxsect = disk->sectors;
+ maxcyl = disk.cylinders - 1;
+ maxhead = disk.heads - 1;
+ maxsect = disk.sectors;
/* Get data */
#define EDIT(p, v, n, m) \
@@ -177,24 +173,23 @@ Xedit(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
EDIT("BIOS Ending sector", pp->esect, 1, maxsect);
#undef EDIT
/* Fix up off/size values */
- PRT_fix_BN(disk, pp, pn);
+ PRT_fix_BN(pp, pn);
/* Fix up CHS values for LBA */
- PRT_fix_CHS(disk, pp);
+ PRT_fix_CHS(pp);
} else {
- pp->bs = getuint(disk, "Partition offset", pp->bs,
- disk->size);
- pp->ns = getuint(disk, "Partition size", pp->ns,
- disk->size - pp->bs);
+ pp->bs = getuint("Partition offset", pp->bs,
+ disk.size);
+ pp->ns = getuint("Partition size", pp->ns,
+ disk.size - pp->bs);
/* Fix up CHS values */
- PRT_fix_CHS(disk, pp);
+ PRT_fix_CHS(pp);
}
return (ret);
}
int
-Xsetpid(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
- int offset)
+Xsetpid(char *args, struct mbr *mbr, struct mbr *tt, int offset)
{
const char *errstr;
int pn, num;
@@ -222,8 +217,7 @@ Xsetpid(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
}
int
-Xselect(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
- int offset)
+Xselect(char *args, struct mbr *mbr, struct mbr *tt, int offset)
{
const char *errstr;
static int firstoff = 0;
@@ -257,17 +251,16 @@ Xselect(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
}
/* Recursion is beautiful! */
- USER_edit(disk, tt, off, firstoff);
+ USER_edit(tt, off, firstoff);
return (CMD_CONT);
}
int
-Xprint(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
- int offset)
+Xprint(char *args, struct mbr *mbr, struct mbr *tt, int offset)
{
- DISK_printgeometry(disk, args);
+ DISK_printgeometry(args);
printf("Offset: %d\t", offset);
MBR_print(mbr, args);
@@ -275,8 +268,7 @@ Xprint(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
}
int
-Xwrite(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
- int offset)
+Xwrite(char *args, struct mbr *mbr, struct mbr *tt, int offset)
{
struct dos_mbr dos_mbr;
int fd, i, n;
@@ -290,7 +282,7 @@ Xwrite(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
return (CMD_CONT);
}
- fd = DISK_open(disk->name, O_RDWR);
+ fd = DISK_open(disk.name, O_RDWR);
MBR_make(mbr, &dos_mbr);
printf("Writing MBR at offset %d.\n", offset);
@@ -304,10 +296,10 @@ Xwrite(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
/* Make sure GPT doesn't get in the way. */
if (reinited)
- MBR_zapgpt(fd, &dos_mbr, disk->size - 1);
+ MBR_zapgpt(fd, &dos_mbr, disk.size - 1);
/* Refresh in memory copy to reflect what was just written. */
- MBR_parse(disk, &dos_mbr, mbr->offset, mbr->reloffset, mbr);
+ MBR_parse(&dos_mbr, mbr->offset, mbr->reloffset, mbr);
close(fd);
@@ -315,29 +307,25 @@ Xwrite(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
}
int
-Xquit(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
- int offset)
+Xquit(char *args, struct mbr *mbr, struct mbr *tt, int offset)
{
return (CMD_SAVE);
}
int
-Xabort(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
- int offset)
+Xabort(char *args, struct mbr *mbr, struct mbr *tt, int offset)
{
exit(0);
}
int
-Xexit(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
- int offset)
+Xexit(char *args, struct mbr *mbr, struct mbr *tt, int offset)
{
return (CMD_EXIT);
}
int
-Xhelp(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
- int offset)
+Xhelp(char *args, struct mbr *mbr, struct mbr *tt, int offset)
{
int i;
@@ -347,8 +335,7 @@ Xhelp(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
}
int
-Xupdate(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
- int offset)
+Xupdate(char *args, struct mbr *mbr, struct mbr *tt, int offset)
{
/* Update code */
memcpy(mbr->code, tt->code, sizeof(mbr->code));
@@ -358,8 +345,7 @@ Xupdate(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
}
int
-Xflag(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
- int offset)
+Xflag(char *args, struct mbr *mbr, struct mbr *tt, int offset)
{
const char *errstr;
int i, pn = -1, val = -1;
@@ -400,8 +386,7 @@ Xflag(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
}
int
-Xmanual(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
- int offset)
+Xmanual(char *args, struct mbr *mbr, struct mbr *tt, int offset)
{
char *pager = "/usr/bin/less";
char *p;
diff --git a/sbin/fdisk/cmd.h b/sbin/fdisk/cmd.h
index 598032c9182..43f8bc34e75 100644
--- a/sbin/fdisk/cmd.h
+++ b/sbin/fdisk/cmd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.h,v 1.14 2015/03/14 15:21:53 krw Exp $ */
+/* $OpenBSD: cmd.h,v 1.15 2015/03/16 23:51:50 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -27,26 +27,25 @@
struct cmd {
char *cmd;
- int (*fcn)(char *, struct disk *, struct mbr *, struct mbr *,
- int);
+ int (*fcn)(char *, struct mbr *, struct mbr *, int);
char *help;
};
extern struct cmd cmd_table[];
-int Xreinit(char *, struct disk *, struct mbr *, struct mbr *, int);
-int Xdisk(char *, struct disk *, struct mbr *, struct mbr *, int);
-int Xmanual(char *, struct disk *, struct mbr *, struct mbr *, int);
-int Xedit(char *, struct disk *, struct mbr *, struct mbr *, int);
-int Xsetpid(char *, struct disk *, struct mbr *, struct mbr *, int);
-int Xselect(char *, struct disk *, struct mbr *, struct mbr *, int);
-int Xswap(char *, struct disk *, struct mbr *, struct mbr *, int);
-int Xprint(char *, struct disk *, struct mbr *, struct mbr *, int);
-int Xwrite(char *, struct disk *, struct mbr *, struct mbr *, int);
-int Xexit(char *, struct disk *, struct mbr *, struct mbr *, int);
-int Xquit(char *, struct disk *, struct mbr *, struct mbr *, int);
-int Xabort(char *, struct disk *, struct mbr *, struct mbr *, int);
-int Xhelp(char *, struct disk *, struct mbr *, struct mbr *, int);
-int Xflag(char *, struct disk *, struct mbr *, struct mbr *, int);
-int Xupdate(char *, struct disk *, struct mbr *, struct mbr *, int);
+int Xreinit(char *, struct mbr *, struct mbr *, int);
+int Xdisk(char *, struct mbr *, struct mbr *, int);
+int Xmanual(char *, struct mbr *, struct mbr *, int);
+int Xedit(char *, struct mbr *, struct mbr *, int);
+int Xsetpid(char *, struct mbr *, struct mbr *, int);
+int Xselect(char *, struct mbr *, struct mbr *, int);
+int Xswap(char *, struct mbr *, struct mbr *, int);
+int Xprint(char *, struct mbr *, struct mbr *, int);
+int Xwrite(char *, struct mbr *, struct mbr *, int);
+int Xexit(char *, struct mbr *, struct mbr *, int);
+int Xquit(char *, struct mbr *, struct mbr *, int);
+int Xabort(char *, struct mbr *, struct mbr *, int);
+int Xhelp(char *, struct mbr *, struct mbr *, int);
+int Xflag(char *, struct mbr *, struct mbr *, int);
+int Xupdate(char *, struct mbr *, struct mbr *, int);
#endif /* _CMD_H */
diff --git a/sbin/fdisk/disk.c b/sbin/fdisk/disk.c
index 8f9fe533ed9..cbea7fd3c47 100644
--- a/sbin/fdisk/disk.c
+++ b/sbin/fdisk/disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disk.c,v 1.44 2015/03/14 18:32:29 krw Exp $ */
+/* $OpenBSD: disk.c,v 1.45 2015/03/16 23:51:50 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -32,6 +32,7 @@
#include "disk.h"
#include "misc.h"
+struct disk disk;
struct disklabel dl;
int
@@ -52,29 +53,29 @@ DISK_open(char *disk, int mode)
}
void
-DISK_getlabelgeometry(struct disk *disk)
+DISK_getlabelgeometry(void)
{
u_int64_t sz, spc;
int fd;
/* Get label geometry. */
- if ((fd = DISK_open(disk->name, O_RDONLY)) != -1) {
+ if ((fd = DISK_open(disk.name, O_RDONLY)) != -1) {
if (ioctl(fd, DIOCGPDINFO, &dl) == -1) {
warn("DIOCGPDINFO");
} else {
- disk->cylinders = dl.d_ncylinders;
- disk->heads = dl.d_ntracks;
- disk->sectors = dl.d_nsectors;
+ disk.cylinders = dl.d_ncylinders;
+ disk.heads = dl.d_ntracks;
+ disk.sectors = dl.d_nsectors;
/* MBR handles only first UINT32_MAX sectors. */
- spc = (u_int64_t)disk->heads * disk->sectors;
+ spc = (u_int64_t)disk.heads * disk.sectors;
sz = DL_GETDSIZE(&dl);
if (sz > UINT32_MAX) {
- disk->cylinders = UINT32_MAX / spc;
- disk->size = disk->cylinders * spc;
+ disk.cylinders = UINT32_MAX / spc;
+ disk.size = disk.cylinders * spc;
warnx("disk too large (%llu sectors)."
" size truncated.", sz);
} else
- disk->size = sz;
+ disk.size = sz;
unit_types[SECTORS].conversion = dl.d_secsize;
}
close(fd);
@@ -86,18 +87,18 @@ DISK_getlabelgeometry(struct disk *disk)
* to indicate the units that should be used for display.
*/
int
-DISK_printgeometry(struct disk *disk, char *units)
+DISK_printgeometry(char *units)
{
const int secsize = unit_types[SECTORS].conversion;
double size;
int i;
i = unit_lookup(units);
- size = ((double)disk->size * secsize) / unit_types[i].conversion;
- printf("Disk: %s\t", disk->name);
- if (disk->size) {
- printf("geometry: %d/%d/%d [%.0f ", disk->cylinders,
- disk->heads, disk->sectors, size);
+ size = ((double)disk.size * secsize) / unit_types[i].conversion;
+ printf("Disk: %s\t", disk.name);
+ if (disk.size) {
+ printf("geometry: %d/%d/%d [%.0f ", disk.cylinders,
+ disk.heads, disk.sectors, size);
if (i == SECTORS && secsize != sizeof(struct dos_mbr))
printf("%d-byte ", secsize);
printf("%s]\n", unit_types[i].lname);
diff --git a/sbin/fdisk/disk.h b/sbin/fdisk/disk.h
index 1affb693e7c..64cb9a92024 100644
--- a/sbin/fdisk/disk.h
+++ b/sbin/fdisk/disk.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: disk.h,v 1.17 2015/03/14 15:21:53 krw Exp $ */
+/* $OpenBSD: disk.h,v 1.18 2015/03/16 23:51:50 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -28,9 +28,10 @@ struct disk {
};
int DISK_open(char *, int);
-void DISK_getlabelgeometry(struct disk *);
-int DISK_printgeometry(struct disk *, char *);
+void DISK_getlabelgeometry(void);
+int DISK_printgeometry(char *);
+extern struct disk disk;
extern struct disklabel dl;
#endif /* _DISK_H */
diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c
index 9afd33a6223..b8d49456dc7 100644
--- a/sbin/fdisk/fdisk.c
+++ b/sbin/fdisk/fdisk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdisk.c,v 1.68 2015/03/16 18:45:51 krw Exp $ */
+/* $OpenBSD: fdisk.c,v 1.69 2015/03/16 23:51:50 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -70,7 +70,6 @@ main(int argc, char *argv[])
int ch, fd, error;
int i_flag = 0, e_flag = 0, u_flag = 0;
int c_arg = 0, h_arg = 0, s_arg = 0;
- struct disk disk;
u_int32_t l_arg = 0;
char *query;
#ifdef HAS_MBR
@@ -146,7 +145,7 @@ main(int argc, char *argv[])
}
/* Start with the disklabel geometry and get the sector size. */
- DISK_getlabelgeometry(&disk);
+ DISK_getlabelgeometry();
if (c_arg | h_arg | s_arg) {
/* Use supplied geometry if it is completely specified. */
@@ -172,7 +171,7 @@ main(int argc, char *argv[])
/* Print out current MBRs on disk */
if ((i_flag + u_flag + e_flag) == 0)
- USER_print_disk(&disk);
+ USER_print_disk();
/* Parse mbr template, to pass on later */
if (mbrfile != NULL && (fd = open(mbrfile, O_RDONLY)) == -1) {
@@ -188,21 +187,21 @@ main(int argc, char *argv[])
err(1, "Unable to read MBR");
close(fd);
}
- MBR_parse(&disk, &dos_mbr, 0, 0, &mbr);
+ MBR_parse(&dos_mbr, 0, 0, &mbr);
query = NULL;
if (i_flag) {
- MBR_init(&disk, &mbr);
+ MBR_init(&mbr);
query = "Do you wish to write new MBR and partition table?";
} else if (u_flag) {
- MBR_pcopy(&disk, &mbr);
+ MBR_pcopy(&mbr);
query = "Do you wish to write new MBR?";
}
if (query && ask_yn(query))
- Xwrite(NULL, &disk, &mbr, NULL, 0);
+ Xwrite(NULL, &mbr, NULL, 0);
if (e_flag)
- USER_edit(&disk, &mbr, 0, 0);
+ USER_edit(&mbr, 0, 0);
return (0);
}
diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c
index eb4dedd3544..f3d7de3c04a 100644
--- a/sbin/fdisk/mbr.c
+++ b/sbin/fdisk/mbr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbr.c,v 1.46 2015/03/14 18:32:29 krw Exp $ */
+/* $OpenBSD: mbr.c,v 1.47 2015/03/16 23:51:50 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -36,7 +36,7 @@
#include "mbr.h"
void
-MBR_init_GPT(struct disk *disk, struct mbr *mbr)
+MBR_init_GPT(struct mbr *mbr)
{
/* Initialize a protective MBR for GPT. */
bzero(&mbr->part, sizeof(mbr->part));
@@ -44,21 +44,21 @@ MBR_init_GPT(struct disk *disk, struct mbr *mbr)
/* Use whole disk, starting after MBR. */
mbr->part[0].id = DOSPTYP_EFI;
mbr->part[0].bs = 1;
- mbr->part[0].ns = disk->size - 1;
+ mbr->part[0].ns = disk.size - 1;
/* Fix up start/length fields. */
- PRT_fix_CHS(disk, &mbr->part[0]);
+ PRT_fix_CHS(&mbr->part[0]);
}
void
-MBR_init(struct disk *disk, struct mbr *mbr)
+MBR_init(struct mbr *mbr)
{
extern int g_flag;
u_int64_t adj;
daddr_t i;
if (g_flag) {
- MBR_init_GPT(disk, mbr);
+ MBR_init_GPT(mbr);
return;
}
@@ -72,23 +72,23 @@ MBR_init(struct disk *disk, struct mbr *mbr)
/* Use whole disk. Reserve first track, or first cyl, if possible. */
mbr->part[3].id = DOSPTYP_OPENBSD;
- if (disk->heads > 1)
+ if (disk.heads > 1)
mbr->part[3].shead = 1;
else
mbr->part[3].shead = 0;
- if (disk->heads < 2 && disk->cylinders > 1)
+ if (disk.heads < 2 && disk.cylinders > 1)
mbr->part[3].scyl = 1;
else
mbr->part[3].scyl = 0;
mbr->part[3].ssect = 1;
/* Go right to the end */
- mbr->part[3].ecyl = disk->cylinders - 1;
- mbr->part[3].ehead = disk->heads - 1;
- mbr->part[3].esect = disk->sectors;
+ mbr->part[3].ecyl = disk.cylinders - 1;
+ mbr->part[3].ehead = disk.heads - 1;
+ mbr->part[3].esect = disk.sectors;
/* Fix up start/length fields */
- PRT_fix_BN(disk, &mbr->part[3], 3);
+ PRT_fix_BN(&mbr->part[3], 3);
#if defined(__powerpc__) || defined(__mips__)
/* Now fix up for the MS-DOS boot partition on PowerPC. */
@@ -97,7 +97,7 @@ MBR_init(struct disk *disk, struct mbr *mbr)
mbr->part[3].ns += mbr->part[3].bs;
mbr->part[3].bs = mbr->part[0].bs + mbr->part[0].ns;
mbr->part[3].ns -= mbr->part[3].bs;
- PRT_fix_CHS(disk, &mbr->part[3]);
+ PRT_fix_CHS(&mbr->part[3]);
if ((mbr->part[3].shead != 1) || (mbr->part[3].ssect != 1)) {
/* align the partition on a cylinder boundary */
mbr->part[3].shead = 0;
@@ -105,7 +105,7 @@ MBR_init(struct disk *disk, struct mbr *mbr)
mbr->part[3].scyl += 1;
}
/* Fix up start/length fields */
- PRT_fix_BN(disk, &mbr->part[3], 3);
+ PRT_fix_BN(&mbr->part[3], 3);
#endif
/* Start OpenBSD MBR partition on a power of 2 block number. */
@@ -115,12 +115,11 @@ MBR_init(struct disk *disk, struct mbr *mbr)
adj = DL_BLKTOSEC(&dl, i) - mbr->part[3].bs;
mbr->part[3].bs += adj;
mbr->part[3].ns -= adj;
- PRT_fix_CHS(disk, &mbr->part[3]);
+ PRT_fix_CHS(&mbr->part[3]);
}
void
-MBR_parse(struct disk *disk, struct dos_mbr *dos_mbr, off_t offset,
- off_t reloff, struct mbr *mbr)
+MBR_parse(struct dos_mbr *dos_mbr, off_t offset, off_t reloff, struct mbr *mbr)
{
struct dos_partition dos_parts[NDOSPART];
int i;
@@ -133,7 +132,7 @@ MBR_parse(struct disk *disk, struct dos_mbr *dos_mbr, off_t offset,
memcpy(dos_parts, dos_mbr->dmbr_parts, sizeof(dos_parts));
for (i = 0; i < NDOSPART; i++)
- PRT_parse(disk, &dos_parts[i], offset, reloff, &mbr->part[i]);
+ PRT_parse(&dos_parts[i], offset, reloff, &mbr->part[i]);
}
void
@@ -209,13 +208,13 @@ MBR_write(int fd, off_t where, struct dos_mbr *dos_mbr)
* untouched.
*/
void
-MBR_pcopy(struct disk *disk, struct mbr *mbr)
+MBR_pcopy(struct mbr *mbr)
{
struct dos_partition dos_parts[NDOSPART];
struct dos_mbr dos_mbr;
int i, fd, error;
- fd = DISK_open(disk->name, O_RDONLY);
+ fd = DISK_open(disk.name, O_RDONLY);
error = MBR_read(fd, 0, &dos_mbr);
close(fd);
@@ -225,7 +224,7 @@ MBR_pcopy(struct disk *disk, struct mbr *mbr)
memcpy(dos_parts, dos_mbr.dmbr_parts, sizeof(dos_parts));
for (i = 0; i < NDOSPART; i++)
- PRT_parse(disk, &dos_parts[i], 0, 0, &mbr->part[i]);
+ PRT_parse(&dos_parts[i], 0, 0, &mbr->part[i]);
}
/*
diff --git a/sbin/fdisk/mbr.h b/sbin/fdisk/mbr.h
index fe388c3cdb6..567ac7975d8 100644
--- a/sbin/fdisk/mbr.h
+++ b/sbin/fdisk/mbr.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbr.h,v 1.19 2015/03/14 15:21:53 krw Exp $ */
+/* $OpenBSD: mbr.h,v 1.20 2015/03/16 23:51:50 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -29,12 +29,12 @@ struct mbr {
void MBR_print_disk(char *);
void MBR_print(struct mbr *, char *);
-void MBR_parse(struct disk *, struct dos_mbr *, off_t, off_t, struct mbr *);
+void MBR_parse(struct dos_mbr *, off_t, off_t, struct mbr *);
void MBR_make(struct mbr *, struct dos_mbr *);
-void MBR_init(struct disk *, struct mbr *);
+void MBR_init(struct mbr *);
int MBR_read(int, off_t, struct dos_mbr *);
int MBR_write(int, off_t, struct dos_mbr *);
-void MBR_pcopy(struct disk *, struct mbr *);
+void MBR_pcopy(struct mbr *);
char *MBR_readsector(int, off_t);
int MBR_writesector(int, char *, off_t);
void MBR_zapgpt(int, struct dos_mbr *, uint64_t);
diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c
index 7512bbdcc82..ad4c7a46aa4 100644
--- a/sbin/fdisk/misc.c
+++ b/sbin/fdisk/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.44 2015/03/14 18:32:29 krw Exp $ */
+/* $OpenBSD: misc.c,v 1.45 2015/03/16 23:51:50 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -192,7 +192,7 @@ ask_yn(const char *str)
* adapted from sbin/disklabel/editor.c
*/
u_int32_t
-getuint(struct disk *disk, char *prompt, u_int32_t oval, u_int32_t maxval)
+getuint(char *prompt, u_int32_t oval, u_int32_t maxval)
{
char buf[BUFSIZ], *endptr, *p, operator = '\0';
size_t n;
@@ -204,7 +204,7 @@ getuint(struct disk *disk, char *prompt, u_int32_t oval, u_int32_t maxval)
if (oval > maxval)
oval = maxval;
- secpercyl = disk->sectors * disk->heads;
+ secpercyl = disk.sectors * disk.heads;
do {
printf("%s: [%u] ", prompt, oval);
diff --git a/sbin/fdisk/misc.h b/sbin/fdisk/misc.h
index 6da2e8ef1b2..302c66dfaba 100644
--- a/sbin/fdisk/misc.h
+++ b/sbin/fdisk/misc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.h,v 1.23 2015/03/14 15:21:53 krw Exp $ */
+/* $OpenBSD: misc.h,v 1.24 2015/03/16 23:51:50 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -33,6 +33,6 @@ int ask_cmd(char **, char **);
int ask_num(const char *, int, int, int);
int ask_pid(int);
int ask_yn(const char *);
-u_int32_t getuint(struct disk *, char *, u_int32_t, u_int32_t);
+u_int32_t getuint(char *, u_int32_t, u_int32_t);
#endif /* _MISC_H */
diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c
index dae423cf997..50173f680cd 100644
--- a/sbin/fdisk/part.c
+++ b/sbin/fdisk/part.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: part.c,v 1.68 2015/03/14 18:32:29 krw Exp $ */
+/* $OpenBSD: part.c,v 1.69 2015/03/16 23:51:50 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -166,8 +166,8 @@ PRT_ascii_id(int id)
}
void
-PRT_parse(struct disk *disk, struct dos_partition *prt, off_t offset,
- off_t reloff, struct prt *partn)
+PRT_parse(struct dos_partition *prt, off_t offset, off_t reloff,
+ struct prt *partn)
{
off_t off;
u_int32_t t;
@@ -198,7 +198,7 @@ PRT_parse(struct disk *disk, struct dos_partition *prt, off_t offset,
partn->ns = letoh32(t);
#endif
- PRT_fix_CHS(disk, partn);
+ PRT_fix_CHS(partn);
}
int
@@ -296,7 +296,7 @@ PRT_print(int num, struct prt *partn, char *units)
}
void
-PRT_fix_BN(struct disk *disk, struct prt *part, int pn)
+PRT_fix_BN(struct prt *part, int pn)
{
u_int32_t spt, tpc, spc;
u_int32_t start = 0;
@@ -309,8 +309,8 @@ PRT_fix_BN(struct disk *disk, struct prt *part, int pn)
}
/* Disk geometry. */
- spt = disk->sectors;
- tpc = disk->heads;
+ spt = disk.sectors;
+ tpc = disk.heads;
spc = spt * tpc;
start += part->scyl * spc;
@@ -330,7 +330,7 @@ PRT_fix_BN(struct disk *disk, struct prt *part, int pn)
}
void
-PRT_fix_CHS(struct disk *disk, struct prt *part)
+PRT_fix_CHS(struct prt *part)
{
u_int32_t spt, tpc, spc;
u_int32_t start, end, size;
@@ -343,8 +343,8 @@ PRT_fix_CHS(struct disk *disk, struct prt *part)
}
/* Disk geometry. */
- spt = disk->sectors;
- tpc = disk->heads;
+ spt = disk.sectors;
+ tpc = disk.heads;
spc = spt * tpc;
start = part->bs;
diff --git a/sbin/fdisk/part.h b/sbin/fdisk/part.h
index 5d5adecd672..1c16f7f02f8 100644
--- a/sbin/fdisk/part.h
+++ b/sbin/fdisk/part.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: part.h,v 1.17 2015/03/14 15:21:53 krw Exp $ */
+/* $OpenBSD: part.h,v 1.18 2015/03/16 23:51:50 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -30,15 +30,15 @@ struct prt {
void PRT_printall(void);
const char *PRT_ascii_id(int);
-void PRT_parse(struct disk *, struct dos_partition *, off_t, off_t,
+void PRT_parse(struct dos_partition *, off_t, off_t,
struct prt *);
void PRT_make(struct prt *, off_t, off_t, struct dos_partition *);
void PRT_print(int, struct prt *, char *);
/* This does CHS -> bs/ns */
-void PRT_fix_BN(struct disk *, struct prt *, int);
+void PRT_fix_BN(struct prt *, int);
/* This does bs/ns -> CHS */
-void PRT_fix_CHS(struct disk *, struct prt *);
+void PRT_fix_CHS(struct prt *);
#endif /* _PART_H */
diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c
index adb35898e78..082a11bfd33 100644
--- a/sbin/fdisk/user.c
+++ b/sbin/fdisk/user.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: user.c,v 1.39 2015/03/16 18:45:51 krw Exp $ */
+/* $OpenBSD: user.c,v 1.40 2015/03/16 23:51:50 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -55,7 +55,7 @@ struct cmd cmd_table[] = {
int modified;
void
-USER_edit(struct disk *disk, struct mbr *tt, off_t offset, off_t reloff)
+USER_edit(struct mbr *tt, off_t offset, off_t reloff)
{
static int editlevel;
struct dos_mbr dos_mbr;
@@ -67,14 +67,14 @@ USER_edit(struct disk *disk, struct mbr *tt, off_t offset, off_t reloff)
editlevel += 1;
/* Read MBR & partition */
- fd = DISK_open(disk->name, O_RDONLY);
+ fd = DISK_open(disk.name, O_RDONLY);
error = MBR_read(fd, offset, &dos_mbr);
close(fd);
if (error == -1)
goto done;
/* Parse the sucker */
- MBR_parse(disk, &dos_mbr, offset, reloff, &mbr);
+ MBR_parse(&dos_mbr, offset, reloff, &mbr);
printf("Enter 'help' for information\n");
@@ -102,7 +102,7 @@ again:
}
/* Call function */
- st = cmd_table[i].fcn(args, disk, &mbr, tt, offset);
+ st = cmd_table[i].fcn(args, &mbr, tt, offset);
/* Update status */
if (st == CMD_EXIT)
@@ -118,7 +118,7 @@ again:
/* Write out MBR */
if (modified) {
if (st == CMD_SAVE) {
- if (Xwrite(NULL, disk, &mbr, NULL, offset) == CMD_CONT)
+ if (Xwrite(NULL, &mbr, NULL, offset) == CMD_CONT)
goto again;
close(fd);
} else
@@ -131,23 +131,23 @@ done:
}
void
-USER_print_disk(struct disk *disk)
+USER_print_disk(void)
{
off_t offset, firstoff;
int fd, i, error;
struct dos_mbr dos_mbr;
struct mbr mbr;
- fd = DISK_open(disk->name, O_RDONLY);
+ fd = DISK_open(disk.name, O_RDONLY);
offset = firstoff = 0;
- DISK_printgeometry(disk, NULL);
+ DISK_printgeometry(NULL);
do {
error = MBR_read(fd, offset, &dos_mbr);
if (error == -1)
break;
- MBR_parse(disk, &dos_mbr, offset, firstoff, &mbr);
+ MBR_parse(&dos_mbr, offset, firstoff, &mbr);
printf("Offset: %lld\t", offset);
MBR_print(&mbr, NULL);
diff --git a/sbin/fdisk/user.h b/sbin/fdisk/user.h
index 85d12e3552c..e74885303f2 100644
--- a/sbin/fdisk/user.h
+++ b/sbin/fdisk/user.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: user.h,v 1.14 2015/03/16 18:45:51 krw Exp $ */
+/* $OpenBSD: user.h,v 1.15 2015/03/16 23:51:50 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -20,7 +20,7 @@
#define _USER_H
/* Prototypes */
-void USER_edit(struct disk *, struct mbr *, off_t, off_t);
-void USER_print_disk(struct disk *);
+void USER_edit(struct mbr *, off_t, off_t);
+void USER_print_disk(void);
#endif /* _USER_H */