[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.42.1, Sat Jan 17 12:10:54 2015 UTC (6 years, 3 months ago) by martin
Branch: netbsd-7
CVS Tags: netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0
Changes since 1.66: +2 -3 lines

Pull up following revision(s) (requested by maxv in ticket #427):
	sys/compat/svr4/svr4_schedctl.c: revision 1.8
	sys/netinet/tcp_timer.c: revision 1.88
	sys/miscfs/genfs/layer_vfsops.c: revision 1.45
	sys/compat/svr4/svr4_ioctl.c: revision 1.37
	sys/ufs/chfs/chfs_vfsops.c: revision 1.14
	sys/miscfs/fdesc/fdesc_vfsops.c: revision 1.91
	sys/compat/linux/arch/i386/linux_ptrace.c: revision 1.30
	sys/compat/common/kern_time_50.c: revision 1.28
	sys/netinet6/ip6_forward.c: revision 1.74
	sys/miscfs/umapfs/umap_vnops.c: revision 1.57
	sys/compat/svr4/svr4_fcntl.c: revision 1.74
	distrib/sets/lists/comp/mi: revision 1.1931
	sys/netinet6/udp6_output.c: revision 1.46
	sys/fs/puffs/puffs_compat.c: revision 1.3
	sys/fs/udf/udf_rename.c: revision 1.11
	sys/compat/svr4/svr4_filio.c: revision 1.24
	sys/fs/udf/udf_rename.c: revision 1.12
	sys/netinet/tcp_usrreq.c: revision 1.202
	sys/miscfs/umapfs/umap_subr.c: revision 1.29
	sys/compat/linux/common/linux_fadvise64.c: revision 1.3
	sys/netinet/if_atm.c: revision 1.34
	sys/miscfs/procfs/procfs_subr.c: revision 1.106
	sys/miscfs/genfs/layer_subr.c: revision 1.37
	sys/netinet/tcp_sack.c: revision 1.30
	sys/compat/freebsd/freebsd_misc.c: revision 1.33
	sys/compat/freebsd/freebsd_file.c: revision 1.33
	sys/ufs/chfs/chfs_vnode.c: revision 1.12
	sys/compat/svr4/svr4_ttold.c: revision 1.34
	sys/compat/linux/common/linux_file.c: revision 1.114
	sys/compat/linux/arch/mips/linux_machdep.c: revision 1.43
	sys/compat/linux/common/linux_signal.c: revision 1.76
	sys/compat/common/compat_util.c: revision 1.46
	sys/compat/linux/arch/arm/linux_ptrace.c: revision 1.18
	sys/compat/svr4/svr4_sockio.c: revision 1.36
	sys/compat/linux/arch/arm/linux_machdep.c: revision 1.32
	sys/compat/svr4/svr4_signal.c: revision 1.66
	sys/kern/kern_exec.c: revision 1.410
	sys/fs/puffs/puffs_vfsops.c: revision 1.115
	sys/compat/svr4/svr4_exec_elf64.c: revision 1.15
	sys/compat/linux/arch/i386/linux_machdep.c: revision 1.159
	sys/compat/linux/arch/alpha/linux_machdep.c: revision 1.50
	sys/compat/linux32/common/linux32_misc.c: revision 1.24
	sys/netinet/in_pcb.c: revision 1.153
	sys/sys/malloc.h: revision 1.116
	sys/compat/common/if_43.c: revision 1.9
	share/man/man9/Makefile: revision 1.380
	sys/netinet/tcp_vtw.c: revision 1.12
	sys/miscfs/umapfs/umap_vfsops.c: revision 1.95
	sys/ufs/ext2fs/ext2fs_vfsops.c: revision 1.186
	sys/compat/common/uipc_syscalls_43.c: revision 1.46
	sys/ufs/ext2fs/ext2fs_vnops.c: revision 1.115
	sys/fs/puffs/puffs_msgif.c: revision 1.97
	sys/compat/svr4/svr4_ipc.c: revision 1.27
	sys/compat/linux/common/linux_exec.c: revision 1.117
	sys/ufs/ext2fs/ext2fs_readwrite.c: revision 1.66
	sys/netinet/tcp_output.c: revision 1.179
	sys/compat/svr4/svr4_termios.c: revision 1.28
	sys/fs/udf/udf_strat_bootstrap.c: revision 1.4
	sys/fs/puffs/puffs_subr.c: revision 1.67
	sys/fs/puffs/puffs_node.c: revision 1.36
	sys/miscfs/overlay/overlay_vnops.c: revision 1.21
	sys/fs/cd9660/cd9660_node.c: revision 1.34
	sys/netinet/raw_ip.c: revision 1.146
	sys/sys/mallocvar.h: revision 1.13
	sys/miscfs/overlay/overlay_vfsops.c: revision 1.63
	share/man/man9/malloc.9: revision 1.50
	sys/netinet6/dest6.c: revision 1.18
	sys/compat/linux/common/linux_uselib.c: revision 1.33
	sys/compat/linux/common/linux_socket.c: revision 1.120
	share/man/man9/malloc.9: revision 1.51
	sys/netinet/tcp_subr.c: revision 1.257
	sys/compat/linux/common/linux_socketcall.c: revision 1.45
	sys/compat/linux/common/linux_fadvise64_64.c: revision 1.3
	sys/compat/freebsd/freebsd_ipc.c: revision 1.17
	sys/compat/linux/common/linux_misc_notalpha.c: revision 1.109
	sys/compat/linux/arch/alpha/linux_pipe.c: revision 1.17
	sys/netinet6/in6_pcb.c: revision 1.132
	sys/netinet6/in6_ifattach.c: revision 1.94
	sys/compat/svr4/svr4_exec_elf32.c: revision 1.15
	sys/miscfs/nullfs/null_vfsops.c: revision 1.90
	sys/fs/cd9660/cd9660_util.c: revision 1.12
	sys/compat/linux/arch/powerpc/linux_machdep.c: revision 1.48
	sys/compat/freebsd/freebsd_exec_elf32.c: revision 1.20
	sys/miscfs/procfs/procfs_vfsops.c: revision 1.94
	sys/compat/linux/arch/powerpc/linux_ptrace.c: revision 1.28
	sys/compat/linux/common/linux_sched.c: revision 1.67
	sys/compat/linux/common/linux_exec_aout.c: revision 1.67
	sys/compat/linux/common/linux_pipe.c: revision 1.67
	sys/compat/linux/common/linux_llseek.c: revision 1.34
	sys/compat/linux/arch/mips/linux_ptrace.c: revision 1.10
Do not uselessly include <sys/malloc.h>.
Cleanup:
 - remove struct kmembuckets (dead)
 - correctly deadify MALLOC_XX
 - remove MALLOC_DEFINE_LIMIT and MALLOC_JUSTDEFINE_LIMIT (dead)
 - remove malloc_roundup(), malloc_type_setlimit(), MALLOC_DEFINE_LIMIT()
   and MALLOC_JUSTDEFINE_LIMIT() from man 9 malloc
New sentence, new line. Bump date for previous.
Obsolete malloc_roundup(9), malloc_type_setlimit(9) and MALLOC_DEFINE_LIMIT(9)
man pages.

/*	$NetBSD: puffs_subr.c,v 1.66.42.1 2015/01/17 12:10:54 martin 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.42.1 2015/01/17 12:10:54 martin Exp $");

#include <sys/param.h>
#include <sys/buf.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);
}