From: deraadt Date: Wed, 6 Oct 2021 00:40:39 +0000 (+0000) Subject: annotate all required sys/param.h uses with what they bring into scope, X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4874b543168b8168ff9788e98a56e3398af44a49;p=openbsd annotate all required sys/param.h uses with what they bring into scope, and delete all others. use PATH_MAX and other standardized symbols instead of prehistoric kernel-only names, create local MINIMUM/MAXIMUM macros where required, and directly include standard userland .h files as required. --- diff --git a/usr.sbin/makefs/ffs.c b/usr.sbin/makefs/ffs.c index 6ea3896c38f..26a59b35f5d 100644 --- a/usr.sbin/makefs/ffs.c +++ b/usr.sbin/makefs/ffs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs.c,v 1.33 2021/09/01 15:19:00 deraadt Exp $ */ +/* $OpenBSD: ffs.c,v 1.34 2021/10/06 00:40:39 deraadt Exp $ */ /* $NetBSD: ffs.c,v 1.66 2015/12/21 00:58:08 christos Exp $ */ /* @@ -66,6 +66,7 @@ * @(#)ffs_alloc.c 8.19 (Berkeley) 7/13/95 */ +#include /* roundup DEV_BSIZE */ #include #include @@ -75,6 +76,7 @@ #include #include #include +#include #include #include #include @@ -340,9 +342,9 @@ ffs_validate(const char *dir, fsnode *root, fsinfo_t *fsopts) if (fsopts->sectorsize == -1) fsopts->sectorsize = DFL_SECSIZE; if (ffs_opts->fsize == -1) - ffs_opts->fsize = MAX(DFL_FRAGSIZE, fsopts->sectorsize); + ffs_opts->fsize = MAXIMUM(DFL_FRAGSIZE, fsopts->sectorsize); if (ffs_opts->bsize == -1) - ffs_opts->bsize = MIN(DFL_BLKSIZE, 8 * ffs_opts->fsize); + ffs_opts->bsize = MINIMUM(DFL_BLKSIZE, 8 * ffs_opts->fsize); /* fsopts->density is set below */ /* XXX ondisk32 */ if (ffs_opts->maxbpg == -1) @@ -439,7 +441,7 @@ ffs_create_image(const char *image, fsinfo_t *fsopts) if (bufrem > 0) buf = ecalloc(1, bufsize); while (bufrem > 0) { - i = write(fsopts->fd, buf, MIN(bufsize, bufrem)); + i = write(fsopts->fd, buf, MINIMUM(bufsize, bufrem)); if (i == -1) { warn("zeroing image, %lld bytes to go", (long long)bufrem); @@ -619,7 +621,7 @@ ffs_populate_dir(const char *dir, fsnode *root, fsinfo_t *fsopts) dirbuf_t dirbuf; union dinode din; void *membuf; - char path[MAXPATHLEN + 1]; + char path[PATH_MAX + 1]; ffs_opt_t *ffs_opts = fsopts->fs_specific; assert(dir != NULL); @@ -759,7 +761,7 @@ ffs_write_file(union dinode *din, uint32_t ino, void *buf, fsinfo_t *fsopts) chunk = 0; for (bufleft = DIP(din, size); bufleft > 0; bufleft -= chunk) { - chunk = MIN(bufleft, ffs_opts->bsize); + chunk = MINIMUM(bufleft, ffs_opts->bsize); if (!isfile) ; else if ((nread = read(ffd, fbuf, chunk)) == -1) diff --git a/usr.sbin/makefs/ffs/buf.c b/usr.sbin/makefs/ffs/buf.c index b9f735225af..ce512c7d389 100644 --- a/usr.sbin/makefs/ffs/buf.c +++ b/usr.sbin/makefs/ffs/buf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buf.c,v 1.6 2016/12/17 16:26:46 krw Exp $ */ +/* $OpenBSD: buf.c,v 1.7 2021/10/06 00:40:41 deraadt Exp $ */ /* $NetBSD: buf.c,v 1.24 2016/06/24 19:24:11 christos Exp $ */ /* @@ -36,7 +36,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include diff --git a/usr.sbin/makefs/ffs/buf.h b/usr.sbin/makefs/ffs/buf.h index 4107d61fc97..e20de9334bc 100644 --- a/usr.sbin/makefs/ffs/buf.h +++ b/usr.sbin/makefs/ffs/buf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: buf.h,v 1.4 2016/10/17 01:16:22 tedu Exp $ */ +/* $OpenBSD: buf.h,v 1.5 2021/10/06 00:40:41 deraadt Exp $ */ /* $NetBSD: buf.h,v 1.10 2015/03/29 05:52:59 agc Exp $ */ /* @@ -39,7 +39,6 @@ #ifndef _FFS_BUF_H #define _FFS_BUF_H -#include #include #include @@ -86,7 +85,6 @@ struct mkfsbuf * getblk(struct mkfsvnode *, daddr_t, int, int, int); #define B_MODIFY 0 #define BC_AGE 0 -#define min(a, b) MIN((a), (b)) #define microtime(tv) gettimeofday((tv), NULL) #define KASSERT(a) #define IO_SYNC 1 diff --git a/usr.sbin/makefs/ffs/ffs_alloc.c b/usr.sbin/makefs/ffs/ffs_alloc.c index c3549a2fa20..5873c40aad7 100644 --- a/usr.sbin/makefs/ffs/ffs_alloc.c +++ b/usr.sbin/makefs/ffs/ffs_alloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_alloc.c,v 1.13 2016/12/17 16:26:46 krw Exp $ */ +/* $OpenBSD: ffs_alloc.c,v 1.14 2021/10/06 00:40:41 deraadt Exp $ */ /* $NetBSD: ffs_alloc.c,v 1.29 2016/06/24 19:24:11 christos Exp $ */ /* From: NetBSD: ffs_alloc.c,v 1.50 2001/09/06 02:16:01 lukem Exp */ @@ -42,9 +42,8 @@ * @(#)ffs_alloc.c 8.19 (Berkeley) 7/13/95 */ -#include - -#include +#include /* DEV_BSIZE setbit clrbit NBBY howmany */ +#include #include #include @@ -53,6 +52,7 @@ #include "ffs/ufs_inode.h" #include "ffs/ffs_extern.h" +#include static int scanc(u_int, const u_char *, const u_char *, int); diff --git a/usr.sbin/makefs/ffs/ffs_subr.c b/usr.sbin/makefs/ffs/ffs_subr.c index bc03ecf7a64..18c9e621193 100644 --- a/usr.sbin/makefs/ffs/ffs_subr.c +++ b/usr.sbin/makefs/ffs/ffs_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_subr.c,v 1.4 2016/10/22 19:43:50 natano Exp $ */ +/* $OpenBSD: ffs_subr.c,v 1.5 2021/10/06 00:40:41 deraadt Exp $ */ /* $NetBSD: ffs_subr.c,v 1.49 2016/05/07 11:59:08 maxv Exp $ */ /* @@ -32,11 +32,12 @@ * @(#)ffs_subr.c 8.5 (Berkeley) 3/21/95 */ -#include - +#include /* setbit clrbit NBBY */ +#include #include #include +#include #include #include "ffs/ffs_extern.h" diff --git a/usr.sbin/makefs/ffs/ffs_tables.c b/usr.sbin/makefs/ffs/ffs_tables.c index 077eb900a0e..8aa8d100160 100644 --- a/usr.sbin/makefs/ffs/ffs_tables.c +++ b/usr.sbin/makefs/ffs/ffs_tables.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_tables.c,v 1.2 2016/10/22 16:51:52 natano Exp $ */ +/* $OpenBSD: ffs_tables.c,v 1.3 2021/10/06 00:40:41 deraadt Exp $ */ /* $NetBSD: ffs_tables.c,v 1.2 1994/06/29 06:46:35 cgd Exp $ */ /* @@ -32,9 +32,11 @@ * @(#)ffs_tables.c 8.1 (Berkeley) 6/11/93 */ -#include +#include #include +#include + /* * Bit patterns for identifying fragments in the block map * used as ((map & around) == inside) diff --git a/usr.sbin/makefs/ffs/mkfs.c b/usr.sbin/makefs/ffs/mkfs.c index 2f53207c9f0..a4d57c008a2 100644 --- a/usr.sbin/makefs/ffs/mkfs.c +++ b/usr.sbin/makefs/ffs/mkfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkfs.c,v 1.13 2016/11/11 09:54:07 natano Exp $ */ +/* $OpenBSD: mkfs.c,v 1.14 2021/10/06 00:40:41 deraadt Exp $ */ /* $NetBSD: mkfs.c,v 1.34 2016/06/24 19:24:11 christos Exp $ */ /* @@ -39,12 +39,13 @@ * SUCH DAMAGE. */ -#include +#include /* roundup howmany setbit */ #include #include #include #include +#include #include #include #include @@ -126,7 +127,7 @@ ffs_mkfs(const char *fsys, const fsinfo_t *fsopts, time_t tstamp) minfree = ffs_opts->minfree; opt = ffs_opts->optimization; density = ffs_opts->density; - maxcontig = MAX(1, MIN(MAXBSIZE, FFS_MAXBSIZE) / bsize); + maxcontig = MAXIMUM(1, MINIMUM(MAXBSIZE, FFS_MAXBSIZE) / bsize); maxbpg = ffs_opts->maxbpg; avgfilesize = ffs_opts->avgfilesize; avgfpdir = ffs_opts->avgfpdir; @@ -215,7 +216,7 @@ ffs_mkfs(const char *fsys, const fsinfo_t *fsopts, time_t tstamp) } if (sblock.fs_maxcontig > 1) - sblock.fs_contigsumsize = MIN(sblock.fs_maxcontig,FS_MAXCONTIG); + sblock.fs_contigsumsize = MINIMUM(sblock.fs_maxcontig,FS_MAXCONTIG); sblock.fs_bmask = ~(sblock.fs_bsize - 1); sblock.fs_fmask = ~(sblock.fs_fsize - 1); @@ -297,7 +298,7 @@ ffs_mkfs(const char *fsys, const fsinfo_t *fsopts, time_t tstamp) */ origdensity = density; for (;;) { - fragsperinode = MAX(numfrags(&sblock, density), 1); + fragsperinode = MAXIMUM(numfrags(&sblock, density), 1); minfpg = fragsperinode * INOPB(&sblock); if (minfpg > sblock.fs_size) minfpg = sblock.fs_size; diff --git a/usr.sbin/makefs/ffs/ufs_bmap.c b/usr.sbin/makefs/ffs/ufs_bmap.c index d33eec60e14..ce41a1830f9 100644 --- a/usr.sbin/makefs/ffs/ufs_bmap.c +++ b/usr.sbin/makefs/ffs/ufs_bmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ufs_bmap.c,v 1.6 2016/12/17 16:26:46 krw Exp $ */ +/* $OpenBSD: ufs_bmap.c,v 1.7 2021/10/06 00:40:41 deraadt Exp $ */ /* $NetBSD: ufs_bmap.c,v 1.18 2013/06/19 17:51:27 dholland Exp $ */ /* From: NetBSD: ufs_bmap.c,v 1.14 2001/11/08 05:00:51 chs Exp */ @@ -38,7 +38,6 @@ * @(#)ufs_bmap.c 8.8 (Berkeley) 8/11/95 */ -#include #include #include diff --git a/usr.sbin/makefs/makefs.h b/usr.sbin/makefs/makefs.h index beb6fd6f259..303ec7a2c46 100644 --- a/usr.sbin/makefs/makefs.h +++ b/usr.sbin/makefs/makefs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: makefs.h,v 1.12 2016/12/17 16:12:15 krw Exp $ */ +/* $OpenBSD: makefs.h,v 1.13 2021/10/06 00:40:39 deraadt Exp $ */ /* $NetBSD: makefs.h,v 1.36 2015/11/25 00:48:49 christos Exp $ */ /* @@ -184,6 +184,8 @@ extern struct timespec start_time; #define DEFAULT_FSTYPE "ffs" #endif +#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) +#define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b)) /* xmalloc.c */ void *emalloc(size_t); diff --git a/usr.sbin/makefs/msdos.c b/usr.sbin/makefs/msdos.c index b78b1a7a2a9..da79fb33a0e 100644 --- a/usr.sbin/makefs/msdos.c +++ b/usr.sbin/makefs/msdos.c @@ -1,4 +1,4 @@ -/* $OpenBSD: msdos.c,v 1.12 2021/09/01 15:19:00 deraadt Exp $ */ +/* $OpenBSD: msdos.c,v 1.13 2021/10/06 00:40:39 deraadt Exp $ */ /* $NetBSD: msdos.c,v 1.16 2016/01/30 09:59:27 mlelstv Exp $ */ /*- @@ -30,10 +30,12 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include #include +#include #include #include "ffs/buf.h" @@ -121,7 +123,7 @@ msdos_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts) * XXX: pick up other options from the msdos specific ones? * Is minsize right here? */ - msdos_opt->create_size = MAX(msdos_opt->create_size, + msdos_opt->create_size = MAXIMUM(msdos_opt->create_size, fsopts->minsize); msdos_opt->offset = fsopts->offset; if (msdos_opt->bytes_per_sector == 0) { @@ -165,7 +167,7 @@ msdos_populate_dir(const char *path, struct denode *dir, fsnode *root, fsnode *parent, fsinfo_t *fsopts) { fsnode *cur; - char pbuf[MAXPATHLEN]; + char pbuf[PATH_MAX]; assert(dir != NULL); assert(root != NULL); diff --git a/usr.sbin/makefs/msdos/mkfs_msdos.c b/usr.sbin/makefs/msdos/mkfs_msdos.c index 7fbcca01750..d9a98446234 100644 --- a/usr.sbin/makefs/msdos/mkfs_msdos.c +++ b/usr.sbin/makefs/msdos/mkfs_msdos.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkfs_msdos.c,v 1.5 2017/11/02 11:06:54 jca Exp $ */ +/* $OpenBSD: mkfs_msdos.c,v 1.6 2021/10/06 00:40:41 deraadt Exp $ */ /* $NetBSD: mkfs_msdos.c,v 1.10 2016/04/03 11:00:13 mlelstv Exp $ */ /* @@ -28,7 +28,8 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include /* powerof2 */ +#include #include #include @@ -40,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -224,7 +226,7 @@ static void infohandler(int sig); int mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op) { - char buf[MAXPATHLEN]; + char buf[PATH_MAX]; struct stat sb; struct timeval tv; struct bpb bpb; @@ -492,7 +494,7 @@ mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op) x = bpb.bkbs + 1; } if (!bpb.res) - bpb.res = o.fat_type == 32 ? MAX(x, MAX(16384 / bpb.bps, 4)) : x; + bpb.res = o.fat_type == 32 ? MAXIMUM(x, MAXIMUM(16384 / bpb.bps, 4)) : x; else if (bpb.res < x) { warnx("too few reserved sectors (need %d have %d)", x, bpb.res); return -1; @@ -522,7 +524,7 @@ mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op) x1 += x * bpb.nft; x = (u_int64_t)(bpb.bsec - x1) * bpb.bps * NPB / (bpb.spc * bpb.bps * NPB + o.fat_type / BPN * bpb.nft); - x2 = howmany((RESFTE + MIN(x, maxcls(o.fat_type))) * (o.fat_type / BPN), + x2 = howmany((RESFTE + MINIMUM(x, maxcls(o.fat_type))) * (o.fat_type / BPN), bpb.bps * NPB); if (!bpb.bspf) { bpb.bspf = x2; diff --git a/usr.sbin/makefs/msdos/msdosfs_conv.c b/usr.sbin/makefs/msdos/msdosfs_conv.c index ce904ebf157..a07f1486d6c 100644 --- a/usr.sbin/makefs/msdos/msdosfs_conv.c +++ b/usr.sbin/makefs/msdos/msdosfs_conv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: msdosfs_conv.c,v 1.1 2016/10/18 17:05:30 natano Exp $ */ +/* $OpenBSD: msdosfs_conv.c,v 1.2 2021/10/06 00:40:41 deraadt Exp $ */ /* $NetBSD: msdosfs_conv.c,v 1.24 1997/10/17 11:23:54 ws Exp $ */ /*- @@ -51,7 +51,6 @@ /* * System include files. */ -#include #include #include #include diff --git a/usr.sbin/makefs/msdos/msdosfs_denode.c b/usr.sbin/makefs/msdos/msdosfs_denode.c index d65c4b79a5e..f32ea584109 100644 --- a/usr.sbin/makefs/msdos/msdosfs_denode.c +++ b/usr.sbin/makefs/msdos/msdosfs_denode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: msdosfs_denode.c,v 1.6 2016/10/22 22:20:24 natano Exp $ */ +/* $OpenBSD: msdosfs_denode.c,v 1.7 2021/10/06 00:40:41 deraadt Exp $ */ /* $NetBSD: msdosfs_denode.c,v 1.7 2015/03/29 05:52:59 agc Exp $ */ /*- @@ -48,7 +48,6 @@ * October 1992 */ -#include #include "ffs/buf.h" diff --git a/usr.sbin/makefs/msdos/msdosfs_fat.c b/usr.sbin/makefs/msdos/msdosfs_fat.c index 5ac212b6b8b..336c5f68560 100644 --- a/usr.sbin/makefs/msdos/msdosfs_fat.c +++ b/usr.sbin/makefs/msdos/msdosfs_fat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: msdosfs_fat.c,v 1.5 2018/04/26 12:42:51 guenther Exp $ */ +/* $OpenBSD: msdosfs_fat.c,v 1.6 2021/10/06 00:40:41 deraadt Exp $ */ /* $NetBSD: msdosfs_fat.c,v 1.31 2016/05/07 16:43:02 mlelstv Exp $ */ /*- @@ -48,10 +48,12 @@ * October 1992 */ +#include +#include + /* * kernel include files. */ -#include #include "ffs/buf.h" @@ -63,6 +65,7 @@ #include "msdos/direntry.h" #include "msdos/denode.h" #include "msdos/fat.h" +#include "makefs.h" /* * Fat cache stats. @@ -101,7 +104,7 @@ fatblock(struct msdosfsmount *pmp, u_long ofs, u_long *bnp, u_long *sizep, u_lon u_long bn, size; bn = ofs / pmp->pm_fatblocksize * pmp->pm_fatblocksec; - size = min(pmp->pm_fatblocksec, pmp->pm_FATsecs - bn) + size = MINIMUM(pmp->pm_fatblocksec, pmp->pm_FATsecs - bn) * pmp->pm_BytesPerSec; bn += pmp->pm_fatblk + pmp->pm_curfat * pmp->pm_FATsecs; @@ -185,7 +188,7 @@ pcbmap(struct denode *dep, u_long findcn, daddr_t *bnp, u_long *cnp, int *sp) if (cnp) *cnp = MSDOSFSROOT; if (sp) - *sp = min(pmp->pm_bpcluster, + *sp = MINIMUM(pmp->pm_bpcluster, dep->de_FileSize - de_cn2off(pmp, findcn)); DPRINTF(("%s(root, bn=%lu, cn=%u)\n", __func__, pmp->pm_rootdirblk + de_cn2bn(pmp, findcn), diff --git a/usr.sbin/makefs/msdos/msdosfs_lookup.c b/usr.sbin/makefs/msdos/msdosfs_lookup.c index 33e1bd9bb4e..aa1ded379b4 100644 --- a/usr.sbin/makefs/msdos/msdosfs_lookup.c +++ b/usr.sbin/makefs/msdos/msdosfs_lookup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: msdosfs_lookup.c,v 1.3 2017/08/31 12:03:02 otto Exp $ */ +/* $OpenBSD: msdosfs_lookup.c,v 1.4 2021/10/06 00:40:41 deraadt Exp $ */ /* $NetBSD: msdosfs_lookup.c,v 1.35 2016/01/30 09:59:27 mlelstv Exp $ */ /*- @@ -48,7 +48,6 @@ * October 1992 */ -#include #include "ffs/buf.h" diff --git a/usr.sbin/makefs/msdos/msdosfs_vfsops.c b/usr.sbin/makefs/msdos/msdosfs_vfsops.c index 91032db91ab..237cd392f59 100644 --- a/usr.sbin/makefs/msdos/msdosfs_vfsops.c +++ b/usr.sbin/makefs/msdos/msdosfs_vfsops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: msdosfs_vfsops.c,v 1.12 2019/09/04 14:40:22 cheloha Exp $ */ +/* $OpenBSD: msdosfs_vfsops.c,v 1.13 2021/10/06 00:40:41 deraadt Exp $ */ /*- * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. @@ -47,7 +47,9 @@ * October 1992 */ -#include + +#include /* MAXBSIZE */ +#include #include "ffs/buf.h" diff --git a/usr.sbin/makefs/msdos/msdosfs_vnops.c b/usr.sbin/makefs/msdos/msdosfs_vnops.c index 7a0e5996a00..901c9855e3b 100644 --- a/usr.sbin/makefs/msdos/msdosfs_vnops.c +++ b/usr.sbin/makefs/msdos/msdosfs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: msdosfs_vnops.c,v 1.8 2016/12/17 16:43:30 krw Exp $ */ +/* $OpenBSD: msdosfs_vnops.c,v 1.9 2021/10/06 00:40:41 deraadt Exp $ */ /* $NetBSD: msdosfs_vnops.c,v 1.17 2016/01/30 09:59:27 mlelstv Exp $ */ /*- @@ -48,7 +48,7 @@ * October 1992 */ -#include +#include #include #include #include @@ -474,7 +474,7 @@ msdosfs_wfile(const char *path, struct denode *dep, fsnode *node) DPRINTF(("bread %d\n", error)); goto out; } - cpsize = MIN((nsize - offs), blsize - on); + cpsize = MINIMUM((nsize - offs), blsize - on); memcpy((char *)bp->b_data + on, dat + offs, cpsize); bwrite(bp); offs += cpsize;