示例#1
0
文件: devpipe.c 项目: Shamar/harvey
/*
 *  create a pipe, no streams are created until an open
 */
static Chan*
pipeattach(char *spec)
{
	Pipe *p;
	Chan *c;

	c = devattach('|', spec);
	p = malloc(sizeof(Pipe));
	if(p == 0)
		exhausted("memory");
	p->ref = 1;

	p->q[0] = qopen(Pipeqsize, 0, 0, 0);
	if(p->q[0] == 0){
		free(p);
		exhausted("memory");
	}
	p->q[1] = qopen(Pipeqsize, 0, 0, 0);
	if(p->q[1] == 0){
		free(p->q[0]);
		free(p);
		exhausted("memory");
	}

	lock(&pipealloc);
	p->path = ++pipealloc.path;
	unlock(&pipealloc);

	mkqid(&c->qid, PIPEQID(2*p->path, Qdir), 0, QTDIR);
	c->aux = p;
	c->devno = 0;
	return c;
}
示例#2
0
文件: linux_file.c 项目: husthl/qos
static bool test_all(void){
    test( linux_file_vfs_open() );

    // write
    int fid = qopen( "./a.txt", O_RDWR | O_CREAT | O_TRUNC, NULL );
    test( 0 != fid );
    test( 5 == qwrite( fid, "12345", 5 ) );
    {
        struct qstat buf;
        test( qfstat( fid, &buf ) );
        test( 5 == buf.size );
    }
    test( qclose( fid ) );
    fid = 0;

    // read
    fid = qopen( "./a.txt", O_RDONLY, NULL );
    test( 0 != fid );
    {
        struct qstat buf;
        test( qfstat( fid, &buf ) );
        test( 5 == buf.size );
    }
    char buf[100];
    memset( buf, 0, sizeof( buf ) );
    test( 5 == qread( fid, buf, sizeof(buf) ) );
    test( 0 == memcmp( buf, "12345", 5 ) );
    test( qclose( fid ) );
    fid = 0;

    return true;
}
示例#3
0
文件: devuart.c 项目: 8l/inferno
static void
uartsetup(ulong port, char *name)
{
	Uart *p;

	if(nuart >= Nuart)
		return;

	p = xalloc(sizeof(Uart));
	uart[nuart++] = p;
	strcpy(p->name, name);

	p->reg = &UARTREG[port];
	p->bps = 9600;
	p->bits = 8;
	p->parity = 'n';
	p->stop = 1;
	p->kickme = 0;
	p->port = port;

	p->iq = qopen(4*1024, 0, 0 , p);
	p->oq = qopen(4*1024, 0, uartkick, p);

	p->ip = p->istage;
	p->ie = &p->istage[Stagesize];
	p->op = p->ostage;
	p->oe = p->ostage;

	intrenable(UARTTXbit(port), uarttxintr, p, 0); 
	intrenable(UARTRXbit(port), uartrxintr, p, 0); 
}
示例#4
0
/*
 *  enable/disable uart and add/remove to list of enabled uarts
 */
