tpfs.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 tp tapes. dectape versions have 192
  14. * entries, magtape have 496. This treats the same
  15. * by ignoring entries with bad header checksums
  16. */
  17. struct tp {
  18. unsigned char name[32];
  19. unsigned char mode[2];
  20. unsigned char uid[1];
  21. unsigned char gid[1];
  22. unsigned char unused[1];
  23. unsigned char size[3];
  24. unsigned char tmod[4];
  25. unsigned char taddress[2];
  26. unsigned char unused2[16];
  27. unsigned char checksum[2];
  28. } dir[496+8];
  29. char buffer[8192];
  30. int tapefile;
  31. void
  32. populate(char *name)
  33. {
  34. int i, isabs, badcksum, goodcksum;
  35. struct tp *tpp;
  36. Fileinf f;
  37. replete = 1;
  38. tapefile = open(name, OREAD);
  39. if (tapefile<0)
  40. error("Can't open argument file");
  41. read(tapefile, dir, sizeof dir);
  42. badcksum = goodcksum = 0;
  43. for (i=0, tpp=&dir[8]; i<496; i++, tpp++) {
  44. unsigned char *sp = (unsigned char *)tpp;
  45. int j, cksum = 0;
  46. for (j=0; j<32; j++, sp+=2)
  47. cksum += sp[0] + (sp[1]<<8);
  48. cksum &= 0xFFFF;
  49. if (cksum!=0) {
  50. badcksum++;
  51. continue;
  52. }
  53. goodcksum++;
  54. if (tpp->name[0]=='\0')
  55. continue;
  56. f.addr = tpp->taddress[0] + (tpp->taddress[1]<<8);
  57. if (f.addr==0)
  58. continue;
  59. f.size = (tpp->size[0]<<16) + (tpp->size[1]<<0) + (tpp->size[2]<<8);
  60. f.mdate = (tpp->tmod[2]<<0) + (tpp->tmod[3]<<8)
  61. +(tpp->tmod[0]<<16) + (tpp->tmod[1]<<24);
  62. f.mode = tpp->mode[0]&0777;
  63. f.uid = tpp->uid[0];
  64. f.gid = tpp->gid[0];
  65. isabs = tpp->name[0]=='/';
  66. f.name = (char *)tpp->name+isabs;
  67. poppath(f, 1);
  68. }
  69. fprint(2, "%d bad checksums, %d good\n", badcksum, goodcksum);
  70. }
  71. void
  72. popdir(Ram *r)
  73. {
  74. USED(r);
  75. }
  76. void
  77. dotrunc(Ram *r)
  78. {
  79. USED(r);
  80. }
  81. void
  82. docreate(Ram *r)
  83. {
  84. USED(r);
  85. }
  86. char *
  87. doread(Ram *r, int64_t off, int32_t cnt)
  88. {
  89. if (cnt>sizeof(buffer))
  90. print("count too big\n");
  91. seek(tapefile, 512*r->addr+off, 0);
  92. read(tapefile, buffer, cnt);
  93. return buffer;
  94. }
  95. void
  96. dowrite(Ram *r, char *buf, int32_t off, int32_t cnt)
  97. {
  98. USED(r); USED(buf); USED(off); USED(cnt);
  99. }
  100. int
  101. dopermw(Ram *r)
  102. {
  103. USED(r);
  104. return 0;
  105. }