summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/RESTORE/RTFILE.C
diff options
context:
space:
mode:
Diffstat (limited to 'v4.0/src/CMD/RESTORE/RTFILE.C')
-rw-r--r--v4.0/src/CMD/RESTORE/RTFILE.C598
1 files changed, 598 insertions, 0 deletions
diff --git a/v4.0/src/CMD/RESTORE/RTFILE.C b/v4.0/src/CMD/RESTORE/RTFILE.C
new file mode 100644
index 0000000..d853f52
--- /dev/null
+++ b/v4.0/src/CMD/RESTORE/RTFILE.C
@@ -0,0 +1,598 @@
1
2/*----------------------------
3/* SOURCE FILE NAME: rtfile.c
4/*----------------------------
5/*  0 */
6
7#include "rt.h"
8#include "rt1.h"
9#include "rt2.h"
10#include "restpars.h" /*;AN000;4*/
11#include "string.h"
12#include "stdio.h"
13#include "dos.h" /*;AN000;2*/
14#include "comsub.h" /* common subroutine def'n */
15#include "doscalls.h"
16#include "error.h"
17
18extern BYTE rtswitch;
19extern BYTE control_flag;
20extern BYTE control_flag2;
21extern BYTE filename[12];
22extern BYTE far *buf_pointer;
23extern char far *control_buf_pointer;
24extern unsigned int done_searching; /* !wrw */
25extern unsigned int numentry;
26
27unsigned dest_file_handle;
28extern unsigned src_file_handle;
29extern unsigned control_file_handle; /* !wrw */
30BYTE dest_file_spec[MAXFSPEC+3];
31extern struct FileFindBuf filefindbuf;
32extern BYTE src_fname[MAXFNAME];
33extern struct subst_list sublist; /*;AN000;6 Message substitution list */
34
35/***************** START OF SPECIFICATION *********************************/
36/* */
37/* SUBROUTINE NAME : restore_a_file */
38/* */
39/* DESCRIPTIVE NAME : restore a file found onto the destination disk. */
40/* */
41/* FUNCTION: This subroutine call open_dest_file to open the destination */
42/* file under the proper path. If the path is not found, build */
43/* the path. */
44/* It then enter a loop to do reading the source disk and */
45/* writing the destination disk until end of file. If the file */
46/* is so large that it is backed up on more than one disk, */
47/* the user is prompt to insert next diskette. In this */
48/* situation, the disk is checked for correct sequence number, */
49/* and then searched for the file to be continue restoring. */
50/* after the file is completely restored, the time, date, and */
51/* attributes of the restored file is set to be the same as */
52/* its original value. */
53/* */
54/********************** END OF SPECIFICATIONS *******************************/
55
56void restore_a_file(finfo,dinfo,bufsize,control_bufsize, /* wrw! */
57 fheadnew,dheadold,dheadnew,
58 srcd,destd,inpath,infname,infspec,dnumwant,dirhandle)
59
60 struct file_info *finfo;
61 struct disk_info *dinfo;
62 unsigned long bufsize;
63 unsigned int *control_bufsize;
64 struct file_header_new far *fheadnew;
65 struct disk_header_old *dheadold;
66 struct disk_header_new far *dheadnew;
67 BYTE srcd;
68 BYTE destd;
69 unsigned char *inpath;
70 unsigned char *infname;
71 unsigned char *infspec;
72 unsigned int *dnumwant;
73 unsigned int *dirhandle;
74{
75 BYTE c;
76 BYTE temp_array1[4];
77 BYTE temp_array2[4];
78 BYTE temp_fname[MAXFSPEC];
79 WORD action;
80 WORD first_time=TRUE;
81
82 /*declaration for dosfindfirst */
83 WORD temp_dirhandle;
84 WORD next_dirhandle;
85 unsigned attribute = NOTV; /* */
86 unsigned search_cnt = 1; /* # of entries to find */
87 unsigned buf_len = sizeof(struct FileFindBuf);
88 BYTE search_string[MAXPATHF+2];
89 /*end decleration for ffirst and fnext*/
90
91 BYTE outstring[MAXPATHF+2];
92 WORD retcode;
93 DWORD iterate_num;
94 DWORD i; /* wrw! */
95 WORD numread;
96 WORD numwrite;
97 DWORD int remainder;
98 DWORD part_size;
99 WORD file_seq_num = 1; /*when this routine is called, the first
100 part of the file already get check against the
101 file sequence number */
102 BYTE file_tobe_opened[MAXFSPEC+2];
103 WORD found = FALSE;
104 WORD *dirptr;
105 WORD *flptr;
106 WORD read_count;
107 DWORD newptr;
108 WORD next_file_pointer;
109 unsigned int dnum;
110 DWORD temp_offset;
111
112 BYTE my_own_dirpath[MAXPATH];
113 int x; /*;AN000;8*/
114 union REGS qregs; /*;AN000;8*/
115
116 /*build a string of destination file specification*/
117 dest_file_spec[0] = destd;
118 dest_file_spec[1] = ':';
119 dest_file_spec[2] = NULLC;
120 strcat(dest_file_spec,finfo->fname);
121
122 /*********************************************************************/
123 /* Open destination file, and chdir the the path where the dest file */
124 /* going to reside. If the path is not there, then create the path. */
125 /* If file sharing error, exit this routine */
126 /*********************************************************************/
127 /*open_dest_file*/
128 retcode=open_dest_file(finfo,destd);
129
130 /*if file sharring error, exit this subroutine*/
131 if (retcode == FALSE)
132 display_it(FILE_CREATION_ERROR,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
133 else
134 {
135 /*setflag PARTIAL*/
136 set_reset_test_flag(&control_flag,PARTIAL,SET);
137
138 /*********************************************************************/
139 /* This loop will be processed once for each part of the source file */
140 /*********************************************************************/
141 for ( ; ; )
142 {
143
144 /*********************************************************************/
145 /* compare source file size and buf size to determine the */
146 /* iteration of reading and writing */
147 /*********************************************************************/
148 part_size = finfo->partsize;
149 /*if old*/
150 if (set_reset_test_flag(&control_flag,OLDNEW,TEST)==TRUE)
151 part_size = part_size - HEADLEN;
152
153 iterate_num = part_size / bufsize;
154 /*if remain of of filesize/bufsize != 0, add 1 to iterate_num*/
155 remainder = part_size % bufsize;
156 if (remainder > 0)
157 ++iterate_num;
158
159 /*********************************************************************/
160 /*loop through each of the iteration */
161 /*********************************************************************/
162 for (i = 1; i <= iterate_num; ++i)
163 {
164 /***************************************************************/
165 /* if old format, read from the beginning of the source file */
166 /***************************************************************/
167 /*read source file (new and old have different pointer)*/
168 if (set_reset_test_flag(&control_flag,OLDNEW,TEST) == TRUE)
169 {
170 retcode = DOSREAD( src_file_handle,
171 (char far *)&buf_pointer[0],
172 (unsigned)bufsize,
173 (unsigned far *)&numread);
174
175 if (retcode != 0)
176 {
177 com_msg(retcode);
178 unexperror(retcode);
179 }
180 }
181 else
182 { /*new format*/
183 /***************************************************************/
184 /* if new format, search backup.xxx for the file to be restored*/
185 /* and read it. */
186 /***************************************************************/
187 temp_offset = finfo->offset + bufsize * (i - 1);
188 retcode =
189 DOSCHGFILEPTR
190 (src_file_handle,
191 (DWORD) temp_offset,
192 (unsigned) 0,
193 (DWORD far *) &newptr
194 );
195
196 if (i == iterate_num)
197 {
198 part_size = part_size - bufsize * (iterate_num -1);
199 retcode =
200 DOSREAD
201 ( src_file_handle,
202 (char far *)&buf_pointer[0],
203 (unsigned)part_size,
204 (unsigned far *)&numread
205 );
206 }
207 else
208 {
209 retcode =
210 DOSREAD
211 (src_file_handle,
212 (char far *)&buf_pointer[0],
213 (unsigned)bufsize,
214 (unsigned far *)&numread
215 );
216
217 } /*end of i == iterate_num */
218 } /*end of new format */
219
220 /*************************************************************/
221 /* write to dest file */
222 /*************************************************************/
223 retcode =
224 DOSWRITE
225 (dest_file_handle,
226 (char far *)&buf_pointer[0],
227 (unsigned) numread,
228 (unsigned far *) &numwrite
229 );
230
231 /*************************************************************/
232 /*if the num of bytes read != num of bytes write */
233 /* call dos_write_error to find out why */
234 /*************************************************************/
235 if (numread != numwrite)
236 dos_write_error(bufsize,destd);
237 }
238 /*end iteration loop*/
239
240 /*****************************************************************/
241 /*if the file is system file, turn RTSYSTEM on */
242 /*****************************************************************/
243 if (strcmp(finfo->fname,"IBMBIO.COM")==0 ||
244 strcmp(finfo->fname,"IBMDOS.COM")==0 ||
245 strcmp(finfo->fname,"COMMAND.COM")==0 )
246 set_reset_test_flag(&control_flag2,RTSYSTEM,SET);
247
248
249 /*****************************************************************/
250 /*if the source file header indicate that this is the last disk, */
251 /* that is,it is completely copied, then exit the for loop */
252 /*****************************************************************/
253 if (set_reset_test_flag(&finfo->fflag,LAST_PART,TEST) == TRUE)
254 break; /* exit the loop */
255
256 /*****************************************************************/
257 /*The logic flow come here when the file expanded into next disk.*/
258 /* if old format, close the file handle and find handle */
259 /* if new format, close src file */
260 /*****************************************************************/
261 if (set_reset_test_flag(&control_flag,OLDNEW,TEST) == TRUE)
262 { /*close source file*/
263 DOSCLOSE(src_file_handle);
264
265 if (first_time == TRUE)
266 { temp_dirhandle = *dirhandle;
267 first_time = FALSE;
268 retcode = DOSFINDCLOSE(temp_dirhandle);
269 }
270 }
271 else
272 {
273 DOSCLOSE(src_file_handle);
274 DOSCLOSE(control_file_handle); /* !wrw */
275 control_file_handle = 0xffff; /* !wrw */
276 }
277
278 /*****************************************************************/
279 /* output message for user to insert another diskette */
280 /* "strike any key when ready" */
281 /* with response type 4 (wait for a key to be hit) */
282 /*****************************************************************/
283
284 if (control_file_handle != 0xffff) /* !wrw */
285 { /* !wrw */
286 DOSCLOSE(control_file_handle); /* !wrw */
287 control_file_handle = 0xffff; /* !wrw */
288 } /* !wrw */
289
290 printf("\n");
291 temp_array1[0] = (char) (*dnumwant / 10) + '0';
292 temp_array1[1] = (char) (*dnumwant % 10) + '0';
293 temp_array1[2] = NULLC;
294 temp_array2[0] = srcd;
295 temp_array2[1] = NULLC;
296
297 sublist.value1 = (char far *)temp_array1; /*;AN000;6 */
298 sublist.flags1 = LEFT_ALIGN + CHAR_FIELD_ASCIIZ; /*;AN000;6 */
299 sublist.max_width1 = (BYTE)strlen(temp_array1); /*;AN000;6 */
300 sublist.min_width1 = sublist.max_width1; /*;AN000;6 */
301
302 sublist.value2 = (char far *)temp_array2; /*;AN000;6 */
303 sublist.flags2 = LEFT_ALIGN + CHAR_FIELD_ASCIIZ; /*;AN000;6 */
304 sublist.max_width2 = (BYTE)strlen(temp_array2); /*;AN000;6 */
305 sublist.min_width2 = sublist.max_width2; /*;AN000;6 */
306
307 display_it(INSERT_SOURCE_DISK,STND_ERR_DEV,2,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
308 display_it(PRESS_ANY_KEY,STND_ERR_DEV,0,ANY_KEY_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
309
310 /* If single drive system, eliminates double prompting */
311 /* for user to "Insert diskette for drive %1" */
312 qregs.x.ax = SETLOGICALDRIVE; /*;AN000;8*/
313 qregs.h.bl = srcd; /*;AN000;8*/
314 intdos(&qregs,&qregs); /*;AN000;8*/
315
316 /**************************************************/
317 /**************************************************/
318 if (set_reset_test_flag(&control_flag,OLDNEW,TEST) == TRUE)
319 check_bkdisk_old(dheadold,dinfo,srcd,dnumwant);
320 else
321 check_bkdisk_new(dheadnew,dinfo,srcd,dnumwant,control_bufsize);
322
323 /*at this point a real backup diskette which is in correct sequence
324 number has been found. In the case of new format, the file
325 CONTROL.xxx is opened.*/
326
327 /*****************************************************************/
328 /*increament file sequence number */
329 /*****************************************************************/
330 file_seq_num = file_seq_num + 1;
331
332 /*****************************************************************/
333 /* search the new disk for next part of the file */
334 /*****************************************************************/
335 if (set_reset_test_flag(&control_flag,OLDNEW,TEST) == TRUE)
336 { /**************************************************************/
337 /* if old format, */
338 /*DosFindFirst:find the first file on the diskette (non-vol id*/
339 /*entry) */
340 /**************************************************************/
341 search_string[0] = srcd;
342 search_string[1] = ':';
343 search_string[2] = NULLC;
344 strcat(search_string, src_fname);
345
346 next_dirhandle = 0xffff; /* directory handle */
347
348 retcode = /* Find the 1st filename that */
349 DOSFINDFIRST( /* matches specified file spec*/
350 (char far * ) search_string, /* File path name */
351 (unsigned far * ) &next_dirhandle, /* Directory search */
352 attribute, /* Search attribute */
353 (struct FileFindBuf far *) &filefindbuf,
354 buf_len, /* Result buffer length */
355 (unsigned far * ) &search_cnt, /* Number of entries to find*/
356 (DWORD) 0
357 );
358
359 if (retcode != 0)
360 {
361 display_it(NOT_ABLE_TO_RESTORE_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
362 unexperror(retcode);
363 }
364
365
366 /*if the directory found is a subdirectory, find next one*/
367 while((retcode = filefindbuf.attributes & SUBDIR) == SUBDIR)
368 {
369 search_cnt = 1;
370 retcode = DOSFINDNEXT(next_dirhandle,
371 (struct FileFindBuf far *)&filefindbuf,
372 buf_len,
373 (unsigned far *)&search_cnt);
374
375 if (retcode != 0)
376 {
377 display_it(NOT_ABLE_TO_RESTORE_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
378 unexperror(retcode);
379 }
380
381 } /*end while */
382
383 retcode = DOSFINDCLOSE(next_dirhandle);
384
385 /*****************************************************************/
386 /* check_flheader_old: open and read file header, check dnum */
387 /* of the file, and fill fheadold and finfo with correct info*/
388 /*****************************************************************/
389 strcpy(temp_fname,filefindbuf.file_name);
390 retcode =
391 check_flheader_old
392 ( finfo, temp_fname,
393 filefindbuf.write_date, filefindbuf.write_time,
394 filefindbuf.attributes, filefindbuf.file_size,
395 file_seq_num, srcd, destd, infspec, inpath, dnumwant
396 );
397
398 if (retcode != 0)
399 {
400 display_it(NOT_ABLE_TO_RESTORE_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
401 unexperror(retcode);
402 }
403
404 /*****************************************************************/
405 /* check file sequence number. */
406 /*****************************************************************/
407 if (finfo->dnum != file_seq_num)
408 { display_it(FILE_SEQUENCE_ERROR,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
409 unexperror(FILESEQERROR);
410 }
411
412 }
413 else
414 { /*new format*/
415 /**********************************************/
416 /* Find the file on the CONTROL.xxx first */
417 /**********************************************/
418
419 /* findfirst_new on the new diskette using the filename.??? */
420 retcode =
421 findfirst_new
422 ( finfo, &found, &done_searching,
423 finfo->path, finfo->fname, (WORD far **) &dirptr, /* wrw! */
424 (WORD far **) &flptr, &numentry, my_own_dirpath
425 ); /* wrw! */
426
427 while (retcode != 0 )
428 {
429 display_it(NOT_ABLE_TO_RESTORE_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
430 unexperror(CREATIONERROR);
431 }
432
433 if (finfo->dnum != file_seq_num)
434 { display_it(FILE_SEQUENCE_ERROR,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
435 unexperror(FILESEQERROR);
436 }
437
438 /**************************************************************/
439 /* open file backup.xxx */
440 /**************************************************************/
441 /*the current disk is one less than the disk num wanted*/
442 dnum = *dnumwant -1;
443 /*make the file name to be opened*/
444 file_tobe_opened[0] = srcd;
445 file_tobe_opened[1] = ':';
446 file_tobe_opened[2] = NULLC;
447 strcat(file_tobe_opened,"BACKUP.");
448 file_tobe_opened[9] = (char)((dnum / 100) + '0');
449 dnum = dnum % 100;
450 file_tobe_opened[10] = (char)((dnum / 10) + '0');
451 dnum = dnum % 10;
452 file_tobe_opened[11] = (char)(dnum + '0');
453 file_tobe_opened[12] = NULLC;
454
455 retcode =
456 DOSOPEN
457 ( (char far *)&file_tobe_opened[0],
458 (unsigned far *)&src_file_handle,
459 (unsigned far *)&action,
460 (DWORD)0, /*file size*/
461 0, /*file attribute*/
462 0x01, /*if file exist, open it*/
463 /*if file not exist, fail it*/
464 0x00c0, /*deny write, read only*/
465 (DWORD)0
466 ); /*reserved*/
467
468 if (retcode != 0)
469 { display_it(NOT_ABLE_TO_RESTORE_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
470 unexperror(retcode);
471 }
472
473 }
474 /*end of if new format*/
475
476 /*assume the file to be continue definatly will be found on the
477 second diskette because the dnum of the file already gets checked
478 in check_bkdisk_old or check_bkdisk_new*/
479
480 /*set flag to be SPLITFILE*/
481 set_reset_test_flag(&control_flag,SPLITFILE,SET);
482
483 /*******************************************/
484 /* Display name of file is to be restored */
485 /*******************************************/
486 /*outstring = inpath\infspec*/
487 strcpy(outstring,finfo->path);
488 if (strlen(finfo->path) != 1 )
489 strcat(outstring,"\\");
490
491 strcat(outstring,finfo->fname);
492 x = strlen(outstring);
493 outstring[x] = CR; /*;AN000;6*/
494 outstring[x+1] = LF; /*;AN000;6*/
495 outstring[x+2] = NUL; /*;AN000;6*/
496 qregs.x.ax = 0x4000; /*;AN000;6*/
497 qregs.x.bx = 0x0001; /*;AN000;6*/
498 qregs.x.cx = (WORD)strlen(outstring); /*;AN000;6*/
499 qregs.x.dx = (unsigned int)&outstring[0]; /*;AN000;6*/
500 intdos(&qregs,&qregs); /*;AN000;6*/
501
502 /*loop back to do the read source and write dest until finfo->fflag
503 indicate that this is the last part of file*/
504 } /*end of for loop*/
505
506 /************************************************************************/
507 /*set_attributes_and_close: set the attributes and last write date/time */
508 /*of the file just restore to be like those of the backup file */
509 /************************************************************************/
510 set_attributes_and_close(finfo,destd);
511
512 /************************************************************************/
513 /* If old format and the file split, then find next matching file */
514 /************************************************************************/
515 if (set_reset_test_flag(&control_flag,SPLITFILE,TEST)==TRUE &&
516 set_reset_test_flag(&control_flag,OLDNEW,TEST) == TRUE)
517 {
518 /*search string used for DisFindFirst = srcd:infname.**/
519 /*DosFindFirst:find the first file on the diskette (non-vol id entry)
520 using the search string*/
521 search_string[0] = srcd;
522 search_string[1] = ':';
523 search_string[2] = NULLC;
524 strcat(search_string, infname);
525 strcat(search_string, ".*");
526
527 temp_dirhandle = 0xffff;
528 retcode = /* Find the 1st filename that */
529 DOSFINDFIRST( /* matches specified file spec*/
530 ( char far * ) search_string, /* File path name */
531 ( unsigned far * ) &temp_dirhandle, /* Directory search handle*/
532 (unsigned) NOTV, /* Search attribute */
533 (struct FileFindBuf far *) &filefindbuf,
534 buf_len, /* Result buffer length */
535 ( unsigned far * ) &search_cnt, /* Number of entries to find */
536 ( DWORD) 0
537 );
538
539 /*if not found return*/
540 if (retcode != 0)
541 temp_dirhandle = 0xffff;
542 else
543 {
544
545 /*if the directory found is a subdirectory, find next one*/
546 while((retcode = filefindbuf.attributes & SUBDIR) == SUBDIR)
547 {
548 search_cnt = 1;
549 retcode = DOSFINDNEXT(temp_dirhandle,
550 (struct FileFindBuf far *)&filefindbuf,
551 buf_len,
552 (unsigned far *)&search_cnt);
553 if (retcode != 0)
554 temp_dirhandle = 0xffff;
555 } /*end while */
556
557 if(strcmp(filefindbuf.file_name,BACKUPID)==0 ||
558 strcmp(filefindbuf.file_name,src_fname)==0 )
559 {
560 retcode =DOSFINDNEXT(temp_dirhandle,
561 (struct FileFindBuf far *)&filefindbuf,
562 buf_len,
563 (unsigned far *)&search_cnt);
564
565 if (retcode != 0)
566 temp_dirhandle = 0xffff;
567
568 else
569 {
570 if(strcmp(filefindbuf.file_name,BACKUPID)==0 ||
571 strcmp(filefindbuf.file_name,src_fname)==0 )
572 {
573 retcode =DOSFINDNEXT(temp_dirhandle,
574 (struct FileFindBuf far *)&filefindbuf,
575 buf_len,
576 (unsigned far *)&search_cnt);
577
578 if (retcode != 0)
579 temp_dirhandle = 0xffff;
580 }
581
582 } /*end of the rc is 0 */
583 } /*end of if strcomp is sucessful*/
584
585 }
586 *dirhandle = temp_dirhandle;
587
588 } /*end of if the file was splitted */
589
590
591 /****************************************************************/
592 /*set FOUNDFILE flag */
593 /****************************************************************/
594 set_reset_test_flag(&control_flag,FOUND,SET);
595 } /* end of if open destination file get file sharing error */
596
597} /*end of restore_a_file subroutine*/
598 \ No newline at end of file