diff options
author | rsc <devnull@localhost> | 2003-11-23 18:19:58 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2003-11-23 18:19:58 +0000 |
commit | 056fe1ba7fa0b70f871dfb9005b24eb8e4cc230b (patch) | |
tree | 9ad42f31c3bc124cf6617cf9eb41dd525eccce83 /src/libventi/root.c | |
parent | 9df487d720a59bf8cb0dc4ccffc30ad8eb48256a (diff) | |
download | plan9port-056fe1ba7fa0b70f871dfb9005b24eb8e4cc230b.tar.gz plan9port-056fe1ba7fa0b70f871dfb9005b24eb8e4cc230b.tar.bz2 plan9port-056fe1ba7fa0b70f871dfb9005b24eb8e4cc230b.zip |
new venti library.
Diffstat (limited to 'src/libventi/root.c')
-rw-r--r-- | src/libventi/root.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/libventi/root.c b/src/libventi/root.c new file mode 100644 index 00000000..c9449af8 --- /dev/null +++ b/src/libventi/root.c @@ -0,0 +1,67 @@ +#include <u.h> +#include <libc.h> +#include <venti.h> +#include "cvt.h" + +static int +checksize(int n) +{ + if(n < 256 || n > VtMaxLumpSize) { + werrstr("bad block size"); + return -1; + } + return 0; +} + +void +vtrootpack(VtRoot *r, uchar *p) +{ + uchar *op = p; + + U16PUT(p, VtRootVersion); + p += 2; + memmove(p, r->name, sizeof(r->name)); + p += sizeof(r->name); + memmove(p, r->type, sizeof(r->type)); + p += sizeof(r->type); + memmove(p, r->score, VtScoreSize); + p += VtScoreSize; + U16PUT(p, r->blocksize); + p += 2; + memmove(p, r->prev, VtScoreSize); + p += VtScoreSize; + + assert(p-op == VtRootSize); +} + +int +vtrootunpack(VtRoot *r, uchar *p) +{ + uchar *op = p; + uint vers; + memset(r, 0, sizeof(*r)); + + vers = U16GET(p); + if(vers != VtRootVersion) { + werrstr("unknown root version"); + return 0; + } + p += 2; + memmove(r->name, p, sizeof(r->name)); + r->name[sizeof(r->name)-1] = 0; + p += sizeof(r->name); + memmove(r->type, p, sizeof(r->type)); + r->type[sizeof(r->type)-1] = 0; + p += sizeof(r->type); + memmove(r->score, p, VtScoreSize); + p += VtScoreSize; + r->blocksize = U16GET(p); + if(checksize(r->blocksize) < 0) + return -1; + p += 2; + memmove(r->prev, p, VtScoreSize); + p += VtScoreSize; + + assert(p-op == VtRootSize); + return 0; +} |