touchfs.c 1.5 KB

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