tapfs.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 "tapefs.h"
  12. /*
  13. * File system for old tap tapes.
  14. */
  15. struct tap {
  16. unsigned char name[32];
  17. unsigned char mode[1];
  18. unsigned char uid[1];
  19. unsigned char size[2];
  20. unsigned char tmod[4];
  21. unsigned char taddress[2];
  22. unsigned char unused[20];
  23. unsigned char checksum[2];
  24. } dir[192];
  25. int tapefile;
  26. char buffer[8192];
  27. int32_t cvtime(unsigned char *);
  28. extern int verbose;
  29. extern int newtap;
  30. void
  31. populate(char *name)
  32. {
  33. int i, isabs;
  34. struct tap *tpp;
  35. Fileinf f;
  36. replete = 1;
  37. tapefile = open(name, OREAD);
  38. if (tapefile<0)
  39. error("Can't open argument file");
  40. read(tapefile, dir, sizeof dir);
  41. for (i=0, tpp=&dir[8]; i<192; i++, tpp++) {
  42. unsigned char *sp = (unsigned char *)tpp;
  43. int j, cksum = 0;
  44. for (j=0; j<32; j++, sp+=2)
  45. cksum += sp[0] + (sp[1]<<8);
  46. cksum &= 0xFFFF;
  47. if (cksum!=0) {
  48. print("cksum failure\n");
  49. continue;
  50. }
  51. if (tpp->name[0]=='\0')
  52. continue;
  53. f.addr = tpp->taddress[0] + (tpp->taddress[1]<<8);
  54. if (f.addr==0)
  55. continue;
  56. f.size = tpp->size[0] + (tpp->size[1]<<8);
  57. f.mdate = cvtime(tpp->tmod);
  58. f.mode = tpp->mode[0]&0777;
  59. f.uid = tpp->uid[0]&0377;
  60. isabs = tpp->name[0]=='/';
  61. f.name = (char *)tpp->name+isabs;
  62. if (verbose)
  63. print("%s mode %o uid %d, %s", f.name, f.mode, f.uid, ctime(f.mdate));
  64. poppath(f, 1);
  65. }
  66. }
  67. int32_t
  68. cvtime(unsigned char *tp)
  69. {
  70. unsigned long t = (tp[1]<<24)+(tp[0]<<16)+(tp[3]<<8)+(tp[2]<<0);
  71. if (!newtap) {
  72. t /= 60;
  73. t += 3*365*24*3600;
  74. }
  75. return t;
  76. }
  77. void
  78. popdir(Ram *r)
  79. {
  80. USED(r);
  81. }
  82. void
  83. dotrunc(Ram *r)
  84. {
  85. USED(r);
  86. }
  87. void
  88. docreate(Ram *r)
  89. {
  90. USED(r);
  91. }
  92. char *
  93. doread(Ram *r, int64_t off, int32_t cnt)
  94. {
  95. if (cnt>sizeof(buffer))
  96. print("count too big\n");
  97. seek(tapefile, 512*r->addr+off, 0);
  98. read(tapefile, buffer, cnt);
  99. return buffer;
  100. }
  101. void
  102. dowrite(Ram *r, char *buf, int32_t off, int32_t cnt)
  103. {
  104. USED(r); USED(buf); USED(off); USED(cnt);
  105. }
  106. int
  107. dopermw(Ram *r)
  108. {
  109. USED(r);
  110. return 0;
  111. }