diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2015-03-18 14:47:00 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2015-03-18 14:47:00 +0000 |
commit | 0b9e2b1cfec8a0b09290cf013863810bdb628d6a (patch) | |
tree | 690eecbe6b6dcfd96e77ad2b7b52f9c1dcaa3862 | |
parent | 48d9f1e388725c3bfe00a151f512708ca04fb70e (diff) |
Stop passing around little used 'struct mbr tt' parameter. Just
make the initial mbr that tt pointed at a global that can be directly
accessed in the couple of places it is needed.
Fewer parameters, less confusion, no functional change.
-rw-r--r-- | sbin/fdisk/cmd.c | 41 | ||||
-rw-r--r-- | sbin/fdisk/cmd.h | 34 | ||||
-rw-r--r-- | sbin/fdisk/fdisk.c | 14 | ||||
-rw-r--r-- | sbin/fdisk/mbr.c | 4 | ||||
-rw-r--r-- | sbin/fdisk/mbr.h | 4 | ||||
-rw-r--r-- | sbin/fdisk/user.c | 8 | ||||
-rw-r--r-- | sbin/fdisk/user.h | 4 |
7 files changed, 56 insertions, 53 deletions
diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index 67f72c66698..5821e1201fe 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.77 2015/03/17 21:42:15 krw Exp $ */ +/* $OpenBSD: cmd.c,v 1.78 2015/03/18 14:46:59 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -37,12 +37,11 @@ int reinited; int -Xreinit(char *args, struct mbr *mbr, struct mbr *tt) +Xreinit(char *args, struct mbr *mbr) { struct dos_mbr dos_mbr; - /* Copy template MBR */ - MBR_make(tt, &dos_mbr); + MBR_make(&initial_mbr, &dos_mbr); MBR_parse(&dos_mbr, mbr->offset, mbr->reloffset, mbr); MBR_init(mbr); @@ -58,7 +57,7 @@ Xreinit(char *args, struct mbr *mbr, struct mbr *tt) } int -Xdisk(char *args, struct mbr *mbr, struct mbr *tt) +Xdisk(char *args, struct mbr *mbr) { int maxcyl = 1024; int maxhead = 256; @@ -89,7 +88,7 @@ Xdisk(char *args, struct mbr *mbr, struct mbr *tt) } int -Xswap(char *args, struct mbr *mbr, struct mbr *tt) +Xswap(char *args, struct mbr *mbr) { const char *errstr; char *from, *to; @@ -128,7 +127,7 @@ Xswap(char *args, struct mbr *mbr, struct mbr *tt) } int -Xedit(char *args, struct mbr *mbr, struct mbr *tt) +Xedit(char *args, struct mbr *mbr) { const char *errstr; int pn, num, ret; @@ -142,7 +141,7 @@ Xedit(char *args, struct mbr *mbr, struct mbr *tt) pp = &mbr->part[pn]; /* Edit partition type */ - ret = Xsetpid(args, mbr, tt); + ret = Xsetpid(args, mbr); /* Unused, so just zero out */ if (pp->id == DOSPTYP_UNUSED) { @@ -189,7 +188,7 @@ Xedit(char *args, struct mbr *mbr, struct mbr *tt) } int -Xsetpid(char *args, struct mbr *mbr, struct mbr *tt) +Xsetpid(char *args, struct mbr *mbr) { const char *errstr; int pn, num; @@ -217,7 +216,7 @@ Xsetpid(char *args, struct mbr *mbr, struct mbr *tt) } int -Xselect(char *args, struct mbr *mbr, struct mbr *tt) +Xselect(char *args, struct mbr *mbr) { const char *errstr; static int firstoff = 0; @@ -251,13 +250,13 @@ Xselect(char *args, struct mbr *mbr, struct mbr *tt) } /* Recursion is beautiful! */ - USER_edit(tt, off, firstoff); + USER_edit(off, firstoff); return (CMD_CONT); } int -Xprint(char *args, struct mbr *mbr, struct mbr *tt) +Xprint(char *args, struct mbr *mbr) { DISK_printgeometry(args); @@ -268,7 +267,7 @@ Xprint(char *args, struct mbr *mbr, struct mbr *tt) } int -Xwrite(char *args, struct mbr *mbr, struct mbr *tt) +Xwrite(char *args, struct mbr *mbr) { struct dos_mbr dos_mbr; int fd, i, n; @@ -307,25 +306,25 @@ Xwrite(char *args, struct mbr *mbr, struct mbr *tt) } int -Xquit(char *args, struct mbr *mbr, struct mbr *tt) +Xquit(char *args, struct mbr *mbr) { return (CMD_SAVE); } int -Xabort(char *args, struct mbr *mbr, struct mbr *tt) +Xabort(char *args, struct mbr *mbr) { exit(0); } int -Xexit(char *args, struct mbr *mbr, struct mbr *tt) +Xexit(char *args, struct mbr *mbr) { return (CMD_EXIT); } int -Xhelp(char *args, struct mbr *mbr, struct mbr *tt) +Xhelp(char *args, struct mbr *mbr) { int i; @@ -335,17 +334,17 @@ Xhelp(char *args, struct mbr *mbr, struct mbr *tt) } int -Xupdate(char *args, struct mbr *mbr, struct mbr *tt) +Xupdate(char *args, struct mbr *mbr) { /* Update code */ - memcpy(mbr->code, tt->code, sizeof(mbr->code)); + memcpy(mbr->code, initial_mbr.code, sizeof(mbr->code)); mbr->signature = DOSMBR_SIGNATURE; printf("Machine code updated.\n"); return (CMD_DIRTY); } int -Xflag(char *args, struct mbr *mbr, struct mbr *tt) +Xflag(char *args, struct mbr *mbr) { const char *errstr; int i, pn = -1, val = -1; @@ -386,7 +385,7 @@ Xflag(char *args, struct mbr *mbr, struct mbr *tt) } int -Xmanual(char *args, struct mbr *mbr, struct mbr *tt) +Xmanual(char *args, struct mbr *mbr) { char *pager = "/usr/bin/less"; char *p; diff --git a/sbin/fdisk/cmd.h b/sbin/fdisk/cmd.h index a6fb5466009..9d478b64668 100644 --- a/sbin/fdisk/cmd.h +++ b/sbin/fdisk/cmd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.h,v 1.16 2015/03/17 21:42:15 krw Exp $ */ +/* $OpenBSD: cmd.h,v 1.17 2015/03/18 14:46:59 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -27,25 +27,25 @@ struct cmd { char *cmd; - int (*fcn)(char *, struct mbr *, struct mbr *); + int (*fcn)(char *, struct mbr *); char *help; }; extern struct cmd cmd_table[]; -int Xreinit(char *, struct mbr *, struct mbr *); -int Xdisk(char *, struct mbr *, struct mbr *); -int Xmanual(char *, struct mbr *, struct mbr *); -int Xedit(char *, struct mbr *, struct mbr *); -int Xsetpid(char *, struct mbr *, struct mbr *); -int Xselect(char *, struct mbr *, struct mbr *); -int Xswap(char *, struct mbr *, struct mbr *); -int Xprint(char *, struct mbr *, struct mbr *); -int Xwrite(char *, struct mbr *, struct mbr *); -int Xexit(char *, struct mbr *, struct mbr *); -int Xquit(char *, struct mbr *, struct mbr *); -int Xabort(char *, struct mbr *, struct mbr *); -int Xhelp(char *, struct mbr *, struct mbr *); -int Xflag(char *, struct mbr *, struct mbr *); -int Xupdate(char *, struct mbr *, struct mbr *); +int Xreinit(char *, struct mbr *); +int Xdisk(char *, struct mbr *); +int Xmanual(char *, struct mbr *); +int Xedit(char *, struct mbr *); +int Xsetpid(char *, struct mbr *); +int Xselect(char *, struct mbr *); +int Xswap(char *, struct mbr *); +int Xprint(char *, struct mbr *); +int Xwrite(char *, struct mbr *); +int Xexit(char *, struct mbr *); +int Xquit(char *, struct mbr *); +int Xabort(char *, struct mbr *); +int Xhelp(char *, struct mbr *); +int Xflag(char *, struct mbr *); +int Xupdate(char *, struct mbr *); #endif /* _CMD_H */ diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index b9da2a8394e..e2608eeb75e 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdisk.c,v 1.70 2015/03/17 21:42:15 krw Exp $ */ +/* $OpenBSD: fdisk.c,v 1.71 2015/03/18 14:46:59 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -173,7 +173,7 @@ main(int argc, char *argv[]) if ((i_flag + u_flag + e_flag) == 0) USER_print_disk(); - /* Parse mbr template, to pass on later */ + /* Create initial/default MBR. */ if (mbrfile != NULL && (fd = open(mbrfile, O_RDONLY)) == -1) { warn("%s", mbrfile); warnx("using builtin MBR"); @@ -187,21 +187,21 @@ main(int argc, char *argv[]) err(1, "Unable to read MBR"); close(fd); } - MBR_parse(&dos_mbr, 0, 0, &mbr); + MBR_parse(&dos_mbr, 0, 0, &initial_mbr); query = NULL; if (i_flag) { - MBR_init(&mbr); + MBR_init(&initial_mbr); query = "Do you wish to write new MBR and partition table?"; } else if (u_flag) { - MBR_pcopy(&mbr); + MBR_pcopy(&initial_mbr); query = "Do you wish to write new MBR?"; } if (query && ask_yn(query)) - Xwrite(NULL, &mbr, NULL); + Xwrite(NULL, &initial_mbr); if (e_flag) - USER_edit(&mbr, 0, 0); + USER_edit(0, 0); return (0); } diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c index f3d7de3c04a..c8f51e4585b 100644 --- a/sbin/fdisk/mbr.c +++ b/sbin/fdisk/mbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.c,v 1.47 2015/03/16 23:51:50 krw Exp $ */ +/* $OpenBSD: mbr.c,v 1.48 2015/03/18 14:46:59 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -35,6 +35,8 @@ #include "misc.h" #include "mbr.h" +struct mbr initial_mbr; + void MBR_init_GPT(struct mbr *mbr) { diff --git a/sbin/fdisk/mbr.h b/sbin/fdisk/mbr.h index 567ac7975d8..a73568f640e 100644 --- a/sbin/fdisk/mbr.h +++ b/sbin/fdisk/mbr.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.h,v 1.20 2015/03/16 23:51:50 krw Exp $ */ +/* $OpenBSD: mbr.h,v 1.21 2015/03/18 14:46:59 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -27,6 +27,8 @@ struct mbr { u_int16_t signature; }; +extern struct mbr initial_mbr; + void MBR_print_disk(char *); void MBR_print(struct mbr *, char *); void MBR_parse(struct dos_mbr *, off_t, off_t, struct mbr *); diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c index e4720b640f0..1a25339bd35 100644 --- a/sbin/fdisk/user.c +++ b/sbin/fdisk/user.c @@ -1,4 +1,4 @@ -/* $OpenBSD: user.c,v 1.41 2015/03/17 21:42:15 krw Exp $ */ +/* $OpenBSD: user.c,v 1.42 2015/03/18 14:46:59 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -55,7 +55,7 @@ struct cmd cmd_table[] = { int modified; void -USER_edit(struct mbr *tt, off_t offset, off_t reloff) +USER_edit(off_t offset, off_t reloff) { static int editlevel; struct dos_mbr dos_mbr; @@ -102,7 +102,7 @@ again: } /* Call function */ - st = cmd_table[i].fcn(args, &mbr, tt); + st = cmd_table[i].fcn(args, &mbr); /* Update status */ if (st == CMD_EXIT) @@ -118,7 +118,7 @@ again: /* Write out MBR */ if (modified) { if (st == CMD_SAVE) { - if (Xwrite(NULL, &mbr, NULL) == CMD_CONT) + if (Xwrite(NULL, &mbr) == CMD_CONT) goto again; close(fd); } else diff --git a/sbin/fdisk/user.h b/sbin/fdisk/user.h index e74885303f2..ded782f8ae9 100644 --- a/sbin/fdisk/user.h +++ b/sbin/fdisk/user.h @@ -1,4 +1,4 @@ -/* $OpenBSD: user.h,v 1.15 2015/03/16 23:51:50 krw Exp $ */ +/* $OpenBSD: user.h,v 1.16 2015/03/18 14:46:59 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -20,7 +20,7 @@ #define _USER_H /* Prototypes */ -void USER_edit(struct mbr *, off_t, off_t); +void USER_edit(off_t, off_t); void USER_print_disk(void); #endif /* _USER_H */ |