From: miod Date: Tue, 30 Apr 2024 17:05:20 +0000 (+0000) Subject: Constify NFS data whenever possible. Also make a few more const data static. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=45db009a9c9de031a1e3de5808bf0642a77c8550;p=openbsd Constify NFS data whenever possible. Also make a few more const data static. ok jsg@ semarie@ --- diff --git a/sys/nfs/nfs_serv.c b/sys/nfs/nfs_serv.c index c637ac8a3eb..3f6c9463e23 100644 --- a/sys/nfs/nfs_serv.c +++ b/sys/nfs/nfs_serv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs_serv.c,v 1.124 2024/04/30 17:04:23 miod Exp $ */ +/* $OpenBSD: nfs_serv.c,v 1.125 2024/04/30 17:05:20 miod Exp $ */ /* $NetBSD: nfs_serv.c,v 1.34 1997/05/12 23:37:12 fvdl Exp $ */ /* @@ -82,10 +82,8 @@ /* Global vars */ extern u_int32_t nfs_xdrneg1; extern u_int32_t nfs_false, nfs_true; -extern enum vtype nv3tov_type[8]; +extern const enum vtype nv3tov_type[8]; extern struct nfsstats nfsstats; -extern nfstype nfsv2_type[9]; -extern nfstype nfsv3_type[9]; int nfsrv_access(struct vnode *, int, struct ucred *, int, struct proc *, int); diff --git a/sys/nfs/nfs_socket.c b/sys/nfs/nfs_socket.c index 7d695f8739c..c6ec74e1cc3 100644 --- a/sys/nfs/nfs_socket.c +++ b/sys/nfs/nfs_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs_socket.c,v 1.149 2024/04/30 17:04:23 miod Exp $ */ +/* $OpenBSD: nfs_socket.c,v 1.150 2024/04/30 17:05:20 miod Exp $ */ /* $NetBSD: nfs_socket.c,v 1.27 1996/04/15 20:20:00 thorpej Exp $ */ /* @@ -72,7 +72,7 @@ extern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers, rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr; extern u_int32_t nfs_prog; extern struct nfsstats nfsstats; -extern int nfsv3_procid[NFS_NPROCS]; +extern const int nfsv3_procid[NFS_NPROCS]; extern int nfs_ticks; extern struct pool nfsrv_descript_pl; @@ -92,10 +92,10 @@ extern struct pool nfsrv_descript_pl; */ #define NFS_CWNDSCALE 256 #define NFS_MAXCWND (NFS_CWNDSCALE * 32) -int nfs_backoff[8] = { 2, 4, 8, 16, 32, 64, 128, 256 }; +static const int nfs_backoff[8] = { 2, 4, 8, 16, 32, 64, 128, 256 }; /* RTT estimator */ -enum nfs_rto_timers nfs_ptimers[NFS_NPROCS] = { +static const enum nfs_rto_timers nfs_ptimers[NFS_NPROCS] = { NFS_DEFAULT_TIMER, /* NULL */ NFS_GETATTR_TIMER, /* GETATTR */ NFS_DEFAULT_TIMER, /* SETATTR */ diff --git a/sys/nfs/nfs_srvcache.c b/sys/nfs/nfs_srvcache.c index 4a4b07fc234..83797fd2b62 100644 --- a/sys/nfs/nfs_srvcache.c +++ b/sys/nfs/nfs_srvcache.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs_srvcache.c,v 1.29 2019/12/05 10:41:57 mpi Exp $ */ +/* $OpenBSD: nfs_srvcache.c,v 1.30 2024/04/30 17:05:20 miod Exp $ */ /* $NetBSD: nfs_srvcache.c,v 1.12 1996/02/18 11:53:49 fvdl Exp $ */ /* @@ -58,7 +58,7 @@ #include extern struct nfsstats nfsstats; -extern int nfsv2_procid[NFS_NPROCS]; +extern const int nfsv2_procid[NFS_NPROCS]; long numnfsrvcache, desirednfsrvcache = NFSRVCACHESIZ; struct nfsrvcache *nfsrv_lookupcache(struct nfsrv_descript *); @@ -75,14 +75,14 @@ u_long nfsrvhash; (((rp)->rc_flag & RC_INETADDR) ? AF_INET : AF_UNSPEC) /* Array that defines which nfs rpc's are nonidempotent */ -int nonidempotent[NFS_NPROCS] = { +static const int nonidempotent[NFS_NPROCS] = { 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; /* True iff the rpc reply is an nfs status ONLY! */ -int nfsv2_repstat[NFS_NPROCS] = { +static const int nfsv2_repstat[NFS_NPROCS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0 diff --git a/sys/nfs/nfs_subs.c b/sys/nfs/nfs_subs.c index 1ccebbfe7d7..a3d81091b6a 100644 --- a/sys/nfs/nfs_subs.c +++ b/sys/nfs/nfs_subs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs_subs.c,v 1.147 2024/04/30 17:04:23 miod Exp $ */ +/* $OpenBSD: nfs_subs.c,v 1.148 2024/04/30 17:05:20 miod Exp $ */ /* $NetBSD: nfs_subs.c,v 1.27.4.3 1996/07/08 20:34:24 jtc Exp $ */ /* @@ -82,19 +82,21 @@ u_int32_t rpc_call, rpc_vers, rpc_reply, rpc_msgdenied, rpc_autherr, u_int32_t nfs_prog, nfs_true, nfs_false; /* And other global data */ -nfstype nfsv2_type[9] = { NFNON, NFREG, NFDIR, NFBLK, NFCHR, NFLNK, NFNON, - NFCHR, NFNON }; -nfstype nfsv3_type[9] = { NFNON, NFREG, NFDIR, NFBLK, NFCHR, NFLNK, NFSOCK, - NFFIFO, NFNON }; -enum vtype nv2tov_type[8] = { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VNON, VNON }; -enum vtype nv3tov_type[8]={ VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO }; +const nfstype nfsv2_type[9] = + { NFNON, NFREG, NFDIR, NFBLK, NFCHR, NFLNK, NFNON, NFCHR, NFNON }; +const nfstype nfsv3_type[9] = + { NFNON, NFREG, NFDIR, NFBLK, NFCHR, NFLNK, NFSOCK, NFFIFO, NFNON }; +const enum vtype nv2tov_type[8] = + { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VNON, VNON }; +const enum vtype nv3tov_type[8]= + { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO }; int nfs_ticks; struct nfsstats nfsstats; /* * Mapping of old NFS Version 2 RPC numbers to generic numbers. */ -int nfsv3_procid[NFS_NPROCS] = { +const int nfsv3_procid[NFS_NPROCS] = { NFSPROC_NULL, NFSPROC_GETATTR, NFSPROC_SETATTR, @@ -123,7 +125,7 @@ int nfsv3_procid[NFS_NPROCS] = { /* * and the reverse mapping from generic to Version 2 procedure numbers */ -int nfsv2_procid[NFS_NPROCS] = { +const int nfsv2_procid[NFS_NPROCS] = { NFSV2PROC_NULL, NFSV2PROC_GETATTR, NFSV2PROC_SETATTR, @@ -154,7 +156,7 @@ int nfsv2_procid[NFS_NPROCS] = { * Use NFSERR_IO as the catch all for ones not specifically defined in * RFC 1094. */ -static u_char nfsrv_v2errmap[] = { +static const u_char nfsrv_v2errmap[] = { NFSERR_PERM, NFSERR_NOENT, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_NXIO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_ACCES, NFSERR_IO, NFSERR_IO, @@ -183,12 +185,12 @@ static u_char nfsrv_v2errmap[] = { * The first entry is the default error return and the rest are the valid * errors for that RPC in increasing numeric order. */ -static short nfsv3err_null[] = { +static const short nfsv3err_null[] = { 0, 0, }; -static short nfsv3err_getattr[] = { +static const short nfsv3err_getattr[] = { NFSERR_IO, NFSERR_IO, NFSERR_STALE, @@ -197,7 +199,7 @@ static short nfsv3err_getattr[] = { 0, }; -static short nfsv3err_setattr[] = { +static const short nfsv3err_setattr[] = { NFSERR_IO, NFSERR_PERM, NFSERR_IO, @@ -213,7 +215,7 @@ static short nfsv3err_setattr[] = { 0, }; -static short nfsv3err_lookup[] = { +static const short nfsv3err_lookup[] = { NFSERR_IO, NFSERR_NOENT, NFSERR_IO, @@ -226,7 +228,7 @@ static short nfsv3err_lookup[] = { 0, }; -static short nfsv3err_access[] = { +static const short nfsv3err_access[] = { NFSERR_IO, NFSERR_IO, NFSERR_STALE, @@ -235,7 +237,7 @@ static short nfsv3err_access[] = { 0, }; -static short nfsv3err_readlink[] = { +static const short nfsv3err_readlink[] = { NFSERR_IO, NFSERR_IO, NFSERR_ACCES, @@ -247,7 +249,7 @@ static short nfsv3err_readlink[] = { 0, }; -static short nfsv3err_read[] = { +static const short nfsv3err_read[] = { NFSERR_IO, NFSERR_IO, NFSERR_NXIO, @@ -259,7 +261,7 @@ static short nfsv3err_read[] = { 0, }; -static short nfsv3err_write[] = { +static const short nfsv3err_write[] = { NFSERR_IO, NFSERR_IO, NFSERR_ACCES, @@ -274,7 +276,7 @@ static short nfsv3err_write[] = { 0, }; -static short nfsv3err_create[] = { +static const short nfsv3err_create[] = { NFSERR_IO, NFSERR_IO, NFSERR_ACCES, @@ -291,7 +293,7 @@ static short nfsv3err_create[] = { 0, }; -static short nfsv3err_mkdir[] = { +static const short nfsv3err_mkdir[] = { NFSERR_IO, NFSERR_IO, NFSERR_ACCES, @@ -308,7 +310,7 @@ static short nfsv3err_mkdir[] = { 0, }; -static short nfsv3err_symlink[] = { +static const short nfsv3err_symlink[] = { NFSERR_IO, NFSERR_IO, NFSERR_ACCES, @@ -325,7 +327,7 @@ static short nfsv3err_symlink[] = { 0, }; -static short nfsv3err_mknod[] = { +static const short nfsv3err_mknod[] = { NFSERR_IO, NFSERR_IO, NFSERR_ACCES, @@ -343,7 +345,7 @@ static short nfsv3err_mknod[] = { 0, }; -static short nfsv3err_remove[] = { +static const short nfsv3err_remove[] = { NFSERR_IO, NFSERR_NOENT, NFSERR_IO, @@ -357,7 +359,7 @@ static short nfsv3err_remove[] = { 0, }; -static short nfsv3err_rmdir[] = { +static const short nfsv3err_rmdir[] = { NFSERR_IO, NFSERR_NOENT, NFSERR_IO, @@ -375,7 +377,7 @@ static short nfsv3err_rmdir[] = { 0, }; -static short nfsv3err_rename[] = { +static const short nfsv3err_rename[] = { NFSERR_IO, NFSERR_NOENT, NFSERR_IO, @@ -398,7 +400,7 @@ static short nfsv3err_rename[] = { 0, }; -static short nfsv3err_link[] = { +static const short nfsv3err_link[] = { NFSERR_IO, NFSERR_IO, NFSERR_ACCES, @@ -418,7 +420,7 @@ static short nfsv3err_link[] = { 0, }; -static short nfsv3err_readdir[] = { +static const short nfsv3err_readdir[] = { NFSERR_IO, NFSERR_IO, NFSERR_ACCES, @@ -431,7 +433,7 @@ static short nfsv3err_readdir[] = { 0, }; -static short nfsv3err_readdirplus[] = { +static const short nfsv3err_readdirplus[] = { NFSERR_IO, NFSERR_IO, NFSERR_ACCES, @@ -445,7 +447,7 @@ static short nfsv3err_readdirplus[] = { 0, }; -static short nfsv3err_fsstat[] = { +static const short nfsv3err_fsstat[] = { NFSERR_IO, NFSERR_IO, NFSERR_STALE, @@ -454,7 +456,7 @@ static short nfsv3err_fsstat[] = { 0, }; -static short nfsv3err_fsinfo[] = { +static const short nfsv3err_fsinfo[] = { NFSERR_STALE, NFSERR_STALE, NFSERR_BADHANDLE, @@ -462,7 +464,7 @@ static short nfsv3err_fsinfo[] = { 0, }; -static short nfsv3err_pathconf[] = { +static const short nfsv3err_pathconf[] = { NFSERR_STALE, NFSERR_STALE, NFSERR_BADHANDLE, @@ -470,7 +472,7 @@ static short nfsv3err_pathconf[] = { 0, }; -static short nfsv3err_commit[] = { +static const short nfsv3err_commit[] = { NFSERR_IO, NFSERR_IO, NFSERR_STALE, @@ -479,7 +481,7 @@ static short nfsv3err_commit[] = { 0, }; -static short *nfsrv_v3errmap[] = { +static const short *nfsrv_v3errmap[] = { nfsv3err_null, nfsv3err_getattr, nfsv3err_setattr, @@ -1678,7 +1680,7 @@ nfs_del_tobecommitted_range(struct vnode *vp, struct buf *bp) int nfsrv_errmap(struct nfsrv_descript *nd, int err) { - short *defaulterrp, *errp; + const short *defaulterrp, *errp; if (nd->nd_flag & ND_NFSV3) { if (nd->nd_procnum <= NFSPROC_COMMIT) { diff --git a/sys/nfs/nfs_syscalls.c b/sys/nfs/nfs_syscalls.c index 13bbd641d53..0c83e6172fa 100644 --- a/sys/nfs/nfs_syscalls.c +++ b/sys/nfs/nfs_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs_syscalls.c,v 1.124 2024/04/19 06:50:37 ratchov Exp $ */ +/* $OpenBSD: nfs_syscalls.c,v 1.125 2024/04/30 17:05:20 miod Exp $ */ /* $NetBSD: nfs_syscalls.c,v 1.19 1996/02/18 11:53:52 fvdl Exp $ */ /* @@ -84,7 +84,7 @@ struct pool nfsrv_descript_pl; int nfsrv_getslp(struct nfsd *nfsd); static int nfs_numnfsd = 0; -int (*nfsrv3_procs[NFS_NPROCS])(struct nfsrv_descript *, +static int (*const nfsrv3_procs[NFS_NPROCS])(struct nfsrv_descript *, struct nfssvc_sock *, struct proc *, struct mbuf **) = { nfsrv_null, nfsrv_getattr, diff --git a/sys/nfs/nfs_vnops.c b/sys/nfs/nfs_vnops.c index 6ade5bb0962..4d6e2d96b6c 100644 --- a/sys/nfs/nfs_vnops.c +++ b/sys/nfs/nfs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs_vnops.c,v 1.196 2024/04/30 17:04:23 miod Exp $ */ +/* $OpenBSD: nfs_vnops.c,v 1.197 2024/04/30 17:05:20 miod Exp $ */ /* $NetBSD: nfs_vnops.c,v 1.62.4.1 1996/07/08 20:26:52 jtc Exp $ */ /* @@ -259,7 +259,7 @@ const struct vops nfs_fifovops = { extern u_int32_t nfs_true, nfs_false; extern u_int32_t nfs_xdrneg1; extern struct nfsstats nfsstats; -extern nfstype nfsv3_type[9]; +extern const nfstype nfsv3_type[9]; int nfs_numasync = 0; void