]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/miscfs/devfs/devfs_vnops.c
This commit was generated by cvs2svn to compensate for changes in r43855,
[FreeBSD/FreeBSD.git] / sys / miscfs / devfs / devfs_vnops.c
1 /*
2  * Copyright 1997,1998 Julian Elischer.  All rights reserved.
3  * julian@freebsd.org
4  * 
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *  1. Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  *  2. Redistributions in binary form must reproduce the above copyright notice,
11  *     this list of conditions and the following disclaimer in the documentation
12  *     and/or other materials provided with the distribution.
13  * 
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17  * DISCLAIMED.  IN NO EVENT SHALL THE HOLDER OR CONTRIBUTORS BE LIABLE FOR
18  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  * 
26  *      $Id: devfs_vnops.c,v 1.68 1999/01/27 23:49:45 dillon Exp $
27  */
28
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/namei.h>
33 #include <sys/kernel.h>
34 #include <sys/fcntl.h>
35 #include <sys/conf.h>
36 #include <sys/disklabel.h>
37 #include <sys/lock.h>
38 #include <sys/stat.h>
39 #include <sys/mount.h>
40 #include <sys/proc.h>
41 #include <sys/time.h>
42 #include <sys/vnode.h>
43 #include <miscfs/specfs/specdev.h>/* definitions of spec functions we use */
44 #include <sys/dirent.h>
45 #include <miscfs/devfs/devfsdefs.h>
46 #include <sys/vmmeter.h>                                                        
47
48 #include <vm/vm.h>
49 #include <vm/vm_prot.h>
50 #include <vm/vm_object.h>
51 #include <vm/vm_page.h>
52 #include <vm/vm_pager.h>
53 #include <vm/vnode_pager.h>
54 #include <vm/vm_extern.h>
55
56
57 /*
58  * Insert description here
59  */
60
61
62 /*
63  * Convert a component of a pathname into a pointer to a locked node.
64  * This is a very central and rather complicated routine.
65  * If the file system is not maintained in a strict tree hierarchy,
66  * this can result in a deadlock situation (see comments in code below).
67  *
68  * The flag argument is LOOKUP, CREATE, RENAME, or DELETE depending on
69  * whether the name is to be looked up, created, renamed, or deleted.
70  * When CREATE, RENAME, or DELETE is specified, information usable in
71  * creating, renaming, or deleting a directory entry may be calculated.
72  * If flag has LOCKPARENT or'ed into it and the target of the pathname
73  * exists, lookup returns both the target and its parent directory locked.
74  * When creating or renaming and LOCKPARENT is specified, the target may
75  * not be ".".  When deleting and LOCKPARENT is specified, the target may
76  * be "."., but the caller must check to ensure it does an vrele and DNUNLOCK
77  * instead of two DNUNLOCKs.
78  *
79  * Overall outline of devfs_lookup:
80  *
81  *      check accessibility of directory
82  *      null terminate the component (lookup leaves the whole string alone)
83  *      look for name in cache, if found, then if at end of path
84  *        and deleting or creating, drop it, else return name
85  *      search for name in directory, to found or notfound
86  * notfound:
87  *      if creating, return locked directory,
88  *      else return error
89  * found:
90  *      if at end of path and deleting, return information to allow delete
91  *      if at end of path and rewriting (RENAME and LOCKPARENT), lock target
92  *        node and return info to allow rewrite
93  *      if not at end, add name to cache; if at end and neither creating
94  *        nor deleting, add name to cache
95  * On return to lookup, remove the null termination we put in at the start.
96  *
97  * NOTE: (LOOKUP | LOCKPARENT) currently returns the parent node unlocked.
98  */
99 static int
100 devfs_lookup(struct vop_lookup_args *ap)
101         /*struct vop_lookup_args {
102                 struct vnode * a_dvp; directory vnode ptr
103                 struct vnode ** a_vpp; where to put the result
104                 struct componentname * a_cnp; the name we want
105         };*/
106 {
107         struct componentname *cnp = ap->a_cnp;
108         struct vnode *dir_vnode = ap->a_dvp;
109         struct vnode **result_vnode = ap->a_vpp;
110         dn_p   dir_node;       /* the directory we are searching */
111         dn_p   new_node;       /* the node we are searching for */
112         devnm_p new_nodename;
113         int flags = cnp->cn_flags;
114         int op = cnp->cn_nameiop;       /* LOOKUP, CREATE, RENAME, or DELETE */
115         int lockparent = flags & LOCKPARENT;
116         int wantparent = flags & (LOCKPARENT|WANTPARENT);
117         int error = 0;
118         struct proc *p = cnp->cn_proc;
119         char    heldchar;       /* the char at the end of the name componet */
120
121         *result_vnode = NULL; /* safe not sorry */ /*XXX*/
122
123 DBPRINT(("lookup\n"));
124
125         if (dir_vnode->v_usecount == 0)
126             printf("dir had no refs ");
127         if (devfs_vntodn(dir_vnode,&dir_node))
128         {
129                 printf("vnode has changed?\n");
130                 vprint("=",dir_vnode);
131                 return(EINVAL);
132         }
133
134         /*
135          * Check accessiblity of directory.
136          */
137         if (dir_node->type != DEV_DIR) /* XXX or symlink? */
138         {
139                 return (ENOTDIR);
140         }
141         if ((error = VOP_ACCESS(dir_vnode, VEXEC, cnp->cn_cred, p)) != 0)
142         {
143                 return (error);
144         }
145
146         /*
147          * We now have a segment name to search for, and a directory to search.
148          *
149          */
150
151 /***********************************************************************\
152 * SEARCH FOR NAME                                                       *
153 * while making sure the component is null terminated for the strcmp     *
154 \***********************************************************************/
155
156         heldchar = cnp->cn_nameptr[cnp->cn_namelen];
157         cnp->cn_nameptr[cnp->cn_namelen] = '\0';
158         new_nodename = dev_findname(dir_node,cnp->cn_nameptr);
159         cnp->cn_nameptr[cnp->cn_namelen] = heldchar;
160         if(!new_nodename) {
161                 /*******************************************************\
162                 * Failed to find it.. (That may be good)                *
163                 \*******************************************************/
164                 new_node = NULL; /* to be safe */
165                 /*
166                  * If creating, and at end of pathname
167                  * then can consider
168                  * allowing file to be created.
169                  */
170                 if (!(flags & ISLASTCN) || !(op == CREATE || op == RENAME)) {
171                         return ENOENT;
172                 }
173                 /*
174                  * Access for write is interpreted as allowing
175                  * creation of files in the directory.
176                  */
177                 if ((error = VOP_ACCESS(dir_vnode, VWRITE,
178                                 cnp->cn_cred, p)) != 0)
179                 {
180 DBPRINT(("MKACCESS "));
181                         return (error);
182                 }
183                 /*
184                  * We return with the directory locked, so that
185                  * the parameters we set up above will still be
186                  * valid if we actually decide to add a new entry.
187                  * We return ni_vp == NULL to indicate that the entry
188                  * does not currently exist; we leave a pointer to
189                  * the (locked) directory vnode in namei_data->ni_dvp.
190                  * The pathname buffer is saved so that the name
191                  * can be obtained later.
192                  *
193                  * NB - if the directory is unlocked, then this
194                  * information cannot be used.
195                  */
196                 cnp->cn_flags |= SAVENAME; /*XXX why? */
197                 if (!lockparent)
198                         VOP_UNLOCK(dir_vnode, 0, p);
199                 return (EJUSTRETURN);
200         }
201
202         /***************************************************************\
203         * Found it.. this is not always a good thing..                  *
204         \***************************************************************/
205         new_node = new_nodename->dnp;
206         new_node->last_lookup = new_nodename; /* for unlink */
207         /*
208          * If deleting, and at end of pathname, return
209          * parameters which can be used to remove file.
210          * If the wantparent flag isn't set, we return only
211          * the directory (in namei_data->ni_dvp), otherwise we go
212          * on and lock the node, being careful with ".".
213          */
214         if (op == DELETE && (flags & ISLASTCN)) {
215                 /*
216                  * Write access to directory required to delete files.
217                  */
218                 if ((error = VOP_ACCESS(dir_vnode, VWRITE,
219                                 cnp->cn_cred, p)) != 0)
220                         return (error);
221                 /*
222                  * we are trying to delete '.'.  What does this mean? XXX
223                  */
224                 if (dir_node == new_node) {
225                         VREF(dir_vnode);
226                         *result_vnode = dir_vnode;
227                         return (0);
228                 }
229                 /*
230                  * If directory is "sticky", then user must own
231                  * the directory, or the file in it, else she
232                  * may not delete it (unless she's root). This
233                  * implements append-only directories.
234                  */
235                 devfs_dntovn(new_node,result_vnode);
236 #ifdef NOTYET
237                 if ((dir_node->mode & ISVTX) &&
238                     cnp->cn_cred->cr_uid != 0 &&
239                     cnp->cn_cred->cr_uid != dir_node->uid &&
240                     cnp->cn_cred->cr_uid != new_node->uid) {
241                         VOP_UNLOCK(*result_vnode, 0, p);
242                         return (EPERM);
243                 }
244 #endif
245                 if (!lockparent)
246                         VOP_UNLOCK(dir_vnode, 0, p);
247                 return (0);
248         }
249
250         /*
251          * If rewriting (RENAME), return the vnode and the
252          * information required to rewrite the present directory
253          * Must get node of directory entry to verify it's a
254          * regular file, or empty directory.
255          */
256         if (op == RENAME && wantparent && (flags & ISLASTCN)) {
257                 /*
258                  * Are we allowed to change the holding directory?
259                  */
260                 if ((error = VOP_ACCESS(dir_vnode, VWRITE,
261                                 cnp->cn_cred, p)) != 0)
262                         return (error);
263                 /*
264                  * Careful about locking second node.
265                  * This can only occur if the target is ".".
266                  */
267                 if (dir_node == new_node)
268                         return (EISDIR);
269                 devfs_dntovn(new_node,result_vnode);
270                 /* hmm save the 'from' name (we need to delete it) */
271                 cnp->cn_flags |= SAVENAME;
272                 if (!lockparent)
273                         VOP_UNLOCK(dir_vnode, 0, p);
274                 return (0);
275         }
276
277         /*
278          * Step through the translation in the name.  We do not unlock the
279          * directory because we may need it again if a symbolic link
280          * is relative to the current directory.  Instead we save it
281          * unlocked as "saved_dir_node" XXX.  We must get the target
282          * node before unlocking
283          * the directory to insure that the node will not be removed
284          * before we get it.  We prevent deadlock by always fetching
285          * nodes from the root, moving down the directory tree. Thus
286          * when following backward pointers ".." we must unlock the
287          * parent directory before getting the requested directory.
288          * There is a potential race condition here if both the current
289          * and parent directories are removed before the lock for the
290          * node associated with ".." returns.  We hope that this occurs
291          * infrequently since we cannot avoid this race condition without
292          * implementing a sophisticated deadlock detection algorithm.
293          * Note also that this simple deadlock detection scheme will not
294          * work if the file system has any hard links other than ".."
295          * that point backwards in the directory structure.
296          */
297         if (flags & ISDOTDOT) {
298                 VOP_UNLOCK(dir_vnode, 0, p);    /* race to get the node */
299                 devfs_dntovn(new_node,result_vnode);
300                 if (lockparent && (flags & ISLASTCN))
301                         vn_lock(dir_vnode, LK_EXCLUSIVE | LK_RETRY, p);
302         } else if (dir_node == new_node) {
303                 VREF(dir_vnode);        /* we want ourself, ie "." */
304                 *result_vnode = dir_vnode;
305         } else {
306                 devfs_dntovn(new_node,result_vnode);
307                 if (!lockparent || (flags & ISLASTCN))
308                         VOP_UNLOCK(dir_vnode, 0, p);
309         }
310
311 DBPRINT(("GOT\n"));
312         return (0);
313 }
314
315 /*
316  */
317
318 static int
319 devfs_access(struct vop_access_args *ap)
320         /*struct vop_access_args  {
321                 struct vnode *a_vp;
322                 int  a_mode;
323                 struct ucred *a_cred;
324                 struct proc *a_p;
325         } */ 
326 {
327         /*
328          *  mode is filled with a combination of VREAD, VWRITE,
329          *  and/or VEXEC bits turned on.  In an octal number these
330          *  are the Y in 0Y00.
331          */
332         struct vnode *vp = ap->a_vp;
333         int mode = ap->a_mode;
334         struct ucred *cred = ap->a_cred;
335         dn_p    file_node;
336         int     error;
337         gid_t   *gp;
338         int     i;
339
340 DBPRINT(("access\n"));
341         if ((error = devfs_vntodn(vp,&file_node)) != 0)
342         {
343                 printf("devfs_vntodn returned %d ",error);
344                 return error;
345         }
346
347         /* 
348          * if we are not running as a process, we are in the 
349          * kernel and we DO have permission
350          */
351         if (ap->a_p == NULL)
352                 return 0;
353
354         /*
355          * Access check is based on only one of owner, group, public.
356          * If not owner, then check group. If not a member of the
357          * group, then check public access.
358          */
359         if (cred->cr_uid != file_node->uid)
360         {
361                 /* failing that.. try groups */
362                 mode >>= 3;
363                 gp = cred->cr_groups;
364                 for (i = 0; i < cred->cr_ngroups; i++, gp++)
365                 {
366                         if (file_node->gid == *gp)
367                         {
368                                 goto found;
369                         }
370                 }
371                 /* failing that.. try general access */
372                 mode >>= 3;
373 found:
374                 ;
375         }
376         if ((file_node->mode & mode) == mode)
377                 return (0);
378         /*
379          *  Root gets to do anything.
380          * but only use suser prives as a last resort
381          * (Use of super powers is recorded in ap->a_p->p_acflag)
382          */
383         if( suser(cred, &ap->a_p->p_acflag) == 0) /* XXX what if no proc? */
384                 return 0;
385         return (EACCES);
386 }
387
388 static int
389 devfs_getattr(struct vop_getattr_args *ap)
390         /*struct vop_getattr_args {
391                 struct vnode *a_vp;
392                 struct vattr *a_vap;
393                 struct ucred *a_cred;
394                 struct proc *a_p;
395         } */ 
396 {
397         struct vnode *vp = ap->a_vp;
398         struct vattr *vap = ap->a_vap;
399         dn_p    file_node;
400         int     error;
401
402 DBPRINT(("getattr\n"));
403         if ((error = devfs_vntodn(vp,&file_node)) != 0)
404         {
405                 printf("devfs_vntodn returned %d ",error);
406                 return error;
407         }
408         vap->va_rdev = 0;/* default value only */
409         vap->va_mode = file_node->mode;
410         switch (file_node->type)
411         {
412         case    DEV_DIR:
413                 vap->va_rdev = (dev_t)file_node->dvm;
414                 vap->va_mode |= (S_IFDIR);
415                 break;
416         case    DEV_CDEV:
417                 vap->va_rdev = file_node->by.Cdev.dev;
418                 vap->va_mode |= (S_IFCHR);
419                 break;
420         case    DEV_BDEV:
421                 vap->va_rdev = file_node->by.Bdev.dev;
422                 vap->va_mode |= (S_IFBLK);
423                 break;
424         case    DEV_SLNK:
425                 break;
426         }
427         vap->va_type = vp->v_type;
428         vap->va_nlink = file_node->links;
429         vap->va_uid = file_node->uid;
430         vap->va_gid = file_node->gid;
431         vap->va_fsid = (intptr_t)(void *)file_node->dvm;
432         vap->va_fileid = (intptr_t)(void *)file_node;
433         vap->va_size = file_node->len; /* now a u_quad_t */
434         vap->va_blocksize = 512;
435         /*
436          * XXX If the node times are in  Jan 1, 1970, then
437          * update them to the boot time.
438          * When we made the node, the date/time was not yet known.
439          */
440         if(file_node->ctime.tv_sec < (24 * 3600))
441         {
442                 TIMEVAL_TO_TIMESPEC(&boottime,&(file_node->ctime));
443                 TIMEVAL_TO_TIMESPEC(&boottime,&(file_node->mtime));
444                 TIMEVAL_TO_TIMESPEC(&boottime,&(file_node->atime));
445         }
446         if (file_node->flags & IN_ACCESS) {
447                 nanotime(&file_node->atime);
448                 file_node->flags &= ~IN_ACCESS;
449         }
450         vap->va_ctime = file_node->ctime;
451         vap->va_mtime = file_node->mtime;
452         vap->va_atime = file_node->atime;
453         vap->va_gen = 0;
454         vap->va_flags = 0;
455         vap->va_bytes = file_node->len;         /* u_quad_t */
456         vap->va_filerev = 0; /* XXX */          /* u_quad_t */
457         vap->va_vaflags = 0; /* XXX */
458         return 0;
459 }
460
461 static int
462 devfs_setattr(struct vop_setattr_args *ap)
463         /*struct vop_setattr_args  {
464                 struct vnode *a_vp;
465                 struct vattr *a_vap;
466                 struct ucred *a_cred;
467                 struct proc *a_p;
468         } */ 
469 {
470         struct vnode *vp = ap->a_vp;
471         struct vattr *vap = ap->a_vap;
472         struct ucred *cred = ap->a_cred;
473         struct proc *p = ap->a_p;
474         int error = 0;
475         gid_t *gp;
476         int i;
477         dn_p    file_node;
478
479         if (vap->va_flags != VNOVAL)    /* XXX needs to be implemented */
480                 return (EOPNOTSUPP);
481
482         if ((error = devfs_vntodn(vp,&file_node)) != 0)
483         {
484                 printf("devfs_vntodn returned %d ",error);
485                 return error;
486         }
487 DBPRINT(("setattr\n"));
488         if ((vap->va_type != VNON)  ||
489             (vap->va_nlink != VNOVAL)  ||
490             (vap->va_fsid != VNOVAL)  ||
491             (vap->va_fileid != VNOVAL)  ||
492             (vap->va_blocksize != VNOVAL)  ||
493             (vap->va_rdev != VNOVAL)  ||
494             (vap->va_bytes != VNOVAL)  ||
495             (vap->va_gen != VNOVAL ))
496         {
497                 return EINVAL;
498         }
499
500
501         /* 
502          * Anyone can touch the files in such a way that the times are set
503          * to NOW (e.g. run 'touch') if they have write permissions
504          * however only the owner or root can set "un-natural times.
505          * They also don't need write permissions.
506          */
507         if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
508 #if 0           /*
509                  * This next test is pointless under devfs for now..
510                  * as there is only one devfs hiding under potentially many
511                  * mountpoints and actual device node are really 'mounted' under
512                  * a FAKE mountpoint inside the kernel only, no matter where it
513                  * APPEARS they are mounted to the outside world..
514                  * A readonly devfs doesn't exist anyway.
515                  */
516                 if (vp->v_mount->mnt_flag & MNT_RDONLY)
517                         return (EROFS);
518 #endif
519                 if (((vap->va_vaflags & VA_UTIMES_NULL) == 0) &&
520                     (cred->cr_uid != file_node->uid)  &&
521                     suser(cred, &p->p_acflag))
522                         return (EPERM);
523                     if(VOP_ACCESS(vp, VWRITE, cred, p))
524                         return (EACCES);
525                 file_node->atime = vap->va_atime;
526                 file_node->mtime = vap->va_mtime;
527                 nanotime(&file_node->ctime);
528                 return (0);
529         }
530
531         /*
532          * Change the permissions.. must be root or owner to do this.
533          */
534         if (vap->va_mode != (u_short)VNOVAL) {
535                 if ((cred->cr_uid != file_node->uid)
536                  && suser(cred, &p->p_acflag))
537                         return (EPERM);
538                 /* set drwxwxrwx stuff */
539                 file_node->mode &= ~07777;
540                 file_node->mode |= vap->va_mode & 07777;
541         }
542
543         /*
544          * Change the owner.. must be root to do this.
545          */
546         if (vap->va_uid != (uid_t)VNOVAL) {
547                 if (suser(cred, &p->p_acflag))
548                         return (EPERM);
549                 file_node->uid = vap->va_uid;
550         }
551
552         /*
553          * Change the group.. must be root or owner to do this.
554          * If we are the owner, we must be in the target group too.
555          * don't use suser() unless you have to as it reports
556          * whether you needed suser powers or not.
557          */
558         if (vap->va_gid != (gid_t)VNOVAL) {
559                 if (cred->cr_uid == file_node->uid){
560                         gp = cred->cr_groups;
561                         for (i = 0; i < cred->cr_ngroups; i++, gp++) {
562                                 if (vap->va_gid == *gp)
563                                         goto cando; 
564                         }
565                 }
566                 /*
567                  * we can't do it with normal privs,
568                  * do we have an ace up our sleeve?
569                  */
570                 if( suser(cred, &p->p_acflag))
571                         return (EPERM);
572 cando:
573                 file_node->gid = vap->va_gid;
574         }
575 #if 0
576         /*
577          * Copied from somewhere else
578          * but only kept as a marker and reminder of the fact that
579          * flags should be handled some day
580          */
581         if (vap->va_flags != VNOVAL) {
582                 if (error = suser(cred, &p->p_acflag))
583                         return error;
584                 if (cred->cr_uid == 0)
585                 ;
586                 else {
587                 }
588         }
589 #endif
590         return error;
591 }
592
593
594 static int
595 devfs_xread(struct vop_read_args *ap)
596         /*struct vop_read_args {
597                 struct vnode *a_vp;
598                 struct uio *a_uio;
599                 int  a_ioflag;
600                 struct ucred *a_cred;
601         } */
602 {
603         int     error = 0;
604         dn_p    file_node;
605
606 DBPRINT(("read\n"));
607         if ((error = devfs_vntodn(ap->a_vp,&file_node)) != 0)
608         {
609                 printf("devfs_vntodn returned %d ",error);
610                 return error;
611         }
612
613
614         switch (ap->a_vp->v_type) {
615         case VREG:
616                 return(EINVAL);
617         case VDIR:
618                 return VOP_READDIR(ap->a_vp,ap->a_uio,ap->a_cred,
619                                         NULL,NULL,NULL);
620         case VCHR:
621         case VBLK:
622                 panic("devfs:  vnode methods");
623
624         default:
625                 panic("devfs_read(): bad file type");
626                 break;
627         }
628 }
629
630 /*
631  *  Write data to a file or directory.
632  */
633 static int
634 devfs_xwrite(struct vop_write_args *ap)
635         /*struct vop_write_args  {
636                 struct vnode *a_vp;
637                 struct uio *a_uio;
638                 int  a_ioflag;
639                 struct ucred *a_cred;
640         } */
641 {
642         switch (ap->a_vp->v_type) {
643         case VREG:
644                 return(EINVAL);
645         case VDIR:
646                 return(EISDIR);
647         case VCHR:
648         case VBLK:
649                 panic("devfs:  vnode methods");
650         default:
651                 panic("devfs_write(): bad file type");
652         }
653 }
654
655
656 static int
657 devfs_remove(struct vop_remove_args *ap)
658         /*struct vop_remove_args  {
659                 struct vnode *a_dvp;
660                 struct vnode *a_vp;
661                 struct componentname *a_cnp;
662         } */ 
663 {
664         struct vnode *vp = ap->a_vp;
665         struct vnode *dvp = ap->a_dvp;
666         struct componentname *cnp = ap->a_cnp;
667         dn_p  tp, tdp;
668         devnm_p tnp;
669         int doingdirectory = 0;
670         int error = 0;
671         uid_t ouruid = cnp->cn_cred->cr_uid;
672
673
674 DBPRINT(("remove\n"));
675         /*
676          * Lock our directories and get our name pointers
677          * assume that the names are null terminated as they
678          * are the end of the path. Get pointers to all our
679          * devfs structures.
680          */
681         if ((error = devfs_vntodn(dvp, &tdp)) != 0) {
682 abortit:
683                 VOP_ABORTOP(dvp, cnp); 
684                 return (error);
685         }
686         if ((error = devfs_vntodn(vp, &tp)) != 0) goto abortit;
687         /*
688          * Assuming we are atomic, dev_lookup left this for us
689          */
690         tnp = tp->last_lookup;
691         
692
693         /*
694          * Check we are doing legal things WRT the new flags
695          */
696         if ((tp->flags & (IMMUTABLE | APPEND))
697           || (tdp->flags & APPEND) /*XXX eh?*/ ) {
698                 error = EPERM;
699                 goto abortit;
700         }
701
702         /*
703          * Make sure that we don't try do something stupid
704          */
705         if ((tp->type) == DEV_DIR) {
706                 /*
707                  * Avoid ".", "..", and aliases of "." for obvious reasons.
708                  */
709                 if ( (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') 
710                     || (cnp->cn_flags&ISDOTDOT) ) {
711                         error = EINVAL;
712                         goto abortit;
713                 }
714                 doingdirectory++;
715         }
716
717         /***********************************
718          * Start actually doing things.... *
719          ***********************************/
720         getnanotime(&(tdp->mtime));
721
722
723         /*
724          * own the parent directory, or the destination of the rename,
725          * otherwise the destination may not be changed (except by
726          * root). This implements append-only directories.
727          * XXX shoudn't this be in generic code? 
728          */
729         if ((tdp->mode & S_ISTXT)
730           && ouruid != 0
731           && ouruid != tdp->uid
732           && ouruid != tp->uid ) {
733                 error = EPERM;
734                 goto abortit;
735         }
736         /*
737          * Target must be empty if a directory and have no links
738          * to it. Also, ensure source and target are compatible
739          * (both directories, or both not directories).
740          */
741         if (( doingdirectory) && (tp->links > 2)) {
742                         printf("nlink = %d\n",tp->links); /*XXX*/
743                         error = ENOTEMPTY;
744                         goto abortit;
745         }
746         dev_free_name(tnp);
747         tp = NULL;
748         return (error);
749 }
750
751 /*
752  */
753 static int
754 devfs_link(struct vop_link_args *ap)
755         /*struct vop_link_args  {
756                 struct vnode *a_tdvp;
757                 struct vnode *a_vp;
758                 struct componentname *a_cnp;
759         } */ 
760 {
761         struct vnode *vp = ap->a_vp;
762         struct vnode *tdvp = ap->a_tdvp;
763         struct componentname *cnp = ap->a_cnp;
764         dn_p  fp, tdp;
765         devnm_p tnp;
766         int error = 0;
767
768 DBPRINT(("link\n"));
769         /*
770          * First catch an arbitrary restriction for this FS
771          */
772         if(cnp->cn_namelen > DEVMAXNAMESIZE) {
773                 error = ENAMETOOLONG;
774                 goto abortit;
775         }
776
777         /*
778          * Lock our directories and get our name pointers
779          * assume that the names are null terminated as they
780          * are the end of the path. Get pointers to all our
781          * devfs structures.
782          */
783         if ((error = devfs_vntodn(tdvp,&tdp)) != 0) goto abortit;
784         if ((error = devfs_vntodn(vp,&fp)) != 0) goto abortit;
785         
786         /*
787          * trying to move it out of devfs? (v_tag == VT_DEVFS)
788          */
789         if ( (vp->v_tag != VT_DEVFS)
790          || (vp->v_tag != tdvp->v_tag) ) {
791                 error = EXDEV;
792 abortit:
793                 VOP_ABORTOP(tdvp, cnp); 
794                 goto out;
795         }
796
797         /*
798          * Check we are doing legal things WRT the new flags
799          */
800         if (fp->flags & (IMMUTABLE | APPEND)) {
801                 error = EPERM;
802                 goto abortit;
803         }
804
805         /***********************************
806          * Start actually doing things.... *
807          ***********************************/
808         getnanotime(&(tdp->atime));
809         error = dev_add_name(cnp->cn_nameptr,
810                         tdp,
811                         NULL,
812                         fp,
813                         &tnp);
814 out:
815         return (error);
816
817 }
818
819 /*
820  * Rename system call. Seems overly complicated to me...
821  *      rename("foo", "bar");
822  * is essentially
823  *      unlink("bar");
824  *      link("foo", "bar");
825  *      unlink("foo");
826  * but ``atomically''.
827  *
828  * When the target exists, both the directory
829  * and target vnodes are locked.
830  * the source and source-parent vnodes are referenced
831  *
832  *
833  * Basic algorithm is:
834  *
835  * 1) Bump link count on source while we're linking it to the
836  *    target.  This also ensure the inode won't be deleted out
837  *    from underneath us while we work (it may be truncated by
838  *    a concurrent `trunc' or `open' for creation).
839  * 2) Link source to destination.  If destination already exists,
840  *    delete it first.
841  * 3) Unlink source reference to node if still around. If a
842  *    directory was moved and the parent of the destination
843  *    is different from the source, patch the ".." entry in the
844  *    directory.
845  */
846 static int
847 devfs_rename(struct vop_rename_args *ap)
848         /*struct vop_rename_args  {
849                 struct vnode *a_fdvp;
850                 struct vnode *a_fvp;
851                 struct componentname *a_fcnp;
852                 struct vnode *a_tdvp;
853                 struct vnode *a_tvp;
854                 struct componentname *a_tcnp;
855         } */
856 {
857         struct vnode *tvp = ap->a_tvp;
858         struct vnode *tdvp = ap->a_tdvp;
859         struct vnode *fvp = ap->a_fvp;
860         struct vnode *fdvp = ap->a_fdvp;
861         struct componentname *tcnp = ap->a_tcnp;
862         struct componentname *fcnp = ap->a_fcnp;
863         struct proc *p = fcnp->cn_proc;
864         dn_p fp, fdp, tp, tdp;
865         devnm_p fnp,tnp;
866         int doingdirectory = 0;
867         int error = 0;
868
869         /*
870          * First catch an arbitrary restriction for this FS
871          */
872         if(tcnp->cn_namelen > DEVMAXNAMESIZE) {
873                 error = ENAMETOOLONG;
874                 goto abortit;
875         }
876
877         /*
878          * Lock our directories and get our name pointers
879          * assume that the names are null terminated as they
880          * are the end of the path. Get pointers to all our
881          * devfs structures.
882          */
883         if ((error = devfs_vntodn(tdvp,&tdp)) != 0) goto abortit;
884         if ((error = devfs_vntodn(fdvp,&fdp)) != 0) goto abortit;
885         if ((error = devfs_vntodn(fvp,&fp)) != 0) goto abortit;
886         fnp = fp->last_lookup;
887         if (tvp) {
888                 if ((error = devfs_vntodn(tvp,&tp)) != 0) goto abortit;
889                 tnp = tp->last_lookup;
890         } else {
891                 tp = NULL;
892                 tnp = NULL;
893         }
894         
895         /*
896          * trying to move it out of devfs? (v_tag == VT_DEVFS)
897          * if we move a dir across mnt points. we need to fix all
898          * the mountpoint pointers! XXX
899          * so for now keep dirs within the same mount
900          */
901         if ( (fvp->v_tag != VT_DEVFS)
902          || (fvp->v_tag != tdvp->v_tag)
903          || (tvp && (fvp->v_tag != tvp->v_tag))
904          || ((fp->type == DEV_DIR) && (fp->dvm != tdp->dvm ))) {
905                 error = EXDEV;
906 abortit:
907                 VOP_ABORTOP(tdvp, tcnp); 
908                 if (tdvp == tvp) /* eh? */
909                         vrele(tdvp);
910                 else
911                         vput(tdvp);
912                 if (tvp)
913                         vput(tvp);
914                 VOP_ABORTOP(fdvp, fcnp); /* XXX, why not in NFS? */
915                 vrele(fdvp);
916                 vrele(fvp);
917                 return (error);
918         }
919
920         /*
921          * Check we are doing legal things WRT the new flags
922          */
923         if ((tp && (tp->flags & (IMMUTABLE | APPEND)))
924           || (fp->flags & (IMMUTABLE | APPEND))
925           || (fdp->flags & APPEND)) {
926                 error = EPERM;
927                 goto abortit;
928         }
929
930         /*
931          * Make sure that we don't try do something stupid
932          */
933         if ((fp->type) == DEV_DIR) {
934                 /*
935                  * Avoid ".", "..", and aliases of "." for obvious reasons.
936                  */
937                 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') 
938                     || (fcnp->cn_flags&ISDOTDOT) 
939                     || (tcnp->cn_namelen == 1 && tcnp->cn_nameptr[0] == '.') 
940                     || (tcnp->cn_flags&ISDOTDOT) 
941                     || (tdp == fp )) {
942                         error = EINVAL;
943                         goto abortit;
944                 }
945                 doingdirectory++;
946         }
947
948         /*
949          * If ".." must be changed (ie the directory gets a new
950          * parent) then the source directory must not be in the
951          * directory heirarchy above the target, as this would
952          * orphan everything below the source directory. Also
953          * the user must have write permission in the source so
954          * as to be able to change "..". 
955          */
956         if (doingdirectory && (tdp != fdp)) {
957                 dn_p tmp,ntmp;
958                 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_proc);
959                 tmp = tdp;
960                 do {
961                         if(tmp == fp) {
962                                 /* XXX unlock stuff here probably */
963                                 error = EINVAL;
964                                 goto out;
965                         }
966                         ntmp = tmp;
967                 } while ((tmp = tmp->by.Dir.parent) != ntmp);
968         }
969
970         /***********************************
971          * Start actually doing things.... *
972          ***********************************/
973         getnanotime(&(fp->atime));
974         /*
975          * Check if just deleting a link name.
976          */
977         if (fvp == tvp) {
978                 if (fvp->v_type == VDIR) {
979                         error = EINVAL;
980                         goto abortit;
981                 }
982
983                 /* Release destination completely. */
984                 VOP_ABORTOP(tdvp, tcnp);
985                 vput(tdvp);
986                 vput(tvp);
987
988                 /* Delete source. */
989                 VOP_ABORTOP(fdvp, fcnp); /*XXX*/
990                 vrele(fdvp);
991                 vrele(fvp);
992                 dev_free_name(fnp);
993                 return 0;
994         }
995
996
997         /*
998          * 1) Bump link count while we're moving stuff
999          *    around.  If we crash somewhere before
1000          *    completing our work,  too bad :)
1001          */
1002         fp->links++;
1003         /*
1004          * If the target exists zap it (unless it's a non-empty directory)
1005          * We could do that as well but won't
1006          */
1007         if (tp) {
1008                 int ouruid = tcnp->cn_cred->cr_uid;
1009                 /*
1010                  * If the parent directory is "sticky", then the user must
1011                  * own the parent directory, or the destination of the rename,
1012                  * otherwise the destination may not be changed (except by
1013                  * root). This implements append-only directories.
1014                  * XXX shoudn't this be in generic code? 
1015                  */
1016                 if ((tdp->mode & S_ISTXT)
1017                   && ouruid != 0
1018                   && ouruid != tdp->uid
1019                   && ouruid != tp->uid ) {
1020                         error = EPERM;
1021                         goto bad;
1022                 }
1023                 /*
1024                  * Target must be empty if a directory and have no links
1025                  * to it. Also, ensure source and target are compatible
1026                  * (both directories, or both not directories).
1027                  */
1028                 if (( doingdirectory) && (tp->links > 2)) {
1029                                 printf("nlink = %d\n",tp->links); /*XXX*/
1030                                 error = ENOTEMPTY;
1031                                 goto bad;
1032                 }
1033                 dev_free_name(tnp);
1034                 tp = NULL;
1035         }
1036         dev_add_name(tcnp->cn_nameptr,tdp,fnp->as.front.realthing,fp,&tnp);
1037         fnp->dnp = NULL;
1038         fp->links--; /* one less link to it.. */
1039         dev_free_name(fnp);
1040         fp->links--; /* we added one earlier*/
1041         if (tdp)
1042                 vput(tdvp);
1043         if (tp)
1044                 vput(fvp);
1045         vrele(ap->a_fvp);
1046         return (error);
1047
1048 bad:
1049         if (tp)
1050                 vput(tvp);
1051         vput(tdvp);
1052 out:
1053         if (vn_lock(fvp, LK_EXCLUSIVE | LK_RETRY, p) == 0) {
1054                 fp->links--; /* we added one earlier*/
1055                 vput(fvp);
1056         } else
1057                 vrele(fvp);
1058         return (error);
1059 }
1060
1061 static int
1062 devfs_symlink(struct vop_symlink_args *ap)
1063         /*struct vop_symlink_args {
1064                 struct vnode *a_dvp;
1065                 struct vnode **a_vpp;
1066                 struct componentname *a_cnp;
1067                 struct vattr *a_vap;
1068                 char *a_target;
1069         } */
1070 {
1071         struct vnode *vp;
1072         int error;
1073         dn_p dnp;
1074         union typeinfo by;
1075         devnm_p nm_p;
1076
1077 DBPRINT(("symlink\n"));
1078         if((error = devfs_vntodn(ap->a_dvp, &dnp)) != 0) {
1079                 return (error);
1080         }
1081                 
1082         by.Slnk.name = ap->a_target;
1083         by.Slnk.namelen = strlen(ap->a_target);
1084         dev_add_entry(ap->a_cnp->cn_nameptr, dnp, DEV_SLNK, &by,
1085                 NULL, NULL, &nm_p);
1086         if((error = devfs_dntovn(nm_p->dnp, &vp)) != 0) {
1087                 return (error);
1088         }
1089         VOP_SETATTR(vp, ap->a_vap, ap->a_cnp->cn_cred, ap->a_cnp->cn_proc);
1090         *ap->a_vpp = NULL;
1091         vput(vp);
1092         return 0;
1093 }
1094
1095 /*
1096  * Vnode op for readdir
1097  */
1098 static int
1099 devfs_readdir(struct vop_readdir_args *ap)
1100         /*struct vop_readdir_args {
1101                 struct vnode *a_vp;
1102                 struct uio *a_uio;
1103                 struct ucred *a_cred;
1104                 int *eofflag;
1105                 int *ncookies;
1106                 u_int **cookies;
1107         } */
1108 {
1109         struct vnode *vp = ap->a_vp;
1110         struct uio *uio = ap->a_uio;
1111         struct dirent dirent;
1112         dn_p dir_node;
1113         devnm_p name_node;
1114         char    *name;
1115         int error = 0;
1116         int reclen;
1117         int nodenumber;
1118         int     startpos,pos;
1119
1120 DBPRINT(("readdir\n"));
1121
1122 /*  set up refs to dir */
1123         if ((error = devfs_vntodn(vp,&dir_node)) != 0)
1124                 return error;
1125         if(dir_node->type != DEV_DIR)
1126                 return(ENOTDIR);
1127
1128         pos = 0;
1129         startpos = uio->uio_offset;
1130         name_node = dir_node->by.Dir.dirlist;
1131         nodenumber = 0;
1132         getnanotime(&(dir_node->atime));
1133
1134         while ((name_node || (nodenumber < 2)) && (uio->uio_resid > 0))
1135         {
1136                 switch(nodenumber)
1137                 {
1138                 case    0:
1139                         dirent.d_fileno = (uintptr_t)(void *)dir_node;
1140                         name = ".";
1141                         dirent.d_namlen = 1;
1142                         dirent.d_type = DT_DIR;
1143                         break;
1144                 case    1:
1145                         if(dir_node->by.Dir.parent)
1146                                 dirent.d_fileno
1147                                  = (uintptr_t)(void *)dir_node->by.Dir.parent;
1148                         else
1149                                 dirent.d_fileno = (uintptr_t)(void *)dir_node;
1150                         name = "..";
1151                         dirent.d_namlen = 2;
1152                         dirent.d_type = DT_DIR;
1153                         break;
1154                 default:
1155                         dirent.d_fileno = (uintptr_t)(void *)name_node->dnp;
1156                         dirent.d_namlen = strlen(name_node->name);
1157                         name = name_node->name;
1158                         switch(name_node->dnp->type) {
1159                         case DEV_BDEV:
1160                                 dirent.d_type = DT_BLK;
1161                                 break;
1162                         case DEV_CDEV:
1163                                 dirent.d_type = DT_CHR;
1164                                 break;
1165                         case DEV_DDEV:
1166                                 dirent.d_type = DT_SOCK; /*XXX*/
1167                                 break;
1168                         case DEV_DIR:
1169                                 dirent.d_type = DT_DIR;
1170                                 break;
1171                         case DEV_SLNK:
1172                                 dirent.d_type = DT_LNK;
1173                                 break;
1174                         default:
1175                                 dirent.d_type = DT_UNKNOWN;
1176                         }
1177                 }
1178
1179                 reclen = dirent.d_reclen = GENERIC_DIRSIZ(&dirent);
1180
1181                 if(pos >= startpos)     /* made it to the offset yet? */
1182                 {
1183                         if (uio->uio_resid < reclen) /* will it fit? */
1184                                 break;
1185                         strcpy( dirent.d_name,name);
1186                         if ((error = uiomove ((caddr_t)&dirent,
1187                                         dirent.d_reclen, uio)) != 0)
1188                                 break;
1189                 }
1190                 pos += reclen;
1191                 if((nodenumber >1) && name_node)
1192                         name_node = name_node->next;
1193                 nodenumber++;
1194         }
1195         uio->uio_offset = pos;
1196
1197         return (error);
1198 }
1199
1200
1201 /*
1202  */
1203 static int
1204 devfs_readlink(struct vop_readlink_args *ap)
1205         /*struct vop_readlink_args {
1206                 struct vnode *a_vp;
1207                 struct uio *a_uio;
1208                 struct ucred *a_cred;
1209         } */
1210 {
1211         struct vnode *vp = ap->a_vp;
1212         struct uio *uio = ap->a_uio;
1213         dn_p lnk_node;
1214         int error = 0;
1215
1216
1217 DBPRINT(("readlink\n"));
1218 /*  set up refs to dir */
1219         if ((error = devfs_vntodn(vp,&lnk_node)) != 0)
1220                 return error;
1221         if(lnk_node->type != DEV_SLNK)
1222                 return(EINVAL);
1223         if ((error = VOP_ACCESS(vp, VREAD, ap->a_cred, NULL)) != 0) { /* XXX */
1224                 return error;
1225         }
1226         error = uiomove(lnk_node->by.Slnk.name, lnk_node->by.Slnk.namelen, uio);
1227         return error;
1228 }
1229
1230 #ifdef notyet
1231 static int
1232 devfs_abortop(struct vop_abortop_args *ap)
1233         /*struct vop_abortop_args {
1234                 struct vnode *a_dvp;
1235                 struct componentname *a_cnp;
1236         } */
1237 {
1238 DBPRINT(("abortop\n"));
1239         if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
1240                 zfree(namei_zone, ap->a_cnp->cn_pnbuf);
1241         return 0;
1242 }
1243 #endif /* notyet */
1244
1245
1246 static int
1247 devfs_reclaim(struct vop_reclaim_args *ap)
1248         /*struct vop_reclaim_args {
1249                 struct vnode *a_vp;
1250         } */
1251 {
1252         dn_p    file_node = NULL;
1253         int     error;
1254
1255 DBPRINT(("reclaim\n"));
1256         if ((error = devfs_vntodn(ap->a_vp,&file_node)) != 0)
1257         {
1258                 printf("devfs_vntodn returned %d ",error);
1259                 return error;
1260         }
1261
1262         ap->a_vp->v_data = NULL;
1263         if (file_node) {
1264                 file_node->vn = 0;
1265                 file_node->vn_id = 0;
1266         }
1267         return(0);
1268 }
1269
1270 /*
1271  * Print out the contents of a /devfs vnode.
1272  */
1273 static int
1274 devfs_print(struct vop_print_args *ap)
1275         /*struct vop_print_args {
1276                 struct vnode *a_vp;
1277         } */
1278 {
1279
1280         printf("tag VT_DEVFS, devfs vnode\n");
1281         return (0);
1282 }
1283
1284 /**************************************************************************\
1285 * pseudo ops *
1286 \**************************************************************************/
1287
1288 /*proto*/
1289 void
1290 devfs_dropvnode(dn_p dnp)
1291 {
1292         struct vnode *vn_p;
1293
1294 #ifdef PARANOID
1295         if(!dnp)
1296         {
1297                 printf("devfs: dn count dropped too early\n");
1298         }
1299 #endif
1300         vn_p = dnp->vn;
1301         /*
1302          * check if we have a vnode.......
1303          */
1304         if((vn_p) && ( dnp->vn_id == vn_p->v_id) && (dnp == (dn_p)vn_p->v_data))
1305         {
1306                 VOP_REVOKE(vn_p, REVOKEALL);
1307         }
1308         dnp->vn = NULL; /* be pedantic about this */
1309 }
1310
1311 /* struct vnode *speclisth[SPECHSZ];*/ /* till specfs goes away */
1312
1313 /*
1314  * Open a special file.
1315         struct vop_open_args {
1316                 struct vnode *a_vp;
1317                 int  a_mode;
1318                 struct ucred *a_cred;
1319                 struct proc *a_p;
1320         } *ap;
1321  */
1322 /* ARGSUSED */
1323 static int
1324 devfs_open( struct vop_open_args *ap)
1325 {
1326         struct proc *p = ap->a_p;
1327         struct vnode *vp = ap->a_vp;
1328         int error;
1329         dn_p    dnp;
1330
1331         if ((error = devfs_vntodn(vp,&dnp)) != 0)
1332                 return error;
1333
1334         switch (vp->v_type) {
1335         case VCHR:
1336                 VOP_UNLOCK(vp, 0, p);
1337                 error = (*dnp->by.Cdev.cdevsw->d_open)(
1338                                         dnp->by.Cdev.dev,
1339                                         ap->a_mode,
1340                                         S_IFCHR,
1341                                         p);
1342                 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
1343                 return (error);
1344                 /* NOT REACHED */
1345         case VBLK:
1346                 error = (*dnp->by.Bdev.bdevsw->d_open)(
1347                                         dnp->by.Bdev.dev,
1348                                         ap->a_mode,
1349                                         S_IFBLK,
1350                                         p);
1351                 break;
1352         default:
1353                 break;
1354         }
1355         return (error);
1356 }
1357
1358 /*
1359  * Vnode op for read
1360         struct vop_read_args {
1361                 struct vnode *a_vp;
1362                 struct uio *a_uio;
1363                 int  a_ioflag;
1364                 struct ucred *a_cred;
1365         } 
1366
1367  */
1368 /* ARGSUSED */
1369 static int
1370 devfs_read( struct vop_read_args *ap)
1371 {
1372         register struct vnode *vp = ap->a_vp;
1373         register struct uio *uio = ap->a_uio;
1374         struct proc *p = uio->uio_procp;
1375         struct buf *bp;
1376         daddr_t bn, nextbn;
1377         long bsize, bscale;
1378         struct partinfo dpart;
1379         int n, on;
1380         d_ioctl_t *ioctl;
1381         int error = 0;
1382         dev_t dev;
1383         dn_p    dnp;
1384
1385         if ((error = devfs_vntodn(vp,&dnp)) != 0)
1386                 return error;
1387
1388
1389 #ifdef DIAGNOSTIC
1390         if (uio->uio_rw != UIO_READ)
1391                 panic("devfs_read mode");
1392         if (uio->uio_segflg == UIO_USERSPACE && uio->uio_procp != curproc)
1393                 panic("devfs_read proc");
1394 #endif
1395         if (uio->uio_resid == 0)
1396                 return (0);
1397
1398         switch (vp->v_type) {
1399
1400         case VCHR:
1401                 VOP_UNLOCK(vp, 0, p);
1402                 error = (*dnp->by.Cdev.cdevsw->d_read)
1403                         (dnp->by.Cdev.dev, uio, ap->a_ioflag);
1404                 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
1405                 break;
1406
1407         case VBLK:
1408                 if (uio->uio_offset < 0)
1409                         return (EINVAL);
1410                 bsize = BLKDEV_IOSIZE;
1411                 dev = dnp->by.Bdev.dev;
1412                 /*
1413                  * This is a hack!
1414                  */
1415                 if ( (ioctl = dnp->by.Bdev.bdevsw->d_ioctl) != NULL &&
1416                     (*ioctl)(dev, DIOCGPART, (caddr_t)&dpart, FREAD, p) == 0 &&
1417                     dpart.part->p_fstype == FS_BSDFFS &&
1418                     dpart.part->p_frag != 0 && dpart.part->p_fsize != 0)
1419                         bsize = dpart.part->p_frag * dpart.part->p_fsize;
1420                 bscale = btodb(bsize);
1421                 /* 
1422                  * Get buffers with this data from the buffer cache.
1423                  * If it's not there the strategy() entrypoint will be called.
1424                  * We may do this in several chunks.
1425                  */
1426                 do {
1427                         bn = btodb(uio->uio_offset) & ~(bscale - 1);
1428                         on = uio->uio_offset % bsize;
1429                         n = min((unsigned)(bsize - on), uio->uio_resid);
1430                         if (vp->v_lastr + bscale == bn) {
1431                                 nextbn = bn + bscale;
1432                                 error = breadn(vp, bn, (int)bsize, &nextbn,
1433                                         (int *)&bsize, 1, NOCRED, &bp);
1434                         } else
1435                                 error = bread(vp, bn, (int)bsize, NOCRED, &bp);
1436                         vp->v_lastr = bn;
1437                         n = min(n, bsize - bp->b_resid);
1438                         if (error) {
1439                                 brelse(bp);
1440                                 return (error);
1441                         }
1442                         /* 
1443                          * Copy it to the user's space
1444                          */
1445                         error = uiomove((char *)bp->b_data + on, n, uio);
1446                         brelse(bp);
1447                 } while (error == 0 && uio->uio_resid > 0 && n != 0);
1448                 break;
1449
1450         default:
1451                 panic("devfs_read type");
1452         }
1453         if (!(vp->v_mount->mnt_flag & MNT_NOATIME))
1454                 dnp->flags |= IN_ACCESS;        
1455         return (error);
1456 }
1457
1458 /*
1459  * Vnode op for write
1460         struct vop_write_args  {
1461                 struct vnode *a_vp;
1462                 struct uio *a_uio;
1463                 int  a_ioflag;
1464                 struct ucred *a_cred;
1465         }
1466  */
1467 /* ARGSUSED */
1468 static int
1469 devfs_write( struct vop_write_args *ap)
1470 {
1471         register struct vnode *vp = ap->a_vp;
1472         register struct uio *uio = ap->a_uio;
1473         struct proc *p = uio->uio_procp;
1474         struct buf *bp;
1475         daddr_t bn;
1476         int bsize, blkmask;
1477         struct partinfo dpart;
1478         register int n, on;
1479         int error = 0;
1480         dn_p    dnp;
1481
1482         if ((error = devfs_vntodn(vp,&dnp)) != 0)
1483                 return error;
1484
1485
1486 #ifdef DIAGNOSTIC
1487         if (uio->uio_rw != UIO_WRITE)
1488                 panic("devfs_write mode");
1489         if (uio->uio_segflg == UIO_USERSPACE && uio->uio_procp != curproc)
1490                 panic("devfs_write proc");
1491 #endif
1492
1493         switch (vp->v_type) {
1494
1495         case VCHR:
1496                 VOP_UNLOCK(vp, 0, p);
1497                 error = (*dnp->by.Cdev.cdevsw->d_write)
1498                         (dnp->by.Cdev.dev, uio, ap->a_ioflag);
1499                 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
1500                 return (error);
1501
1502         case VBLK:
1503                 if (uio->uio_resid == 0)
1504                         return (0);
1505                 if (uio->uio_offset < 0)
1506                         return (EINVAL);
1507                 bsize = BLKDEV_IOSIZE;
1508                 if ((dnp->by.Bdev.bdevsw->d_ioctl != NULL)
1509                 && ((*dnp->by.Bdev.bdevsw->d_ioctl)(dnp->by.Bdev.dev, DIOCGPART,
1510                                         (caddr_t)&dpart, FREAD, p) == 0)
1511                 && (dpart.part->p_fstype == FS_BSDFFS)
1512                 && (dpart.part->p_frag != 0)
1513                 && (dpart.part->p_fsize != 0)) {
1514                         bsize = dpart.part->p_frag * dpart.part->p_fsize;
1515                 }
1516                 blkmask = btodb(bsize) - 1;
1517                 do {
1518                         bn = btodb(uio->uio_offset) & ~blkmask;
1519                         on = uio->uio_offset % bsize;
1520                         n = min((unsigned)(bsize - on), uio->uio_resid);
1521                         if (n == bsize)
1522                                 bp = getblk(vp, bn, bsize, 0, 0);
1523                         else
1524                                 error = bread(vp, bn, bsize, NOCRED, &bp);
1525                         if (error) {
1526                                 brelse(bp);
1527                                 return (error);
1528                         }
1529                         n = min(n, bsize - bp->b_resid);
1530                         error = uiomove((char *)bp->b_data + on, n, uio);
1531                         if (n + on == bsize)
1532                                 bawrite(bp);
1533                         else
1534                                 bdwrite(bp);
1535                 } while (error == 0 && uio->uio_resid > 0 && n != 0);
1536                 return (error);
1537
1538         default:
1539                 panic("devfs_write type");
1540         }
1541         /* NOTREACHED */
1542 }
1543
1544 /*
1545  * Device ioctl operation.
1546         struct vop_ioctl_args {
1547                 struct vnode *a_vp;
1548                 int  a_command;
1549                 caddr_t  a_data;
1550                 int  a_fflag;
1551                 struct ucred *a_cred;
1552                 struct proc *a_p;
1553         }
1554  */
1555 /* ARGSUSED */
1556 static int
1557 devfs_ioctl(struct vop_ioctl_args *ap)
1558 {
1559         dn_p    dnp;
1560         int     error;
1561
1562         if ((error = devfs_vntodn(ap->a_vp,&dnp)) != 0)
1563                 return error;
1564
1565
1566         switch (ap->a_vp->v_type) {
1567
1568         case VCHR:
1569                 return ((*dnp->by.Cdev.cdevsw->d_ioctl)(dnp->by.Cdev.dev,
1570                                         ap->a_command,
1571                                         ap->a_data,
1572                                         ap->a_fflag,
1573                                         ap->a_p));
1574         case VBLK:
1575                 return ((*dnp->by.Bdev.bdevsw->d_ioctl)(dnp->by.Bdev.dev,
1576                                         ap->a_command,
1577                                         ap->a_data,
1578                                         ap->a_fflag,
1579                                         ap->a_p));
1580         default:
1581                 panic("devfs_ioctl");
1582                 /* NOTREACHED */
1583         }
1584 }
1585
1586 /*
1587         struct vop_poll_args {
1588                 struct vnode *a_vp;
1589                 int  a_events;
1590                 struct ucred *a_cred;
1591                 struct proc *a_p;
1592         } *ap;
1593 */
1594 /* ARGSUSED */
1595 static int
1596 devfs_poll(struct vop_poll_args *ap)
1597 {
1598         dn_p    dnp;
1599         int     error;
1600
1601         if ((error = devfs_vntodn(ap->a_vp,&dnp)) != 0)
1602                 return error;
1603
1604
1605         switch (ap->a_vp->v_type) {
1606
1607         case VCHR:
1608                 return (*dnp->by.Cdev.cdevsw->d_poll)(dnp->by.Cdev.dev,
1609                                         ap->a_events,
1610                                         ap->a_p);
1611         default:
1612                 return (vop_defaultop((struct vop_generic_args *)ap));
1613
1614         }
1615 }
1616 /*
1617  * Synch buffers associated with a block device
1618         struct vop_fsync_args {
1619                 struct vnode *a_vp;
1620                 struct ucred *a_cred;
1621                 int  a_waitfor;
1622                 struct proc *a_p;
1623         } 
1624  */
1625 /* ARGSUSED */
1626 static int
1627 devfs_fsync(struct vop_fsync_args *ap)
1628 {
1629         register struct vnode *vp = ap->a_vp;
1630         register struct buf *bp;
1631         struct buf *nbp;
1632         int s;
1633         dn_p    dnp;
1634         int     error;
1635
1636         if ((error = devfs_vntodn(vp,&dnp)) != 0)
1637                 return error;
1638
1639
1640         if (vp->v_type == VCHR)
1641                 return (0);
1642         /*
1643          * Flush all dirty buffers associated with a block device.
1644          */
1645 loop:
1646         s = splbio();
1647         for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
1648                 nbp = TAILQ_NEXT(bp, b_vnbufs);
1649                 if ((bp->b_flags & B_BUSY))
1650                         continue;
1651                 if ((bp->b_flags & B_DELWRI) == 0)
1652                         panic("devfs_fsync: not dirty");
1653                 if ((vp->v_flag & VOBJBUF) && (bp->b_flags & B_CLUSTEROK)) {
1654                         vfs_bio_awrite(bp);
1655                         splx(s);
1656                 } else {
1657                         bremfree(bp);
1658                         bp->b_flags |= B_BUSY;
1659                         splx(s);
1660                         bawrite(bp);
1661                 }
1662                 goto loop;
1663         }
1664         if (ap->a_waitfor == MNT_WAIT) {
1665                 while (vp->v_numoutput) {
1666                         vp->v_flag |= VBWAIT;
1667                         (void) tsleep((caddr_t)&vp->v_numoutput, PRIBIO + 1, "spfsyn", 0);
1668                 }
1669 #ifdef DIAGNOSTIC
1670                 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd)) {
1671                         vprint("devfs_fsync: dirty", vp);
1672                         splx(s);
1673                         goto loop;
1674                 }
1675 #endif
1676         }
1677         splx(s);
1678         return (0);
1679 }
1680 /*
1681  *
1682  *      struct vop_inactive_args {
1683  *              struct vnode *a_vp;
1684  *              struct proc *a_p;
1685  *      } 
1686  */
1687
1688 static int
1689 devfs_inactive(struct vop_inactive_args *ap)
1690 {
1691
1692         VOP_UNLOCK(ap->a_vp, 0, ap->a_p);
1693         return (0);
1694 }
1695
1696 /*
1697  * Just call the device strategy routine
1698         struct vop_strategy_args {
1699                 struct vnode *a_vp;
1700                 struct buf *a_bp;
1701         }
1702  */
1703 static int
1704 devfs_strategy(struct vop_strategy_args *ap)
1705 {
1706         struct buf *bp = ap->a_bp;
1707         dn_p    dnp;
1708         int     error;
1709
1710         if ((ap->a_vp->v_type != VCHR)
1711         &&  (ap->a_vp->v_type != VBLK))
1712                 panic ("devfs_strat:badvnode type");
1713         if ((error = devfs_vntodn(ap->a_vp,&dnp)) != 0)
1714                 return error;
1715
1716
1717         if (((bp->b_flags & B_READ) == 0) &&
1718                 (LIST_FIRST(&bp->b_dep)) != NULL && bioops.io_start)
1719                 (*bioops.io_start)(bp);
1720         switch (ap->a_vp->v_type) {
1721         case VCHR:
1722                 (*dnp->by.Cdev.cdevsw->d_strategy)(bp);
1723                 break;
1724         case VBLK:
1725                 (*dnp->by.Bdev.bdevsw->d_strategy)(bp);
1726                 break;
1727         default:
1728                 /* XXX set error code? */
1729                 break;
1730         }
1731         return (0);
1732 }
1733
1734 /*
1735  * This is a noop, simply returning what one has been given.
1736         struct vop_bmap_args  {
1737                 struct vnode *a_vp;
1738                 daddr_t  a_bn;
1739                 struct vnode **a_vpp;
1740                 daddr_t *a_bnp;
1741                 int *a_runp;
1742                 int *a_runb;
1743         }
1744  */
1745 static int
1746 devfs_bmap(struct vop_bmap_args *ap)
1747 {
1748
1749         if (ap->a_vpp != NULL)
1750                 *ap->a_vpp = ap->a_vp;
1751         if (ap->a_bnp != NULL)
1752                 *ap->a_bnp = ap->a_bn;
1753         if (ap->a_runp != NULL)
1754                 *ap->a_runp = 0;
1755         if (ap->a_runb != NULL)
1756                 *ap->a_runb = 0;
1757         return (0);
1758 }
1759
1760 /*
1761  * Device close routine
1762         struct vop_close_args {
1763                 struct vnode *a_vp;
1764                 int  a_fflag;
1765                 struct ucred *a_cred;
1766                 struct proc *a_p;
1767         }
1768  */
1769 /* ARGSUSED */
1770 static int
1771 devfs_close(struct vop_close_args *ap)
1772 {
1773         register struct vnode *vp = ap->a_vp;
1774         int error;
1775         dn_p dnp;
1776
1777         if ((error = devfs_vntodn(vp,&dnp)) != 0)
1778                 return error;
1779
1780
1781         switch (vp->v_type) {
1782
1783         case VCHR:
1784                 /*
1785                  * Hack: a tty device that is a controlling terminal
1786                  * has a reference from the session structure.
1787                  * We cannot easily tell that a character device is
1788                  * a controlling terminal, unless it is the closing
1789                  * process' controlling terminal.  In that case,
1790                  * if the reference count is 2 (this last descriptor
1791                  * plus the session), release the reference from the session.
1792                  */
1793                 if (vcount(vp) == 2 && ap->a_p &&
1794                     (vp->v_flag & VXLOCK) == 0 &&
1795                     vp == ap->a_p->p_session->s_ttyvp) {
1796                         vrele(vp);
1797                         ap->a_p->p_session->s_ttyvp = NULL;
1798                 }
1799                 /*
1800                  * If the vnode is locked, then we are in the midst
1801                  * of forcably closing the device, otherwise we only
1802                  * close on last reference.
1803                  */
1804                 if (vcount(vp) > 1 && (vp->v_flag & VXLOCK) == 0)
1805                         return (0);
1806                 return ((*dnp->by.Cdev.cdevsw->d_close)(dnp->by.Cdev.dev,
1807                                                 ap->a_fflag,
1808                                                 S_IFCHR,
1809                                                 ap->a_p));
1810                 /* NOT REACHED */
1811         case VBLK:
1812                 /*
1813                  * On last close of a block device (that isn't mounted)
1814                  * we must invalidate any in core blocks, so that
1815                  * we can, for instance, change floppy disks.
1816                  */
1817                 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, ap->a_p);
1818                 error = vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_p, 0, 0);
1819                 VOP_UNLOCK(vp, 0, ap->a_p);
1820                 if (error)
1821                         return (error);
1822
1823                 /*
1824                  * We do not want to really close the device if it
1825                  * is still in use unless we are trying to close it
1826                  * forcibly. Since every use (buffer, vnode, swap, cmap)
1827                  * holds a reference to the vnode, and because we mark
1828                  * any other vnodes that alias this device, when the
1829                  * sum of the reference counts on all the aliased
1830                  * vnodes descends to one, we are on last close.
1831                  */
1832                 if ((vcount(vp) > 1) && (vp->v_flag & VXLOCK) == 0)
1833                         return (0);
1834
1835                 return ((*dnp->by.Bdev.bdevsw->d_close)(dnp->by.Bdev.dev,
1836                                                 ap->a_fflag,
1837                                                 S_IFBLK,
1838                                                 ap->a_p));
1839                 /* NOT REACHED */
1840         default:
1841                 panic("devfs_close: not special");
1842         }
1843 }
1844
1845 /*
1846  * Print out the contents of a special device vnode.
1847         struct vop_print_args {
1848                 struct vnode *a_vp;
1849         }
1850  */
1851
1852 /*
1853  * Special device advisory byte-level locks.
1854         struct vop_advlock_args {
1855                 struct vnode *a_vp;
1856                 caddr_t  a_id;
1857                 int  a_op;
1858                 struct flock *a_fl;
1859                 int  a_flags;
1860         }
1861  */
1862 /* ARGSUSED */
1863 static int
1864 devfs_advlock(struct vop_advlock_args *ap)
1865 {
1866
1867         return (ap->a_flags & F_FLOCK ? EOPNOTSUPP : EINVAL);
1868 }
1869
1870 /*
1871  * Special device bad operation
1872  */
1873 static int
1874 devfs_badop(void)
1875 {
1876
1877         panic("devfs_badop called");
1878         /* NOTREACHED */
1879 }
1880
1881 static void
1882 devfs_getpages_iodone(struct buf *bp)
1883 {
1884
1885         bp->b_flags |= B_DONE;
1886         wakeup(bp);
1887 }
1888
1889 static int
1890 devfs_getpages(struct vop_getpages_args *ap)
1891 {
1892         vm_offset_t kva;
1893         int error;
1894         int i, pcount, size, s;
1895         daddr_t blkno;
1896         struct buf *bp;
1897         vm_page_t m;
1898         vm_ooffset_t offset;
1899         int toff, nextoff, nread;
1900         struct vnode *vp = ap->a_vp;
1901         int blksiz;
1902         int gotreqpage;
1903
1904         error = 0;
1905         pcount = round_page(ap->a_count) / PAGE_SIZE;
1906
1907         /*
1908          * Calculate the offset of the transfer.
1909          */
1910         offset = IDX_TO_OFF(ap->a_m[0]->pindex) + ap->a_offset;
1911
1912         /* XXX sanity check before we go into details. */
1913         /* XXX limits should be defined elsewhere. */
1914 #define DADDR_T_BIT     32
1915 #define OFFSET_MAX      ((1LL << (DADDR_T_BIT + DEV_BSHIFT)) - 1)
1916         if (offset < 0 || offset > OFFSET_MAX) {
1917                 /* XXX still no %q in kernel. */
1918                 printf("devfs_getpages: preposterous offset 0x%x%08x\n",
1919                        (u_int)((u_quad_t)offset >> 32),
1920                        (u_int)(offset & 0xffffffff));
1921                 return (VM_PAGER_ERROR);
1922         }
1923
1924         blkno = btodb(offset);
1925
1926         /*
1927          * Round up physical size for real devices, use the
1928          * fundamental blocksize of the fs if possible.
1929          */
1930         if (vp && vp->v_mount) {
1931                 if (vp->v_type != VBLK) {
1932                         vprint("Non VBLK", vp);
1933                 }
1934                 blksiz = vp->v_mount->mnt_stat.f_bsize;
1935                 if (blksiz < DEV_BSIZE) {
1936                         blksiz = DEV_BSIZE;
1937                 }
1938         }
1939         else
1940                 blksiz = DEV_BSIZE;
1941         size = (ap->a_count + blksiz - 1) & ~(blksiz - 1);
1942
1943         bp = getpbuf(NULL);
1944         kva = (vm_offset_t)bp->b_data;
1945
1946         /*
1947          * Map the pages to be read into the kva.
1948          */
1949         pmap_qenter(kva, ap->a_m, pcount);
1950
1951         /* Build a minimal buffer header. */
1952         bp->b_flags = B_BUSY | B_READ | B_CALL;
1953         bp->b_iodone = devfs_getpages_iodone;
1954
1955         /* B_PHYS is not set, but it is nice to fill this in. */
1956         bp->b_proc = curproc;
1957         bp->b_rcred = bp->b_wcred = bp->b_proc->p_ucred;
1958         if (bp->b_rcred != NOCRED)
1959                 crhold(bp->b_rcred);
1960         if (bp->b_wcred != NOCRED)
1961                 crhold(bp->b_wcred);
1962         bp->b_blkno = blkno;
1963         bp->b_lblkno = blkno;
1964         pbgetvp(ap->a_vp, bp);
1965         bp->b_bcount = size;
1966         bp->b_bufsize = size;
1967         bp->b_resid = 0;
1968
1969         cnt.v_vnodein++;
1970         cnt.v_vnodepgsin += pcount;
1971
1972         /* Do the input. */
1973         VOP_STRATEGY(bp->b_vp, bp);
1974
1975         s = splbio();
1976
1977         /* We definitely need to be at splbio here. */
1978         while ((bp->b_flags & B_DONE) == 0)
1979                 tsleep(bp, PVM, "spread", 0);
1980
1981         splx(s);
1982
1983         if ((bp->b_flags & B_ERROR) != 0) {
1984                 if (bp->b_error)
1985                         error = bp->b_error;
1986                 else
1987                         error = EIO;
1988         }
1989
1990         nread = size - bp->b_resid;
1991
1992         if (nread < ap->a_count) {
1993                 bzero((caddr_t)kva + nread,
1994                         ap->a_count - nread);
1995         }
1996         pmap_qremove(kva, pcount);
1997
1998
1999         gotreqpage = 0;
2000         for (i = 0, toff = 0; i < pcount; i++, toff = nextoff) {
2001                 nextoff = toff + PAGE_SIZE;
2002                 m = ap->a_m[i];
2003
2004                 m->flags &= ~PG_ZERO;
2005
2006                 if (nextoff <= nread) {
2007                         m->valid = VM_PAGE_BITS_ALL;
2008                         m->dirty = 0;
2009                 } else if (toff < nread) {
2010                         int nvalid = ((nread + DEV_BSIZE - 1) - toff) & ~(DEV_BSIZE - 1);
2011                         vm_page_set_validclean(m, 0, nvalid);
2012                 } else {
2013                         m->valid = 0;
2014                         m->dirty = 0;
2015                 }
2016
2017                 if (i != ap->a_reqpage) {
2018                         /*
2019                          * Just in case someone was asking for this page we
2020                          * now tell them that it is ok to use.
2021                          */
2022                         if (!error || (m->valid == VM_PAGE_BITS_ALL)) {
2023                                 if (m->valid) {
2024                                         if (m->flags & PG_WANTED) {
2025                                                 vm_page_activate(m);
2026                                         } else {
2027                                                 vm_page_deactivate(m);
2028                                         }
2029                                         vm_page_wakeup(m);
2030                                 } else {
2031                                         vm_page_free(m);
2032                                 }
2033                         } else {
2034                                 vm_page_free(m);
2035                         }
2036                 } else if (m->valid) {
2037                         gotreqpage = 1;
2038                 }
2039         }
2040         if (!gotreqpage) {
2041                 m = ap->a_m[ap->a_reqpage];
2042 #ifndef MAX_PERF
2043                 printf("devfs_getpages: I/O read failure: (error code=%d)\n", error);
2044                 printf("               size: %d, resid: %ld, a_count: %d, valid: 0x%x\n",
2045                                 size, bp->b_resid, ap->a_count, m->valid);
2046                 printf("               nread: %d, reqpage: %d, pindex: %d, pcount: %d\n",
2047                                 nread, ap->a_reqpage, m->pindex, pcount);
2048 #endif
2049                 /*
2050                  * Free the buffer header back to the swap buffer pool.
2051                  */
2052                 relpbuf(bp, NULL);
2053                 return VM_PAGER_ERROR;
2054         }
2055         /*
2056          * Free the buffer header back to the swap buffer pool.
2057          */
2058         relpbuf(bp, NULL);
2059         return VM_PAGER_OK;
2060 }
2061
2062
2063
2064 /* These are the operations used by directories etc in a devfs */
2065
2066 vop_t **devfs_vnodeop_p;
2067 static struct vnodeopv_entry_desc devfs_vnodeop_entries[] = {
2068         { &vop_default_desc,            (vop_t *) vop_defaultop },
2069         { &vop_access_desc,             (vop_t *) devfs_access },
2070         { &vop_bmap_desc,               (vop_t *) devfs_badop },
2071         { &vop_getattr_desc,            (vop_t *) devfs_getattr },
2072         { &vop_inactive_desc,           (vop_t *) devfs_inactive },
2073         { &vop_link_desc,               (vop_t *) devfs_link },
2074         { &vop_lookup_desc,             (vop_t *) devfs_lookup },
2075         { &vop_pathconf_desc,           (vop_t *) vop_stdpathconf },
2076         { &vop_print_desc,              (vop_t *) devfs_print },
2077         { &vop_read_desc,               (vop_t *) devfs_xread },
2078         { &vop_readdir_desc,            (vop_t *) devfs_readdir },
2079         { &vop_readlink_desc,           (vop_t *) devfs_readlink },
2080         { &vop_reclaim_desc,            (vop_t *) devfs_reclaim },
2081         { &vop_remove_desc,             (vop_t *) devfs_remove },
2082         { &vop_rename_desc,             (vop_t *) devfs_rename },
2083         { &vop_setattr_desc,            (vop_t *) devfs_setattr },
2084         { &vop_symlink_desc,            (vop_t *) devfs_symlink },
2085         { &vop_write_desc,              (vop_t *) devfs_xwrite },
2086         { NULL, NULL }
2087 };
2088 static struct vnodeopv_desc devfs_vnodeop_opv_desc =
2089         { &devfs_vnodeop_p, devfs_vnodeop_entries };
2090
2091 VNODEOP_SET(devfs_vnodeop_opv_desc);
2092
2093
2094
2095 vop_t **devfs_spec_vnodeop_p;
2096 static struct vnodeopv_entry_desc devfs_spec_vnodeop_entries[] = {
2097         { &vop_default_desc,            (vop_t *) vop_defaultop },
2098         { &vop_access_desc,             (vop_t *) devfs_access },
2099         { &vop_advlock_desc,            (vop_t *) devfs_advlock },
2100         { &vop_bmap_desc,               (vop_t *) devfs_bmap },
2101         { &vop_close_desc,              (vop_t *) devfs_close },
2102         { &vop_create_desc,             (vop_t *) devfs_badop },
2103         { &vop_fsync_desc,              (vop_t *) devfs_fsync },
2104         { &vop_getattr_desc,            (vop_t *) devfs_getattr },
2105         { &vop_getpages_desc,           (vop_t *) devfs_getpages },
2106         { &vop_inactive_desc,           (vop_t *) devfs_inactive },
2107         { &vop_ioctl_desc,              (vop_t *) devfs_ioctl },
2108         { &vop_lease_desc,              (vop_t *) vop_null },
2109         { &vop_link_desc,               (vop_t *) devfs_badop },
2110         { &vop_lookup_desc,             (vop_t *) devfs_lookup },
2111         { &vop_mkdir_desc,              (vop_t *) devfs_badop },
2112         { &vop_mknod_desc,              (vop_t *) devfs_badop },
2113         { &vop_open_desc,               (vop_t *) devfs_open },
2114         { &vop_pathconf_desc,           (vop_t *) vop_stdpathconf },
2115         { &vop_poll_desc,               (vop_t *) devfs_poll },
2116         { &vop_print_desc,              (vop_t *) devfs_print },
2117         { &vop_read_desc,               (vop_t *) devfs_read },
2118         { &vop_readdir_desc,            (vop_t *) devfs_badop },
2119         { &vop_readlink_desc,           (vop_t *) devfs_badop },
2120         { &vop_reallocblks_desc,        (vop_t *) devfs_badop },
2121         { &vop_reclaim_desc,            (vop_t *) devfs_reclaim },
2122         { &vop_remove_desc,             (vop_t *) devfs_badop },
2123         { &vop_rename_desc,             (vop_t *) devfs_badop },
2124         { &vop_rmdir_desc,              (vop_t *) devfs_badop },
2125         { &vop_setattr_desc,            (vop_t *) devfs_setattr },
2126         { &vop_strategy_desc,           (vop_t *) devfs_strategy },
2127         { &vop_symlink_desc,            (vop_t *) devfs_symlink },
2128         { &vop_write_desc,              (vop_t *) devfs_write },
2129         { NULL, NULL }
2130 };
2131 static struct vnodeopv_desc devfs_spec_vnodeop_opv_desc =
2132         { &devfs_spec_vnodeop_p, devfs_spec_vnodeop_entries };
2133
2134 VNODEOP_SET(devfs_spec_vnodeop_opv_desc);
2135