code: mafs

ref: bcdbd28d00321d615839e60d46d61bc7352d2fb4
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->d->buf, buf->d->size);
	putbuf(buf, 0);

	parseconfig(cfg, &config);
}

u16
configstr(s8 *buf, u16 nbuf)
{
	u16 n;

	n = (u16)snprint(buf, nbuf,
			"disksize %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 == nbuf)
		panic("config needs more blocks");
	return n;
}

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

	buf = getmetachk(bno, Bwritable, Tdentry, Qpconfig);
	if(buf == nil)
		panic("cannot write config");
	n = configstr(buf->d->buf, Ddatasize);
	buf->d->size = n;
	putbuf(buf, 1);
}