|
|
1.1 ! root 1: #line 1 "FILE.C" ! 2: ! 3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */ ! 4: ! 5: /*************************************************************************/ ! 6: /* Add/delete/edit/view/retrieve the file information for struct file_t */ ! 7: /* Called only from functions within xfer.c */ ! 8: /*************************************************************************/ ! 9: ! 10: #include "sbbs.h" ! 11: ! 12: long fdate_dir(char *filespec); ! 13: ! 14: void getextdesc(uint dirnum, ulong datoffset, char *ext) ! 15: { ! 16: char str[256]; ! 17: int file; ! 18: ! 19: memset(ext,0,513); ! 20: sprintf(str,"%s%s.EXB",dir[dirnum]->data_dir,dir[dirnum]->code); ! 21: if((file=nopen(str,O_RDONLY))==-1) ! 22: return; ! 23: lseek(file,(datoffset/F_LEN)*512L,SEEK_SET); ! 24: read(file,ext,512); ! 25: close(file); ! 26: } ! 27: ! 28: void putextdesc(uint dirnum, ulong datoffset, char *ext) ! 29: { ! 30: char str[256],nulbuf[512]; ! 31: int file; ! 32: ! 33: memset(nulbuf,0,512); ! 34: sprintf(str,"%s%s.EXB",dir[dirnum]->data_dir,dir[dirnum]->code); ! 35: if((file=nopen(str,O_WRONLY|O_CREAT))==-1) ! 36: return; ! 37: lseek(file,0L,SEEK_END); ! 38: while(filelength(file)<(datoffset/F_LEN)*512L) ! 39: write(file,nulbuf,512); ! 40: lseek(file,(datoffset/F_LEN)*512L,SEEK_SET); ! 41: write(file,ext,512); ! 42: close(file); ! 43: } ! 44: ! 45: /****************************************************************************/ ! 46: /* Prints all information of file in file_t structure 'f' */ ! 47: /****************************************************************************/ ! 48: void fileinfo(file_t f) ! 49: { ! 50: char str[256],fname[13],ext[513]; ! 51: uint i,j; ! 52: long t; ! 53: ! 54: for(i=0;i<usrlibs;i++) ! 55: if(usrlib[i]==dir[f.dir]->lib) ! 56: break; ! 57: for(j=0;j<usrdirs[i];j++) ! 58: if(usrdir[i][j]==f.dir) ! 59: break; ! 60: unpadfname(f.name,fname); ! 61: bprintf(text[FiLib],i+1,lib[dir[f.dir]->lib]->lname); ! 62: bprintf(text[FiDir],j+1,dir[f.dir]->lname); ! 63: bprintf(text[FiFilename],fname); ! 64: if(f.size!=-1L) ! 65: bprintf(text[FiFileSize],ultoac(f.size,tmp)); ! 66: bprintf(text[FiCredits] ! 67: ,(dir[f.dir]->misc&DIR_FREE || !f.cdt) ? "FREE" : ultoac(f.cdt,tmp)); ! 68: bprintf(text[FiDescription],f.desc); ! 69: bprintf(text[FiUploadedBy],f.misc&FM_ANON ? text[UNKNOWN_USER] : f.uler); ! 70: if(f.date) ! 71: bprintf(text[FiFileDate],timestr(&f.date)); ! 72: bprintf(text[FiDateUled],timestr(&f.dateuled)); ! 73: bprintf(text[FiDateDled],f.datedled ? timestr(&f.datedled) : "Never"); ! 74: bprintf(text[FiTimesDled],f.timesdled); ! 75: if(f.size!=-1L) ! 76: bprintf(text[FiTransferTime],sectostr(f.timetodl,tmp)); ! 77: if(f.altpath) { ! 78: if(f.altpath<=altpaths) { ! 79: if(SYSOP) ! 80: bprintf(text[FiAlternatePath],altpath[f.altpath-1]); } ! 81: else ! 82: bprintf(text[InvalidAlternatePathN],f.altpath); } ! 83: CRLF; ! 84: if(f.misc&FM_EXTDESC) { ! 85: getextdesc(f.dir,f.datoffset,ext); ! 86: CRLF; ! 87: putmsg(ext,P_NOATCODES); ! 88: CRLF; } ! 89: if(f.size==-1L) ! 90: bprintf(text[FileIsNotOnline],f.name); ! 91: if(f.opencount) ! 92: bprintf(text[FileIsOpen],f.opencount,f.opencount>1 ? "s" : nulstr); ! 93: ! 94: } ! 95: ! 96: /****************************************************************************/ ! 97: /* Gets file data from dircode.IXB file */ ! 98: /* Need fields .name and .dir filled. */ ! 99: /* only fills .offset, .dateuled, and .datedled */ ! 100: /****************************************************************************/ ! 101: void getfileixb(file_t *f) ! 102: { ! 103: uchar HUGE16 *ixbbuf,str[256],fname[13]; ! 104: int file; ! 105: ulong l,length; ! 106: ! 107: sprintf(str,"%s%s.IXB",dir[f->dir]->data_dir,dir[f->dir]->code); ! 108: if((file=nopen(str,O_RDONLY))==-1) { ! 109: errormsg(WHERE,ERR_OPEN,str,O_RDONLY); ! 110: return; } ! 111: length=filelength(file); ! 112: if(length%F_IXBSIZE) { ! 113: close(file); ! 114: errormsg(WHERE,ERR_LEN,str,length); ! 115: return; } ! 116: if((ixbbuf=MALLOC(length))==NULL) { ! 117: close(file); ! 118: errormsg(WHERE,ERR_ALLOC,str,length); ! 119: return; } ! 120: if(lread(file,ixbbuf,length)!=length) { ! 121: close(file); ! 122: FREE((char *)ixbbuf); ! 123: errormsg(WHERE,ERR_READ,str,length); ! 124: return; } ! 125: close(file); ! 126: strcpy(fname,f->name); ! 127: for(l=8;l<12;l++) /* Turn FILENAME.EXT into FILENAMEEXT */ ! 128: fname[l]=fname[l+1]; ! 129: for(l=0;l<length;l+=F_IXBSIZE) { ! 130: sprintf(str,"%11.11s",ixbbuf+l); ! 131: if(!strcmp(str,fname)) ! 132: break; } ! 133: if(l>=length) { ! 134: errormsg(WHERE,ERR_CHK,str,0); ! 135: FREE((char *)ixbbuf); ! 136: return; } ! 137: l+=11; ! 138: f->datoffset=ixbbuf[l]|((long)ixbbuf[l+1]<<8)|((long)ixbbuf[l+2]<<16); ! 139: f->dateuled=ixbbuf[l+3]|((long)ixbbuf[l+4]<<8) ! 140: |((long)ixbbuf[l+5]<<16)|((long)ixbbuf[l+6]<<24); ! 141: f->datedled=ixbbuf[l+7]|((long)ixbbuf[l+8]<<8) ! 142: |((long)ixbbuf[l+9]<<16)|((long)ixbbuf[l+10]<<24); ! 143: FREE((char *)ixbbuf); ! 144: } ! 145: ! 146: /****************************************************************************/ ! 147: /* Gets filedata from dircode.DAT file */ ! 148: /* Need fields .name ,.dir and .offset to get other info */ ! 149: /* Does not fill .dateuled or .datedled fields. */ ! 150: /****************************************************************************/ ! 151: void getfiledat(file_t *f) ! 152: { ! 153: char buf[F_LEN+1],str[256]; ! 154: int file; ! 155: long length; ! 156: ! 157: sprintf(str,"%s%s.DAT",dir[f->dir]->data_dir,dir[f->dir]->code); ! 158: if((file=nopen(str,O_RDONLY))==-1) { ! 159: errormsg(WHERE,ERR_OPEN,str,O_RDONLY); ! 160: return; } ! 161: length=filelength(file); ! 162: if(f->datoffset>length) { ! 163: close(file); ! 164: errormsg(WHERE,ERR_LEN,str,length); ! 165: return; } ! 166: if(length%F_LEN) { ! 167: close(file); ! 168: errormsg(WHERE,ERR_LEN,str,length); ! 169: return; } ! 170: lseek(file,f->datoffset,SEEK_SET); ! 171: if(read(file,buf,F_LEN)!=F_LEN) { ! 172: close(file); ! 173: errormsg(WHERE,ERR_READ,str,F_LEN); ! 174: return; } ! 175: close(file); ! 176: getrec(buf,F_ALTPATH,2,str); ! 177: f->altpath=hptoi(str); ! 178: getrec(buf,F_CDT,LEN_FCDT,str); ! 179: f->cdt=atol(str); ! 180: ! 181: if(!f->size) { /* only read disk if this is null */ ! 182: // if(dir[f->dir]->misc&DIR_FCHK) { ! 183: sprintf(str,"%s%s" ! 184: ,f->altpath>0 && f->altpath<=altpaths ? altpath[f->altpath-1] ! 185: : dir[f->dir]->path,unpadfname(f->name,tmp)); ! 186: f->size=flength(str); ! 187: f->date=fdate_dir(str); ! 188: /* ! 189: } ! 190: else { ! 191: f->size=f->cdt; ! 192: f->date=0; } ! 193: */ ! 194: } ! 195: if((f->size>0L) && cur_cps) ! 196: f->timetodl=(f->size/(ulong)cur_cps); ! 197: else ! 198: f->timetodl=0; ! 199: ! 200: getrec(buf,F_DESC,LEN_FDESC,f->desc); ! 201: getrec(buf,F_ULER,LEN_ALIAS,f->uler); ! 202: getrec(buf,F_TIMESDLED,5,str); ! 203: f->timesdled=atoi(str); ! 204: getrec(buf,F_OPENCOUNT,3,str); ! 205: f->opencount=atoi(str); ! 206: if(buf[F_MISC]!=ETX) ! 207: f->misc=buf[F_MISC]-SP; ! 208: else ! 209: f->misc=0; ! 210: } ! 211: ! 212: /****************************************************************************/ ! 213: /* Increments the opencount on the file data 'f' and adds the transaction */ ! 214: /* to the backout.dab */ ! 215: /****************************************************************************/ ! 216: void openfile(file_t f) ! 217: { ! 218: char str1[256],str2[4],str3[4],ch; ! 219: int file; ! 220: ! 221: /************************************/ ! 222: /* Increment open count in dat file */ ! 223: /************************************/ ! 224: sprintf(str1,"%s%s.DAT",dir[f.dir]->data_dir,dir[f.dir]->code); ! 225: if((file=nopen(str1,O_RDWR))==-1) { ! 226: errormsg(WHERE,ERR_OPEN,str1,O_RDWR); ! 227: return; } ! 228: lseek(file,f.datoffset+F_OPENCOUNT,SEEK_SET); ! 229: if(read(file,str2,3)!=3) { ! 230: close(file); ! 231: errormsg(WHERE,ERR_READ,str1,3); ! 232: return; } ! 233: str2[3]=0; ! 234: itoa(atoi(str2)+1,str3,10); ! 235: putrec(str2,0,3,str3); ! 236: lseek(file,f.datoffset+F_OPENCOUNT,SEEK_SET); ! 237: if(write(file,str2,3)!=3) { ! 238: close(file); ! 239: errormsg(WHERE,ERR_WRITE,str1,3); ! 240: return; } ! 241: close(file); ! 242: /**********************************/ ! 243: /* Add transaction to BACKOUT.DAB */ ! 244: /**********************************/ ! 245: sprintf(str1,"%sBACKOUT.DAB",node_dir); ! 246: if((file=nopen(str1,O_WRONLY|O_APPEND|O_CREAT))==-1) { ! 247: errormsg(WHERE,ERR_OPEN,str1,O_WRONLY|O_APPEND|O_CREAT); ! 248: return; } ! 249: ch=BO_OPENFILE; ! 250: write(file,&ch,1); /* backout type */ ! 251: write(file,dir[f.dir]->code,8); /* directory code */ ! 252: write(file,&f.datoffset,4); /* offset into .dat file */ ! 253: write(file,&ch,BO_LEN-(1+8+4)); /* pad it */ ! 254: close(file); ! 255: } ! 256: ! 257: /****************************************************************************/ ! 258: /* Decrements the opencount on the file data 'f' and removes the backout */ ! 259: /* from the backout.dab */ ! 260: /****************************************************************************/ ! 261: void closefile(file_t f) ! 262: { ! 263: uchar str1[256],str2[4],str3[4],ch,*buf; ! 264: int file; ! 265: long length,l,offset; ! 266: ! 267: /************************************/ ! 268: /* Decrement open count in dat file */ ! 269: /************************************/ ! 270: sprintf(str1,"%s%s.DAT",dir[f.dir]->data_dir,dir[f.dir]->code); ! 271: if((file=nopen(str1,O_RDWR))==-1) { ! 272: errormsg(WHERE,ERR_OPEN,str1,O_RDWR); ! 273: return; } ! 274: lseek(file,f.datoffset+F_OPENCOUNT,SEEK_SET); ! 275: if(read(file,str2,3)!=3) { ! 276: close(file); ! 277: errormsg(WHERE,ERR_READ,str1,3); ! 278: return; } ! 279: str2[3]=0; ! 280: ch=atoi(str2); ! 281: if(ch) ch--; ! 282: itoa(ch,str3,10); ! 283: putrec(str2,0,3,str3); ! 284: lseek(file,f.datoffset+F_OPENCOUNT,SEEK_SET); ! 285: if(write(file,str2,3)!=3) { ! 286: close(file); ! 287: errormsg(WHERE,ERR_WRITE,str1,3); ! 288: return; } ! 289: close(file); ! 290: /*****************************************/ ! 291: /* Removing transaction from BACKOUT.DAB */ ! 292: /*****************************************/ ! 293: sprintf(str1,"%sBACKOUT.DAB",node_dir); ! 294: if(flength(str1)<1L) /* file is not there or empty */ ! 295: return; ! 296: if((file=nopen(str1,O_RDONLY))==-1) { ! 297: errormsg(WHERE,ERR_OPEN,str1,O_RDONLY); ! 298: return; } ! 299: length=filelength(file); ! 300: if((buf=MALLOC(length))==NULL) { ! 301: close(file); ! 302: errormsg(WHERE,ERR_ALLOC,str1,length); ! 303: return; } ! 304: if(read(file,buf,length)!=length) { ! 305: close(file); ! 306: FREE(buf); ! 307: errormsg(WHERE,ERR_READ,str1,length); ! 308: return; } ! 309: close(file); ! 310: if((file=nopen(str1,O_WRONLY|O_TRUNC))==-1) { ! 311: errormsg(WHERE,ERR_OPEN,str1,O_WRONLY|O_TRUNC); ! 312: return; } ! 313: ch=0; /* 'ch' is a 'file already removed' flag */ ! 314: for(l=0;l<length;l+=BO_LEN) { /* in case file is in backout.dab > 1 */ ! 315: if(!ch && buf[l]==BO_OPENFILE) { ! 316: memcpy(str1,buf+l+1,8); ! 317: str1[8]=0; ! 318: memcpy(&offset,buf+l+9,4); ! 319: if(!stricmp(str1,dir[f.dir]->code) && offset==f.datoffset) { ! 320: ch=1; ! 321: continue; } } ! 322: write(file,buf+l,BO_LEN); } ! 323: FREE(buf); ! 324: close(file); ! 325: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.