From: krw Date: Mon, 12 Jul 2021 22:18:54 +0000 (+0000) Subject: Toss 'const' in anywhere the compiler doesn't complain about, thus identifying X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=859be6c9dfba1dab8e7f1036d24b90c365c59bec;p=openbsd Toss 'const' in anywhere the compiler doesn't complain about, thus identifying places that *should* be const but currently aren't and preventing the rot from spreading further while those issues are dealt with. No functional change. --- diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index 473eb9d52c7..60984d530ef 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.125 2021/07/12 18:31:53 krw Exp $ */ +/* $OpenBSD: cmd.c,v 1.126 2021/07/12 22:18:54 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -35,14 +35,14 @@ #include "user.h" #include "cmd.h" -int gedit(int); -int edit(int, struct mbr *); -int gsetpid(int); -int setpid(int, struct mbr *); -int parsepn(char *); +int gedit(const int); +int edit(const int, struct mbr *); +int gsetpid(const int); +int setpid(const int, struct mbr *); +int parsepn(const char *); int ask_num(const char *, int, int, int); -int ask_pid(int, struct uuid *); +int ask_pid(const int, struct uuid *); char *ask_string(const char *, const char *); extern const unsigned char manpage[]; @@ -152,7 +152,7 @@ Xswap(char *args, struct mbr *mbr) } int -gedit(int pn) +gedit(const int pn) { struct gpt_partition oldgg; struct gpt_partition *gg; @@ -207,7 +207,7 @@ gedit(int pn) } int -parsepn(char *pnstr) +parsepn(const char *pnstr) { const char *errstr; int maxpn, pn; @@ -232,7 +232,7 @@ parsepn(char *pnstr) } int -edit(int pn, struct mbr *mbr) +edit(const int pn, struct mbr *mbr) { struct prt oldpp; struct prt *pp; @@ -641,7 +641,7 @@ ask_num(const char *str, int dflt, int low, int high) } int -ask_pid(int dflt, struct uuid *guid) +ask_pid(const int dflt, struct uuid *guid) { char lbuf[100], *cp; int num = -1, status; diff --git a/sbin/fdisk/cmd.h b/sbin/fdisk/cmd.h index 1954b55048a..ffa270133fa 100644 --- a/sbin/fdisk/cmd.h +++ b/sbin/fdisk/cmd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.h,v 1.22 2021/07/12 18:31:53 krw Exp $ */ +/* $OpenBSD: cmd.h,v 1.23 2021/07/12 22:18:54 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -31,7 +31,7 @@ struct cmd { int (*cmd_fcn)(char *, struct mbr *); char *cmd_help; }; -extern struct cmd cmd_table[]; +extern const struct cmd cmd_table[]; int Xreinit(char *, struct mbr *); int Xdisk(char *, struct mbr *); diff --git a/sbin/fdisk/disk.c b/sbin/fdisk/disk.c index 4349aa90f4b..00952c1b108 100644 --- a/sbin/fdisk/disk.c +++ b/sbin/fdisk/disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disk.c,v 1.61 2021/07/12 18:31:53 krw Exp $ */ +/* $OpenBSD: disk.c,v 1.62 2021/07/12 22:18:54 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -38,7 +38,7 @@ struct disk disk; struct disklabel dl; void -DISK_open(int rw) +DISK_open(const int rw) { struct stat st; uint64_t sz, spc; @@ -84,7 +84,7 @@ DISK_open(int rw) * to indicate the units that should be used for display. */ int -DISK_printgeometry(char *units) +DISK_printgeometry(const char *units) { const int secsize = unit_types[SECTORS].ut_conversion; double size; @@ -146,7 +146,7 @@ DISK_readsector(off_t where) * errno if the write fails. */ int -DISK_writesector(char *secbuf, off_t where) +DISK_writesector(const char *secbuf, off_t where) { int secsize; ssize_t len; diff --git a/sbin/fdisk/disk.h b/sbin/fdisk/disk.h index cb5267fd594..928be0942e8 100644 --- a/sbin/fdisk/disk.h +++ b/sbin/fdisk/disk.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disk.h,v 1.25 2021/07/12 14:06:19 krw Exp $ */ +/* $OpenBSD: disk.h,v 1.26 2021/07/12 22:18:54 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -31,10 +31,10 @@ struct disk { /* Align partition starts/sizes on 32K-byte boundaries. */ #define BLOCKALIGNMENT 64 -void DISK_open(int); -int DISK_printgeometry(char *); +void DISK_open(const int); +int DISK_printgeometry(const char *); char *DISK_readsector(off_t); -int DISK_writesector(char *, off_t); +int DISK_writesector(const char *, off_t); extern struct disk disk; extern struct disklabel dl; diff --git a/sbin/fdisk/gpt.c b/sbin/fdisk/gpt.c index bb867bd7c3f..0ad0585136b 100644 --- a/sbin/fdisk/gpt.c +++ b/sbin/fdisk/gpt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpt.c,v 1.39 2021/07/12 18:31:53 krw Exp $ */ +/* $OpenBSD: gpt.c,v 1.40 2021/07/12 22:18:54 krw Exp $ */ /* * Copyright (c) 2015 Markus Muller * Copyright (c) 2015 Kenneth R Westerback @@ -46,14 +46,14 @@ struct gpt_partition **sort_gpt(void); int lba_start_cmp(const void *e1, const void *e2); int lba_free(uint64_t *, uint64_t *); int add_partition(const uint8_t *, const char *, uint64_t); -int get_header(off_t); +int get_header(const off_t); int get_partition_table(void); int init_gh(void); -int init_gp(int, uint32_t); +int init_gp(const int, const uint32_t); uint32_t crc32(const u_char *, const uint32_t); int -get_header(off_t where) +get_header(const off_t where) { char *secbuf; uint64_t partlastlba, partslen, lba_end; @@ -203,7 +203,7 @@ get_partition_table(void) } void -GPT_read(int which) +GPT_read(const int which) { int valid; @@ -234,7 +234,7 @@ GPT_read(int which) } void -GPT_print(char *units, int verbosity) +GPT_print(const char *units, const int verbosity) { const int secsize = unit_types[SECTORS].ut_conversion; struct uuid guid; @@ -271,7 +271,7 @@ GPT_print(char *units, int verbosity) } void -GPT_print_parthdr(int verbosity) +GPT_print_parthdr(const int verbosity) { printf(" #: type " " [ start: size ]\n"); @@ -282,7 +282,7 @@ GPT_print_parthdr(int verbosity) } void -GPT_print_part(int n, char *units, int verbosity) +GPT_print_part(const int n, const char *units, const int verbosity) { struct uuid guid; struct gpt_partition *partn = &gp[n]; @@ -414,7 +414,7 @@ init_gh(void) } int -init_gp(int how, uint32_t bootsectors) +init_gp(const int how, const uint32_t bootsectors) { struct gpt_partition oldgp[NGPTPARTITIONS]; const uint8_t gpt_uuid_efi_system[] = GPT_UUID_EFI_SYSTEM; @@ -447,7 +447,7 @@ init_gp(int how, uint32_t bootsectors) } int -GPT_init(int how, uint32_t bootsectors) +GPT_init(const int how, const uint32_t bootsectors) { int rslt = 0; @@ -651,7 +651,7 @@ lba_free(uint64_t *start, uint64_t *end) } int -GPT_get_lba_start(unsigned int pn) +GPT_get_lba_start(const unsigned int pn) { uint64_t bs; unsigned int i; @@ -689,7 +689,7 @@ GPT_get_lba_start(unsigned int pn) } int -GPT_get_lba_end(unsigned int pn) +GPT_get_lba_end(const unsigned int pn) { struct gpt_partition **sgp; uint64_t bs, nextbs, ns; diff --git a/sbin/fdisk/gpt.h b/sbin/fdisk/gpt.h index 659dbf19c23..7a87f533222 100644 --- a/sbin/fdisk/gpt.h +++ b/sbin/fdisk/gpt.h @@ -1,4 +1,4 @@ -/* $OpenBSD: gpt.h,v 1.14 2021/07/11 13:23:18 krw Exp $ */ +/* $OpenBSD: gpt.h,v 1.15 2021/07/12 22:18:54 krw Exp $ */ /* * Copyright (c) 2015 Markus Muller * Copyright (c) 2015 Kenneth R Westerback @@ -16,16 +16,16 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -void GPT_read(int); -int GPT_get_lba_start(unsigned int); -int GPT_get_lba_end(unsigned int); +void GPT_read(const int); +int GPT_get_lba_start(const unsigned int); +int GPT_get_lba_end(const unsigned int); -int GPT_init(int, uint32_t); +int GPT_init(const int, const uint32_t); int GPT_write(void); void GPT_zap_headers(void); -void GPT_print(char *, int); -void GPT_print_part(int, char *, int); -void GPT_print_parthdr(int); +void GPT_print(const char *, const int); +void GPT_print_part(const int, const char *, const int); +void GPT_print_parthdr(const int); extern struct gpt_header gh; extern struct gpt_partition gp[NGPTPARTITIONS]; diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c index e4ada994bb3..328d8536106 100644 --- a/sbin/fdisk/mbr.c +++ b/sbin/fdisk/mbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.c,v 1.83 2021/07/12 14:06:19 krw Exp $ */ +/* $OpenBSD: mbr.c,v 1.84 2021/07/12 22:18:54 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -157,8 +157,8 @@ MBR_init(struct mbr *mbr) } void -MBR_parse(struct dos_mbr *dos_mbr, off_t lba_self, off_t lba_firstembr, - struct mbr *mbr) +MBR_parse(const struct dos_mbr *dos_mbr, const off_t lba_self, + const off_t lba_firstembr, struct mbr *mbr) { struct dos_partition dos_parts[NDOSPART]; int i; @@ -193,7 +193,7 @@ MBR_make(struct mbr *mbr, struct dos_mbr *dos_mbr) } void -MBR_print(struct mbr *mbr, char *units) +MBR_print(const struct mbr *mbr, const char *units) { int i; @@ -210,7 +210,7 @@ MBR_print(struct mbr *mbr, char *units) } int -MBR_read(off_t where, struct dos_mbr *dos_mbr) +MBR_read(const off_t where, struct dos_mbr *dos_mbr) { char *secbuf; @@ -225,7 +225,7 @@ MBR_read(off_t where, struct dos_mbr *dos_mbr) } int -MBR_write(off_t where, struct dos_mbr *dos_mbr) +MBR_write(const off_t where, const struct dos_mbr *dos_mbr) { char *secbuf; diff --git a/sbin/fdisk/mbr.h b/sbin/fdisk/mbr.h index 7fb39efc05a..2387e4b011a 100644 --- a/sbin/fdisk/mbr.h +++ b/sbin/fdisk/mbr.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.h,v 1.33 2021/07/11 19:43:19 krw Exp $ */ +/* $OpenBSD: mbr.h,v 1.34 2021/07/12 22:18:54 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -29,13 +29,14 @@ struct mbr { extern struct mbr initial_mbr; -void MBR_print(struct mbr *, char *); -void MBR_parse(struct dos_mbr *, off_t, off_t, struct mbr *); +void MBR_print(const struct mbr *, const char *); +void MBR_parse(const struct dos_mbr *, const off_t, const off_t, + struct mbr *); void MBR_make(struct mbr *, struct dos_mbr *); void MBR_init(struct mbr *); void MBR_init_GPT(struct mbr *); -int MBR_read(off_t, struct dos_mbr *); -int MBR_write(off_t, struct dos_mbr *); +int MBR_read(const off_t, struct dos_mbr *); +int MBR_write(const off_t, const struct dos_mbr *); int MBR_protective_mbr(struct mbr *); #endif /* _MBR_H */ diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c index a57c6cc0392..0ca8896b261 100644 --- a/sbin/fdisk/misc.c +++ b/sbin/fdisk/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.74 2021/07/12 18:31:53 krw Exp $ */ +/* $OpenBSD: misc.c,v 1.75 2021/07/12 22:18:54 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -43,7 +43,7 @@ struct unit_type unit_types[] = { }; int -unit_lookup(char *units) +unit_lookup(const char *units) { int i = 0; @@ -63,7 +63,7 @@ unit_lookup(char *units) } int -string_from_line(char *buf, size_t buflen) +string_from_line(char *buf, const size_t buflen) { static char *line; static size_t sz; @@ -107,7 +107,8 @@ ask_yn(const char *str) * adapted from sbin/disklabel/editor.c */ uint64_t -getuint64(char *prompt, uint64_t oval, uint64_t minval, uint64_t maxval) +getuint64(const char *prompt, uint64_t oval, const uint64_t minval, + const uint64_t maxval) { char buf[BUFSIZ], *endptr, *p, operator = '\0'; const int secsize = unit_types[SECTORS].ut_conversion; diff --git a/sbin/fdisk/misc.h b/sbin/fdisk/misc.h index 648936856b2..9acfba50b6c 100644 --- a/sbin/fdisk/misc.h +++ b/sbin/fdisk/misc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.h,v 1.38 2021/07/11 13:51:42 krw Exp $ */ +/* $OpenBSD: misc.h,v 1.39 2021/07/12 22:18:54 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -20,18 +20,18 @@ #define _MISC_H struct unit_type { - char *abbr; - int64_t conversion; - char *lname; + char *ut_abbr; + int64_t ut_conversion; + char *ut_lname; }; extern struct unit_type unit_types[]; #define SECTORS 1 /* Prototypes */ -int unit_lookup(char *); -int string_from_line(char *, size_t); +int unit_lookup(const char *); +int string_from_line(char *, const size_t); int ask_yn(const char *); -uint64_t getuint64(char *, uint64_t, uint64_t, uint64_t); +uint64_t getuint64(const char *, uint64_t, const uint64_t, const uint64_t); char *utf16le_to_string(const uint16_t *); uint16_t *string_to_utf16le(const char *); diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c index ab974e266d1..40783e12c78 100644 --- a/sbin/fdisk/part.c +++ b/sbin/fdisk/part.c @@ -1,4 +1,4 @@ -/* $OpenBSD: part.c,v 1.93 2021/07/12 18:31:53 krw Exp $ */ +/* $OpenBSD: part.c,v 1.94 2021/07/12 22:18:54 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -30,8 +30,8 @@ #include "misc.h" #include "part.h" -int check_chs(struct prt *); -const char *ascii_id(int); +int check_chs(const struct prt *); +const char *ascii_id(const int); static const struct part_type { int pt_type; @@ -157,7 +157,7 @@ static const struct protected_guid { #endif int -PRT_protected_guid(struct uuid *leuuid) +PRT_protected_guid(const struct uuid *leuuid) { struct uuid uuid; char *str = NULL; @@ -208,7 +208,7 @@ PRT_printall(void) } const char * -ascii_id(int id) +ascii_id(const int id) { static char unknown[] = ""; int i; @@ -222,8 +222,8 @@ ascii_id(int id) } void -PRT_parse(struct dos_partition *dp, off_t lba_self, off_t lba_firstembr, - struct prt *prt) +PRT_parse(const struct dos_partition *dp, const off_t lba_self, + const off_t lba_firstembr, struct prt *prt) { off_t off; uint32_t t; @@ -262,7 +262,7 @@ PRT_parse(struct dos_partition *dp, off_t lba_self, off_t lba_firstembr, } int -check_chs(struct prt *prt) +check_chs(const struct prt *prt) { if ( (prt->prt_shead > 255) || (prt->prt_ssect >63) || @@ -277,7 +277,7 @@ check_chs(struct prt *prt) } void -PRT_make(struct prt *prt, off_t lba_self, off_t lba_firstembr, +PRT_make(struct prt *prt, const off_t lba_self, const off_t lba_firstembr, struct dos_partition *dp) { off_t off; @@ -327,7 +327,7 @@ PRT_make(struct prt *prt, off_t lba_self, off_t lba_firstembr, } void -PRT_print(int num, struct prt *prt, char *units) +PRT_print(const int num, const struct prt *prt, const char *units) { const int secsize = unit_types[SECTORS].ut_conversion; double size; @@ -357,7 +357,7 @@ PRT_print(int num, struct prt *prt, char *units) } void -PRT_fix_BN(struct prt *prt, int pn) +PRT_fix_BN(struct prt *prt, const int pn) { uint32_t spt, tpc, spc; uint32_t start = 0; @@ -432,7 +432,7 @@ PRT_fix_CHS(struct prt *prt) } char * -PRT_uuid_to_typename(struct uuid *uuid) +PRT_uuid_to_typename(const struct uuid *uuid) { static char partition_type[UUID_STR_LEN + 1]; char *uuidstr = NULL; @@ -465,7 +465,7 @@ done: } int -PRT_uuid_to_type(struct uuid *uuid) +PRT_uuid_to_type(const struct uuid *uuid) { char *uuidstr; int entries, i, status, type; @@ -491,7 +491,7 @@ done: } struct uuid * -PRT_type_to_uuid(int type) +PRT_type_to_uuid(const int type) { static struct uuid guid; int i, entries, status = uuid_s_ok; diff --git a/sbin/fdisk/part.h b/sbin/fdisk/part.h index a6c61a4055d..a04f5d719d5 100644 --- a/sbin/fdisk/part.h +++ b/sbin/fdisk/part.h @@ -1,4 +1,4 @@ -/* $OpenBSD: part.h,v 1.26 2021/07/11 20:51:50 krw Exp $ */ +/* $OpenBSD: part.h,v 1.27 2021/07/12 22:18:54 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -29,17 +29,17 @@ struct prt { }; void PRT_printall(void); -void PRT_parse(struct dos_partition *, off_t, off_t, +void PRT_parse(const struct dos_partition *, const off_t, const off_t, struct prt *); -void PRT_make(struct prt *, off_t, off_t, struct dos_partition *); -void PRT_print(int, struct prt *, char *); -char *PRT_uuid_to_typename(struct uuid *); -int PRT_uuid_to_type(struct uuid *); -struct uuid *PRT_type_to_uuid(int); -int PRT_protected_guid(struct uuid *); +void PRT_make(struct prt *,const off_t, const off_t, struct dos_partition *); +void PRT_print(const int, const struct prt *, const char *); +char *PRT_uuid_to_typename(const struct uuid *); +int PRT_uuid_to_type(const struct uuid *); +struct uuid *PRT_type_to_uuid(const int); +int PRT_protected_guid(const struct uuid *); /* This does CHS -> bs/ns */ -void PRT_fix_BN(struct prt *, int); +void PRT_fix_BN(struct prt *, const int); /* This does bs/ns -> CHS */ void PRT_fix_CHS(struct prt *); diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c index ed375885dbd..faff7afe92e 100644 --- a/sbin/fdisk/user.c +++ b/sbin/fdisk/user.c @@ -1,4 +1,4 @@ -/* $OpenBSD: user.c,v 1.61 2021/07/12 18:31:53 krw Exp $ */ +/* $OpenBSD: user.c,v 1.62 2021/07/12 22:18:54 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -34,7 +34,7 @@ #include "disk.h" /* Our command table */ -struct cmd cmd_table[] = { +const struct cmd cmd_table[] = { {"help", 1, Xhelp, "Command help list"}, {"manual", 1, Xmanual, "Show entire OpenBSD man page for fdisk"}, {"reinit", 1, Xreinit, "Re-initialize loaded MBR (to defaults)"}, @@ -59,7 +59,7 @@ int modified; void ask_cmd(char **, char **); void -USER_edit(off_t offset, off_t reloff) +USER_edit(const off_t offset, const off_t reloff) { struct dos_mbr dos_mbr; struct mbr mbr; @@ -141,7 +141,7 @@ done: } void -USER_print_disk(int verbosity) +USER_print_disk(const int verbosity) { struct dos_mbr dos_mbr; struct mbr mbr;