Home | History | Annotate | Line # | Download | only in coda
coda_vfsops.c revision 1.64
      1 /*	$NetBSD: coda_vfsops.c,v 1.64 2008/01/28 14:31:15 dholland 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.64 2008/01/28 14:31:15 dholland 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 #include <sys/kauth.h>
     67 
     68 #include <coda/coda.h>
     69 #include <coda/cnode.h>
     70 #include <coda/coda_vfsops.h>
     71 #include <coda/coda_venus.h>
     72 #include <coda/coda_subr.h>
     73 #include <coda/coda_opstats.h>
     74 /* for VN_RDEV */
     75 #include <miscfs/specfs/specdev.h>
     76 #include <miscfs/genfs/genfs.h>
     77 
     78 MALLOC_DEFINE(M_CODA, "coda", "Coda file system structures and tables");
     79 
     80 int codadebug = 0;
     81 
     82 int coda_vfsop_print_entry = 0;
     83 #define ENTRY if(coda_vfsop_print_entry) myprintf(("Entered %s\n",__func__))
     84 
     85 struct vnode *coda_ctlvp;
     86 struct coda_mntinfo coda_mnttbl[NVCODA]; /* indexed by minor device number */
     87 
     88 /* structure to keep statistics of internally generated/satisfied calls */
     89 
     90 struct coda_op_stats coda_vfsopstats[CODA_VFSOPS_SIZE];
     91 
     92 #define MARK_ENTRY(op) (coda_vfsopstats[op].entries++)
     93 #define MARK_INT_SAT(op) (coda_vfsopstats[op].sat_intrn++)
     94 #define MARK_INT_FAIL(op) (coda_vfsopstats[op].unsat_intrn++)
     95 #define MRAK_INT_GEN(op) (coda_vfsopstats[op].gen_intrn++)
     96 
     97 extern const struct cdevsw vcoda_cdevsw;
     98 extern const struct vnodeopv_desc coda_vnodeop_opv_desc;
     99 
    100 const struct vnodeopv_desc * const coda_vnodeopv_descs[] = {
    101 	&coda_vnodeop_opv_desc,
    102 	NULL,
    103 };
    104 
    105 struct vfsops coda_vfsops = {
    106     MOUNT_CODA,
    107     256,		/* This is the pathname, unlike every other fs */
    108     coda_mount,
    109     coda_start,
    110     coda_unmount,
    111     coda_root,
    112     (void *)eopnotsupp,	/* vfs_quotactl */
    113     coda_nb_statvfs,
    114     coda_sync,
    115     coda_vget,
    116     (void *)eopnotsupp,	/* vfs_fhtovp */
    117     (void *)eopnotsupp,	/* vfs_vptofh */
    118     coda_init,
    119     NULL,		/* vfs_reinit */
    120     coda_done,
    121     (int (*)(void)) eopnotsupp,
    122     (int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
    123     vfs_stdextattrctl,
    124     (void *)eopnotsupp,	/* vfs_suspendctl */
    125     genfs_renamelock_enter,
    126     genfs_renamelock_exit,
    127     coda_vnodeopv_descs,
    128     0,			/* vfs_refcount */
    129     { NULL, NULL },	/* vfs_list */
    130 };
    131 
    132 VFS_ATTACH(coda_vfsops);
    133 
    134 int
    135 coda_vfsopstats_init(void)
    136 {
    137 	int i;
    138 
    139 	for (i=0;i<CODA_VFSOPS_SIZE;i++) {
    140 		coda_vfsopstats[i].opcode = i;
    141 		coda_vfsopstats[i].entries = 0;
    142 		coda_vfsopstats[i].sat_intrn = 0;
    143 		coda_vfsopstats[i].unsat_intrn = 0;
    144 		coda_vfsopstats[i].gen_intrn = 0;
    145 	}
    146 
    147 	return 0;
    148 }
    149 
    150 /*
    151  * cfs mount vfsop
    152  * Set up mount info record and attach it to vfs struct.
    153  */
    154 /*ARGSUSED*/
    155 int
    156 coda_mount(struct mount *vfsp,	/* Allocated and initialized by mount(2) */
    157     const char *path,	/* path covered: ignored by the fs-layer */
    158     void *data,		/* Need to define a data type for this in netbsd? */
    159     size_t *data_len)
    160 {
    161     struct lwp *l = curlwp;
    162     struct nameidata nd;
    163     struct vnode *dvp;
    164     struct cnode *cp;
    165     dev_t dev;
    166     struct coda_mntinfo *mi;
    167     struct vnode *rtvp;
    168     const struct cdevsw *cdev;
    169     CodaFid rootfid = INVAL_FID;
    170     CodaFid ctlfid = CTL_FID;
    171     int error;
    172 
    173     if (vfsp->mnt_flag & MNT_GETARGS)
    174 	return EINVAL;
    175     ENTRY;
    176 
    177     coda_vfsopstats_init();
    178     coda_vnodeopstats_init();
    179 
    180     MARK_ENTRY(CODA_MOUNT_STATS);
    181     if (CODA_MOUNTED(vfsp)) {
    182 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    183 	return(EBUSY);
    184     }
    185 
    186     /* Validate mount device.  Similar to getmdev(). */
    187 
    188     /*
    189      * XXX: coda passes the mount device as the entire mount args,
    190      * All other fs pass a structure contining a pointer.
    191      * In order to get sys_mount() to do the copyin() we've set a
    192      * fixed default size for the filename buffer.
    193      */
    194     /* Ensure that namei() doesn't run off the filename buffer */
    195     ((char *)data)[*data_len - 1] = 0;
    196     NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, data);
    197     error = namei(&nd);
    198     dvp = nd.ni_vp;
    199 
    200     if (error) {
    201 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    202 	return (error);
    203     }
    204     if (dvp->v_type != VCHR) {
    205 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    206 	vrele(dvp);
    207 	return(ENXIO);
    208     }
    209     dev = dvp->v_rdev;
    210     vrele(dvp);
    211     cdev = cdevsw_lookup(dev);
    212     if (cdev == NULL) {
    213 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    214 	return(ENXIO);
    215     }
    216 
    217     /*
    218      * See if the device table matches our expectations.
    219      */
    220     if (cdev != &vcoda_cdevsw)
    221     {
    222 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    223 	return(ENXIO);
    224     }
    225 
    226     if (minor(dev) >= NVCODA || minor(dev) < 0) {
    227 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    228 	return(ENXIO);
    229     }
    230 
    231     /*
    232      * Initialize the mount record and link it to the vfs struct
    233      */
    234     mi = &coda_mnttbl[minor(dev)];
    235 
    236     if (!VC_OPEN(&mi->mi_vcomm)) {
    237 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    238 	return(ENODEV);
    239     }
    240 
    241     /* No initialization (here) of mi_vcomm! */
    242     vfsp->mnt_data = mi;
    243     vfsp->mnt_stat.f_fsidx.__fsid_val[0] = 0;
    244     vfsp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_CODA);
    245     vfsp->mnt_stat.f_fsid = vfsp->mnt_stat.f_fsidx.__fsid_val[0];
    246     vfsp->mnt_stat.f_namemax = MAXNAMLEN;
    247     mi->mi_vfsp = vfsp;
    248 
    249     /*
    250      * Make a root vnode to placate the Vnode interface, but don't
    251      * actually make the CODA_ROOT call to venus until the first call
    252      * to coda_root in case a server is down while venus is starting.
    253      */
    254     cp = make_coda_node(&rootfid, vfsp, VDIR);
    255     rtvp = CTOV(cp);
    256     rtvp->v_vflag |= VV_ROOT;
    257 
    258 /*  cp = make_coda_node(&ctlfid, vfsp, VCHR);
    259     The above code seems to cause a loop in the cnode links.
    260     I don't totally understand when it happens, it is caught
    261     when closing down the system.
    262  */
    263     cp = make_coda_node(&ctlfid, 0, VCHR);
    264 
    265     coda_ctlvp = CTOV(cp);
    266 
    267     /* Add vfs and rootvp to chain of vfs hanging off mntinfo */
    268     mi->mi_vfsp = vfsp;
    269     mi->mi_rootvp = rtvp;
    270 
    271     /* set filesystem block size */
    272     vfsp->mnt_stat.f_bsize = 8192;	    /* XXX -JJK */
    273     vfsp->mnt_stat.f_frsize = 8192;	    /* XXX -JJK */
    274 
    275     /* error is currently guaranteed to be zero, but in case some
    276        code changes... */
    277     CODADEBUG(1,
    278 	     myprintf(("coda_mount returned %d\n",error)););
    279     if (error)
    280 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    281     else
    282 	MARK_INT_SAT(CODA_MOUNT_STATS);
    283 
    284     return set_statvfs_info("/coda", UIO_SYSSPACE, "CODA", UIO_SYSSPACE,
    285 	vfsp->mnt_op->vfs_name, vfsp, l);
    286 }
    287 
    288 int
    289 coda_start(struct mount *vfsp, int flags)
    290 {
    291     ENTRY;
    292     vftomi(vfsp)->mi_started = 1;
    293     return (0);
    294 }
    295 
    296 int
    297 coda_unmount(struct mount *vfsp, int mntflags)
    298 {
    299     struct coda_mntinfo *mi = vftomi(vfsp);
    300     int active, error = 0;
    301 
    302     ENTRY;
    303     MARK_ENTRY(CODA_UMOUNT_STATS);
    304     if (!CODA_MOUNTED(vfsp)) {
    305 	MARK_INT_FAIL(CODA_UMOUNT_STATS);
    306 	return(EINVAL);
    307     }
    308 
    309     if (mi->mi_vfsp == vfsp) {	/* We found the victim */
    310 	if (!IS_UNMOUNTING(VTOC(mi->mi_rootvp)))
    311 	    return (EBUSY); 	/* Venus is still running */
    312 
    313 #ifdef	DEBUG
    314 	printf("coda_unmount: ROOT: vp %p, cp %p\n", mi->mi_rootvp, VTOC(mi->mi_rootvp));
    315 #endif
    316 	mi->mi_started = 0;
    317 
    318 	vrele(mi->mi_rootvp);
    319 
    320 	active = coda_kill(vfsp, NOT_DOWNCALL);
    321 	mi->mi_rootvp->v_vflag &= ~VV_ROOT;
    322 	error = vflush(mi->mi_vfsp, NULLVP, FORCECLOSE);
    323 	printf("coda_unmount: active = %d, vflush active %d\n", active, error);
    324 	error = 0;
    325 
    326 	/* I'm going to take this out to allow lookups to go through. I'm
    327 	 * not sure it's important anyway. -- DCS 2/2/94
    328 	 */
    329 	/* vfsp->VFS_DATA = NULL; */
    330 
    331 	/* No more vfsp's to hold onto */
    332 	mi->mi_vfsp = NULL;
    333 	mi->mi_rootvp = NULL;
    334 
    335 	if (error)
    336 	    MARK_INT_FAIL(CODA_UMOUNT_STATS);
    337 	else
    338 	    MARK_INT_SAT(CODA_UMOUNT_STATS);
    339 
    340 	return(error);
    341     }
    342     return (EINVAL);
    343 }
    344 
    345 /*
    346  * find root of cfs
    347  */
    348 int
    349 coda_root(struct mount *vfsp, struct vnode **vpp)
    350 {
    351     struct coda_mntinfo *mi = vftomi(vfsp);
    352     int error;
    353     struct lwp *l = curlwp;    /* XXX - bnoble */
    354     CodaFid VFid;
    355     static const CodaFid invalfid = INVAL_FID;
    356 
    357     ENTRY;
    358     MARK_ENTRY(CODA_ROOT_STATS);
    359 
    360     if (vfsp == mi->mi_vfsp) {
    361     	if (memcmp(&VTOC(mi->mi_rootvp)->c_fid, &invalfid, sizeof(CodaFid)))
    362 	    { /* Found valid root. */
    363 		*vpp = mi->mi_rootvp;
    364 		/* On Mach, this is vref.  On NetBSD, VOP_LOCK */
    365 		vref(*vpp);
    366 		vn_lock(*vpp, LK_EXCLUSIVE);
    367 		MARK_INT_SAT(CODA_ROOT_STATS);
    368 		return(0);
    369 	    }
    370     }
    371 
    372     error = venus_root(vftomi(vfsp), l->l_cred, l->l_proc, &VFid);
    373 
    374     if (!error) {
    375 	/*
    376 	 * Save the new rootfid in the cnode, and rehash the cnode into the
    377 	 * cnode hash with the new fid key.
    378 	 */
    379 	coda_unsave(VTOC(mi->mi_rootvp));
    380 	VTOC(mi->mi_rootvp)->c_fid = VFid;
    381 	coda_save(VTOC(mi->mi_rootvp));
    382 
    383 	*vpp = mi->mi_rootvp;
    384 	vref(*vpp);
    385 	vn_lock(*vpp, LK_EXCLUSIVE);
    386 	MARK_INT_SAT(CODA_ROOT_STATS);
    387 	goto exit;
    388     } else if (error == ENODEV || error == EINTR) {
    389 	/* Gross hack here! */
    390 	/*
    391 	 * If Venus fails to respond to the CODA_ROOT call, coda_call returns
    392 	 * ENODEV. Return the uninitialized root vnode to allow vfs
    393 	 * operations such as unmount to continue. Without this hack,
    394 	 * there is no way to do an unmount if Venus dies before a
    395 	 * successful CODA_ROOT call is done. All vnode operations
    396 	 * will fail.
    397 	 */
    398 	*vpp = mi->mi_rootvp;
    399 	vref(*vpp);
    400 	vn_lock(*vpp, LK_EXCLUSIVE);
    401 	MARK_INT_FAIL(CODA_ROOT_STATS);
    402 	error = 0;
    403 	goto exit;
    404     } else {
    405 	CODADEBUG( CODA_ROOT, myprintf(("error %d in CODA_ROOT\n", error)); );
    406 	MARK_INT_FAIL(CODA_ROOT_STATS);
    407 
    408 	goto exit;
    409     }
    410  exit:
    411     return(error);
    412 }
    413 
    414 /*
    415  * Get file system statistics.
    416  */
    417 int
    418 coda_nb_statvfs(struct mount *vfsp, struct statvfs *sbp)
    419 {
    420     struct lwp *l = curlwp;
    421     struct coda_statfs fsstat;
    422     int error;
    423 
    424     ENTRY;
    425     MARK_ENTRY(CODA_STATFS_STATS);
    426     if (!CODA_MOUNTED(vfsp)) {
    427 /*	MARK_INT_FAIL(CODA_STATFS_STATS); */
    428 	return(EINVAL);
    429     }
    430 
    431     /* XXX - what to do about f_flags, others? --bnoble */
    432     /* Below This is what AFS does
    433     	#define NB_SFS_SIZ 0x895440
    434      */
    435     /* Note: Normal fs's have a bsize of 0x400 == 1024 */
    436 
    437     error = venus_statfs(vftomi(vfsp), l->l_cred, l, &fsstat);
    438 
    439     if (!error) {
    440 	sbp->f_bsize = 8192; /* XXX */
    441 	sbp->f_frsize = 8192; /* XXX */
    442 	sbp->f_iosize = 8192; /* XXX */
    443 	sbp->f_blocks = fsstat.f_blocks;
    444 	sbp->f_bfree  = fsstat.f_bfree;
    445 	sbp->f_bavail = fsstat.f_bavail;
    446 	sbp->f_bresvd = 0;
    447 	sbp->f_files  = fsstat.f_files;
    448 	sbp->f_ffree  = fsstat.f_ffree;
    449 	sbp->f_favail = fsstat.f_ffree;
    450 	sbp->f_fresvd = 0;
    451 	copy_statvfs_info(sbp, vfsp);
    452     }
    453 
    454     MARK_INT_SAT(CODA_STATFS_STATS);
    455     return(error);
    456 }
    457 
    458 /*
    459  * Flush any pending I/O.
    460  */
    461 int
    462 coda_sync(struct mount *vfsp, int waitfor,
    463     kauth_cred_t cred)
    464 {
    465     ENTRY;
    466     MARK_ENTRY(CODA_SYNC_STATS);
    467     MARK_INT_SAT(CODA_SYNC_STATS);
    468     return(0);
    469 }
    470 
    471 int
    472 coda_vget(struct mount *vfsp, ino_t ino,
    473     struct vnode **vpp)
    474 {
    475     ENTRY;
    476     return (EOPNOTSUPP);
    477 }
    478 
    479 /*
    480  * fhtovp is now what vget used to be in 4.3-derived systems.  For
    481  * some silly reason, vget is now keyed by a 32 bit ino_t, rather than
    482  * a type-specific fid.
    483  */
    484 int
    485 coda_fhtovp(struct mount *vfsp, struct fid *fhp, struct mbuf *nam,
    486     struct vnode **vpp, int *exflagsp,
    487     kauth_cred_t *creadanonp)
    488 {
    489     struct cfid *cfid = (struct cfid *)fhp;
    490     struct cnode *cp = 0;
    491     int error;
    492     struct lwp *l = curlwp; /* XXX -mach */
    493     CodaFid VFid;
    494     int vtype;
    495 
    496     ENTRY;
    497 
    498     MARK_ENTRY(CODA_VGET_STATS);
    499     /* Check for vget of control object. */
    500     if (IS_CTL_FID(&cfid->cfid_fid)) {
    501 	*vpp = coda_ctlvp;
    502 	vref(coda_ctlvp);
    503 	MARK_INT_SAT(CODA_VGET_STATS);
    504 	return(0);
    505     }
    506 
    507     error = venus_fhtovp(vftomi(vfsp), &cfid->cfid_fid, l->l_cred, l->l_proc, &VFid, &vtype);
    508 
    509     if (error) {
    510 	CODADEBUG(CODA_VGET, myprintf(("vget error %d\n",error));)
    511 	    *vpp = (struct vnode *)0;
    512     } else {
    513 	CODADEBUG(CODA_VGET,
    514 		 myprintf(("vget: %s type %d result %d\n",
    515 			coda_f2s(&VFid), vtype, error)); )
    516 
    517 	cp = make_coda_node(&VFid, vfsp, vtype);
    518 	*vpp = CTOV(cp);
    519     }
    520     return(error);
    521 }
    522 
    523 int
    524 coda_vptofh(struct vnode *vnp, struct fid *fidp)
    525 {
    526     ENTRY;
    527     return (EOPNOTSUPP);
    528 }
    529 
    530 void
    531 coda_init(void)
    532 {
    533     ENTRY;
    534 }
    535 
    536 void
    537 coda_done(void)
    538 {
    539     ENTRY;
    540 }
    541 
    542 SYSCTL_SETUP(sysctl_vfs_coda_setup, "sysctl vfs.coda subtree setup")
    543 {
    544 	sysctl_createv(clog, 0, NULL, NULL,
    545 		       CTLFLAG_PERMANENT,
    546 		       CTLTYPE_NODE, "vfs", NULL,
    547 		       NULL, 0, NULL, 0,
    548 		       CTL_VFS, CTL_EOL);
    549 	sysctl_createv(clog, 0, NULL, NULL,
    550 		       CTLFLAG_PERMANENT,
    551 		       CTLTYPE_NODE, "coda",
    552 		       SYSCTL_DESCR("code vfs options"),
    553 		       NULL, 0, NULL, 0,
    554 		       CTL_VFS, 18, CTL_EOL);
    555 	/*
    556 	 * XXX the "18" above could be dynamic, thereby eliminating
    557 	 * one more instance of the "number to vfs" mapping problem,
    558 	 * but "18" is the order as taken from sys/mount.h
    559 	 */
    560 
    561 /*
    562 	sysctl_createv(clog, 0, NULL, NULL,
    563 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    564 		       CTLTYPE_INT, "clusterread",
    565 		       SYSCTL_DESCR( anyone? ),
    566 		       NULL, 0, &doclusterread, 0,
    567 		       CTL_VFS, 18, FFS_CLUSTERREAD, CTL_EOL);
    568 */
    569 }
    570 
    571 /*
    572  * To allow for greater ease of use, some vnodes may be orphaned when
    573  * Venus dies.  Certain operations should still be allowed to go
    574  * through, but without propagating orphan-ness.  So this function will
    575  * get a new vnode for the file from the current run of Venus.
    576  */
    577 
    578 int
    579 getNewVnode(struct vnode **vpp)
    580 {
    581     struct cfid cfid;
    582     struct coda_mntinfo *mi = vftomi((*vpp)->v_mount);
    583 
    584     ENTRY;
    585 
    586     cfid.cfid_len = (short)sizeof(CodaFid);
    587     cfid.cfid_fid = VTOC(*vpp)->c_fid;	/* Structure assignment. */
    588     /* XXX ? */
    589 
    590     /* We're guessing that if set, the 1st element on the list is a
    591      * valid vnode to use. If not, return ENODEV as venus is dead.
    592      */
    593     if (mi->mi_vfsp == NULL)
    594 	return ENODEV;
    595 
    596     return coda_fhtovp(mi->mi_vfsp, (struct fid*)&cfid, NULL, vpp,
    597 		      NULL, NULL);
    598 }
    599 
    600 #include <ufs/ufs/quota.h>
    601 #include <ufs/ufs/ufsmount.h>
    602 /* get the mount structure corresponding to a given device.  Assume
    603  * device corresponds to a UFS. Return NULL if no device is found.
    604  */
    605 struct mount *devtomp(dev_t dev)
    606 {
    607     struct mount *mp, *nmp;
    608 
    609     for (mp = mountlist.cqh_first; mp != (void*)&mountlist; mp = nmp) {
    610 	nmp = mp->mnt_list.cqe_next;
    611 	if ((!strcmp(mp->mnt_op->vfs_name, MOUNT_UFS)) &&
    612 	    ((VFSTOUFS(mp))->um_dev == (dev_t) dev)) {
    613 	    /* mount corresponds to UFS and the device matches one we want */
    614 	    return(mp);
    615 	}
    616     }
    617     /* mount structure wasn't found */
    618     return(NULL);
    619 }
    620