2 * Copyright 1997,1998 Julian Elischer. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
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.
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
26 * $Id: devfs_vnops.c,v 1.68 1999/01/27 23:49:45 dillon Exp $
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>
36 #include <sys/disklabel.h>
39 #include <sys/mount.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>
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>
58 * Insert description here
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).
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.
79 * Overall outline of devfs_lookup:
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
87 * if creating, return locked directory,
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.
97 * NOTE: (LOOKUP | LOCKPARENT) currently returns the parent node unlocked.
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
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);
118 struct proc *p = cnp->cn_proc;
119 char heldchar; /* the char at the end of the name componet */
121 *result_vnode = NULL; /* safe not sorry */ /*XXX*/
123 DBPRINT(("lookup\n"));
125 if (dir_vnode->v_usecount == 0)
126 printf("dir had no refs ");
127 if (devfs_vntodn(dir_vnode,&dir_node))
129 printf("vnode has changed?\n");
130 vprint("=",dir_vnode);
135 * Check accessiblity of directory.
137 if (dir_node->type != DEV_DIR) /* XXX or symlink? */
141 if ((error = VOP_ACCESS(dir_vnode, VEXEC, cnp->cn_cred, p)) != 0)
147 * We now have a segment name to search for, and a directory to search.
151 /***********************************************************************\
153 * while making sure the component is null terminated for the strcmp *
154 \***********************************************************************/
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;
161 /*******************************************************\
162 * Failed to find it.. (That may be good) *
163 \*******************************************************/
164 new_node = NULL; /* to be safe */
166 * If creating, and at end of pathname
168 * allowing file to be created.
170 if (!(flags & ISLASTCN) || !(op == CREATE || op == RENAME)) {
174 * Access for write is interpreted as allowing
175 * creation of files in the directory.
177 if ((error = VOP_ACCESS(dir_vnode, VWRITE,
178 cnp->cn_cred, p)) != 0)
180 DBPRINT(("MKACCESS "));
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.
193 * NB - if the directory is unlocked, then this
194 * information cannot be used.
196 cnp->cn_flags |= SAVENAME; /*XXX why? */
198 VOP_UNLOCK(dir_vnode, 0, p);
199 return (EJUSTRETURN);
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 */
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 ".".
214 if (op == DELETE && (flags & ISLASTCN)) {
216 * Write access to directory required to delete files.
218 if ((error = VOP_ACCESS(dir_vnode, VWRITE,
219 cnp->cn_cred, p)) != 0)
222 * we are trying to delete '.'. What does this mean? XXX
224 if (dir_node == new_node) {
226 *result_vnode = dir_vnode;
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.
235 devfs_dntovn(new_node,result_vnode);
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);
246 VOP_UNLOCK(dir_vnode, 0, p);
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.
256 if (op == RENAME && wantparent && (flags & ISLASTCN)) {
258 * Are we allowed to change the holding directory?
260 if ((error = VOP_ACCESS(dir_vnode, VWRITE,
261 cnp->cn_cred, p)) != 0)
264 * Careful about locking second node.
265 * This can only occur if the target is ".".
267 if (dir_node == new_node)
269 devfs_dntovn(new_node,result_vnode);
270 /* hmm save the 'from' name (we need to delete it) */
271 cnp->cn_flags |= SAVENAME;
273 VOP_UNLOCK(dir_vnode, 0, p);
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.
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;
306 devfs_dntovn(new_node,result_vnode);
307 if (!lockparent || (flags & ISLASTCN))
308 VOP_UNLOCK(dir_vnode, 0, p);
319 devfs_access(struct vop_access_args *ap)
320 /*struct vop_access_args {
323 struct ucred *a_cred;
328 * mode is filled with a combination of VREAD, VWRITE,
329 * and/or VEXEC bits turned on. In an octal number these
332 struct vnode *vp = ap->a_vp;
333 int mode = ap->a_mode;
334 struct ucred *cred = ap->a_cred;
340 DBPRINT(("access\n"));
341 if ((error = devfs_vntodn(vp,&file_node)) != 0)
343 printf("devfs_vntodn returned %d ",error);
348 * if we are not running as a process, we are in the
349 * kernel and we DO have permission
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.
359 if (cred->cr_uid != file_node->uid)
361 /* failing that.. try groups */
363 gp = cred->cr_groups;
364 for (i = 0; i < cred->cr_ngroups; i++, gp++)
366 if (file_node->gid == *gp)
371 /* failing that.. try general access */
376 if ((file_node->mode & mode) == mode)
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)
383 if( suser(cred, &ap->a_p->p_acflag) == 0) /* XXX what if no proc? */
389 devfs_getattr(struct vop_getattr_args *ap)
390 /*struct vop_getattr_args {
393 struct ucred *a_cred;
397 struct vnode *vp = ap->a_vp;
398 struct vattr *vap = ap->a_vap;
402 DBPRINT(("getattr\n"));
403 if ((error = devfs_vntodn(vp,&file_node)) != 0)
405 printf("devfs_vntodn returned %d ",error);
408 vap->va_rdev = 0;/* default value only */
409 vap->va_mode = file_node->mode;
410 switch (file_node->type)
413 vap->va_rdev = (dev_t)file_node->dvm;
414 vap->va_mode |= (S_IFDIR);
417 vap->va_rdev = file_node->by.Cdev.dev;
418 vap->va_mode |= (S_IFCHR);
421 vap->va_rdev = file_node->by.Bdev.dev;
422 vap->va_mode |= (S_IFBLK);
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;
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.
440 if(file_node->ctime.tv_sec < (24 * 3600))
442 TIMEVAL_TO_TIMESPEC(&boottime,&(file_node->ctime));
443 TIMEVAL_TO_TIMESPEC(&boottime,&(file_node->mtime));
444 TIMEVAL_TO_TIMESPEC(&boottime,&(file_node->atime));
446 if (file_node->flags & IN_ACCESS) {
447 nanotime(&file_node->atime);
448 file_node->flags &= ~IN_ACCESS;
450 vap->va_ctime = file_node->ctime;
451 vap->va_mtime = file_node->mtime;
452 vap->va_atime = file_node->atime;
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 */
462 devfs_setattr(struct vop_setattr_args *ap)
463 /*struct vop_setattr_args {
466 struct ucred *a_cred;
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;
479 if (vap->va_flags != VNOVAL) /* XXX needs to be implemented */
482 if ((error = devfs_vntodn(vp,&file_node)) != 0)
484 printf("devfs_vntodn returned %d ",error);
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 ))
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.
507 if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
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.
516 if (vp->v_mount->mnt_flag & MNT_RDONLY)
519 if (((vap->va_vaflags & VA_UTIMES_NULL) == 0) &&
520 (cred->cr_uid != file_node->uid) &&
521 suser(cred, &p->p_acflag))
523 if(VOP_ACCESS(vp, VWRITE, cred, p))
525 file_node->atime = vap->va_atime;
526 file_node->mtime = vap->va_mtime;
527 nanotime(&file_node->ctime);
532 * Change the permissions.. must be root or owner to do this.
534 if (vap->va_mode != (u_short)VNOVAL) {
535 if ((cred->cr_uid != file_node->uid)
536 && suser(cred, &p->p_acflag))
538 /* set drwxwxrwx stuff */
539 file_node->mode &= ~07777;
540 file_node->mode |= vap->va_mode & 07777;
544 * Change the owner.. must be root to do this.
546 if (vap->va_uid != (uid_t)VNOVAL) {
547 if (suser(cred, &p->p_acflag))
549 file_node->uid = vap->va_uid;
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.
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)
567 * we can't do it with normal privs,
568 * do we have an ace up our sleeve?
570 if( suser(cred, &p->p_acflag))
573 file_node->gid = vap->va_gid;
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
581 if (vap->va_flags != VNOVAL) {
582 if (error = suser(cred, &p->p_acflag))
584 if (cred->cr_uid == 0)
595 devfs_xread(struct vop_read_args *ap)
596 /*struct vop_read_args {
600 struct ucred *a_cred;
607 if ((error = devfs_vntodn(ap->a_vp,&file_node)) != 0)
609 printf("devfs_vntodn returned %d ",error);
614 switch (ap->a_vp->v_type) {
618 return VOP_READDIR(ap->a_vp,ap->a_uio,ap->a_cred,
622 panic("devfs: vnode methods");
625 panic("devfs_read(): bad file type");
631 * Write data to a file or directory.
634 devfs_xwrite(struct vop_write_args *ap)
635 /*struct vop_write_args {
639 struct ucred *a_cred;
642 switch (ap->a_vp->v_type) {
649 panic("devfs: vnode methods");
651 panic("devfs_write(): bad file type");
657 devfs_remove(struct vop_remove_args *ap)
658 /*struct vop_remove_args {
661 struct componentname *a_cnp;
664 struct vnode *vp = ap->a_vp;
665 struct vnode *dvp = ap->a_dvp;
666 struct componentname *cnp = ap->a_cnp;
669 int doingdirectory = 0;
671 uid_t ouruid = cnp->cn_cred->cr_uid;
674 DBPRINT(("remove\n"));
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
681 if ((error = devfs_vntodn(dvp, &tdp)) != 0) {
683 VOP_ABORTOP(dvp, cnp);
686 if ((error = devfs_vntodn(vp, &tp)) != 0) goto abortit;
688 * Assuming we are atomic, dev_lookup left this for us
690 tnp = tp->last_lookup;
694 * Check we are doing legal things WRT the new flags
696 if ((tp->flags & (IMMUTABLE | APPEND))
697 || (tdp->flags & APPEND) /*XXX eh?*/ ) {
703 * Make sure that we don't try do something stupid
705 if ((tp->type) == DEV_DIR) {
707 * Avoid ".", "..", and aliases of "." for obvious reasons.
709 if ( (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.')
710 || (cnp->cn_flags&ISDOTDOT) ) {
717 /***********************************
718 * Start actually doing things.... *
719 ***********************************/
720 getnanotime(&(tdp->mtime));
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?
729 if ((tdp->mode & S_ISTXT)
731 && ouruid != tdp->uid
732 && ouruid != tp->uid ) {
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).
741 if (( doingdirectory) && (tp->links > 2)) {
742 printf("nlink = %d\n",tp->links); /*XXX*/
754 devfs_link(struct vop_link_args *ap)
755 /*struct vop_link_args {
756 struct vnode *a_tdvp;
758 struct componentname *a_cnp;
761 struct vnode *vp = ap->a_vp;
762 struct vnode *tdvp = ap->a_tdvp;
763 struct componentname *cnp = ap->a_cnp;
770 * First catch an arbitrary restriction for this FS
772 if(cnp->cn_namelen > DEVMAXNAMESIZE) {
773 error = ENAMETOOLONG;
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
783 if ((error = devfs_vntodn(tdvp,&tdp)) != 0) goto abortit;
784 if ((error = devfs_vntodn(vp,&fp)) != 0) goto abortit;
787 * trying to move it out of devfs? (v_tag == VT_DEVFS)
789 if ( (vp->v_tag != VT_DEVFS)
790 || (vp->v_tag != tdvp->v_tag) ) {
793 VOP_ABORTOP(tdvp, cnp);
798 * Check we are doing legal things WRT the new flags
800 if (fp->flags & (IMMUTABLE | APPEND)) {
805 /***********************************
806 * Start actually doing things.... *
807 ***********************************/
808 getnanotime(&(tdp->atime));
809 error = dev_add_name(cnp->cn_nameptr,
820 * Rename system call. Seems overly complicated to me...
821 * rename("foo", "bar");
824 * link("foo", "bar");
826 * but ``atomically''.
828 * When the target exists, both the directory
829 * and target vnodes are locked.
830 * the source and source-parent vnodes are referenced
833 * Basic algorithm is:
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,
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
847 devfs_rename(struct vop_rename_args *ap)
848 /*struct vop_rename_args {
849 struct vnode *a_fdvp;
851 struct componentname *a_fcnp;
852 struct vnode *a_tdvp;
854 struct componentname *a_tcnp;
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;
866 int doingdirectory = 0;
870 * First catch an arbitrary restriction for this FS
872 if(tcnp->cn_namelen > DEVMAXNAMESIZE) {
873 error = ENAMETOOLONG;
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
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;
888 if ((error = devfs_vntodn(tvp,&tp)) != 0) goto abortit;
889 tnp = tp->last_lookup;
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
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 ))) {
907 VOP_ABORTOP(tdvp, tcnp);
908 if (tdvp == tvp) /* eh? */
914 VOP_ABORTOP(fdvp, fcnp); /* XXX, why not in NFS? */
921 * Check we are doing legal things WRT the new flags
923 if ((tp && (tp->flags & (IMMUTABLE | APPEND)))
924 || (fp->flags & (IMMUTABLE | APPEND))
925 || (fdp->flags & APPEND)) {
931 * Make sure that we don't try do something stupid
933 if ((fp->type) == DEV_DIR) {
935 * Avoid ".", "..", and aliases of "." for obvious reasons.
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)
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 "..".
956 if (doingdirectory && (tdp != fdp)) {
958 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_proc);
962 /* XXX unlock stuff here probably */
967 } while ((tmp = tmp->by.Dir.parent) != ntmp);
970 /***********************************
971 * Start actually doing things.... *
972 ***********************************/
973 getnanotime(&(fp->atime));
975 * Check if just deleting a link name.
978 if (fvp->v_type == VDIR) {
983 /* Release destination completely. */
984 VOP_ABORTOP(tdvp, tcnp);
989 VOP_ABORTOP(fdvp, fcnp); /*XXX*/
998 * 1) Bump link count while we're moving stuff
999 * around. If we crash somewhere before
1000 * completing our work, too bad :)
1004 * If the target exists zap it (unless it's a non-empty directory)
1005 * We could do that as well but won't
1008 int ouruid = tcnp->cn_cred->cr_uid;
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?
1016 if ((tdp->mode & S_ISTXT)
1018 && ouruid != tdp->uid
1019 && ouruid != tp->uid ) {
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).
1028 if (( doingdirectory) && (tp->links > 2)) {
1029 printf("nlink = %d\n",tp->links); /*XXX*/
1036 dev_add_name(tcnp->cn_nameptr,tdp,fnp->as.front.realthing,fp,&tnp);
1038 fp->links--; /* one less link to it.. */
1040 fp->links--; /* we added one earlier*/
1053 if (vn_lock(fvp, LK_EXCLUSIVE | LK_RETRY, p) == 0) {
1054 fp->links--; /* we added one earlier*/
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;
1077 DBPRINT(("symlink\n"));
1078 if((error = devfs_vntodn(ap->a_dvp, &dnp)) != 0) {
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,
1086 if((error = devfs_dntovn(nm_p->dnp, &vp)) != 0) {
1089 VOP_SETATTR(vp, ap->a_vap, ap->a_cnp->cn_cred, ap->a_cnp->cn_proc);
1096 * Vnode op for readdir
1099 devfs_readdir(struct vop_readdir_args *ap)
1100 /*struct vop_readdir_args {
1103 struct ucred *a_cred;
1109 struct vnode *vp = ap->a_vp;
1110 struct uio *uio = ap->a_uio;
1111 struct dirent dirent;
1120 DBPRINT(("readdir\n"));
1122 /* set up refs to dir */
1123 if ((error = devfs_vntodn(vp,&dir_node)) != 0)
1125 if(dir_node->type != DEV_DIR)
1129 startpos = uio->uio_offset;
1130 name_node = dir_node->by.Dir.dirlist;
1132 getnanotime(&(dir_node->atime));
1134 while ((name_node || (nodenumber < 2)) && (uio->uio_resid > 0))
1139 dirent.d_fileno = (uintptr_t)(void *)dir_node;
1141 dirent.d_namlen = 1;
1142 dirent.d_type = DT_DIR;
1145 if(dir_node->by.Dir.parent)
1147 = (uintptr_t)(void *)dir_node->by.Dir.parent;
1149 dirent.d_fileno = (uintptr_t)(void *)dir_node;
1151 dirent.d_namlen = 2;
1152 dirent.d_type = DT_DIR;
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) {
1160 dirent.d_type = DT_BLK;
1163 dirent.d_type = DT_CHR;
1166 dirent.d_type = DT_SOCK; /*XXX*/
1169 dirent.d_type = DT_DIR;
1172 dirent.d_type = DT_LNK;
1175 dirent.d_type = DT_UNKNOWN;
1179 reclen = dirent.d_reclen = GENERIC_DIRSIZ(&dirent);
1181 if(pos >= startpos) /* made it to the offset yet? */
1183 if (uio->uio_resid < reclen) /* will it fit? */
1185 strcpy( dirent.d_name,name);
1186 if ((error = uiomove ((caddr_t)&dirent,
1187 dirent.d_reclen, uio)) != 0)
1191 if((nodenumber >1) && name_node)
1192 name_node = name_node->next;
1195 uio->uio_offset = pos;
1204 devfs_readlink(struct vop_readlink_args *ap)
1205 /*struct vop_readlink_args {
1208 struct ucred *a_cred;
1211 struct vnode *vp = ap->a_vp;
1212 struct uio *uio = ap->a_uio;
1217 DBPRINT(("readlink\n"));
1218 /* set up refs to dir */
1219 if ((error = devfs_vntodn(vp,&lnk_node)) != 0)
1221 if(lnk_node->type != DEV_SLNK)
1223 if ((error = VOP_ACCESS(vp, VREAD, ap->a_cred, NULL)) != 0) { /* XXX */
1226 error = uiomove(lnk_node->by.Slnk.name, lnk_node->by.Slnk.namelen, uio);
1232 devfs_abortop(struct vop_abortop_args *ap)
1233 /*struct vop_abortop_args {
1234 struct vnode *a_dvp;
1235 struct componentname *a_cnp;
1238 DBPRINT(("abortop\n"));
1239 if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
1240 zfree(namei_zone, ap->a_cnp->cn_pnbuf);
1247 devfs_reclaim(struct vop_reclaim_args *ap)
1248 /*struct vop_reclaim_args {
1252 dn_p file_node = NULL;
1255 DBPRINT(("reclaim\n"));
1256 if ((error = devfs_vntodn(ap->a_vp,&file_node)) != 0)
1258 printf("devfs_vntodn returned %d ",error);
1262 ap->a_vp->v_data = NULL;
1265 file_node->vn_id = 0;
1271 * Print out the contents of a /devfs vnode.
1274 devfs_print(struct vop_print_args *ap)
1275 /*struct vop_print_args {
1280 printf("tag VT_DEVFS, devfs vnode\n");
1284 /**************************************************************************\
1286 \**************************************************************************/
1290 devfs_dropvnode(dn_p dnp)
1297 printf("devfs: dn count dropped too early\n");
1302 * check if we have a vnode.......
1304 if((vn_p) && ( dnp->vn_id == vn_p->v_id) && (dnp == (dn_p)vn_p->v_data))
1306 VOP_REVOKE(vn_p, REVOKEALL);
1308 dnp->vn = NULL; /* be pedantic about this */
1311 /* struct vnode *speclisth[SPECHSZ];*/ /* till specfs goes away */
1314 * Open a special file.
1315 struct vop_open_args {
1318 struct ucred *a_cred;
1324 devfs_open( struct vop_open_args *ap)
1326 struct proc *p = ap->a_p;
1327 struct vnode *vp = ap->a_vp;
1331 if ((error = devfs_vntodn(vp,&dnp)) != 0)
1334 switch (vp->v_type) {
1336 VOP_UNLOCK(vp, 0, p);
1337 error = (*dnp->by.Cdev.cdevsw->d_open)(
1342 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
1346 error = (*dnp->by.Bdev.bdevsw->d_open)(
1360 struct vop_read_args {
1364 struct ucred *a_cred;
1370 devfs_read( struct vop_read_args *ap)
1372 register struct vnode *vp = ap->a_vp;
1373 register struct uio *uio = ap->a_uio;
1374 struct proc *p = uio->uio_procp;
1378 struct partinfo dpart;
1385 if ((error = devfs_vntodn(vp,&dnp)) != 0)
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");
1395 if (uio->uio_resid == 0)
1398 switch (vp->v_type) {
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);
1408 if (uio->uio_offset < 0)
1410 bsize = BLKDEV_IOSIZE;
1411 dev = dnp->by.Bdev.dev;
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);
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.
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);
1435 error = bread(vp, bn, (int)bsize, NOCRED, &bp);
1437 n = min(n, bsize - bp->b_resid);
1443 * Copy it to the user's space
1445 error = uiomove((char *)bp->b_data + on, n, uio);
1447 } while (error == 0 && uio->uio_resid > 0 && n != 0);
1451 panic("devfs_read type");
1453 if (!(vp->v_mount->mnt_flag & MNT_NOATIME))
1454 dnp->flags |= IN_ACCESS;
1459 * Vnode op for write
1460 struct vop_write_args {
1464 struct ucred *a_cred;
1469 devfs_write( struct vop_write_args *ap)
1471 register struct vnode *vp = ap->a_vp;
1472 register struct uio *uio = ap->a_uio;
1473 struct proc *p = uio->uio_procp;
1477 struct partinfo dpart;
1482 if ((error = devfs_vntodn(vp,&dnp)) != 0)
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");
1493 switch (vp->v_type) {
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);
1503 if (uio->uio_resid == 0)
1505 if (uio->uio_offset < 0)
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;
1516 blkmask = btodb(bsize) - 1;
1518 bn = btodb(uio->uio_offset) & ~blkmask;
1519 on = uio->uio_offset % bsize;
1520 n = min((unsigned)(bsize - on), uio->uio_resid);
1522 bp = getblk(vp, bn, bsize, 0, 0);
1524 error = bread(vp, bn, bsize, NOCRED, &bp);
1529 n = min(n, bsize - bp->b_resid);
1530 error = uiomove((char *)bp->b_data + on, n, uio);
1531 if (n + on == bsize)
1535 } while (error == 0 && uio->uio_resid > 0 && n != 0);
1539 panic("devfs_write type");
1545 * Device ioctl operation.
1546 struct vop_ioctl_args {
1551 struct ucred *a_cred;
1557 devfs_ioctl(struct vop_ioctl_args *ap)
1562 if ((error = devfs_vntodn(ap->a_vp,&dnp)) != 0)
1566 switch (ap->a_vp->v_type) {
1569 return ((*dnp->by.Cdev.cdevsw->d_ioctl)(dnp->by.Cdev.dev,
1575 return ((*dnp->by.Bdev.bdevsw->d_ioctl)(dnp->by.Bdev.dev,
1581 panic("devfs_ioctl");
1587 struct vop_poll_args {
1590 struct ucred *a_cred;
1596 devfs_poll(struct vop_poll_args *ap)
1601 if ((error = devfs_vntodn(ap->a_vp,&dnp)) != 0)
1605 switch (ap->a_vp->v_type) {
1608 return (*dnp->by.Cdev.cdevsw->d_poll)(dnp->by.Cdev.dev,
1612 return (vop_defaultop((struct vop_generic_args *)ap));
1617 * Synch buffers associated with a block device
1618 struct vop_fsync_args {
1620 struct ucred *a_cred;
1627 devfs_fsync(struct vop_fsync_args *ap)
1629 register struct vnode *vp = ap->a_vp;
1630 register struct buf *bp;
1636 if ((error = devfs_vntodn(vp,&dnp)) != 0)
1640 if (vp->v_type == VCHR)
1643 * Flush all dirty buffers associated with a block device.
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))
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)) {
1658 bp->b_flags |= B_BUSY;
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);
1670 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd)) {
1671 vprint("devfs_fsync: dirty", vp);
1682 * struct vop_inactive_args {
1683 * struct vnode *a_vp;
1689 devfs_inactive(struct vop_inactive_args *ap)
1692 VOP_UNLOCK(ap->a_vp, 0, ap->a_p);
1697 * Just call the device strategy routine
1698 struct vop_strategy_args {
1704 devfs_strategy(struct vop_strategy_args *ap)
1706 struct buf *bp = ap->a_bp;
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)
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) {
1722 (*dnp->by.Cdev.cdevsw->d_strategy)(bp);
1725 (*dnp->by.Bdev.bdevsw->d_strategy)(bp);
1728 /* XXX set error code? */
1735 * This is a noop, simply returning what one has been given.
1736 struct vop_bmap_args {
1739 struct vnode **a_vpp;
1746 devfs_bmap(struct vop_bmap_args *ap)
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)
1755 if (ap->a_runb != NULL)
1761 * Device close routine
1762 struct vop_close_args {
1765 struct ucred *a_cred;
1771 devfs_close(struct vop_close_args *ap)
1773 register struct vnode *vp = ap->a_vp;
1777 if ((error = devfs_vntodn(vp,&dnp)) != 0)
1781 switch (vp->v_type) {
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.
1793 if (vcount(vp) == 2 && ap->a_p &&
1794 (vp->v_flag & VXLOCK) == 0 &&
1795 vp == ap->a_p->p_session->s_ttyvp) {
1797 ap->a_p->p_session->s_ttyvp = NULL;
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.
1804 if (vcount(vp) > 1 && (vp->v_flag & VXLOCK) == 0)
1806 return ((*dnp->by.Cdev.cdevsw->d_close)(dnp->by.Cdev.dev,
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.
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);
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.
1832 if ((vcount(vp) > 1) && (vp->v_flag & VXLOCK) == 0)
1835 return ((*dnp->by.Bdev.bdevsw->d_close)(dnp->by.Bdev.dev,
1841 panic("devfs_close: not special");
1846 * Print out the contents of a special device vnode.
1847 struct vop_print_args {
1853 * Special device advisory byte-level locks.
1854 struct vop_advlock_args {
1864 devfs_advlock(struct vop_advlock_args *ap)
1867 return (ap->a_flags & F_FLOCK ? EOPNOTSUPP : EINVAL);
1871 * Special device bad operation
1877 panic("devfs_badop called");
1882 devfs_getpages_iodone(struct buf *bp)
1885 bp->b_flags |= B_DONE;
1890 devfs_getpages(struct vop_getpages_args *ap)
1894 int i, pcount, size, s;
1898 vm_ooffset_t offset;
1899 int toff, nextoff, nread;
1900 struct vnode *vp = ap->a_vp;
1905 pcount = round_page(ap->a_count) / PAGE_SIZE;
1908 * Calculate the offset of the transfer.
1910 offset = IDX_TO_OFF(ap->a_m[0]->pindex) + ap->a_offset;
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);
1924 blkno = btodb(offset);
1927 * Round up physical size for real devices, use the
1928 * fundamental blocksize of the fs if possible.
1930 if (vp && vp->v_mount) {
1931 if (vp->v_type != VBLK) {
1932 vprint("Non VBLK", vp);
1934 blksiz = vp->v_mount->mnt_stat.f_bsize;
1935 if (blksiz < DEV_BSIZE) {
1941 size = (ap->a_count + blksiz - 1) & ~(blksiz - 1);
1944 kva = (vm_offset_t)bp->b_data;
1947 * Map the pages to be read into the kva.
1949 pmap_qenter(kva, ap->a_m, pcount);
1951 /* Build a minimal buffer header. */
1952 bp->b_flags = B_BUSY | B_READ | B_CALL;
1953 bp->b_iodone = devfs_getpages_iodone;
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;
1970 cnt.v_vnodepgsin += pcount;
1973 VOP_STRATEGY(bp->b_vp, bp);
1977 /* We definitely need to be at splbio here. */
1978 while ((bp->b_flags & B_DONE) == 0)
1979 tsleep(bp, PVM, "spread", 0);
1983 if ((bp->b_flags & B_ERROR) != 0) {
1985 error = bp->b_error;
1990 nread = size - bp->b_resid;
1992 if (nread < ap->a_count) {
1993 bzero((caddr_t)kva + nread,
1994 ap->a_count - nread);
1996 pmap_qremove(kva, pcount);
2000 for (i = 0, toff = 0; i < pcount; i++, toff = nextoff) {
2001 nextoff = toff + PAGE_SIZE;
2004 m->flags &= ~PG_ZERO;
2006 if (nextoff <= nread) {
2007 m->valid = VM_PAGE_BITS_ALL;
2009 } else if (toff < nread) {
2010 int nvalid = ((nread + DEV_BSIZE - 1) - toff) & ~(DEV_BSIZE - 1);
2011 vm_page_set_validclean(m, 0, nvalid);
2017 if (i != ap->a_reqpage) {
2019 * Just in case someone was asking for this page we
2020 * now tell them that it is ok to use.
2022 if (!error || (m->valid == VM_PAGE_BITS_ALL)) {
2024 if (m->flags & PG_WANTED) {
2025 vm_page_activate(m);
2027 vm_page_deactivate(m);
2036 } else if (m->valid) {
2041 m = ap->a_m[ap->a_reqpage];
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);
2050 * Free the buffer header back to the swap buffer pool.
2053 return VM_PAGER_ERROR;
2056 * Free the buffer header back to the swap buffer pool.
2064 /* These are the operations used by directories etc in a devfs */
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 },
2088 static struct vnodeopv_desc devfs_vnodeop_opv_desc =
2089 { &devfs_vnodeop_p, devfs_vnodeop_entries };
2091 VNODEOP_SET(devfs_vnodeop_opv_desc);
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 },
2131 static struct vnodeopv_desc devfs_spec_vnodeop_opv_desc =
2132 { &devfs_spec_vnodeop_p, devfs_spec_vnodeop_entries };
2134 VNODEOP_SET(devfs_spec_vnodeop_opv_desc);