Annotation of XNU/bsd/miscfs/deadfs/dead_vnops.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * The contents of this file constitute Original Code as defined in and
                      7:  * are subject to the Apple Public Source License Version 1.1 (the
                      8:  * "License").  You may not use this file except in compliance with the
                      9:  * License.  Please obtain a copy of the License at
                     10:  * http://www.apple.com/publicsource and read it before using this file.
                     11:  * 
                     12:  * This Original Code and all software distributed under the License are
                     13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     17:  * License for the specific language governing rights and limitations
                     18:  * under the License.
                     19:  * 
                     20:  * @APPLE_LICENSE_HEADER_END@
                     21:  */
                     22: /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
                     23: /*
                     24:  * Copyright (c) 1989, 1993
                     25:  *     The Regents of the University of California.  All rights reserved.
                     26:  *
                     27:  * Redistribution and use in source and binary forms, with or without
                     28:  * modification, are permitted provided that the following conditions
                     29:  * are met:
                     30:  * 1. Redistributions of source code must retain the above copyright
                     31:  *    notice, this list of conditions and the following disclaimer.
                     32:  * 2. Redistributions in binary form must reproduce the above copyright
                     33:  *    notice, this list of conditions and the following disclaimer in the
                     34:  *    documentation and/or other materials provided with the distribution.
                     35:  * 3. All advertising materials mentioning features or use of this software
                     36:  *    must display the following acknowledgement:
                     37:  *     This product includes software developed by the University of
                     38:  *     California, Berkeley and its contributors.
                     39:  * 4. Neither the name of the University nor the names of its contributors
                     40:  *    may be used to endorse or promote products derived from this software
                     41:  *    without specific prior written permission.
                     42:  *
                     43:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     44:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     45:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     46:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     47:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     48:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     49:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     50:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     51:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     52:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     53:  * SUCH DAMAGE.
                     54:  *
                     55:  *     @(#)dead_vnops.c        8.3 (Berkeley) 5/14/95
                     56:  */
                     57: 
                     58: #include <sys/param.h>
                     59: #include <sys/systm.h>
                     60: #include <sys/time.h>
                     61: #include <sys/vnode.h>
                     62: #include <sys/errno.h>
                     63: #include <sys/namei.h>
                     64: #include <sys/buf.h>
                     65: #include <vfs/vfs_support.h>
                     66: 
                     67: /*
                     68:  * Prototypes for dead operations on vnodes.
                     69:  */
                     70: int    dead_badop(),
                     71:        dead_ebadf();
                     72: int    dead_lookup __P((struct vop_lookup_args *));
                     73: #define dead_create ((int (*) __P((struct  vop_create_args *)))dead_badop)
                     74: #define dead_mknod ((int (*) __P((struct  vop_mknod_args *)))dead_badop)
                     75: int    dead_open __P((struct vop_open_args *));
                     76: #define dead_close ((int (*) __P((struct  vop_close_args *)))nullop)
                     77: #define dead_access ((int (*) __P((struct  vop_access_args *)))dead_ebadf)
                     78: #define dead_getattr ((int (*) __P((struct  vop_getattr_args *)))dead_ebadf)
                     79: #define dead_setattr ((int (*) __P((struct  vop_setattr_args *)))dead_ebadf)
                     80: int    dead_read __P((struct vop_read_args *));
                     81: int    dead_write __P((struct vop_write_args *));
                     82: int    dead_ioctl __P((struct vop_ioctl_args *));
                     83: int    dead_select __P((struct vop_select_args *));
                     84: #define dead_mmap ((int (*) __P((struct  vop_mmap_args *)))dead_badop)
                     85: #define dead_fsync ((int (*) __P((struct  vop_fsync_args *)))nullop)
                     86: #define dead_seek ((int (*) __P((struct  vop_seek_args *)))nullop)
                     87: #define dead_remove ((int (*) __P((struct  vop_remove_args *)))dead_badop)
                     88: #define dead_link ((int (*) __P((struct  vop_link_args *)))dead_badop)
                     89: #define dead_rename ((int (*) __P((struct  vop_rename_args *)))dead_badop)
                     90: #define dead_mkdir ((int (*) __P((struct  vop_mkdir_args *)))dead_badop)
                     91: #define dead_rmdir ((int (*) __P((struct  vop_rmdir_args *)))dead_badop)
                     92: #define dead_symlink ((int (*) __P((struct  vop_symlink_args *)))dead_badop)
                     93: #define dead_readdir ((int (*) __P((struct  vop_readdir_args *)))dead_ebadf)
                     94: #define dead_readlink ((int (*) __P((struct  vop_readlink_args *)))dead_ebadf)
                     95: #define dead_abortop ((int (*) __P((struct  vop_abortop_args *)))dead_badop)
                     96: #define dead_inactive ((int (*) __P((struct  vop_inactive_args *)))nullop)
                     97: #define dead_reclaim ((int (*) __P((struct  vop_reclaim_args *)))nullop)
                     98: int    dead_lock __P((struct vop_lock_args *));
                     99: #define dead_unlock ((int (*) __P((struct  vop_unlock_args *)))nullop)
                    100: int    dead_bmap __P((struct vop_bmap_args *));
                    101: int    dead_strategy __P((struct vop_strategy_args *));
                    102: int    dead_print __P((struct vop_print_args *));
                    103: #define dead_islocked ((int (*) __P((struct  vop_islocked_args *)))nullop)
                    104: #define dead_pathconf ((int (*) __P((struct  vop_pathconf_args *)))dead_ebadf)
                    105: #define dead_advlock ((int (*) __P((struct  vop_advlock_args *)))dead_ebadf)
                    106: #define dead_blkatoff ((int (*) __P((struct  vop_blkatoff_args *)))dead_badop)
                    107: #define dead_valloc ((int (*) __P((struct  vop_valloc_args *)))dead_badop)
                    108: #define dead_vfree ((int (*) __P((struct  vop_vfree_args *)))dead_badop)
                    109: #define dead_truncate ((int (*) __P((struct  vop_truncate_args *)))nullop)
                    110: #define dead_update ((int (*) __P((struct  vop_update_args *)))nullop)
                    111: #define dead_bwrite ((int (*) __P((struct  vop_bwrite_args *)))nullop)
                    112: int    dead_pagein __P((struct vop_pagein_args *));
                    113: int    dead_pageout __P((struct vop_pageout_args *));
                    114: 
                    115: int (**dead_vnodeop_p)();
                    116: struct vnodeopv_entry_desc dead_vnodeop_entries[] = {
                    117:        { &vop_default_desc, vn_default_error },
                    118:        { &vop_lookup_desc, dead_lookup },      /* lookup */
                    119:        { &vop_create_desc, dead_create },      /* create */
                    120:        { &vop_mknod_desc, dead_mknod },        /* mknod */
                    121:        { &vop_open_desc, dead_open },  /* open */
                    122:        { &vop_close_desc, dead_close },        /* close */
                    123:        { &vop_access_desc, dead_access },      /* access */
                    124:        { &vop_getattr_desc, dead_getattr },    /* getattr */
                    125:        { &vop_setattr_desc, dead_setattr },    /* setattr */
                    126:        { &vop_read_desc, dead_read },  /* read */
                    127:        { &vop_write_desc, dead_write },        /* write */
                    128:        { &vop_ioctl_desc, dead_ioctl },        /* ioctl */
                    129:        { &vop_select_desc, dead_select },      /* select */
                    130:        { &vop_mmap_desc, dead_mmap },  /* mmap */
                    131:        { &vop_fsync_desc, dead_fsync },        /* fsync */
                    132:        { &vop_seek_desc, dead_seek },  /* seek */
                    133:        { &vop_remove_desc, dead_remove },      /* remove */
                    134:        { &vop_link_desc, dead_link },  /* link */
                    135:        { &vop_rename_desc, dead_rename },      /* rename */
                    136:        { &vop_mkdir_desc, dead_mkdir },        /* mkdir */
                    137:        { &vop_rmdir_desc, dead_rmdir },        /* rmdir */
                    138:        { &vop_symlink_desc, dead_symlink },    /* symlink */
                    139:        { &vop_readdir_desc, dead_readdir },    /* readdir */
                    140:        { &vop_readlink_desc, dead_readlink },  /* readlink */
                    141:        { &vop_abortop_desc, dead_abortop },    /* abortop */
                    142:        { &vop_inactive_desc, dead_inactive },  /* inactive */
                    143:        { &vop_reclaim_desc, dead_reclaim },    /* reclaim */
                    144:        { &vop_lock_desc, dead_lock },  /* lock */
                    145:        { &vop_unlock_desc, dead_unlock },      /* unlock */
                    146:        { &vop_bmap_desc, dead_bmap },  /* bmap */
                    147:        { &vop_strategy_desc, dead_strategy },  /* strategy */
                    148:        { &vop_print_desc, dead_print },        /* print */
                    149:        { &vop_islocked_desc, dead_islocked },  /* islocked */
                    150:        { &vop_pathconf_desc, dead_pathconf },  /* pathconf */
                    151:        { &vop_advlock_desc, dead_advlock },    /* advlock */
                    152:        { &vop_blkatoff_desc, dead_blkatoff },  /* blkatoff */
                    153:        { &vop_valloc_desc, dead_valloc },      /* valloc */
                    154:        { &vop_vfree_desc, dead_vfree },        /* vfree */
                    155:        { &vop_truncate_desc, dead_truncate },  /* truncate */
                    156:        { &vop_update_desc, dead_update },      /* update */
                    157:        { &vop_bwrite_desc, dead_bwrite },      /* bwrite */
                    158:        { &vop_pagein_desc, dead_pagein },      /* Pagein */
                    159:        { &vop_pageout_desc, dead_pageout },    /* Pageout */
                    160:         { &vop_copyfile_desc, err_copyfile },        /* Copyfile */
                    161:        { (struct vnodeop_desc*)NULL, (int(*)())NULL }
                    162: };
                    163: struct vnodeopv_desc dead_vnodeop_opv_desc =
                    164:        { &dead_vnodeop_p, dead_vnodeop_entries };
                    165: 
                    166: /*
                    167:  * Trivial lookup routine that always fails.
                    168:  */
                    169: /* ARGSUSED */
                    170: int
                    171: dead_lookup(ap)
                    172:        struct vop_lookup_args /* {
                    173:                struct vnode * a_dvp;
                    174:                struct vnode ** a_vpp;
                    175:                struct componentname * a_cnp;
                    176:        } */ *ap;
                    177: {
                    178: 
                    179:        *ap->a_vpp = NULL;
                    180:        return (ENOTDIR);
                    181: }
                    182: 
                    183: /*
                    184:  * Open always fails as if device did not exist.
                    185:  */
                    186: /* ARGSUSED */
                    187: dead_open(ap)
                    188:        struct vop_open_args /* {
                    189:                struct vnode *a_vp;
                    190:                int  a_mode;
                    191:                struct ucred *a_cred;
                    192:                struct proc *a_p;
                    193:        } */ *ap;
                    194: {
                    195: 
                    196:        return (ENXIO);
                    197: }
                    198: 
                    199: /*
                    200:  * Vnode op for read
                    201:  */
                    202: /* ARGSUSED */
                    203: dead_read(ap)
                    204:        struct vop_read_args /* {
                    205:                struct vnode *a_vp;
                    206:                struct uio *a_uio;
                    207:                int  a_ioflag;
                    208:                struct ucred *a_cred;
                    209:        } */ *ap;
                    210: {
                    211: 
                    212:        if (chkvnlock(ap->a_vp))
                    213:                panic("dead_read: lock");
                    214:        /*
                    215:         * Return EOF for character devices, EIO for others
                    216:         */
                    217:        if (ap->a_vp->v_type != VCHR)
                    218:                return (EIO);
                    219:        return (0);
                    220: }
                    221: 
                    222: /*
                    223:  * Vnode op for write
                    224:  */
                    225: /* ARGSUSED */
                    226: dead_write(ap)
                    227:        struct vop_write_args /* {
                    228:                struct vnode *a_vp;
                    229:                struct uio *a_uio;
                    230:                int  a_ioflag;
                    231:                struct ucred *a_cred;
                    232:        } */ *ap;
                    233: {
                    234: 
                    235:        if (chkvnlock(ap->a_vp))
                    236:                panic("dead_write: lock");
                    237:        return (EIO);
                    238: }
                    239: 
                    240: /*
                    241:  * Device ioctl operation.
                    242:  */
                    243: /* ARGSUSED */
                    244: dead_ioctl(ap)
                    245:        struct vop_ioctl_args /* {
                    246:                struct vnode *a_vp;
                    247:                u_long a_command;
                    248:                caddr_t  a_data;
                    249:                int  a_fflag;
                    250:                struct ucred *a_cred;
                    251:                struct proc *a_p;
                    252:        } */ *ap;
                    253: {
                    254: 
                    255:        if (!chkvnlock(ap->a_vp))
                    256:                return (EBADF);
                    257:        return (VCALL(ap->a_vp, VOFFSET(vop_ioctl), ap));
                    258: }
                    259: 
                    260: /* ARGSUSED */
                    261: dead_select(ap)
                    262:        struct vop_select_args /* {
                    263:                struct vnode *a_vp;
                    264:                int  a_which;
                    265:                int  a_fflags;
                    266:                struct ucred *a_cred;
                    267:                struct proc *a_p;
                    268:        } */ *ap;
                    269: {
                    270: 
                    271:        /*
                    272:         * Let the user find out that the descriptor is gone.
                    273:         */
                    274:        return (1);
                    275: }
                    276: 
                    277: /*
                    278:  * Just call the device strategy routine
                    279:  */
                    280: dead_strategy(ap)
                    281:        struct vop_strategy_args /* {
                    282:                struct buf *a_bp;
                    283:        } */ *ap;
                    284: {
                    285: 
                    286:        if (ap->a_bp->b_vp == NULL || !chkvnlock(ap->a_bp->b_vp)) {
                    287:                ap->a_bp->b_flags |= B_ERROR;
                    288:                biodone(ap->a_bp);
                    289:                return (EIO);
                    290:        }
                    291:        return (VOP_STRATEGY(ap->a_bp));
                    292: }
                    293: 
                    294: /*
                    295:  * Wait until the vnode has finished changing state.
                    296:  */
                    297: dead_lock(ap)
                    298:        struct vop_lock_args /* {
                    299:                struct vnode *a_vp;
                    300:        } */ *ap;
                    301: {
                    302: 
                    303:        struct vnode *vp = ap->a_vp;
                    304: 
                    305:        /*
                    306:         * Since we are not using the lock manager, we must clear
                    307:         * the interlock here.
                    308:         */
                    309:        if (ap->a_flags & LK_INTERLOCK) {
                    310:                simple_unlock(&vp->v_interlock);
                    311:                ap->a_flags &= ~LK_INTERLOCK;
                    312:        }
                    313:        if (!chkvnlock(ap->a_vp))
                    314:                return (0);
                    315:        return (VCALL(ap->a_vp, VOFFSET(vop_lock), ap));
                    316: }
                    317: 
                    318: /*
                    319:  * Wait until the vnode has finished changing state.
                    320:  */
                    321: dead_bmap(ap)
                    322:        struct vop_bmap_args /* {
                    323:                struct vnode *a_vp;
                    324:                daddr_t  a_bn;
                    325:                struct vnode **a_vpp;
                    326:                daddr_t *a_bnp;
                    327:                int *a_runp;
                    328:        } */ *ap;
                    329: {
                    330: 
                    331:        if (!chkvnlock(ap->a_vp))
                    332:                return (EIO);
                    333:        return (VOP_BMAP(ap->a_vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp));
                    334: }
                    335: 
                    336: /*
                    337:  * Print out the contents of a dead vnode.
                    338:  */
                    339: /* ARGSUSED */
                    340: dead_print(ap)
                    341:        struct vop_print_args /* {
                    342:                struct vnode *a_vp;
                    343:        } */ *ap;
                    344: {
                    345: 
                    346:        printf("tag VT_NON, dead vnode\n");
                    347: }
                    348: 
                    349: /*
                    350:  * Empty vnode failed operation
                    351:  */
                    352: dead_ebadf()
                    353: {
                    354: 
                    355:        return (EBADF);
                    356: }
                    357: 
                    358: /*
                    359:  * Empty vnode bad operation
                    360:  */
                    361: dead_badop()
                    362: {
                    363: 
                    364:        panic("dead_badop called");
                    365:        /* NOTREACHED */
                    366: }
                    367: 
                    368: /*
                    369:  * Empty vnode null operation
                    370:  */
                    371: dead_nullop()
                    372: {
                    373: 
                    374:        return (0);
                    375: }
                    376: 
                    377: /*
                    378:  * We have to wait during times when the vnode is
                    379:  * in a state of change.
                    380:  */
                    381: chkvnlock(vp)
                    382:        register struct vnode *vp;
                    383: {
                    384:        int locked = 0;
                    385: 
                    386:        while (vp->v_flag & VXLOCK) {
                    387:                vp->v_flag |= VXWANT;
                    388:                sleep((caddr_t)vp, PINOD);
                    389:                locked = 1;
                    390:        }
                    391:        return (locked);
                    392: }
                    393: /* Pagein  */
                    394: dead_pagein(ap)
                    395:        struct vop_pagein_args /* {
                    396:                struct vnode *a_vp;
                    397:                struct uio *a_uio;
                    398:                int a_ioflag;
                    399:                struct ucred *a_cred;
                    400:        } */ *ap;
                    401: {
                    402:        /* pass thru to read */ 
                    403:        return (VOP_READ(ap->a_vp, ap->a_uio, ap->a_ioflag, ap->a_cred));
                    404: }
                    405: 
                    406: /* Pageout  */
                    407: dead_pageout(ap)
                    408:        struct vop_pageout_args /* {
                    409:                struct vnode *a_vp;
                    410:                struct uio *a_uio;
                    411:                int a_ioflag;
                    412:                struct ucred *a_cred;
                    413:        } */ *ap;
                    414: {
                    415:        /* pass thru to write */ 
                    416:        return (VOP_WRITE(ap->a_vp, ap->a_uio, ap->a_ioflag, ap->a_cred));
                    417: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.