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