ref: 84d66beb90246495861436c041297528298ba74f
dir: /config.c/
#include "all.h" /* assuming that the config will not be more than a block */ void initconfig(u64 dblkno) { Iobuf *buf; char *tokens[128], cfg[Ddatasize], *nl; s32 n, i; 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); n = tokenize(cfg, tokens, 128); if(n > 128) panic("cannot read config, increase tokens size\n"); if(n == 0){ panic("nil config"); } for(i = 0; i<n; i++){ if(strcmp(tokens[i], "nblocks") == 0){ if((config.nblocks = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid nblocks\n", service); }else if(strcmp(tokens[i], "size") == 0){ if((config.size = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); }else if(strcmp(tokens[i], "backup") == 0 && strcmp(tokens[i+1], "config") == 0){ i++; if((config.config.srcbno = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); i++; /* skip over to */ if((config.config.dest[0] = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); if((config.config.dest[1] = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); }else if(strcmp(tokens[i], "backup") == 0 && strcmp(tokens[i+1], "super") == 0){ i++; if((config.super.srcbno = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); i++; /* skip over to */ if((config.super.dest[0] = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); if((config.super.dest[1] = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); }else if(strcmp(tokens[i], "backup") == 0 && strcmp(tokens[i+1], "root") == 0){ i++; if((config.root.srcbno = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); i++; /* skip over to */ if((config.root.dest[0] = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); if((config.root.dest[1] = atoll(tokens[++i])) == 0) panic("mafs: %s initconfig(): invalid size\n", service); }else if(strcmp(tokens[i], "service") == 0){ snprint(config.service, Namelen,"%s", tokens[++i]); if((nl=strchr(config.service, '\n')) != nil) *nl = '\0'; } } if(chatty9p > 1) dprint("config:\n" "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); } 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); }