1
0

touchfs.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. void
  5. Bpass(Biobuf *bin, Biobuf *bout, int n)
  6. {
  7. char buf[8192];
  8. int m;
  9. while(n > 0) {
  10. m = sizeof buf;
  11. if(m > n)
  12. m = n;
  13. m = Bread(bin, buf, m);
  14. if(m <= 0) {
  15. fprint(2, "corrupt archive\n");
  16. exits("notdone");
  17. }
  18. Bwrite(bout, buf, m);
  19. n -= m;
  20. }
  21. assert(n == 0);
  22. }
  23. void
  24. main(int argc, char **argv)
  25. {
  26. char *p, *f[10];
  27. Biobuf bin, bout;
  28. int nf;
  29. ulong d, size;
  30. if(argc != 2) {
  31. fprint(2, "usage: cat mkfs-archive | touchfs date (in seconds)\n");
  32. exits("usage");
  33. }
  34. d = strtoul(argv[1], 0, 0);
  35. quotefmtinstall();
  36. Binit(&bin, 0, OREAD);
  37. Binit(&bout, 1, OWRITE);
  38. while(p = Brdline(&bin, '\n')) {
  39. p[Blinelen(&bin)-1] = '\0';
  40. if(strcmp(p, "end of archive") == 0) {
  41. Bprint(&bout, "end of archive\n");
  42. exits(0);
  43. }
  44. nf = tokenize(p, f, nelem(f));
  45. if(nf != 6) {
  46. fprint(2, "corrupt archive\n");
  47. exits("notdone");
  48. }
  49. Bprint(&bout, "%q %q %q %q %lud %q\n",
  50. f[0], f[1], f[2], f[3], d, f[5]);
  51. size = strtoul(f[5], 0, 0);
  52. Bpass(&bin, &bout, size);
  53. }
  54. fprint(2, "premature end of archive\n");
  55. exits("notdone");
  56. }