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

File: [cvs.NetBSD.org] / src / sys / fs / puffs / puffs_subr.c (download)

Revision 1.66, Sun Nov 16 19:34:30 2008 UTC (5 years, 10 months ago) by pooka
Branch: MAIN
CVS Tags: yamt-pagecache-tag8, yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, yamt-pagecache, yamt-nfs-mp-base9, yamt-nfs-mp-base8, yamt-nfs-mp-base7, yamt-nfs-mp-base6, yamt-nfs-mp-base5, yamt-nfs-mp-base4, yamt-nfs-mp-base3, yamt-nfs-mp-base11, yamt-nfs-mp-base10, uebayasi-xip-base4, uebayasi-xip-base3, uebayasi-xip-base2, uebayasi-xip-base1, uebayasi-xip-base, uebayasi-xip, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, rmind-uvmplock-nbase, rmind-uvmplock-base, rmind-uvmplock, rmind-smpnet-nbase, rmind-smpnet-base, rmind-smpnet, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, nick-hppapmap-base4, nick-hppapmap-base3, nick-hppapmap-base2, nick-hppapmap-base, netbsd-7-base, netbsd-7, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, mjf-devfs2-base, matt-premerge-20091211, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, matt-mips64-premerge-20101231, khorben-n900, jymxensuspend-base, jym-xensuspend-nbase, jym-xensuspend-base, jym-xensuspend, jruoho-x86intr-base, jruoho-x86intr, jmcneill-usbmp-pre-base2, jmcneill-usbmp-base9, jmcneill-usbmp-base8, jmcneill-usbmp-base7, jmcneill-usbmp-base6, jmcneill-usbmp-base5, jmcneill-usbmp-base4, jmcneill-usbmp-base3, jmcneill-usbmp-base2, jmcneill-usbmp-base10, jmcneill-usbmp-base, jmcneill-usbmp, jmcneill-audiomp3-base, jmcneill-audiomp3, haad-nbase2, haad-dm-base2, haad-dm-base, cherry-xenmp-base, cherry-xenmp, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2, agc-symver-base, agc-symver, ad-audiomp2-base, ad-audiomp2, HEAD
Changes since 1.65: +3 -2 lines

more <sys/buf.h> police

/*	$NetBSD: puffs_subr.c,v 1.66 2008/11/16 19:34:30 pooka Exp $	*/

/*
 * Copyright (c) 2006, 2007  Antti Kantee.  All Rights Reserved.
 *
 * Development of this software was supported by the
 * Ulla Tuominen Foundation and the Finnish Cultural Foundation.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: puffs_subr.c,v 1.66 2008/11/16 19:34:30 pooka Exp $");

#include <sys/param.h>
#include <sys/buf.h>
#include <sys/malloc.h>
#include <sys/mount.h>
#include <sys/namei.h>
#include <sys/poll.h>
#include <sys/proc.h>

#include <fs/puffs/puffs_msgif.h>
#include <fs/puffs/puffs_sys.h>

#ifdef PUFFSDEBUG
int puffsdebug;
#endif

void
puffs_makecn(struct puffs_kcn *pkcn, struct puffs_kcred *pkcr,
	const struct componentname *cn, int full)
{

	pkcn->pkcn_nameiop = cn->cn_nameiop;
	pkcn->pkcn_flags = cn->cn_flags;

	if (full) {
		(void)strcpy(pkcn->pkcn_name, cn->cn_nameptr);
	} else {
		(void)memcpy(pkcn->pkcn_name, cn->cn_nameptr, cn->cn_namelen);
		pkcn->pkcn_name[cn->cn_namelen] = '\0';
	}
	pkcn->pkcn_namelen = cn->cn_namelen;
	pkcn->pkcn_consume = 0;

	puffs_credcvt(pkcr, cn->cn_cred);
}

/*
 * Convert given credentials to struct puffs_kcred for userspace.
 */
void
puffs_credcvt(struct puffs_kcred *pkcr, const kauth_cred_t cred)
{

	memset(pkcr, 0, sizeof(struct puffs_kcred));

	if (cred == NOCRED || cred == FSCRED) {
		pkcr->pkcr_type = PUFFCRED_TYPE_INTERNAL;
		if (cred == NOCRED)
			pkcr->pkcr_internal = PUFFCRED_CRED_NOCRED;
		if (cred == FSCRED)
			pkcr->pkcr_internal = PUFFCRED_CRED_FSCRED;
 	} else {
		pkcr->pkcr_type = PUFFCRED_TYPE_UUC;
		kauth_cred_to_uucred(&pkcr->pkcr_uuc, cred);
	}
}

