Пример #1
0
static long pipebwrite(struct chan *c, struct block *bp, uint32_t junk)
{
	long n;
	Pipe *p;
	//Prog *r;

	p = c->aux;
	switch (NETTYPE(c->qid.path)) {
		case Qdata0:
			if (c->flag & O_NONBLOCK)
				n = qbwrite_nonblock(p->q[1], bp);
			else
				n = qbwrite(p->q[1], bp);
			break;

		case Qdata1:
			if (c->flag & O_NONBLOCK)
				n = qbwrite_nonblock(p->q[0], bp);
			else
				n = qbwrite(p->q[0], bp);
			break;

		default:
			n = 0;
			panic("pipebwrite");
	}

	return n;
}
Пример #2
0
static long
pipebwrite(Chan *c, Block *bp, ulong)
{
	long n;
	Pipe *p;

	if(waserror()) {
		/* avoid notes when pipe is a mounted queue */
		if((c->flag & CMSG) == 0)
			postnote(up, 1, "sys: write on closed pipe", NUser);
		nexterror();
	}

	p = c->aux;
	switch(NETTYPE(c->qid.path)){
	case Qdata0:
		n = qbwrite(p->q[1], bp);
		break;

	case Qdata1:
		n = qbwrite(p->q[0], bp);
		break;

	default:
		n = 0;
		panic("pipebwrite");
	}

	poperror();
	return n;
}
Пример #3
0
static long
loopoput(Loop *lb, Link *link, Block *volatile bp)
{
	long n;

	n = BLEN(bp);

	/* make it a single block with space for the loopback timing header */
	if(waserror()){
		freeb(bp);
		nexterror();
	}
	bp = padblock(bp, Tmsize);
	if(bp->next)
		bp = concatblock(bp);
	if(BLEN(bp) < lb->minmtu)
		bp = adjustblock(bp, lb->minmtu);
	poperror();
	ptime(bp->rp, todget(nil));

	link->packets++;
	link->bytes += n;

	qbwrite(link->oq, bp);

	looper(lb);
	return n;
}
Пример #4
0
static long
ipbwrite(Chan* ch, Block* bp, ulong offset)
{
	Conv *c;
	Proto *x;
	Fs *f;
	int n;

	switch(TYPE(ch->qid)){
	case Qdata:
		f = ipfs[ch->dev];
		x = f->p[PROTO(ch->qid)];
		c = x->conv[CONV(ch->qid)];

		if(c->wq == nil)
			error(Eperm);

		if(bp->next)
			bp = concatblock(bp);
		n = BLEN(bp);
		qbwrite(c->wq, bp);
		return n;
	default:
		return devbwrite(ch, bp, offset);
	}
}
Пример #5
0
/*
 *  write to a queue.  only Maxatomic bytes at a time is atomic.
 */
int
qwrite(Queue *q, void *vp, int len)
{
	int n, sofar;
	Block *b;
	uchar *p = vp;

	QDEBUG if(!islo())
		print("qwrite hi %#p\n", getcallerpc(&q));

	sofar = 0;
	do {
		n = len-sofar;
		if(n > Maxatomic)
			n = Maxatomic;

		b = allocb(n);
		setmalloctag(b, (up->text[0]<<24)|(up->text[1]<<16)|(up->text[2]<<8)|up->text[3]);
		if(waserror()){
			freeb(b);
			nexterror();
		}
		memmove(b->wp, p+sofar, n);
		poperror();
		b->wp += n;

		qbwrite(q, b);

		sofar += n;
	} while(sofar < len && (q->state & Qmsg) == 0);

	return len;
}
Пример #6
0
Файл: qio.c Проект: 8l/inferno
/*
 *  write to a queue.  only Maxatomic bytes at a time is atomic.
 */
