zero.c 899 B

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