static Uart*
uartenable(Uart *p)
{
	Uart **l;

	if(p->iq == nil){
		if((p->iq = qopen(8*1024, 0, uartflow, p)) == nil)
			return nil;
	}
	else
		qreopen(p->iq);
	if(p->oq == nil){
		if((p->oq = qopen(8*1024, 0, uartkick, p)) == nil){
			qfree(p->iq);
			p->iq = nil;
			return nil;
		}
	}
	else
		qreopen(p->oq);

	p->ir = p->istage;
	p->iw = p->istage;
	p->ie = &p->istage[Stagesize];
	p->op = p->ostage;
	p->oe = p->ostage;

	p->hup_dsr = p->hup_dcd = 0;
	p->dsr = p->dcd = 0;

	/* assume we can send */
	p->cts = 1;
	p->ctsbackoff = 0;

	if(p->bits == 0)
		uartctl(p, "l8");
	if(p->stop == 0)
		uartctl(p, "s1");
	if(p->parity == 0)
		uartctl(p, "pn");
	if(p->baud == 0)
		uartctl(p, "b9600");
	(*p->phys->enable)(p, 1);

	lock(&uartalloc.Lock);
	for(l = &uartalloc.elist; *l; l = &(*l)->elist){
		if(*l == p)
			break;
	}
	if(*l == 0){
		p->elist = uartalloc.elist;
		uartalloc.elist = p;
	}
	p->enabled = 1;
	unlock(&uartalloc.Lock);

	return p;
}
示例#5
0
文件: devcons.c 项目: 8l/inferno
static Chan*
consopen(Chan *c, int omode)
{
	c->aux = 0;
	switch((ulong)c->qid.path){
	case Qconsctl:
		if(!iseve())
			error(Eperm);
		qlock(&kbd);
		kbd.ctl++;
		qunlock(&kbd);
		break;

	case Qkeyboard:
		if((omode & 3) != OWRITE) {
			qlock(&kbd);
			kbd.kbdr++;
			flushkbdline(kbdq);
			kbd.raw = 1;
			qunlock(&kbd);
		}
		break;

	case Qscancode:
		qlock(&kbd);
		if(kscanq || !kscanid) {
			qunlock(&kbd);
			c->flag &= ~COPEN;
			if(kscanq)
				error(Einuse);
			else
				error(Ebadarg);
		}
		kscanq = qopen(256, 0, nil, nil);
		qunlock(&kbd);
		break;

	case Qkprint:
		if((omode & 3) != OWRITE) {
			wlock(&kprintq);
			if(kprintq.q != nil){
				wunlock(&kprintq);
				error(Einuse);
			}
			kprintq.q = qopen(32*1024, Qcoalesce, nil, nil);
			if(kprintq.q == nil){
				wunlock(&kprintq);
				error(Enomem);
			}
			qnoblock(kprintq.q, 1);
			wunlock(&kprintq);
			c->iounit = qiomaxatomic;
		}
		break;
	}
	return devopen(c, omode, consdir, nelem(consdir), devgen);
}
示例#6
0
Chan*
consopen(Chan *c, int omode)
{
	c = devopen(c, omode, contab, nelem(contab), devgen);
	switch((ulong)c->qid.path) {
	case Qconsctl:
		incref(&kbd.ctl);
		break;
	case Qpointer:
		if(incref(&kbd.ptr) != 1){
			decref(&kbd.ptr);
			c->flag &= ~COPEN;
			error(Einuse);
		}
		break;
	case Qscancode:
		qlock(&kbd.gq);
		if(gkscanq || !gkscanid) {
			qunlock(&kbd.q);
			c->flag &= ~COPEN;
			if(gkscanq)
				error(Einuse);
			else
				error(Ebadarg);
		}
		gkscanq = qopen(256, 0, nil, nil);
		qunlock(&kbd.gq);
		break;
	case Qkprint:
		wlock(&kprintq.l);
		if(kprintq.q != nil){
			wunlock(&kprintq.l);
			c->flag &= ~COPEN;
			error(Einuse);
		}
		kprintq.q = qopen(32*1024, 0, 0, 0);
		if(kprintq.q == nil){
			wunlock(&kprintq.l);
			c->flag &= ~COPEN;
			error(Enomem);
		}
		qnoblock(kprintq.q, 1);
		wunlock(&kprintq.l);
		break;
	case Qsnarf:
		if(omode == ORDWR)
			error(Eperm);
		if(omode == OREAD)
			c->aux = strdup("");
		else
			c->aux = mallocz(SnarfSize, 1);
		break;
	}
	return c;
}
示例#7
0
文件: ipifc.c 项目: 7perl/akaros
/*
 *  called when a new ipifc structure is created
 */
