code: mafs

ref: 80e6c118c65b013bde24f8b9c95881c0e3a73d3e
dir: /config.c/

View raw version
#include "all.h"

/* assuming that the config will not be more than a block */
void
initconfig(u64 dblkno)
{
	Iobuf *buf;
	char cfg[Ddatasize];

	buf = getmetachk(dblkno, Breadonly, Tdentry, Qpconfig);
	if(buf == nil)
		panic("cannot find config file in %llud block\n", dblkno);
	memcpy(cfg, buf->cur->buf, buf->cur->size);
	putbuf(buf, 0);

	parseconfig(cfg, &config);
}

void
writeconfig(u64 bno)
{
	Iobuf *buf;
	s32 n;

	buf = getmetachk(bno, Bwritable, Tdentry, Qpconfig);
	if(buf == nil)
		panic("cannot write config");
	n = snprint((s8*)buf->new->buf, Ddatasize,
			"size %llud\n"
			"nblocks %llud\n"
			"backup config %llud to %llud\n"
			"backup super %llud to %llud\n"
			"backup root %llud to %llud\n"
			"service %s\n",
			config.size,
			config.nblocks,
			config.config.srcbno,
			config.config.dest[0],
			config.super.srcbno,
			config.super.dest[0],
			config.root.srcbno,
			config.root.dest[0],
			config.service);
	if(n == Ddatasize)
		panic("config needs more blocks");
	buf->new->size = n;
	if(chatty9p > 1)
		dprint("config:\n%s", buf->new->buf);
	putbuf(buf, 1);
}