2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
27 * Copyright (c) 1989, 1993, 1995
28 * The Regents of the University of California. All rights reserved.
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by the University of
41 * California, Berkeley and its contributors.
42 * 4. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * @(#)spec_vnops.c 8.14 (Berkeley) 5/21/95
61 #include <sys/param.h>
63 #include <sys/systm.h>
64 #include <sys/kernel.h>
67 #include <sys/mount.h>
68 #include <sys/namei.h>
69 #include <sys/vnode.h>
71 #include <sys/errno.h>
72 #include <sys/ioctl.h>
74 #include <sys/malloc.h>
76 #include <miscfs/specfs/specdev.h>
77 #include <vfs/vfs_support.h>
79 #include <sys/kdebug.h>
81 struct vnode
*speclisth
[SPECHSZ
];
83 /* symbolic sleep message strings for devices */
84 char devopn
[] = "devopn";
85 char devio
[] = "devio";
86 char devwait
[] = "devwait";
87 char devin
[] = "devin";
88 char devout
[] = "devout";
89 char devioc
[] = "devioc";
90 char devcls
[] = "devcls";
92 #define VOPFUNC int (*)(void *)
94 int (**spec_vnodeop_p
)(void *);
95 struct vnodeopv_entry_desc spec_vnodeop_entries
[] = {
96 { &vop_default_desc
, (VOPFUNC
)vn_default_error
},
97 { &vop_lookup_desc
, (VOPFUNC
)spec_lookup
}, /* lookup */
98 { &vop_create_desc
, (VOPFUNC
)err_create
}, /* create */
99 { &vop_mknod_desc
, (VOPFUNC
)err_mknod
}, /* mknod */
100 { &vop_open_desc
, (VOPFUNC
)spec_open
}, /* open */
101 { &vop_close_desc
, (VOPFUNC
)spec_close
}, /* close */
102 { &vop_access_desc
, (VOPFUNC
)spec_access
}, /* access */
103 { &vop_getattr_desc
, (VOPFUNC
)spec_getattr
}, /* getattr */
104 { &vop_setattr_desc
, (VOPFUNC
)spec_setattr
}, /* setattr */
105 { &vop_read_desc
, (VOPFUNC
)spec_read
}, /* read */
106 { &vop_write_desc
, (VOPFUNC
)spec_write
}, /* write */
107 { &vop_lease_desc
, (VOPFUNC
)nop_lease
}, /* lease */
108 { &vop_ioctl_desc
, (VOPFUNC
)spec_ioctl
}, /* ioctl */
109 { &vop_select_desc
, (VOPFUNC
)spec_select
}, /* select */
110 { &vop_revoke_desc
, (VOPFUNC
)nop_revoke
}, /* revoke */
111 { &vop_mmap_desc
, (VOPFUNC
)err_mmap
}, /* mmap */
112 { &vop_fsync_desc
, (VOPFUNC
)spec_fsync
}, /* fsync */
113 { &vop_seek_desc
, (VOPFUNC
)err_seek
}, /* seek */
114 { &vop_remove_desc
, (VOPFUNC
)err_remove
}, /* remove */
115 { &vop_link_desc
, (VOPFUNC
)err_link
}, /* link */
116 { &vop_rename_desc
, (VOPFUNC
)err_rename
}, /* rename */
117 { &vop_mkdir_desc
, (VOPFUNC
)err_mkdir
}, /* mkdir */
118 { &vop_rmdir_desc
, (VOPFUNC
)err_rmdir
}, /* rmdir */
119 { &vop_symlink_desc
, (VOPFUNC
)err_symlink
}, /* symlink */
120 { &vop_readdir_desc
, (VOPFUNC
)err_readdir
}, /* readdir */
121 { &vop_readlink_desc
, (VOPFUNC
)err_readlink
}, /* readlink */
122 { &vop_abortop_desc
, (VOPFUNC
)err_abortop
}, /* abortop */
123 { &vop_inactive_desc
, (VOPFUNC
)nop_inactive
}, /* inactive */
124 { &vop_reclaim_desc
, (VOPFUNC
)nop_reclaim
}, /* reclaim */
125 { &vop_lock_desc
, (VOPFUNC
)nop_lock
}, /* lock */
126 { &vop_unlock_desc
, (VOPFUNC
)nop_unlock
}, /* unlock */
127 { &vop_bmap_desc
, (VOPFUNC
)spec_bmap
}, /* bmap */
128 { &vop_strategy_desc
, (VOPFUNC
)spec_strategy
}, /* strategy */
129 { &vop_print_desc
, (VOPFUNC
)spec_print
}, /* print */
130 { &vop_islocked_desc
, (VOPFUNC
)nop_islocked
}, /* islocked */
131 { &vop_pathconf_desc
, (VOPFUNC
)spec_pathconf
}, /* pathconf */
132 { &vop_advlock_desc
, (VOPFUNC
)err_advlock
}, /* advlock */
133 { &vop_blkatoff_desc
, (VOPFUNC
)err_blkatoff
}, /* blkatoff */
134 { &vop_valloc_desc
, (VOPFUNC
)err_valloc
}, /* valloc */
135 { &vop_vfree_desc
, (VOPFUNC
)err_vfree
}, /* vfree */
136 { &vop_truncate_desc
, (VOPFUNC
)nop_truncate
}, /* truncate */
137 { &vop_update_desc
, (VOPFUNC
)nop_update
}, /* update */
138 { &vop_bwrite_desc
, (VOPFUNC
)spec_bwrite
}, /* bwrite */
139 { &vop_devblocksize_desc
, (VOPFUNC
)spec_devblocksize
}, /* devblocksize */
140 { &vop_pagein_desc
, (VOPFUNC
)err_pagein
}, /* Pagein */
141 { &vop_pageout_desc
, (VOPFUNC
)err_pageout
}, /* Pageout */
142 { &vop_copyfile_desc
, (VOPFUNC
)err_copyfile
}, /* Copyfile */
143 { &vop_blktooff_desc
, (VOPFUNC
)spec_blktooff
}, /* blktooff */
144 { &vop_offtoblk_desc
, (VOPFUNC
)spec_offtoblk
}, /* offtoblk */
145 { &vop_cmap_desc
, (VOPFUNC
)spec_cmap
}, /* cmap */
146 { (struct vnodeop_desc
*)NULL
, (int(*)())NULL
}
148 struct vnodeopv_desc spec_vnodeop_opv_desc
=
149 { &spec_vnodeop_p
, spec_vnodeop_entries
};
152 * Trivial lookup routine that always fails.
156 struct vop_lookup_args
/* {
158 struct vnode **a_vpp;
159 struct componentname *a_cnp;
168 set_blocksize(struct vnode
*vp
, dev_t dev
)
173 if ((major(dev
) < nblkdev
) && (size
= bdevsw
[major(dev
)].d_psize
)) {
174 rsize
= (*size
)(dev
);
175 if (rsize
<= 0) /* did size fail? */
176 vp
->v_specsize
= DEV_BSIZE
;
178 vp
->v_specsize
= rsize
;
181 vp
->v_specsize
= DEV_BSIZE
;
185 set_fsblocksize(struct vnode
*vp
)
188 if (vp
->v_type
== VBLK
) {
189 dev_t dev
= (dev_t
)vp
->v_rdev
;
190 int maj
= major(dev
);
192 if ((u_int
)maj
>= nblkdev
)
195 set_blocksize(vp
, dev
);
202 * Open a special file.
206 struct vop_open_args
/* {
209 struct ucred *a_cred;
213 struct proc
*p
= ap
->a_p
;
214 struct vnode
*bvp
, *vp
= ap
->a_vp
;
215 dev_t bdev
, dev
= (dev_t
)vp
->v_rdev
;
216 int maj
= major(dev
);
220 * Don't allow open if fs is mounted -nodev.
222 if (vp
->v_mount
&& (vp
->v_mount
->mnt_flag
& MNT_NODEV
))
225 switch (vp
->v_type
) {
228 if ((u_int
)maj
>= nchrdev
)
230 if (ap
->a_cred
!= FSCRED
&& (ap
->a_mode
& FWRITE
)) {
232 * When running in very secure mode, do not allow
233 * opens for writing of any disk character devices.
235 if (securelevel
>= 2 && isdisk(dev
, VCHR
))
238 * When running in secure mode, do not allow opens
239 * for writing of /dev/mem, /dev/kmem, or character
240 * devices whose corresponding block devices are
243 if (securelevel
>= 1) {
244 if ((bdev
= chrtoblk(dev
)) != NODEV
&&
245 vfinddev(bdev
, VBLK
, &bvp
) &&
246 bvp
->v_usecount
> 0 &&
247 (error
= vfs_mountedon(bvp
)))
253 if (cdevsw
[maj
].d_type
== D_TTY
)
254 vp
->v_flag
|= VISTTY
;
255 VOP_UNLOCK(vp
, 0, p
);
256 error
= (*cdevsw
[maj
].d_open
)(dev
, ap
->a_mode
, S_IFCHR
, p
);
257 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
, p
);
261 if ((u_int
)maj
>= nblkdev
)
264 * When running in very secure mode, do not allow
265 * opens for writing of any disk block devices.
267 if (securelevel
>= 2 && ap
->a_cred
!= FSCRED
&&
268 (ap
->a_mode
& FWRITE
) && bdevsw
[maj
].d_type
== D_DISK
)
271 * Do not allow opens of block devices that are
274 if (error
= vfs_mountedon(vp
))
276 error
= (*bdevsw
[maj
].d_open
)(dev
, ap
->a_mode
, S_IFBLK
, p
);
281 set_blocksize(vp
, dev
);
284 * Cache the size in bytes of the block device for later
285 * use by spec_write().
287 vp
->v_specdevsize
= (u_int64_t
)0; /* Default: Can't get */
288 if (!VOP_IOCTL(vp
, DKIOCGETBLOCKSIZE
, (caddr_t
)&blksize
, 0, NOCRED
, p
)) {
289 /* Switch to 512 byte sectors (temporarily) */
290 u_int32_t size512
= 512;
292 if (!VOP_IOCTL(vp
, DKIOCSETBLOCKSIZE
, (caddr_t
)&size512
, FWRITE
, NOCRED
, p
)) {
293 /* Get the number of 512 byte physical blocks. */
294 if (!VOP_IOCTL(vp
, DKIOCGETBLOCKCOUNT
, (caddr_t
)&blkcnt
, 0, NOCRED
, p
)) {
295 vp
->v_specdevsize
= blkcnt
* (u_int64_t
)size512
;
298 /* If it doesn't set back, we can't recover */
299 if (VOP_IOCTL(vp
, DKIOCSETBLOCKSIZE
, (caddr_t
)&blksize
, FWRITE
, NOCRED
, p
))
313 struct vop_read_args
/* {
317 struct ucred *a_cred;
320 register struct vnode
*vp
= ap
->a_vp
;
321 register struct uio
*uio
= ap
->a_uio
;
322 struct proc
*p
= uio
->uio_procp
;
327 int n
, on
, majordev
, (*ioctl
)();
332 if (uio
->uio_rw
!= UIO_READ
)
333 panic("spec_read mode");
334 if (uio
->uio_segflg
== UIO_USERSPACE
&& uio
->uio_procp
!= current_proc())
335 panic("spec_read proc");
337 if (uio
->uio_resid
== 0)
340 switch (vp
->v_type
) {
343 VOP_UNLOCK(vp
, 0, p
);
344 error
= (*cdevsw
[major(vp
->v_rdev
)].d_read
)
345 (vp
->v_rdev
, uio
, ap
->a_ioflag
);
346 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
, p
);
350 if (uio
->uio_offset
< 0)
355 devBlockSize
= vp
->v_specsize
;
357 if (devBlockSize
> PAGE_SIZE
)
360 bscale
= PAGE_SIZE
/ devBlockSize
;
361 bsize
= bscale
* devBlockSize
;
364 on
= uio
->uio_offset
% bsize
;
366 bn
= (uio
->uio_offset
/ devBlockSize
) &~ (bscale
- 1);
368 if (vp
->v_lastr
+ bscale
== bn
) {
369 nextbn
= bn
+ bscale
;
370 error
= breadn(vp
, bn
, (int)bsize
, &nextbn
,
371 (int *)&bsize
, 1, NOCRED
, &bp
);
373 error
= bread(vp
, bn
, (int)bsize
, NOCRED
, &bp
);
376 n
= bsize
- bp
->b_resid
;
377 if ((on
> n
) || error
) {
383 n
= min((unsigned)(n
- on
), uio
->uio_resid
);
385 error
= uiomove((char *)bp
->b_data
+ on
, n
, uio
);
387 bp
->b_flags
|= B_AGE
;
389 } while (error
== 0 && uio
->uio_resid
> 0 && n
!= 0);
393 panic("spec_read type");
403 struct vop_write_args
/* {
407 struct ucred *a_cred;
410 register struct vnode
*vp
= ap
->a_vp
;
411 register struct uio
*uio
= ap
->a_uio
;
412 struct proc
*p
= uio
->uio_procp
;
415 int bsize
, blkmask
, bscale
;
416 register int io_sync
;
417 register int io_size
;
424 if (uio
->uio_rw
!= UIO_WRITE
)
425 panic("spec_write mode");
426 if (uio
->uio_segflg
== UIO_USERSPACE
&& uio
->uio_procp
!= current_proc())
427 panic("spec_write proc");
430 switch (vp
->v_type
) {
433 VOP_UNLOCK(vp
, 0, p
);
434 error
= (*cdevsw
[major(vp
->v_rdev
)].d_write
)
435 (vp
->v_rdev
, uio
, ap
->a_ioflag
);
436 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
, p
);
440 if (uio
->uio_resid
== 0)
442 if (uio
->uio_offset
< 0)
445 io_sync
= (ap
->a_ioflag
& IO_SYNC
);
446 io_size
= uio
->uio_resid
;
450 devBlockSize
= vp
->v_specsize
;
451 if (devBlockSize
> PAGE_SIZE
)
454 bscale
= PAGE_SIZE
/ devBlockSize
;
455 blkmask
= bscale
- 1;
456 bsize
= bscale
* devBlockSize
;
460 bn
= (uio
->uio_offset
/ devBlockSize
) &~ blkmask
;
461 on
= uio
->uio_offset
% bsize
;
463 n
= min((unsigned)(bsize
- on
), uio
->uio_resid
);
466 * Use getblk() as an optimization IFF:
468 * 1) We are reading exactly a block on a block
470 * 2) We know the size of the device from spec_open
471 * 3) The read doesn't span the end of the device
473 * Otherwise, we fall back on bread().
476 vp
->v_specdevsize
!= (u_int64_t
)0 &&
477 (uio
->uio_offset
+ (u_int64_t
)n
) > vp
->v_specdevsize
) {
478 /* reduce the size of the read to what is there */
479 n
= (uio
->uio_offset
+ (u_int64_t
)n
) - vp
->v_specdevsize
;
483 bp
= getblk(vp
, bn
, bsize
, 0, 0, BLK_WRITE
);
485 error
= bread(vp
, bn
, bsize
, NOCRED
, &bp
);
487 /* Translate downstream error for upstream, if needed */
490 if (!error
&& (bp
->b_flags
& B_ERROR
) != 0) {
498 n
= min(n
, bsize
- bp
->b_resid
);
500 error
= uiomove((char *)bp
->b_data
+ on
, n
, uio
);
502 bp
->b_flags
|= B_AGE
;
507 if ((n
+ on
) == bsize
)
512 } while (error
== 0 && uio
->uio_resid
> 0 && n
!= 0);
516 panic("spec_write type");
522 * Device ioctl operation.
526 struct vop_ioctl_args
/* {
531 struct ucred *a_cred;
535 dev_t dev
= ap
->a_vp
->v_rdev
;
537 switch (ap
->a_vp
->v_type
) {
540 return ((*cdevsw
[major(dev
)].d_ioctl
)(dev
, ap
->a_command
, ap
->a_data
,
541 ap
->a_fflag
, ap
->a_p
));
544 if (ap
->a_command
== 0 && (int)ap
->a_data
== B_TAPE
)
545 if (bdevsw
[major(dev
)].d_type
== D_TAPE
)
549 return ((*bdevsw
[major(dev
)].d_ioctl
)(dev
, ap
->a_command
, ap
->a_data
,
550 ap
->a_fflag
, ap
->a_p
));
560 struct vop_select_args
/* {
564 struct ucred *a_cred;
571 switch (ap
->a_vp
->v_type
) {
574 return (1); /* XXX */
577 dev
= ap
->a_vp
->v_rdev
;
578 return (*cdevsw
[major(dev
)].d_select
)(dev
, ap
->a_which
, ap
->a_wql
, ap
->a_p
);
582 * Synch buffers associated with a block device
587 struct vop_fsync_args
/* {
589 struct ucred *a_cred;
594 register struct vnode
*vp
= ap
->a_vp
;
595 register struct buf
*bp
;
599 if (vp
->v_type
== VCHR
)
602 * Flush all dirty buffers associated with a block device.
606 for (bp
= vp
->v_dirtyblkhd
.lh_first
; bp
; bp
= nbp
) {
607 nbp
= bp
->b_vnbufs
.le_next
;
608 // XXXdbg - don't flush locked blocks. they may be journaled.
609 if ((bp
->b_flags
& B_BUSY
) || (bp
->b_flags
& B_LOCKED
))
611 if ((bp
->b_flags
& B_DELWRI
) == 0)
612 panic("spec_fsync: not dirty");
614 bp
->b_flags
|= B_BUSY
;
619 if (ap
->a_waitfor
== MNT_WAIT
) {
620 while (vp
->v_numoutput
) {
621 vp
->v_flag
|= VBWAIT
;
622 tsleep((caddr_t
)&vp
->v_numoutput
, PRIBIO
+ 1, "spec_fsync", 0);
625 if (vp
->v_dirtyblkhd
.lh_first
) {
626 vprint("spec_fsync: dirty", vp
);
637 * Just call the device strategy routine
640 struct vop_strategy_args
/* {
645 extern int hard_throttle_on_root
;
652 if (bp
->b_flags
& B_READ
)
654 if (bp
->b_flags
& B_ASYNC
)
657 if (bp
->b_flags
& B_META
)
659 else if (bp
->b_flags
& (B_PGIN
| B_PAGEOUT
))
662 KERNEL_DEBUG_CONSTANT(FSDBG_CODE(DBG_DKRW
, code
) | DBG_FUNC_NONE
,
663 (unsigned int)bp
, bp
->b_dev
, bp
->b_blkno
, bp
->b_bcount
, 0);
665 if ((bp
->b_flags
& B_PGIN
) && (bp
->b_vp
->v_mount
->mnt_kern_flag
& MNTK_ROOTDEV
))
666 hard_throttle_on_root
= 1;
668 (*bdevsw
[major(bp
->b_dev
)].d_strategy
)(bp
);
673 * This is a noop, simply returning what one has been given.
676 struct vop_bmap_args
/* {
679 struct vnode **a_vpp;
685 if (ap
->a_vpp
!= NULL
)
686 *ap
->a_vpp
= ap
->a_vp
;
687 if (ap
->a_bnp
!= NULL
)
688 *ap
->a_bnp
= ap
->a_bn
* (PAGE_SIZE
/ ap
->a_vp
->v_specsize
);
689 if (ap
->a_runp
!= NULL
)
690 *ap
->a_runp
= (MAXPHYSIO
/ PAGE_SIZE
) - 1;
695 * This is a noop, simply returning what one has been given.
698 struct vop_cmap_args
/* {
712 * Device close routine
716 struct vop_close_args
/* {
719 struct ucred *a_cred;
723 register struct vnode
*vp
= ap
->a_vp
;
724 dev_t dev
= vp
->v_rdev
;
725 int (*devclose
) __P((dev_t
, int, int, struct proc
*));
728 switch (vp
->v_type
) {
732 * Hack: a tty device that is a controlling terminal
733 * has a reference from the session structure.
734 * We cannot easily tell that a character device is
735 * a controlling terminal, unless it is the closing
736 * process' controlling terminal. In that case,
737 * if the reference count is 2 (this last descriptor
738 * plus the session), release the reference from the session.
740 if (vcount(vp
) == 2 && ap
->a_p
&&
741 vp
== ap
->a_p
->p_session
->s_ttyvp
) {
742 ap
->a_p
->p_session
->s_ttyvp
= NULL
;
746 * If the vnode is locked, then we are in the midst
747 * of forcably closing the device, otherwise we only
748 * close on last reference.
750 if (vcount(vp
) > 1 && (vp
->v_flag
& VXLOCK
) == 0)
752 devclose
= cdevsw
[major(dev
)].d_close
;
757 #ifdef DEVFS_IMPLEMENTS_LOCKING
759 * On last close of a block device (that isn't mounted)
760 * we must invalidate any in core blocks, so that
761 * we can, for instance, change floppy disks.
763 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
, ap
->a_p
);
764 error
= vinvalbuf(vp
, V_SAVE
, ap
->a_cred
, ap
->a_p
, 0, 0);
765 VOP_UNLOCK(vp
, 0, ap
->a_p
);
769 * We do not want to really close the device if it
770 * is still in use unless we are trying to close it
771 * forcibly. Since every use (buffer, vnode, swap, cmap)
772 * holds a reference to the vnode, and because we mark
773 * any other vnodes that alias this device, when the
774 * sum of the reference counts on all the aliased
775 * vnodes descends to one, we are on last close.
777 if (vcount(vp
) > 1 && (vp
->v_flag
& VXLOCK
) == 0)
779 #else /* DEVFS_IMPLEMENTS_LOCKING */
781 * We do not want to really close the device if it
782 * is still in use unless we are trying to close it
783 * forcibly. Since every use (buffer, vnode, swap, cmap)
784 * holds a reference to the vnode, and because we mark
785 * any other vnodes that alias this device, when the
786 * sum of the reference counts on all the aliased
787 * vnodes descends to one, we are on last close.
789 if (vcount(vp
) > 1 && (vp
->v_flag
& VXLOCK
) == 0)
793 * On last close of a block device (that isn't mounted)
794 * we must invalidate any in core blocks, so that
795 * we can, for instance, change floppy disks.
797 error
= vinvalbuf(vp
, V_SAVE
, ap
->a_cred
, ap
->a_p
, 0, 0);
800 #endif /* DEVFS_IMPLEMENTS_LOCKING */
801 devclose
= bdevsw
[major(dev
)].d_close
;
806 panic("spec_close: not special");
809 return ((*devclose
)(dev
, ap
->a_fflag
, mode
, ap
->a_p
));
813 * Print out the contents of a special device vnode.
816 struct vop_print_args
/* {
821 printf("tag VT_NON, dev %d, %d\n", major(ap
->a_vp
->v_rdev
),
822 minor(ap
->a_vp
->v_rdev
));
826 * Return POSIX pathconf information applicable to special devices.
829 struct vop_pathconf_args
/* {
836 switch (ap
->a_name
) {
838 *ap
->a_retval
= LINK_MAX
;
841 *ap
->a_retval
= MAX_CANON
;
844 *ap
->a_retval
= MAX_INPUT
;
847 *ap
->a_retval
= PIPE_BUF
;
849 case _PC_CHOWN_RESTRICTED
:
853 *ap
->a_retval
= _POSIX_VDISABLE
;
862 spec_devblocksize(ap
)
863 struct vop_devblocksize_args
/* {
868 *ap
->a_retval
= (ap
->a_vp
->v_specsize
);
873 * Special device failed operation
882 * Special device bad operation
887 panic("spec_badop called");
891 /* Blktooff derives file offset from logical block number */
894 struct vop_blktooff_args
/* {
900 register struct vnode
*vp
= ap
->a_vp
;
902 switch (vp
->v_type
) {
904 *ap
->a_offset
= (off_t
)-1; /* failure */
908 printf("spec_blktooff: not implemented for VBLK\n");
909 *ap
->a_offset
= (off_t
)-1; /* failure */
913 panic("spec_blktooff type");
918 /* Offtoblk derives logical block number from file offset */
921 struct vop_offtoblk_args
/* {
927 register struct vnode
*vp
= ap
->a_vp
;
929 switch (vp
->v_type
) {
931 *ap
->a_lblkno
= (daddr_t
)-1; /* failure */
935 printf("spec_offtoblk: not implemented for VBLK\n");
936 *ap
->a_lblkno
= (daddr_t
)-1; /* failure */
940 panic("spec_offtoblk type");