static void ipifccreate(struct conv *c)
{
	struct Ipifc *ifc;

	c->rq = qopen(QMAX, 0, 0, 0);
	c->sq = qopen(2 * QMAX, 0, 0, 0);
	c->wq = qopen(QMAX, Qkick, ipifckick, c);
	ifc = (struct Ipifc *)c->ptcl;
	ifc->conv = c;
	ifc->unbinding = 0;
	ifc->m = NULL;
	ifc->reassemble = 0;
}
示例#8
0
文件: ipifc.c 项目: qioixiy/harvey
/*
 *  called when a new ipifc structure is created
 */
static void
ipifccreate(Conv *c)
{
	Ipifc *ifc;

	c->rq = qopen(QMAX, 0, 0, 0);
	c->sq = qopen(QMAX, 0, 0, 0);
	c->wq = qopen(QMAX, Qkick, ipifckick, c);
	ifc = (Ipifc*)c->ptcl;
	ifc->conv = c;
	ifc->unbinding = 0;
	ifc->medium = nil;
	ifc->reassemble = 0;
}
示例#9
0
void
consinit(void)
{
	kbdq = qopen(512, 0, nil, nil);
	if(kbdq == 0)
		panic("no memory");
	lineq = qopen(2*1024, 0, nil, nil);
	if(lineq == 0)
		panic("no memory");
	gkbdq = qopen(512, 0, nil, nil);
	if(gkbdq == 0)
		panic("no memory");
	randominit();
}
示例#10
0
文件: cons.c 项目: ihategit/akaros
static struct chan *consopen(struct chan *c, int omode)
{
    c->aux = NULL;
    c = devopen(c, omode, consdir, ARRAY_SIZE(consdir), devgen);
    switch ((uint32_t) c->qid.path) {
    case Qconsctl:
        kref_get(&kbd.ctl, 1);
        break;

    case Qkprint:
        if (atomic_swap(&kprintinuse, 1) != 0) {
            c->flag &= ~COPEN;
            error(EADDRINUSE, "kprintinuse lock failed");
        }
        if (kprintoq == NULL) {
            kprintoq = qopen(8 * 1024, Qcoalesce, 0, 0);
            if (kprintoq == NULL) {
                c->flag &= ~COPEN;
                error(ENOMEM, "Can't allocate kprintoq");
            }
            qdropoverflow(kprintoq, 1);
        } else
            qreopen(kprintoq);
        c->iounit = qiomaxatomic;
        break;
    }
    return c;
}
示例#11
0
文件: cons.c 项目: ihategit/akaros
void printinit(void)
{
    lineq = qopen(2 * 1024, 0, NULL, NULL);
    if (lineq == NULL)
        panic("printinit");
    qdropoverflow(lineq, 1);
}
int create_open_file(const char* file_name) {
	int file_id = qopen(file_name, O_BINARY | O_TRUNC | O_CREAT);
	if (file_id == BADADDR)
		file_id = qcreate(file_name, 511);

	return file_id;
}
示例#13
0
static Chan*
consopen(Chan *c, int omode)
{
	c->aux = nil;
	c = devopen(c, omode, consdir, nelem(consdir), devgen);
	switch((ulong)c->qid.path){
	case Qkprint:
		if(tas(&kprintinuse) != 0){
			c->flag &= ~COPEN;
			error(Einuse);
		}
		if(kprintoq == nil){
			kprintoq = qopen(8*1024, Qcoalesce, 0, 0);
			if(kprintoq == nil){
				c->flag &= ~COPEN;
				error(Enomem);
			}
			qnoblock(kprintoq, 1);
		}else
			qreopen(kprintoq);
		c->iounit = qiomaxatomic;
		break;
	}
	return c;
}
示例#14
0
文件: devcons.c 项目: 8l/inferno
static Chan*
consopen(Chan *c, int omode)
{
	c = devopen(c, omode, contab, nelem(contab), devgen);
	switch((ulong)c->qid.path) {
	case Qconsctl:
		incref(&kbd.ctl);
		break;

	case Qscancode:
		qlock(&kbd.gq);
		if(gkscanq != nil || gkscanid == nil) {
			qunlock(&kbd.q);
			c->flag &= ~COPEN;
			if(gkscanq)
				error(Einuse);
			else
				error("not supported");
		}
		gkscanq = qopen(256, 0, nil, nil);
		qunlock(&kbd.gq);
		break;

	case Qkprint:
		wlock(&kprintq.l);
		if(waserror()){
			wunlock(&kprintq.l);
			c->flag &= ~COPEN;
			nexterror();
		}
		if(kprintq.q != nil)
			error(Einuse);
		kprintq.q = qopen(32*1024, Qcoalesce, nil, nil);
		if(kprintq.q == nil)
			error(Enomem);
		qnoblock(kprintq.q, 1);
		poperror();
		wunlock(&kprintq.l);
		c->iounit = qiomaxatomic;
		break;
	case Qevents:
		c->aux = qopen(512, 0, nil, nil);
		add_listener(&event_listeners, c->aux);
		break;
	}
	return c;
}
示例#15
0
文件: devcons.c 项目: 8l/inferno
void
printinit(void)
{
	lineq = qopen(2*1024, 0, nil, nil);
	if(lineq == nil)
		panic("printinit");
	qnoblock(lineq, 1);
}
示例#16
0
void
consinit(void)
{
    uv_mutex_init(&line_lock);
    uv_cond_init(&line_ready);
    
	kbdq = qopen(512, 0, nil, nil);
	if(kbdq == 0)
		panic("no memory");
	lineq = qopen(2*1024, 0, nil, nil);
	if(lineq == 0)
		panic("no memory");
	gkbdq = qopen(512, 0, nil, nil);
	if(gkbdq == 0)
		panic("no memory");
	randominit();
}
示例#17
0
文件: pipe.c 项目: GanShun/akaros
/*
 *  create a pipe, no streams are created until an open
 */
