Esempio n. 1
0
/*---------------------------------------------------------------------------*/
void
slip_init(void)
{
  setvbuf(stdout, NULL, _IOLBF, 0);     /* Line buffered output. */

  if(slip_config_host != NULL) {
    if(slip_config_port == NULL) {
      slip_config_port = "60001";
    }
    slipfd = connect_to_server(slip_config_host, slip_config_port);
    if(slipfd == -1) {
      err(1, "can't connect to ``%s:%s''", slip_config_host,
          slip_config_port);
    }

  } else if(slip_config_siodev != NULL) {
    if(strcmp(slip_config_siodev, "null") == 0) {
      /* Disable slip */
      return;
    }
    slipfd = devopen(slip_config_siodev, O_RDWR | O_NONBLOCK);
    if(slipfd == -1) {
      err(1, "can't open siodev ``/dev/%s''", slip_config_siodev);
    }

  } else {
    static const char *siodevs[] = {
      "ttyUSB0", "cuaU0", "ucom0"       /* linux, fbsd6, fbsd5 */
    };
    int i;

    for(i = 0; i < 3; i++) {
      slip_config_siodev = siodevs[i];
      slipfd = devopen(slip_config_siodev, O_RDWR | O_NONBLOCK);
      if(slipfd != -1) {
        break;
      }
    }
    if(slipfd == -1) {
      err(1, "can't open siodev");
    }
  }

  select_set_callback(slipfd, &slip_callback);

  if(slip_config_host != NULL) {
    printf("********SLIP opened to ``%s:%s''\n", slip_config_host,
           slip_config_port);
  } else {
    printf("********SLIP started on ``/dev/%s''\n", slip_config_siodev);
    stty_telos(slipfd);
  }

  timer_set(&send_delay_timer, 0);
  slip_send(slipfd, SLIP_END);
  inslip = fdopen(slipfd, "r");
  if(inslip == NULL) {
    err(1, "main: fdopen");
  }
}
Esempio n. 2
0
/*---------------------------------------------------------------------------*/
void
slip_init(void)
{
  setvbuf(stdout, NULL, _IOLBF, 0); /* Line buffered output. */

  if(slip_config_siodev != NULL) {
    slipfd = devopen(slip_config_siodev, O_RDWR | O_NONBLOCK);
    if(slipfd == -1) {
      err(1, "can't open siodev ``/dev/%s''", slip_config_siodev);
    }
  } else {
    static const char *siodevs[] = {
      "ttyUSB0", "cuaU0", "ucom0" /* linux, fbsd6, fbsd5 */
    };
    int i;
    for(i = 0; i < 3; i++) {
      slip_config_siodev = siodevs[i];
      slipfd = devopen(slip_config_siodev, O_RDWR | O_NONBLOCK);
      if(slipfd != -1) {
	break;
      }
    }
    if(slipfd == -1) {
      err(1, "can't open siodev");
    }
  }

  fprintf(stderr, "********SLIP started on ``/dev/%s''\n", slip_config_siodev);
  stty_telos(slipfd);

  slip_send(slipfd, SLIP_END);
  inslip = fdopen(slipfd, "r");
  if(inslip == NULL) err(1, "main: fdopen");
}
Esempio n. 3
0
static Chan*
poweropen(Chan* c, int omode)
{
	Puser *p;

	if(c->qid.type & QTDIR)
		return devopen(c, omode, powertab, nelem(powertab), devgen);
	switch(c->qid.path){
	case Qdata:
		p = mallocz(sizeof(Puser), 1);
		if(p == nil)
			error(Enovmem);
		p->state = Pwridle;
		p->ref = 1;
		if(waserror()){
			free(p);
			nexterror();
		}
		c = devopen(c, omode, powertab, nelem(powertab), devgen);
		c->aux = p;
		qlock(&pwrusers);
		p->next = pwrusers.list;
		pwrusers.list = p;	/* note: must place on front of list for correct shutdown ordering */
		qunlock(&pwrusers);
		poperror();
		break;
	case Qctl:
		c = devopen(c, omode, powertab, nelem(powertab), devgen);
		break;
	}
	return c;
}
Esempio n. 4
0
static Chan*
devlogfsopen(Chan *c, int omode)
{
	int instance, qid, qt;

	omode = openmode(omode);
	SPLITPATH(c->qid.path, c->qid.type, instance, qid, qt);
#ifdef CALLTRACE
	print("devlogfsopen(c = 0x%.8lux, omode = %o, instance = %d, qid = %d, qt = %d)\n",
		(ulong)c, omode, instance, qid, qt);
#endif


	rlock(&devlogfslist.rwlock);
	if (waserror()) {
		runlock(&devlogfslist.rwlock);
#ifdef CALLTRACE
		print("devlogfsopen(c = 0x%.8lux, omode = %o) - error %s\n", (ulong)c, omode, up->env->errstr);
#endif
		nexterror();
	}

	if (DATAQID(qid, qt)) {
		Devlogfs *d;
		d = devlogfsfind(instance);
		if (d == nil)
			error(Enodev);
		if (strcmp(up->env->user, eve) != 0)
			error(Eperm);
		if (qid == Qfs && d->state != BootOpen)
			error(Eperm);
		if (d->server == nil) {
			errorany(logfsservernew(d->lb, d->ll, is, d->openflags, d->logfstrace, &d->server));
			d->state = NeedVersion;
		}
		c = devopen(c, omode, 0, 0, devlogfsgennolock);
		incref(&d->ref);
		c->aux = d;
	}
	else if (qid == Qctl || qid == Qusers) {
		if (strcmp(up->env->user, eve) != 0)
			error(Eperm);
		c = devopen(c, omode, 0, 0, devlogfsgennolock);
	}
	else
		c = devopen(c, omode, 0, 0, devlogfsgennolock);
	poperror();
	runlock(&devlogfslist.rwlock);
#ifdef CALLTRACE
	print("devlogfsopen(c = 0x%.8lux, omode = %o) - return\n", (ulong)c, omode);
#endif
	return c;
}
Esempio n. 5
0
int cmd_ctty(char *param)
{ int fin, fout;
  int failed;

  if(!param || !*param) {
    displayString(TEXT_CMDHELP_CTTY);
    return 1;
  }

#ifdef DEBUG
  devAttr(0);
  devAttr(1);
  devAttr(2);
#endif

  if((fin = devopen(param, O_BINARY | O_RDONLY)) < 0
   || (fout = devopen(param, O_BINARY | O_WRONLY)) < 0) {
    close(fin);     /* if fin failed, close(-1) won't hurt */
    error_no_rw_device(param);
    return 1;
  }

  fflush(stdin);      /* prepare asynchroneous changes of internal fd's */
  fflush(stdout);
  fflush(stderr);

  /* Now change the file descriptors:
    0 := rdonly
    1,2 := wronly

    if CTTY is called within a pipe or its I/O is redirected,
    oldinfd or oldoutfd is not equal to -1. In such case the
    old*fd is modified in order to effect the file descriptor
    after the redirections are restored. Otherwise a pipe or
    redirection would left CTTY in a half-made status.
  */
  failed = dup2(fout, 2);   /* no redirection support */
  if(oldinfd == -1) {     /* stdin not redirected */
    failed = dup2(fin, 0) || failed;
    close(fin);
  } else  oldinfd = fin;
  if(oldoutfd == -1) {      /* stdout not redirected */
    failed = dup2(fout, 1) || failed;
    close(fout);
  } else  oldoutfd = fout;

  if(failed)
    error_ctty_dup(param);

  return failed;
}
Esempio n. 6
0
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;
}
Esempio n. 7
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;
}
Esempio n. 8
0
int 
main(void)
{
	struct open_file	f;
	void	*entry;
	char	*addr;
	int error;

#ifdef DEBUG
	printf("bootxx: open...\n");
#endif
	f.f_flags = F_RAW;
	if (devopen(&f, 0, &addr)) {
		putstr("bootxx: devopen failed\n");
		return 1;
	}

	addr = (char*)LOADADDR;
	error = copyboot(&f, addr);
	f.f_dev->dv_close(&f);
	if (!error) {
#ifdef DEBUG
		printf("bootxx: start 0x%x\n", (long)addr);
#endif
		entry = addr;
		chain_to(entry);
	}
	/* copyboot had a problem... */
	return 0;
}
Esempio n. 9
0
static Chan*
uartopen(Chan *c, int omode)
{
	Uart *p;

	c = devopen(c, omode, uartdir, uartndir, devgen);

	switch(UARTTYPE(c->qid.path)){
	case Qctl:
	case Qdata:
		p = uart[UARTID(c->qid.path)];
		qlock(&p->ql);
		if(p->opens == 0 && uartenable(p) == nil){
			qunlock(&p->ql);
			c->flag &= ~COPEN;
			error(Enodev);
		}
		p->opens++;
		qunlock(&p->ql);
		break;
	}

	c->iounit = qiomaxatomic;
	return c;
}
Esempio n. 10
0
main()
{
	struct open_file	f;
	char	*addr;
	int n, error;

	bootdev_type = BUGDEV_DISK;

	printf("Boot: bug device: ctrl=%d, dev=%d\n", 
		bugargs.ctrl_lun, bugargs.dev_lun);
	printf("\nbootxx: first level bootstrap program [%s]\n\n", version);

	f.f_flags = F_RAW;
	if (devopen(&f, 0, &addr)) {
		printf("bootxx: open failed\n");
		_rtt();
	}

	addr = (char *)STAGE2_RELOC;
	error = copyboot(&f, addr);
	f.f_dev->dv_close(&f);
	if (!error) {
		bugexec((void (*)())addr);
	}
	/* copyboot had a problem... */
	_rtt();
}
Esempio n. 11
0
static Chan*
pmcopen(Chan *c, int omode)
{
	if (!iseve())
		error(Eperm);
	return devopen(c, omode, nil, 0, pmcgen);
}
Esempio n. 12
0
static struct chan *rootopen(struct chan *c, int omode)
{
	int p;
	printd("rootopen: omode %o\n", omode);
	p = c->qid.path;
	return devopen(c, omode, rootdata[p].ptr, rootdata[p].size, rootgen);
}
Esempio n. 13
0
Chan*
gpioopen(Chan *c, int omode)
{
	int type;
	
	c = devopen(c, omode, 0, 0, gpiogen);
	
	type = FILE_TYPE(c->qid);
	
	switch(type)
	{
	case Qdata:
		c->iounit = 1;
		break;
	case Qctl:
		break;
	case Qevent:
		lock(&eventlock);
		if(eventinuse != 0){
			c->flag &= ~COPEN;
			unlock(&eventlock);
			error(Einuse);
		}
		eventinuse = 1;
		unlock(&eventlock);
		eventvalue = 0;
		c->iounit = 4;
	}

	return c;
}
Esempio n. 14
0
static Chan*
acpiopen(Chan *c, int omode)
{
	if( !iseve() ) {
		error( Eperm );
	}
	return devopen( c, omode, acpidir, nelem(acpidir), devgen);
}
Esempio n. 15
0
static Chan*
dsoopen(Chan *c, int omode)
{
	if(!iseve())
		error(Eperm);

	return devopen(c, omode, dsotab, nfichtab+2, devgen);
}
Esempio n. 16
0
File: devroot.c Progetto: 8l/inferno
static Chan*
rootopen(Chan *c, int omode)
{
	int p;

	p = rootdata[c->qid.path].dotdot;
	return devopen(c, omode, rootdata[p].ptr, rootdata[p].size, rootgen);
}
Esempio n. 17
0
int cmd_ctty(char *param)
{ int f, attr, failed;

  if(!param || !*param) {
    displayString(TEXT_CMDHELP_CTTY);
    return 1;
  }

#ifdef DEBUG
  devAttr(0);
  devAttr(1);
  devAttr(2);
#endif

  if((f = devopen(param, O_RDWR)) < 0) {
    error_no_rw_device(param);
    return 1;
  }

  if(((attr = fdattr(f)) & 0x80) == 0
   || write(f, "\r\n", 2) != 2) {		/* need \r as in bin mode */
    close(f);
    error_no_rw_device(param);
    return 1;
  }

	/* Now inform the system that this device is the new console
		now; STDIN and STDOUT flag are the most lowest two bits  */
	fdsetattr(f, (attr & 0xFF) | 0x03);

  fflush(stdin);      /* prepare asynchroneous changes of internal fd's */
  fflush(stdout);
  fflush(stderr);

  /* Now change the file descriptors:
    0 := rdonly
    1,2 := wronly

    if CTTY is called within a pipe or its I/O is redirected,
    oldinfd or oldoutfd is not equal to -1. In such case the
    old*fd is modified in order to effect the file descriptor
    after the redirections are restored. Otherwise a pipe or
    redirection would left CTTY in a half-made status.
  */
  failed = dup2(f, 2);   /* no redirection support */
  if(oldinfd != -1)
  	close(oldinfd);
  oldinfd = f;
  if(oldoutfd != -1)
  	close(oldoutfd);
  if((oldoutfd = dup(f)) == -1)
  	failed = 1;

  if(failed)
    error_ctty_dup(param);

  return failed;
}
Esempio n. 18
0
File: type.c Progetto: FDOS/freecom
int cmd_type(char *param)
{
    char buf[256];
    char **argv;
    int argc, opts, ec = E_None;
    int fd, len;

    if((argv = scanCmdline(param, 0, 0, &argc, &opts)) == 0)
        return 1;

    /* Because no option was passed into scanCmdline() no
    	option can have been processed */
    assert(opts == 0);

    if(!argc) {
        error_req_param_missing();
        ec = E_Useage;
        goto errRet;
    }

    for(argc = 0; argv[argc]; ++argc) {
        if((fd = devopen(argv[argc], O_RDONLY)) == 0) {
            error_sfile_not_found(argv[argc]);
            ec = E_Other;
            break;
        }

        while((len = dos_read(fd, buf, sizeof(buf))) >= 0) {
            char *bufp, *p;
            if(cbreak) {
                dos_close(fd);
                ec = E_CBreak;
                goto errRet;
            }
            bufp = buf;
            for(p = buf; p < buf+len; p++) {
                if(*p == 26) break; /* CTRL-Z */
                if(*p == '\r' || *p == '\n') {
                    if(p > bufp) dos_write(1, bufp, p - bufp);
                    if(*p == '\n') dos_write(1, "\r\n", 2);
                    bufp = p + 1;
                }
            }
            dos_write(1, bufp, p - bufp);
            if (len < sizeof(buf) || *p == 26) break;
        }
        dos_close(fd);
        if(cbreak) {
            ec = E_CBreak;
            break;
        }
    }

errRet:
    freep(argv);

    return ec;
}
Esempio n. 19
0
void
outportw(int32_t port, uint16_t data)
{
	if(iowfd == -1)
		iowfd = devopen("#P/iow", ORDWR);

	if(pwrite(iowfd, &data, sizeof(data), port) != sizeof(data))
		error("outportw(0x%4.4lx, 0x%2.2X): %r\n", port, data);
}
Esempio n. 20
0
int
open(const char *fname, int mode)
{
    struct open_file	*f;
    int			fd, i, error, besterror;
    const char		*file;

    if ((fd = o_gethandle()) == -1) {
	errno = EMFILE;
	return(-1);
    }

    f = &files[fd];
    f->f_flags = mode + 1;
    f->f_dev = (struct devsw *)0;
    f->f_ops = (struct fs_ops *)0;
    f->f_offset = 0;
    f->f_devdata = NULL;
    file = (char *)0;
    error = devopen(f, fname, &file);
    if (error ||
	(((f->f_flags & F_NODEV) == 0) && f->f_dev == (struct devsw *)0))
	goto err;

    /* see if we opened a raw device; otherwise, 'file' is the file name. */
    if (file == (char *)0 || *file == '\0') {
	f->f_flags |= F_RAW;
	f->f_rabuf = NULL;
	return (fd);
    }

    /* pass file name to the different filesystem open routines */
    besterror = ENOENT;
    for (i = 0; file_system[i] != NULL; i++) {

	error = ((*file_system[i]).fo_open)(file, f);
	if (error == 0) {
	    
	    f->f_ops = file_system[i];
	    o_rainit(f);
	    return (fd);
	}
	if (error != EINVAL)
	    besterror = error;
    }
    error = besterror;

    if ((f->f_flags & F_NODEV) == 0)
	f->f_dev->dv_close(f);
    if (error)
	devclose(f);

 err:
    f->f_flags = 0;
    errno = error;
    return (-1);
}
Esempio n. 21
0
void
wrmsr(long port, uvlong data)
{
	if(msrfd == -1)
		msrfd = devopen("#P/msr", ORDWR);

	if(pwrite(msrfd, &data, sizeof(data), port) != sizeof(data))
		error("wrmsr(0x%4.4lx, 0x%2.2lluX): %r\n", port, data);
}
Esempio n. 22
0
void
outportb(long port, uchar data)
{
	if(iobfd == -1)
		iobfd = devopen("#P/iob", ORDWR);

	if(pwrite(iobfd, &data, sizeof(data), port) != sizeof(data))
		error("outportb(0x%4.4lx, 0x%2.2uX): %r\n", port, data);
}
Esempio n. 23
0
File: devcons.c Progetto: 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);
}
Esempio n. 24
0
void
outportl(long port, ulong data)
{
	if(iolfd == -1)
		iolfd = devopen("#P/iol", ORDWR);

	if(pwrite(iolfd, &data, sizeof(data), port) != sizeof(data))
		error("outportl(0x%4.4lx, 0x%2.2luX): %r\n", port, data);
}
Esempio n. 25
0
static Chan*
wdopen(Chan* c, int omode)
{
	wdautostop();
	c = devopen(c, omode, wddir, nelem(wddir), devgen);
	if (c->qid.path == Qwdctl)
		incref(&refs);
	return c;
}
Esempio n. 26
0
void displaywrite(const char *s, const char *dev){
	void *handle=devopen(dev);
	if(!handle){
		dbgpf("BOOT: Specified display device: %s\n", dev);
		panic("(BOOT) Display device not valid!");
	}
    dputs(handle, (char*)s);
    devclose(handle);
}
Esempio n. 27
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;
}
Esempio n. 28
0
uint32_t
inportl(int32_t port)
{
	uint32_t data;

	if(iolfd == -1)
		iolfd = devopen("#P/iol", ORDWR);

	if(pread(iolfd, &data, sizeof(data), port) != sizeof(data))
		error("inportl(0x%4.4lx): %r\n", port);
	return data;
}
Esempio n. 29
0
ushort
inportw(long port)
{
	ushort data;

	if(iowfd == -1)
		iowfd = devopen("#P/iow", ORDWR);

	if(pread(iowfd, &data, sizeof(data), port) != sizeof(data))
		error("inportw(0x%4.4lx): %r\n", port);
	return data;
}
Esempio n. 30
0
static Chan*
rtcopen(Chan* c, int omode)
{
	omode = openmode(omode);
	switch((ulong)c->qid.path){
	case Qrtc:
		if(strcmp(up->user, eve)!=0 && omode!=OREAD)
			error(Eperm);
		break;
	}
	return devopen(c, omode, rtcdir, nelem(rtcdir), devgen);
}