#include #include #include #include #include #include using namespace std; FILE *fptr; FILE *edrptr; FILE *outptr; int banner(void) { int descrip; cout << "***************************************************\n"; cout << " VOYAGER EDR CDROM VERIFICATION SYSTEM\n"; cout << "***************************************************\n"; cout << "ENTER 0: TO BEGIN EXECUTION\n"; cout << "ENTER 1: SYSTEM DESCRIPTION\n"; cout << "ENTER 2: EXIT PROGRAM\n"; cin >> descrip; while (descrip) { if (descrip == 2) exit(0); if (descrip == 1) { cout << "\n"; cout << " This routine is designed to reblock and verify\n"; cout << " EDR records transfered to this platform via\n"; cout << " binary copy. Input consists of a directory\n"; cout << " listing of the EDR subdirectory containing data\n"; cout << " to be verified. The directory listing must be\n"; cout << " ordered filename...file ext...size...date.\n"; cout << "\n"; cout << " Windows 2000/XP, use command: \n"; cout << "\n"; cout << " dir/p/-n/-c/o [path] >> [index filename]\n"; cout << "\n"; cout << "ENTER 0: TO BEGIN EXECUTION\n"; cout << "ENTER 1: SYSTEM DESCRIPTION\n"; cout << "ENTER 2: EXIT PROGRAM\n"; cin >> descrip; } } return 0; } int open_idxfile(void) { unsigned int dirsize; char idxfile[30]; cout << "Enter the full path name of index file:\n"; cin >> idxfile; if ((fptr = fopen(idxfile,"rt")) == NULL) //open file as readonly, text { cout << "ERROR: UNABLE TO OPEN FILE: " << idxfile << "\n"; exit(1); } return 0; } int open_outfile(void) { unsigned int dirsize; char verfile[30]; cout << "Enter the full path name of verification file:\n"; cin >> verfile; if ((outptr = fopen(verfile,"wt")) == NULL) //open file as write only, text { cout << "ERROR: UNABLE TO OPEN FILE: " << verfile << "\n"; exit(1); } return 0; } int telem(char fmt) { char mode[8]; if ( fmt == 0X00 ) strcpy(mode," ENG \n"); if ( fmt == 0X01 ) strcpy(mode," CR-2 \n"); if ( fmt == 0X02 ) strcpy(mode," CR-3 \n"); if ( fmt == 0X03 ) strcpy(mode," CR-4 \n"); if ( fmt == 0X04 ) strcpy(mode," CR-5 \n"); if ( fmt == 0X05 ) strcpy(mode," CR-6 \n"); if ( fmt == 0X06 ) strcpy(mode," CR-7 \n"); if ( fmt == 0X07 ) strcpy(mode," CR-1 \n"); if ( fmt == 0X08 ) strcpy(mode," ???? \n"); if ( fmt == 0X09 ) strcpy(mode," ???? \n"); if ( fmt == 0X0A ) strcpy(mode," GS-3 \n"); if ( fmt == 0X0B ) strcpy(mode," ???? \n"); if ( fmt == 0X0C ) strcpy(mode," GS-7 \n"); if ( fmt == 0X0D ) strcpy(mode," ???? \n"); if ( fmt == 0X0E ) strcpy(mode," GS-6 \n"); if ( fmt == 0X0F ) strcpy(mode," GS-4 \n"); if ( fmt == 0X10 ) strcpy(mode," ???? \n"); if ( fmt == 0X11 ) strcpy(mode," GS-2 \n"); if ( fmt == 0X12 ) strcpy(mode," ???? \n"); if ( fmt == 0X13 ) strcpy(mode," ???? \n"); if ( fmt == 0X14 ) strcpy(mode," ???? \n"); if ( fmt == 0X15 ) strcpy(mode," ???? \n"); if ( fmt == 0X16 ) strcpy(mode," OC-2 \n"); if ( fmt == 0X17 ) strcpy(mode," OC-1 \n"); if ( fmt == 0X18 ) strcpy(mode," CR5-A\n"); if ( fmt == 0X19 ) strcpy(mode," GS-10\n"); if ( fmt == 0X1A ) strcpy(mode," GS-8 \n"); if ( fmt == 0X1B ) strcpy(mode," ???? \n"); if ( fmt == 0X1C ) strcpy(mode," ???? \n"); if ( fmt == 0X1D ) strcpy(mode," UV-5A\n"); if ( fmt == 0X1E ) strcpy(mode," ???? \n"); if ( fmt == 0X1F ) strcpy(mode," ???? \n"); printf(" MODE%s",mode); fprintf(outptr," MODE%s",mode); return(0); } //important INTEL x86 platform note: // long int = 64 bits // int = 32 bits // short int = 16 bits // char always 8 bits int verify(char tmprec[20000]) { unsigned int *longptr; unsigned int scidmask; unsigned int scid; unsigned short int *ihour; unsigned short int *isec; unsigned short int *imsec; unsigned short int msec; unsigned short int sec; unsigned short int min; unsigned short int hour; unsigned short int day; unsigned short int tmp; short int year; char *iyr; char halfword[2]; //assign pointer to start of record (array element 0) //longptr = (unsigned long int*)&tmprec[0]; longptr = (unsigned int*) tmprec; scidmask = 0X0F000000; scid = *longptr & scidmask; //get s/c id scid = scid >> 24; //get hours of current SCET year ihour = ((unsigned short int*) & *longptr) + 12; hour = *ihour & 0X00FF; tmp = *ihour & 0XFF00; hour = hour << 8; tmp = tmp >> 8; hour = hour | tmp; day = hour/24; hour = hour - (day*24); // test alternate swap algorithm - confirmed /* halfword[0] = tmprec[25]; halfword[1] = tmprec[24]; ihour = (unsigned short int*) halfword; hour = *ihour; day = hour/24; hour = hour - (day*24); */ //get seconds of current SCET hour isec = ((unsigned short int*) longptr) + 13; sec = *isec & 0X00FF; tmp = *isec & 0XFF00; sec = sec << 8; tmp = tmp >> 8; sec = sec | tmp; min = sec/60; sec = sec - (min*60); //get milliseconds of current second imsec = ((unsigned short int*) & *longptr) + 14; msec = *imsec & 0X00FF; tmp = *imsec & 0XFF00; msec = msec << 8; tmp = tmp >> 8; msec = msec | tmp; //get SCET year iyr = ((char*) & *longptr) + 30; //header record byte 15 where first char is byte 1 year = (short)*iyr; printf("SC %1d SCET %2d:%3d:%2d:%2d:%2d:%3d",scid,year,day,hour,min,sec,msec); fprintf(outptr,"SC %1d SCET %2d:%3d:%2d:%2d:%2d:%3d",scid,year,day,hour,min,sec,msec); return(0); } int main(void) { unsigned int recnt = 0; unsigned int bytecnt = 0; unsigned int btot = 0; unsigned int bytes = 0; unsigned int totalcnt = 0; unsigned int totalbytes = 0; unsigned int dirsize; unsigned int mjs; unsigned int mjsflag = 0X00E2D1D4; unsigned int mjsmask = 0X00FFFFFF; unsigned int *longptr; int open_idxfile(); int open_outfile(); int scval; int pcnt = 0; int fcnt = 14; int blen = 0; char block[512]; char tmprec[20000]; char edrfile[50]; char fstring[80]; char *fstr = &fstring[0]; char path[30]; char name[30]; char *pth = &path[0]; time_t t; banner(); // display program info if ( open_idxfile()!=0 ) exit(1); //open index file if ( open_outfile()!=0 ) exit(1); //open verify file for (int i = 1; i <= 4; i++) //get EDR path in index file { fgets(fstring,80,fptr); //line #4 } printf("\n"); while (fstring[fcnt] != '\0') //copy substring to path { path[pcnt] = fstring[fcnt]; pcnt = pcnt + 1; fcnt = fcnt + 1; } //end copy substring to path path[pcnt] = '\0'; for (int i = 1; i <= 4; i++) //move to 1st edr listed in index file { fgets(fstring,80,fptr); } t = time(NULL); cout << "DATE: " << ctime(&t); cout << "ENTER LAST NAME OF OPERATOR:\n"; cin >> name; fprintf(outptr,"\n"); fprintf(outptr,"************ VOYAGER EDR CD-ROM ARCHIVE ************\n"); fprintf(outptr,"DATE: %s",ctime(&t)); fprintf(outptr,"LAST NAME OF OPERATOR: %s \n",name); fprintf(outptr,"FILE STATISTICS:\n"); fprintf(outptr,"----------------\n\n"); while (fstring[0] == 'e') //check for edr in line { fstr = &fstring[0]; fstring[7] = '\0'; // parse edrname strcpy(edrfile,pth); // concatenate path edrfile[pcnt-1] = '\\'; edrfile[pcnt] = '\0'; // end of string strcat(edrfile,fstr); // concat edrname strcat(edrfile,".edr"); // concat extension printf("PROCESSING FILE %s ...\n",edrfile); fprintf(outptr,"PROCESSING FILE %s ...\n",edrfile); if ((edrptr = fopen(edrfile,"rb")) == NULL) //open edr file for read { cout << "ERROR: UNABLE TO OPEN FILE: " << edrfile << "\n"; exit(0); } printf("\n"); fprintf(outptr,"\n"); printf("****BEGIN FILE VERIFICATION****\n"); fprintf(outptr,"****BEGIN FILE VERIFICATION****\n"); recnt = 0; bytes = 0; bytecnt = 0; while (!feof(edrptr)) // read entire edr file { fread(&block,512,1,edrptr); //read 512 byte block for (int k = 0; k <= 511; k++) //go through block { tmprec[bytes+k] = block[k]; // load bytes into holding array if (bytes+k>=2) //search for string MJS = record start { longptr = (unsigned int*)&tmprec[bytes+k-2]; mjs = *longptr & mjsmask; // extract 3 least significant bytes if (mjsflag == mjs) //check for rec begin { blen = bytes + k - 2; if ( blen > 2 ) //output reblocked record { recnt = recnt + 1; btot = btot + blen; if ((recnt-1)%100 == 0) //display every 100th record { printf("REC # %5d %5d BYTES ",recnt,blen); fprintf(outptr,"REC # %5d %5d BYTES ",recnt,blen); if ( verify(tmprec)!=0 ) exit(1); if ( telem(tmprec[6])!=0 ) exit(1); // printf("WORD 1 %4x %4x %4x %4x\n",tmprec[0],tmprec[1],tmprec[2],tmprec[3]); // exit(0); //stop after first record output } //end display every 100th record tmprec[0] = tmprec[bytes+k-2]; tmprec[1] = tmprec[bytes+k-1]; tmprec[2] = tmprec[bytes+k]; bytes = 2 - k; } //end output reblocked record } //end check for rec begin } //end search for string MJS = record start } //end go through block bytes = bytes + 512; } //end read 512 byte block blen = bytes; if (blen > 2) { recnt = recnt + 1; printf("REC # %5d %5d BYTES ",recnt,blen); fprintf(outptr,"REC # %5d %5d BYTES ",recnt,blen); if ( verify(tmprec)!=0 ) exit(1); if ( telem(tmprec[6])!=0 ) exit(1); /* printf("WORD 1 %4x %4x %4x %4x\n",tmprec[0], tmprec[1],tmprec[2],tmprec[3]); */ } fseek(edrptr,0,SEEK_END); // find end of file bytecnt = ftell(edrptr); // total file bytes totalbytes = totalbytes + bytecnt; // total bytes in dir totalcnt = totalcnt + recnt; // total recs in dir printf("TOTAL FILE BYTES: %10d\n",bytecnt); printf("TOTAL FILE RECORDS: %10d\n",recnt); printf("****END FILE VERIFICATION****\n\n"); fprintf(outptr,"TOTAL FILE BYTES: %10d\n",bytecnt); fprintf(outptr,"TOTAL FILE RECORDS: %10d\n",recnt); fprintf(outptr,"****END FILE VERIFICATION****\n\n"); fclose(edrptr); // close index file fgets(fstring,80,fptr); // next edr file // exit(0); //stop after processing first edr file } printf("TOTAL DIRECTORY BYTES = %10d\n",totalbytes); printf("TOTAL DIRECTORY RECORDS: %10d\n",totalcnt); printf("\n\n"); fprintf(outptr,"SUCCESSFUL COMPLETION OF CDVERIFY......\n"); fprintf(outptr,"TOTAL DIRECTORY BYTES = %10d\n",totalbytes); fprintf(outptr,"TOTAL DIRECTORY RECORDS: %10d\n",totalcnt); fprintf(outptr,"\n\n"); fprintf(outptr,"SUCCESSFUL COMPLETION OF CDVERIFY......\n"); fclose(outptr); // close verify file return 0; }