[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.3

1.44.2.3! joerg       1: /*     $NetBSD: puffs_subr.c,v 1.44.2.2 2007/10/26 15:48:19 joerg 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.3! joerg      32: __KERNEL_RCSID(0, "$NetBSD: puffs_subr.c,v 1.44.2.2 2007/10/26 15:48:19 joerg 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.44.2.2  joerg      39: #include <sys/proc.h>
1.1       pooka      40:
                     41: #include <fs/puffs/puffs_msgif.h>
                     42: #include <fs/puffs/puffs_sys.h>
                     43:
1.19      pooka      44: #ifdef PUFFSDEBUG
1.10      pooka      45: int puffsdebug;
                     46: #endif
                     47:
1.1       pooka      48: void
1.36      pooka      49: puffs_makecn(struct puffs_kcn *pkcn, struct puffs_kcred *pkcr,
1.38      pooka      50:        struct puffs_kcid *pkcid, const struct componentname *cn, int full)
1.1       pooka      51: {
                     52:
1.12      pooka      53:        pkcn->pkcn_nameiop = cn->cn_nameiop;
                     54:        pkcn->pkcn_flags = cn->cn_flags;
1.37      pooka      55:        puffs_cidcvt(pkcid, cn->cn_lwp);
1.1       pooka      56:
1.38      pooka      57:        if (full) {
                     58:                (void)strcpy(pkcn->pkcn_name, cn->cn_nameptr);
                     59:        } else {
                     60:                (void)memcpy(pkcn->pkcn_name, cn->cn_nameptr, cn->cn_namelen);
                     61:                pkcn->pkcn_name[cn->cn_namelen] = '\0';
                     62:        }
1.12      pooka      63:        pkcn->pkcn_namelen = cn->cn_namelen;
1.38      pooka      64:        pkcn->pkcn_consume = 0;
1.36      pooka      65:
                     66:        puffs_credcvt(pkcr, cn->cn_cred);
1.1       pooka      67: }
                     68:
                     69: /*
1.36      pooka      70:  * Convert given credentials to struct puffs_kcred for userspace.
1.1       pooka      71:  */
                     72: void
1.36      pooka      73: puffs_credcvt(struct puffs_kcred *pkcr, const kauth_cred_t cred)
1.1       pooka      74: {
                     75:
1.36      pooka      76:        memset(pkcr, 0, sizeof(struct puffs_kcred));
1.1       pooka      77:
                     78:        if (cred == NOCRED || cred == FSCRED) {
1.36      pooka      79:                pkcr->pkcr_type = PUFFCRED_TYPE_INTERNAL;
1.1       pooka      80:                if (cred == NOCRED)
1.36      pooka      81:                        pkcr->pkcr_internal = PUFFCRED_CRED_NOCRED;
1.1       pooka      82:                if (cred == FSCRED)
1.36      pooka      83:                        pkcr->pkcr_internal = PUFFCRED_CRED_FSCRED;
1.1       pooka      84:        } else {
1.36      pooka      85:                pkcr->pkcr_type = PUFFCRED_TYPE_UUC;
                     86:                kauth_cred_to_uucred(&pkcr->pkcr_uuc, cred);
1.1       pooka      87:        }
                     88: }
                     89:
1.37      pooka      90: void
                     91: puffs_cidcvt(struct puffs_kcid *pkcid, const struct lwp *l)
1.1       pooka      92: {
                     93:
1.37      pooka      94:        if (l) {
                     95:                pkcid->pkcid_type = PUFFCID_TYPE_REAL;
                     96:                pkcid->pkcid_pid = l->l_proc->p_pid;
                     97:                pkcid->pkcid_lwpid = l->l_lid;
                     98:        } else {
                     99:                pkcid->pkcid_type = PUFFCID_TYPE_FAKE;
                    100:                pkcid->pkcid_pid = 0;
                    101:                pkcid->pkcid_lwpid = 0;
                    102:        }
1.1       pooka     103: }
1.7       pooka     104:
                    105: void
1.44.2.1  joerg     106: puffs_parkdone_asyncbioread(struct puffs_mount *pmp,
                    107:        struct puffs_req *preq, void *arg)
1.27      pooka     108: {
1.44.2.2  joerg     109:        struct puffs_vnmsg_read *read_msg = (void *)preq;
1.27      pooka     110:        struct buf *bp = arg;
                    111:        size_t moved;
                    112:
1.44.2.3! joerg     113:        DPRINTF(("%s\n", __func__));
        !           114:
1.44.2.1  joerg     115:        bp->b_error = checkerr(pmp, preq->preq_rv, __func__);
1.27      pooka     116:        if (bp->b_error == 0) {
1.44.2.3! joerg     117:                if (read_msg->pvnr_resid > bp->b_bcount) {
        !           118:                        puffs_senderr(pmp, PUFFS_ERR_READ, E2BIG,
        !           119:                            "resid grew", preq->preq_cookie);
        !           120:                        bp->b_error = E2BIG;
        !           121:                } else {
        !           122:                        moved = bp->b_bcount - read_msg->pvnr_resid;
        !           123:                        bp->b_resid = read_msg->pvnr_resid;
1.27      pooka     124:
1.44.2.3! joerg     125:                        memcpy(bp->b_data, read_msg->pvnr_data, moved);
        !           126:                }
        !           127:        }
        !           128:
        !           129:        biodone(bp);
        !           130: }
        !           131:
        !           132: void
        !           133: puffs_parkdone_asyncbiowrite(struct puffs_mount *pmp,
        !           134:        struct puffs_req *preq, void *arg)
        !           135: {
        !           136:        struct puffs_vnmsg_write *write_msg = (void *)preq;
        !           137:        struct buf *bp = arg;
        !           138:
        !           139:        DPRINTF(("%s\n", __func__));
        !           140:
        !           141:        bp->b_error = checkerr(pmp, preq->preq_rv, __func__);
        !           142:        if (bp->b_error == 0) {
        !           143:                if (write_msg->pvnr_resid > bp->b_bcount) {
        !           144:                        puffs_senderr(pmp, PUFFS_ERR_WRITE, E2BIG,
        !           145:                            "resid grew", preq->preq_cookie);
        !           146:                        bp->b_error = E2BIG;
        !           147:                } else {
        !           148:                        bp->b_resid = write_msg->pvnr_resid;
        !           149:                }
1.27      pooka     150:        }
                    151:
                    152:        biodone(bp);
                    153: }
1.28      pooka     154:
1.44      pooka     155: /* XXX: userspace can leak kernel resources */
1.28      pooka     156: void
1.44.2.1  joerg     157: puffs_parkdone_poll(struct puffs_mount *pmp, struct puffs_req *preq, void *arg)
1.31      pooka     158: {
1.44.2.2  joerg     159:        struct puffs_vnmsg_poll *poll_msg = (void *)preq;
1.31      pooka     160:        struct puffs_node *pn = arg;
1.44.2.1  joerg     161:        int revents, error;
1.31      pooka     162:
1.44.2.1  joerg     163:        error = checkerr(pmp, preq->preq_rv, __func__);
                    164:        if (error)
1.44.2.2  joerg     165:                revents = poll_msg->pvnr_events;
1.31      pooka     166:        else
                    167:                revents = POLLERR;
                    168:
                    169:        mutex_enter(&pn->pn_mtx);
                    170:        pn->pn_revents |= revents;
                    171:        mutex_exit(&pn->pn_mtx);
                    172:
                    173:        selnotify(&pn->pn_sel, 0);
                    174:
                    175:        puffs_releasenode(pn);
                    176: }
                    177:
                    178: void
1.28      pooka     179: puffs_mp_reference(struct puffs_mount *pmp)
                    180: {
                    181:
                    182:        KASSERT(mutex_owned(&pmp->pmp_lock));
                    183:        pmp->pmp_refcount++;
                    184: }
                    185:
                    186: void
                    187: puffs_mp_release(struct puffs_mount *pmp)
                    188: {
                    189:
                    190:        KASSERT(mutex_owned(&pmp->pmp_lock));
                    191:        if (--pmp->pmp_refcount == 0)
                    192:                cv_broadcast(&pmp->pmp_refcount_cv);
                    193: }
1.44.2.1  joerg     194:
                    195: void
                    196: puffs_gop_size(struct vnode *vp, off_t size, off_t *eobp,
                    197:        int flags)
                    198: {
                    199:
                    200:        *eobp = size;
                    201: }
                    202:
                    203: void
                    204: puffs_gop_markupdate(struct vnode *vp, int flags)
                    205: {
                    206:        int uflags = 0;
                    207:
                    208:        if (flags & GOP_UPDATE_ACCESSED)
                    209:                uflags |= PUFFS_UPDATEATIME;
                    210:        if (flags & GOP_UPDATE_MODIFIED)
                    211:                uflags |= PUFFS_UPDATEMTIME;
                    212:
1.44.2.3! joerg     213:        puffs_updatenode(VPTOPP(vp), uflags, 0);
        !           214: }
        !           215:
        !           216: void
        !           217: puffs_senderr(struct puffs_mount *pmp, int type, int error,
        !           218:        const char *str, void *cookie)
        !           219: {
        !           220:        struct puffs_msgpark *park;
        !           221:        struct puffs_error *perr;
        !           222:
        !           223:        puffs_msgmem_alloc(sizeof(struct puffs_error), &park, (void**)&perr, 1);
        !           224:        puffs_msg_setfaf(park);
        !           225:        puffs_msg_setinfo(park, PUFFSOP_ERROR, type, cookie);
        !           226:
        !           227:        perr->perr_error = error;
        !           228:        strlcpy(perr->perr_str, str, sizeof(perr->perr_str));
        !           229:
        !           230:        puffs_msg_enqueue(pmp, park);
        !           231:        puffs_msgmem_release(park);
1.44.2.1  joerg     232: }

CVSweb <webmaster@jp.NetBSD.org>