[BACK]Return to puffs_subr.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / fs / puffs

Annotation of src/sys/fs/puffs/puffs_subr.c, Revision 1.44.2.1

1.44.2.1! joerg       1: /*     $NetBSD: puffs_subr.c,v 1.55 2007/10/01 21:09:08 pooka Exp $    */
1.1       pooka       2:
                      3: /*
1.44.2.1! joerg       4:  * Copyright (c) 2006, 2007  Antti Kantee.  All Rights Reserved.
1.1       pooka       5:  *
                      6:  * Development of this software was supported by the
1.44.2.1! joerg       7:  * Ulla Tuominen Foundation and the Finnish Cultural Foundation.
1.1       pooka       8:  *
                      9:  * Redistribution and use in source and binary forms, with or without
                     10:  * modification, are permitted provided that the following conditions
                     11:  * are met:
                     12:  * 1. Redistributions of source code must retain the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer.
                     14:  * 2. Redistributions in binary form must reproduce the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer in the
                     16:  *    documentation and/or other materials provided with the distribution.
                     17:  *
                     18:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
                     19:  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                     20:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
                     21:  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     22:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     23:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
                     24:  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     25:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     26:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     27:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     28:  * SUCH DAMAGE.
                     29:  */
                     30:
                     31: #include <sys/cdefs.h>
1.44.2.1! joerg      32: __KERNEL_RCSID(0, "$NetBSD: puffs_subr.c,v 1.55 2007/10/01 21:09:08 pooka Exp $");
1.1       pooka      33:
                     34: #include <sys/param.h>
                     35: #include <sys/malloc.h>
                     36: #include <sys/mount.h>
1.31      pooka      37: #include <sys/namei.h>
                     38: #include <sys/poll.h>
1.1       pooka      39:
                     40: #include <fs/puffs/puffs_msgif.h>
                     41: #include <fs/puffs/puffs_sys.h>
                     42:
1.19      pooka      43: #ifdef PUFFSDEBUG
1.10      pooka      44: int puffsdebug;
                     45: #endif
                     46:
1.1       pooka      47: void
1.36      pooka      48: puffs_makecn(struct puffs_kcn *pkcn, struct puffs_kcred *pkcr,
1.38      pooka      49:        struct puffs_kcid *pkcid, const struct componentname *cn, int full)
1.1       pooka      50: {
                     51:
1.12      pooka      52:        pkcn->pkcn_nameiop = cn->cn_nameiop;
                     53:        pkcn->pkcn_flags = cn->cn_flags;
1.37      pooka      54:        puffs_cidcvt(pkcid, cn->cn_lwp);
1.1       pooka      55:
1.38      pooka      56:        if (full) {
                     57:                (void)strcpy(pkcn->pkcn_name, cn->cn_nameptr);
                     58:        } else {
                     59:                (void)memcpy(pkcn->pkcn_name, cn->cn_nameptr, cn->cn_namelen);
                     60:                pkcn->pkcn_name[cn->cn_namelen] = '\0';
                     61:        }
1.12      pooka      62:        pkcn->pkcn_namelen = cn->cn_namelen;
1.38      pooka      63:        pkcn->pkcn_consume = 0;
1.36      pooka      64:
                     65:        puffs_credcvt(pkcr, cn->cn_cred);
1.1       pooka      66: }
                     67:
                     68: /*
1.36      pooka      69:  * Convert given credentials to struct puffs_kcred for userspace.
1.1       pooka      70:  */
                     71: void
1.36      pooka      72: puffs_credcvt(struct puffs_kcred *pkcr, const kauth_cred_t cred)
1.1       pooka      73: {
                     74:
1.36      pooka      75:        memset(pkcr, 0, sizeof(struct puffs_kcred));
1.1       pooka      76:
                     77:        if (cred == NOCRED || cred == FSCRED) {
1.36      pooka      78:                pkcr->pkcr_type = PUFFCRED_TYPE_INTERNAL;
1.1       pooka      79:                if (cred == NOCRED)
1.36      pooka      80:                        pkcr->pkcr_internal = PUFFCRED_CRED_NOCRED;
1.1       pooka      81:                if (cred == FSCRED)
1.36      pooka      82:                        pkcr->pkcr_internal = PUFFCRED_CRED_FSCRED;
1.1       pooka      83:        } else {
1.36      pooka      84:                pkcr->pkcr_type = PUFFCRED_TYPE_UUC;
                     85:                kauth_cred_to_uucred(&pkcr->pkcr_uuc, cred);
1.1       pooka      86:        }
                     87: }
                     88:
