ref: b3e875d7db45fca0cde9f4efa12872f61afc54d7
dir: /config.c/
#include "all.h" /* assuming that the config will not be more than a block */ void initconfig(u64 dblkno) { Iobuf *buf; char cfg[Ddatasize]; if(waserror()) panic("cannot find config file in %llud block\n", dblkno); buf = egetmetachk(dblkno, Breadonly, Tdentry, Qpconfig); memcpy(cfg, buf->d->buf, buf->d->size); poperror(); 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; if(waserror()) panic("cannot write config"); buf = egetmetachk(bno, Bwritable, Tdentry, Qpconfig); n = configstr(buf->d->buf, Ddatasize); buf->d->size = n; poperror(); putbuf(buf, 1); }