diff options
author | rsc <devnull@localhost> | 2007-05-03 03:14:30 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2007-05-03 03:14:30 +0000 |
commit | 91872ab97b7c9cabacef61f37b90a1af29f257af (patch) | |
tree | 3f7c292a4a4929f8f35b699fbacffb6513e0cc5d /src/cmd | |
parent | c482feff4bc6002f0c1373a8d41e04f86dda5a21 (diff) | |
download | plan9port-91872ab97b7c9cabacef61f37b90a1af29f257af.tar.gz plan9port-91872ab97b7c9cabacef61f37b90a1af29f257af.tar.bz2 plan9port-91872ab97b7c9cabacef61f37b90a1af29f257af.zip |
allow plan9-style branded disks as configs
Diffstat (limited to 'src/cmd')
-rw-r--r-- | src/cmd/venti/srv/ifile.c | 51 | ||||
-rw-r--r-- | src/cmd/venti/srv/readifile.c | 29 |
2 files changed, 77 insertions, 3 deletions
diff --git a/src/cmd/venti/srv/ifile.c b/src/cmd/venti/srv/ifile.c index fc784c9b..e5d5460a 100644 --- a/src/cmd/venti/srv/ifile.c +++ b/src/cmd/venti/srv/ifile.c @@ -5,11 +5,56 @@ int readifile(IFile *f, char *name) { + int m; + Part *p; ZBlock *b; - - b = readfile(name); - if(b == nil) + u8int *z; + + p = initpart(name, OREAD); + if(p == nil) + return -1; + b = alloczblock(8192, 1, 0); + if(b == nil){ + seterr(EOk, "can't alloc for %s: %R", name); + return -1; + } + if(p->size > PartBlank){ + /* + * this is likely a real venti partition, in which case + * we're looking for the config file stored as 8k at end of PartBlank. + */ + if(readpart(p, PartBlank-8192, b->data, 8192) < 0){ + seterr(EOk, "can't read %s: %r", name); + freezblock(b); + freepart(p); + return -1; + } + m = 5+1+6+1; + if(memcmp(b->data, "venti config\n", m) != 0){ + seterr(EOk, "bad venti config magic in %s", name); + freezblock(b); + freepart(p); + return -1; + } + b->data += m; + b->len -= m; + z = memchr(b->data, 0, b->len); + if(z) + b->len = z - b->data; + }else if(p->size > 8192){ + seterr(EOk, "config file is too large"); + freepart(p); + freezblock(b); return -1; + }else{ + freezblock(b); + b = readfile(name); + if(b == nil){ + freepart(p); + return -1; + } + } + freepart(p); f->name = name; f->b = b; f->pos = 0; diff --git a/src/cmd/venti/srv/readifile.c b/src/cmd/venti/srv/readifile.c new file mode 100644 index 00000000..a822a987 --- /dev/null +++ b/src/cmd/venti/srv/readifile.c @@ -0,0 +1,29 @@ +#include "stdinc.h" +#include "dat.h" +#include "fns.h" + +void +usage(void) +{ + fprint(2, "usage: readifile file\n"); + threadexitsall("usage"); +} + +void +threadmain(int argc, char *argv[]) +{ + IFile ifile; + + ARGBEGIN{ + default: + usage(); + }ARGEND + + if(argc != 1) + usage(); + + if(readifile(&ifile, argv[0]) < 0) + sysfatal("readifile %s: %r", argv[0]); + write(1, ifile.b->data, ifile.b->len); + threadexitsall(nil); +} |