epoch.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 "stdinc.h"
  10. #include "dat.h"
  11. #include "fns.h"
  12. uint8_t buf[65536];
  13. void
  14. usage(void)
  15. {
  16. fprint(2, "usage: fossil/epoch fs [new-low-epoch]\n");
  17. exits("usage");
  18. }
  19. void
  20. main(int argc, char **argv)
  21. {
  22. int fd;
  23. Header h;
  24. Super s;
  25. ARGBEGIN{
  26. default:
  27. usage();
  28. }ARGEND
  29. if(argc == 0 || argc > 2)
  30. usage();
  31. if((fd = open(argv[0], argc==2 ? ORDWR : OREAD)) < 0)
  32. sysfatal("open %s: %r", argv[0]);
  33. if(pread(fd, buf, HeaderSize, HeaderOffset) != HeaderSize)
  34. sysfatal("reading header: %r");
  35. if(!headerUnpack(&h, buf))
  36. sysfatal("unpacking header: %r");
  37. if(pread(fd, buf, h.blockSize, (int64_t)h.super*h.blockSize) != h.blockSize)
  38. sysfatal("reading super block: %r");
  39. if(!superUnpack(&s, buf))
  40. sysfatal("unpacking super block: %r");
  41. print("epoch %d\n", s.epochLow);
  42. if(argc == 2){
  43. s.epochLow = strtoul(argv[1], 0, 0);
  44. superPack(&s, buf);
  45. if(pwrite(fd, buf, h.blockSize, (int64_t)h.super*h.blockSize) != h.blockSize)
  46. sysfatal("writing super block: %r");
  47. }
  48. exits(0);
  49. }