int
qwrite(Queue *q, void *vp, int len)
{
	int n, sofar;
	Block *b;
	uchar *p = vp;

	sofar = 0;
	do {
		n = len-sofar;
		if(n > Maxatomic)
			n = Maxatomic;

		b = allocb(n);
		setmalloctag(b, getcallerpc(&q));
		if(waserror()){
			freeb(b);
			nexterror();
		}
		memmove(b->wp, p+sofar, n);
		poperror();
		b->wp += n;

		qbwrite(q, b);

		sofar += n;
	} while(sofar < len && (q->state & Qmsg) == 0);

	return len;
}
Пример #7
0
Файл: ether.c Проект: 8l/inferno
int
ethertxpkt(int ctlrno, Etherpkt *pkt, int len, int)
{
	Ctlr *ctlr;
	Block *b;
	int s;

	if((ctlr = attach(ctlrno)) == 0)
		return 0;

	if(qlen(ctlr->oq) > 16*1024){
		print("ether%d: tx queue full\n", ctlrno);
		return 0;
	}
	b = iallocb(sizeof(Etherpkt));
	memmove(b->wp, pkt, len);
	memmove(((Etherpkt*)b->wp)->s, ctlr->card.ea, Eaddrlen);
	b->wp += len;
	qbwrite(ctlr->oq, b);
	s = splhi();
	(*ctlr->card.transmit)(ctlr);
	splx(s);

	return 1;
}
Пример #8
0
Файл: qio.c Проект: 8l/inferno
void
qbputc(Queue *q, int c)
{
	Block *b;

	b = iallocb(1);
	*b->wp++ = c;
	qbwrite(q, b);
}
Пример #9
0
static long pipebwrite(struct chan *c, struct block *bp, uint32_t junk)
{
	ERRSTACK(2);
	long n;
	Pipe *p;
	//Prog *r;

	if (waserror()) {
		/* avoid exceptions when pipe is a mounted queue */
/*
		if((c->flag & CMSG) == 0) {
			r = up->iprog;
			if(r != NULL && r->kill == NULL)
				r->kill = "write on closed pipe";
		}
*/
		set_errno(EPIPE);
		nexterror();
	}

	p = c->aux;
	switch (NETTYPE(c->qid.path)) {
		case Qdata0:
			if (c->flag & O_NONBLOCK)
				n = qbwrite_nonblock(p->q[1], bp);
			else
				n = qbwrite(p->q[1], bp);
			break;

		case Qdata1:
			if (c->flag & O_NONBLOCK)
				n = qbwrite_nonblock(p->q[0], bp);
			else
				n = qbwrite(p->q[0], bp);
			break;

		default:
			n = 0;
			panic("pipebwrite");
	}

	poperror();
	return n;
}
Пример #10
0
Файл: ether.c Проект: 8l/inferno
int
etheriq(Ctlr *ctlr, Block *b, int freebp)
{
	if(memcmp(((Etherpkt*)b->rp)->d, ctlr->card.ea, Eaddrlen) != 0){
		if(freebp)
			freeb(b);
		return 0;
	}
	qbwrite(ctlr->iq, b);
	return 1;
}
Пример #11
0
Файл: devtk.c Проект: 8l/inferno
static void
tkwiretapper(void *top, char *cmd, char *result, void *image, Rectangle *rp)
{
	Block *b;
	int n;
	char *s, *e;

	n = 12;
	if(cmd != nil)
		n += strlen(cmd)+2+1;
	if(result != nil)
		n += strlen(result)+2+1;
	if(image != nil)
		n += 12;
	if(rp != nil)
		n += 4*20;
	n++;
	b = allocb(n);
	if(b != nil){
		s = (char*)b->wp;
		e = s+n;
		s += snprint(s, e-s, "%p", top);
		if(cmd != nil){
			*s++ = ' ';
			*s++ = '[';
			n = strlen(cmd);
			memmove(s, cmd, n);
			s += n;
			*s++ = ']';
		}
		/* ignore result for now */
		if(image != nil)
			s += snprint(s, e-s, " %p", image);
		if(rp != nil)
			s += snprint(s, e-s, " %d %d %d %d", rp->min.x, rp->min.y, rp->max.x, rp->max.y);
		*s++ = '\n';
		b->wp = (uchar*)s;
		release();
		qlock(&tkevents.l);
		if(waserror()){
			qunlock(&tkevents.l);
			acquire();
			return;
		}
		if(tkevents.eq != nil)
			qbwrite(tkevents.eq, b);
		poperror();
		qunlock(&tkevents.l);
		acquire();
	}
}
Пример #12
0
static long
pipebwrite(Chan *c, Block *bp, ulong junk)
{
	long n;
	Pipe *p;

	USED(junk);
	if(waserror()) {
		/* avoid exceptions when pipe is a mounted queue */
		if((c->flag & CMSG) == 0) {
			if (up->ptype == Vm_proc) {
                vproc_t* r = (vproc_t*)up;
                if (r->kill == nil) {
                    r->kill = "write on closed pipe";
                }
            }
		}
		nexterror();
	}

	p = c->aux;
	switch(NETTYPE(c->qid.path)){
	case Qdata0:
		n = qbwrite(p->q[1], bp);
		break;

	case Qdata1:
		n = qbwrite(p->q[0], bp);
		break;

	default:
		n = 0;
		panic("pipebwrite");
	}

	poperror();
	return n;
}
Пример #13
0
/*
 *  write to a queue.  only Maxatomic bytes at a time is atomic.
 */
