syncindex.c 983 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "stdinc.h"
  2. #include "dat.h"
  3. #include "fns.h"
  4. static int verbose;
  5. void
  6. usage(void)
  7. {
  8. fprint(2, "usage: syncindex [-fv] [-B blockcachesize] config\n");
  9. exits("usage");
  10. }
  11. int
  12. main(int argc, char *argv[])
  13. {
  14. u32int bcmem;
  15. int fix;
  16. fix = 0;
  17. bcmem = 0;
  18. ARGBEGIN{
  19. case 'B':
  20. bcmem = unittoull(ARGF());
  21. break;
  22. case 'f':
  23. fix++;
  24. break;
  25. case 'v':
  26. verbose++;
  27. break;
  28. default:
  29. usage();
  30. break;
  31. }ARGEND
  32. if(!fix)
  33. readonly = 1;
  34. if(argc != 1)
  35. usage();
  36. vtAttach();
  37. if(!initVenti(argv[0], nil))
  38. fatal("can't init venti: %R");
  39. if(bcmem < maxBlockSize * (mainIndex->narenas + mainIndex->nsects * 4 + 16))
  40. bcmem = maxBlockSize * (mainIndex->narenas + mainIndex->nsects * 4 + 16);
  41. fprint(2, "initialize %d bytes of disk block cache\n", bcmem);
  42. initDCache(bcmem);
  43. if(verbose)
  44. printIndex(2, mainIndex);
  45. if(!syncIndex(mainIndex, fix))
  46. fatal("failed to sync index=%s: %R\n", mainIndex->name);
  47. exits(0);
  48. return 0; /* shut up stupid compiler */
  49. }