Esempio n. 1
0
/* open the xenevt device; this is where we clone */
int
xenevtopen(dev_t dev, int flags, int mode, struct lwp *l)
{
	struct xenevt_d *d;
	struct file *fp;
	int fd, error;

	switch(minor(dev)) {
	case DEV_EVT:
		/* falloc() will use the descriptor for us. */
		if ((error = fd_allocfile(&fp, &fd)) != 0)
			return error;

		d = malloc(sizeof(*d), M_DEVBUF, M_WAITOK | M_ZERO);
		d->ci = &cpu_info_primary;
		mutex_init(&d->lock, MUTEX_DEFAULT, IPL_HIGH);
		cv_init(&d->cv, "xenevt");
		selinit(&d->sel);
		return fd_clone(fp, fd, flags, &xenevt_fileops, d);
	case DEV_XSD:
		/* no clone for /dev/xsd_kva */
		return (0);
	default:
		break;
	}
	return ENODEV;
}
Esempio n. 2
0
static int
xen_dev_open(dev_t dev, int flags, int mode, struct lwp *l)
{
	const struct xen_dev_info *xdinfo;
	int fd, err;
	struct file *fp;
	void *fdata;

	DPRINTF(("xen devsw: opening minor=%lu\n", (unsigned long)minor(dev)));

        if (minor(dev) < 0 || minor(dev) >= NUM_DEV_INFOS)
		return ENODEV;

	xdinfo = &devs[minor(dev)];

	if (!xdinfo->xd_open)
		return ENODEV;

	err = fd_allocfile(&fp, &fd);
	if (err)
		return err;

	DPRINTF(("%s: opening...\n", xdinfo->path));

	err = xdinfo->xd_open(fp, &fdata);
	if (err) {
		fd_abort(curproc, fp, fd);
		return err;
	}

	DPRINTF(("%s: opened, fd_clone\n", xdinfo->path));

	return fd_clone(fp, fd, flags, xdinfo->fo, fdata);
}
int
rndopen(dev_t dev, int flags, int fmt, struct lwp *l)
{
	bool hard;
	struct file *fp;
	int fd;
	int error;

	switch (minor(dev)) {
	case RND_DEV_URANDOM:
		hard = false;
		break;

	case RND_DEV_RANDOM:
		hard = true;
		break;

	default:
		return ENXIO;
	}

	error = fd_allocfile(&fp, &fd);
	if (error)
		return error;

	/*
	 * Allocate a context, but don't create a CPRNG yet -- do that
	 * lazily because it consumes entropy from the system entropy
	 * pool, which (currently) has the effect of depleting it and
	 * causing readers from /dev/random to block.  If this is
	 * /dev/urandom and the process is about to send only short
	 * reads to it, then we will be using a per-CPU CPRNG anyway.
	 */
	struct rnd_ctx *const ctx = pool_cache_get(rnd_ctx_cache, PR_WAITOK);
	ctx->rc_cprng = NULL;
	ctx->rc_hard = hard;

	error = fd_clone(fp, fd, flags, &rnd_fileops, ctx);
	KASSERT(error == EMOVEFD);

	return error;
}
Esempio n. 4
0
static int
tap_dev_cloner(struct lwp *l)
{
	struct tap_softc *sc;
	file_t *fp;
	int error, fd;

	if ((error = fd_allocfile(&fp, &fd)) != 0)
		return (error);

	if ((sc = tap_clone_creator(-1)) == NULL) {
		fd_abort(curproc, fp, fd);
		return (ENXIO);
	}

	sc->sc_flags |= TAP_INUSE;

	return fd_clone(fp, fd, FREAD|FWRITE, &tap_fileops,
	    (void *)(intptr_t)device_unit(sc->sc_dev));
}
Esempio n. 5
0
/*
 * dmoverioopen:
 *
 *	Device switch open routine.
 */
int
dmoverioopen(dev_t dev, int flag, int mode, struct lwp *l)
{
	struct dmio_state *ds;
	struct file *fp;
	int error, fd, s;

	/* falloc() will use the descriptor for us. */
	if ((error = fd_allocfile(&fp, &fd)) != 0)
		return (error);

	s = splsoftclock();
	ds = pool_get(&dmio_state_pool, PR_WAITOK);
	splx(s);

	memset(ds, 0, sizeof(*ds));
	simple_lock_init(&ds->ds_slock);
	TAILQ_INIT(&ds->ds_pending);
	TAILQ_INIT(&ds->ds_complete);
	selinit(&ds->ds_selq);

	return fd_clone(fp, fd, flag, &dmio_fileops, ds);
}
Esempio n. 6
0
int
svr4_netopen(dev_t dev, int flag, int mode, struct lwp *l)
{
	int type, protocol;
	int fd;
	file_t *fp;
	struct socket *so;
	int error;
	int family;

	DPRINTF(("netopen("));

	if (curlwp->l_dupfd >= 0)	/* XXX */
		return ENODEV;

	switch (minor(dev)) {
	case dev_udp:
		family = AF_INET;
		type = SOCK_DGRAM;
		protocol = IPPROTO_UDP;
		DPRINTF(("udp, "));
		break;

	case dev_tcp:
		family = AF_INET;
		type = SOCK_STREAM;
		protocol = IPPROTO_TCP;
		DPRINTF(("tcp, "));
		break;

	case dev_ip:
	case dev_rawip:
		family = AF_INET;
		type = SOCK_RAW;
		protocol = IPPROTO_IP;
		DPRINTF(("ip, "));
		break;

	case dev_icmp:
		family = AF_INET;
		type = SOCK_RAW;
		protocol = IPPROTO_ICMP;
		DPRINTF(("icmp, "));
		break;

	case dev_unix_dgram:
		family = AF_LOCAL;
		type = SOCK_DGRAM;
		protocol = 0;
		DPRINTF(("unix-dgram, "));
		break;

	case dev_unix_stream:
	case dev_unix_ord_stream:
		family = AF_LOCAL;
		type = SOCK_STREAM;
		protocol = 0;
		DPRINTF(("unix-stream, "));
		break;

	default:
		DPRINTF(("%d);\n", minor(dev)));
		return EOPNOTSUPP;
	}

	if ((error = fd_allocfile(&fp, &fd)) != 0)
		return error;

	if ((error = socreate(family, &so, type, protocol, l, NULL)) != 0) {
		DPRINTF(("socreate error %d\n", error));
		fd_abort(curproc, fp, fd);
		return error;
	}

	error = fd_clone(fp, fd, flag, &svr4_netops, so);
	fp->f_type = DTYPE_SOCKET;
	(void)svr4_stream_get(fp);

	DPRINTF(("ok);\n"));
	return error;
}