summaryrefslogtreecommitdiff
path: root/sys/src/libventi/zero.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/zero.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libventi/zero.c')
-rwxr-xr-xsys/src/libventi/zero.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/sys/src/libventi/zero.c b/sys/src/libventi/zero.c
new file mode 100755
index 000000000..c40aea969
--- /dev/null
+++ b/sys/src/libventi/zero.c
@@ -0,0 +1,55 @@
+#include <u.h>
+#include <libc.h>
+#include <venti.h>
+
+void
+vtzeroextend(int type, uchar *buf, uint n, uint nn)
+{
+ uchar *p, *ep;
+
+ switch(type&7) {
+ case 0:
+ memset(buf+n, 0, nn-n);
+ break;
+ default:
+ p = buf + (n/VtScoreSize)*VtScoreSize;
+ ep = buf + (nn/VtScoreSize)*VtScoreSize;
+ while(p < ep) {
+ memmove(p, vtzeroscore, VtScoreSize);
+ p += VtScoreSize;
+ }
+ memset(p, 0, buf+nn-p);
+ break;
+ }
+}
+
+uint
+vtzerotruncate(int type, uchar *buf, uint n)
+{
+ uchar *p;
+
+ if(type == VtRootType){
+ if(n < VtRootSize)
+ return n;
+ return VtRootSize;
+ }
+
+ switch(type&7){
+ case 0:
+ for(p = buf + n; p > buf; p--) {
+ if(p[-1] != 0)
+ break;
+ }
+ return p - buf;
+ default:
+ /* ignore slop at end of block */
+ p = buf + (n/VtScoreSize)*VtScoreSize;
+
+ while(p > buf) {
+ if(memcmp(p - VtScoreSize, vtzeroscore, VtScoreSize) != 0)
+ break;
+ p -= VtScoreSize;
+ }
+ return p - buf;
+ }
+}