spec_vnops.c revision 1.194 1 1.194 riastrad /* $NetBSD: spec_vnops.c,v 1.194 2022/03/28 12:35:35 riastradh Exp $ */
2 1.112 ad
3 1.112 ad /*-
4 1.112 ad * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.112 ad * All rights reserved.
6 1.112 ad *
7 1.112 ad * Redistribution and use in source and binary forms, with or without
8 1.112 ad * modification, are permitted provided that the following conditions
9 1.112 ad * are met:
10 1.112 ad * 1. Redistributions of source code must retain the above copyright
11 1.112 ad * notice, this list of conditions and the following disclaimer.
12 1.112 ad * 2. Redistributions in binary form must reproduce the above copyright
13 1.112 ad * notice, this list of conditions and the following disclaimer in the
14 1.112 ad * documentation and/or other materials provided with the distribution.
15 1.112 ad *
16 1.112 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.112 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.112 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.112 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.112 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.112 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.112 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.112 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.112 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.112 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.112 ad * POSSIBILITY OF SUCH DAMAGE.
27 1.112 ad */
28 1.16 cgd
29 1.1 cgd /*
30 1.15 mycroft * Copyright (c) 1989, 1993
31 1.15 mycroft * The Regents of the University of California. All rights reserved.
32 1.1 cgd *
33 1.1 cgd * Redistribution and use in source and binary forms, with or without
34 1.1 cgd * modification, are permitted provided that the following conditions
35 1.1 cgd * are met:
36 1.1 cgd * 1. Redistributions of source code must retain the above copyright
37 1.1 cgd * notice, this list of conditions and the following disclaimer.
38 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
39 1.1 cgd * notice, this list of conditions and the following disclaimer in the
40 1.1 cgd * documentation and/or other materials provided with the distribution.
41 1.69 agc * 3. Neither the name of the University nor the names of its contributors
42 1.1 cgd * may be used to endorse or promote products derived from this software
43 1.1 cgd * without specific prior written permission.
44 1.1 cgd *
45 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 1.1 cgd * SUCH DAMAGE.
56 1.1 cgd *
57 1.39 fvdl * @(#)spec_vnops.c 8.15 (Berkeley) 7/14/95
58 1.1 cgd */
59 1.60 lukem
60 1.60 lukem #include <sys/cdefs.h>
61 1.194 riastrad __KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.194 2022/03/28 12:35:35 riastradh Exp $");
62 1.1 cgd
63 1.9 mycroft #include <sys/param.h>
64 1.9 mycroft #include <sys/proc.h>
65 1.9 mycroft #include <sys/systm.h>
66 1.9 mycroft #include <sys/kernel.h>
67 1.9 mycroft #include <sys/conf.h>
68 1.9 mycroft #include <sys/buf.h>
69 1.9 mycroft #include <sys/mount.h>
70 1.9 mycroft #include <sys/namei.h>
71 1.168 hannken #include <sys/vnode_impl.h>
72 1.9 mycroft #include <sys/stat.h>
73 1.9 mycroft #include <sys/errno.h>
74 1.9 mycroft #include <sys/ioctl.h>
75 1.81 ws #include <sys/poll.h>
76 1.9 mycroft #include <sys/file.h>
77 1.9 mycroft #include <sys/disklabel.h>
78 1.176 christos #include <sys/disk.h>
79 1.35 kleink #include <sys/lockf.h>
80 1.71 dsl #include <sys/tty.h>
81 1.87 elad #include <sys/kauth.h>
82 1.106 hannken #include <sys/fstrans.h>
83 1.122 haad #include <sys/module.h>
84 1.28 christos
85 1.30 mycroft #include <miscfs/genfs/genfs.h>
86 1.15 mycroft #include <miscfs/specfs/specdev.h>
87 1.1 cgd
88 1.186 riastrad /*
89 1.186 riastrad * Lock order:
90 1.186 riastrad *
91 1.186 riastrad * vnode lock
92 1.186 riastrad * -> device_lock
93 1.186 riastrad * -> struct vnode::v_interlock
94 1.186 riastrad */
95 1.186 riastrad
96 1.1 cgd /* symbolic sleep message strings for devices */
97 1.37 mycroft const char devopn[] = "devopn";
98 1.37 mycroft const char devio[] = "devio";
99 1.37 mycroft const char devwait[] = "devwait";
100 1.37 mycroft const char devin[] = "devin";
101 1.37 mycroft const char devout[] = "devout";
102 1.37 mycroft const char devioc[] = "devioc";
103 1.37 mycroft const char devcls[] = "devcls";
104 1.61 matt
105 1.137 hannken #define SPECHSZ 64
106 1.137 hannken #if ((SPECHSZ&(SPECHSZ-1)) == 0)
107 1.137 hannken #define SPECHASH(rdev) (((rdev>>5)+(rdev))&(SPECHSZ-1))
108 1.137 hannken #else
109 1.137 hannken #define SPECHASH(rdev) (((unsigned)((rdev>>5)+(rdev)))%SPECHSZ)
110 1.137 hannken #endif
111 1.137 hannken
112 1.137 hannken static vnode_t *specfs_hash[SPECHSZ];
113 1.148 hannken extern struct mount *dead_rootmount;
114 1.46 sommerfe
115 1.46 sommerfe /*
116 1.112 ad * This vnode operations vector is used for special device nodes
117 1.112 ad * created from whole cloth by the kernel. For the ops vector for
118 1.112 ad * vnodes built from special devices found in a filesystem, see (e.g)
119 1.112 ad * ffs_specop_entries[] in ffs_vnops.c or the equivalent for other
120 1.112 ad * filesystems.
121 1.46 sommerfe */
122 1.1 cgd
123 1.82 xtraeme int (**spec_vnodeop_p)(void *);
124 1.53 jdolecek const struct vnodeopv_entry_desc spec_vnodeop_entries[] = {
125 1.15 mycroft { &vop_default_desc, vn_default_error },
126 1.182 dholland { &vop_parsepath_desc, genfs_parsepath }, /* parsepath */
127 1.15 mycroft { &vop_lookup_desc, spec_lookup }, /* lookup */
128 1.183 dholland { &vop_create_desc, genfs_badop }, /* create */
129 1.183 dholland { &vop_mknod_desc, genfs_badop }, /* mknod */
130 1.15 mycroft { &vop_open_desc, spec_open }, /* open */
131 1.15 mycroft { &vop_close_desc, spec_close }, /* close */
132 1.183 dholland { &vop_access_desc, genfs_ebadf }, /* access */
133 1.183 dholland { &vop_accessx_desc, genfs_ebadf }, /* accessx */
134 1.183 dholland { &vop_getattr_desc, genfs_ebadf }, /* getattr */
135 1.183 dholland { &vop_setattr_desc, genfs_ebadf }, /* setattr */
136 1.15 mycroft { &vop_read_desc, spec_read }, /* read */
137 1.15 mycroft { &vop_write_desc, spec_write }, /* write */
138 1.183 dholland { &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */
139 1.145 dholland { &vop_fdiscard_desc, spec_fdiscard }, /* fdiscard */
140 1.183 dholland { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */
141 1.15 mycroft { &vop_ioctl_desc, spec_ioctl }, /* ioctl */
142 1.32 mycroft { &vop_poll_desc, spec_poll }, /* poll */
143 1.65 jdolecek { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */
144 1.183 dholland { &vop_revoke_desc, genfs_revoke }, /* revoke */
145 1.15 mycroft { &vop_mmap_desc, spec_mmap }, /* mmap */
146 1.15 mycroft { &vop_fsync_desc, spec_fsync }, /* fsync */
147 1.15 mycroft { &vop_seek_desc, spec_seek }, /* seek */
148 1.183 dholland { &vop_remove_desc, genfs_badop }, /* remove */
149 1.183 dholland { &vop_link_desc, genfs_badop }, /* link */
150 1.183 dholland { &vop_rename_desc, genfs_badop }, /* rename */
151 1.183 dholland { &vop_mkdir_desc, genfs_badop }, /* mkdir */
152 1.183 dholland { &vop_rmdir_desc, genfs_badop }, /* rmdir */
153 1.183 dholland { &vop_symlink_desc, genfs_badop }, /* symlink */
154 1.183 dholland { &vop_readdir_desc, genfs_badop }, /* readdir */
155 1.183 dholland { &vop_readlink_desc, genfs_badop }, /* readlink */
156 1.183 dholland { &vop_abortop_desc, genfs_badop }, /* abortop */
157 1.15 mycroft { &vop_inactive_desc, spec_inactive }, /* inactive */
158 1.15 mycroft { &vop_reclaim_desc, spec_reclaim }, /* reclaim */
159 1.184 hannken { &vop_lock_desc, genfs_lock }, /* lock */
160 1.184 hannken { &vop_unlock_desc, genfs_unlock }, /* unlock */
161 1.15 mycroft { &vop_bmap_desc, spec_bmap }, /* bmap */
162 1.15 mycroft { &vop_strategy_desc, spec_strategy }, /* strategy */
163 1.15 mycroft { &vop_print_desc, spec_print }, /* print */
164 1.184 hannken { &vop_islocked_desc, genfs_islocked }, /* islocked */
165 1.15 mycroft { &vop_pathconf_desc, spec_pathconf }, /* pathconf */
166 1.15 mycroft { &vop_advlock_desc, spec_advlock }, /* advlock */
167 1.183 dholland { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
168 1.183 dholland { &vop_getpages_desc, genfs_getpages }, /* getpages */
169 1.183 dholland { &vop_putpages_desc, genfs_putpages }, /* putpages */
170 1.55 chs { NULL, NULL }
171 1.1 cgd };
172 1.53 jdolecek const struct vnodeopv_desc spec_vnodeop_opv_desc =
173 1.15 mycroft { &spec_vnodeop_p, spec_vnodeop_entries };
174 1.1 cgd
175 1.127 elad static kauth_listener_t rawio_listener;
176 1.127 elad
177 1.126 elad /* Returns true if vnode is /dev/mem or /dev/kmem. */
178 1.126 elad bool
179 1.126 elad iskmemvp(struct vnode *vp)
180 1.126 elad {
181 1.126 elad return ((vp->v_type == VCHR) && iskmemdev(vp->v_rdev));
182 1.126 elad }
183 1.126 elad
184 1.1 cgd /*
185 1.112 ad * Returns true if dev is /dev/mem or /dev/kmem.
186 1.112 ad */
187 1.112 ad int
188 1.112 ad iskmemdev(dev_t dev)
189 1.112 ad {
190 1.112 ad /* mem_no is emitted by config(8) to generated devsw.c */
191 1.112 ad extern const int mem_no;
192 1.112 ad
193 1.112 ad /* minor 14 is /dev/io on i386 with COMPAT_10 */
194 1.112 ad return (major(dev) == mem_no && (minor(dev) < 2 || minor(dev) == 14));
195 1.112 ad }
196 1.112 ad
197 1.127 elad static int
198 1.127 elad rawio_listener_cb(kauth_cred_t cred, kauth_action_t action, void *cookie,
199 1.127 elad void *arg0, void *arg1, void *arg2, void *arg3)
200 1.127 elad {
201 1.127 elad int result;
202 1.127 elad
203 1.127 elad result = KAUTH_RESULT_DEFER;
204 1.127 elad
205 1.127 elad if ((action != KAUTH_DEVICE_RAWIO_SPEC) &&
206 1.127 elad (action != KAUTH_DEVICE_RAWIO_PASSTHRU))
207 1.127 elad return result;
208 1.127 elad
209 1.127 elad /* Access is mandated by permissions. */
210 1.127 elad result = KAUTH_RESULT_ALLOW;
211 1.127 elad
212 1.127 elad return result;
213 1.127 elad }
214 1.127 elad
215 1.127 elad void
216 1.127 elad spec_init(void)
217 1.127 elad {
218 1.127 elad
219 1.127 elad rawio_listener = kauth_listen_scope(KAUTH_SCOPE_DEVICE,
220 1.127 elad rawio_listener_cb, NULL);
221 1.127 elad }
222 1.127 elad
223 1.112 ad /*
224 1.112 ad * Initialize a vnode that represents a device.
225 1.112 ad */
226 1.112 ad void
227 1.112 ad spec_node_init(vnode_t *vp, dev_t rdev)
228 1.112 ad {
229 1.112 ad specnode_t *sn;
230 1.112 ad specdev_t *sd;
231 1.112 ad vnode_t *vp2;
232 1.112 ad vnode_t **vpp;
233 1.112 ad
234 1.112 ad KASSERT(vp->v_type == VBLK || vp->v_type == VCHR);
235 1.112 ad KASSERT(vp->v_specnode == NULL);
236 1.112 ad
237 1.112 ad /*
238 1.112 ad * Search the hash table for this device. If known, add a
239 1.112 ad * reference to the device structure. If not known, create
240 1.112 ad * a new entry to represent the device. In all cases add
241 1.112 ad * the vnode to the hash table.
242 1.112 ad */
243 1.112 ad sn = kmem_alloc(sizeof(*sn), KM_SLEEP);
244 1.112 ad sd = kmem_alloc(sizeof(*sd), KM_SLEEP);
245 1.120 pooka mutex_enter(&device_lock);
246 1.112 ad vpp = &specfs_hash[SPECHASH(rdev)];
247 1.112 ad for (vp2 = *vpp; vp2 != NULL; vp2 = vp2->v_specnext) {
248 1.112 ad KASSERT(vp2->v_specnode != NULL);
249 1.112 ad if (rdev == vp2->v_rdev && vp->v_type == vp2->v_type) {
250 1.112 ad break;
251 1.112 ad }
252 1.112 ad }
253 1.112 ad if (vp2 == NULL) {
254 1.112 ad /* No existing record, create a new one. */
255 1.112 ad sd->sd_rdev = rdev;
256 1.112 ad sd->sd_mountpoint = NULL;
257 1.112 ad sd->sd_lockf = NULL;
258 1.112 ad sd->sd_refcnt = 1;
259 1.112 ad sd->sd_opencnt = 0;
260 1.112 ad sd->sd_bdevvp = NULL;
261 1.112 ad sn->sn_dev = sd;
262 1.112 ad sd = NULL;
263 1.112 ad } else {
264 1.112 ad /* Use the existing record. */
265 1.112 ad sn->sn_dev = vp2->v_specnode->sn_dev;
266 1.112 ad sn->sn_dev->sd_refcnt++;
267 1.112 ad }
268 1.112 ad /* Insert vnode into the hash chain. */
269 1.112 ad sn->sn_opencnt = 0;
270 1.112 ad sn->sn_rdev = rdev;
271 1.112 ad sn->sn_gone = false;
272 1.112 ad vp->v_specnode = sn;
273 1.112 ad vp->v_specnext = *vpp;
274 1.112 ad *vpp = vp;
275 1.120 pooka mutex_exit(&device_lock);
276 1.112 ad
277 1.112 ad /* Free the record we allocated if unused. */
278 1.112 ad if (sd != NULL) {
279 1.112 ad kmem_free(sd, sizeof(*sd));
280 1.112 ad }
281 1.112 ad }
282 1.112 ad
283 1.112 ad /*
284 1.137 hannken * Lookup a vnode by device number and return it referenced.
285 1.137 hannken */
286 1.137 hannken int
287 1.137 hannken spec_node_lookup_by_dev(enum vtype type, dev_t dev, vnode_t **vpp)
288 1.137 hannken {
289 1.137 hannken int error;
290 1.137 hannken vnode_t *vp;
291 1.137 hannken
292 1.137 hannken mutex_enter(&device_lock);
293 1.137 hannken for (vp = specfs_hash[SPECHASH(dev)]; vp; vp = vp->v_specnext) {
294 1.137 hannken if (type == vp->v_type && dev == vp->v_rdev) {
295 1.137 hannken mutex_enter(vp->v_interlock);
296 1.137 hannken /* If clean or being cleaned, then ignore it. */
297 1.143 hannken if (vdead_check(vp, VDEAD_NOWAIT) == 0)
298 1.137 hannken break;
299 1.137 hannken mutex_exit(vp->v_interlock);
300 1.137 hannken }
301 1.137 hannken }
302 1.137 hannken KASSERT(vp == NULL || mutex_owned(vp->v_interlock));
303 1.137 hannken if (vp == NULL) {
304 1.137 hannken mutex_exit(&device_lock);
305 1.137 hannken return ENOENT;
306 1.137 hannken }
307 1.137 hannken /*
308 1.137 hannken * If it is an opened block device return the opened vnode.
309 1.137 hannken */
310 1.137 hannken if (type == VBLK && vp->v_specnode->sn_dev->sd_bdevvp != NULL) {
311 1.137 hannken mutex_exit(vp->v_interlock);
312 1.137 hannken vp = vp->v_specnode->sn_dev->sd_bdevvp;
313 1.137 hannken mutex_enter(vp->v_interlock);
314 1.137 hannken }
315 1.137 hannken mutex_exit(&device_lock);
316 1.168 hannken error = vcache_vget(vp);
317 1.137 hannken if (error != 0)
318 1.137 hannken return error;
319 1.137 hannken *vpp = vp;
320 1.137 hannken
321 1.137 hannken return 0;
322 1.137 hannken }
323 1.137 hannken
324 1.137 hannken /*
325 1.137 hannken * Lookup a vnode by file system mounted on and return it referenced.
326 1.137 hannken */
327 1.137 hannken int
328 1.137 hannken spec_node_lookup_by_mount(struct mount *mp, vnode_t **vpp)
329 1.137 hannken {
330 1.137 hannken int i, error;
331 1.137 hannken vnode_t *vp, *vq;
332 1.137 hannken
333 1.137 hannken mutex_enter(&device_lock);
334 1.137 hannken for (i = 0, vq = NULL; i < SPECHSZ && vq == NULL; i++) {
335 1.137 hannken for (vp = specfs_hash[i]; vp; vp = vp->v_specnext) {
336 1.137 hannken if (vp->v_type != VBLK)
337 1.137 hannken continue;
338 1.137 hannken vq = vp->v_specnode->sn_dev->sd_bdevvp;
339 1.141 hannken if (vq != NULL &&
340 1.141 hannken vq->v_specnode->sn_dev->sd_mountpoint == mp)
341 1.137 hannken break;
342 1.137 hannken vq = NULL;
343 1.137 hannken }
344 1.137 hannken }
345 1.137 hannken if (vq == NULL) {
346 1.137 hannken mutex_exit(&device_lock);
347 1.137 hannken return ENOENT;
348 1.137 hannken }
349 1.137 hannken mutex_enter(vq->v_interlock);
350 1.137 hannken mutex_exit(&device_lock);
351 1.168 hannken error = vcache_vget(vq);
352 1.137 hannken if (error != 0)
353 1.137 hannken return error;
354 1.137 hannken *vpp = vq;
355 1.137 hannken
356 1.137 hannken return 0;
357 1.137 hannken
358 1.137 hannken }
359 1.137 hannken
360 1.137 hannken /*
361 1.141 hannken * Get the file system mounted on this block device.
362 1.141 hannken */
363 1.141 hannken struct mount *
364 1.141 hannken spec_node_getmountedfs(vnode_t *devvp)
365 1.141 hannken {
366 1.141 hannken struct mount *mp;
367 1.141 hannken
368 1.141 hannken KASSERT(devvp->v_type == VBLK);
369 1.141 hannken mp = devvp->v_specnode->sn_dev->sd_mountpoint;
370 1.141 hannken
371 1.141 hannken return mp;
372 1.141 hannken }
373 1.141 hannken
374 1.141 hannken /*
375 1.141 hannken * Set the file system mounted on this block device.
376 1.141 hannken */
377 1.141 hannken void
378 1.141 hannken spec_node_setmountedfs(vnode_t *devvp, struct mount *mp)
379 1.141 hannken {
380 1.176 christos struct dkwedge_info dkw;
381 1.141 hannken
382 1.141 hannken KASSERT(devvp->v_type == VBLK);
383 1.141 hannken KASSERT(devvp->v_specnode->sn_dev->sd_mountpoint == NULL || mp == NULL);
384 1.141 hannken devvp->v_specnode->sn_dev->sd_mountpoint = mp;
385 1.176 christos if (mp == NULL)
386 1.176 christos return;
387 1.176 christos
388 1.176 christos if (bdev_ioctl(devvp->v_rdev, DIOCGWEDGEINFO, &dkw, FREAD, curlwp) != 0)
389 1.176 christos return;
390 1.176 christos
391 1.176 christos strlcpy(mp->mnt_stat.f_mntfromlabel, dkw.dkw_wname,
392 1.176 christos sizeof(mp->mnt_stat.f_mntfromlabel));
393 1.141 hannken }
394 1.141 hannken
395 1.141 hannken /*
396 1.112 ad * A vnode representing a special device is going away. Close
397 1.112 ad * the device if the vnode holds it open.
398 1.112 ad */
399 1.112 ad void
400 1.112 ad spec_node_revoke(vnode_t *vp)
401 1.112 ad {
402 1.112 ad specnode_t *sn;
403 1.112 ad specdev_t *sd;
404 1.112 ad
405 1.112 ad sn = vp->v_specnode;
406 1.112 ad sd = sn->sn_dev;
407 1.112 ad
408 1.112 ad KASSERT(vp->v_type == VBLK || vp->v_type == VCHR);
409 1.112 ad KASSERT(vp->v_specnode != NULL);
410 1.112 ad KASSERT(sn->sn_gone == false);
411 1.112 ad
412 1.120 pooka mutex_enter(&device_lock);
413 1.112 ad KASSERT(sn->sn_opencnt <= sd->sd_opencnt);
414 1.112 ad if (sn->sn_opencnt != 0) {
415 1.112 ad sd->sd_opencnt -= (sn->sn_opencnt - 1);
416 1.112 ad sn->sn_opencnt = 1;
417 1.112 ad sn->sn_gone = true;
418 1.120 pooka mutex_exit(&device_lock);
419 1.112 ad
420 1.112 ad VOP_CLOSE(vp, FNONBLOCK, NOCRED);
421 1.112 ad
422 1.120 pooka mutex_enter(&device_lock);
423 1.112 ad KASSERT(sn->sn_opencnt == 0);
424 1.112 ad }
425 1.120 pooka mutex_exit(&device_lock);
426 1.112 ad }
427 1.112 ad
428 1.112 ad /*
429 1.112 ad * A vnode representing a special device is being recycled.
430 1.112 ad * Destroy the specfs component.
431 1.112 ad */
432 1.112 ad void
433 1.112 ad spec_node_destroy(vnode_t *vp)
434 1.112 ad {
435 1.112 ad specnode_t *sn;
436 1.112 ad specdev_t *sd;
437 1.112 ad vnode_t **vpp, *vp2;
438 1.112 ad int refcnt;
439 1.112 ad
440 1.112 ad sn = vp->v_specnode;
441 1.112 ad sd = sn->sn_dev;
442 1.112 ad
443 1.112 ad KASSERT(vp->v_type == VBLK || vp->v_type == VCHR);
444 1.112 ad KASSERT(vp->v_specnode != NULL);
445 1.112 ad KASSERT(sn->sn_opencnt == 0);
446 1.112 ad
447 1.120 pooka mutex_enter(&device_lock);
448 1.112 ad /* Remove from the hash and destroy the node. */
449 1.112 ad vpp = &specfs_hash[SPECHASH(vp->v_rdev)];
450 1.112 ad for (vp2 = *vpp;; vp2 = vp2->v_specnext) {
451 1.112 ad if (vp2 == NULL) {
452 1.112 ad panic("spec_node_destroy: corrupt hash");
453 1.112 ad }
454 1.112 ad if (vp2 == vp) {
455 1.112 ad KASSERT(vp == *vpp);
456 1.112 ad *vpp = vp->v_specnext;
457 1.112 ad break;
458 1.112 ad }
459 1.112 ad if (vp2->v_specnext == vp) {
460 1.112 ad vp2->v_specnext = vp->v_specnext;
461 1.112 ad break;
462 1.112 ad }
463 1.112 ad }
464 1.112 ad sn = vp->v_specnode;
465 1.112 ad vp->v_specnode = NULL;
466 1.112 ad refcnt = sd->sd_refcnt--;
467 1.112 ad KASSERT(refcnt > 0);
468 1.120 pooka mutex_exit(&device_lock);
469 1.112 ad
470 1.112 ad /* If the device is no longer in use, destroy our record. */
471 1.112 ad if (refcnt == 1) {
472 1.112 ad KASSERT(sd->sd_opencnt == 0);
473 1.112 ad KASSERT(sd->sd_bdevvp == NULL);
474 1.112 ad kmem_free(sd, sizeof(*sd));
475 1.112 ad }
476 1.112 ad kmem_free(sn, sizeof(*sn));
477 1.112 ad }
478 1.112 ad
479 1.112 ad /*
480 1.1 cgd * Trivial lookup routine that always fails.
481 1.1 cgd */
482 1.4 andrew int
483 1.104 pooka spec_lookup(void *v)
484 1.28 christos {
485 1.142 hannken struct vop_lookup_v2_args /* {
486 1.15 mycroft struct vnode *a_dvp;
487 1.15 mycroft struct vnode **a_vpp;
488 1.15 mycroft struct componentname *a_cnp;
489 1.28 christos } */ *ap = v;
490 1.1 cgd
491 1.15 mycroft *ap->a_vpp = NULL;
492 1.1 cgd return (ENOTDIR);
493 1.66 jdolecek }
494 1.66 jdolecek
495 1.154 christos typedef int (*spec_ioctl_t)(dev_t, u_long, void *, int, struct lwp *);
496 1.154 christos
497 1.66 jdolecek /*
498 1.15 mycroft * Open a special file.
499 1.1 cgd */
500 1.1 cgd /* ARGSUSED */
501 1.28 christos int
502 1.104 pooka spec_open(void *v)
503 1.28 christos {
504 1.15 mycroft struct vop_open_args /* {
505 1.15 mycroft struct vnode *a_vp;
506 1.15 mycroft int a_mode;
507 1.87 elad kauth_cred_t a_cred;
508 1.28 christos } */ *ap = v;
509 1.112 ad struct lwp *l;
510 1.112 ad struct vnode *vp;
511 1.112 ad dev_t dev;
512 1.1 cgd int error;
513 1.96 elad enum kauth_device_req req;
514 1.112 ad specnode_t *sn;
515 1.112 ad specdev_t *sd;
516 1.154 christos spec_ioctl_t ioctl;
517 1.122 haad u_int gen;
518 1.122 haad const char *name;
519 1.157 christos struct partinfo pi;
520 1.122 haad
521 1.112 ad l = curlwp;
522 1.112 ad vp = ap->a_vp;
523 1.112 ad dev = vp->v_rdev;
524 1.112 ad sn = vp->v_specnode;
525 1.112 ad sd = sn->sn_dev;
526 1.122 haad name = NULL;
527 1.122 haad gen = 0;
528 1.188 riastrad
529 1.188 riastrad KASSERTMSG(vp->v_type == VBLK || vp->v_type == VCHR, "type=%d",
530 1.188 riastrad vp->v_type);
531 1.188 riastrad
532 1.15 mycroft /*
533 1.15 mycroft * Don't allow open if fs is mounted -nodev.
534 1.15 mycroft */
535 1.1 cgd if (vp->v_mount && (vp->v_mount->mnt_flag & MNT_NODEV))
536 1.1 cgd return (ENXIO);
537 1.1 cgd
538 1.112 ad switch (ap->a_mode & (FREAD | FWRITE)) {
539 1.112 ad case FREAD | FWRITE:
540 1.112 ad req = KAUTH_REQ_DEVICE_RAWIO_SPEC_RW;
541 1.112 ad break;
542 1.112 ad case FWRITE:
543 1.112 ad req = KAUTH_REQ_DEVICE_RAWIO_SPEC_WRITE;
544 1.112 ad break;
545 1.112 ad default:
546 1.112 ad req = KAUTH_REQ_DEVICE_RAWIO_SPEC_READ;
547 1.112 ad break;
548 1.112 ad }
549 1.189 riastrad error = kauth_authorize_device_spec(ap->a_cred, req, vp);
550 1.189 riastrad if (error != 0)
551 1.189 riastrad return (error);
552 1.89 elad
553 1.190 riastrad /*
554 1.190 riastrad * Acquire an open reference -- as long as we hold onto it, and
555 1.190 riastrad * the vnode isn't revoked, it can't be closed.
556 1.190 riastrad *
557 1.190 riastrad * But first check whether it has been revoked -- if so, we
558 1.190 riastrad * can't acquire more open references and we must fail
559 1.190 riastrad * immediately with EBADF.
560 1.190 riastrad */
561 1.192 riastrad mutex_enter(&device_lock);
562 1.1 cgd switch (vp->v_type) {
563 1.1 cgd case VCHR:
564 1.112 ad /*
565 1.112 ad * Character devices can accept opens from multiple
566 1.112 ad * vnodes.
567 1.112 ad */
568 1.112 ad if (sn->sn_gone) {
569 1.192 riastrad error = EBADF;
570 1.192 riastrad break;
571 1.112 ad }
572 1.112 ad sd->sd_opencnt++;
573 1.112 ad sn->sn_opencnt++;
574 1.190 riastrad break;
575 1.190 riastrad case VBLK:
576 1.190 riastrad /*
577 1.190 riastrad * For block devices, permit only one open. The buffer
578 1.190 riastrad * cache cannot remain self-consistent with multiple
579 1.190 riastrad * vnodes holding a block device open.
580 1.190 riastrad *
581 1.190 riastrad * Treat zero opencnt with non-NULL mountpoint as open.
582 1.190 riastrad * This may happen after forced detach of a mounted device.
583 1.190 riastrad */
584 1.190 riastrad if (sn->sn_gone) {
585 1.192 riastrad error = EBADF;
586 1.192 riastrad break;
587 1.190 riastrad }
588 1.190 riastrad if (sd->sd_opencnt != 0 || sd->sd_mountpoint != NULL) {
589 1.192 riastrad error = EBUSY;
590 1.192 riastrad break;
591 1.190 riastrad }
592 1.190 riastrad sn->sn_opencnt = 1;
593 1.190 riastrad sd->sd_opencnt = 1;
594 1.190 riastrad sd->sd_bdevvp = vp;
595 1.190 riastrad break;
596 1.190 riastrad default:
597 1.190 riastrad panic("invalid specfs vnode type: %d", vp->v_type);
598 1.190 riastrad }
599 1.192 riastrad mutex_exit(&device_lock);
600 1.192 riastrad if (error)
601 1.192 riastrad return error;
602 1.190 riastrad
603 1.190 riastrad /*
604 1.190 riastrad * Set VV_ISTTY if this is a tty cdev.
605 1.190 riastrad *
606 1.190 riastrad * XXX This does the wrong thing if the module has to be
607 1.190 riastrad * autoloaded. We should maybe set this after autoloading
608 1.190 riastrad * modules and calling .d_open successfully, except (a) we need
609 1.190 riastrad * the vnode lock to touch it, and (b) once we acquire the
610 1.190 riastrad * vnode lock again, the vnode may have been revoked, and
611 1.190 riastrad * deadfs's dead_read needs VV_ISTTY to be already set in order
612 1.190 riastrad * to return the right answer. So this needs some additional
613 1.190 riastrad * synchronization to be made to work correctly with tty driver
614 1.190 riastrad * module autoload. For now, let's just hope it doesn't cause
615 1.190 riastrad * too much trouble for a tty from an autoloaded driver module
616 1.190 riastrad * to fail with EIO instead of returning EOF.
617 1.190 riastrad */
618 1.190 riastrad if (vp->v_type == VCHR) {
619 1.100 ad if (cdev_type(dev) == D_TTY)
620 1.108 ad vp->v_vflag |= VV_ISTTY;
621 1.190 riastrad }
622 1.190 riastrad
623 1.190 riastrad /*
624 1.190 riastrad * Open the device. If .d_open returns ENXIO (device not
625 1.190 riastrad * configured), the driver may not be loaded, so try
626 1.190 riastrad * autoloading a module and then try .d_open again if anything
627 1.190 riastrad * got loaded.
628 1.190 riastrad *
629 1.190 riastrad * Because opening the device may block indefinitely, e.g. when
630 1.190 riastrad * opening a tty, and loading a module may cross into many
631 1.190 riastrad * other subsystems, we must not hold the vnode lock while
632 1.190 riastrad * calling .d_open, so release it now and reacquire it when
633 1.190 riastrad * done.
634 1.190 riastrad */
635 1.193 riastrad VOP_UNLOCK(vp);
636 1.190 riastrad switch (vp->v_type) {
637 1.190 riastrad case VCHR:
638 1.122 haad do {
639 1.125 tsutsui const struct cdevsw *cdev;
640 1.125 tsutsui
641 1.122 haad gen = module_gen;
642 1.122 haad error = cdev_open(dev, ap->a_mode, S_IFCHR, l);
643 1.122 haad if (error != ENXIO)
644 1.122 haad break;
645 1.122 haad
646 1.125 tsutsui /* Check if we already have a valid driver */
647 1.125 tsutsui mutex_enter(&device_lock);
648 1.125 tsutsui cdev = cdevsw_lookup(dev);
649 1.125 tsutsui mutex_exit(&device_lock);
650 1.125 tsutsui if (cdev != NULL)
651 1.125 tsutsui break;
652 1.125 tsutsui
653 1.122 haad /* Get device name from devsw_conv array */
654 1.122 haad if ((name = cdevsw_getname(major(dev))) == NULL)
655 1.122 haad break;
656 1.122 haad
657 1.122 haad /* Try to autoload device module */
658 1.159 pgoyette (void) module_autoload(name, MODULE_CLASS_DRIVER);
659 1.122 haad } while (gen != module_gen);
660 1.70 dsl break;
661 1.1 cgd
662 1.1 cgd case VBLK:
663 1.122 haad do {
664 1.125 tsutsui const struct bdevsw *bdev;
665 1.125 tsutsui
666 1.122 haad gen = module_gen;
667 1.122 haad error = bdev_open(dev, ap->a_mode, S_IFBLK, l);
668 1.122 haad if (error != ENXIO)
669 1.122 haad break;
670 1.122 haad
671 1.125 tsutsui /* Check if we already have a valid driver */
672 1.125 tsutsui mutex_enter(&device_lock);
673 1.125 tsutsui bdev = bdevsw_lookup(dev);
674 1.125 tsutsui mutex_exit(&device_lock);
675 1.125 tsutsui if (bdev != NULL)
676 1.125 tsutsui break;
677 1.125 tsutsui
678 1.122 haad /* Get device name from devsw_conv array */
679 1.122 haad if ((name = bdevsw_getname(major(dev))) == NULL)
680 1.122 haad break;
681 1.122 haad
682 1.122 haad /* Try to autoload device module */
683 1.159 pgoyette (void) module_autoload(name, MODULE_CLASS_DRIVER);
684 1.122 haad } while (gen != module_gen);
685 1.70 dsl break;
686 1.55 chs
687 1.70 dsl default:
688 1.190 riastrad __unreachable();
689 1.1 cgd }
690 1.193 riastrad vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
691 1.70 dsl
692 1.190 riastrad /*
693 1.190 riastrad * If it has been revoked since we released the vnode lock and
694 1.190 riastrad * reacquired it, then spec_node_revoke has closed it, and we
695 1.190 riastrad * must fail with EBADF.
696 1.190 riastrad *
697 1.190 riastrad * Otherwise, if opening it failed, back out and release the
698 1.190 riastrad * open reference.
699 1.190 riastrad *
700 1.190 riastrad * XXX This is wrong -- we might release the last open
701 1.190 riastrad * reference here, but we don't close the device. If only this
702 1.190 riastrad * thread's call to open failed, that's fine, but we might
703 1.190 riastrad * have:
704 1.190 riastrad *
705 1.190 riastrad * Thread 1 Thread 2
706 1.190 riastrad * VOP_OPEN
707 1.190 riastrad * ...
708 1.190 riastrad * .d_open -> 0 (success)
709 1.190 riastrad * acquire vnode lock
710 1.190 riastrad * do stuff VOP_OPEN
711 1.190 riastrad * release vnode lock ...
712 1.190 riastrad * .d_open -> EBUSY
713 1.190 riastrad * VOP_CLOSE
714 1.190 riastrad * acquire vnode lock
715 1.190 riastrad * --sd_opencnt != 0
716 1.190 riastrad * => no .d_close
717 1.190 riastrad * release vnode lock
718 1.190 riastrad * acquire vnode lock
719 1.190 riastrad * --sd_opencnt == 0
720 1.190 riastrad * but no .d_close (***)
721 1.190 riastrad */
722 1.120 pooka mutex_enter(&device_lock);
723 1.112 ad if (sn->sn_gone) {
724 1.112 ad if (error == 0)
725 1.112 ad error = EBADF;
726 1.112 ad } else if (error != 0) {
727 1.112 ad sd->sd_opencnt--;
728 1.112 ad sn->sn_opencnt--;
729 1.115 hannken if (vp->v_type == VBLK)
730 1.115 hannken sd->sd_bdevvp = NULL;
731 1.115 hannken
732 1.112 ad }
733 1.120 pooka mutex_exit(&device_lock);
734 1.89 elad
735 1.194 riastrad /* If anything went wrong, we're done. */
736 1.194 riastrad if (error)
737 1.70 dsl return error;
738 1.112 ad
739 1.194 riastrad /*
740 1.194 riastrad * For disk devices, automagically set the vnode size to the
741 1.194 riastrad * partition size, if we can. This applies to block devices
742 1.194 riastrad * and character devices alike -- every block device must have
743 1.194 riastrad * a corresponding character device. And if the module is
744 1.194 riastrad * loaded it will remain loaded until we're done here (it is
745 1.194 riastrad * forbidden to devsw_detach until closed). So it is safe to
746 1.194 riastrad * query cdev_type unconditionally here.
747 1.194 riastrad */
748 1.194 riastrad if (cdev_type(dev) == D_DISK) {
749 1.194 riastrad ioctl = vp->v_type == VCHR ? cdev_ioctl : bdev_ioctl;
750 1.194 riastrad if ((*ioctl)(dev, DIOCGPARTINFO, &pi, FREAD, curlwp) == 0)
751 1.194 riastrad uvm_vnp_setsize(vp,
752 1.194 riastrad (voff_t)pi.pi_secsize * pi.pi_size);
753 1.194 riastrad }
754 1.154 christos
755 1.194 riastrad /* Success! */
756 1.70 dsl return 0;
757 1.1 cgd }
758 1.1 cgd
759 1.1 cgd /*
760 1.1 cgd * Vnode op for read
761 1.1 cgd */
762 1.1 cgd /* ARGSUSED */
763 1.28 christos int
764 1.104 pooka spec_read(void *v)
765 1.28 christos {
766 1.15 mycroft struct vop_read_args /* {
767 1.15 mycroft struct vnode *a_vp;
768 1.15 mycroft struct uio *a_uio;
769 1.15 mycroft int a_ioflag;
770 1.87 elad kauth_cred_t a_cred;
771 1.28 christos } */ *ap = v;
772 1.48 augustss struct vnode *vp = ap->a_vp;
773 1.48 augustss struct uio *uio = ap->a_uio;
774 1.86 yamt struct lwp *l = curlwp;
775 1.56 chs struct buf *bp;
776 1.57 chs daddr_t bn;
777 1.59 chs int bsize, bscale;
778 1.157 christos struct partinfo pi;
779 1.64 gehenna int n, on;
780 1.1 cgd int error = 0;
781 1.181 mlelstv int i, nra;
782 1.181 mlelstv daddr_t lastbn, *rablks;
783 1.181 mlelstv int *rasizes;
784 1.181 mlelstv int nrablks, ratogo;
785 1.1 cgd
786 1.160 pgoyette KASSERT(uio->uio_rw == UIO_READ);
787 1.160 pgoyette KASSERTMSG(VMSPACE_IS_KERNEL_P(uio->uio_vmspace) ||
788 1.160 pgoyette uio->uio_vmspace == curproc->p_vmspace,
789 1.160 pgoyette "vmspace belongs to neither kernel nor curproc");
790 1.160 pgoyette
791 1.1 cgd if (uio->uio_resid == 0)
792 1.1 cgd return (0);
793 1.1 cgd
794 1.56 chs switch (vp->v_type) {
795 1.56 chs
796 1.56 chs case VCHR:
797 1.130 hannken VOP_UNLOCK(vp);
798 1.100 ad error = cdev_read(vp->v_rdev, uio, ap->a_ioflag);
799 1.58 chs vn_lock(vp, LK_SHARED | LK_RETRY);
800 1.1 cgd return (error);
801 1.1 cgd
802 1.56 chs case VBLK:
803 1.112 ad KASSERT(vp == vp->v_specnode->sn_dev->sd_bdevvp);
804 1.56 chs if (uio->uio_offset < 0)
805 1.56 chs return (EINVAL);
806 1.138 dholland
807 1.157 christos if (bdev_ioctl(vp->v_rdev, DIOCGPARTINFO, &pi, FREAD, l) == 0)
808 1.177 jdolecek bsize = imin(imax(pi.pi_bsize, DEV_BSIZE), MAXBSIZE);
809 1.157 christos else
810 1.157 christos bsize = BLKDEV_IOSIZE;
811 1.138 dholland
812 1.59 chs bscale = bsize >> DEV_BSHIFT;
813 1.181 mlelstv
814 1.181 mlelstv nra = uimax(16 * MAXPHYS / bsize - 1, 511);
815 1.181 mlelstv rablks = kmem_alloc(nra * sizeof(*rablks), KM_SLEEP);
816 1.181 mlelstv rasizes = kmem_alloc(nra * sizeof(*rasizes), KM_SLEEP);
817 1.181 mlelstv lastbn = ((uio->uio_offset + uio->uio_resid - 1) >> DEV_BSHIFT)
818 1.181 mlelstv &~ (bscale - 1);
819 1.181 mlelstv nrablks = ratogo = 0;
820 1.56 chs do {
821 1.59 chs bn = (uio->uio_offset >> DEV_BSHIFT) &~ (bscale - 1);
822 1.56 chs on = uio->uio_offset % bsize;
823 1.175 riastrad n = uimin((unsigned)(bsize - on), uio->uio_resid);
824 1.181 mlelstv
825 1.181 mlelstv if (ratogo == 0) {
826 1.181 mlelstv nrablks = uimin((lastbn - bn) / bscale, nra);
827 1.181 mlelstv ratogo = nrablks;
828 1.181 mlelstv
829 1.181 mlelstv for (i = 0; i < nrablks; ++i) {
830 1.181 mlelstv rablks[i] = bn + (i+1) * bscale;
831 1.181 mlelstv rasizes[i] = bsize;
832 1.181 mlelstv }
833 1.181 mlelstv
834 1.181 mlelstv error = breadn(vp, bn, bsize,
835 1.181 mlelstv rablks, rasizes, nrablks,
836 1.181 mlelstv 0, &bp);
837 1.181 mlelstv } else {
838 1.181 mlelstv if (ratogo > 0)
839 1.181 mlelstv --ratogo;
840 1.181 mlelstv error = bread(vp, bn, bsize, 0, &bp);
841 1.56 chs }
842 1.181 mlelstv if (error)
843 1.181 mlelstv break;
844 1.175 riastrad n = uimin(n, bsize - bp->b_resid);
845 1.56 chs error = uiomove((char *)bp->b_data + on, n, uio);
846 1.107 ad brelse(bp, 0);
847 1.56 chs } while (error == 0 && uio->uio_resid > 0 && n != 0);
848 1.181 mlelstv
849 1.181 mlelstv kmem_free(rablks, nra * sizeof(*rablks));
850 1.181 mlelstv kmem_free(rasizes, nra * sizeof(*rasizes));
851 1.181 mlelstv
852 1.56 chs return (error);
853 1.56 chs
854 1.56 chs default:
855 1.56 chs panic("spec_read type");
856 1.1 cgd }
857 1.56 chs /* NOTREACHED */
858 1.1 cgd }
859 1.1 cgd
860 1.1 cgd /*
861 1.1 cgd * Vnode op for write
862 1.1 cgd */
863 1.1 cgd /* ARGSUSED */
864 1.28 christos int
865 1.104 pooka spec_write(void *v)
866 1.28 christos {
867 1.15 mycroft struct vop_write_args /* {
868 1.15 mycroft struct vnode *a_vp;
869 1.15 mycroft struct uio *a_uio;
870 1.15 mycroft int a_ioflag;
871 1.87 elad kauth_cred_t a_cred;
872 1.28 christos } */ *ap = v;
873 1.48 augustss struct vnode *vp = ap->a_vp;
874 1.48 augustss struct uio *uio = ap->a_uio;
875 1.86 yamt struct lwp *l = curlwp;
876 1.56 chs struct buf *bp;
877 1.56 chs daddr_t bn;
878 1.59 chs int bsize, bscale;
879 1.157 christos struct partinfo pi;
880 1.64 gehenna int n, on;
881 1.1 cgd int error = 0;
882 1.1 cgd
883 1.160 pgoyette KASSERT(uio->uio_rw == UIO_WRITE);
884 1.160 pgoyette KASSERTMSG(VMSPACE_IS_KERNEL_P(uio->uio_vmspace) ||
885 1.160 pgoyette uio->uio_vmspace == curproc->p_vmspace,
886 1.160 pgoyette "vmspace belongs to neither kernel nor curproc");
887 1.1 cgd
888 1.56 chs switch (vp->v_type) {
889 1.56 chs
890 1.56 chs case VCHR:
891 1.130 hannken VOP_UNLOCK(vp);
892 1.100 ad error = cdev_write(vp->v_rdev, uio, ap->a_ioflag);
893 1.39 fvdl vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
894 1.1 cgd return (error);
895 1.56 chs
896 1.56 chs case VBLK:
897 1.112 ad KASSERT(vp == vp->v_specnode->sn_dev->sd_bdevvp);
898 1.56 chs if (uio->uio_resid == 0)
899 1.56 chs return (0);
900 1.56 chs if (uio->uio_offset < 0)
901 1.56 chs return (EINVAL);
902 1.157 christos
903 1.157 christos if (bdev_ioctl(vp->v_rdev, DIOCGPARTINFO, &pi, FREAD, l) == 0)
904 1.177 jdolecek bsize = imin(imax(pi.pi_bsize, DEV_BSIZE), MAXBSIZE);
905 1.157 christos else
906 1.157 christos bsize = BLKDEV_IOSIZE;
907 1.157 christos
908 1.59 chs bscale = bsize >> DEV_BSHIFT;
909 1.56 chs do {
910 1.59 chs bn = (uio->uio_offset >> DEV_BSHIFT) &~ (bscale - 1);
911 1.56 chs on = uio->uio_offset % bsize;
912 1.175 riastrad n = uimin((unsigned)(bsize - on), uio->uio_resid);
913 1.56 chs if (n == bsize)
914 1.56 chs bp = getblk(vp, bn, bsize, 0, 0);
915 1.56 chs else
916 1.146 maxv error = bread(vp, bn, bsize, B_MODIFY, &bp);
917 1.56 chs if (error) {
918 1.56 chs return (error);
919 1.56 chs }
920 1.175 riastrad n = uimin(n, bsize - bp->b_resid);
921 1.56 chs error = uiomove((char *)bp->b_data + on, n, uio);
922 1.56 chs if (error)
923 1.107 ad brelse(bp, 0);
924 1.56 chs else {
925 1.56 chs if (n + on == bsize)
926 1.56 chs bawrite(bp);
927 1.56 chs else
928 1.56 chs bdwrite(bp);
929 1.107 ad error = bp->b_error;
930 1.56 chs }
931 1.56 chs } while (error == 0 && uio->uio_resid > 0 && n != 0);
932 1.56 chs return (error);
933 1.56 chs
934 1.56 chs default:
935 1.56 chs panic("spec_write type");
936 1.55 chs }
937 1.56 chs /* NOTREACHED */
938 1.1 cgd }
939 1.1 cgd
940 1.1 cgd /*
941 1.144 dholland * fdiscard, which on disk devices becomes TRIM.
942 1.144 dholland */
943 1.144 dholland int
944 1.144 dholland spec_fdiscard(void *v)
945 1.144 dholland {
946 1.144 dholland struct vop_fdiscard_args /* {
947 1.144 dholland struct vnode *a_vp;
948 1.144 dholland off_t a_pos;
949 1.144 dholland off_t a_len;
950 1.144 dholland } */ *ap = v;
951 1.144 dholland struct vnode *vp;
952 1.144 dholland dev_t dev;
953 1.144 dholland
954 1.144 dholland vp = ap->a_vp;
955 1.144 dholland dev = NODEV;
956 1.144 dholland
957 1.144 dholland mutex_enter(vp->v_interlock);
958 1.144 dholland if (vdead_check(vp, VDEAD_NOWAIT) == 0 && vp->v_specnode != NULL) {
959 1.144 dholland dev = vp->v_rdev;
960 1.144 dholland }
961 1.144 dholland mutex_exit(vp->v_interlock);
962 1.144 dholland
963 1.144 dholland if (dev == NODEV) {
964 1.144 dholland return ENXIO;
965 1.144 dholland }
966 1.144 dholland
967 1.144 dholland switch (vp->v_type) {
968 1.144 dholland case VCHR:
969 1.144 dholland // this is not stored for character devices
970 1.144 dholland //KASSERT(vp == vp->v_specnode->sn_dev->sd_cdevvp);
971 1.144 dholland return cdev_discard(dev, ap->a_pos, ap->a_len);
972 1.144 dholland case VBLK:
973 1.144 dholland KASSERT(vp == vp->v_specnode->sn_dev->sd_bdevvp);
974 1.144 dholland return bdev_discard(dev, ap->a_pos, ap->a_len);
975 1.144 dholland default:
976 1.144 dholland panic("spec_fdiscard: not a device\n");
977 1.144 dholland }
978 1.144 dholland }
979 1.144 dholland
980 1.144 dholland /*
981 1.1 cgd * Device ioctl operation.
982 1.1 cgd */
983 1.1 cgd /* ARGSUSED */
984 1.28 christos int
985 1.104 pooka spec_ioctl(void *v)
986 1.28 christos {
987 1.15 mycroft struct vop_ioctl_args /* {
988 1.15 mycroft struct vnode *a_vp;
989 1.19 cgd u_long a_command;
990 1.78 jrf void *a_data;
991 1.15 mycroft int a_fflag;
992 1.87 elad kauth_cred_t a_cred;
993 1.28 christos } */ *ap = v;
994 1.83 chs struct vnode *vp;
995 1.83 chs dev_t dev;
996 1.1 cgd
997 1.83 chs /*
998 1.83 chs * Extract all the info we need from the vnode, taking care to
999 1.83 chs * avoid a race with VOP_REVOKE().
1000 1.83 chs */
1001 1.83 chs
1002 1.83 chs vp = ap->a_vp;
1003 1.83 chs dev = NODEV;
1004 1.134 rmind mutex_enter(vp->v_interlock);
1005 1.143 hannken if (vdead_check(vp, VDEAD_NOWAIT) == 0 && vp->v_specnode) {
1006 1.83 chs dev = vp->v_rdev;
1007 1.83 chs }
1008 1.134 rmind mutex_exit(vp->v_interlock);
1009 1.83 chs if (dev == NODEV) {
1010 1.83 chs return ENXIO;
1011 1.83 chs }
1012 1.83 chs
1013 1.83 chs switch (vp->v_type) {
1014 1.1 cgd
1015 1.1 cgd case VCHR:
1016 1.100 ad return cdev_ioctl(dev, ap->a_command, ap->a_data,
1017 1.109 pooka ap->a_fflag, curlwp);
1018 1.1 cgd
1019 1.1 cgd case VBLK:
1020 1.112 ad KASSERT(vp == vp->v_specnode->sn_dev->sd_bdevvp);
1021 1.100 ad return bdev_ioctl(dev, ap->a_command, ap->a_data,
1022 1.109 pooka ap->a_fflag, curlwp);
1023 1.1 cgd
1024 1.1 cgd default:
1025 1.1 cgd panic("spec_ioctl");
1026 1.1 cgd /* NOTREACHED */
1027 1.1 cgd }
1028 1.1 cgd }
1029 1.1 cgd
1030 1.1 cgd /* ARGSUSED */
1031 1.28 christos int
1032 1.104 pooka spec_poll(void *v)
1033 1.28 christos {
1034 1.32 mycroft struct vop_poll_args /* {
1035 1.15 mycroft struct vnode *a_vp;
1036 1.32 mycroft int a_events;
1037 1.28 christos } */ *ap = v;
1038 1.91 jld struct vnode *vp;
1039 1.48 augustss dev_t dev;
1040 1.1 cgd
1041 1.91 jld /*
1042 1.91 jld * Extract all the info we need from the vnode, taking care to
1043 1.91 jld * avoid a race with VOP_REVOKE().
1044 1.91 jld */
1045 1.91 jld
1046 1.91 jld vp = ap->a_vp;
1047 1.91 jld dev = NODEV;
1048 1.134 rmind mutex_enter(vp->v_interlock);
1049 1.143 hannken if (vdead_check(vp, VDEAD_NOWAIT) == 0 && vp->v_specnode) {
1050 1.91 jld dev = vp->v_rdev;
1051 1.91 jld }
1052 1.134 rmind mutex_exit(vp->v_interlock);
1053 1.91 jld if (dev == NODEV) {
1054 1.92 jld return POLLERR;
1055 1.91 jld }
1056 1.91 jld
1057 1.91 jld switch (vp->v_type) {
1058 1.1 cgd
1059 1.1 cgd case VCHR:
1060 1.109 pooka return cdev_poll(dev, ap->a_events, curlwp);
1061 1.30 mycroft
1062 1.30 mycroft default:
1063 1.32 mycroft return (genfs_poll(v));
1064 1.15 mycroft }
1065 1.15 mycroft }
1066 1.65 jdolecek
1067 1.65 jdolecek /* ARGSUSED */
1068 1.65 jdolecek int
1069 1.104 pooka spec_kqfilter(void *v)
1070 1.65 jdolecek {
1071 1.65 jdolecek struct vop_kqfilter_args /* {
1072 1.65 jdolecek struct vnode *a_vp;
1073 1.65 jdolecek struct proc *a_kn;
1074 1.65 jdolecek } */ *ap = v;
1075 1.65 jdolecek dev_t dev;
1076 1.65 jdolecek
1077 1.65 jdolecek switch (ap->a_vp->v_type) {
1078 1.65 jdolecek
1079 1.65 jdolecek case VCHR:
1080 1.65 jdolecek dev = ap->a_vp->v_rdev;
1081 1.100 ad return cdev_kqfilter(dev, ap->a_kn);
1082 1.65 jdolecek default:
1083 1.65 jdolecek /*
1084 1.65 jdolecek * Block devices don't support kqfilter, and refuse it
1085 1.65 jdolecek * for any other files (like those vflush()ed) too.
1086 1.65 jdolecek */
1087 1.65 jdolecek return (EOPNOTSUPP);
1088 1.65 jdolecek }
1089 1.65 jdolecek }
1090 1.65 jdolecek
1091 1.15 mycroft /*
1092 1.101 pooka * Allow mapping of only D_DISK. This is called only for VBLK.
1093 1.101 pooka */
1094 1.101 pooka int
1095 1.104 pooka spec_mmap(void *v)
1096 1.101 pooka {
1097 1.101 pooka struct vop_mmap_args /* {
1098 1.101 pooka struct vnode *a_vp;
1099 1.102 pooka vm_prot_t a_prot;
1100 1.101 pooka kauth_cred_t a_cred;
1101 1.101 pooka } */ *ap = v;
1102 1.101 pooka struct vnode *vp = ap->a_vp;
1103 1.101 pooka
1104 1.101 pooka KASSERT(vp->v_type == VBLK);
1105 1.101 pooka if (bdev_type(vp->v_rdev) != D_DISK)
1106 1.101 pooka return EINVAL;
1107 1.101 pooka
1108 1.101 pooka return 0;
1109 1.101 pooka }
1110 1.101 pooka
1111 1.101 pooka /*
1112 1.15 mycroft * Synch buffers associated with a block device
1113 1.15 mycroft */
1114 1.15 mycroft /* ARGSUSED */
1115 1.15 mycroft int
1116 1.104 pooka spec_fsync(void *v)
1117 1.28 christos {
1118 1.15 mycroft struct vop_fsync_args /* {
1119 1.15 mycroft struct vnode *a_vp;
1120 1.87 elad kauth_cred_t a_cred;
1121 1.40 kleink int a_flags;
1122 1.50 fvdl off_t offlo;
1123 1.50 fvdl off_t offhi;
1124 1.28 christos } */ *ap = v;
1125 1.48 augustss struct vnode *vp = ap->a_vp;
1126 1.118 ad struct mount *mp;
1127 1.118 ad int error;
1128 1.15 mycroft
1129 1.112 ad if (vp->v_type == VBLK) {
1130 1.141 hannken if ((mp = spec_node_getmountedfs(vp)) != NULL) {
1131 1.133 hannken error = VFS_FSYNC(mp, vp, ap->a_flags);
1132 1.118 ad if (error != EOPNOTSUPP)
1133 1.118 ad return error;
1134 1.118 ad }
1135 1.135 chs return vflushbuf(vp, ap->a_flags);
1136 1.112 ad }
1137 1.15 mycroft return (0);
1138 1.1 cgd }
1139 1.1 cgd
1140 1.1 cgd /*
1141 1.1 cgd * Just call the device strategy routine
1142 1.1 cgd */
1143 1.28 christos int
1144 1.104 pooka spec_strategy(void *v)
1145 1.28 christos {
1146 1.15 mycroft struct vop_strategy_args /* {
1147 1.76 hannken struct vnode *a_vp;
1148 1.15 mycroft struct buf *a_bp;
1149 1.28 christos } */ *ap = v;
1150 1.76 hannken struct vnode *vp = ap->a_vp;
1151 1.76 hannken struct buf *bp = ap->a_bp;
1152 1.161 hannken dev_t dev;
1153 1.106 hannken int error;
1154 1.1 cgd
1155 1.161 hannken dev = NODEV;
1156 1.112 ad
1157 1.161 hannken /*
1158 1.161 hannken * Extract all the info we need from the vnode, taking care to
1159 1.161 hannken * avoid a race with VOP_REVOKE().
1160 1.161 hannken */
1161 1.77 hannken
1162 1.161 hannken mutex_enter(vp->v_interlock);
1163 1.161 hannken if (vdead_check(vp, VDEAD_NOWAIT) == 0 && vp->v_specnode != NULL) {
1164 1.162 hannken KASSERT(vp == vp->v_specnode->sn_dev->sd_bdevvp);
1165 1.161 hannken dev = vp->v_rdev;
1166 1.161 hannken }
1167 1.161 hannken mutex_exit(vp->v_interlock);
1168 1.77 hannken
1169 1.161 hannken if (dev == NODEV) {
1170 1.161 hannken error = ENXIO;
1171 1.161 hannken goto out;
1172 1.79 hannken }
1173 1.161 hannken bp->b_dev = dev;
1174 1.79 hannken
1175 1.161 hannken if (!(bp->b_flags & B_READ)) {
1176 1.169 hannken #ifdef DIAGNOSTIC
1177 1.169 hannken if (bp->b_vp && bp->b_vp->v_type == VBLK) {
1178 1.169 hannken struct mount *mp = spec_node_getmountedfs(bp->b_vp);
1179 1.169 hannken
1180 1.169 hannken if (mp && (mp->mnt_flag & MNT_RDONLY)) {
1181 1.169 hannken printf("%s blk %"PRId64" written while ro!\n",
1182 1.169 hannken mp->mnt_stat.f_mntonname, bp->b_blkno);
1183 1.169 hannken }
1184 1.169 hannken }
1185 1.169 hannken #endif /* DIAGNOSTIC */
1186 1.161 hannken error = fscow_run(bp, false);
1187 1.161 hannken if (error)
1188 1.161 hannken goto out;
1189 1.161 hannken }
1190 1.100 ad bdev_strategy(bp);
1191 1.76 hannken
1192 1.161 hannken return 0;
1193 1.161 hannken
1194 1.161 hannken out:
1195 1.161 hannken bp->b_error = error;
1196 1.161 hannken bp->b_resid = bp->b_bcount;
1197 1.161 hannken biodone(bp);
1198 1.161 hannken
1199 1.161 hannken return error;
1200 1.1 cgd }
1201 1.1 cgd
1202 1.39 fvdl int
1203 1.104 pooka spec_inactive(void *v)
1204 1.39 fvdl {
1205 1.170 riastrad struct vop_inactive_v2_args /* {
1206 1.39 fvdl struct vnode *a_vp;
1207 1.148 hannken struct bool *a_recycle;
1208 1.39 fvdl } */ *ap = v;
1209 1.148 hannken
1210 1.171 martin KASSERT(ap->a_vp->v_mount == dead_rootmount);
1211 1.148 hannken *ap->a_recycle = true;
1212 1.170 riastrad
1213 1.148 hannken return 0;
1214 1.148 hannken }
1215 1.148 hannken
1216 1.148 hannken int
1217 1.148 hannken spec_reclaim(void *v)
1218 1.148 hannken {
1219 1.172 riastrad struct vop_reclaim_v2_args /* {
1220 1.148 hannken struct vnode *a_vp;
1221 1.148 hannken } */ *ap = v;
1222 1.172 riastrad struct vnode *vp = ap->a_vp;
1223 1.172 riastrad
1224 1.172 riastrad VOP_UNLOCK(vp);
1225 1.39 fvdl
1226 1.148 hannken KASSERT(vp->v_mount == dead_rootmount);
1227 1.148 hannken return 0;
1228 1.39 fvdl }
1229 1.39 fvdl
1230 1.1 cgd /*
1231 1.1 cgd * This is a noop, simply returning what one has been given.
1232 1.1 cgd */
1233 1.28 christos int
1234 1.104 pooka spec_bmap(void *v)
1235 1.28 christos {
1236 1.15 mycroft struct vop_bmap_args /* {
1237 1.15 mycroft struct vnode *a_vp;
1238 1.15 mycroft daddr_t a_bn;
1239 1.15 mycroft struct vnode **a_vpp;
1240 1.15 mycroft daddr_t *a_bnp;
1241 1.39 fvdl int *a_runp;
1242 1.28 christos } */ *ap = v;
1243 1.1 cgd
1244 1.15 mycroft if (ap->a_vpp != NULL)
1245 1.15 mycroft *ap->a_vpp = ap->a_vp;
1246 1.15 mycroft if (ap->a_bnp != NULL)
1247 1.15 mycroft *ap->a_bnp = ap->a_bn;
1248 1.39 fvdl if (ap->a_runp != NULL)
1249 1.55 chs *ap->a_runp = (MAXBSIZE >> DEV_BSHIFT) - 1;
1250 1.1 cgd return (0);
1251 1.1 cgd }
1252 1.1 cgd
1253 1.1 cgd /*
1254 1.1 cgd * Device close routine
1255 1.1 cgd */
1256 1.1 cgd /* ARGSUSED */
1257 1.28 christos int
1258 1.104 pooka spec_close(void *v)
1259 1.28 christos {
1260 1.15 mycroft struct vop_close_args /* {
1261 1.15 mycroft struct vnode *a_vp;
1262 1.15 mycroft int a_fflag;
1263 1.87 elad kauth_cred_t a_cred;
1264 1.28 christos } */ *ap = v;
1265 1.48 augustss struct vnode *vp = ap->a_vp;
1266 1.71 dsl struct session *sess;
1267 1.1 cgd dev_t dev = vp->v_rdev;
1268 1.143 hannken int flags = ap->a_fflag;
1269 1.143 hannken int mode, error, count;
1270 1.112 ad specnode_t *sn;
1271 1.112 ad specdev_t *sd;
1272 1.44 wrstuden
1273 1.143 hannken mutex_enter(vp->v_interlock);
1274 1.112 ad sn = vp->v_specnode;
1275 1.112 ad sd = sn->sn_dev;
1276 1.143 hannken /*
1277 1.143 hannken * If we're going away soon, make this non-blocking.
1278 1.143 hannken * Also ensures that we won't wedge in vn_lock below.
1279 1.143 hannken */
1280 1.143 hannken if (vdead_check(vp, VDEAD_NOWAIT) != 0)
1281 1.143 hannken flags |= FNONBLOCK;
1282 1.143 hannken mutex_exit(vp->v_interlock);
1283 1.1 cgd
1284 1.1 cgd switch (vp->v_type) {
1285 1.1 cgd
1286 1.1 cgd case VCHR:
1287 1.11 cgd /*
1288 1.11 cgd * Hack: a tty device that is a controlling terminal
1289 1.112 ad * has a reference from the session structure. We
1290 1.112 ad * cannot easily tell that a character device is a
1291 1.112 ad * controlling terminal, unless it is the closing
1292 1.112 ad * process' controlling terminal. In that case, if the
1293 1.112 ad * open count is 1 release the reference from the
1294 1.112 ad * session. Also, remove the link from the tty back to
1295 1.112 ad * the session and pgrp.
1296 1.112 ad *
1297 1.112 ad * XXX V. fishy.
1298 1.11 cgd */
1299 1.179 ad mutex_enter(&proc_lock);
1300 1.112 ad sess = curlwp->l_proc->p_session;
1301 1.112 ad if (sn->sn_opencnt == 1 && vp == sess->s_ttyvp) {
1302 1.112 ad mutex_spin_enter(&tty_lock);
1303 1.71 dsl sess->s_ttyvp = NULL;
1304 1.72 pk if (sess->s_ttyp->t_session != NULL) {
1305 1.72 pk sess->s_ttyp->t_pgrp = NULL;
1306 1.72 pk sess->s_ttyp->t_session = NULL;
1307 1.112 ad mutex_spin_exit(&tty_lock);
1308 1.124 rmind /* Releases proc_lock. */
1309 1.124 rmind proc_sessrele(sess);
1310 1.100 ad } else {
1311 1.112 ad mutex_spin_exit(&tty_lock);
1312 1.100 ad if (sess->s_ttyp->t_pgrp != NULL)
1313 1.100 ad panic("spec_close: spurious pgrp ref");
1314 1.179 ad mutex_exit(&proc_lock);
1315 1.100 ad }
1316 1.11 cgd vrele(vp);
1317 1.100 ad } else
1318 1.179 ad mutex_exit(&proc_lock);
1319 1.100 ad
1320 1.1 cgd /*
1321 1.1 cgd * If the vnode is locked, then we are in the midst
1322 1.1 cgd * of forcably closing the device, otherwise we only
1323 1.1 cgd * close on last reference.
1324 1.1 cgd */
1325 1.1 cgd mode = S_IFCHR;
1326 1.1 cgd break;
1327 1.1 cgd
1328 1.1 cgd case VBLK:
1329 1.112 ad KASSERT(vp == vp->v_specnode->sn_dev->sd_bdevvp);
1330 1.1 cgd /*
1331 1.1 cgd * On last close of a block device (that isn't mounted)
1332 1.1 cgd * we must invalidate any in core blocks, so that
1333 1.1 cgd * we can, for instance, change floppy disks.
1334 1.1 cgd */
1335 1.109 pooka error = vinvalbuf(vp, V_SAVE, ap->a_cred, curlwp, 0, 0);
1336 1.28 christos if (error)
1337 1.15 mycroft return (error);
1338 1.1 cgd /*
1339 1.1 cgd * We do not want to really close the device if it
1340 1.1 cgd * is still in use unless we are trying to close it
1341 1.1 cgd * forcibly. Since every use (buffer, vnode, swap, cmap)
1342 1.1 cgd * holds a reference to the vnode, and because we mark
1343 1.1 cgd * any other vnodes that alias this device, when the
1344 1.1 cgd * sum of the reference counts on all the aliased
1345 1.1 cgd * vnodes descends to one, we are on last close.
1346 1.1 cgd */
1347 1.1 cgd mode = S_IFBLK;
1348 1.1 cgd break;
1349 1.5 cgd
1350 1.1 cgd default:
1351 1.1 cgd panic("spec_close: not special");
1352 1.1 cgd }
1353 1.1 cgd
1354 1.120 pooka mutex_enter(&device_lock);
1355 1.112 ad sn->sn_opencnt--;
1356 1.112 ad count = --sd->sd_opencnt;
1357 1.112 ad if (vp->v_type == VBLK)
1358 1.112 ad sd->sd_bdevvp = NULL;
1359 1.120 pooka mutex_exit(&device_lock);
1360 1.112 ad
1361 1.185 riastrad if (count != 0)
1362 1.112 ad return 0;
1363 1.112 ad
1364 1.44 wrstuden /*
1365 1.62 wiz * If we're able to block, release the vnode lock & reacquire. We
1366 1.72 pk * might end up sleeping for someone else who wants our queues. They
1367 1.143 hannken * won't get them if we hold the vnode locked.
1368 1.44 wrstuden */
1369 1.143 hannken if (!(flags & FNONBLOCK))
1370 1.130 hannken VOP_UNLOCK(vp);
1371 1.44 wrstuden
1372 1.100 ad if (vp->v_type == VBLK)
1373 1.143 hannken error = bdev_close(dev, flags, mode, curlwp);
1374 1.64 gehenna else
1375 1.143 hannken error = cdev_close(dev, flags, mode, curlwp);
1376 1.44 wrstuden
1377 1.143 hannken if (!(flags & FNONBLOCK))
1378 1.44 wrstuden vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1379 1.44 wrstuden
1380 1.44 wrstuden return (error);
1381 1.1 cgd }
1382 1.1 cgd
1383 1.1 cgd /*
1384 1.1 cgd * Print out the contents of a special device vnode.
1385 1.1 cgd */
1386 1.28 christos int
1387 1.104 pooka spec_print(void *v)
1388 1.28 christos {
1389 1.15 mycroft struct vop_print_args /* {
1390 1.15 mycroft struct vnode *a_vp;
1391 1.28 christos } */ *ap = v;
1392 1.15 mycroft
1393 1.121 christos printf("dev %llu, %llu\n", (unsigned long long)major(ap->a_vp->v_rdev),
1394 1.121 christos (unsigned long long)minor(ap->a_vp->v_rdev));
1395 1.28 christos return 0;
1396 1.15 mycroft }
1397 1.15 mycroft
1398 1.15 mycroft /*
1399 1.15 mycroft * Return POSIX pathconf information applicable to special devices.
1400 1.15 mycroft */
1401 1.28 christos int
1402 1.104 pooka spec_pathconf(void *v)
1403 1.28 christos {
1404 1.15 mycroft struct vop_pathconf_args /* {
1405 1.15 mycroft struct vnode *a_vp;
1406 1.15 mycroft int a_name;
1407 1.18 cgd register_t *a_retval;
1408 1.28 christos } */ *ap = v;
1409 1.1 cgd
1410 1.15 mycroft switch (ap->a_name) {
1411 1.15 mycroft case _PC_LINK_MAX:
1412 1.15 mycroft *ap->a_retval = LINK_MAX;
1413 1.15 mycroft return (0);
1414 1.15 mycroft case _PC_MAX_CANON:
1415 1.15 mycroft *ap->a_retval = MAX_CANON;
1416 1.15 mycroft return (0);
1417 1.15 mycroft case _PC_MAX_INPUT:
1418 1.15 mycroft *ap->a_retval = MAX_INPUT;
1419 1.15 mycroft return (0);
1420 1.15 mycroft case _PC_PIPE_BUF:
1421 1.15 mycroft *ap->a_retval = PIPE_BUF;
1422 1.15 mycroft return (0);
1423 1.15 mycroft case _PC_CHOWN_RESTRICTED:
1424 1.15 mycroft *ap->a_retval = 1;
1425 1.15 mycroft return (0);
1426 1.15 mycroft case _PC_VDISABLE:
1427 1.15 mycroft *ap->a_retval = _POSIX_VDISABLE;
1428 1.41 kleink return (0);
1429 1.41 kleink case _PC_SYNC_IO:
1430 1.41 kleink *ap->a_retval = 1;
1431 1.15 mycroft return (0);
1432 1.15 mycroft default:
1433 1.180 christos return genfs_pathconf(ap);
1434 1.15 mycroft }
1435 1.1 cgd /* NOTREACHED */
1436 1.35 kleink }
1437 1.35 kleink
1438 1.80 perry /*
1439 1.35 kleink * Advisory record locking support.
1440 1.35 kleink */
1441 1.35 kleink int
1442 1.104 pooka spec_advlock(void *v)
1443 1.35 kleink {
1444 1.35 kleink struct vop_advlock_args /* {
1445 1.35 kleink struct vnode *a_vp;
1446 1.78 jrf void *a_id;
1447 1.35 kleink int a_op;
1448 1.35 kleink struct flock *a_fl;
1449 1.35 kleink int a_flags;
1450 1.35 kleink } */ *ap = v;
1451 1.48 augustss struct vnode *vp = ap->a_vp;
1452 1.35 kleink
1453 1.49 jdolecek return lf_advlock(ap, &vp->v_speclockf, (off_t)0);
1454 1.1 cgd }
1455