1.37      pooka      89: void
                     90: puffs_cidcvt(struct puffs_kcid *pkcid, const struct lwp *l)
1.1       pooka      91: {
                     92:
1.37      pooka      93:        if (l) {
                     94:                pkcid->pkcid_type = PUFFCID_TYPE_REAL;
                     95:                pkcid->pkcid_pid = l->l_proc->p_pid;
                     96:                pkcid->pkcid_lwpid = l->l_lid;
                     97:        } else {
                     98:                pkcid->pkcid_type = PUFFCID_TYPE_FAKE;
                     99:                pkcid->pkcid_pid = 0;
                    100:                pkcid->pkcid_lwpid = 0;
                    101:        }
1.1       pooka     102: }
1.7       pooka     103:
                    104: void
1.44.2.1! joerg     105: puffs_parkdone_asyncbioread(struct puffs_mount *pmp,
        !           106:        struct puffs_req *preq, void *arg)
1.27      pooka     107: {
                    108:        struct puffs_vnreq_read *read_argp = (void *)preq;
                    109:        struct buf *bp = arg;
                    110:        size_t moved;
                    111:
1.44.2.1! joerg     112:        bp->b_error = checkerr(pmp, preq->preq_rv, __func__);
1.27      pooka     113:        if (bp->b_error == 0) {
                    114:                moved = bp->b_bcount - read_argp->pvnr_resid;
                    115:                bp->b_resid = read_argp->pvnr_resid;
                    116:
                    117:                memcpy(bp->b_data, read_argp->pvnr_data, moved);
                    118:        }
                    119:
                    120:        biodone(bp);
                    121:        free(preq, M_PUFFS);
                    122: }
1.28      pooka     123:
1.44      pooka     124: /* XXX: userspace can leak kernel resources */
1.28      pooka     125: void
1.44.2.1! joerg     126: puffs_parkdone_poll(struct puffs_mount *pmp, struct puffs_req *preq, void *arg)
1.31      pooka     127: {
                    128:        struct puffs_vnreq_poll *poll_argp = (void *)preq;
                    129:        struct puffs_node *pn = arg;
1.44.2.1! joerg     130:        int revents, error;
1.31      pooka     131:
1.44.2.1! joerg     132:        error = checkerr(pmp, preq->preq_rv, __func__);
        !           133:        if (error)
1.31      pooka     134:                revents = poll_argp->pvnr_events;
                    135:        else
                    136:                revents = POLLERR;
                    137:
                    138:        mutex_enter(&pn->pn_mtx);
                    139:        pn->pn_revents |= revents;
                    140:        mutex_exit(&pn->pn_mtx);
                    141:
                    142:        selnotify(&pn->pn_sel, 0);
                    143:        free(preq, M_PUFFS);
                    144:
                    145:        puffs_releasenode(pn);
                    146: }
                    147:
                    148: void
1.28      pooka     149: puffs_mp_reference(struct puffs_mount *pmp)
                    150: {
                    151:
                    152:        KASSERT(mutex_owned(&pmp->pmp_lock));
                    153:        pmp->pmp_refcount++;
                    154: }
                    155:
                    156: void
                    157: puffs_mp_release(struct puffs_mount *pmp)
                    158: {
                    159:
                    160:        KASSERT(mutex_owned(&pmp->pmp_lock));
                    161:        if (--pmp->pmp_refcount == 0)
                    162:                cv_broadcast(&pmp->pmp_refcount_cv);
                    163: }
1.44.2.1! joerg     164:
        !           165: void
        !           166: puffs_gop_size(struct vnode *vp, off_t size, off_t *eobp,
        !           167:        int flags)
        !           168: {
        !           169:
        !           170:        *eobp = size;
        !           171: }
        !           172:
        !           173: void
        !           174: puffs_gop_markupdate(struct vnode *vp, int flags)
        !           175: {
        !           176:        int uflags = 0;
        !           177:
        !           178:        if (flags & GOP_UPDATE_ACCESSED)
        !           179:                uflags |= PUFFS_UPDATEATIME;
        !           180:        if (flags & GOP_UPDATE_MODIFIED)
        !           181:                uflags |= PUFFS_UPDATEMTIME;
        !           182:
        !           183:        puffs_updatenode(vp, uflags);
        !           184: }

CVSweb <webmaster@jp.NetBSD.org>