static struct chan *pipeattach(char *spec)
{
	ERRSTACK(2);
	Pipe *p;
	struct chan *c;

	c = devattach(devname(), spec);
	p = kzmalloc(sizeof(Pipe), 0);
	if (p == 0)
		error(ENOMEM, ERROR_FIXME);
	if (waserror()) {
		freepipe(p);
		nexterror();
	}
	p->pipedir = kzmalloc(sizeof(pipedir), 0);
	if (p->pipedir == 0)
		error(ENOMEM, ERROR_FIXME);
	memmove(p->pipedir, pipedir, sizeof(pipedir));
	kstrdup(&p->user, current->user);
	kref_init(&p->ref, pipe_release, 1);
	qlock_init(&p->qlock);

	p->q[0] = qopen(pipealloc.pipeqsize, Qcoalesce, 0, 0);
	if (p->q[0] == 0)
		error(ENOMEM, ERROR_FIXME);
	p->q[1] = qopen(pipealloc.pipeqsize, Qcoalesce, 0, 0);
	if (p->q[1] == 0)
		error(ENOMEM, ERROR_FIXME);
	poperror();

	spin_lock(&(&pipealloc)->lock);
	p->path = ++pipealloc.path;
	spin_unlock(&(&pipealloc)->lock);

	c->qid.path = NETQID(2 * p->path, Qdir);
	c->qid.vers = 0;
	c->qid.type = QTDIR;
	c->aux = p;
	c->dev = 0;

