1*e7776783SApple OSS Distributions /*
2*e7776783SApple OSS Distributions * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
3*e7776783SApple OSS Distributions *
4*e7776783SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*e7776783SApple OSS Distributions *
6*e7776783SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*e7776783SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*e7776783SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*e7776783SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*e7776783SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*e7776783SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*e7776783SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*e7776783SApple OSS Distributions * terms of an Apple operating system software license agreement.
14*e7776783SApple OSS Distributions *
15*e7776783SApple OSS Distributions * Please obtain a copy of the License at
16*e7776783SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*e7776783SApple OSS Distributions *
18*e7776783SApple OSS Distributions * The Original Code and all software distributed under the License are
19*e7776783SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*e7776783SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*e7776783SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*e7776783SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*e7776783SApple OSS Distributions * Please see the License for the specific language governing rights and
24*e7776783SApple OSS Distributions * limitations under the License.
25*e7776783SApple OSS Distributions *
26*e7776783SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*e7776783SApple OSS Distributions */
28*e7776783SApple OSS Distributions /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
29*e7776783SApple OSS Distributions /*
30*e7776783SApple OSS Distributions * Copyright (c) 1992, 1993
31*e7776783SApple OSS Distributions * The Regents of the University of California. All rights reserved.
32*e7776783SApple OSS Distributions *
33*e7776783SApple OSS Distributions * This code is derived from software donated to Berkeley by
34*e7776783SApple OSS Distributions * Jan-Simon Pendry.
35*e7776783SApple OSS Distributions *
36*e7776783SApple OSS Distributions * Redistribution and use in source and binary forms, with or without
37*e7776783SApple OSS Distributions * modification, are permitted provided that the following conditions
38*e7776783SApple OSS Distributions * are met:
39*e7776783SApple OSS Distributions * 1. Redistributions of source code must retain the above copyright
40*e7776783SApple OSS Distributions * notice, this list of conditions and the following disclaimer.
41*e7776783SApple OSS Distributions * 2. Redistributions in binary form must reproduce the above copyright
42*e7776783SApple OSS Distributions * notice, this list of conditions and the following disclaimer in the
43*e7776783SApple OSS Distributions * documentation and/or other materials provided with the distribution.
44*e7776783SApple OSS Distributions * 3. All advertising materials mentioning features or use of this software
45*e7776783SApple OSS Distributions * must display the following acknowledgement:
46*e7776783SApple OSS Distributions * This product includes software developed by the University of
47*e7776783SApple OSS Distributions * California, Berkeley and its contributors.
48*e7776783SApple OSS Distributions * 4. Neither the name of the University nor the names of its contributors
49*e7776783SApple OSS Distributions * may be used to endorse or promote products derived from this software
50*e7776783SApple OSS Distributions * without specific prior written permission.
51*e7776783SApple OSS Distributions *
52*e7776783SApple OSS Distributions * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53*e7776783SApple OSS Distributions * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54*e7776783SApple OSS Distributions * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55*e7776783SApple OSS Distributions * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56*e7776783SApple OSS Distributions * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57*e7776783SApple OSS Distributions * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58*e7776783SApple OSS Distributions * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59*e7776783SApple OSS Distributions * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60*e7776783SApple OSS Distributions * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61*e7776783SApple OSS Distributions * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62*e7776783SApple OSS Distributions * SUCH DAMAGE.
63*e7776783SApple OSS Distributions *
64*e7776783SApple OSS Distributions * @(#)fdesc_vnops.c 8.17 (Berkeley) 5/22/95
65*e7776783SApple OSS Distributions *
66*e7776783SApple OSS Distributions */
67*e7776783SApple OSS Distributions
68*e7776783SApple OSS Distributions /*
69*e7776783SApple OSS Distributions * /dev/fd Filesystem
70*e7776783SApple OSS Distributions */
71*e7776783SApple OSS Distributions
72*e7776783SApple OSS Distributions #include <sys/param.h>
73*e7776783SApple OSS Distributions #include <sys/systm.h>
74*e7776783SApple OSS Distributions #include <sys/types.h>
75*e7776783SApple OSS Distributions #include <sys/time.h>
76*e7776783SApple OSS Distributions #include <sys/proc_internal.h>
77*e7776783SApple OSS Distributions #include <sys/kernel.h> /* boottime */
78*e7776783SApple OSS Distributions #include <sys/resourcevar.h>
79*e7776783SApple OSS Distributions #include <sys/filedesc.h>
80*e7776783SApple OSS Distributions #include <sys/kauth.h>
81*e7776783SApple OSS Distributions #include <sys/vnode_internal.h>
82*e7776783SApple OSS Distributions #include <sys/malloc.h>
83*e7776783SApple OSS Distributions #include <sys/file_internal.h>
84*e7776783SApple OSS Distributions #include <sys/stat.h>
85*e7776783SApple OSS Distributions #include <sys/mount_internal.h>
86*e7776783SApple OSS Distributions #include <sys/namei.h>
87*e7776783SApple OSS Distributions #include <sys/dirent.h>
88*e7776783SApple OSS Distributions #include <sys/ubc.h>
89*e7776783SApple OSS Distributions #include <sys/socketvar.h>
90*e7776783SApple OSS Distributions #include <sys/pipe.h>
91*e7776783SApple OSS Distributions #include <sys/uio_internal.h>
92*e7776783SApple OSS Distributions #include <vfs/vfs_support.h>
93*e7776783SApple OSS Distributions #include <pexpert/pexpert.h>
94*e7776783SApple OSS Distributions #include <miscfs/devfs/fdesc.h>
95*e7776783SApple OSS Distributions #include <miscfs/devfs/devfs.h>
96*e7776783SApple OSS Distributions #include <miscfs/devfs/devfsdefs.h>
97*e7776783SApple OSS Distributions
98*e7776783SApple OSS Distributions #define FDL_WANT 0x01
99*e7776783SApple OSS Distributions #define FDL_LOCKED 0x02
100*e7776783SApple OSS Distributions static int fdcache_lock;
101*e7776783SApple OSS Distributions
102*e7776783SApple OSS Distributions
103*e7776783SApple OSS Distributions #if (FD_STDIN != FD_STDOUT - 1) || (FD_STDOUT != FD_STDERR - 1)
104*e7776783SApple OSS Distributions FD_STDIN, FD_STDOUT, FD_STDERR must be a sequence n, n + 1, n + 2
105*e7776783SApple OSS Distributions #endif
106*e7776783SApple OSS Distributions
107*e7776783SApple OSS Distributions #define NFDCACHE 3
108*e7776783SApple OSS Distributions
109*e7776783SApple OSS Distributions #define FD_NHASH(ix) \
110*e7776783SApple OSS Distributions (&fdhashtbl[(ix) & fdhash])
111*e7776783SApple OSS Distributions LIST_HEAD(fdhashhead, fdescnode) * fdhashtbl;
112*e7776783SApple OSS Distributions u_long fdhash;
113*e7776783SApple OSS Distributions
114*e7776783SApple OSS Distributions static int fdesc_attr(int fd, struct vnode_attr *vap, vfs_context_t a_context);
115*e7776783SApple OSS Distributions
116*e7776783SApple OSS Distributions static LCK_GRP_DECLARE(fdesc_lckgrp, "fdesc");
117*e7776783SApple OSS Distributions static LCK_MTX_DECLARE(fdesc_mtx, &fdesc_lckgrp);
118*e7776783SApple OSS Distributions
119*e7776783SApple OSS Distributions static void
fdesc_lock(void)120*e7776783SApple OSS Distributions fdesc_lock(void)
121*e7776783SApple OSS Distributions {
122*e7776783SApple OSS Distributions lck_mtx_lock(&fdesc_mtx);
123*e7776783SApple OSS Distributions }
124*e7776783SApple OSS Distributions
125*e7776783SApple OSS Distributions static void
fdesc_unlock(void)126*e7776783SApple OSS Distributions fdesc_unlock(void)
127*e7776783SApple OSS Distributions {
128*e7776783SApple OSS Distributions lck_mtx_unlock(&fdesc_mtx);
129*e7776783SApple OSS Distributions }
130*e7776783SApple OSS Distributions
131*e7776783SApple OSS Distributions
132*e7776783SApple OSS Distributions /*
133*e7776783SApple OSS Distributions * Initialise cache headers, create the devfs node
134*e7776783SApple OSS Distributions */
135*e7776783SApple OSS Distributions int
devfs_fdesc_init()136*e7776783SApple OSS Distributions devfs_fdesc_init()
137*e7776783SApple OSS Distributions {
138*e7776783SApple OSS Distributions int error = 0;
139*e7776783SApple OSS Distributions devnode_t *rootdir = dev_root->de_dnp;
140*e7776783SApple OSS Distributions devdirent_t *direntp;
141*e7776783SApple OSS Distributions
142*e7776783SApple OSS Distributions /* XXX Make sure you have the right path... */
143*e7776783SApple OSS Distributions fdhashtbl = hashinit(NFDCACHE, M_CACHE, &fdhash);
144*e7776783SApple OSS Distributions
145*e7776783SApple OSS Distributions DEVFS_LOCK();
146*e7776783SApple OSS Distributions dev_add_entry("fd", rootdir, DEV_DEVFD, NULL, NULL, NULL, &direntp);
147*e7776783SApple OSS Distributions devfs_fdesc_makelinks();
148*e7776783SApple OSS Distributions DEVFS_UNLOCK();
149*e7776783SApple OSS Distributions
150*e7776783SApple OSS Distributions return error;
151*e7776783SApple OSS Distributions }
152*e7776783SApple OSS Distributions
153*e7776783SApple OSS Distributions /*
154*e7776783SApple OSS Distributions * Called during early startup, no need to synchronize
155*e7776783SApple OSS Distributions */
156*e7776783SApple OSS Distributions int
devfs_fdesc_makelinks()157*e7776783SApple OSS Distributions devfs_fdesc_makelinks()
158*e7776783SApple OSS Distributions {
159*e7776783SApple OSS Distributions int error = 0;
160*e7776783SApple OSS Distributions devdirent_t *stdin_ent = NULL, *stdout_ent = NULL, *stderr_ent = NULL;
161*e7776783SApple OSS Distributions devnode_t *root_devnode = dev_root->de_dnp;
162*e7776783SApple OSS Distributions
163*e7776783SApple OSS Distributions /* We do this ugliness to get around some "const" warnings */
164*e7776783SApple OSS Distributions char in[] = "stdin";
165*e7776783SApple OSS Distributions char out[] = "stdout";
166*e7776783SApple OSS Distributions char err[] = "stderr";
167*e7776783SApple OSS Distributions char zero[] = "fd/0";
168*e7776783SApple OSS Distributions char one[] = "fd/1";
169*e7776783SApple OSS Distributions char two[] = "fd/2";
170*e7776783SApple OSS Distributions
171*e7776783SApple OSS Distributions if ((error = devfs_make_symlink(root_devnode, in, 0555, zero, &stdin_ent))) {
172*e7776783SApple OSS Distributions printf("Couldn't make stdin, err %d.\n", error);
173*e7776783SApple OSS Distributions goto bad;
174*e7776783SApple OSS Distributions }
175*e7776783SApple OSS Distributions
176*e7776783SApple OSS Distributions if ((error = devfs_make_symlink(root_devnode, out, 0555, one, &stdout_ent))) {
177*e7776783SApple OSS Distributions printf("Couldn't make stdout, err %d.\n", error);
178*e7776783SApple OSS Distributions goto bad;
179*e7776783SApple OSS Distributions }
180*e7776783SApple OSS Distributions
181*e7776783SApple OSS Distributions if ((error = devfs_make_symlink(root_devnode, err, 0555, two, &stderr_ent))) {
182*e7776783SApple OSS Distributions printf("Couldn't make stderr, err %d.\n", error);
183*e7776783SApple OSS Distributions goto bad;
184*e7776783SApple OSS Distributions }
185*e7776783SApple OSS Distributions
186*e7776783SApple OSS Distributions return 0;
187*e7776783SApple OSS Distributions
188*e7776783SApple OSS Distributions bad:
189*e7776783SApple OSS Distributions if (stdin_ent) {
190*e7776783SApple OSS Distributions dev_free_name(stdin_ent);
191*e7776783SApple OSS Distributions }
192*e7776783SApple OSS Distributions if (stdout_ent) {
193*e7776783SApple OSS Distributions dev_free_name(stdout_ent);
194*e7776783SApple OSS Distributions }
195*e7776783SApple OSS Distributions if (stderr_ent) {
196*e7776783SApple OSS Distributions dev_free_name(stderr_ent);
197*e7776783SApple OSS Distributions }
198*e7776783SApple OSS Distributions
199*e7776783SApple OSS Distributions return error;
200*e7776783SApple OSS Distributions }
201*e7776783SApple OSS Distributions
202*e7776783SApple OSS Distributions int
fdesc_allocvp(fdntype ftype,int ix,struct mount * mp,struct vnode ** vpp,enum vtype vtype,int fdno)203*e7776783SApple OSS Distributions fdesc_allocvp(fdntype ftype, int ix, struct mount *mp, struct vnode **vpp, enum vtype vtype, int fdno)
204*e7776783SApple OSS Distributions {
205*e7776783SApple OSS Distributions struct fdhashhead *fc;
206*e7776783SApple OSS Distributions struct fdescnode *fd;
207*e7776783SApple OSS Distributions int error = 0;
208*e7776783SApple OSS Distributions int vid = 0;
209*e7776783SApple OSS Distributions struct vnode_fsparam vfsp;
210*e7776783SApple OSS Distributions
211*e7776783SApple OSS Distributions fdesc_lock();
212*e7776783SApple OSS Distributions
213*e7776783SApple OSS Distributions fc = FD_NHASH(ix);
214*e7776783SApple OSS Distributions loop:
215*e7776783SApple OSS Distributions for (fd = fc->lh_first; fd != 0; fd = fd->fd_hash.le_next) {
216*e7776783SApple OSS Distributions if (fd->fd_ix == ix && vnode_mount(fd->fd_vnode) == mp) {
217*e7776783SApple OSS Distributions vid = vnode_vid(fd->fd_vnode);
218*e7776783SApple OSS Distributions fdesc_unlock();
219*e7776783SApple OSS Distributions
220*e7776783SApple OSS Distributions if (vnode_getwithvid(fd->fd_vnode, vid)) {
221*e7776783SApple OSS Distributions fdesc_lock();
222*e7776783SApple OSS Distributions goto loop;
223*e7776783SApple OSS Distributions }
224*e7776783SApple OSS Distributions
225*e7776783SApple OSS Distributions *vpp = fd->fd_vnode;
226*e7776783SApple OSS Distributions (*vpp)->v_type = (uint16_t)vtype;
227*e7776783SApple OSS Distributions
228*e7776783SApple OSS Distributions return error;
229*e7776783SApple OSS Distributions }
230*e7776783SApple OSS Distributions }
231*e7776783SApple OSS Distributions
232*e7776783SApple OSS Distributions /* Only one thread can add to the hash at a time */
233*e7776783SApple OSS Distributions if (fdcache_lock & FDL_LOCKED) {
234*e7776783SApple OSS Distributions fdcache_lock |= FDL_WANT;
235*e7776783SApple OSS Distributions msleep((caddr_t) &fdcache_lock, &fdesc_mtx, PINOD, "fdesc_allocvp", NULL);
236*e7776783SApple OSS Distributions goto loop;
237*e7776783SApple OSS Distributions }
238*e7776783SApple OSS Distributions
239*e7776783SApple OSS Distributions fdcache_lock |= FDL_LOCKED;
240*e7776783SApple OSS Distributions fdesc_unlock();
241*e7776783SApple OSS Distributions
242*e7776783SApple OSS Distributions fd = kalloc_type(struct fdescnode, Z_WAITOK);
243*e7776783SApple OSS Distributions
244*e7776783SApple OSS Distributions vfsp.vnfs_mp = mp;
245*e7776783SApple OSS Distributions vfsp.vnfs_vtype = vtype;
246*e7776783SApple OSS Distributions vfsp.vnfs_str = "fdesc";
247*e7776783SApple OSS Distributions vfsp.vnfs_dvp = NULL;
248*e7776783SApple OSS Distributions vfsp.vnfs_fsnode = fd;
249*e7776783SApple OSS Distributions vfsp.vnfs_cnp = NULL;
250*e7776783SApple OSS Distributions vfsp.vnfs_vops = fdesc_vnodeop_p;
251*e7776783SApple OSS Distributions vfsp.vnfs_rdev = 0;
252*e7776783SApple OSS Distributions vfsp.vnfs_filesize = 0;
253*e7776783SApple OSS Distributions vfsp.vnfs_flags = VNFS_NOCACHE | VNFS_CANTCACHE;
254*e7776783SApple OSS Distributions vfsp.vnfs_marksystem = 0;
255*e7776783SApple OSS Distributions vfsp.vnfs_markroot = 0;
256*e7776783SApple OSS Distributions
257*e7776783SApple OSS Distributions error = vnode_create(VNCREATE_FLAVOR, VCREATESIZE, &vfsp, vpp);
258*e7776783SApple OSS Distributions if (error) {
259*e7776783SApple OSS Distributions kfree_type(struct fdescnode, fd);
260*e7776783SApple OSS Distributions fdesc_lock();
261*e7776783SApple OSS Distributions goto out;
262*e7776783SApple OSS Distributions }
263*e7776783SApple OSS Distributions
264*e7776783SApple OSS Distributions (*vpp)->v_tag = VT_FDESC;
265*e7776783SApple OSS Distributions fd->fd_vnode = *vpp;
266*e7776783SApple OSS Distributions fd->fd_type = ftype;
267*e7776783SApple OSS Distributions fd->fd_fd = fdno;
268*e7776783SApple OSS Distributions fd->fd_link = NULL;
269*e7776783SApple OSS Distributions fd->fd_ix = ix;
270*e7776783SApple OSS Distributions
271*e7776783SApple OSS Distributions fdesc_lock();
272*e7776783SApple OSS Distributions
273*e7776783SApple OSS Distributions LIST_INSERT_HEAD(fc, fd, fd_hash);
274*e7776783SApple OSS Distributions out:
275*e7776783SApple OSS Distributions /* Hold the lock when we get here */
276*e7776783SApple OSS Distributions fdcache_lock &= ~FDL_LOCKED;
277*e7776783SApple OSS Distributions
278*e7776783SApple OSS Distributions if (fdcache_lock & FDL_WANT) {
279*e7776783SApple OSS Distributions fdcache_lock &= ~FDL_WANT;
280*e7776783SApple OSS Distributions wakeup((caddr_t) &fdcache_lock);
281*e7776783SApple OSS Distributions }
282*e7776783SApple OSS Distributions
283*e7776783SApple OSS Distributions fdesc_unlock();
284*e7776783SApple OSS Distributions
285*e7776783SApple OSS Distributions return error;
286*e7776783SApple OSS Distributions }
287*e7776783SApple OSS Distributions
288*e7776783SApple OSS Distributions /*
289*e7776783SApple OSS Distributions * vp is the current namei directory
290*e7776783SApple OSS Distributions * ndp is the name to locate in that directory...
291*e7776783SApple OSS Distributions *
292*e7776783SApple OSS Distributions * This vnop should only be called on the special directory /dev/fd.
293*e7776783SApple OSS Distributions */
294*e7776783SApple OSS Distributions int
devfs_devfd_lookup(struct vnop_lookup_args * ap)295*e7776783SApple OSS Distributions devfs_devfd_lookup(struct vnop_lookup_args *ap)
296*e7776783SApple OSS Distributions {
297*e7776783SApple OSS Distributions struct vnode **vpp = ap->a_vpp;
298*e7776783SApple OSS Distributions struct vnode *dvp = ap->a_dvp;
299*e7776783SApple OSS Distributions struct componentname *cnp = ap->a_cnp;
300*e7776783SApple OSS Distributions char *pname = cnp->cn_nameptr;
301*e7776783SApple OSS Distributions struct proc *p = vfs_context_proc(ap->a_context);
302*e7776783SApple OSS Distributions int numfiles = p->p_fd.fd_nfiles;
303*e7776783SApple OSS Distributions int fd;
304*e7776783SApple OSS Distributions int error;
305*e7776783SApple OSS Distributions struct vnode *fvp;
306*e7776783SApple OSS Distributions
307*e7776783SApple OSS Distributions if (cnp->cn_namelen == 1 && *pname == '.') {
308*e7776783SApple OSS Distributions *vpp = dvp;
309*e7776783SApple OSS Distributions
310*e7776783SApple OSS Distributions if ((error = vnode_get(dvp))) {
311*e7776783SApple OSS Distributions goto bad;
312*e7776783SApple OSS Distributions }
313*e7776783SApple OSS Distributions return 0;
314*e7776783SApple OSS Distributions }
315*e7776783SApple OSS Distributions
316*e7776783SApple OSS Distributions fd = 0;
317*e7776783SApple OSS Distributions while (*pname >= '0' && *pname <= '9') {
318*e7776783SApple OSS Distributions if (os_mul_and_add_overflow(fd, 10, *pname++ - '0', &fd)) {
319*e7776783SApple OSS Distributions break;
320*e7776783SApple OSS Distributions }
321*e7776783SApple OSS Distributions }
322*e7776783SApple OSS Distributions
323*e7776783SApple OSS Distributions if (*pname != '\0') {
324*e7776783SApple OSS Distributions error = ENOENT;
325*e7776783SApple OSS Distributions goto bad;
326*e7776783SApple OSS Distributions }
327*e7776783SApple OSS Distributions
328*e7776783SApple OSS Distributions if (fd < 0 || fd >= numfiles ||
329*e7776783SApple OSS Distributions *fdfile(p, fd) == NULL ||
330*e7776783SApple OSS Distributions (*fdflags(p, fd) & UF_RESERVED)) {
331*e7776783SApple OSS Distributions error = EBADF;
332*e7776783SApple OSS Distributions goto bad;
333*e7776783SApple OSS Distributions }
334*e7776783SApple OSS Distributions
335*e7776783SApple OSS Distributions error = fdesc_allocvp(Fdesc, FD_DESC + fd, dvp->v_mount, &fvp, VNON, fd);
336*e7776783SApple OSS Distributions if (error) {
337*e7776783SApple OSS Distributions goto bad;
338*e7776783SApple OSS Distributions }
339*e7776783SApple OSS Distributions *vpp = fvp;
340*e7776783SApple OSS Distributions return 0;
341*e7776783SApple OSS Distributions
342*e7776783SApple OSS Distributions bad:
343*e7776783SApple OSS Distributions *vpp = NULL;
344*e7776783SApple OSS Distributions return error;
345*e7776783SApple OSS Distributions }
346*e7776783SApple OSS Distributions
347*e7776783SApple OSS Distributions int
fdesc_open(struct vnop_open_args * ap)348*e7776783SApple OSS Distributions fdesc_open(struct vnop_open_args *ap)
349*e7776783SApple OSS Distributions {
350*e7776783SApple OSS Distributions struct vnode *vp = ap->a_vp;
351*e7776783SApple OSS Distributions thread_t thr = vfs_context_thread(ap->a_context);
352*e7776783SApple OSS Distributions uthread_t uu;
353*e7776783SApple OSS Distributions int error = 0;
354*e7776783SApple OSS Distributions
355*e7776783SApple OSS Distributions if (thr == NULL) {
356*e7776783SApple OSS Distributions return EINVAL;
357*e7776783SApple OSS Distributions }
358*e7776783SApple OSS Distributions
359*e7776783SApple OSS Distributions uu = get_bsdthread_info(thr);
360*e7776783SApple OSS Distributions
361*e7776783SApple OSS Distributions switch (VTOFDESC(vp)->fd_type) {
362*e7776783SApple OSS Distributions case Fdesc:
363*e7776783SApple OSS Distributions /*
364*e7776783SApple OSS Distributions * XXX Kludge: set uu->uu_dupfd to contain the value of the
365*e7776783SApple OSS Distributions * the file descriptor being sought for duplication. The error
366*e7776783SApple OSS Distributions * return ensures that the vnode for this device will be
367*e7776783SApple OSS Distributions * released by vn_open. Open will detect this special error and
368*e7776783SApple OSS Distributions * take the actions in dupfdopen. Other callers of vn_open or
369*e7776783SApple OSS Distributions * vnop_open will simply report the error.
370*e7776783SApple OSS Distributions */
371*e7776783SApple OSS Distributions uu->uu_dupfd = VTOFDESC(vp)->fd_fd; /* XXX */
372*e7776783SApple OSS Distributions error = ENODEV;
373*e7776783SApple OSS Distributions break;
374*e7776783SApple OSS Distributions default:
375*e7776783SApple OSS Distributions panic("Invalid type for fdesc node!");
376*e7776783SApple OSS Distributions break;
377*e7776783SApple OSS Distributions }
378*e7776783SApple OSS Distributions
379*e7776783SApple OSS Distributions return error;
380*e7776783SApple OSS Distributions }
381*e7776783SApple OSS Distributions
382*e7776783SApple OSS Distributions static int
fdesc_attr(int fd,struct vnode_attr * vap,vfs_context_t a_context)383*e7776783SApple OSS Distributions fdesc_attr(int fd, struct vnode_attr *vap, vfs_context_t a_context)
384*e7776783SApple OSS Distributions {
385*e7776783SApple OSS Distributions struct fileproc *fp;
386*e7776783SApple OSS Distributions struct proc *p = vfs_context_proc(a_context);
387*e7776783SApple OSS Distributions struct stat stb;
388*e7776783SApple OSS Distributions int error;
389*e7776783SApple OSS Distributions
390*e7776783SApple OSS Distributions if ((error = fp_lookup(p, fd, &fp, 0))) {
391*e7776783SApple OSS Distributions return error;
392*e7776783SApple OSS Distributions }
393*e7776783SApple OSS Distributions switch (FILEGLOB_DTYPE(fp->fp_glob)) {
394*e7776783SApple OSS Distributions case DTYPE_VNODE:
395*e7776783SApple OSS Distributions if ((error = vnode_getwithref((struct vnode *)fp_get_data(fp))) != 0) {
396*e7776783SApple OSS Distributions break;
397*e7776783SApple OSS Distributions }
398*e7776783SApple OSS Distributions if ((error = vnode_authorize((struct vnode *)fp_get_data(fp),
399*e7776783SApple OSS Distributions NULL,
400*e7776783SApple OSS Distributions KAUTH_VNODE_READ_ATTRIBUTES | KAUTH_VNODE_READ_SECURITY,
401*e7776783SApple OSS Distributions a_context)) == 0) {
402*e7776783SApple OSS Distributions error = vnode_getattr((struct vnode *)fp_get_data(fp), vap, a_context);
403*e7776783SApple OSS Distributions }
404*e7776783SApple OSS Distributions if (error == 0 && vap->va_type == VDIR) {
405*e7776783SApple OSS Distributions /*
406*e7776783SApple OSS Distributions * directories can cause loops in the namespace,
407*e7776783SApple OSS Distributions * so turn off the 'x' bits to avoid trouble.
408*e7776783SApple OSS Distributions *
409*e7776783SApple OSS Distributions * XXX ACLs break this, of course
410*e7776783SApple OSS Distributions */
411*e7776783SApple OSS Distributions vap->va_mode &= ~((VEXEC) | (VEXEC >> 3) | (VEXEC >> 6));
412*e7776783SApple OSS Distributions }
413*e7776783SApple OSS Distributions (void)vnode_put((struct vnode *)fp_get_data(fp));
414*e7776783SApple OSS Distributions break;
415*e7776783SApple OSS Distributions
416*e7776783SApple OSS Distributions case DTYPE_SOCKET:
417*e7776783SApple OSS Distributions case DTYPE_PIPE:
418*e7776783SApple OSS Distributions #if SOCKETS
419*e7776783SApple OSS Distributions if (FILEGLOB_DTYPE(fp->fp_glob) == DTYPE_SOCKET) {
420*e7776783SApple OSS Distributions error = soo_stat((struct socket *)fp_get_data(fp), (void *)&stb, 0);
421*e7776783SApple OSS Distributions } else
422*e7776783SApple OSS Distributions #endif /* SOCKETS */
423*e7776783SApple OSS Distributions error = pipe_stat((struct pipe *)fp_get_data(fp), (void *)&stb, 0);
424*e7776783SApple OSS Distributions
425*e7776783SApple OSS Distributions if (error == 0) {
426*e7776783SApple OSS Distributions if (FILEGLOB_DTYPE(fp->fp_glob) == DTYPE_SOCKET) {
427*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_type, VSOCK);
428*e7776783SApple OSS Distributions } else {
429*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_type, VFIFO);
430*e7776783SApple OSS Distributions }
431*e7776783SApple OSS Distributions
432*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_mode, stb.st_mode);
433*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_nlink, stb.st_nlink);
434*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_uid, stb.st_uid);
435*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_gid, stb.st_gid);
436*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_fsid, stb.st_dev);
437*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_fileid, stb.st_ino);
438*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_data_size, stb.st_size);
439*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_access_time, stb.st_atimespec);
440*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_modify_time, stb.st_mtimespec);
441*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_change_time, stb.st_ctimespec);
442*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_gen, stb.st_gen);
443*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_flags, stb.st_flags);
444*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_rdev, stb.st_rdev);
445*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_total_alloc, stb.st_blocks * stb.st_blksize);
446*e7776783SApple OSS Distributions VATTR_RETURN(vap, va_acl, NULL);
447*e7776783SApple OSS Distributions }
448*e7776783SApple OSS Distributions break;
449*e7776783SApple OSS Distributions
450*e7776783SApple OSS Distributions default:
451*e7776783SApple OSS Distributions error = EBADF;
452*e7776783SApple OSS Distributions }
453*e7776783SApple OSS Distributions
454*e7776783SApple OSS Distributions fp_drop(p, fd, fp, 0);
455*e7776783SApple OSS Distributions return error;
456*e7776783SApple OSS Distributions }
457*e7776783SApple OSS Distributions
458*e7776783SApple OSS Distributions int
fdesc_getattr(struct vnop_getattr_args * ap)459*e7776783SApple OSS Distributions fdesc_getattr(struct vnop_getattr_args *ap)
460*e7776783SApple OSS Distributions {
461*e7776783SApple OSS Distributions struct vnode *vp = ap->a_vp;
462*e7776783SApple OSS Distributions struct vnode_attr *vap = ap->a_vap;
463*e7776783SApple OSS Distributions unsigned fd;
464*e7776783SApple OSS Distributions int error = 0;
465*e7776783SApple OSS Distributions
466*e7776783SApple OSS Distributions switch (VTOFDESC(vp)->fd_type) {
467*e7776783SApple OSS Distributions case Fdesc:
468*e7776783SApple OSS Distributions fd = VTOFDESC(vp)->fd_fd;
469*e7776783SApple OSS Distributions error = fdesc_attr(fd, vap, ap->a_context);
470*e7776783SApple OSS Distributions break;
471*e7776783SApple OSS Distributions
472*e7776783SApple OSS Distributions default:
473*e7776783SApple OSS Distributions panic("Invalid type for an fdesc node!");
474*e7776783SApple OSS Distributions break;
475*e7776783SApple OSS Distributions }
476*e7776783SApple OSS Distributions
477*e7776783SApple OSS Distributions /*
478*e7776783SApple OSS Distributions * Yes, we do this without locking, but this value is always just
479*e7776783SApple OSS Distributions * a snapshot.
480*e7776783SApple OSS Distributions */
481*e7776783SApple OSS Distributions if (error == 0) {
482*e7776783SApple OSS Distributions vp->v_type = (uint16_t)vap->va_type;
483*e7776783SApple OSS Distributions
484*e7776783SApple OSS Distributions /* We need an inactive to reset type to VNON */
485*e7776783SApple OSS Distributions vnode_setneedinactive(vp);
486*e7776783SApple OSS Distributions }
487*e7776783SApple OSS Distributions
488*e7776783SApple OSS Distributions return error;
489*e7776783SApple OSS Distributions }
490*e7776783SApple OSS Distributions
491*e7776783SApple OSS Distributions int
fdesc_setattr(struct vnop_setattr_args * ap)492*e7776783SApple OSS Distributions fdesc_setattr(struct vnop_setattr_args *ap)
493*e7776783SApple OSS Distributions {
494*e7776783SApple OSS Distributions struct fileproc *fp;
495*e7776783SApple OSS Distributions unsigned fd;
496*e7776783SApple OSS Distributions int error;
497*e7776783SApple OSS Distributions struct proc * p = vfs_context_proc(ap->a_context);
498*e7776783SApple OSS Distributions
499*e7776783SApple OSS Distributions /*
500*e7776783SApple OSS Distributions * Can't mess with the root vnode
501*e7776783SApple OSS Distributions */
502*e7776783SApple OSS Distributions switch (VTOFDESC(ap->a_vp)->fd_type) {
503*e7776783SApple OSS Distributions case Fdesc:
504*e7776783SApple OSS Distributions break;
505*e7776783SApple OSS Distributions default:
506*e7776783SApple OSS Distributions panic("Invalid type for an fdesc node!");
507*e7776783SApple OSS Distributions return EACCES;
508*e7776783SApple OSS Distributions }
509*e7776783SApple OSS Distributions
510*e7776783SApple OSS Distributions fd = VTOFDESC(ap->a_vp)->fd_fd;
511*e7776783SApple OSS Distributions if ((error = fp_lookup(vfs_context_proc(ap->a_context), fd, &fp, 0))) {
512*e7776783SApple OSS Distributions return error;
513*e7776783SApple OSS Distributions }
514*e7776783SApple OSS Distributions
515*e7776783SApple OSS Distributions /*
516*e7776783SApple OSS Distributions * Can setattr the underlying vnode, but not sockets!
517*e7776783SApple OSS Distributions */
518*e7776783SApple OSS Distributions switch (FILEGLOB_DTYPE(fp->fp_glob)) {
519*e7776783SApple OSS Distributions case DTYPE_VNODE:
520*e7776783SApple OSS Distributions {
521*e7776783SApple OSS Distributions if ((error = vnode_getwithref((struct vnode *)fp_get_data(fp))) != 0) {
522*e7776783SApple OSS Distributions break;
523*e7776783SApple OSS Distributions }
524*e7776783SApple OSS Distributions error = vnode_setattr((struct vnode *)fp_get_data(fp), ap->a_vap, ap->a_context);
525*e7776783SApple OSS Distributions (void)vnode_put((struct vnode *)fp_get_data(fp));
526*e7776783SApple OSS Distributions break;
527*e7776783SApple OSS Distributions }
528*e7776783SApple OSS Distributions
529*e7776783SApple OSS Distributions case DTYPE_SOCKET:
530*e7776783SApple OSS Distributions case DTYPE_PIPE:
531*e7776783SApple OSS Distributions error = 0;
532*e7776783SApple OSS Distributions break;
533*e7776783SApple OSS Distributions
534*e7776783SApple OSS Distributions default:
535*e7776783SApple OSS Distributions error = EBADF;
536*e7776783SApple OSS Distributions break;
537*e7776783SApple OSS Distributions }
538*e7776783SApple OSS Distributions
539*e7776783SApple OSS Distributions fp_drop(p, fd, fp, 0);
540*e7776783SApple OSS Distributions return error;
541*e7776783SApple OSS Distributions }
542*e7776783SApple OSS Distributions
543*e7776783SApple OSS Distributions #define UIO_MX 16
544*e7776783SApple OSS Distributions
545*e7776783SApple OSS Distributions /*
546*e7776783SApple OSS Distributions * static struct dirtmp {
547*e7776783SApple OSS Distributions * u_int32_t d_fileno;
548*e7776783SApple OSS Distributions * u_short d_reclen;
549*e7776783SApple OSS Distributions * u_short d_namlen;
550*e7776783SApple OSS Distributions * char d_name[8];
551*e7776783SApple OSS Distributions * } rootent[] = {
552*e7776783SApple OSS Distributions * { FD_DEVFD, UIO_MX, 2, "fd" },
553*e7776783SApple OSS Distributions * { FD_STDIN, UIO_MX, 5, "stdin" },
554*e7776783SApple OSS Distributions * { FD_STDOUT, UIO_MX, 6, "stdout" },
555*e7776783SApple OSS Distributions * { FD_STDERR, UIO_MX, 6, "stderr" },
556*e7776783SApple OSS Distributions * { 0, 0, 0, "" }
557*e7776783SApple OSS Distributions * };
558*e7776783SApple OSS Distributions */
559*e7776783SApple OSS Distributions
560*e7776783SApple OSS Distributions /* Only called on /dev/fd */
561*e7776783SApple OSS Distributions int
devfs_devfd_readdir(struct vnop_readdir_args * ap)562*e7776783SApple OSS Distributions devfs_devfd_readdir(struct vnop_readdir_args *ap)
563*e7776783SApple OSS Distributions {
564*e7776783SApple OSS Distributions struct uio *uio = ap->a_uio;
565*e7776783SApple OSS Distributions struct proc *p = current_proc();
566*e7776783SApple OSS Distributions off_t i;
567*e7776783SApple OSS Distributions int error;
568*e7776783SApple OSS Distributions
569*e7776783SApple OSS Distributions /*
570*e7776783SApple OSS Distributions * We don't allow exporting fdesc mounts, and currently local
571*e7776783SApple OSS Distributions * requests do not need cookies.
572*e7776783SApple OSS Distributions */
573*e7776783SApple OSS Distributions if (ap->a_flags & (VNODE_READDIR_EXTENDED | VNODE_READDIR_REQSEEKOFF)) {
574*e7776783SApple OSS Distributions return EINVAL;
575*e7776783SApple OSS Distributions }
576*e7776783SApple OSS Distributions
577*e7776783SApple OSS Distributions /*
578*e7776783SApple OSS Distributions * There needs to be space for at least one entry.
579*e7776783SApple OSS Distributions */
580*e7776783SApple OSS Distributions if (uio_resid(uio) < UIO_MX) {
581*e7776783SApple OSS Distributions return EINVAL;
582*e7776783SApple OSS Distributions }
583*e7776783SApple OSS Distributions
584*e7776783SApple OSS Distributions i = uio->uio_offset / UIO_MX;
585*e7776783SApple OSS Distributions error = 0;
586*e7776783SApple OSS Distributions while (uio_resid(uio) >= UIO_MX) {
587*e7776783SApple OSS Distributions if (i >= p->p_fd.fd_nfiles || i < 0) {
588*e7776783SApple OSS Distributions break;
589*e7776783SApple OSS Distributions }
590*e7776783SApple OSS Distributions
591*e7776783SApple OSS Distributions if (*fdfile(p, i) != NULL && !(*fdflags(p, i) & UF_RESERVED)) {
592*e7776783SApple OSS Distributions struct dirent d;
593*e7776783SApple OSS Distributions struct dirent *dp = &d;
594*e7776783SApple OSS Distributions
595*e7776783SApple OSS Distributions bzero((caddr_t) dp, UIO_MX);
596*e7776783SApple OSS Distributions
597*e7776783SApple OSS Distributions dp->d_namlen = (__uint8_t)scnprintf(dp->d_name, sizeof(dp->d_name),
598*e7776783SApple OSS Distributions "%lld", i);
599*e7776783SApple OSS Distributions dp->d_reclen = UIO_MX;
600*e7776783SApple OSS Distributions dp->d_type = DT_UNKNOWN;
601*e7776783SApple OSS Distributions dp->d_fileno = (ino_t)i + FD_STDIN;
602*e7776783SApple OSS Distributions /*
603*e7776783SApple OSS Distributions * And ship to userland
604*e7776783SApple OSS Distributions */
605*e7776783SApple OSS Distributions error = uiomove((caddr_t) dp, UIO_MX, uio);
606*e7776783SApple OSS Distributions if (error) {
607*e7776783SApple OSS Distributions break;
608*e7776783SApple OSS Distributions }
609*e7776783SApple OSS Distributions }
610*e7776783SApple OSS Distributions i++;
611*e7776783SApple OSS Distributions }
612*e7776783SApple OSS Distributions
613*e7776783SApple OSS Distributions uio->uio_offset = i * UIO_MX;
614*e7776783SApple OSS Distributions return error;
615*e7776783SApple OSS Distributions }
616*e7776783SApple OSS Distributions
617*e7776783SApple OSS Distributions int
fdesc_read(__unused struct vnop_read_args * ap)618*e7776783SApple OSS Distributions fdesc_read(__unused struct vnop_read_args *ap)
619*e7776783SApple OSS Distributions {
620*e7776783SApple OSS Distributions return ENOTSUP;
621*e7776783SApple OSS Distributions }
622*e7776783SApple OSS Distributions
623*e7776783SApple OSS Distributions int
fdesc_write(__unused struct vnop_write_args * ap)624*e7776783SApple OSS Distributions fdesc_write(__unused struct vnop_write_args *ap)
625*e7776783SApple OSS Distributions {
626*e7776783SApple OSS Distributions return ENOTSUP;
627*e7776783SApple OSS Distributions }
628*e7776783SApple OSS Distributions
629*e7776783SApple OSS Distributions int
fdesc_ioctl(__unused struct vnop_ioctl_args * ap)630*e7776783SApple OSS Distributions fdesc_ioctl(__unused struct vnop_ioctl_args *ap)
631*e7776783SApple OSS Distributions {
632*e7776783SApple OSS Distributions return ENOTSUP;
633*e7776783SApple OSS Distributions }
634*e7776783SApple OSS Distributions
635*e7776783SApple OSS Distributions int
fdesc_select(__unused struct vnop_select_args * ap)636*e7776783SApple OSS Distributions fdesc_select(__unused struct vnop_select_args *ap)
637*e7776783SApple OSS Distributions {
638*e7776783SApple OSS Distributions return ENOTSUP;
639*e7776783SApple OSS Distributions }
640*e7776783SApple OSS Distributions
641*e7776783SApple OSS Distributions int
fdesc_inactive(struct vnop_inactive_args * ap)642*e7776783SApple OSS Distributions fdesc_inactive(struct vnop_inactive_args *ap)
643*e7776783SApple OSS Distributions {
644*e7776783SApple OSS Distributions struct vnode *vp = ap->a_vp;
645*e7776783SApple OSS Distributions
646*e7776783SApple OSS Distributions /*
647*e7776783SApple OSS Distributions * Clear out the v_type field to avoid
648*e7776783SApple OSS Distributions * nasty things happening in vgone().
649*e7776783SApple OSS Distributions */
650*e7776783SApple OSS Distributions vp->v_type = VNON;
651*e7776783SApple OSS Distributions
652*e7776783SApple OSS Distributions return 0;
653*e7776783SApple OSS Distributions }
654*e7776783SApple OSS Distributions
655*e7776783SApple OSS Distributions int
fdesc_reclaim(struct vnop_reclaim_args * ap)656*e7776783SApple OSS Distributions fdesc_reclaim(struct vnop_reclaim_args *ap)
657*e7776783SApple OSS Distributions {
658*e7776783SApple OSS Distributions struct vnode *vp = ap->a_vp;
659*e7776783SApple OSS Distributions struct fdescnode *fd = VTOFDESC(vp);
660*e7776783SApple OSS Distributions
661*e7776783SApple OSS Distributions fdesc_lock();
662*e7776783SApple OSS Distributions
663*e7776783SApple OSS Distributions LIST_REMOVE(fd, fd_hash);
664*e7776783SApple OSS Distributions kfree_type(struct fdescnode, vp->v_data);
665*e7776783SApple OSS Distributions
666*e7776783SApple OSS Distributions fdesc_unlock();
667*e7776783SApple OSS Distributions
668*e7776783SApple OSS Distributions return 0;
669*e7776783SApple OSS Distributions }
670*e7776783SApple OSS Distributions
671*e7776783SApple OSS Distributions /*
672*e7776783SApple OSS Distributions * Return POSIX pathconf information applicable to special devices.
673*e7776783SApple OSS Distributions */
674*e7776783SApple OSS Distributions int
fdesc_pathconf(struct vnop_pathconf_args * ap)675*e7776783SApple OSS Distributions fdesc_pathconf(struct vnop_pathconf_args *ap)
676*e7776783SApple OSS Distributions {
677*e7776783SApple OSS Distributions switch (ap->a_name) {
678*e7776783SApple OSS Distributions case _PC_LINK_MAX:
679*e7776783SApple OSS Distributions *ap->a_retval = LINK_MAX;
680*e7776783SApple OSS Distributions return 0;
681*e7776783SApple OSS Distributions case _PC_MAX_CANON:
682*e7776783SApple OSS Distributions *ap->a_retval = MAX_CANON;
683*e7776783SApple OSS Distributions return 0;
684*e7776783SApple OSS Distributions case _PC_MAX_INPUT:
685*e7776783SApple OSS Distributions *ap->a_retval = MAX_INPUT;
686*e7776783SApple OSS Distributions return 0;
687*e7776783SApple OSS Distributions case _PC_PIPE_BUF:
688*e7776783SApple OSS Distributions *ap->a_retval = PIPE_BUF;
689*e7776783SApple OSS Distributions return 0;
690*e7776783SApple OSS Distributions case _PC_CHOWN_RESTRICTED:
691*e7776783SApple OSS Distributions *ap->a_retval = 200112; /* _POSIX_CHOWN_RESTRICTED */
692*e7776783SApple OSS Distributions return 0;
693*e7776783SApple OSS Distributions case _PC_VDISABLE:
694*e7776783SApple OSS Distributions *ap->a_retval = _POSIX_VDISABLE;
695*e7776783SApple OSS Distributions return 0;
696*e7776783SApple OSS Distributions default:
697*e7776783SApple OSS Distributions return EINVAL;
698*e7776783SApple OSS Distributions }
699*e7776783SApple OSS Distributions /* NOTREACHED */
700*e7776783SApple OSS Distributions }
701*e7776783SApple OSS Distributions
702*e7776783SApple OSS Distributions /*
703*e7776783SApple OSS Distributions * /dev/fd "should never get here" operation
704*e7776783SApple OSS Distributions */
705*e7776783SApple OSS Distributions int
fdesc_badop(void)706*e7776783SApple OSS Distributions fdesc_badop(void)
707*e7776783SApple OSS Distributions {
708*e7776783SApple OSS Distributions return ENOTSUP;
709*e7776783SApple OSS Distributions /* NOTREACHED */
710*e7776783SApple OSS Distributions }
711*e7776783SApple OSS Distributions
712*e7776783SApple OSS Distributions #define VOPFUNC int (*)(void *)
713*e7776783SApple OSS Distributions
714*e7776783SApple OSS Distributions #define fdesc_create (int (*) (struct vnop_create_args *))eopnotsupp
715*e7776783SApple OSS Distributions #define fdesc_mknod (int (*) (struct vnop_mknod_args *))eopnotsupp
716*e7776783SApple OSS Distributions #define fdesc_close (int (*) (struct vnop_close_args *))nullop
717*e7776783SApple OSS Distributions #define fdesc_access (int (*) (struct vnop_access_args *))nullop
718*e7776783SApple OSS Distributions #define fdesc_mmap (int (*) (struct vnop_mmap_args *))eopnotsupp
719*e7776783SApple OSS Distributions #define fdesc_revoke nop_revoke
720*e7776783SApple OSS Distributions #define fdesc_fsync (int (*) (struct vnop_fsync_args *))nullop
721*e7776783SApple OSS Distributions #define fdesc_remove (int (*) (struct vnop_remove_args *))eopnotsupp
722*e7776783SApple OSS Distributions #define fdesc_link (int (*) (struct vnop_link_args *))eopnotsupp
723*e7776783SApple OSS Distributions #define fdesc_rename (int (*) (struct vnop_rename_args *))eopnotsupp
724*e7776783SApple OSS Distributions #define fdesc_mkdir (int (*) (struct vnop_mkdir_args *))eopnotsupp
725*e7776783SApple OSS Distributions #define fdesc_rmdir (int (*) (struct vnop_rmdir_args *))eopnotsupp
726*e7776783SApple OSS Distributions #define fdesc_symlink (int (*) (struct vnop_symlink_args *))eopnotsupp
727*e7776783SApple OSS Distributions #define fdesc_strategy (int (*) (struct vnop_strategy_args *))fdesc_badop
728*e7776783SApple OSS Distributions #define fdesc_advlock (int (*) (struct vnop_advlock_args *))eopnotsupp
729*e7776783SApple OSS Distributions #define fdesc_bwrite (int (*) (struct vnop_bwrite_args *))eopnotsupp
730*e7776783SApple OSS Distributions #define fdesc_blktooff (int (*) (struct vnop_blktooff_args *))eopnotsupp
731*e7776783SApple OSS Distributions #define fdesc_offtoblk (int (*) (struct vnop_offtoblk_args *))eopnotsupp
732*e7776783SApple OSS Distributions #define fdesc_blockmap (int (*) (struct vnop_blockmap_args *))eopnotsupp
733*e7776783SApple OSS Distributions
734*e7776783SApple OSS Distributions int(**fdesc_vnodeop_p)(void *);
735*e7776783SApple OSS Distributions const struct vnodeopv_entry_desc devfs_fdesc_vnodeop_entries[] = {
736*e7776783SApple OSS Distributions { .opve_op = &vnop_default_desc, .opve_impl = (VOPFUNC)vn_default_error },
737*e7776783SApple OSS Distributions { .opve_op = &vnop_lookup_desc, .opve_impl = (VOPFUNC)vn_default_error}, /* lookup */
738*e7776783SApple OSS Distributions { .opve_op = &vnop_create_desc, .opve_impl = (VOPFUNC)fdesc_create }, /* create */
739*e7776783SApple OSS Distributions { .opve_op = &vnop_mknod_desc, .opve_impl = (VOPFUNC)fdesc_mknod }, /* mknod */
740*e7776783SApple OSS Distributions { .opve_op = &vnop_open_desc, .opve_impl = (VOPFUNC)fdesc_open }, /* open */
741*e7776783SApple OSS Distributions { .opve_op = &vnop_close_desc, .opve_impl = (VOPFUNC)fdesc_close }, /* close */
742*e7776783SApple OSS Distributions { .opve_op = &vnop_access_desc, .opve_impl = (VOPFUNC)fdesc_access }, /* access */
743*e7776783SApple OSS Distributions { .opve_op = &vnop_getattr_desc, .opve_impl = (VOPFUNC)fdesc_getattr }, /* getattr */
744*e7776783SApple OSS Distributions { .opve_op = &vnop_setattr_desc, .opve_impl = (VOPFUNC)fdesc_setattr }, /* setattr */
745*e7776783SApple OSS Distributions { .opve_op = &vnop_read_desc, .opve_impl = (VOPFUNC)fdesc_read }, /* read */
746*e7776783SApple OSS Distributions { .opve_op = &vnop_write_desc, .opve_impl = (VOPFUNC)fdesc_write }, /* write */
747*e7776783SApple OSS Distributions { .opve_op = &vnop_ioctl_desc, .opve_impl = (VOPFUNC)fdesc_ioctl }, /* ioctl */
748*e7776783SApple OSS Distributions { .opve_op = &vnop_select_desc, .opve_impl = (VOPFUNC)fdesc_select }, /* select */
749*e7776783SApple OSS Distributions { .opve_op = &vnop_revoke_desc, .opve_impl = (VOPFUNC)fdesc_revoke }, /* revoke */
750*e7776783SApple OSS Distributions { .opve_op = &vnop_mmap_desc, .opve_impl = (VOPFUNC)fdesc_mmap }, /* mmap */
751*e7776783SApple OSS Distributions { .opve_op = &vnop_fsync_desc, .opve_impl = (VOPFUNC)fdesc_fsync }, /* fsync */
752*e7776783SApple OSS Distributions { .opve_op = &vnop_remove_desc, .opve_impl = (VOPFUNC)fdesc_remove }, /* remove */
753*e7776783SApple OSS Distributions { .opve_op = &vnop_link_desc, .opve_impl = (VOPFUNC)fdesc_link }, /* link */
754*e7776783SApple OSS Distributions { .opve_op = &vnop_rename_desc, .opve_impl = (VOPFUNC)fdesc_rename }, /* rename */
755*e7776783SApple OSS Distributions { .opve_op = &vnop_mkdir_desc, .opve_impl = (VOPFUNC)fdesc_mkdir }, /* mkdir */
756*e7776783SApple OSS Distributions { .opve_op = &vnop_rmdir_desc, .opve_impl = (VOPFUNC)fdesc_rmdir }, /* rmdir */
757*e7776783SApple OSS Distributions { .opve_op = &vnop_symlink_desc, .opve_impl = (VOPFUNC)fdesc_symlink }, /* symlink */
758*e7776783SApple OSS Distributions { .opve_op = &vnop_readdir_desc, .opve_impl = (VOPFUNC)vn_default_error},/* readdir */
759*e7776783SApple OSS Distributions { .opve_op = &vnop_readlink_desc, .opve_impl = (VOPFUNC)err_readlink}, /* readlink */
760*e7776783SApple OSS Distributions { .opve_op = &vnop_inactive_desc, .opve_impl = (VOPFUNC)fdesc_inactive },/* inactive */
761*e7776783SApple OSS Distributions { .opve_op = &vnop_reclaim_desc, .opve_impl = (VOPFUNC)fdesc_reclaim }, /* reclaim */
762*e7776783SApple OSS Distributions { .opve_op = &vnop_strategy_desc, .opve_impl = (VOPFUNC)fdesc_strategy }, /* strategy */
763*e7776783SApple OSS Distributions { .opve_op = &vnop_pathconf_desc, .opve_impl = (VOPFUNC)fdesc_pathconf }, /* pathconf */
764*e7776783SApple OSS Distributions { .opve_op = &vnop_advlock_desc, .opve_impl = (VOPFUNC)fdesc_advlock }, /* advlock */
765*e7776783SApple OSS Distributions { .opve_op = &vnop_bwrite_desc, .opve_impl = (VOPFUNC)fdesc_bwrite }, /* bwrite */
766*e7776783SApple OSS Distributions { .opve_op = &vnop_pagein_desc, .opve_impl = (VOPFUNC)err_pagein }, /* pagein */
767*e7776783SApple OSS Distributions { .opve_op = &vnop_pageout_desc, .opve_impl = (VOPFUNC)err_pageout }, /* pageout */
768*e7776783SApple OSS Distributions { .opve_op = &vnop_copyfile_desc, .opve_impl = (VOPFUNC)err_copyfile }, /* Copyfile */
769*e7776783SApple OSS Distributions { .opve_op = &vnop_blktooff_desc, .opve_impl = (VOPFUNC)fdesc_blktooff }, /* blktooff */
770*e7776783SApple OSS Distributions { .opve_op = &vnop_blktooff_desc, .opve_impl = (VOPFUNC)fdesc_offtoblk }, /* offtoblk */
771*e7776783SApple OSS Distributions { .opve_op = &vnop_blockmap_desc, .opve_impl = (VOPFUNC)fdesc_blockmap }, /* blockmap */
772*e7776783SApple OSS Distributions { .opve_op = (struct vnodeop_desc*)NULL, .opve_impl = (VOPFUNC)NULL }
773*e7776783SApple OSS Distributions };
774*e7776783SApple OSS Distributions
775*e7776783SApple OSS Distributions const struct vnodeopv_desc devfs_fdesc_vnodeop_opv_desc =
776*e7776783SApple OSS Distributions { .opv_desc_vector_p = &fdesc_vnodeop_p, .opv_desc_ops = devfs_fdesc_vnodeop_entries };
777