Пример #1
0
static long	 
rtcread(Chan *c, void *buf, long n, vlong offset)
{
	ulong t, ot;

	if(c->qid.type & QTDIR)
		return devdirread(c, buf, n, rtcdir, NRTC, devgen);

	switch((ulong)c->qid.path){
	case Qrtc:
		qlock(&rtclock);
		t = rtctime();
		do{
			ot = t;
			t = rtctime();	/* make sure there's no skew */
		}while(t != ot);
		qunlock(&rtclock);
		n = readnum(offset, buf, n, t, 12);
		return n;
	case Qnvram:
		if(offset > NVREAD)
			return 0;
		if(n > NVREAD - offset)
			n = NVREAD - offset;
		qlock(&rtclock);
		memmove(buf, nvr.ram+offset, n);
		qunlock(&rtclock);
		return n;
	}
	error(Egreg);
	return 0;		/* not reached */
}
Пример #2
0
static long	 
rtcread(Chan* c, void* buf, long n, vlong off)
{
	ulong t;
	ulong offset = off;

	if(c->qid.type & QTDIR)
		return devdirread(c, buf, n, rtcdir, nelem(rtcdir), devgen);

	switch((ulong)c->qid.path){
	case Qrtc:
		t = rtctime();
		n = readnum(offset, buf, n, t, 12);
		return n;
	}
	error(Ebadarg);
	return 0;
}
Пример #3
0
static long	 
rtcread(Chan* c, void* buf, long n, vlong off)
{
	ulong t;
	char *a, *start;
	ulong offset = off;

	if(c->qid.type & QTDIR)
		return devdirread(c, buf, n, rtcdir, nelem(rtcdir), devgen);

	switch((ulong)c->qid.path){
	case Qrtc:
		t = rtctime();
		n = readnum(offset, buf, n, t, 12);
		return n;
	case Qnvram:
		if(n == 0)
			return 0;
		if(n > Nvsize)
			n = Nvsize;
		a = start = smalloc(n);

		ilock(&nvrtlock);
		for(t = offset; t < offset + n; t++){
			if(t >= Nvsize)
				break;
			outb(Paddr, Nvoff+t);
			*a++ = inb(Pdata);
		}
		iunlock(&nvrtlock);

		if(waserror()){
			free(start);
			nexterror();
		}
		memmove(buf, start, t - offset);
		poperror();

		free(start);
		return t - offset;
	}
	error(Ebadarg);
	return 0;
}