]> git.saurik.com Git - apple/xnu.git/blob - bsd/miscfs/devfs/devfs_vnops.c
d9aedf798df57c93e32d49946810b4e01c335bb7
[apple/xnu.git] / bsd / miscfs / devfs / devfs_vnops.c
1 /*
2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * Copyright 1997,1998 Julian Elischer. All rights reserved.
30 * julian@freebsd.org
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions are
34 * met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright notice,
38 * this list of conditions and the following disclaimer in the documentation
39 * and/or other materials provided with the distribution.
40 *
41 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS
42 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
43 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44 * DISCLAIMED. IN NO EVENT SHALL THE HOLDER OR CONTRIBUTORS BE LIABLE FOR
45 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
47 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
48 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * devfs_vnops.c
54 */
55
56 /*
57 * HISTORY
58 * Clark Warner (warner_c@apple.com) Tue Feb 10 2000
59 * - Added err_copyfile to the vnode operations table
60 * Dieter Siegmund (dieter@apple.com) Thu Apr 8 14:08:19 PDT 1999
61 * - instead of duplicating specfs here, created a vnode-ops table
62 * that redirects most operations to specfs (as is done with ufs);
63 * - removed routines that made no sense
64 * - cleaned up reclaim: replaced devfs_vntodn() with a macro VTODN()
65 * - cleaned up symlink, link locking
66 * - added the devfs_lock to protect devfs data structures against
67 * driver's calling devfs_add_devswf()/etc.
68 * Dieter Siegmund (dieter@apple.com) Wed Jul 14 13:37:59 PDT 1999
69 * - free the devfs devnode in devfs_inactive(), not just in devfs_reclaim()
70 * to free up kernel memory as soon as it's available
71 * - got rid of devfsspec_{read, write}
72 * Dieter Siegmund (dieter@apple.com) Fri Sep 17 09:58:38 PDT 1999
73 * - update the mod/access times
74 */
75 /*
76 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
77 * support for mandatory and extensible security protections. This notice
78 * is included in support of clause 2.2 (b) of the Apple Public License,
79 * Version 2.0.
80 */
81
82 #include <sys/param.h>
83 #include <sys/systm.h>
84 #include <sys/namei.h>
85 #include <sys/kernel.h>
86 #include <sys/fcntl.h>
87 #include <sys/conf.h>
88 #include <sys/disklabel.h>
89 #include <sys/lock.h>
90 #include <sys/stat.h>
91 #include <sys/mount_internal.h>
92 #include <sys/proc.h>
93 #include <sys/kauth.h>
94 #include <sys/time.h>
95 #include <sys/vnode_internal.h>
96 #include <miscfs/specfs/specdev.h>
97 #include <sys/dirent.h>
98 #include <sys/vmmeter.h>
99 #include <sys/vm.h>
100 #include <sys/uio_internal.h>
101
102 #if CONFIG_MACF
103 #include <security/mac_framework.h>
104 #endif
105
106 #include "devfsdefs.h"
107
108 static int devfs_update(struct vnode *vp, struct timeval *access,
109 struct timeval *modify);
110
111
112 /*
113 * Convert a component of a pathname into a pointer to a locked node.
114 * This is a very central and rather complicated routine.
115 * If the file system is not maintained in a strict tree hierarchy,
116 * this can result in a deadlock situation (see comments in code below).
117 *
118 * The flag argument is LOOKUP, CREATE, RENAME, or DELETE depending on
119 * whether the name is to be looked up, created, renamed, or deleted.
120 * When CREATE, RENAME, or DELETE is specified, information usable in
121 * creating, renaming, or deleting a directory entry may be calculated.
122 * If flag has LOCKPARENT or'ed into it and the target of the pathname
123 * exists, lookup returns both the target and its parent directory locked.
124 * When creating or renaming and LOCKPARENT is specified, the target may
125 * not be ".". When deleting and LOCKPARENT is specified, the target may
126 * be "."., but the caller must check to ensure it does an vrele and DNUNLOCK
127 * instead of two DNUNLOCKs.
128 *
129 * Overall outline of devfs_lookup:
130 *
131 * check accessibility of directory
132 * null terminate the component (lookup leaves the whole string alone)
133 * look for name in cache, if found, then if at end of path
134 * and deleting or creating, drop it, else return name
135 * search for name in directory, to found or notfound
136 * notfound:
137 * if creating, return locked directory,
138 * else return error
139 * found:
140 * if at end of path and deleting, return information to allow delete
141 * if at end of path and rewriting (RENAME and LOCKPARENT), lock target
142 * node and return info to allow rewrite
143 * if not at end, add name to cache; if at end and neither creating
144 * nor deleting, add name to cache
145 * On return to lookup, remove the null termination we put in at the start.
146 *
147 * NOTE: (LOOKUP | LOCKPARENT) currently returns the parent node unlocked.
148 */
149 static int
150 devfs_lookup(struct vnop_lookup_args *ap)
151 /*struct vnop_lookup_args {
152 struct vnode * a_dvp; directory vnode ptr
153 struct vnode ** a_vpp; where to put the result
154 struct componentname * a_cnp; the name we want
155 vfs_context_t a_context;
156 };*/
157 {
158 struct componentname *cnp = ap->a_cnp;
159 vfs_context_t ctx = cnp->cn_context;
160 struct proc *p = vfs_context_proc(ctx);
161 struct vnode *dir_vnode = ap->a_dvp;
162 struct vnode **result_vnode = ap->a_vpp;
163 devnode_t * dir_node; /* the directory we are searching */
164 devnode_t * node = NULL; /* the node we are searching for */
165 devdirent_t * nodename;
166 int flags = cnp->cn_flags;
167 int op = cnp->cn_nameiop; /* LOOKUP, CREATE, RENAME, or DELETE */
168 int wantparent = flags & (LOCKPARENT|WANTPARENT);
169 int error = 0;
170 char heldchar; /* the char at the end of the name componet */
171
172 retry:
173
174 *result_vnode = NULL; /* safe not sorry */ /*XXX*/
175
176 /* okay to look at directory vnodes ourside devfs lock as they are not aliased */
177 dir_node = VTODN(dir_vnode);
178
179 /*
180 * Make sure that our node is a directory as well.
181 */
182 if (dir_node->dn_type != DEV_DIR) {
183 return (ENOTDIR);
184 }
185
186 DEVFS_LOCK();
187 /*
188 * temporarily terminate string component
189 */
190 heldchar = cnp->cn_nameptr[cnp->cn_namelen];
191 cnp->cn_nameptr[cnp->cn_namelen] = '\0';
192
193 nodename = dev_findname(dir_node, cnp->cn_nameptr);
194 /*
195 * restore saved character
196 */
197 cnp->cn_nameptr[cnp->cn_namelen] = heldchar;
198
199 if (nodename) {
200 /* entry exists */
201 node = nodename->de_dnp;
202
203 /* Do potential vnode allocation here inside the lock
204 * to make sure that our device node has a non-NULL dn_vn
205 * associated with it. The device node might otherwise
206 * get deleted out from under us (see devfs_dn_free()).
207 */
208 error = devfs_dntovn(node, result_vnode, p);
209 }
210 DEVFS_UNLOCK();
211
212 if (error) {
213 if (error == EAGAIN)
214 goto retry;
215 return error;
216 }
217 if (!nodename) {
218 /*
219 * we haven't called devfs_dntovn if we get here
220 * we have not taken a reference on the node.. no
221 * vnode_put is necessary on these error returns
222 *
223 * If it doesn't exist and we're not the last component,
224 * or we're at the last component, but we're not creating
225 * or renaming, return ENOENT.
226 */
227 if (!(flags & ISLASTCN) || !(op == CREATE || op == RENAME)) {
228 return ENOENT;
229 }
230 /*
231 * We return with the directory locked, so that
232 * the parameters we set up above will still be
233 * valid if we actually decide to add a new entry.
234 * We return ni_vp == NULL to indicate that the entry
235 * does not currently exist; we leave a pointer to
236 * the (locked) directory vnode in namei_data->ni_dvp.
237 *
238 * NB - if the directory is unlocked, then this
239 * information cannot be used.
240 */
241 return (EJUSTRETURN);
242 }
243 /*
244 * from this point forward, we need to vnode_put the reference
245 * picked up in devfs_dntovn if we decide to return an error
246 */
247
248 /*
249 * If deleting, and at end of pathname, return
250 * parameters which can be used to remove file.
251 * If the wantparent flag isn't set, we return only
252 * the directory (in namei_data->ni_dvp), otherwise we go
253 * on and lock the node, being careful with ".".
254 */
255 if (op == DELETE && (flags & ISLASTCN)) {
256
257 /*
258 * we are trying to delete '.'. What does this mean? XXX
259 */
260 if (dir_node == node) {
261 if (*result_vnode) {
262 vnode_put(*result_vnode);
263 *result_vnode = NULL;
264 }
265 if ( ((error = vnode_get(dir_vnode)) == 0) ) {
266 *result_vnode = dir_vnode;
267 }
268 return (error);
269 }
270 return (0);
271 }
272
273 /*
274 * If rewriting (RENAME), return the vnode and the
275 * information required to rewrite the present directory
276 * Must get node of directory entry to verify it's a
277 * regular file, or empty directory.
278 */
279 if (op == RENAME && wantparent && (flags & ISLASTCN)) {
280
281 /*
282 * Careful about locking second node.
283 * This can only occur if the target is ".".
284 */
285 if (dir_node == node) {
286 error = EISDIR;
287 goto drop_ref;
288 }
289 return (0);
290 }
291
292 /*
293 * Step through the translation in the name. We do not unlock the
294 * directory because we may need it again if a symbolic link
295 * is relative to the current directory. Instead we save it
296 * unlocked as "saved_dir_node" XXX. We must get the target
297 * node before unlocking
298 * the directory to insure that the node will not be removed
299 * before we get it. We prevent deadlock by always fetching
300 * nodes from the root, moving down the directory tree. Thus
301 * when following backward pointers ".." we must unlock the
302 * parent directory before getting the requested directory.
303 * There is a potential race condition here if both the current
304 * and parent directories are removed before the lock for the
305 * node associated with ".." returns. We hope that this occurs
306 * infrequently since we cannot avoid this race condition without
307 * implementing a sophisticated deadlock detection algorithm.
308 * Note also that this simple deadlock detection scheme will not
309 * work if the file system has any hard links other than ".."
310 * that point backwards in the directory structure.
311 */
312 if ((flags & ISDOTDOT) == 0 && dir_node == node) {
313 if (*result_vnode) {
314 vnode_put(*result_vnode);
315 *result_vnode = NULL;
316 }
317 if ( (error = vnode_get(dir_vnode)) ) {
318 return (error);
319 }
320 *result_vnode = dir_vnode;
321 }
322 return (0);
323
324 drop_ref:
325 if (*result_vnode) {
326 vnode_put(*result_vnode);
327 *result_vnode = NULL;
328 }
329 return (error);
330 }
331
332 static int
333 devfs_getattr(struct vnop_getattr_args *ap)
334 /*struct vnop_getattr_args {
335 struct vnode *a_vp;
336 struct vnode_attr *a_vap;
337 kauth_cred_t a_cred;
338 struct proc *a_p;
339 } */
340 {
341 struct vnode *vp = ap->a_vp;
342 struct vnode_attr *vap = ap->a_vap;
343 devnode_t * file_node;
344 struct timeval now;
345
346
347 DEVFS_LOCK();
348 file_node = VTODN(vp);
349
350 microtime(&now);
351 dn_times(file_node, &now, &now, &now);
352
353 VATTR_RETURN(vap, va_mode, file_node->dn_mode);
354
355 /*
356 * Note: for DEV_CDEV and DEV_BDEV, we return the device from
357 * the vp, not the file_node; if we getting information on a
358 * cloning device, we want the cloned information, not the template.
359 */
360 switch (file_node->dn_type)
361 {
362 case DEV_DIR:
363 VATTR_RETURN(vap, va_rdev, (dev_t)file_node->dn_dvm);
364 vap->va_mode |= (S_IFDIR);
365 break;
366 case DEV_CDEV:
367 VATTR_RETURN(vap, va_rdev, vp->v_rdev);
368 vap->va_mode |= (S_IFCHR);
369 break;
370 case DEV_BDEV:
371 VATTR_RETURN(vap, va_rdev, vp->v_rdev);
372 vap->va_mode |= (S_IFBLK);
373 break;
374 case DEV_SLNK:
375 VATTR_RETURN(vap, va_rdev, 0);
376 vap->va_mode |= (S_IFLNK);
377 break;
378 default:
379 VATTR_RETURN(vap, va_rdev, 0); /* default value only */
380 }
381 VATTR_RETURN(vap, va_type, vp->v_type);
382 VATTR_RETURN(vap, va_nlink, file_node->dn_links);
383 VATTR_RETURN(vap, va_uid, file_node->dn_uid);
384 VATTR_RETURN(vap, va_gid, file_node->dn_gid);
385 VATTR_RETURN(vap, va_fsid, (uintptr_t)file_node->dn_dvm);
386 VATTR_RETURN(vap, va_fileid, (uintptr_t)file_node);
387 VATTR_RETURN(vap, va_data_size, file_node->dn_len);
388
389 /* return an override block size (advisory) */
390 if (vp->v_type == VBLK)
391 VATTR_RETURN(vap, va_iosize, BLKDEV_IOSIZE);
392 else if (vp->v_type == VCHR)
393 VATTR_RETURN(vap, va_iosize, MAXPHYSIO);
394 else
395 VATTR_RETURN(vap, va_iosize, vp->v_mount->mnt_vfsstat.f_iosize);
396 /* if the time is bogus, set it to the boot time */
397 if (file_node->dn_ctime.tv_sec == 0) {
398 file_node->dn_ctime.tv_sec = boottime_sec();
399 file_node->dn_ctime.tv_nsec = 0;
400 }
401 if (file_node->dn_mtime.tv_sec == 0)
402 file_node->dn_mtime = file_node->dn_ctime;
403 if (file_node->dn_atime.tv_sec == 0)
404 file_node->dn_atime = file_node->dn_ctime;
405 VATTR_RETURN(vap, va_change_time, file_node->dn_ctime);
406 VATTR_RETURN(vap, va_modify_time, file_node->dn_mtime);
407 VATTR_RETURN(vap, va_access_time, file_node->dn_atime);
408 VATTR_RETURN(vap, va_gen, 0);
409 VATTR_RETURN(vap, va_flags, 0);
410 VATTR_RETURN(vap, va_filerev, 0);
411 VATTR_RETURN(vap, va_acl, NULL);
412
413 DEVFS_UNLOCK();
414
415 return 0;
416 }
417
418 static int
419 devfs_setattr(struct vnop_setattr_args *ap)
420 /*struct vnop_setattr_args {
421 struct vnode *a_vp;
422 struct vnode_attr *a_vap;
423 vfs_context_t a_context;
424 } */
425 {
426 struct vnode *vp = ap->a_vp;
427 struct vnode_attr *vap = ap->a_vap;
428 int error = 0;
429 devnode_t * file_node;
430 struct timeval atimeval, mtimeval;
431
432 DEVFS_LOCK();
433
434 file_node = VTODN(vp);
435 /*
436 * Go through the fields and update if set.
437 */
438 if (VATTR_IS_ACTIVE(vap, va_access_time) || VATTR_IS_ACTIVE(vap, va_modify_time)) {
439
440
441 if (VATTR_IS_ACTIVE(vap, va_access_time))
442 file_node->dn_access = 1;
443 if (VATTR_IS_ACTIVE(vap, va_modify_time)) {
444 file_node->dn_change = 1;
445 file_node->dn_update = 1;
446 }
447 atimeval.tv_sec = vap->va_access_time.tv_sec;
448 atimeval.tv_usec = vap->va_access_time.tv_nsec / 1000;
449 mtimeval.tv_sec = vap->va_modify_time.tv_sec;
450 mtimeval.tv_usec = vap->va_modify_time.tv_nsec / 1000;
451
452 if ( (error = devfs_update(vp, &atimeval, &mtimeval)) )
453 goto exit;
454 }
455 VATTR_SET_SUPPORTED(vap, va_access_time);
456 VATTR_SET_SUPPORTED(vap, va_change_time);
457
458 /*
459 * Change the permissions.
460 */
461 if (VATTR_IS_ACTIVE(vap, va_mode)) {
462 file_node->dn_mode &= ~07777;
463 file_node->dn_mode |= vap->va_mode & 07777;
464 }
465 VATTR_SET_SUPPORTED(vap, va_mode);
466
467 /*
468 * Change the owner.
469 */
470 if (VATTR_IS_ACTIVE(vap, va_uid))
471 file_node->dn_uid = vap->va_uid;
472 VATTR_SET_SUPPORTED(vap, va_uid);
473
474 /*
475 * Change the group.
476 */
477 if (VATTR_IS_ACTIVE(vap, va_gid))
478 file_node->dn_gid = vap->va_gid;
479 VATTR_SET_SUPPORTED(vap, va_gid);
480 exit:
481 DEVFS_UNLOCK();
482
483 return error;
484 }
485
486 #if CONFIG_MACF
487 static int
488 devfs_setlabel(struct vnop_setlabel_args *ap)
489 /* struct vnop_setlabel_args {
490 struct vnodeop_desc *a_desc;
491 struct vnode *a_vp;
492 struct label *a_vl;
493 vfs_context_t a_context;
494 } */
495 {
496 struct vnode *vp;
497 struct devnode *de;
498
499 vp = ap->a_vp;
500 de = VTODN(vp);
501
502 mac_vnode_label_update(ap->a_context, vp, ap->a_vl);
503 mac_devfs_label_update(vp->v_mount, de, vp);
504
505 return (0);
506 }
507 #endif
508
509 static int
510 devfs_read(struct vnop_read_args *ap)
511 /* struct vnop_read_args {
512 struct vnode *a_vp;
513 struct uio *a_uio;
514 int a_ioflag;
515 vfs_context_t a_context;
516 } */
517 {
518 devnode_t * dn_p = VTODN(ap->a_vp);
519
520 switch (ap->a_vp->v_type) {
521 case VDIR: {
522 dn_p->dn_access = 1;
523
524 return VNOP_READDIR(ap->a_vp, ap->a_uio, 0, NULL, NULL, ap->a_context);
525 }
526 default: {
527 printf("devfs_read(): bad file type %d", ap->a_vp->v_type);
528 return(EINVAL);
529 break;
530 }
531 }
532 return (0); /* not reached */
533 }
534
535 static int
536 devfs_close(struct vnop_close_args *ap)
537 /* struct vnop_close_args {
538 struct vnode *a_vp;
539 int a_fflag;
540 vfs_context_t a_context;
541 } */
542 {
543 struct vnode * vp = ap->a_vp;
544 register devnode_t * dnp;
545 struct timeval now;
546
547 if (vnode_isinuse(vp, 1)) {
548 DEVFS_LOCK();
549 dnp = VTODN(vp);
550 microtime(&now);
551 dn_times(dnp, &now, &now, &now);
552 DEVFS_UNLOCK();
553 }
554 return (0);
555 }
556
557 static int
558 devfsspec_close(struct vnop_close_args *ap)
559 /* struct vnop_close_args {
560 struct vnode *a_vp;
561 int a_fflag;
562 vfs_context_t a_context;
563 } */
564 {
565 struct vnode * vp = ap->a_vp;
566 register devnode_t * dnp;
567 struct timeval now;
568
569 if (vnode_isinuse(vp, 1)) {
570 DEVFS_LOCK();
571 microtime(&now);
572 dnp = VTODN(vp);
573 dn_times(dnp, &now, &now, &now);
574 DEVFS_UNLOCK();
575 }
576 return (VOCALL (spec_vnodeop_p, VOFFSET(vnop_close), ap));
577 }
578
579 static int
580 devfsspec_read(struct vnop_read_args *ap)
581 /* struct vnop_read_args {
582 struct vnode *a_vp;
583 struct uio *a_uio;
584 int a_ioflag;
585 kauth_cred_t a_cred;
586 } */
587 {
588 register devnode_t * dnp = VTODN(ap->a_vp);
589
590 dnp->dn_access = 1;
591
592 return (VOCALL (spec_vnodeop_p, VOFFSET(vnop_read), ap));
593 }
594
595 static int
596 devfsspec_write(struct vnop_write_args *ap)
597 /* struct vnop_write_args {
598 struct vnode *a_vp;
599 struct uio *a_uio;
600 int a_ioflag;
601 vfs_context_t a_context;
602 } */
603 {
604 register devnode_t * dnp = VTODN(ap->a_vp);
605
606 dnp->dn_change = 1;
607 dnp->dn_update = 1;
608
609 return (VOCALL (spec_vnodeop_p, VOFFSET(vnop_write), ap));
610 }
611
612 /*
613 * Write data to a file or directory.
614 */
615 static int
616 devfs_write(struct vnop_write_args *ap)
617 /* struct vnop_write_args {
618 struct vnode *a_vp;
619 struct uio *a_uio;
620 int a_ioflag;
621 kauth_cred_t a_cred;
622 } */
623 {
624 switch (ap->a_vp->v_type) {
625 case VDIR:
626 return(EISDIR);
627 default:
628 printf("devfs_write(): bad file type %d", ap->a_vp->v_type);
629 return (EINVAL);
630 }
631 return 0; /* not reached */
632 }
633
634 static int
635 devfs_remove(struct vnop_remove_args *ap)
636 /* struct vnop_remove_args {
637 struct vnode *a_dvp;
638 struct vnode *a_vp;
639 struct componentname *a_cnp;
640 } */
641 {
642 struct vnode *vp = ap->a_vp;
643 struct vnode *dvp = ap->a_dvp;
644 struct componentname *cnp = ap->a_cnp;
645 devnode_t * tp;
646 devnode_t * tdp;
647 devdirent_t * tnp;
648 int doingdirectory = 0;
649 int error = 0;
650
651 /*
652 * assume that the name is null terminated as they
653 * are the end of the path. Get pointers to all our
654 * devfs structures.
655 */
656 DEVFS_LOCK();
657
658 tp = VTODN(vp);
659 tdp = VTODN(dvp);
660
661
662 tnp = dev_findname(tdp, cnp->cn_nameptr);
663
664 if (tnp == NULL) {
665 error = ENOENT;
666 goto abort;
667 }
668
669 /*
670 * Make sure that we don't try do something stupid
671 */
672 if ((tp->dn_type) == DEV_DIR) {
673 /*
674 * Avoid ".", "..", and aliases of "." for obvious reasons.
675 */
676 if ( (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.')
677 || (cnp->cn_flags&ISDOTDOT) ) {
678 error = EINVAL;
679 goto abort;
680 }
681 doingdirectory++;
682 }
683
684 /***********************************
685 * Start actually doing things.... *
686 ***********************************/
687 tdp->dn_change = 1;
688 tdp->dn_update = 1;
689
690 /*
691 * Target must be empty if a directory and have no links
692 * to it. Also, ensure source and target are compatible
693 * (both directories, or both not directories).
694 */
695 if (( doingdirectory) && (tp->dn_links > 2)) {
696 error = ENOTEMPTY;
697 goto abort;
698 }
699 dev_free_name(tnp);
700 abort:
701 DEVFS_UNLOCK();
702
703 return (error);
704 }
705
706 /*
707 */
708 static int
709 devfs_link(struct vnop_link_args *ap)
710 /*struct vnop_link_args {
711 struct vnode *a_tdvp;
712 struct vnode *a_vp;
713 struct componentname *a_cnp;
714 vfs_context_t a_context;
715 } */
716 {
717 struct vnode *vp = ap->a_vp;
718 struct vnode *tdvp = ap->a_tdvp;
719 struct componentname *cnp = ap->a_cnp;
720 devnode_t * fp;
721 devnode_t * tdp;
722 devdirent_t * tnp;
723 int error = 0;
724 struct timeval now;
725
726 /*
727 * First catch an arbitrary restriction for this FS
728 */
729 if (cnp->cn_namelen > DEVMAXNAMESIZE) {
730 error = ENAMETOOLONG;
731 goto out1;
732 }
733
734 /*
735 * Lock our directories and get our name pointers
736 * assume that the names are null terminated as they
737 * are the end of the path. Get pointers to all our
738 * devfs structures.
739 */
740 /* can lookup dnode safely for tdvp outside of devfs lock as it is not aliased */
741 tdp = VTODN(tdvp);
742
743 if (tdvp->v_mount != vp->v_mount) {
744 return (EXDEV);
745 }
746 DEVFS_LOCK();
747
748 fp = VTODN(vp);
749
750 /***********************************
751 * Start actually doing things.... *
752 ***********************************/
753 fp->dn_change = 1;
754
755 microtime(&now);
756 error = devfs_update(vp, &now, &now);
757
758 if (!error) {
759 error = dev_add_name(cnp->cn_nameptr, tdp, NULL, fp, &tnp);
760 }
761 out1:
762 DEVFS_UNLOCK();
763
764 return (error);
765 }
766
767 /*
768 * Rename system call. Seems overly complicated to me...
769 * rename("foo", "bar");
770 * is essentially
771 * unlink("bar");
772 * link("foo", "bar");
773 * unlink("foo");
774 * but ``atomically''.
775 *
776 * When the target exists, both the directory
777 * and target vnodes are locked.
778 * the source and source-parent vnodes are referenced
779 *
780 *
781 * Basic algorithm is:
782 *
783 * 1) Bump link count on source while we're linking it to the
784 * target. This also ensure the inode won't be deleted out
785 * from underneath us while we work (it may be truncated by
786 * a concurrent `trunc' or `open' for creation).
787 * 2) Link source to destination. If destination already exists,
788 * delete it first.
789 * 3) Unlink source reference to node if still around. If a
790 * directory was moved and the parent of the destination
791 * is different from the source, patch the ".." entry in the
792 * directory.
793 */
794 static int
795 devfs_rename(struct vnop_rename_args *ap)
796 /*struct vnop_rename_args {
797 struct vnode *a_fdvp;
798 struct vnode *a_fvp;
799 struct componentname *a_fcnp;
800 struct vnode *a_tdvp;
801 struct vnode *a_tvp;
802 struct componentname *a_tcnp;
803 vfs_context_t a_context;
804 } */
805 {
806 struct vnode *tvp = ap->a_tvp;
807 struct vnode *tdvp = ap->a_tdvp;
808 struct vnode *fvp = ap->a_fvp;
809 struct vnode *fdvp = ap->a_fdvp;
810 struct componentname *tcnp = ap->a_tcnp;
811 struct componentname *fcnp = ap->a_fcnp;
812 devnode_t *fp, *fdp, *tp, *tdp;
813 devdirent_t *fnp,*tnp;
814 int doingdirectory = 0;
815 int error = 0;
816 struct timeval now;
817
818 DEVFS_LOCK();
819 /*
820 * First catch an arbitrary restriction for this FS
821 */
822 if (tcnp->cn_namelen > DEVMAXNAMESIZE) {
823 error = ENAMETOOLONG;
824 goto out;
825 }
826
827 /*
828 * assume that the names are null terminated as they
829 * are the end of the path. Get pointers to all our
830 * devfs structures.
831 */
832 tdp = VTODN(tdvp);
833 fdp = VTODN(fdvp);
834 fp = VTODN(fvp);
835
836 fnp = dev_findname(fdp, fcnp->cn_nameptr);
837
838 if (fnp == NULL) {
839 error = ENOENT;
840 goto out;
841 }
842 tp = NULL;
843 tnp = NULL;
844
845 if (tvp) {
846 tnp = dev_findname(tdp, tcnp->cn_nameptr);
847
848 if (tnp == NULL) {
849 error = ENOENT;
850 goto out;
851 }
852 tp = VTODN(tvp);
853 }
854
855 /*
856 * Make sure that we don't try do something stupid
857 */
858 if ((fp->dn_type) == DEV_DIR) {
859 /*
860 * Avoid ".", "..", and aliases of "." for obvious reasons.
861 */
862 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.')
863 || (fcnp->cn_flags&ISDOTDOT)
864 || (tcnp->cn_namelen == 1 && tcnp->cn_nameptr[0] == '.')
865 || (tcnp->cn_flags&ISDOTDOT)
866 || (tdp == fp )) {
867 error = EINVAL;
868 goto out;
869 }
870 doingdirectory++;
871 }
872
873 /*
874 * If ".." must be changed (ie the directory gets a new
875 * parent) then the source directory must not be in the
876 * directory hierarchy above the target, as this would
877 * orphan everything below the source directory. Also
878 * the user must have write permission in the source so
879 * as to be able to change "..".
880 */
881 if (doingdirectory && (tdp != fdp)) {
882 devnode_t * tmp, *ntmp;
883 tmp = tdp;
884 do {
885 if(tmp == fp) {
886 /* XXX unlock stuff here probably */
887 error = EINVAL;
888 goto out;
889 }
890 ntmp = tmp;
891 } while ((tmp = tmp->dn_typeinfo.Dir.parent) != ntmp);
892 }
893
894 /***********************************
895 * Start actually doing things.... *
896 ***********************************/
897 fp->dn_change = 1;
898 microtime(&now);
899
900 if ( (error = devfs_update(fvp, &now, &now)) ) {
901 goto out;
902 }
903 /*
904 * Check if just deleting a link name.
905 */
906 if (fvp == tvp) {
907 if (fvp->v_type == VDIR) {
908 error = EINVAL;
909 goto out;
910 }
911 /* Release destination completely. */
912 dev_free_name(fnp);
913
914 DEVFS_UNLOCK();
915 return 0;
916 }
917 /*
918 * 1) Bump link count while we're moving stuff
919 * around. If we crash somewhere before
920 * completing our work, too bad :)
921 */
922 fp->dn_links++;
923 /*
924 * If the target exists zap it (unless it's a non-empty directory)
925 * We could do that as well but won't
926 */
927 if (tp) {
928 /*
929 * Target must be empty if a directory and have no links
930 * to it. Also, ensure source and target are compatible
931 * (both directories, or both not directories).
932 */
933 if (( doingdirectory) && (tp->dn_links > 2)) {
934 error = ENOTEMPTY;
935 goto bad;
936 }
937 dev_free_name(tnp);
938 tp = NULL;
939 }
940 dev_add_name(tcnp->cn_nameptr,tdp,NULL,fp,&tnp);
941 fnp->de_dnp = NULL;
942 fp->dn_links--; /* one less link to it.. */
943
944 dev_free_name(fnp);
945 bad:
946 fp->dn_links--; /* we added one earlier*/
947 out:
948 DEVFS_UNLOCK();
949 return (error);
950 }
951
952 static int
953 devfs_mkdir(struct vnop_mkdir_args *ap)
954 /*struct vnop_mkdir_args {
955 struct vnode *a_dvp;
956 struct vnode **a_vpp;
957 struct componentname *a_cnp;
958 struct vnode_attr *a_vap;
959 vfs_context_t a_context;
960 } */
961 {
962 struct componentname * cnp = ap->a_cnp;
963 vfs_context_t ctx = cnp->cn_context;
964 struct proc *p = vfs_context_proc(ctx);
965 int error = 0;
966 devnode_t * dir_p;
967 devdirent_t * nm_p;
968 devnode_t * dev_p;
969 struct vnode_attr * vap = ap->a_vap;
970 struct vnode * * vpp = ap->a_vpp;
971
972 DEVFS_LOCK();
973
974 dir_p = VTODN(ap->a_dvp);
975 error = dev_add_entry(cnp->cn_nameptr, dir_p, DEV_DIR,
976 NULL, NULL, NULL, &nm_p);
977 if (error) {
978 goto failure;
979 }
980 dev_p = nm_p->de_dnp;
981 dev_p->dn_uid = dir_p->dn_uid;
982 dev_p->dn_gid = dir_p->dn_gid;
983 dev_p->dn_mode = vap->va_mode;
984 dn_copy_times(dev_p, dir_p);
985
986 error = devfs_dntovn(dev_p, vpp, p);
987 failure:
988 DEVFS_UNLOCK();
989
990 return error;
991 }
992
993 /*
994 * An rmdir is a special type of remove, which we already support; we wrap
995 * and reexpress the arguments to call devfs_remove directly. The only
996 * different argument is flags, which we do not set, since it's ignored.
997 */
998 static int
999 devfs_rmdir(struct vnop_rmdir_args *ap)
1000 /* struct vnop_rmdir_args {
1001 struct vnode *a_dvp;
1002 struct vnode *a_vp;
1003 struct componentname *a_cnp;
1004 vfs_context_t a_context;
1005 } */
1006 {
1007 struct vnop_remove_args ra;
1008
1009 ra.a_dvp = ap->a_dvp;
1010 ra.a_vp = ap->a_vp;
1011 ra.a_cnp = ap->a_cnp;
1012 ra.a_flags = 0; /* XXX */
1013 ra.a_context = ap->a_context;
1014
1015 return devfs_remove(&ra);
1016 }
1017
1018
1019 static int
1020 devfs_symlink(struct vnop_symlink_args *ap)
1021 /*struct vnop_symlink_args {
1022 struct vnode *a_dvp;
1023 struct vnode **a_vpp;
1024 struct componentname *a_cnp;
1025 struct vnode_attr *a_vap;
1026 char *a_target;
1027 vfs_context_t a_context;
1028 } */
1029 {
1030 struct componentname * cnp = ap->a_cnp;
1031 vfs_context_t ctx = cnp->cn_context;
1032 struct proc *p = vfs_context_proc(ctx);
1033 int error = 0;
1034 devnode_t * dir_p;
1035 devnode_type_t typeinfo;
1036 devdirent_t * nm_p;
1037 devnode_t * dev_p;
1038 struct vnode_attr * vap = ap->a_vap;
1039 struct vnode * * vpp = ap->a_vpp;
1040
1041 typeinfo.Slnk.name = ap->a_target;
1042 typeinfo.Slnk.namelen = strlen(ap->a_target);
1043
1044 DEVFS_LOCK();
1045
1046 dir_p = VTODN(ap->a_dvp);
1047
1048 error = dev_add_entry(cnp->cn_nameptr, dir_p, DEV_SLNK,
1049 &typeinfo, NULL, NULL, &nm_p);
1050 if (error) {
1051 goto failure;
1052 }
1053 dev_p = nm_p->de_dnp;
1054 dev_p->dn_uid = dir_p->dn_uid;
1055 dev_p->dn_gid = dir_p->dn_gid;
1056 dev_p->dn_mode = vap->va_mode;
1057 dn_copy_times(dev_p, dir_p);
1058
1059 error = devfs_dntovn(dev_p, vpp, p);
1060 failure:
1061 DEVFS_UNLOCK();
1062
1063 return error;
1064 }
1065
1066 /*
1067 * Mknod vnode call
1068 */
1069 static int
1070 devfs_mknod(struct vnop_mknod_args *ap)
1071 /* struct vnop_mknod_args {
1072 struct vnode *a_dvp;
1073 struct vnode **a_vpp;
1074 struct componentname *a_cnp;
1075 struct vnode_attr *a_vap;
1076 vfs_context_t a_context;
1077 } */
1078 {
1079 struct componentname * cnp = ap->a_cnp;
1080 vfs_context_t ctx = cnp->cn_context;
1081 struct proc *p = vfs_context_proc(ctx);
1082 devnode_t * dev_p;
1083 devdirent_t * devent;
1084 devnode_t * dir_p; /* devnode for parent directory */
1085 struct vnode * dvp = ap->a_dvp;
1086 int error = 0;
1087 devnode_type_t typeinfo;
1088 struct vnode_attr * vap = ap->a_vap;
1089 struct vnode ** vpp = ap->a_vpp;
1090
1091 *vpp = NULL;
1092 if (!(vap->va_type == VBLK) && !(vap->va_type == VCHR)) {
1093 return (EINVAL); /* only support mknod of special files */
1094 }
1095 typeinfo.dev = vap->va_rdev;
1096
1097 DEVFS_LOCK();
1098
1099 dir_p = VTODN(dvp);
1100
1101 error = dev_add_entry(cnp->cn_nameptr, dir_p,
1102 (vap->va_type == VBLK) ? DEV_BDEV : DEV_CDEV,
1103 &typeinfo, NULL, NULL, &devent);
1104 if (error) {
1105 goto failure;
1106 }
1107 dev_p = devent->de_dnp;
1108 error = devfs_dntovn(dev_p, vpp, p);
1109 if (error)
1110 goto failure;
1111 dev_p->dn_uid = vap->va_uid;
1112 dev_p->dn_gid = vap->va_gid;
1113 dev_p->dn_mode = vap->va_mode;
1114 VATTR_SET_SUPPORTED(vap, va_uid);
1115 VATTR_SET_SUPPORTED(vap, va_gid);
1116 VATTR_SET_SUPPORTED(vap, va_mode);
1117 failure:
1118 DEVFS_UNLOCK();
1119
1120 return (error);
1121 }
1122
1123 /*
1124 * Vnode op for readdir
1125 */
1126 static int
1127 devfs_readdir(struct vnop_readdir_args *ap)
1128 /*struct vnop_readdir_args {
1129 struct vnode *a_vp;
1130 struct uio *a_uio;
1131 int a_flags;
1132 int *a_eofflag;
1133 int *a_numdirent;
1134 vfs_context_t a_context;
1135 } */
1136 {
1137 struct vnode *vp = ap->a_vp;
1138 struct uio *uio = ap->a_uio;
1139 struct dirent dirent;
1140 devnode_t * dir_node;
1141 devdirent_t * name_node;
1142 const char *name;
1143 int error = 0;
1144 int reclen;
1145 int nodenumber;
1146 int startpos,pos;
1147
1148 if (ap->a_flags & (VNODE_READDIR_EXTENDED | VNODE_READDIR_REQSEEKOFF))
1149 return (EINVAL);
1150
1151 /* set up refs to dir */
1152 dir_node = VTODN(vp);
1153 if (dir_node->dn_type != DEV_DIR)
1154 return(ENOTDIR);
1155 pos = 0;
1156 startpos = uio->uio_offset;
1157
1158 DEVFS_LOCK();
1159
1160 name_node = dir_node->dn_typeinfo.Dir.dirlist;
1161 nodenumber = 0;
1162
1163 dir_node->dn_access = 1;
1164
1165 while ((name_node || (nodenumber < 2)) && (uio_resid(uio) > 0))
1166 {
1167 switch(nodenumber)
1168 {
1169 case 0:
1170 dirent.d_fileno = (int32_t)(void *)dir_node;
1171 name = ".";
1172 dirent.d_namlen = 1;
1173 dirent.d_type = DT_DIR;
1174 break;
1175 case 1:
1176 if(dir_node->dn_typeinfo.Dir.parent)
1177 dirent.d_fileno
1178 = (int32_t)dir_node->dn_typeinfo.Dir.parent;
1179 else
1180 dirent.d_fileno = (u_int32_t)dir_node;
1181 name = "..";
1182 dirent.d_namlen = 2;
1183 dirent.d_type = DT_DIR;
1184 break;
1185 default:
1186 dirent.d_fileno = (int32_t)(void *)name_node->de_dnp;
1187 dirent.d_namlen = strlen(name_node->de_name);
1188 name = name_node->de_name;
1189 switch(name_node->de_dnp->dn_type) {
1190 case DEV_BDEV:
1191 dirent.d_type = DT_BLK;
1192 break;
1193 case DEV_CDEV:
1194 dirent.d_type = DT_CHR;
1195 break;
1196 case DEV_DIR:
1197 dirent.d_type = DT_DIR;
1198 break;
1199 case DEV_SLNK:
1200 dirent.d_type = DT_LNK;
1201 break;
1202 default:
1203 dirent.d_type = DT_UNKNOWN;
1204 }
1205 }
1206 #define GENERIC_DIRSIZ(dp) \
1207 ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
1208
1209 reclen = dirent.d_reclen = GENERIC_DIRSIZ(&dirent);
1210
1211 if(pos >= startpos) /* made it to the offset yet? */
1212 {
1213 if (uio_resid(uio) < reclen) /* will it fit? */
1214 break;
1215 strlcpy(dirent.d_name, name, DEVMAXNAMESIZE);
1216 if ((error = uiomove ((caddr_t)&dirent,
1217 dirent.d_reclen, uio)) != 0)
1218 break;
1219 }
1220 pos += reclen;
1221 if((nodenumber >1) && name_node)
1222 name_node = name_node->de_next;
1223 nodenumber++;
1224 }
1225 DEVFS_UNLOCK();
1226 uio->uio_offset = pos;
1227
1228 return (error);
1229 }
1230
1231
1232 /*
1233 */
1234 static int
1235 devfs_readlink(struct vnop_readlink_args *ap)
1236 /*struct vnop_readlink_args {
1237 struct vnode *a_vp;
1238 struct uio *a_uio;
1239 vfs_context_t a_context;
1240 } */
1241 {
1242 struct vnode *vp = ap->a_vp;
1243 struct uio *uio = ap->a_uio;
1244 devnode_t * lnk_node;
1245 int error = 0;
1246
1247 /* set up refs to dir */
1248 lnk_node = VTODN(vp);
1249
1250 if (lnk_node->dn_type != DEV_SLNK) {
1251 error = EINVAL;
1252 goto out;
1253 }
1254 error = uiomove(lnk_node->dn_typeinfo.Slnk.name,
1255 lnk_node->dn_typeinfo.Slnk.namelen, uio);
1256 out:
1257 return error;
1258 }
1259
1260 static int
1261 devfs_reclaim(struct vnop_reclaim_args *ap)
1262 /*struct vnop_reclaim_args {
1263 struct vnode *a_vp;
1264 } */
1265 {
1266 struct vnode * vp = ap->a_vp;
1267 devnode_t * dnp;
1268
1269 DEVFS_LOCK();
1270
1271 dnp = VTODN(vp);
1272
1273 if (dnp) {
1274 /*
1275 * do the same as devfs_inactive in case it is not called
1276 * before us (can that ever happen?)
1277 */
1278 dnp->dn_vn = NULL;
1279 vp->v_data = NULL;
1280
1281 if (dnp->dn_delete) {
1282 devnode_free(dnp);
1283 }
1284 }
1285 DEVFS_UNLOCK();
1286
1287 return(0);
1288 }
1289
1290
1291 /*
1292 * Get configurable pathname variables.
1293 */
1294 static int
1295 devs_vnop_pathconf(
1296 struct vnop_pathconf_args /* {
1297 struct vnode *a_vp;
1298 int a_name;
1299 int *a_retval;
1300 vfs_context_t a_context;
1301 } */ *ap)
1302 {
1303 switch (ap->a_name) {
1304 case _PC_LINK_MAX:
1305 /* arbitrary limit matching HFS; devfs has no hard limit */
1306 *ap->a_retval = 32767;
1307 break;
1308 case _PC_NAME_MAX:
1309 *ap->a_retval = DEVMAXNAMESIZE - 1; /* includes NUL */
1310 break;
1311 case _PC_PATH_MAX:
1312 *ap->a_retval = DEVMAXPATHSIZE - 1; /* XXX nonconformant */
1313 break;
1314 case _PC_CHOWN_RESTRICTED:
1315 *ap->a_retval = 200112; /* _POSIX_CHOWN_RESTRICTED */
1316 break;
1317 case _PC_NO_TRUNC:
1318 *ap->a_retval = 0;
1319 break;
1320 case _PC_CASE_SENSITIVE:
1321 *ap->a_retval = 1;
1322 break;
1323 case _PC_CASE_PRESERVING:
1324 *ap->a_retval = 1;
1325 break;
1326 default:
1327 return (EINVAL);
1328 }
1329
1330 return (0);
1331 }
1332
1333
1334
1335 /**************************************************************************\
1336 * pseudo ops *
1337 \**************************************************************************/
1338
1339 /*
1340 *
1341 * struct vnop_inactive_args {
1342 * struct vnode *a_vp;
1343 * vfs_context_t a_context;
1344 * }
1345 */
1346
1347 static int
1348 devfs_inactive(__unused struct vnop_inactive_args *ap)
1349 {
1350 return (0);
1351 }
1352
1353 /*
1354 * called with DEVFS_LOCK held
1355 */
1356 static int
1357 devfs_update(struct vnode *vp, struct timeval *access, struct timeval *modify)
1358 {
1359 devnode_t * ip;
1360 struct timeval now;
1361
1362 ip = VTODN(vp);
1363 if (vp->v_mount->mnt_flag & MNT_RDONLY) {
1364 ip->dn_access = 0;
1365 ip->dn_change = 0;
1366 ip->dn_update = 0;
1367
1368 return (0);
1369 }
1370 microtime(&now);
1371 dn_times(ip, access, modify, &now);
1372
1373 return (0);
1374 }
1375
1376 #define VOPFUNC int (*)(void *)
1377
1378 /* The following ops are used by directories and symlinks */
1379 int (**devfs_vnodeop_p)(void *);
1380 static struct vnodeopv_entry_desc devfs_vnodeop_entries[] = {
1381 { &vnop_default_desc, (VOPFUNC)vn_default_error },
1382 { &vnop_lookup_desc, (VOPFUNC)devfs_lookup }, /* lookup */
1383 { &vnop_create_desc, (VOPFUNC)err_create }, /* create */
1384 { &vnop_whiteout_desc, (VOPFUNC)err_whiteout }, /* whiteout */
1385 { &vnop_mknod_desc, (VOPFUNC)devfs_mknod }, /* mknod */
1386 { &vnop_open_desc, (VOPFUNC)nop_open }, /* open */
1387 { &vnop_close_desc, (VOPFUNC)devfs_close }, /* close */
1388 { &vnop_getattr_desc, (VOPFUNC)devfs_getattr }, /* getattr */
1389 { &vnop_setattr_desc, (VOPFUNC)devfs_setattr }, /* setattr */
1390 { &vnop_read_desc, (VOPFUNC)devfs_read }, /* read */
1391 { &vnop_write_desc, (VOPFUNC)devfs_write }, /* write */
1392 { &vnop_ioctl_desc, (VOPFUNC)err_ioctl }, /* ioctl */
1393 { &vnop_select_desc, (VOPFUNC)err_select }, /* select */
1394 { &vnop_revoke_desc, (VOPFUNC)err_revoke }, /* revoke */
1395 { &vnop_mmap_desc, (VOPFUNC)err_mmap }, /* mmap */
1396 { &vnop_fsync_desc, (VOPFUNC)nop_fsync }, /* fsync */
1397 { &vnop_remove_desc, (VOPFUNC)devfs_remove }, /* remove */
1398 { &vnop_link_desc, (VOPFUNC)devfs_link }, /* link */
1399 { &vnop_rename_desc, (VOPFUNC)devfs_rename }, /* rename */
1400 { &vnop_mkdir_desc, (VOPFUNC)devfs_mkdir }, /* mkdir */
1401 { &vnop_rmdir_desc, (VOPFUNC)devfs_rmdir }, /* rmdir */
1402 { &vnop_symlink_desc, (VOPFUNC)devfs_symlink }, /* symlink */
1403 { &vnop_readdir_desc, (VOPFUNC)devfs_readdir }, /* readdir */
1404 { &vnop_readlink_desc, (VOPFUNC)devfs_readlink }, /* readlink */
1405 { &vnop_inactive_desc, (VOPFUNC)devfs_inactive }, /* inactive */
1406 { &vnop_reclaim_desc, (VOPFUNC)devfs_reclaim }, /* reclaim */
1407 { &vnop_strategy_desc, (VOPFUNC)err_strategy }, /* strategy */
1408 { &vnop_pathconf_desc, (VOPFUNC)devs_vnop_pathconf }, /* pathconf */
1409 { &vnop_advlock_desc, (VOPFUNC)err_advlock }, /* advlock */
1410 { &vnop_bwrite_desc, (VOPFUNC)err_bwrite },
1411 { &vnop_pagein_desc, (VOPFUNC)err_pagein }, /* Pagein */
1412 { &vnop_pageout_desc, (VOPFUNC)err_pageout }, /* Pageout */
1413 { &vnop_copyfile_desc, (VOPFUNC)err_copyfile }, /* Copyfile */
1414 { &vnop_blktooff_desc, (VOPFUNC)err_blktooff }, /* blktooff */
1415 { &vnop_offtoblk_desc, (VOPFUNC)err_offtoblk }, /* offtoblk */
1416 { &vnop_blockmap_desc, (VOPFUNC)err_blockmap }, /* blockmap */
1417 #if CONFIG_MACF
1418 { &vnop_setlabel_desc, (VOPFUNC)devfs_setlabel }, /* setlabel */
1419 #endif
1420 { (struct vnodeop_desc*)NULL, (int(*)())NULL }
1421 };
1422 struct vnodeopv_desc devfs_vnodeop_opv_desc =
1423 { &devfs_vnodeop_p, devfs_vnodeop_entries };
1424
1425 /* The following ops are used by the device nodes */
1426 int (**devfs_spec_vnodeop_p)(void *);
1427 static struct vnodeopv_entry_desc devfs_spec_vnodeop_entries[] = {
1428 { &vnop_default_desc, (VOPFUNC)vn_default_error },
1429 { &vnop_lookup_desc, (VOPFUNC)spec_lookup }, /* lookup */
1430 { &vnop_create_desc, (VOPFUNC)spec_create }, /* create */
1431 { &vnop_mknod_desc, (VOPFUNC)spec_mknod }, /* mknod */
1432 { &vnop_open_desc, (VOPFUNC)spec_open }, /* open */
1433 { &vnop_close_desc, (VOPFUNC)devfsspec_close }, /* close */
1434 { &vnop_getattr_desc, (VOPFUNC)devfs_getattr }, /* getattr */
1435 { &vnop_setattr_desc, (VOPFUNC)devfs_setattr }, /* setattr */
1436 { &vnop_read_desc, (VOPFUNC)devfsspec_read }, /* read */
1437 { &vnop_write_desc, (VOPFUNC)devfsspec_write }, /* write */
1438 { &vnop_ioctl_desc, (VOPFUNC)spec_ioctl }, /* ioctl */
1439 { &vnop_select_desc, (VOPFUNC)spec_select }, /* select */
1440 { &vnop_revoke_desc, (VOPFUNC)spec_revoke }, /* revoke */
1441 { &vnop_mmap_desc, (VOPFUNC)spec_mmap }, /* mmap */
1442 { &vnop_fsync_desc, (VOPFUNC)spec_fsync }, /* fsync */
1443 { &vnop_remove_desc, (VOPFUNC)devfs_remove }, /* remove */
1444 { &vnop_link_desc, (VOPFUNC)devfs_link }, /* link */
1445 { &vnop_rename_desc, (VOPFUNC)spec_rename }, /* rename */
1446 { &vnop_mkdir_desc, (VOPFUNC)spec_mkdir }, /* mkdir */
1447 { &vnop_rmdir_desc, (VOPFUNC)spec_rmdir }, /* rmdir */
1448 { &vnop_symlink_desc, (VOPFUNC)spec_symlink }, /* symlink */
1449 { &vnop_readdir_desc, (VOPFUNC)spec_readdir }, /* readdir */
1450 { &vnop_readlink_desc, (VOPFUNC)spec_readlink }, /* readlink */
1451 { &vnop_inactive_desc, (VOPFUNC)devfs_inactive }, /* inactive */
1452 { &vnop_reclaim_desc, (VOPFUNC)devfs_reclaim }, /* reclaim */
1453 { &vnop_strategy_desc, (VOPFUNC)spec_strategy }, /* strategy */
1454 { &vnop_pathconf_desc, (VOPFUNC)spec_pathconf }, /* pathconf */
1455 { &vnop_advlock_desc, (VOPFUNC)spec_advlock }, /* advlock */
1456 { &vnop_bwrite_desc, (VOPFUNC)vn_bwrite },
1457 { &vnop_pagein_desc, (VOPFUNC)err_pagein }, /* Pagein */
1458 { &vnop_pageout_desc, (VOPFUNC)err_pageout }, /* Pageout */
1459 { &vnop_copyfile_desc, (VOPFUNC)err_copyfile }, /* Copyfile */
1460 { &vnop_blktooff_desc, (VOPFUNC)spec_blktooff }, /* blktooff */
1461 { &vnop_blktooff_desc, (VOPFUNC)spec_offtoblk }, /* blkofftoblk */
1462 { &vnop_blockmap_desc, (VOPFUNC)spec_blockmap }, /* blockmap */
1463 #if CONFIG_MACF
1464 { &vnop_setlabel_desc, (VOPFUNC)devfs_setlabel }, /* setlabel */
1465 #endif
1466 { (struct vnodeop_desc*)NULL, (int(*)())NULL }
1467 };
1468 struct vnodeopv_desc devfs_spec_vnodeop_opv_desc =
1469 { &devfs_spec_vnodeop_p, devfs_spec_vnodeop_entries };