void
puffs_parkdone_asyncbioread(struct puffs_mount *pmp,
	struct puffs_req *preq, void *arg)
{
	struct puffs_vnmsg_read *read_msg = (void *)preq;
	struct buf *bp = arg;
	size_t moved;

	DPRINTF(("%s\n", __func__));

	bp->b_error = checkerr(pmp, preq->preq_rv, __func__);
	if (bp->b_error == 0) {
		if (read_msg->pvnr_resid > bp->b_bcount) {
			puffs_senderr(pmp, PUFFS_ERR_READ, E2BIG,
			    "resid grew", preq->preq_cookie);
			bp->b_error = E2BIG;
		} else {
			moved = bp->b_bcount - read_msg->pvnr_resid;
			bp->b_resid = read_msg->pvnr_resid;

			memcpy(bp->b_data, read_msg->pvnr_data, moved);
		}
	}

	biodone(bp);
}

void
puffs_parkdone_asyncbiowrite(struct puffs_mount *pmp,
	struct puffs_req *preq, void *arg)
{
	struct puffs_vnmsg_write *write_msg = (void *)preq;
	struct buf *bp = arg;

	DPRINTF(("%s\n", __func__));

	bp->b_error = checkerr(pmp, preq->preq_rv, __func__);
	if (bp->b_error == 0) {
		if (write_msg->pvnr_resid > bp->b_bcount) {
			puffs_senderr(pmp, PUFFS_ERR_WRITE, E2BIG,
			    "resid grew", preq->preq_cookie);
			bp->b_error = E2BIG;
		} else {
			bp->b_resid = write_msg->pvnr_resid;
		}
	}

	biodone(bp);
}

/* XXX: userspace can leak kernel resources */
void
puffs_parkdone_poll(struct puffs_mount *pmp, struct puffs_req *preq, void *arg)
{
	struct puffs_vnmsg_poll *poll_msg = (void *)preq;
	struct puffs_node *pn = arg;
	int revents, error;

	error = checkerr(pmp, preq->preq_rv, __func__);
	if (error)
		revents = poll_msg->pvnr_events;
	else
		revents = POLLERR;

	mutex_enter(&pn->pn_mtx);
	pn->pn_revents |= revents;
	mutex_exit(&pn->pn_mtx);

	selnotify(&pn->pn_sel, revents, 0);

	puffs_releasenode(pn);
}

void
puffs_mp_reference(struct puffs_mount *pmp)
{

	KASSERT(mutex_owned(&pmp->pmp_lock));
	pmp->pmp_refcount++;
}

void
puffs_mp_release(struct puffs_mount *pmp)
{

	KASSERT(mutex_owned(&pmp->pmp_lock));
	if (--pmp->pmp_refcount == 0)
		cv_broadcast(&pmp->pmp_refcount_cv);
}

void
puffs_gop_size(struct vnode *vp, off_t size, off_t *eobp,
	int flags)
{

	*eobp = size;
}

void
puffs_gop_markupdate(struct vnode *vp, int flags)
{
	int uflags = 0;

	if (flags & GOP_UPDATE_ACCESSED)
		uflags |= PUFFS_UPDATEATIME;
	if (flags & GOP_UPDATE_MODIFIED)
		uflags |= PUFFS_UPDATEMTIME;

	puffs_updatenode(VPTOPP(vp), uflags, 0);
}

void
puffs_senderr(struct puffs_mount *pmp, int type, int error,
	const char *str, puffs_cookie_t ck)
{
	struct puffs_msgpark *park;
	struct puffs_error *perr;

	puffs_msgmem_alloc(sizeof(struct puffs_error), &park, (void *)&perr, 1);
	puffs_msg_setfaf(park);
	puffs_msg_setinfo(park, PUFFSOP_ERROR, type, ck);

	perr->perr_error = error;
	strlcpy(perr->perr_str, str, sizeof(perr->perr_str));

	puffs_msg_enqueue(pmp, park);
	puffs_msgmem_release(park);
}