-/* $OpenBSD: vfs_init.c,v 1.40 2018/09/16 11:41:44 visa Exp $ */
+/* $OpenBSD: vfs_init.c,v 1.41 2018/09/17 14:56:37 visa Exp $ */
/* $NetBSD: vfs_init.c,v 1.6 1996/02/09 19:00:58 christos Exp $ */
/*
/* Set up the filesystem operations for vnodes. */
static struct vfsconf vfsconflist[] = {
#ifdef FFS
- { &ffs_vfsops, MOUNT_FFS, 1, 0, MNT_LOCAL, NULL,
+ { &ffs_vfsops, MOUNT_FFS, 1, 0, MNT_LOCAL,
sizeof(struct ufs_args) },
#endif
#ifdef MFS
- { &mfs_vfsops, MOUNT_MFS, 3, 0, MNT_LOCAL, NULL,
+ { &mfs_vfsops, MOUNT_MFS, 3, 0, MNT_LOCAL,
sizeof(struct mfs_args) },
#endif
#ifdef EXT2FS
- { &ext2fs_vfsops, MOUNT_EXT2FS, 17, 0, MNT_LOCAL, NULL,
+ { &ext2fs_vfsops, MOUNT_EXT2FS, 17, 0, MNT_LOCAL,
sizeof(struct ufs_args) },
#endif
#ifdef CD9660
- { &cd9660_vfsops, MOUNT_CD9660, 14, 0, MNT_LOCAL, NULL,
+ { &cd9660_vfsops, MOUNT_CD9660, 14, 0, MNT_LOCAL,
sizeof(struct iso_args) },
#endif
#ifdef MSDOSFS
- { &msdosfs_vfsops, MOUNT_MSDOS, 4, 0, MNT_LOCAL, NULL,
+ { &msdosfs_vfsops, MOUNT_MSDOS, 4, 0, MNT_LOCAL,
sizeof(struct msdosfs_args) },
#endif
#ifdef NFSCLIENT
- { &nfs_vfsops, MOUNT_NFS, 2, 0, 0, NULL,
+ { &nfs_vfsops, MOUNT_NFS, 2, 0, 0,
sizeof(struct nfs_args) },
#endif
#ifdef NTFS
- { &ntfs_vfsops, MOUNT_NTFS, 6, 0, MNT_LOCAL, NULL,
+ { &ntfs_vfsops, MOUNT_NTFS, 6, 0, MNT_LOCAL,
sizeof(struct ntfs_args) },
#endif
#ifdef UDF
- { &udf_vfsops, MOUNT_UDF, 13, 0, MNT_LOCAL, NULL,
+ { &udf_vfsops, MOUNT_UDF, 13, 0, MNT_LOCAL,
sizeof(struct iso_args) },
#endif
#ifdef FUSE
- { &fusefs_vfsops, MOUNT_FUSEFS, 18, 0, MNT_LOCAL, NULL,
+ { &fusefs_vfsops, MOUNT_FUSEFS, 18, 0, MNT_LOCAL,
sizeof(struct fusefs_args) },
#endif
#ifdef TMPFS
- { &tmpfs_vfsops, MOUNT_TMPFS, 19, 0, MNT_LOCAL, NULL,
+ { &tmpfs_vfsops, MOUNT_TMPFS, 19, 0, MNT_LOCAL,
sizeof(struct tmpfs_args) },
#endif
};
* to the highest defined type number.
*/
int maxvfsconf = sizeof(vfsconflist) / sizeof(struct vfsconf);
-struct vfsconf *vfsconf = vfsconflist;
/* Initialize the vnode structures and initialize each file system type. */
void
vfsinit(void)
{
+ struct vfsconf *vfsp;
int i;
- struct vfsconf *vfsconflist;
- int vfsconflistlen;
pool_init(&namei_pool, MAXPATHLEN, 0, IPL_NONE, PR_WAITOK, "namei",
NULL);
/* Initialize the vnode name cache. */
nchinit();
- /*
- * Stop using vfsconf and maxvfsconf as a temporary storage,
- * set them to their correct values now.
- */
- vfsconflist = vfsconf;
- vfsconflistlen = maxvfsconf;
- vfsconf = NULL;
maxvfsconf = 0;
-
- for (i = 0; i < vfsconflistlen; i++)
- vfs_register(&vfsconflist[i]);
+ for (i = 0; i < nitems(vfsconflist); i++) {
+ vfsp = &vfsconflist[i];
+ if (vfsp->vfc_typenum > maxvfsconf)
+ maxvfsconf = vfsp->vfc_typenum;
+ if (vfsp->vfc_vfsops->vfs_init != NULL)
+ (*vfsp->vfc_vfsops->vfs_init)(vfsp);
+ }
}
struct vfsconf *
vfs_byname(const char *name)
{
- struct vfsconf *vfsp;
+ int i;
- for (vfsp = vfsconf; vfsp != NULL; vfsp = vfsp->vfc_next) {
- if (strcmp(vfsp->vfc_name, name) == 0)
- break;
+ for (i = 0; i < nitems(vfsconflist); i++) {
+ if (strcmp(vfsconflist[i].vfc_name, name) == 0)
+ return &vfsconflist[i];
}
- return vfsp;
+ return NULL;
}
struct vfsconf *
vfs_bytypenum(int typenum)
{
- struct vfsconf *vfsp;
+ int i;
- for (vfsp = vfsconf; vfsp != NULL; vfsp = vfsp->vfc_next) {
- if (vfsp->vfc_typenum == typenum)
- break;
+ for (i = 0; i < nitems(vfsconflist); i++) {
+ if (vfsconflist[i].vfc_typenum == typenum)
+ return &vfsconflist[i];
}
- return vfsp;
+ return NULL;
}
-/* $OpenBSD: vfs_subr.c,v 1.278 2018/09/16 11:41:44 visa Exp $ */
+/* $OpenBSD: vfs_subr.c,v 1.279 2018/09/17 14:56:37 visa Exp $ */
/* $NetBSD: vfs_subr.c,v 1.53 1996/04/22 01:39:13 christos Exp $ */
/*
tmpvfsp = malloc(sizeof(*tmpvfsp), M_TEMP, M_WAITOK|M_ZERO);
memcpy(tmpvfsp, vfsp, sizeof(*tmpvfsp));
tmpvfsp->vfc_vfsops = NULL;
- tmpvfsp->vfc_next = NULL;
ret = sysctl_rdstruct(oldp, oldlenp, newp, tmpvfsp,
sizeof(struct vfsconf));
bufinsvn(bp, listheadp);
}
-int
-vfs_register(struct vfsconf *vfs)
-{
- struct vfsconf *vfsp;
- struct vfsconf **vfspp;
-
-#ifdef DIAGNOSTIC
- /* Paranoia? */
- if (vfs->vfc_refcount != 0)
- printf("vfs_register called with vfc_refcount > 0\n");
-#endif
-
- /* Check if filesystem already known */
- for (vfspp = &vfsconf, vfsp = vfsconf; vfsp;
- vfspp = &vfsp->vfc_next, vfsp = vfsp->vfc_next)
- if (strcmp(vfsp->vfc_name, vfs->vfc_name) == 0)
- return (EEXIST);
-
- if (vfs->vfc_typenum > maxvfsconf)
- maxvfsconf = vfs->vfc_typenum;
-
- vfs->vfc_next = NULL;
-
- /* Add to the end of the list */
- *vfspp = vfs;
-
- /* Call vfs_init() */
- if (vfs->vfc_vfsops->vfs_init)
- (*(vfs->vfc_vfsops->vfs_init))(vfs);
-
- return 0;
-}
-
-int
-vfs_unregister(struct vfsconf *vfs)
-{
- struct vfsconf *vfsp;
- struct vfsconf **vfspp;
- int maxtypenum;
-
- /* Find our vfsconf struct */
- for (vfspp = &vfsconf, vfsp = vfsconf; vfsp;
- vfspp = &vfsp->vfc_next, vfsp = vfsp->vfc_next) {
- if (strcmp(vfsp->vfc_name, vfs->vfc_name) == 0)
- break;
- }
-
- if (!vfsp) /* Not found */
- return (ENOENT);
-
- if (vfsp->vfc_refcount) /* In use */
- return (EBUSY);
-
- /* Remove from list and free */
- *vfspp = vfsp->vfc_next;
-
- maxtypenum = 0;
-
- for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next)
- if (vfsp->vfc_typenum > maxtypenum)
- maxtypenum = vfsp->vfc_typenum;
-
- maxvfsconf = maxtypenum;
- return 0;
-}
-
/*
* Check if vnode represents a disk device
*/