[BACK]Return to xfs_vnodeops-bsd.c CVS log [TXT][DIR] Up to [local] / sys / xfs

Annotation of sys/xfs/xfs_vnodeops-bsd.c, Revision 1.1.1.1

1.1       nbrk        1: /*
                      2:  * Copyright (c) 1995 - 2002 Kungliga Tekniska Högskolan
                      3:  * (Royal Institute of Technology, Stockholm, Sweden).
                      4:  * All rights reserved.
                      5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  *
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  *
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  *
                     17:  * 3. Neither the name of the Institute nor the names of its contributors
                     18:  *    may be used to endorse or promote products derived from this software
                     19:  *    without specific prior written permission.
                     20:  *
                     21:  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
                     22:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     23:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     24:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
                     25:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     26:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     27:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     28:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     29:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     30:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     31:  * SUCH DAMAGE.
                     32:  */
                     33:
                     34: /*
                     35:  * NNPFS operations.
                     36:  */
                     37:
                     38: #ifdef __APPLE__
                     39: #define MACH_KERNEL 1
                     40: #endif
                     41:
                     42: #include <xfs/xfs_locl.h>
                     43: #include <xfs/xfs_message.h>
                     44: #include <xfs/xfs_common.h>
                     45: #include <xfs/xfs_fs.h>
                     46: #include <xfs/xfs_dev.h>
                     47: #include <xfs/xfs_deb.h>
                     48: #include <xfs/xfs_syscalls.h>
                     49: #include <xfs/xfs_vnodeops.h>
                     50: #ifdef HAVE_VM_VNODE_PAGER_H
                     51: #include <vm/vnode_pager.h>
                     52: #endif
                     53:
                     54: #include <sys/pool.h>
                     55:
                     56: RCSID("$arla: xfs_vnodeops-bsd.c,v 1.123 2003/02/15 16:40:36 lha Exp $");
                     57:
                     58: /*
                     59:  * vnode functions
                     60:  */
                     61:
                     62: #ifdef HAVE_VOP_OPEN
                     63: int
                     64: xfs_open(struct vop_open_args * ap)
                     65:      /*
                     66:   struct vop_open {
                     67:           struct vnode *vp;
                     68:           int mode;
                     69:           struct ucred *cred;
                     70:           struct proc *p;
                     71:   }; */
                     72: {
                     73: #ifdef HAVE_FREEBSD_THREAD
                     74:     return xfs_open_common (ap->a_vp, ap->a_mode, ap->a_cred, ap->a_td);
                     75: #else
                     76:     return xfs_open_common (ap->a_vp, ap->a_mode, ap->a_cred, ap->a_p);
                     77: #endif
                     78: }
                     79: #endif /* HAVE_VOP_OPEN */
                     80:
                     81: #ifdef HAVE_VOP_FSYNC
                     82: int
                     83: xfs_fsync(struct vop_fsync_args * ap)
                     84:      /*
                     85:   vop_fsync {
                     86:        struct vnode *vp;
                     87:        struct ucred *cred;
                     88:        int waitfor;
                     89:        struct proc *p;
                     90: };  */
                     91: {
                     92: #ifdef HAVE_STRUCT_VOP_FSYNC_ARGS_A_FLAGS
                     93:     return xfs_fsync_common(ap->a_vp, ap->a_cred, ap->a_flags, ap->a_p);
                     94: #else
                     95: #ifdef HAVE_FREEBSD_THREAD
                     96:     return xfs_fsync_common(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_td);
                     97: #else
                     98:     return xfs_fsync_common(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_p);
                     99: #endif
                    100: #endif
                    101: }
                    102: #endif /* HAVE_VOP_FSYNC */
                    103:
                    104: #ifdef HAVE_VOP_CLOSE
                    105: int
                    106: xfs_close(struct vop_close_args * ap)
                    107:      /* vop_close {
                    108:        IN struct vnode *vp;
                    109:        IN int fflag;
                    110:        IN struct ucred *cred;
                    111:        IN struct proc *p;
                    112:   }; */
                    113: {
                    114: #ifdef HAVE_FREEBSD_THREAD
                    115:     return xfs_close_common(ap->a_vp, ap->a_fflag, ap->a_td, ap->a_cred);
                    116: #else
                    117:     return xfs_close_common(ap->a_vp, ap->a_fflag, ap->a_p, ap->a_cred);
                    118: #endif
                    119: }
                    120: #endif /* HAVE_VOP_CLOSE */
                    121:
                    122: #ifdef HAVE_VOP_READ
                    123: int
                    124: xfs_read(struct vop_read_args * ap)
                    125:      /* vop_read {
                    126:        IN struct vnode *vp;
                    127:        INOUT struct uio *uio;
                    128:        IN int ioflag;
                    129:        IN struct ucred *cred;
                    130:    }; */
                    131: {
                    132:     return xfs_read_common(ap->a_vp, ap->a_uio, ap->a_ioflag, ap->a_cred);
                    133: }
                    134: #endif /* HAVE_VOP_READ */
                    135:
                    136: #ifdef HAVE_VOP_WRITE
                    137: int
                    138: xfs_write(struct vop_write_args * ap)
                    139:      /* vop_write {
                    140:        IN struct vnode *vp;
                    141:        INOUT struct uio *uio;
                    142:        IN int ioflag;
                    143:        IN struct ucred *cred;
                    144:    }; */
                    145: {
                    146:     return xfs_write_common(ap->a_vp, ap->a_uio, ap->a_ioflag, ap->a_cred);
                    147: }
                    148: #endif /* HAVE_VOP_WRITE */
                    149:
                    150: #ifdef HAVE_VOP_IOCTL
                    151: int
                    152: xfs_ioctl(struct vop_ioctl_args * ap)
                    153:      /* struct vnode *vp,
                    154:          int com,
                    155:          caddr_t data,
                    156:          int flag,
                    157:          struct ucred *cred) */
                    158: {
                    159:     NNPFSDEB(XDEBVNOPS, ("xfs_ioctl\n"));
                    160:
                    161:     return EOPNOTSUPP;
                    162: }
                    163: #endif /* HAVE_VOP_IOCTL */
                    164:
                    165: #ifdef HAVE_VOP_SELECT
                    166: int
                    167: xfs_select(struct vop_select_args * ap)
                    168:      /* struct vnode *vp,
                    169:           int which,
                    170:           struct ucred *cred ) */
                    171: {
                    172:     NNPFSDEB(XDEBVNOPS, ("xfs_select\n"));
                    173:
                    174:     return EOPNOTSUPP;
                    175: }
                    176: #endif /* HAVE_VOP_SELECT */
                    177:
                    178: #ifdef HAVE_VOP_SEEK
                    179: int
                    180: xfs_seek(struct vop_seek_args * ap)
                    181:      /*
                    182: struct vop_seek_args {
                    183:         struct vnodeop_desc *a_desc;
                    184:         struct vnode *a_vp;
                    185:         off_t a_oldoff;
                    186:         off_t a_newoff;
                    187:         struct ucred *a_cred;
                    188: };
                    189: */
                    190: {
                    191:     NNPFSDEB(XDEBVNOPS, ("xfs_seek\n"));
                    192:     return 0;
                    193: }
                    194: #endif /* HAVE_VOP_SEEK */
                    195:
                    196: #ifdef HAVE_VOP_POLL
                    197: int
                    198: xfs_poll(struct vop_poll_args * ap)
                    199:      /* vop_poll {
                    200:        IN struct vnode *vp;
                    201:        IN int events;
                    202:        IN struct proc *p;
                    203:    }; */
                    204: {
                    205:     NNPFSDEB(XDEBVNOPS, ("xfs_poll\n"));
                    206:     return EOPNOTSUPP;
                    207: }
                    208: #endif /* HAVE_VOP_POLL */
                    209:
                    210: #ifdef HAVE_VOP_GETATTR
                    211: int
                    212: xfs_getattr(struct vop_getattr_args * ap)
                    213:      /* struct vnode *vp,
                    214:            struct vattr *vap,
                    215:            struct ucred *cred,
                    216:            struct proc *p) */
                    217: {
                    218: #ifdef HAVE_FREEBSD_THREAD
                    219:     return xfs_getattr_common(ap->a_vp, ap->a_vap, ap->a_cred, ap->a_td);
                    220: #else
                    221:     return xfs_getattr_common(ap->a_vp, ap->a_vap, ap->a_cred, ap->a_p);
                    222: #endif
                    223: }
                    224: #endif /* HAVE_VOP_GETATTR */
                    225:
                    226: #ifdef HAVE_VOP_SETATTR
                    227: int
                    228: xfs_setattr(struct vop_setattr_args * ap)
                    229:      /* struct vnode *vp,
                    230:            struct vattr *vap,
                    231:            struct ucred *cred,
                    232:            struct proc *p)
                    233:            */
                    234: {
                    235: #ifdef HAVE_FREEBSD_THREAD
                    236:     return xfs_setattr_common(ap->a_vp, ap->a_vap, ap->a_cred, ap->a_td);
                    237: #else
                    238:     return xfs_setattr_common(ap->a_vp, ap->a_vap, ap->a_cred, ap->a_p);
                    239: #endif
                    240: }
                    241: #endif /* HAVE_VOP_SETATTR */
                    242:
                    243: #ifdef HAVE_VOP_ACCESS
                    244: int
                    245: xfs_access(struct vop_access_args * ap)
                    246:      /*
                    247: struct vnode *vp,
                    248:           int mode,
                    249:           struct ucred *cred,
                    250:           struct proc *p)
                    251:           */
                    252: {
                    253: #ifdef HAVE_FREEBSD_THREAD
                    254:     return xfs_access_common(ap->a_vp, ap->a_mode, ap->a_cred, ap->a_td);
                    255: #else
                    256:     return xfs_access_common(ap->a_vp, ap->a_mode, ap->a_cred, ap->a_p);
                    257: #endif
                    258: }
                    259: #endif /* HAVE_VOP_ACCESS */
                    260:
                    261: #ifdef HAVE_VOP_LOOKUP
                    262: int
                    263: xfs_lookup(struct vop_lookup_args * ap)
                    264:      /* struct vop_lookup_args {
                    265:        struct vnodeop_desc *a_desc;
                    266:        struct vnode *a_dvp;
                    267:        struct vnode **a_vpp;
                    268:        struct componentname *a_cnp;
                    269: }; */
                    270: {
                    271:     struct componentname *cnp = ap->a_cnp;
                    272:     int error;
                    273:     int lockparent = (cnp->cn_flags & (LOCKPARENT | ISLASTCN))
                    274:        == (LOCKPARENT | ISLASTCN);
                    275:
                    276:     NNPFSDEB(XDEBVNOPS, ("xfs_lookup: (%s, %ld), nameiop = %lu, flags = %lu\n",
                    277:                       cnp->cn_nameptr,
                    278:                       cnp->cn_namelen,
                    279:                       cnp->cn_nameiop,
                    280:                       cnp->cn_flags));
                    281:
                    282: #ifdef PDIRUNLOCK
                    283:     cnp->cn_flags &= ~PDIRUNLOCK;
                    284: #endif
                    285:
                    286:     error = xfs_lookup_common(ap->a_dvp, cnp, ap->a_vpp);
                    287:
                    288:     if (error == ENOENT
                    289:        && (cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME)
                    290:        && (cnp->cn_flags & ISLASTCN)) {
                    291:        error = EJUSTRETURN;
                    292:     }
                    293:
                    294:     if (cnp->cn_nameiop != LOOKUP && cnp->cn_flags & ISLASTCN)
                    295:        cnp->cn_flags |= SAVENAME;
                    296:
                    297:     if (error == 0 || error == EJUSTRETURN) {
                    298:        if (ap->a_dvp == *(ap->a_vpp)) {
                    299:            /* if we looked up ourself, do nothing */
                    300:        } else if (!(cnp->cn_flags & ISLASTCN) || !lockparent) {
                    301:            /* if we isn't last component and is isn't requested,
                    302:             * return parent unlocked */
                    303: #ifdef HAVE_FREEBSD_THREAD
                    304:            xfs_vfs_unlock (ap->a_dvp, xfs_cnp_to_thread(cnp));
                    305: #else
                    306:            xfs_vfs_unlock (ap->a_dvp, xfs_cnp_to_proc(cnp));
                    307: #endif
                    308: #ifdef PDIRUNLOCK
                    309:            cnp->cn_flags |= PDIRUNLOCK;
                    310: #endif
                    311:        }
                    312:     } else {
                    313:        /* in case of a error do nothing  */
                    314:     }
                    315:
                    316:     NNPFSDEB(XDEBVNOPS, ("xfs_lookup: error = %d\n", error));
                    317:
                    318:     return error;
                    319: }
                    320: #endif /* HAVE_VOP_LOOKUP */
                    321:
                    322: #ifdef HAVE_VOP_CACHEDLOOKUP
                    323: int
                    324: xfs_cachedlookup(struct vop_cachedlookup_args * ap)
                    325:      /* struct vop_cachedlookup_args {
                    326:        struct vnodeop_desc *a_desc;
                    327:        struct vnode *a_dvp;
                    328:        struct vnode **a_vpp;
                    329:        struct componentname *a_cnp;
                    330: }; */
                    331: {
                    332:     return xfs_lookup((struct vop_lookup_args *)ap);
                    333: }
                    334: #endif /* HAVE_VOP_CACHEDLOOKUP */
                    335:
                    336: /*
                    337:  * whatever clean-ups are needed for a componentname.
                    338:  */
                    339:
                    340: static void
                    341: cleanup_cnp (struct componentname *cnp, int error)
                    342: {
                    343:     if (error != 0 || (cnp->cn_flags & SAVESTART) == 0) {
                    344: #if defined(HAVE_KERNEL_ZFREEI)
                    345:        zfreei(namei_zone, cnp->cn_pnbuf);
                    346:        cnp->cn_flags &= ~HASBUF;
                    347: #elif defined(HAVE_KERNEL_UMA_ZFREE_ARG)
                    348:        uma_zfree_arg(namei_zone, cnp->cn_pnbuf, NULL);
                    349:        cnp->cn_flags &= ~HASBUF;
                    350: #elif defined(FREE_ZONE)
                    351:        FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
                    352: #elif defined(HAVE_KERNEL_ZFREE)
                    353:        zfree(namei_zone, cnp->cn_pnbuf);
                    354:        cnp->cn_flags &= ~HASBUF;
                    355: #elif defined(PNBUF_PUT)
                    356:        PNBUF_PUT(cnp->cn_pnbuf);
                    357: #else
                    358:        pool_put(&namei_pool, cnp->cn_pnbuf);
                    359: #endif
                    360:     }
                    361: }
                    362:
                    363: #ifdef HAVE_VOP_CREATE
                    364: int
                    365: xfs_create(struct vop_create_args *ap)
                    366: {
                    367:     struct vnode *dvp  = ap->a_dvp;
                    368:     struct componentname *cnp = ap->a_cnp;
                    369:     const char *name   = cnp->cn_nameptr;
                    370:     struct ucred *cred = cnp->cn_cred;
                    371: #ifdef HAVE_FREEBSD_THREAD
                    372:     d_thread_t *p     = xfs_cnp_to_thread(cnp);
                    373: #else
                    374:     d_thread_t *p     = xfs_cnp_to_proc(cnp);
                    375: #endif
                    376:     int error;
                    377:
                    378:     error = xfs_create_common(dvp, name, ap->a_vap, cred, p);
                    379:
                    380:     if (error == 0) {
                    381:        error = xfs_lookup_common(dvp, cnp, ap->a_vpp);
                    382:     }
                    383:
                    384:     cleanup_cnp (cnp, error);
                    385:
                    386: #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
                    387:     vput (dvp);
                    388: #endif
                    389:
                    390:     NNPFSDEB(XDEBVNOPS, ("xfs_create: error = %d\n", error));
                    391:
                    392:     return error;
                    393: }
                    394: #endif /* HAVE_VOP_CREATE */
                    395:
                    396: #ifdef HAVE_VOP_REMOVE
                    397: int
                    398: xfs_remove(struct vop_remove_args * ap)
                    399:      /* struct vnode *dvp,
                    400:    struct vnode *vp,
                    401:    struct componentname *cnp */
                    402: {
                    403:     struct componentname *cnp = ap->a_cnp;
                    404:     struct vnode *dvp = ap->a_dvp;
                    405:     struct vnode *vp  = ap->a_vp;
                    406:
                    407: #ifdef HAVE_FREEBSD_THREAD
                    408:     int error = xfs_remove_common(dvp, vp, cnp->cn_nameptr,
                    409:                                  cnp->cn_cred, xfs_cnp_to_thread(cnp));
                    410: #else
                    411:     int error = xfs_remove_common(dvp, vp, cnp->cn_nameptr,
                    412:                                  cnp->cn_cred, xfs_cnp_to_proc(cnp));
                    413: #endif
                    414:
                    415:     cleanup_cnp (cnp, error);
                    416:
                    417: #if !defined(__FreeBSD__) || __FreeBSD_version < 300000
                    418:     if (dvp == vp)
                    419:        vrele(vp);
                    420:     else
                    421:        vput(vp);
                    422:     vput(dvp);
                    423: #endif
                    424:
                    425: #ifdef __APPLE__
                    426:     if (error == 0) {
                    427:        if (UBCINFOEXISTS(vp)) {
                    428:            ubc_setsize(vp, 0);
                    429:            ubc_release(vp);
                    430:            ubc_uncache(vp);
                    431:        }
                    432:     }
                    433: #endif
                    434:
                    435:     return error;
                    436: }
                    437: #endif /* HAVE_VOP_REMOVE */
                    438:
                    439: #ifdef HAVE_VOP_RENAME
                    440: int
                    441: xfs_rename(struct vop_rename_args * ap)
                    442:      /* vop_rename {
                    443:        IN WILLRELE struct vnode *fdvp;
                    444:        IN WILLRELE struct vnode *fvp;
                    445:        IN struct componentname *fcnp;
                    446:        IN WILLRELE struct vnode *tdvp;
                    447:        IN WILLRELE struct vnode *tvp;
                    448:        IN struct componentname *tcnp;
                    449:   }; */
                    450: {
                    451:     struct vnode *tdvp = ap->a_tdvp;
                    452:     struct vnode *tvp  = ap->a_tvp;
                    453:     struct vnode *fdvp = ap->a_fdvp;
                    454:     struct vnode *fvp  = ap->a_fvp;
                    455:
                    456:     int error = xfs_rename_common(fdvp,
                    457:                                  fvp,
                    458:                                  ap->a_fcnp->cn_nameptr,
                    459:                                  tdvp,
                    460:                                  tvp,
                    461:                                  ap->a_tcnp->cn_nameptr,
                    462:                                  ap->a_tcnp->cn_cred,
                    463: #ifdef HAVE_FREEBSD_THREAD
                    464:                                  xfs_cnp_to_thread (ap->a_fcnp));
                    465: #else
                    466:                                  xfs_cnp_to_proc (ap->a_fcnp));
                    467: #endif
                    468:     if(tdvp == tvp)
                    469:        vrele(tdvp);
                    470:     else
                    471:        vput(tdvp);
                    472:     if(tvp)
                    473:        vput(tvp);
                    474:     vrele(fdvp);
                    475:     vrele(fvp);
                    476:     return error;
                    477: }
                    478: #endif /* HAVE_VOP_RENAME */
                    479:
                    480: #ifdef HAVE_VOP_MKDIR
                    481: int
                    482: xfs_mkdir(struct vop_mkdir_args * ap)
                    483:      /* struct vnode *dvp,
                    484:          char *nm,
                    485:          struct vattr *va,
                    486:          struct vnode **vpp,
                    487:          struct ucred *cred)      */
                    488: {
                    489:     struct vnode *dvp  = ap->a_dvp;
                    490:     struct componentname *cnp = ap->a_cnp;
                    491:     const char *name   = cnp->cn_nameptr;
                    492:     struct ucred *cred = cnp->cn_cred;
                    493: #ifdef HAVE_FREEBSD_THREAD
                    494:     d_thread_t *p     = xfs_cnp_to_thread(cnp);
                    495: #else
                    496:     d_thread_t *p     = xfs_cnp_to_proc(cnp);
                    497: #endif
                    498:     int error;
                    499:
                    500:     error = xfs_mkdir_common(dvp, name, ap->a_vap, cred, p);
                    501:
                    502:     if (error == 0)
                    503:        error = xfs_lookup_common(dvp, cnp, ap->a_vpp);
                    504:
                    505:     cleanup_cnp (cnp, error);
                    506:
                    507: #if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
                    508:     vput(dvp);
                    509: #endif
                    510:
                    511:     NNPFSDEB(XDEBVNOPS, ("xfs_mkdir: error = %d\n", error));
                    512:
                    513:     return error;
                    514: }
                    515: #endif /* HAVE_VOP_MKDIR */
                    516:
                    517: #ifdef HAVE_VOP_RMDIR
                    518: int
                    519: xfs_rmdir(struct vop_rmdir_args * ap)
                    520:      /* struct vnode *dvp,
                    521:    struct vnode *vp,
                    522:    struct componentname *cnp */
                    523: {
                    524:     struct componentname *cnp = ap->a_cnp;
                    525:     struct vnode *dvp = ap->a_dvp;
                    526:     struct vnode *vp  = ap->a_vp;
                    527:     int error = xfs_rmdir_common(ap->a_dvp, ap->a_vp,
                    528:                                 cnp->cn_nameptr,
                    529:                                 cnp->cn_cred,
                    530: #ifdef HAVE_FREEBSD_THREAD
                    531:                                 xfs_cnp_to_thread(cnp));
                    532: #else
                    533:                                 xfs_cnp_to_proc(cnp));
                    534: #endif
                    535:
                    536:     cleanup_cnp (cnp, error);
                    537: #if !defined(__FreeBSD__) || __FreeBSD_version < 300000
                    538:     if (dvp == vp)
                    539:        vrele(vp);
                    540:     else
                    541:        vput(vp);
                    542:     vput(dvp);
                    543: #endif
                    544:
                    545:     return error;
                    546: }
                    547: #endif /* HAVE_VOP_RMDIR */
                    548:
                    549: #ifdef HAVE_VOP_READDIR
                    550:
                    551: #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
                    552: typedef u_long xfs_cookie_t;
                    553: #elif defined(__NetBSD__)
                    554: typedef off_t xfs_cookie_t;
                    555: #else
                    556: #error dunno want kind of cookies you have
                    557: #endif
                    558:
                    559: int
                    560: xfs_readdir(struct vop_readdir_args * ap)
                    561:      /* struct vnode *vp,
                    562:            struct uio *uiop,
                    563:            struct ucred *cred) */
                    564: {
                    565:     int error;
                    566:     off_t off;
                    567:
                    568:     off = ap->a_uio->uio_offset;
                    569:
                    570:     error = xfs_readdir_common(ap->a_vp, ap->a_uio, ap->a_cred,
                    571: #ifdef HAVE_FREEBSD_THREAD
                    572:                               xfs_uio_to_thread (ap->a_uio),
                    573: #else
                    574:                               xfs_uio_to_proc (ap->a_uio),
                    575: #endif
                    576:                               ap->a_eofflag);
                    577:
                    578:     if (!error && ap->a_ncookies != NULL) {
                    579:        struct uio *uio = ap->a_uio;
                    580:        const struct dirent *dp, *dp_start, *dp_end;
                    581:        int ncookies;
                    582:        xfs_cookie_t *cookies, *cookiep;
                    583:
                    584:        if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
                    585:            panic("xfs_readdir: mail arla-drinkers and tell them to bake burned cookies");
                    586:        dp = (const struct dirent *)
                    587:            ((const char *)uio->uio_iov->iov_base - (uio->uio_offset - off));
                    588:
                    589:        dp_end = (const struct dirent *) uio->uio_iov->iov_base;
                    590:        for (dp_start = dp, ncookies = 0;
                    591:             dp < dp_end;
                    592:             dp = (const struct dirent *)((const char *) dp + dp->d_reclen)) {
                    593:            if (dp->d_reclen <= 0)
                    594:                break;
                    595:            ncookies++;
                    596:        }
                    597:
                    598:        MALLOC(cookies, xfs_cookie_t *, ncookies * sizeof(xfs_cookie_t),
                    599:               M_TEMP, M_WAITOK);
                    600:        for (dp = dp_start, cookiep = cookies;
                    601:             dp < dp_end;
                    602:             dp = (const struct dirent *)((const char *) dp + dp->d_reclen)) {
                    603:            if (dp->d_reclen <= 0)
                    604:                break;
                    605:            off += dp->d_reclen;
                    606:            *cookiep++ = off;
                    607:        }
                    608:        *ap->a_cookies = cookies;
                    609:        *ap->a_ncookies = ncookies;
                    610:     }
                    611:     return error;
                    612: }
                    613: #endif /* HAVE_VOP_READDIR */
                    614:
                    615: #ifdef HAVE_VOP_LINK
                    616: int
                    617: xfs_link(struct vop_link_args * ap)
                    618:      /*
                    619:        WILLRELE struct vnode *tdvp;
                    620:        struct vnode *vp;
                    621:        struct componentname *cnp;
                    622:        */
                    623: {
                    624:     struct componentname *cnp = ap->a_cnp;
                    625:     struct vnode *vp = ap->a_vp;
                    626:     struct vnode *dvp;
                    627: #ifdef HAVE_FREEBSD_THREAD
                    628:     d_thread_t *p = cnp->cn_thread;
                    629: #else
                    630:     d_thread_t *p = cnp->cn_proc;
                    631: #endif
                    632:     int error;
                    633:
                    634: #if defined (__OpenBSD__) || defined(__NetBSD__)
                    635:     dvp = ap->a_dvp;
                    636: #elif defined(__FreeBSD__) || defined(__APPLE__)
                    637:     dvp = ap->a_tdvp;
                    638: #else
                    639: #error what kind of BSD is this?
                    640: #endif
                    641:
                    642:     if (vp->v_type == VDIR) {
                    643: #ifdef HAVE_VOP_ABORTOP
                    644:            VOP_ABORTOP(dvp, cnp);
                    645: #endif
                    646:            error = EPERM;
                    647:            goto out;
                    648:     }
                    649:     if (dvp->v_mount != vp->v_mount) {
                    650: #ifdef HAVE_VOP_ABORTOP
                    651:            VOP_ABORTOP(dvp, cnp);
                    652: #endif
                    653:            error = EXDEV;
                    654:            goto out;
                    655:     }
                    656:     /* FreeBSD 5.0 doesn't need to lock the vnode in VOP_LINK */
                    657: #if !defined(__FreeBSD_version) || __FreeBSD_version < 500043
                    658:
                    659:     if (dvp != vp && (error = xfs_vfs_writelock(vp, p))) {
                    660: #ifdef HAVE_VOP_ABORTOP
                    661:            VOP_ABORTOP(dvp, cnp);
                    662: #endif
                    663:            goto out;
                    664:     }
                    665: #endif /* defined(__FreeBSD_version) || __FreeBSD_version < 500043 */
                    666:
                    667:     error = xfs_link_common(
                    668:                           dvp,
                    669:                           vp,
                    670:                           cnp->cn_nameptr,
                    671:                           cnp->cn_cred,
                    672: #ifdef HAVE_FREEBSD_THREAD
                    673:                           xfs_cnp_to_thread (cnp));
                    674: #else
                    675:                           xfs_cnp_to_proc (cnp));
                    676: #endif
                    677:
                    678:     cleanup_cnp (cnp, error);
                    679:
                    680:     if (dvp != vp)
                    681:        xfs_vfs_unlock(vp, p);
                    682:
                    683: out:
                    684: #if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
                    685:     vput(dvp);
                    686: #endif
                    687:
                    688:     return error;
                    689: }
                    690: #endif /* HAVE_VOP_LINK */
                    691:
                    692: #ifdef HAVE_VOP_SYMLINK
                    693: int
                    694: xfs_symlink(struct vop_symlink_args * ap)
                    695:      /*
                    696:   IN WILLRELE struct vnode *dvp;
                    697:   OUT WILLRELE struct vnode **vpp;
                    698:   IN struct componentname *cnp;
                    699:   IN struct vattr *vap;
                    700:   IN char *target;
                    701:   */
                    702: {
                    703:     struct componentname *cnp = ap->a_cnp;
                    704:     struct vnode *dvp  = ap->a_dvp;
                    705:     struct vnode **vpp = ap->a_vpp;
                    706:
                    707:     int error = xfs_symlink_common(dvp,
                    708:                                   vpp,
                    709:                                   cnp,
                    710:                                   ap->a_vap,
                    711:                                   ap->a_target);
                    712:
                    713:     if (error == 0) {
                    714:        error = xfs_lookup_common(dvp, cnp, vpp);
                    715:        if (error == 0)
                    716:            vput (*vpp);
                    717:     }
                    718:     cleanup_cnp (cnp, error);
                    719: #if !defined(__FreeBSD__)
                    720:     vput(dvp);
                    721: #endif
                    722:     return error;
                    723: }
                    724: #endif /* HAVE_VOP_SYMLINK */
                    725:
                    726:
                    727: #ifdef HAVE_VOP_READLINK
                    728: int
                    729: xfs_readlink(struct vop_readlink_args * ap)
                    730:      /* struct vnode *vp,
                    731:             struct uio *uiop,
                    732:             struct ucred *cred) */
                    733: {
                    734:     return xfs_readlink_common(ap->a_vp, ap->a_uio, ap->a_cred);
                    735: }
                    736: #endif /* HAVE_VOP_READLINK */
                    737:
                    738: #ifdef HAVE_VOP_INACTIVE
                    739: int
                    740: xfs_inactive(struct vop_inactive_args * ap)
                    741:      /*struct vnode *vp,
                    742:             struct ucred *cred)*/
                    743: {
                    744: #ifdef HAVE_FREEBSD_THREAD
                    745:     return xfs_inactive_common(ap->a_vp, xfs_curthread());
                    746: #else
                    747:     return xfs_inactive_common(ap->a_vp, xfs_curproc());
                    748: #endif
                    749: }
                    750: #endif /* HAVE_VOP_INACTICE */
                    751:
                    752: #ifdef HAVE_VOP_RECLAIM
                    753: int
                    754: xfs_reclaim(struct vop_reclaim_args * ap)
                    755:      /*struct vop_reclaim_args {
                    756:        struct vnodeop_desc *a_desc;
                    757:        struct vnode *a_vp;
                    758: };*/
                    759: {
                    760:     struct vnode *vp = ap->a_vp;
                    761:     int ret;
                    762:
                    763:     ret = xfs_reclaim_common(vp);
                    764:     vp->v_data = NULL;
                    765:     return ret;
                    766: }
                    767: #endif /* HAVE_VOP_RECLAIM */
                    768:
                    769: /*
                    770:  * Do lock, unlock, and islocked with lockmgr if we have it.
                    771:  */
                    772:
                    773: #if defined(HAVE_KERNEL_LOCKMGR) || defined(HAVE_KERNEL_DEBUGLOCKMGR)
                    774:
                    775: #ifdef HAVE_VOP_LOCK
                    776: int
                    777: xfs_lock(struct vop_lock_args * ap)
                    778: {
                    779:     struct vnode *vp    = ap->a_vp;
                    780:     struct xfs_node *xn = VNODE_TO_XNODE(vp);
                    781:     xfs_vnode_lock *l   = &xn->lock;
                    782:     int flags           = ap->a_flags;
                    783:     int ret;
                    784:
                    785:     NNPFSDEB(XDEBVNOPS, ("xfs_lock: %lx, flags 0x%x\n",
                    786:                       (unsigned long)vp, flags));
                    787:
                    788:     if (l == NULL)
                    789:       panic("xfs_lock: lock NULL");
                    790:
                    791:     NNPFSDEB(XDEBVNOPS, ("xfs_lock before: lk flags: %d share: %d "
                    792:                         "wait: %d excl: %d holder: 0x%llx\n",
                    793:                         l->lk_flags, l->lk_sharecount, l->lk_waitcount,
                    794:                         l->lk_exclusivecount,
                    795:                         (unsigned long long)
                    796:                         (xfs_uintptr_t)l->lk_lockholder));
                    797:
                    798: #ifndef        DEBUG_LOCKS
                    799: #ifdef HAVE_FOUR_ARGUMENT_LOCKMGR
                    800: #ifdef HAVE_FREEBSD_THREAD
                    801:     ret = lockmgr(l, flags, &vp->v_interlock, ap->a_td);
                    802: #else
                    803:     ret = lockmgr(l, flags, &vp->v_interlock, ap->a_p);
                    804: #endif
                    805: #else
                    806:     ret = lockmgr(l, flags, NULL);
                    807: #endif
                    808: #else
                    809: #ifdef HAVE_FREEBSD_THREAD
                    810:     ret = debuglockmgr(l, flags, &vp->v_interlock, ap->a_td,
                    811:                        "xfs_lock", ap->a_vp->filename, ap->a_vp->line);
                    812: #else
                    813:     ret = debuglockmgr(l, flags, &vp->v_interlock, ap->a_p,
                    814:                        "xfs_lock", ap->a_vp->filename, ap->a_vp->line);
                    815: #endif
                    816: #endif
                    817:     NNPFSDEB(XDEBVNOPS, ("xfs_lock: lk flags: %d share: %d "
                    818:                         "wait: %d excl: %d holder: 0x%llx\n",
                    819:                         l->lk_flags, l->lk_sharecount, l->lk_waitcount,
                    820:                         l->lk_exclusivecount,
                    821:                         (unsigned long long)
                    822:                         (xfs_uintptr_t)l->lk_lockholder));
                    823:     return ret;
                    824: }
                    825: #endif /* HAVE_VOP_LOCK */
                    826:
                    827: #ifdef HAVE_VOP_UNLOCK
                    828: int
                    829: xfs_unlock(struct vop_unlock_args * ap)
                    830: {
                    831:     struct vnode *vp    = ap->a_vp;
                    832:     struct xfs_node *xn = VNODE_TO_XNODE(vp);
                    833:     xfs_vnode_lock *l   = &xn->lock;
                    834:     int flags           = ap->a_flags;
                    835:     int ret;
                    836:
                    837:     if (l == NULL)
                    838:       panic("xfs_unlock: lock NULL");
                    839:
                    840:     NNPFSDEB(XDEBVNOPS,
                    841:           ("xfs_unlock: %lx, flags 0x%x, l %lx, ap %lx\n",
                    842:            (unsigned long)vp, flags,
                    843:            (unsigned long)l,
                    844:            (unsigned long)ap));
                    845:
                    846:     NNPFSDEB(XDEBVNOPS, ("xfs_unlock: lk flags: %d share: %d "
                    847:                         "wait: %d excl: %d holder: 0x%lld\n",
                    848:                         l->lk_flags, l->lk_sharecount, l->lk_waitcount,
                    849:                         l->lk_exclusivecount,
                    850:                         (unsigned long long)
                    851:                         (xfs_uintptr_t)l->lk_lockholder));
                    852: #ifndef        DEBUG_LOCKS
                    853: #ifdef HAVE_FOUR_ARGUMENT_LOCKMGR
                    854: #ifdef HAVE_FREEBSD_THREAD
                    855:     ret = lockmgr (l, flags | LK_RELEASE, &vp->v_interlock, ap->a_td);
                    856: #else
                    857:     ret = lockmgr (l, flags | LK_RELEASE, &vp->v_interlock, ap->a_p);
                    858: #endif
                    859: #else
                    860:     ret = lockmgr (l, flags | LK_RELEASE, NULL);
                    861: #endif
                    862: #else
                    863: #ifdef HAVE_FREEBSD_THREAD
                    864:     ret = debuglockmgr (l, flags | LK_RELEASE, &vp->v_interlock, ap->a_td,
                    865:                        "xfs_lock", ap->a_vp->filename, ap->a_vp->line);
                    866: #else
                    867:     ret = debuglockmgr (l, flags | LK_RELEASE, &vp->v_interlock, ap->a_p,
                    868:                        "xfs_lock", ap->a_vp->filename, ap->a_vp->line);
                    869: #endif
                    870: #endif
                    871:     NNPFSDEB(XDEBVNOPS, ("xfs_unlock: return %d\n", ret));
                    872:     return ret;
                    873: }
                    874: #endif /* HAVE_VOP_UNLOCK */
                    875:
                    876: #ifdef HAVE_VOP_ISLOCKED
                    877: int
                    878: xfs_islocked (struct vop_islocked_args *ap)
                    879: {
                    880:     struct vnode *vp    = ap->a_vp;
                    881:     struct xfs_node *xn = VNODE_TO_XNODE(vp);
                    882:     xfs_vnode_lock *l   = &xn->lock;
                    883:
                    884:     NNPFSDEB(XDEBVNOPS, ("xfs_islocked: %lx\n",
                    885:                       (unsigned long)vp));
                    886:
                    887: #if defined(HAVE_TWO_ARGUMENT_LOCKSTATUS)
                    888: #ifdef HAVE_FREEBSD_THREAD
                    889:     return lockstatus (l, ap->a_td);
                    890: #else
                    891:     return lockstatus (l, ap->a_p);
                    892: #endif
                    893: #elif defined(HAVE_ONE_ARGUMENT_LOCKSTATUS)
                    894:     return lockstatus (l);
                    895: #else
                    896: #error what lockstatus?
                    897: #endif
                    898: }
                    899: #endif /* HAVE_VOP_ISLOCKED */
                    900:
                    901: #else /* !HAVE_KERNEL_LOCKMGR && !HAVE_KERNEL_DEBUGLOCKMGR */
                    902:
                    903: #ifdef HAVE_VOP_LOCK
                    904: int
                    905: xfs_lock(struct vop_lock_args * ap)
                    906: {
                    907:     struct vnode *vp    = ap->a_vp;
                    908:     struct xfs_node *xn = VNODE_TO_XNODE(vp);
                    909:
                    910:     NNPFSDEB(XDEBVNOPS, ("xfs_lock: %lx, %d\n",
                    911:                       (unsigned long)vp, xn->vnlocks));
                    912:
                    913:     while (vp->v_flag & VXLOCK) {
                    914:        vp->v_flag |= VXWANT;
                    915:        (void) tsleep((caddr_t)vp, PINOD, "xfs_vnlock", 0);
                    916:     }
                    917:     if (vp->v_tag == VT_NON)
                    918:        return (ENOENT);
                    919:     ++xn->vnlocks;
                    920:     return 0;
                    921: }
                    922: #endif /* HAVE_VOP_LOCK */
                    923:
                    924: #ifdef HAVE_VOP_UNLOCK
                    925: int
                    926: xfs_unlock(struct vop_unlock_args * ap)
                    927: {
                    928:     struct vnode *vp    = ap->a_vp;
                    929:     struct xfs_node *xn = VNODE_TO_XNODE(vp);
                    930:     NNPFSDEB(XDEBVNOPS, ("xfs_unlock: %lx, %d\n",
                    931:                       (unsigned long)vp, xn->vnlocks));
                    932:
                    933:     --xn->vnlocks;
                    934:     if (xn->vnlocks < 0) {
                    935:        printf ("PANIC: xfs_unlock: unlocking unlocked\n");
                    936:        xn->vnlocks = 0;
                    937:     }
                    938:     NNPFSDEB(XDEBVNOPS, ("xfs_unlock: return\n"));
                    939:
                    940:     return 0;
                    941: }
                    942: #endif /* HAVE_VOP_UNLOCK */
                    943:
                    944: #ifdef HAVE_VOP_ISLOCKED
                    945: int
                    946: xfs_islocked (struct vop_islocked_args *ap)
                    947: {
                    948:     struct vnode *vp    = ap->a_vp;
                    949:     struct xfs_node *xn = VNODE_TO_XNODE(vp);
                    950:
                    951:     NNPFSDEB(XDEBVNOPS, ("xfs_islocked: %lx, %d\n",
                    952:                       (unsigned long)vp, xn->vnlocks));
                    953:
                    954:     return xn->vnlocks;
                    955: }
                    956: #endif /* HAVE_VOP_ISLOCKED */
                    957: #endif /* !HAVE_KERNEL_LOCKMGR */
                    958:
                    959: #ifdef HAVE_VOP_ABORTOP
                    960: int
                    961: xfs_abortop (struct vop_abortop_args *ap)
                    962:      /* struct vnode *dvp;
                    963:    struct componentname *cnp; */
                    964: {
                    965:     struct componentname *cnp = ap->a_cnp;
                    966:
                    967:     if ((cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
                    968: #if defined(HAVE_KERNEL_ZFREEI)
                    969:        zfreei(namei_zone, cnp->cn_pnbuf);
                    970:        ap->a_cnp->cn_flags &= ~HASBUF;
                    971: #elif defined(HAVE_KERNEL_UMA_ZFREE_ARG)
                    972:        uma_zfree_arg(namei_zone, cnp->cn_pnbuf, NULL);
                    973:        cnp->cn_flags &= ~HASBUF;
                    974: #elif defined(FREE_ZONE)
                    975:        FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
                    976: #elif defined(HAVE_KERNEL_ZFREE)
                    977:        zfree(namei_zone, cnp->cn_pnbuf);
                    978:        ap->a_cnp->cn_flags &= ~HASBUF;
                    979: #elif defined(PNBUF_PUT)
                    980:        PNBUF_PUT(cnp->cn_pnbuf);
                    981: #else
                    982:        pool_put(&namei_pool, cnp->cn_pnbuf);
                    983: #endif
                    984:     return 0;
                    985: }
                    986: #endif /* HAVE_VOP_ABORTOP */
                    987:
                    988: #ifdef HAVE_VOP_MMAP
                    989: int
                    990: xfs_mmap(struct vop_mmap_args *ap)
                    991:      /*
                    992:        IN struct vnode *vp;
                    993:        IN int fflags;
                    994:        IN struct ucred *cred;
                    995:        IN struct proc *p;
                    996:        */
                    997: {
                    998:     NNPFSDEB(XDEBVNOPS, ("xfs_mmap\n"));
                    999: #ifdef HAVE_KERNEL_GENFS_MMAP
                   1000:     return genfs_mmap(ap);
                   1001: #else
                   1002:     return EOPNOTSUPP;
                   1003: #endif
                   1004: }
                   1005: #endif /* HAVE_VOP_MMAP */
                   1006:
                   1007: #ifdef HAVE_VOP_BMAP
                   1008: int
                   1009: xfs_bmap(struct vop_bmap_args *ap)
                   1010:      /*        IN struct vnode *vp;
                   1011:        IN daddr64_t bn;
                   1012:        OUT struct vnode **vpp;
                   1013:        IN daddr64_t *bnp;
                   1014:        OUT int *runp;
                   1015:        OUT int *runb;
                   1016:        */
                   1017: {
                   1018:     NNPFSDEB(XDEBVNOPS, ("xfs_bmap\n"));
                   1019:     return EOPNOTSUPP;
                   1020: }
                   1021: #endif /* HAVE_VOP_BMAP */
                   1022:
                   1023: #ifdef HAVE_VOP_GETPAGES
                   1024:
                   1025: static size_t
                   1026: get_pages_endlength (struct vop_getpages_args *ap)
                   1027: {
                   1028: #ifdef HAVE_STRUCT_VOP_GETPAGES_ARGS_A_OFFSET
                   1029:     /* NetBSD ubc */
                   1030:     return (ap->a_offset << PAGE_SHIFT) + *ap->a_count * PAGE_SIZE;
                   1031: #else
                   1032:     return (ap->a_reqpage << PAGE_SHIFT) +  ap->a_count * PAGE_SIZE;
                   1033: #endif
                   1034: }
                   1035:
                   1036: int
                   1037: xfs_getpages (struct vop_getpages_args *ap)
                   1038:      /* Old BSD
                   1039:        IN struct vnode *vp;
                   1040:        IN vm_page_t *m;
                   1041:        IN int count;
                   1042:        IN int reqpage;
                   1043:        IN vm_ooffset_t offset;
                   1044:      */
                   1045:     /* NetBSD UBC
                   1046:        IN struct vnode *vp;
                   1047:        IN voff_t offset;
                   1048:        IN vm_page_t *m;
                   1049:        IN int *count;
                   1050:        IN int centeridx;
                   1051:        IN vm_prot_t access_type;
                   1052:        IN int advice;
                   1053:        IN int flags;
                   1054:     */
                   1055: {
                   1056:     int error;
                   1057:
                   1058:     NNPFSDEB(XDEBVNOPS, ("xfs_getpages\n"));
                   1059:
                   1060: #if HAVE_KERNEL_VNODE_PAGER_GENERIC_GETPAGES
                   1061:     error = vnode_pager_generic_getpages (ap->a_vp, ap->a_m,
                   1062:                                          ap->a_count, ap->a_reqpage);
                   1063: #else
                   1064:     error = xfs_data_valid (ap->a_vp, VNODE_TO_XNODE(ap->a_vp)->rd_cred,
                   1065:                            xfs_curproc(), NNPFS_DATA_R,
                   1066:                            get_pages_endlength(ap));
                   1067:     if (error == 0)
                   1068:        error = VOP_GETPAGES(DATA_FROM_VNODE(ap->a_vp),
                   1069:                             ap->a_offset, ap->a_m,
                   1070:                             ap->a_count, ap->a_centeridx, ap->a_access_type,
                   1071:                             ap->a_advice, ap->a_flags);
                   1072: #endif
                   1073:     NNPFSDEB(XDEBVNOPS, ("xfs_getpages = %d\n", error));
                   1074:     return error;
                   1075: }
                   1076: #endif /* HAVE_VOP_GETPAGES */
                   1077:
                   1078: #ifdef HAVE_VOP_PUTPAGES
                   1079: int
                   1080: xfs_putpages (struct vop_putpages_args *ap)
                   1081:      /* Old BSD
                   1082:         IN struct vnode *vp;
                   1083:         IN vm_page_t *m;
                   1084:         IN int count;
                   1085:         IN int sync;
                   1086:         IN int *rtvals;
                   1087:         IN vm_ooffset_t offset;
                   1088:      */
                   1089:     /* NetBSD UBC (>= 1.5Y)
                   1090:        IN struct vnode *vp;
                   1091:        IN voff_t offlo;
                   1092:        IN voff_t offhi;
                   1093:        IN int flags;
                   1094:     */
                   1095: {
                   1096:     struct vnode *vp    = ap->a_vp;
                   1097:     struct xfs_node *xn = VNODE_TO_XNODE(vp);
                   1098:     struct vnode *t     = DATA_FROM_XNODE(xn);
                   1099:     int error;
                   1100:
                   1101:     NNPFSDEB(XDEBVNOPS, ("xfs_putpages\n"));
                   1102:
                   1103:     if (t == NULL)
                   1104:        return 0;
                   1105:
                   1106: #ifdef HAVE_STRUCT_VOP_PUTPAGES_ARGS_A_SYNC /* FreeBSD-style */
                   1107:     xn->flags |= NNPFS_DATA_DIRTY;
                   1108:
                   1109:     return VOP_PUTPAGES(t, ap->a_m, ap->a_count, ap->a_sync, ap->a_rtvals,
                   1110:                        ap->a_offset);
                   1111: #else /* NetBSD-style */
                   1112: #if defined(__NetBSD__) && __NetBSD_Version__  >= 105250000
                   1113:     /* XXX should only walk over those pages that is requested */
                   1114:     if (vp->v_type == VREG && ap->a_flags & PGO_CLEANIT) {
                   1115:        struct uvm_object *uobj = &t->v_uobj;
                   1116:        struct vm_page *pg;
                   1117:        int dirty = 0;
                   1118:
                   1119:        pg = TAILQ_FIRST(&uobj->memq);
                   1120:
                   1121:        while (pg && !dirty) {
                   1122:            dirty = pmap_is_modified(pg) || (pg->flags & PG_CLEAN) == 0;
                   1123:            pg = TAILQ_NEXT(pg, listq);
                   1124:        }
                   1125:
                   1126:        if (dirty)
                   1127:            xn->flags |= NNPFS_DATA_DIRTY;
                   1128:     }
                   1129:
                   1130:     return VOP_PUTPAGES(t, ap->a_offlo, ap->a_offhi, ap->a_flags);
                   1131: #else
                   1132:     xn->flags |= NNPFS_DATA_DIRTY;
                   1133:     return VOP_PUTPAGES(t, ap->a_m, ap->a_count, ap->a_flags, ap->a_rtvals);
                   1134: #endif
                   1135: #endif /* HAVE_STRUCT_VOP_PUTPAGES_ARGS_A_SYNC */
                   1136: }
                   1137: #endif /* HAVE_VOP_PUTPAGES */
                   1138:
                   1139: #ifdef HAVE_VOP_CMP
                   1140: int
                   1141: xfs_cmp(struct vnode * vp1, struct vnode * vp2)
                   1142: {
                   1143:     NNPFSDEB(XDEBVNOPS, ("xfs_cmp\n"));
                   1144:     return EOPNOTSUPP;
                   1145: }
                   1146: #endif /* HAVE_VOP_CMP */
                   1147:
                   1148: #ifdef HAVE_VOP_REALVP
                   1149: int
                   1150: xfs_realvp(struct vnode * vp,
                   1151:           struct vnode ** vpp)
                   1152: {
                   1153:     NNPFSDEB(XDEBVNOPS, ("xfs_realvp\n"));
                   1154:     return EOPNOTSUPP;
                   1155: }
                   1156: #endif /* HAVE_VOP_REALVP */
                   1157:
                   1158: #ifdef HAVE_VOP_CNTL
                   1159: int
                   1160: xfs_cntl(struct vnode * vp,
                   1161:         int cmd,
                   1162:         caddr_t idata,
                   1163:         caddr_t odata,
                   1164:         int iflag,
                   1165:         int oflag)
                   1166: {
                   1167:     NNPFSDEB(XDEBVNOPS, ("xfs_cntl\n"));
                   1168:     return EOPNOTSUPP;
                   1169: }
                   1170: #endif /* HAVE_VOP_CNTL */
                   1171:
                   1172: #ifdef HAVE_VOP_PRINT
                   1173: int
                   1174: xfs_print (struct vop_print_args *v)
                   1175: {
                   1176:     struct vop_print_args *ap = v;
                   1177:     xfs_printnode_common (ap->a_vp);
                   1178:     return 0;
                   1179: }
                   1180: #endif
                   1181:
                   1182: #ifdef HAVE_VOP_ADVLOCK
                   1183: int
                   1184: xfs_advlock(struct vop_advlock_args *v)
                   1185: {
                   1186:     struct vop_advlock_args *ap = v;
                   1187: #if defined(HAVE_KERNEL_LF_ADVLOCK) && !defined(__APPLE__)
                   1188:     struct xfs_node *xn = VNODE_TO_XNODE(ap->a_vp);
                   1189:
                   1190:     return (lf_advlock(&xn->lockf, xn->attr.va_size, ap->a_id, ap->a_op,
                   1191:            ap->a_fl, ap->a_flags));
                   1192: #else
                   1193:      return EOPNOTSUPP;
                   1194: #endif
                   1195: }
                   1196: #endif /* HAVE_VOP_ADVOCK */
                   1197:
                   1198: #ifdef HAVE_VOP_REVOKE
                   1199: int
                   1200: xfs_revoke(struct vop_revoke_args *v)
                   1201: {
                   1202: #if defined(HAVE_KERNEL_GENFS_REVOKE)
                   1203:     return genfs_revoke (v);
                   1204: #elif defined(HAVE_KERNEL_VOP_REVOKE)
                   1205:     return vop_revoke (v);
                   1206: #else
                   1207:     return EOPNOTSUPP;
                   1208: #endif
                   1209: }
                   1210: #endif /* HAVE_VOP_REVOKE */
                   1211:
                   1212: #ifdef HAVE_VOP_PAGEIN
                   1213: int
                   1214: xfs_pagein(struct vop_pagein_args *ap)
                   1215: {
                   1216: #ifdef __APPLE__
                   1217:     struct uio uio;
                   1218:     struct iovec iov;
                   1219:     int ret;
                   1220:
                   1221:     kernel_upl_map(kernel_map, ap->a_pl, &iov.iov_base);
                   1222:     iov.iov_base+=ap->a_pl_offset;
                   1223:     iov.iov_len=ap->a_size;
                   1224:
                   1225:     uio.uio_iov=&iov;
                   1226:     uio.uio_iovcnt=1;
                   1227:     uio.uio_offset=ap->a_f_offset;
                   1228:     uio.uio_resid=ap->a_size;
                   1229:     uio.uio_segflg=UIO_SYSSPACE; /* XXX what is it? */
                   1230:     uio.uio_rw=UIO_READ;
                   1231:     uio.uio_procp=xfs_curproc();
                   1232:
                   1233:     ret = VOP_READ(ap->a_vp, &uio, 0, ap->a_cred);
                   1234:
                   1235:     /* Zero out rest of last page if there wasn't enough data in the file */
                   1236:     if (ret == 0 && uio.uio_resid > 0)
                   1237:        bzero(iov.iov_base, uio.uio_resid);
                   1238:
                   1239:     kernel_upl_unmap(kernel_map, ap->a_pl);
                   1240:
                   1241:     if (ret) {
                   1242:        kernel_upl_abort_range(ap->a_pl, ap->a_pl_offset, ap->a_size,
                   1243:                               UPL_ABORT_ERROR | UPL_ABORT_FREE_ON_EMPTY);
                   1244:     } else {
                   1245:        kernel_upl_commit_range(ap->a_pl, ap->a_pl_offset, ap->a_size,
                   1246:                                UPL_COMMIT_CLEAR_DIRTY | UPL_COMMIT_FREE_ON_EMPTY,
                   1247:                                UPL_GET_INTERNAL_PAGE_LIST(ap->a_pl));
                   1248:     }
                   1249:
                   1250:     return ret;
                   1251: #else
                   1252: #error pagein on non apple ?
                   1253: #endif
                   1254: }
                   1255:
                   1256: #endif
                   1257:
                   1258: #ifdef HAVE_VOP_PAGEOUT
                   1259: int
                   1260: xfs_pageout(struct vop_pageout_args *ap)
                   1261: {
                   1262: #ifdef __APPLE__
                   1263:     struct uio uio;
                   1264:     struct iovec iov;
                   1265:     int ret;
                   1266:
                   1267:     kernel_upl_map(kernel_map, ap->a_pl, &iov.iov_base);
                   1268:     iov.iov_base+=ap->a_pl_offset;
                   1269:     iov.iov_len=ap->a_size;
                   1270:
                   1271:     uio.uio_iov=&iov;
                   1272:     uio.uio_iovcnt=1;
                   1273:     uio.uio_offset=ap->a_f_offset;
                   1274:     uio.uio_resid=ap->a_size;
                   1275:     uio.uio_segflg=UIO_SYSSPACE; /* XXX what is it? */
                   1276:     uio.uio_rw=UIO_WRITE;
                   1277:     uio.uio_procp=xfs_curproc();
                   1278:
                   1279:     ret = VOP_WRITE(ap->a_vp, &uio, 0, ap->a_cred);
                   1280:
                   1281:     kernel_upl_unmap(kernel_map, ap->a_pl);
                   1282:
                   1283:     if (ret) {
                   1284:        kernel_upl_abort_range(ap->a_pl, ap->a_pl_offset, ap->a_size,
                   1285:                               UPL_ABORT_FREE_ON_EMPTY);
                   1286:     } else {
                   1287:        kernel_upl_commit_range(ap->a_pl, ap->a_pl_offset, ap->a_size,
                   1288:                                UPL_COMMIT_CLEAR_DIRTY | UPL_COMMIT_FREE_ON_EMPTY,
                   1289:                                UPL_GET_INTERNAL_PAGE_LIST(ap->a_pl));
                   1290:     }
                   1291:
                   1292:     return ret;
                   1293: #else
                   1294: #error pageout on non apple ?
                   1295: #endif
                   1296: }
                   1297: #endif
                   1298:
                   1299: #ifdef HAVE_VOP_CREATEVOBJECT
                   1300: int
                   1301: xfs_createvobject(struct vop_createvobject_args *ap)
                   1302: /*
                   1303: struct vop_createvobject_args {
                   1304:        struct vnode *vp;
                   1305:        struct ucred *cred;
                   1306:        struct proc *p;
                   1307: };
                   1308:  */
                   1309: {
                   1310:     NNPFSDEB(XDEBVNOPS, ("xfs_createvobject\n"));
                   1311:
                   1312:     return vop_stdcreatevobject (ap);
                   1313: }
                   1314: #endif /* HAVE_VOP_CREATEVOBJECT */
                   1315:
                   1316: #ifdef HAVE_VOP_DESTROYVOBJECT
                   1317: int
                   1318: xfs_destroyvobject(struct vop_destroyvobject_args *ap)
                   1319: /*
                   1320: struct vop_destroyvobject_args {
                   1321:        struct vnode *vp;
                   1322: };
                   1323:  */
                   1324: {
                   1325:     NNPFSDEB(XDEBVNOPS, ("xfs_destroyvobject\n"));
                   1326:
                   1327:     return vop_stddestroyvobject (ap);
                   1328: }
                   1329: #endif /* HAVE_VOP_DESTROYVOBJECT */
                   1330:
                   1331: #ifdef HAVE_VOP_GETVOBJECT
                   1332: int
                   1333: xfs_getvobject(struct vop_getvobject_args *ap)
                   1334: /*
                   1335: struct vop_getvobject_args {
                   1336:        struct vnode *vp;
                   1337:        struct vm_object **objpp;
                   1338: };
                   1339:  */
                   1340: {
                   1341:     NNPFSDEB(XDEBVNOPS, ("xfs_getvobject\n"));
                   1342:
                   1343:     return vop_stdgetvobject (ap);
                   1344: }
                   1345: #endif /* HAVE_VOP_GETVOBJECT */
                   1346:
                   1347: #ifdef HAVE_VOP_PATHCONF
                   1348: int
                   1349: xfs_pathconf(struct vop_pathconf_args *ap)
                   1350: /*
                   1351: struct vop_pathconf_args {
                   1352:         struct vnodeop_desc *a_desc;
                   1353:         struct vnode *a_vp;
                   1354:         int a_name;
                   1355: };
                   1356: */
                   1357: {
                   1358:     NNPFSDEB(XDEBVNOPS, ("xfs_pathconf\n"));
                   1359:
                   1360: #ifdef HAVE_KERNEL_VOP_STDPATHCONF
                   1361:     return vop_stdpathconf(ap);
                   1362: #else
                   1363:     return EOPNOTSUPP;
                   1364: #endif
                   1365: }
                   1366: #endif
                   1367:
                   1368:
                   1369:
                   1370: vop_t **xfs_vnodeop_p;
                   1371:
                   1372: int
                   1373: xfs_eopnotsupp (struct vop_generic_args *ap)
                   1374: {
                   1375:     NNPFSDEB(XDEBVNOPS, ("xfs_eopnotsupp %s\n", ap->a_desc->vdesc_name));
                   1376:     return EOPNOTSUPP;
                   1377: }
                   1378:
                   1379: int
                   1380: xfs_returnzero (struct vop_generic_args *ap)
                   1381: {
                   1382:     NNPFSDEB(XDEBVNOPS, ("xfs_returnzero %s\n", ap->a_desc->vdesc_name));
                   1383:     return 0;
                   1384: }
                   1385:
                   1386: void
                   1387: xfs_pushdirty(struct vnode *vp, struct ucred *cred, d_thread_t *p)
                   1388: {
                   1389: #if defined(__NetBSD_Version__) && __NetBSD_Version__ >= 105280000
                   1390:     VOP_PUTPAGES(vp, 0, 0, PGO_ALLPAGES|PGO_SYNCIO|PGO_CLEANIT);
                   1391: #elif defined(__APPLE__)
                   1392:     ubc_pushdirty(vp);
                   1393: #endif
                   1394: }
                   1395:
                   1396:
                   1397:
                   1398: static struct vnodeopv_entry_desc xfs_vnodeop_entries[] = {
                   1399:     {&vop_default_desc, (vop_t *) xfs_eopnotsupp},
                   1400: #ifdef HAVE_VOP_LOOKUP
                   1401: #ifdef HAVE_KERNEL_VFS_CACHE_LOOKUP
                   1402:     {&vop_lookup_desc, (vop_t *) vfs_cache_lookup },
                   1403: #else
                   1404:     {&vop_lookup_desc, (vop_t *) xfs_lookup },
                   1405: #endif
                   1406: #endif
                   1407: #ifdef HAVE_VOP_CACHEDLOOKUP
                   1408:     {&vop_cachedlookup_desc, (vop_t *) xfs_cachedlookup },
                   1409: #endif
                   1410: #ifdef HAVE_VOP_OPEN
                   1411:     {&vop_open_desc, (vop_t *) xfs_open },
                   1412: #endif
                   1413: #ifdef HAVE_VOP_FSYNC
                   1414:     {&vop_fsync_desc, (vop_t *) xfs_fsync },
                   1415: #endif
                   1416: #ifdef HAVE_VOP_CLOSE
                   1417:     {&vop_close_desc, (vop_t *) xfs_close },
                   1418: #endif
                   1419: #ifdef HAVE_VOP_READ
                   1420:     {&vop_read_desc, (vop_t *) xfs_read },
                   1421: #endif
                   1422: #ifdef HAVE_VOP_WRITE
                   1423:     {&vop_write_desc, (vop_t *) xfs_write },
                   1424: #endif
                   1425: #ifdef HAVE_VOP_MMAP
                   1426:     {&vop_mmap_desc, (vop_t *) xfs_mmap },
                   1427: #endif
                   1428: #ifdef HAVE_VOP_BMAP
                   1429:     {&vop_bmap_desc, (vop_t *) xfs_bmap },
                   1430: #endif
                   1431: #ifdef HAVE_VOP_IOCTL
                   1432:     {&vop_ioctl_desc, (vop_t *) xfs_ioctl },
                   1433: #endif
                   1434: #ifdef HAVE_VOP_SELECT
                   1435:     {&vop_select_desc, (vop_t *) xfs_select },
                   1436: #endif
                   1437: #ifdef HAVE_VOP_SEEK
                   1438:     {&vop_seek_desc, (vop_t *) xfs_seek },
                   1439: #endif
                   1440: #ifdef HAVE_VOP_POLL
                   1441:     {&vop_poll_desc, (vop_t *) xfs_poll },
                   1442: #endif
                   1443: #ifdef HAVE_VOP_GETATTR
                   1444:     {&vop_getattr_desc, (vop_t *) xfs_getattr },
                   1445: #endif
                   1446: #ifdef HAVE_VOP_SETATTR
                   1447:     {&vop_setattr_desc, (vop_t *) xfs_setattr },
                   1448: #endif
                   1449: #ifdef HAVE_VOP_ACCESS
                   1450:     {&vop_access_desc, (vop_t *) xfs_access },
                   1451: #endif
                   1452: #ifdef HAVE_VOP_CREATE
                   1453:     {&vop_create_desc, (vop_t *) xfs_create },
                   1454: #endif
                   1455: #ifdef HAVE_VOP_REMOVE
                   1456:     {&vop_remove_desc, (vop_t *) xfs_remove },
                   1457: #endif
                   1458: #ifdef HAVE_VOP_LINK
                   1459:     {&vop_link_desc, (vop_t *) xfs_link },
                   1460: #endif
                   1461: #ifdef HAVE_VOP_RENAME
                   1462:     {&vop_rename_desc, (vop_t *) xfs_rename },
                   1463: #endif
                   1464: #ifdef HAVE_VOP_MKDIR
                   1465:     {&vop_mkdir_desc, (vop_t *) xfs_mkdir },
                   1466: #endif
                   1467: #ifdef HAVE_VOP_RMDIR
                   1468:     {&vop_rmdir_desc, (vop_t *) xfs_rmdir },
                   1469: #endif
                   1470: #ifdef HAVE_VOP_READDIR
                   1471:     {&vop_readdir_desc, (vop_t *) xfs_readdir },
                   1472: #endif
                   1473: #ifdef HAVE_VOP_SYMLINK
                   1474:     {&vop_symlink_desc, (vop_t *) xfs_symlink },
                   1475: #endif
                   1476: #ifdef HAVE_VOP_READLINK
                   1477:     {&vop_readlink_desc, (vop_t *) xfs_readlink },
                   1478: #endif
                   1479: #ifdef HAVE_VOP_INACTIVE
                   1480:     {&vop_inactive_desc, (vop_t *) xfs_inactive },
                   1481: #endif
                   1482: #ifdef HAVE_VOP_RECLAIM
                   1483:     {&vop_reclaim_desc, (vop_t *) xfs_reclaim },
                   1484: #endif
                   1485: #ifdef HAVE_VOP_LOCK
                   1486:     {&vop_lock_desc, (vop_t *) xfs_lock },
                   1487: #endif
                   1488: #ifdef HAVE_VOP_UNLOCK
                   1489:     {&vop_unlock_desc, (vop_t *) xfs_unlock },
                   1490: #endif
                   1491: #ifdef HAVE_VOP_ISLOCKED
                   1492:     {&vop_islocked_desc, (vop_t *) xfs_islocked },
                   1493: #endif
                   1494: #ifdef HAVE_VOP_ABORTOP
                   1495:     {&vop_abortop_desc, (vop_t *) xfs_abortop },
                   1496: #endif
                   1497: #ifdef HAVE_VOP_GETPAGES
                   1498:     {&vop_getpages_desc, (vop_t *) xfs_getpages },
                   1499: #endif
                   1500: #ifdef HAVE_VOP_PUTPAGES
                   1501:     {&vop_putpages_desc, (vop_t *) xfs_putpages },
                   1502: #endif
                   1503: #ifdef HAVE_VOP_REVOKE
                   1504:     {&vop_revoke_desc, (vop_t *) xfs_revoke },
                   1505: #endif
                   1506: #ifdef HAVE_VOP_PRINT
                   1507:     {&vop_print_desc, (vop_t *) xfs_print},
                   1508: #endif
                   1509: #ifdef HAVE_VOP_ADVLOCK
                   1510:     {&vop_advlock_desc, (vop_t *) xfs_advlock },
                   1511: #endif
                   1512: #ifdef HAVE_VOP_PAGEIN
                   1513:     {&vop_pagein_desc, (vop_t *) xfs_pagein },
                   1514: #endif
                   1515: #ifdef HAVE_VOP_PAGEOUT
                   1516:     {&vop_pageout_desc, (vop_t *) xfs_pageout },
                   1517: #endif
                   1518: #ifdef HAVE_VOP_CREATEVOBJECT
                   1519:     {&vop_createvobject_desc, (vop_t *) xfs_createvobject },
                   1520: #endif
                   1521: #ifdef HAVE_VOP_DESTROYVOBJECT
                   1522:     {&vop_destroyvobject_desc, (vop_t *) xfs_destroyvobject },
                   1523: #endif
                   1524: #ifdef HAVE_VOP_GETVOBJECT
                   1525:     {&vop_getvobject_desc, (vop_t *) xfs_getvobject },
                   1526: #endif
                   1527: #ifdef HAVE_VOP_PATHCONF
                   1528:     {&vop_pathconf_desc, (vop_t *) xfs_pathconf },
                   1529: #endif
                   1530:     {(struct vnodeop_desc *) NULL, (int (*) (void *)) NULL}
                   1531: };
                   1532:
                   1533: struct vnodeopv_desc xfs_vnodeop_opv_desc =
                   1534: {&xfs_vnodeop_p, xfs_vnodeop_entries};
                   1535:
                   1536: #ifdef VNODEOP_SET
                   1537: VNODEOP_SET(xfs_vnodeop_opv_desc);
                   1538: #endif

CVSweb