	/* taps. */
	SLIST_INIT(&p->data_taps[0]);	/* already = 0; set to be futureproof */
	SLIST_INIT(&p->data_taps[1]);
	spinlock_init(&p->tap_lock);
	return c;
}
示例#18
0
文件: cons.c 项目: goovdl/akaros
void printinit(void)
{
#if 0
	lineq = qopen(2 * 1024, 0, NULL, NULL);
	if (lineq == NULL)
		panic("printinit");
	qnoblock(lineq, 1);
#endif
}
示例#19
0
文件: psaux.c 项目: 99years/plan9
void
psauxlink(void)
{
	psauxq = qopen(1024, 0, 0, 0);
	if(psauxq == nil)
		panic("psauxlink");
	qnoblock(psauxq, 1);
	i8042auxenable(psauxputc);
	addarchfile("psaux", DMEXCL|0660, psauxread, psauxwrite);
}
示例#20
0
文件: devcons.c 项目: 8l/inferno
static void
consinit(void)
{
	randominit();
	debuginit();
	debugkey('f', "files/6", fddump, 0);
	debugkey('q', "panic", qpanic, 1);
	debugkey('r', "exit", rexit, 1);
	klogq = qopen(128*1024, 0, 0, 0);
}
示例#21
0
static Uart*
pnp(void)
{
	Uart *uart;

	uart = &miniuart;
	if(uart->console == 0)
		kbdq = qopen(8*1024, 0, nil, nil);
	return uart;
}
示例#22
0
文件: iprouter.c 项目: 7perl/akaros
void iprouteropen(struct Fs *f)
{
	qlock(&(&f->iprouter)->qlock);
	f->iprouter.opens++;
	if (f->iprouter.q == NULL)
		f->iprouter.q = qopen(64 * 1024, 0, 0, 0);
	else if (f->iprouter.opens == 1)
		qreopen(f->iprouter.q);
	qunlock(&(&f->iprouter)->qlock);
}
示例#23
0
文件: netif.c 项目: goovdl/akaros
/*
 *  Increment the reference count of a network device.
 *  If id < 0, return an unused ether device.
 */
static int openfile(struct ether *nif, int id)
{
	ERRSTACK(1);
	struct netfile *f, **fp, **efp;

	if (id >= 0) {
		f = nif->f[id];
		if (f == 0)
			error(Enodev);
		qlock(&f->qlock);
		qreopen(f->in);
		f->inuse++;
		qunlock(&f->qlock);
		return id;
	}

	qlock(&nif->qlock);
	if (waserror()) {
		qunlock(&nif->qlock);
		nexterror();
	}
	efp = &nif->f[nif->nfile];
	for (fp = nif->f; fp < efp; fp++) {
		f = *fp;
		if (f == 0) {
			f = kzmalloc(sizeof(struct netfile), 0);
			if (f == 0)
				exhausted("memory");
			/* since we lock before netifinit (if we ever call that...) */
			qlock_init(&f->qlock);
			f->in = qopen(nif->limit, Qmsg, 0, 0);
			if (f->in == NULL) {
				kfree(f);
				exhausted("memory");
			}
			*fp = f;
			qlock(&f->qlock);
		} else {
			qlock(&f->qlock);
			if (f->inuse) {
				qunlock(&f->qlock);
				continue;
			}
		}
		f->inuse = 1;
		qreopen(f->in);
		netown(f, current->user, 0);
		qunlock(&f->qlock);
		qunlock(&nif->qlock);
		poperror();
		return fp - nif->f;
	}
	error(Enodev);
	return -1;	/* not reached */
}
示例#24
0
文件: ether.c 项目: 8l/inferno
int
etherinit(void)
{
	Ctlr *ctlr;
	int ctlrno, i, mask, n;

	mask = 0;
	for(ctlrno = 0; ctlrno < MaxEther; ctlrno++){
		ctlr = &ether[ctlrno];
		memset(ctlr, 0, sizeof(Ctlr));
		if(isaconfig("ether", ctlrno, &ctlr->card) == 0)
			continue;
		for(n = 0; cards[n].type; n++){
			if(strcmp(cards[n].type, ctlr->card.type))
				continue;
			ctlr->ctlrno = ctlrno;
			if((*cards[n].reset)(ctlr))
				break;

			ctlr->iq = qopen(16*1024, 1, 0, 0);
			ctlr->oq = qopen(16*1024, 1, 0, 0);

			ctlr->present = 1;
			mask |= 1<<ctlrno;

			print("ether%d: %s: port 0x%luX irq %d",
				ctlr->ctlrno, ctlr->card.type, ctlr->card.port, ctlr->card.irq);
			if(ctlr->card.mem)
				print(" addr 0x%luX", ctlr->card.mem & ~KZERO);
			if(ctlr->card.size)
				print(" size 0x%luX", ctlr->card.size);
			print(":");
			for(i = 0; i < sizeof(ctlr->card.ea); i++)
				print(" %2.2uX", ctlr->card.ea[i]);
			print("\n"); uartwait();
			setvec(ctlr->card.irq, ctlr->card.intr, ctlr);
			break;
		}
	}

	return mask;
}
示例#25
0
文件: netif.c 项目: Requaos/harvey
/*
 *  Increment the reference count of a network device.
 *  If id < 0, return an unused ether device.
 */
