Move vfsconf lookup code into dedicated functions.
authorvisa <visa@openbsd.org>
Sun, 16 Sep 2018 11:41:44 +0000 (11:41 +0000)
committervisa <visa@openbsd.org>
Sun, 16 Sep 2018 11:41:44 +0000 (11:41 +0000)
OK bluhm@

sys/kern/vfs_init.c
sys/kern/vfs_subr.c
sys/kern/vfs_syscalls.c
sys/sys/mount.h

index ae66c78..2448e1f 100644 (file)
@@ -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 <sys/param.h>
+#include <sys/systm.h>
 #include <sys/mount.h>
 #include <sys/namei.h>
 #include <sys/vnode.h>
@@ -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;
+}
index fa9e541..997b636 100644 (file)
@@ -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);
 
index 4281137..631c1cd 100644 (file)
@@ -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;
index d1ebe2d..05b5243 100644 (file)
@@ -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 *);