Plan 9 from Bell Labs’s /usr/web/sources/contrib/quanstro/root/sys/src/9/port/led.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "../port/error.h"
#include "fns.h"
#include "led.h"

static char *ibpinames[Ibpilast] = {
[Ibpinone]	"none",
[Ibpinormal]	"normal",
[Ibpilocate]	"locate",
[Ibpifail]		"fail",
[Ibpirebuild]	"rebuild",
[Ibpipfa]		"pfa",
[Ibpispare]	"spare",
[Ibpicritarray]	"critarray",
[Ibpifailarray]	"failarray",
};

char*
ledname(int c)
{
	if(c >= 0 && c < Ibpilast)
		return ibpinames[c];
	return "bad index";
}

 int
name2led(char *s)
{
	int i;

	for(i = 0; i < nelem(ibpinames); i++)
		if(strcmp(ibpinames[i], s) == 0)
			return i;
	return -1;
}

long
ledr(Ledport *p, Chan*, void *a, long n, vlong off)
{
	char buf[64];

	snprint(buf, sizeof buf, "%s\n", ledname(p->led));
	return readstr(off, a, n, buf);
}

long
ledw(Ledport *p, Chan*, void *a, long n, vlong)
{
	int i;
	Cmdbuf *cb;

	cb = parsecmd(a, n);
	i = name2led(cb->f[0]);
	free(cb);
	if(i == -1)
		error(Ebadarg);
	p->led = i;
	return n;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.