zero.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <venti.h>
  12. void
  13. vtzeroextend(int type, uint8_t *buf, uint n, uint nn)
  14. {
  15. uint8_t *p, *ep;
  16. switch(type&7) {
  17. case 0:
  18. memset(buf+n, 0, nn-n);
  19. break;
  20. default:
  21. p = buf + (n/VtScoreSize)*VtScoreSize;
  22. ep = buf + (nn/VtScoreSize)*VtScoreSize;
  23. while(p < ep) {
  24. memmove(p, vtzeroscore, VtScoreSize);
  25. p += VtScoreSize;
  26. }
  27. memset(p, 0, buf+nn-p);
  28. break;
  29. }
  30. }
  31. uint
  32. vtzerotruncate(int type, uint8_t *buf, uint n)
  33. {
  34. uint8_t *p;
  35. if(type == VtRootType){
  36. if(n < VtRootSize)
  37. return n;
  38. return VtRootSize;
  39. }
  40. switch(type&7){
  41. case 0:
  42. for(p = buf + n; p > buf; p--) {
  43. if(p[-1] != 0)
  44. break;
  45. }
  46. return p - buf;
  47. default:
  48. /* ignore slop at end of block */
  49. p = buf + (n/VtScoreSize)*VtScoreSize;
  50. while(p > buf) {
  51. if(memcmp(p - VtScoreSize, vtzeroscore, VtScoreSize) != 0)
  52. break;
  53. p -= VtScoreSize;
  54. }
  55. return p - buf;
  56. }
  57. }