int qwrite(struct queue *q, void *vp, int len)
{
	int n, sofar;
	struct block *b;
	uint8_t *p = vp;
	void *ext_buf;

	QDEBUG if (!islo())
		 printd("qwrite hi %p\n", getcallerpc(&q));

	sofar = 0;
	do {
		n = len - sofar;
		/* This is 64K, the max amount per single block.  Still a good value? */
		if (n > Maxatomic)
			n = Maxatomic;

		/* If n is small, we don't need to bother with the extra_data.  But
		 * until the whole stack can handle extd blocks, we'll use them
		 * unconditionally. */
#ifdef CONFIG_BLOCK_EXTRAS
		/* allocb builds in 128 bytes of header space to all blocks, but this is
		 * only available via padblock (to the left).  we also need some space
		 * for pullupblock for some basic headers (like icmp) that get written
		 * in directly */
		b = allocb(64);
		ext_buf = kmalloc(n, 0);
		memcpy(ext_buf, p + sofar, n);
		block_add_extd(b, 1, KMALLOC_WAIT); /* returns 0 on success */
		b->extra_data[0].base = (uintptr_t)ext_buf;
		b->extra_data[0].off = 0;
		b->extra_data[0].len = n;
		b->extra_len += n;
#else
		b = allocb(n);
		memmove(b->wp, p + sofar, n);
		b->wp += n;
#endif
			
		qbwrite(q, b);

		sofar += n;
	} while (sofar < len && (q->state & Qmsg) == 0);

	return len;
}
Пример #14
0
/*
 *  write to a queue.  only Maxatomic bytes at a time is atomic.
 */
int
qwrite(Queue *q, void *vp, int len)
{
	int n, sofar;
	Block *b;
	uchar *p = vp;

	QDEBUG if(!islo())
		print("qwrite hi %#p\n", getcallerpc(&q));

	/* stop queue bloat before allocating blocks */
	if(q->len/2 >= q->limit && q->noblock == 0 && q->bypass == nil){
		while(waserror()){
			if(up->procctl == Proc_exitme || up->procctl == Proc_exitbig)
				error(Egreg);
		}
		qflow(q);
		poperror();
	}

	sofar = 0;
	do {
		n = len-sofar;
		if(n > Maxatomic)
			n = Maxatomic;

		b = allocb(n);
		setmalloctag(b, (up->text[0]<<24)|(up->text[1]<<16)|(up->text[2]<<8)|up->text[3]);
		if(waserror()){
			freeb(b);
			nexterror();
		}
		memmove(b->wp, p+sofar, n);
		poperror();
		b->wp += n;

		qbwrite(q, b);

		sofar += n;
	} while(sofar < len && (q->state & Qmsg) == 0);

	return len;
}