Home | History | Annotate | Line # | Download | only in coda
coda_vfsops.c revision 1.35
      1 /*	$NetBSD: coda_vfsops.c,v 1.35 2004/04/21 02:41:52 christos Exp $	*/
      2 
      3 /*
      4  *
      5  *             Coda: an Experimental Distributed File System
      6  *                              Release 3.1
      7  *
      8  *           Copyright (c) 1987-1998 Carnegie Mellon University
      9  *                          All Rights Reserved
     10  *
     11  * Permission  to  use, copy, modify and distribute this software and its
     12  * documentation is hereby granted,  provided  that  both  the  copyright
     13  * notice  and  this  permission  notice  appear  in  all  copies  of the
     14  * software, derivative works or  modified  versions,  and  any  portions
     15  * thereof, and that both notices appear in supporting documentation, and
     16  * that credit is given to Carnegie Mellon University  in  all  documents
     17  * and publicity pertaining to direct or indirect use of this code or its
     18  * derivatives.
     19  *
     20  * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS  KNOWN  TO  HAVE  BUGS,
     21  * SOME  OF  WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON ALLOWS
     22  * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.   CARNEGIE  MELLON
     23  * DISCLAIMS  ANY  LIABILITY  OF  ANY  KIND  FOR  ANY  DAMAGES WHATSOEVER
     24  * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE  OR  OF
     25  * ANY DERIVATIVE WORK.
     26  *
     27  * Carnegie  Mellon  encourages  users  of  this  software  to return any
     28  * improvements or extensions that  they  make,  and  to  grant  Carnegie
     29  * Mellon the rights to redistribute these changes without encumbrance.
     30  *
     31  * 	@(#) cfs/coda_vfsops.c,v 1.1.1.1 1998/08/29 21:26:45 rvb Exp $
     32  */
     33 
     34 /*
     35  * Mach Operating System
     36  * Copyright (c) 1989 Carnegie-Mellon University
     37  * All rights reserved.  The CMU software License Agreement specifies
     38  * the terms and conditions for use and redistribution.
     39  */
     40 
     41 /*
     42  * This code was written for the Coda file system at Carnegie Mellon
     43  * University.  Contributers include David Steere, James Kistler, and
     44  * M. Satyanarayanan.
     45  */
     46 
     47 #include <sys/cdefs.h>
     48 __KERNEL_RCSID(0, "$NetBSD: coda_vfsops.c,v 1.35 2004/04/21 02:41:52 christos Exp $");
     49 
     50 #ifdef	_LKM
     51 #define	NVCODA 4
     52 #else
     53 #include <vcoda.h>
     54 #endif
     55 
     56 #include <sys/param.h>
     57 #include <sys/systm.h>
     58 #include <sys/sysctl.h>
     59 #include <sys/malloc.h>
     60 #include <sys/conf.h>
     61 #include <sys/namei.h>
     62 #include <sys/dirent.h>
     63 #include <sys/mount.h>
     64 #include <sys/proc.h>
     65 #include <sys/select.h>
     66 
     67 #include <coda/coda.h>
     68 #include <coda/cnode.h>
     69 #include <coda/coda_vfsops.h>
     70 #include <coda/coda_venus.h>
     71 #include <coda/coda_subr.h>
     72 #include <coda/coda_opstats.h>
     73 /* for VN_RDEV */
     74 #include <miscfs/specfs/specdev.h>
     75 
     76 MALLOC_DEFINE(M_CODA, "coda", "Coda file system structures and tables");
     77 
     78 int codadebug = 0;
     79 
     80 int coda_vfsop_print_entry = 0;
     81 #define ENTRY if(coda_vfsop_print_entry) myprintf(("Entered %s\n",__func__))
     82 
     83 struct vnode *coda_ctlvp;
     84 struct coda_mntinfo coda_mnttbl[NVCODA]; /* indexed by minor device number */
     85 
     86 /* structure to keep statistics of internally generated/satisfied calls */
     87 
     88 struct coda_op_stats coda_vfsopstats[CODA_VFSOPS_SIZE];
     89 
     90 #define MARK_ENTRY(op) (coda_vfsopstats[op].entries++)
     91 #define MARK_INT_SAT(op) (coda_vfsopstats[op].sat_intrn++)
     92 #define MARK_INT_FAIL(op) (coda_vfsopstats[op].unsat_intrn++)
     93 #define MRAK_INT_GEN(op) (coda_vfsopstats[op].gen_intrn++)
     94 
     95 extern const struct cdevsw vcoda_cdevsw;
     96 extern const struct vnodeopv_desc coda_vnodeop_opv_desc;
     97 
     98 const struct vnodeopv_desc * const coda_vnodeopv_descs[] = {
     99 	&coda_vnodeop_opv_desc,
    100 	NULL,
    101 };
    102 
    103 struct vfsops coda_vfsops = {
    104     MOUNT_CODA,
    105     coda_mount,
    106     coda_start,
    107     coda_unmount,
    108     coda_root,
    109     coda_quotactl,
    110     coda_nb_statvfs,
    111     coda_sync,
    112     coda_vget,
    113     (int (*) (struct mount *, struct fid *, struct vnode ** ))
    114 	eopnotsupp,
    115     (int (*) (struct vnode *, struct fid *)) eopnotsupp,
    116     coda_init,
    117     NULL,
    118     coda_done,
    119     NULL,
    120     (int (*)(void)) eopnotsupp,
    121     (int (*)(struct mount *, struct mbuf *, int *, struct ucred **))
    122 	eopnotsupp,
    123     coda_vnodeopv_descs,
    124     0
    125 };
    126 
    127 
    128 int
    129 coda_vfsopstats_init(void)
    130 {
    131 	int i;
    132 
    133 	for (i=0;i<CODA_VFSOPS_SIZE;i++) {
    134 		coda_vfsopstats[i].opcode = i;
    135 		coda_vfsopstats[i].entries = 0;
    136 		coda_vfsopstats[i].sat_intrn = 0;
    137 		coda_vfsopstats[i].unsat_intrn = 0;
    138 		coda_vfsopstats[i].gen_intrn = 0;
    139 	}
    140 
    141 	return 0;
    142 }
    143 
    144 /*
    145  * cfs mount vfsop
    146  * Set up mount info record and attach it to vfs struct.
    147  */
    148 /*ARGSUSED*/
    149 int
    150 coda_mount(vfsp, path, data, ndp, p)
    151     struct mount *vfsp;		/* Allocated and initialized by mount(2) */
    152     const char *path;		/* path covered: ignored by the fs-layer */
    153     void *data;			/* Need to define a data type for this in netbsd? */
    154     struct nameidata *ndp;	/* Clobber this to lookup the device name */
    155     struct proc *p;		/* The ever-famous proc pointer */
    156 {
    157     struct vnode *dvp;
    158     struct cnode *cp;
    159     dev_t dev;
    160     struct coda_mntinfo *mi;
    161     struct vnode *rootvp;
    162     const struct cdevsw *cdev;
    163     CodaFid rootfid = INVAL_FID;
    164     CodaFid ctlfid = CTL_FID;
    165     int error;
    166 
    167     if (vfsp->mnt_flag & MNT_GETARGS)
    168 	return 0;
    169     ENTRY;
    170 
    171     coda_vfsopstats_init();
    172     coda_vnodeopstats_init();
    173 
    174     MARK_ENTRY(CODA_MOUNT_STATS);
    175     if (CODA_MOUNTED(vfsp)) {
    176 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    177 	return(EBUSY);
    178     }
    179 
    180     /* Validate mount device.  Similar to getmdev(). */
    181 
    182     NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, data, p);
    183     error = namei(ndp);
    184     dvp = ndp->ni_vp;
    185 
    186     if (error) {
    187 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    188 	return (error);
    189     }
    190     if (dvp->v_type != VCHR) {
    191 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    192 	vrele(dvp);
    193 	return(ENXIO);
    194     }
    195     dev = dvp->v_specinfo->si_rdev;
    196     vrele(dvp);
    197     cdev = cdevsw_lookup(dev);
    198     if (cdev == NULL) {
    199 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    200 	return(ENXIO);
    201     }
    202 
    203     /*
    204      * See if the device table matches our expectations.
    205      */
    206     if (cdev != &vcoda_cdevsw)
    207     {
    208 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    209 	return(ENXIO);
    210     }
    211 
    212     if (minor(dev) >= NVCODA || minor(dev) < 0) {
    213 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    214 	return(ENXIO);
    215     }
    216 
    217     /*
    218      * Initialize the mount record and link it to the vfs struct
    219      */
    220     mi = &coda_mnttbl[minor(dev)];
    221 
    222     if (!VC_OPEN(&mi->mi_vcomm)) {
    223 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    224 	return(ENODEV);
    225     }
    226 
    227     /* No initialization (here) of mi_vcomm! */
    228     vfsp->mnt_data = mi;
    229     vfsp->mnt_stat.f_fsidx.__fsid_val[0] = 0;
    230     vfsp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_CODA);
    231     vfsp->mnt_stat.f_fsid = vfsp->mnt_stat.f_fsidx.__fsid_val[0];
    232     vfsp->mnt_stat.f_namemax = MAXNAMLEN;
    233     mi->mi_vfsp = vfsp;
    234 
    235     /*
    236      * Make a root vnode to placate the Vnode interface, but don't
    237      * actually make the CODA_ROOT call to venus until the first call
    238      * to coda_root in case a server is down while venus is starting.
    239      */
    240     cp = make_coda_node(&rootfid, vfsp, VDIR);
    241     rootvp = CTOV(cp);
    242     rootvp->v_flag |= VROOT;
    243 
    244 /*  cp = make_coda_node(&ctlfid, vfsp, VCHR);
    245     The above code seems to cause a loop in the cnode links.
    246     I don't totally understand when it happens, it is caught
    247     when closing down the system.
    248  */
    249     cp = make_coda_node(&ctlfid, 0, VCHR);
    250 
    251     coda_ctlvp = CTOV(cp);
    252 
    253     /* Add vfs and rootvp to chain of vfs hanging off mntinfo */
    254     mi->mi_vfsp = vfsp;
    255     mi->mi_rootvp = rootvp;
    256 
    257     /* set filesystem block size */
    258     vfsp->mnt_stat.f_bsize = 8192;	    /* XXX -JJK */
    259     vfsp->mnt_stat.f_frsize = 8192;	    /* XXX -JJK */
    260 
    261     /* error is currently guaranteed to be zero, but in case some
    262        code changes... */
    263     CODADEBUG(1,
    264 	     myprintf(("coda_mount returned %d\n",error)););
    265     if (error)
    266 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    267     else
    268 	MARK_INT_SAT(CODA_MOUNT_STATS);
    269 
    270     return set_statvfs_info("/coda", UIO_SYSSPACE, "CODA", UIO_SYSSPACE, vfsp,
    271 	p);
    272 }
    273 
    274 int
    275 coda_start(vfsp, flags, p)
    276     struct mount *vfsp;
    277     int flags;
    278     struct proc *p;
    279 {
    280     ENTRY;
    281     vftomi(vfsp)->mi_started = 1;
    282     return (0);
    283 }
    284 
    285 int
    286 coda_unmount(vfsp, mntflags, p)
    287     struct mount *vfsp;
    288     int mntflags;
    289     struct proc *p;
    290 {
    291     struct coda_mntinfo *mi = vftomi(vfsp);
    292     int active, error = 0;
    293 
    294     ENTRY;
    295     MARK_ENTRY(CODA_UMOUNT_STATS);
    296     if (!CODA_MOUNTED(vfsp)) {
    297 	MARK_INT_FAIL(CODA_UMOUNT_STATS);
    298 	return(EINVAL);
    299     }
    300 
    301     if (mi->mi_vfsp == vfsp) {	/* We found the victim */
    302 	if (!IS_UNMOUNTING(VTOC(mi->mi_rootvp)))
    303 	    return (EBUSY); 	/* Venus is still running */
    304 
    305 #ifdef	DEBUG
    306 	printf("coda_unmount: ROOT: vp %p, cp %p\n", mi->mi_rootvp, VTOC(mi->mi_rootvp));
    307 #endif
    308 	mi->mi_started = 0;
    309 
    310 	vrele(mi->mi_rootvp);
    311 
    312 	active = coda_kill(vfsp, NOT_DOWNCALL);
    313 	mi->mi_rootvp->v_flag &= ~VROOT;
    314 	error = vflush(mi->mi_vfsp, NULLVP, FORCECLOSE);
    315 	printf("coda_unmount: active = %d, vflush active %d\n", active, error);
    316 	error = 0;
    317 
    318 	/* I'm going to take this out to allow lookups to go through. I'm
    319 	 * not sure it's important anyway. -- DCS 2/2/94
    320 	 */
    321 	/* vfsp->VFS_DATA = NULL; */
    322 
    323 	/* No more vfsp's to hold onto */
    324 	mi->mi_vfsp = NULL;
    325 	mi->mi_rootvp = NULL;
    326 
    327 	if (error)
    328 	    MARK_INT_FAIL(CODA_UMOUNT_STATS);
    329 	else
    330 	    MARK_INT_SAT(CODA_UMOUNT_STATS);
    331 
    332 	return(error);
    333     }
    334     return (EINVAL);
    335 }
    336 
    337 /*
    338  * find root of cfs
    339  */
    340 int
    341 coda_root(vfsp, vpp)
    342 	struct mount *vfsp;
    343 	struct vnode **vpp;
    344 {
    345     struct coda_mntinfo *mi = vftomi(vfsp);
    346     int error;
    347     struct proc *p = curproc;    /* XXX - bnoble */
    348     CodaFid VFid;
    349     static const CodaFid invalfid = INVAL_FID;
    350 
    351     ENTRY;
    352     MARK_ENTRY(CODA_ROOT_STATS);
    353 
    354     if (vfsp == mi->mi_vfsp) {
    355     	if (memcmp(&VTOC(mi->mi_rootvp)->c_fid, &invalfid, sizeof(CodaFid)))
    356 	    { /* Found valid root. */
    357 		*vpp = mi->mi_rootvp;
    358 		/* On Mach, this is vref.  On NetBSD, VOP_LOCK */
    359 		vref(*vpp);
    360 		vn_lock(*vpp, LK_EXCLUSIVE);
    361 		MARK_INT_SAT(CODA_ROOT_STATS);
    362 		return(0);
    363 	    }
    364     }
    365 
    366     error = venus_root(vftomi(vfsp), p->p_cred->pc_ucred, p, &VFid);
    367 
    368     if (!error) {
    369 	/*
    370 	 * Save the new rootfid in the cnode, and rehash the cnode into the
    371 	 * cnode hash with the new fid key.
    372 	 */
    373 	coda_unsave(VTOC(mi->mi_rootvp));
    374 	VTOC(mi->mi_rootvp)->c_fid = VFid;
    375 	coda_save(VTOC(mi->mi_rootvp));
    376 
    377 	*vpp = mi->mi_rootvp;
    378 	vref(*vpp);
    379 	vn_lock(*vpp, LK_EXCLUSIVE);
    380 	MARK_INT_SAT(CODA_ROOT_STATS);
    381 	goto exit;
    382     } else if (error == ENODEV || error == EINTR) {
    383 	/* Gross hack here! */
    384 	/*
    385 	 * If Venus fails to respond to the CODA_ROOT call, coda_call returns
    386 	 * ENODEV. Return the uninitialized root vnode to allow vfs
    387 	 * operations such as unmount to continue. Without this hack,
    388 	 * there is no way to do an unmount if Venus dies before a
    389 	 * successful CODA_ROOT call is done. All vnode operations
    390 	 * will fail.
    391 	 */
    392 	*vpp = mi->mi_rootvp;
    393 	vref(*vpp);
    394 	vn_lock(*vpp, LK_EXCLUSIVE);
    395 	MARK_INT_FAIL(CODA_ROOT_STATS);
    396 	error = 0;
    397 	goto exit;
    398     } else {
    399 	CODADEBUG( CODA_ROOT, myprintf(("error %d in CODA_ROOT\n", error)); );
    400 	MARK_INT_FAIL(CODA_ROOT_STATS);
    401 
    402 	goto exit;
    403     }
    404  exit:
    405     return(error);
    406 }
    407 
    408 int
    409 coda_quotactl(vfsp, cmd, uid, arg, p)
    410     struct mount *vfsp;
    411     int cmd;
    412     uid_t uid;
    413     caddr_t arg;
    414     struct proc *p;
    415 {
    416     ENTRY;
    417     return (EOPNOTSUPP);
    418 }
    419 
    420 /*
    421  * Get file system statistics.
    422  */
    423 int
    424 coda_nb_statvfs(vfsp, sbp, p)
    425     struct mount *vfsp;
    426     struct statvfs *sbp;
    427     struct proc *p;
    428 {
    429     struct coda_statfs fsstat;
    430     int error;
    431 
    432     ENTRY;
    433     MARK_ENTRY(CODA_STATFS_STATS);
    434     if (!CODA_MOUNTED(vfsp)) {
    435 /*	MARK_INT_FAIL(CODA_STATFS_STATS); */
    436 	return(EINVAL);
    437     }
    438 
    439     /* XXX - what to do about f_flags, others? --bnoble */
    440     /* Below This is what AFS does
    441     	#define NB_SFS_SIZ 0x895440
    442      */
    443     /* Note: Normal fs's have a bsize of 0x400 == 1024 */
    444 
    445     error = venus_statfs(vftomi(vfsp), p->p_cred->pc_ucred, p, &fsstat);
    446 
    447     if (!error) {
    448 	sbp->f_bsize = 8192; /* XXX */
    449 	sbp->f_frsize = 8192; /* XXX */
    450 	sbp->f_iosize = 8192; /* XXX */
    451 	sbp->f_blocks = fsstat.f_blocks;
    452 	sbp->f_bfree  = fsstat.f_bfree;
    453 	sbp->f_bavail = fsstat.f_bavail;
    454 	sbp->f_bresvd = 0;
    455 	sbp->f_files  = fsstat.f_files;
    456 	sbp->f_ffree  = fsstat.f_ffree;
    457 	sbp->f_favail = fsstat.f_ffree;
    458 	sbp->f_fresvd = 0;
    459 	copy_statvfs_info(sbp, vfsp);
    460     }
    461 
    462     MARK_INT_SAT(CODA_STATFS_STATS);
    463     return(error);
    464 }
    465 
    466 /*
    467  * Flush any pending I/O.
    468  */
    469 int
    470 coda_sync(vfsp, waitfor, cred, p)
    471     struct mount *vfsp;
    472     int    waitfor;
    473     struct ucred *cred;
    474     struct proc *p;
    475 {
    476     ENTRY;
    477     MARK_ENTRY(CODA_SYNC_STATS);
    478     MARK_INT_SAT(CODA_SYNC_STATS);
    479     return(0);
    480 }
    481 
    482 int
    483 coda_vget(vfsp, ino, vpp)
    484     struct mount *vfsp;
    485     ino_t ino;
    486     struct vnode **vpp;
    487 {
    488     ENTRY;
    489     return (EOPNOTSUPP);
    490 }
    491 
    492 /*
    493  * fhtovp is now what vget used to be in 4.3-derived systems.  For
    494  * some silly reason, vget is now keyed by a 32 bit ino_t, rather than
    495  * a type-specific fid.
    496  */
    497 int
    498 coda_fhtovp(vfsp, fhp, nam, vpp, exflagsp, creadanonp)
    499     struct mount *vfsp;
    500     struct fid *fhp;
    501     struct mbuf *nam;
    502     struct vnode **vpp;
    503     int *exflagsp;
    504     struct ucred **creadanonp;
    505 {
    506     struct cfid *cfid = (struct cfid *)fhp;
    507     struct cnode *cp = 0;
    508     int error;
    509     struct proc *p = curproc; /* XXX -mach */
    510     CodaFid VFid;
    511     int vtype;
    512 
    513     ENTRY;
    514 
    515     MARK_ENTRY(CODA_VGET_STATS);
    516     /* Check for vget of control object. */
    517     if (IS_CTL_FID(&cfid->cfid_fid)) {
    518 	*vpp = coda_ctlvp;
    519 	vref(coda_ctlvp);
    520 	MARK_INT_SAT(CODA_VGET_STATS);
    521 	return(0);
    522     }
    523 
    524     error = venus_fhtovp(vftomi(vfsp), &cfid->cfid_fid, p->p_cred->pc_ucred, p, &VFid, &vtype);
    525 
    526     if (error) {
    527 	CODADEBUG(CODA_VGET, myprintf(("vget error %d\n",error));)
    528 	    *vpp = (struct vnode *)0;
    529     } else {
    530 	CODADEBUG(CODA_VGET,
    531 		 myprintf(("vget: %s type %d result %d\n",
    532 			coda_f2s(&VFid), vtype, error)); )
    533 
    534 	cp = make_coda_node(&VFid, vfsp, vtype);
    535 	*vpp = CTOV(cp);
    536     }
    537     return(error);
    538 }
    539 
    540 int
    541 coda_vptofh(vnp, fidp)
    542     struct vnode *vnp;
    543     struct fid   *fidp;
    544 {
    545     ENTRY;
    546     return (EOPNOTSUPP);
    547 }
    548 
    549 void
    550 coda_init(void)
    551 {
    552     ENTRY;
    553 }
    554 
    555 void
    556 coda_done(void)
    557 {
    558     ENTRY;
    559 }
    560 
    561 SYSCTL_SETUP(sysctl_vfs_coda_setup, "sysctl vfs.coda subtree setup")
    562 {
    563 	sysctl_createv(clog, 0, NULL, NULL,
    564 		       CTLFLAG_PERMANENT,
    565 		       CTLTYPE_NODE, "vfs", NULL,
    566 		       NULL, 0, NULL, 0,
    567 		       CTL_VFS, CTL_EOL);
    568 	sysctl_createv(clog, 0, NULL, NULL,
    569 		       CTLFLAG_PERMANENT,
    570 		       CTLTYPE_NODE, "coda", NULL,
    571 		       NULL, 0, NULL, 0,
    572 		       CTL_VFS, 18, CTL_EOL);
    573 	/*
    574 	 * XXX the "18" above could be dynamic, thereby eliminating
    575 	 * one more instance of the "number to vfs" mapping problem,
    576 	 * but "18" is the order as taken from sys/mount.h
    577 	 */
    578 
    579 /*
    580 	sysctl_createv(clog, 0, NULL, NULL,
    581 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    582 		       CTLTYPE_INT, "clusterread", NULL,
    583 		       NULL, 0, &doclusterread, 0,
    584 		       CTL_VFS, 18, FFS_CLUSTERREAD, CTL_EOL);
    585 */
    586 }
    587 
    588 /*
    589  * To allow for greater ease of use, some vnodes may be orphaned when
    590  * Venus dies.  Certain operations should still be allowed to go
    591  * through, but without propagating orphan-ness.  So this function will
    592  * get a new vnode for the file from the current run of Venus.
    593  */
    594 
    595 int
    596 getNewVnode(vpp)
    597      struct vnode **vpp;
    598 {
    599     struct cfid cfid;
    600     struct coda_mntinfo *mi = vftomi((*vpp)->v_mount);
    601 
    602     ENTRY;
    603 
    604     cfid.cfid_len = (short)sizeof(CodaFid);
    605     cfid.cfid_fid = VTOC(*vpp)->c_fid;	/* Structure assignment. */
    606     /* XXX ? */
    607 
    608     /* We're guessing that if set, the 1st element on the list is a
    609      * valid vnode to use. If not, return ENODEV as venus is dead.
    610      */
    611     if (mi->mi_vfsp == NULL)
    612 	return ENODEV;
    613 
    614     return coda_fhtovp(mi->mi_vfsp, (struct fid*)&cfid, NULL, vpp,
    615 		      NULL, NULL);
    616 }
    617 
    618 #include <ufs/ufs/quota.h>
    619 #include <ufs/ufs/ufsmount.h>
    620 /* get the mount structure corresponding to a given device.  Assume
    621  * device corresponds to a UFS. Return NULL if no device is found.
    622  */
    623 struct mount *devtomp(dev)
    624     dev_t dev;
    625 {
    626     struct mount *mp, *nmp;
    627 
    628     for (mp = mountlist.cqh_first; mp != (void*)&mountlist; mp = nmp) {
    629 	nmp = mp->mnt_list.cqe_next;
    630 	if ((!strcmp(mp->mnt_op->vfs_name, MOUNT_UFS)) &&
    631 	    ((VFSTOUFS(mp))->um_dev == (dev_t) dev)) {
    632 	    /* mount corresponds to UFS and the device matches one we want */
    633 	    return(mp);
    634 	}
    635     }
    636     /* mount structure wasn't found */
    637     return(NULL);
    638 }
    639