static int
openfile(Netif *nif, int id)
{
	Proc *up = externup();
	Netfile *f, **fp, **efp;

	if(id >= 0){
		f = nif->f[id];
		if(f == 0)
			error(Enodev);
		qlock(&f->q);
		qreopen(f->iq);
		f->inuse++;
		qunlock(&f->q);
		return id;
	}

	qlock(&nif->q);
	if(waserror()){
		qunlock(&nif->q);
		nexterror();
	}
	efp = &nif->f[nif->nfile];
	for(fp = nif->f; fp < efp; fp++){
		f = *fp;
		if(f == 0){
			f = malloc(sizeof(Netfile));
			if(f == 0)
				exhausted("memory");
			f->iq = qopen(nif->limit, Qmsg, 0, 0);
			if(f->iq == nil){
				free(f);
				exhausted("memory");
			}
			*fp = f;
			qlock(&f->q);
		} else {
			qlock(&f->q);
			if(f->inuse){
				qunlock(&f->q);
				continue;
			}
		}
		f->inuse = 1;
		qreopen(f->iq);
		netown(f, up->user, 0);
		qunlock(&f->q);
		qunlock(&nif->q);
		poperror();
		return fp - nif->f;
	}
	error(Enodev);
	return -1;	/* not reached */
}
示例#26
0
文件: regress.c 项目: GanShun/akaros
static struct chan*
regressattach(char *spec)
{
	uint32_t n;

	regress.monitor = qopen(2 << 20, 0, 0, 0);
	if (! regress.monitor) {
		printk("monitor allocate failed. No monitor output\n");
	}
	return devattach(devname(), spec);
}
示例#27
0
	}
	kbdputc(kbdq, c);
}

void
kbdenable(void)
{
#ifdef notdef
	kbdq = qopen(4*1024, 0, 0, 0);
	if(kbdq == nil)
		panic("kbdinit");
示例#28
0
void* lqopen(){
    pthread_mutex_t q_lock = PTHREAD_MUTEX_INITIALIZER;
    lqtype *lqueue = (lqtype *)malloc(sizeof(lqtype));
    if(NULL == lqueue){
	printf("unable to alloc memory for queue\n");
	return NULL;
    }
    lqueue->q_lock = q_lock;
    lqueue->queue = qopen();
    return lqueue;
}
示例#29
0
void
pl011init(void)
{
	if(kbdq == nil)
		kbdq = qopen(4*1024, 0, 0, 0);

	/*
	 * at 115200 baud, the 1024 char buffer takes 56 ms to process,
	 * processing it every 22 ms should be fine
	 */
	addclock0link(pl011_clock, 22);
}
示例#30
0
static int32_t
consoleread(Chan* c, void *vbuf, int32_t len, int64_t off64)
{
	int amt;
	if (!keybq) {
		keybq = qopen(32, 0, 0, 0);
		if (!keybq)
			panic("keyboard queue alloc failed");
	}
	amt = qread(keybq, vbuf, len);
	return amt;
}