]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libventi/zero.c
merge
[plan9front.git] / sys / src / libventi / zero.c
1 #include <u.h>
2 #include <libc.h>
3 #include <venti.h>
4
5 void
6 vtzeroextend(int type, uchar *buf, uint n, uint nn)
7 {
8         uchar *p, *ep;
9
10         switch(type&7) {
11         case 0:
12                 memset(buf+n, 0, nn-n);
13                 break;
14         default:
15                 p = buf + (n/VtScoreSize)*VtScoreSize;
16                 ep = buf + (nn/VtScoreSize)*VtScoreSize;
17                 while(p < ep) {
18                         memmove(p, vtzeroscore, VtScoreSize);
19                         p += VtScoreSize;
20                 }
21                 memset(p, 0, buf+nn-p);
22                 break;
23         }
24 }
25
26 uint 
27 vtzerotruncate(int type, uchar *buf, uint n)
28 {
29         uchar *p;
30
31         if(type == VtRootType){
32                 if(n < VtRootSize)
33                         return n;
34                 return VtRootSize;
35         }
36
37         switch(type&7){
38         case 0:
39                 for(p = buf + n; p > buf; p--) {
40                         if(p[-1] != 0)
41                                 break;
42                 }
43                 return p - buf;
44         default:
45                 /* ignore slop at end of block */
46                 p = buf + (n/VtScoreSize)*VtScoreSize;
47
48                 while(p > buf) {
49                         if(memcmp(p - VtScoreSize, vtzeroscore, VtScoreSize) != 0)
50                                 break;
51                         p -= VtScoreSize;
52                 }
53                 return p - buf;
54         }
55 }