2 /*------------------------------
3 /* SOURCE FILE NAME: RTNEW1.C
4 /*------------------------------
9 #include "restpars.h" /*;AN000;4*/
11 #include "dos.h" /*;AN000;2*/
12 #include "comsub.h" /* common subroutine def'n */
17 #define LAST_DIRBLOCK 0xffffffff /* !wrw */
18 BYTE got_first_fh; /* !wrw */
20 struct dir_block russ_dir_block; /* Current directory block /* !wrw */
21 extern BYTE backup_level; /* Tells which DOS version made the BACKUP*/ /*;AN000;3*/
23 struct file_header_new russ_file_header;/* Current file_header /* !wrw */
24 unsigned short tot_num_fh_read_in; /* Num FH read in so far /* !wrw */
25 unsigned short num_fh_in_buffer; /* Num FH currently in buff /* !wrw */
26 unsigned short num_fh_in_buf_processed; /* Number of FH in the buffer that have been processed /* !wrw */
27 struct file_header_new far *fheadnew; /* Global pointer to FH /* !wrw */
30 BYTE fileheader_length; /*;AN000;3 Length of a file header */
33 extern BYTE control_flag;
34 extern BYTE control_flag2;
35 extern char far *control_buf_pointer;
36 extern unsigned control_file_handle;
37 extern WORD control_bufsize; /* !wrw */
41 /***************** START OF SPECIFICATION ********************************
43 /* SUBROUTINE NAME : findfile_new
45 /* DESCRIPTIVE NAME : Find a file with matching file name from
46 /* the file CONTROL.xxx.
48 /* FUNCTION: For new format only, search through all directory blocks
49 /* and all file headers until a file header with matched file
50 /* path, name and extension is found. also store information
51 /* into fhead and finfo if file is found which match the
52 /* filename and file extension specified in the command line.
54 /* NOTES: Path name for comparison has to started with \ and end with \.
56 /********************** END OF SPECIFICATIONS *******************************/
57 int findfile_new( finfo, found, done_searching, inpath,
58 infspec, dirptr, flptr, numentry, dir_path)
60 struct file_info *finfo;
62 unsigned int *done_searching;
67 unsigned int *numentry;
70 struct dir_block far *dirblk;
71 char temp_path[MAXPATH];
72 char temp_fname[MAXFSPEC];
77 dirblk = (struct dir_block far *)&russ_dir_block; /* !wrw */
78 fheadnew = (struct file_header_new far *)&russ_file_header; /* !wrw */
80 /******************************************************************/
81 /* search the directory block for the one that has the right path */
82 /*******************************************************************/
83 while ((*done_searching == FALSE) && (*found == FALSE))
86 for (i = 0; i <= (MAXPATH-2); ++i)
87 temp_path[i+1] = dirblk->path[i];
89 temp_path[MAXPATH-1] = NULLC;
91 /*****************************/
92 /* While path does not match */
93 /*****************************/
95 while (pathmatch(inpath,temp_path) == FALSE)
97 if (dirblk->nextdb == LAST_DIRBLOCK) /* !wrw */
100 *done_searching = TRUE;
105 read_in_next_dirblock(); /* !wrw */
107 for (i = 0; i <= (MAXPATH-2); ++i)
108 temp_path[i+1] = dirblk->path[i];
109 temp_path[MAXPATH-1] = NULLC;
112 /*end of if not last dirblk*/
114 } /*end while loop, searching for the right path in directory block*/
115 /*if done searching, break out of the big loop to exit*/
117 if (*done_searching == TRUE)
120 /***************************************************/
121 /* directory block with correct path has been found*/
122 /***************************************************/
124 /*get the total number of file headers in the directory block*/
125 *numentry = (unsigned int)russ_dir_block.numentry; /* !wrw */
127 if (got_first_fh == FALSE) /* !wrw */
128 read_in_a_fileheader(); /*#### /* !wrw */
130 /****************************************************/
131 /* search all the file headers under this directory */
132 /* block to find the one with right file name */
133 /****************************************************/
137 if ((rc = fheadnew->flag & COMPLETE_BIT) != COMPLETE_BIT)
143 if (dirblk->nextdb == LAST_DIRBLOCK) /* !wrw */
146 *done_searching = TRUE;
147 break; /*exit FOR loop, go back to WHILE loop*/
151 read_in_next_dirblock(); /* !wrw */
152 break; /*exit FOR loop, go back to WHILE loop*/
157 read_in_a_fileheader(); /* !wrw */
162 for (i = 0; i <= (MAXFSPEC-2); ++i)
163 temp_fname[i] = fheadnew->fname[i];
164 temp_fname[MAXFSPEC-1] = NULLC;
166 if (fspecmatch(infspec,temp_fname)==TRUE)
171 else /* This file header is not the right one*/
177 if (dirblk->nextdb == LAST_DIRBLOCK)
180 *done_searching = TRUE;
181 break; /*exit FOR loop, go back to WHILE loop*/
185 read_in_next_dirblock(); /* !wrw */
187 } /*end of if not last dir block */
189 else /*point to the next file header and loop again*/
190 read_in_a_fileheader(); /* !wrw */
194 } /* end for (;;) loop to search all file headers in a directory block */
196 } /*end of while loop*/
200 /*******************************************************************/
201 /* if a file is found, save the information in the disk header and */
203 /*******************************************************************/
206 /* Store information from dir blk into finfo */
207 if (strcmp(dir_path,"no path from fnext") == 0)
208 strcpy(finfo->path,temp_path);
211 finfo->path[0] = '\\';
212 finfo->path[1] = NULLC;
213 strcat(finfo->path,dir_path);
216 /*store information from file header into finfo*/
217 for (i = 0; i <= (MAXFSPEC-2); ++i)
218 finfo->fname[i] = fheadnew->fname[i];
219 finfo->fname[MAXFSPEC-1] = NULLC;
220 finfo->fflag = fheadnew->flag;
221 finfo->dnum = fheadnew->fsequenc;
222 finfo->ftime = fheadnew->ftime;
223 finfo->fdate = fheadnew->fdate;
224 finfo->attrib = fheadnew->attrib;
225 finfo->partsize = fheadnew->partsize;
226 finfo->offset = fheadnew->offset;
228 if ((fheadnew->flag & EXT_ATTR_FLAG) == EXT_ATTR_FLAG) /*;AN000;3*/
229 finfo->ea_offset = fheadnew->FH_EA_offset; /*;AN000;3*/
236 if (dirblk->nextdb == LAST_DIRBLOCK)
237 *done_searching = TRUE;
240 read_in_next_dirblock(); /* !wrw */
241 read_in_a_fileheader(); /* !wrw */
242 *numentry = dirblk->numentry;
246 read_in_a_fileheader(); /* !wrw */
248 *dirptr=(WORD far *)dirblk;
249 *flptr=(WORD far *)fheadnew;
252 } /*end of if found */
256 return(TRUE); /*;AN000;*/
257 } /*end of subroutine */
260 /***************** START OF SPECIFICATION ********************************
262 /* SUBROUTINE NAME : findnext_new
264 /* DESCRIPTIVE NAME : For new format only, continue at the point
265 /* findfirst_new or previous findnext_new exit, search
266 /* the entire file of CONTROL.xxx to find matching file
269 /* FUNCTION: Continue at where findfirst_new or previous findnext_new
270 /* stop, search the current directory blocks for the matching
271 /* file path, if fail to find a file, then call findfile to
272 /* search all directory block.
275 /********************** END OF SPECIFICATIONS *******************************/
276 int findnext_new(finfo, found, done_searching, in_path,
277 infspec, dirptr, flptr, numentry, dir_path)
279 struct file_info *finfo;
281 unsigned int *done_searching;
286 unsigned int *numentry;
289 struct dir_block far *dirblk;
292 BYTE temp_fname[MAXFSPEC];
294 char temp_path[MAXPATH];
296 dirblk=(struct dir_block far *)*dirptr;
297 fheadnew=(struct file_header_new far *)*flptr;
298 strcpy(dir_path,"no path from fnext");
301 for (i = 0; i <= (MAXPATH-2); ++i)
302 temp_path[i+1] = dirblk->path[i];
304 temp_path[MAXPATH-1] = NULLC;
306 /****************************************/
307 /* Should we process this subdirectory ?*/
308 /****************************************/
309 if (pathmatch(in_path,temp_path) == TRUE)
312 /*************************************************/
313 /*complete the scanning current db to find a file*/
314 /*************************************************/
317 if ((rc = fheadnew->flag & COMPLETE_BIT) != COMPLETE_BIT)
324 if (dirblk->nextdb == LAST_DIRBLOCK)
327 *done_searching = TRUE;
332 read_in_next_dirblock(); /* !wrw */
336 else /* There are more files from current dirblock. Get them */
338 read_in_a_fileheader(); /* !wrw */
344 /* If this file header is the right one)*/
345 for (i = 0; i <= (MAXFSPEC-2); ++i)
346 temp_fname[i] = fheadnew->fname[i];
348 temp_fname[MAXFSPEC-1] = NULLC;
350 if (fspecmatch(infspec,temp_fname)==TRUE)
353 for (i = 0; i <= (MAXPATH-2); ++i)
354 dir_path[i] = dirblk->path[i];
357 else /*if this file header is not the right one*/
361 if (*numentry == 0) /* If no more files in this directory block */
363 if (dirblk->nextdb == LAST_DIRBLOCK) /* If this is the last dirblock on current source disk */
366 *done_searching = TRUE;
371 read_in_next_dirblock(); /* !wrw */
373 } /*end of if not last dir block */ /* !wrw */
376 read_in_a_fileheader(); /* !wrw */
378 } /*end loop searching all file headers in dir block */
379 } /*end of if the path match inpath*/
385 /********************************************************************/
386 /* If fail to find a file in the current directory block, call */
387 /* filefind_new to find next. */
388 /* If already found or done searching, call findfile_new to store */
389 /* information in finfo and dinfo */
390 /********************************************************************/
392 *dirptr=(WORD far *)dirblk;
393 *flptr=(WORD far *)fheadnew;
395 retcode = findfile_new(finfo,found,done_searching,in_path,infspec,dirptr,
396 flptr,numentry, dir_path);
402 /***************** START OF SPECIFICATION ********************************
404 /* SUBROUTINE NAME : findfirst_new
406 /* DESCRIPTIVE NAME : For new format only, search the entire file
407 /* of CONTROL.xxx to find matching file names.
409 /* FUNCTION: search directory blocks one after the other to find the
410 /* directory block with the matching file path, then search
411 /* the entire directory block to find the file with matching
415 /********************** END OF SPECIFICATIONS *******************************/
416 int findfirst_new(finfo,found,done_searching,in_path,infspec,dirptr,flptr,numentry,dir_path)
418 struct file_info *finfo;
420 unsigned int *done_searching;
425 unsigned int *numentry;
428 struct dir_block far *dirblk;
431 strcpy(dir_path,"no path from fnext");
432 dirblk = (struct dir_block far *)&russ_dir_block; /* !wrw */
433 read_in_first_dirblock(); /* !wrw */
435 if (got_first_fh == FALSE) /* !wrw */
436 read_in_a_fileheader(); /*### /* !wrw */
439 *done_searching = FALSE;
440 *dirptr=(WORD far *)dirblk;
441 *flptr=(WORD far *)fheadnew;
443 retcode = findfile_new(finfo,found,done_searching,in_path,
444 infspec,dirptr,flptr,numentry,dir_path);
447 } /*end of findfirst_new */
453 /*********************************************************************/
455 /* SUBROUTINE NAME: read_in_next_dirblock
458 /* Reads in a directory block
459 /* Figures out if it was put there by DOS 3.3 or 4.0
460 /*********************************************************************/
461 void read_in_next_dirblock() /* !wrw */
464 WORD retcode; /* return code save area */ /* !wrw */
465 WORD read_count; /* num bytes read in */ /* !wrw */
466 DWORD file_pointer; /* current file pointer, returned by lseek !wrw */
469 DOSCHGFILEPTR /* !wrw */
471 control_file_handle, /* Handle */ /* !wrw */
472 russ_dir_block.nextdb, /* New location */ /* !wrw */
473 (BYTE)0, /* MOVE METHOD */ /* !wrw */
474 (DWORD far *)&file_pointer /* !wrw */
480 control_file_handle, /* !wrw */
481 (char far *)&russ_dir_block, /* !wrw */
482 (unsigned short)DIRBLKLEN, /* !wrw */
483 (unsigned far *)&read_count /* !wrw */
486 if (retcode != NOERROR) /* !wrw */
488 display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
489 unexperror(NOBACKUPFILE); /* !wrw */
492 got_first_fh = FALSE; /* !wrw */
493 get_fileheader_length(); /*;AN000;3*/
499 /*********************************************************************/
501 /* SUBROUTINE NAME: read_in_first_dirblock
504 /* Reads in the first directory block
505 /* Figures out if it was put there by DOS 3.3 or 4.0
506 /*********************************************************************/
508 void read_in_first_dirblock() /* !wrw */
511 WORD retcode; /* return code save area */ /* !wrw */
512 WORD read_count; /* num bytes read in */ /* !wrw */
514 /********************************************************************/
515 /* READ DIRECTORY_BLOCK INTO STATIC DATA AREA */
516 /********************************************************************/
518 retcode = DOSREAD( /* !wrw */
519 control_file_handle, /* !wrw */
520 (char far *)&russ_dir_block, /* !wrw */
521 (unsigned short)DIRBLKLEN, /* !wrw */
522 (unsigned far *)&read_count /* !wrw */
525 if (retcode != 0) /* !wrw */
527 display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
528 unexperror(NOBACKUPFILE); /* !wrw */
531 got_first_fh = FALSE; /* !wrw */
532 get_fileheader_length(); /*;AN000;3*/
534 return; /* end subroutine */ /* !wrw */
537 /**************************************************************/
539 /* SUBROUTINE: get_fileheader_length
541 /* FUNCTION: Gets the length of a file header
542 /* Sets BACKUP_LEVEL to indicate which
543 /**************************************************************/
544 void get_fileheader_length()
546 WORD retcode; /*;AN000;3*/
547 WORD read_count; /*;AN000;3*/
548 DWORD file_position; /*;AN000;3*/
550 /* Save current file pointer */
551 retcode = /*;AN000;3*/
552 DOSCHGFILEPTR /*;AN000;3*/
554 control_file_handle, /* Handle */ /*;AN000;3*/
555 (DWORD)0, /* New location *//*;AN000;3*/
556 (BYTE)1, /* MOVE METHOD *//*;AN000;3*/
557 (DWORD far *)&file_position /*;AN000;3*/
560 if (retcode != 0) /*;AN000;3*/
562 display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
563 unexperror(NOBACKUPFILE); /*;AN000;3*/
566 /* Read in file header length*/
567 retcode = /*;AN000;3*/
570 control_file_handle, /*;AN000;3*/
571 (char far *)&fileheader_length, /*;AN000;3*/
572 (unsigned short)2, /*;AN000;3*/
573 (unsigned far *)&read_count /*;AN000;3*/
576 if (retcode != 0 || read_count != 2) /*;AN000;3*/
578 display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
579 unexperror(NOBACKUPFILE); /*;AN000;3*/
582 /* Reset file pointer */
583 retcode = /*;AN000;3*/
584 DOSCHGFILEPTR /*;AN000;3*/
586 control_file_handle, /* Handle */ /*;AN000;3*/
587 file_position, /* New location *//*;AN000;3*/
588 (BYTE)0, /* MOVE METHOD *//*;AN000;3*/
589 (DWORD far *)&file_position /*;AN000;3*/
593 } /* end get_fileheader_length() */
597 /**************************************************************/
599 /* SUBROUTINE: read_in_a_fileheader
601 /* FUNCTION: Reads in a file header
603 /**************************************************************/
604 void read_in_a_fileheader() /* !wrw */
606 WORD retcode; /* return code save area */ /* !wrw */
607 WORD read_count; /* num bytes read in */ /* !wrw */
609 retcode = DOSREAD /* !wrw */
611 control_file_handle, /* !wrw */
612 (char far *)&russ_file_header, /* !wrw */
613 fileheader_length, /* !wrw */
614 (unsigned far *)&read_count /* !wrw */
617 if (retcode != NOERROR) /* !wrw */
619 display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
620 unexperror(NOBACKUPFILE); /* !wrw */
623 got_first_fh = TRUE; /* !wrw */
624 fheadnew = (struct file_header_new far *)&russ_file_header; /* !wrw */