flchk.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 <bio.h>
  11. #include "dat.h"
  12. #include "fns.h"
  13. Biobuf bout;
  14. Fsck fsck;
  15. static void
  16. usage(void)
  17. {
  18. fprint(2, "usage: %s [-c cachesize] [-h host] file\n", argv0);
  19. exits("usage");
  20. }
  21. //#pragma varargck argpos flprint 1
  22. static int
  23. flprint(char *fmt, ...)
  24. {
  25. int n;
  26. va_list arg;
  27. va_start(arg, fmt);
  28. n = Bvprint(&bout, fmt, arg);
  29. va_end(arg);
  30. return n;
  31. }
  32. static void
  33. flclre(Fsck *f, Block *b, int o)
  34. {
  35. Bprint(&bout, "# clre 0x%x %d\n", b->addr, o);
  36. }
  37. static void
  38. flclrp(Fsck *f, Block *b, int o)
  39. {
  40. Bprint(&bout, "# clrp 0x%x %d\n", b->addr, o);
  41. }
  42. static void
  43. flclri(Fsck *f, char *name, MetaBlock *m, int i, Block *b)
  44. {
  45. Bprint(&bout, "# clri %s\n", name);
  46. }
  47. static void
  48. flclose(Fsck *f, Block *b, uint32_t epoch)
  49. {
  50. Bprint(&bout, "# bclose 0x%x %u\n", b->addr, epoch);
  51. }
  52. void
  53. main(int argc, char *argv[])
  54. {
  55. int csize = 1000;
  56. VtSession *z;
  57. char *host = nil;
  58. fsck.useventi = 1;
  59. Binit(&bout, 1, OWRITE);
  60. ARGBEGIN{
  61. default:
  62. usage();
  63. case 'c':
  64. csize = atoi(ARGF());
  65. if(csize <= 0)
  66. usage();
  67. break;
  68. case 'f':
  69. fsck.useventi = 0;
  70. break;
  71. case 'h':
  72. host = ARGF();
  73. break;
  74. case 'v':
  75. fsck.printdirs = 1;
  76. break;
  77. }ARGEND;
  78. if(argc != 1)
  79. usage();
  80. vtAttach();
  81. fmtinstall('L', labelFmt);
  82. fmtinstall('V', scoreFmt);
  83. fmtinstall('R', vtErrFmt);
  84. /*
  85. * Connect to Venti.
  86. */
  87. z = vtDial(host, 0);
  88. if(z == nil){
  89. if(fsck.useventi)
  90. vtFatal("could not connect to server: %s", vtGetError());
  91. }else if(!vtConnect(z, 0))
  92. vtFatal("vtConnect: %s", vtGetError());
  93. /*
  94. * Initialize file system.
  95. */
  96. fsck.fs = fsOpen(argv[0], z, csize, OReadOnly);
  97. if(fsck.fs == nil)
  98. vtFatal("could not open file system: %R");
  99. fsck.print = flprint;
  100. fsck.clre = flclre;
  101. fsck.clrp = flclrp;
  102. fsck.close = flclose;
  103. fsck.clri = flclri;
  104. fsCheck(&fsck);
  105. exits(0);
  106. }