tapfs.c 1.9 KB

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