Plan 9 from Bell Labs’s /usr/web/sources/contrib/quanstro/root/sys/src/cmd/disk/mknvrsafe.c

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


#include <u.h>
#include <libc.h>
#include <authsrv.h>

Nvrsafe nvr;

void
usage(void)
{
	fprint(2, "usage: mknvrsafe [-r file] [-c config]\n");
	exits("usage");
}

void
main(int argc, char **argv)
{
	char *config, *file;
	int fd;
	uint c;

	config = nil;
	file = nil;
	fd = 1;
	ARGBEGIN{
	case 'r':
		file = EARGF(usage());
		break;
	case 'c':
		config = EARGF(usage());
		break;
	default:
		usage();
	}ARGEND
	if(argc || file != nil && config == nil)
		usage();
	if(file != nil){
		fd = open(file, ORDWR);
		if(fd == -1 || pread(fd, &nvr, sizeof nvr, 0) != sizeof nvr)
			sysfatal("mknvrsafe: read: %r");
	}
	c = 0;
	if(config != nil)
		c = strlen(config);
	if(c >= sizeof nvr.config)
		sysfatal("mknvrsafe: config string too long: %d > %d", c, sizeof nvr.config);
	memcpy(nvr.config, config, c);
	nvr.configsum = nvcsum(nvr.config, sizeof nvr.config);

	pwrite(fd, &nvr, sizeof nvr, 0);
	exits("");
}

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.