From 6d4b78c662d82b8af03c81f64c38fdba924e23b6 Mon Sep 17 00:00:00 2001 From: visa Date: Sun, 16 Sep 2018 11:41:44 +0000 Subject: [PATCH] Move vfsconf lookup code into dedicated functions. OK bluhm@ --- sys/kern/vfs_init.c | 27 ++++++++++++++++++++++++++- sys/kern/vfs_subr.c | 16 ++++------------ sys/kern/vfs_syscalls.c | 8 ++------ sys/sys/mount.h | 4 +++- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/sys/kern/vfs_init.c b/sys/kern/vfs_init.c index ae66c783aad..2448e1f6ad2 100644 --- a/sys/kern/vfs_init.c +++ b/sys/kern/vfs_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_init.c,v 1.39 2017/12/11 05:27:40 deraadt Exp $ */ +/* $OpenBSD: vfs_init.c,v 1.40 2018/09/16 11:41:44 visa Exp $ */ /* $NetBSD: vfs_init.c,v 1.6 1996/02/09 19:00:58 christos Exp $ */ /* @@ -38,6 +38,7 @@ */ #include +#include #include #include #include @@ -179,3 +180,27 @@ vfsinit(void) for (i = 0; i < vfsconflistlen; i++) vfs_register(&vfsconflist[i]); } + +struct vfsconf * +vfs_byname(const char *name) +{ + struct vfsconf *vfsp; + + for (vfsp = vfsconf; vfsp != NULL; vfsp = vfsp->vfc_next) { + if (strcmp(vfsp->vfc_name, name) == 0) + break; + } + return vfsp; +} + +struct vfsconf * +vfs_bytypenum(int typenum) +{ + struct vfsconf *vfsp; + + for (vfsp = vfsconf; vfsp != NULL; vfsp = vfsp->vfc_next) { + if (vfsp->vfc_typenum == typenum) + break; + } + return vfsp; +} diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index fa9e541abec..997b636d009 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_subr.c,v 1.277 2018/07/13 09:25:23 beck Exp $ */ +/* $OpenBSD: vfs_subr.c,v 1.278 2018/09/16 11:41:44 visa Exp $ */ /* $NetBSD: vfs_subr.c,v 1.53 1996/04/22 01:39:13 christos Exp $ */ /* @@ -229,9 +229,7 @@ vfs_rootmountalloc(char *fstypename, char *devname, struct mount **mpp) struct vfsconf *vfsp; struct mount *mp; - for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next) - if (!strcmp(vfsp->vfc_name, fstypename)) - break; + vfsp = vfs_byname(fstypename); if (vfsp == NULL) return (ENODEV); mp = malloc(sizeof(*mp), M_MOUNT, M_WAITOK|M_ZERO); @@ -1307,10 +1305,7 @@ vfs_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, return (ENOTDIR); /* overloaded */ if (name[0] != VFS_GENERIC) { - for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next) - if (vfsp->vfc_typenum == name[0]) - break; - + vfsp = vfs_bytypenum(name[0]); if (vfsp == NULL || vfsp->vfc_vfsops->vfs_sysctl == NULL) return (EOPNOTSUPP); @@ -1326,10 +1321,7 @@ vfs_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, if (namelen < 3) return (ENOTDIR); /* overloaded */ - for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next) - if (vfsp->vfc_typenum == name[2]) - break; - + vfsp = vfs_bytypenum(name[2]); if (vfsp == NULL) return (EOPNOTSUPP); diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 4281137a647..631c1cd54bb 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_syscalls.c,v 1.305 2018/09/01 17:02:12 deraadt Exp $ */ +/* $OpenBSD: vfs_syscalls.c,v 1.306 2018/09/16 11:41:44 visa Exp $ */ /* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */ /* @@ -194,11 +194,7 @@ sys_mount(struct proc *p, void *v, register_t *retval) vput(vp); goto fail; } - for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next) { - if (!strcmp(vfsp->vfc_name, fstypename)) - break; - } - + vfsp = vfs_byname(fstypename); if (vfsp == NULL) { vput(vp); error = EOPNOTSUPP; diff --git a/sys/sys/mount.h b/sys/sys/mount.h index d1ebe2d2d15..05b5243c8ef 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mount.h,v 1.138 2018/06/19 13:01:34 helg Exp $ */ +/* $OpenBSD: mount.h,v 1.139 2018/09/16 11:41:44 visa Exp $ */ /* $NetBSD: mount.h,v 1.48 1996/02/18 11:55:47 fvdl Exp $ */ /* @@ -602,6 +602,8 @@ int dounmount(struct mount *, int, struct proc *); void vfsinit(void); int vfs_register(struct vfsconf *); int vfs_unregister(struct vfsconf *); +struct vfsconf *vfs_byname(const char *); +struct vfsconf *vfs_bytypenum(int); #else /* _KERNEL */ __BEGIN_DECLS int fstatfs(int, struct statfs *); -- 2.20.1