summaryrefslogtreecommitdiff
path: root/sys/src/libventi/root.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libventi/root.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libventi/root.c')
-rwxr-xr-xsys/src/libventi/root.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/sys/src/libventi/root.c b/sys/src/libventi/root.c
new file mode 100755
index 000000000..5b4ccac6e
--- /dev/null
+++ b/sys/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 -1;
+ }
+ 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;
+}