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