code: mafs

ref: e5fae21d7c28103cbd4d5414538f18a448a60766
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);
}