summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/RESTORE/RTDO.C
diff options
context:
space:
mode:
Diffstat (limited to 'v4.0/src/CMD/RESTORE/RTDO.C')
-rw-r--r--v4.0/src/CMD/RESTORE/RTDO.C376
1 files changed, 376 insertions, 0 deletions
diff --git a/v4.0/src/CMD/RESTORE/RTDO.C b/v4.0/src/CMD/RESTORE/RTDO.C
new file mode 100644
index 0000000..bd736b5
--- /dev/null
+++ b/v4.0/src/CMD/RESTORE/RTDO.C
@@ -0,0 +1,376 @@
1
2/*------------------------------------
3/* SOURCE FILE NAME: RTDO.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 "direct.h"
12#include "stdio.h"
13#include "string.h"
14#include "dos.h" /*;AN000;2*/
15#include "comsub.h" /* common subroutine def'n */
16#include "doscalls.h"
17#include "error.h"
18
19BYTE *buf_pointer;
20unsigned control_file_pointer;
21unsigned src_file_handle;
22struct FileFindBuf filefindbuf;
23struct FileFindBuf dfilefindbuf;
24BYTE far *control_buf_pointer;
25unsigned int control_bufsize; /* !wrw */
26
27extern unsigned char srcddir[MAXPATH+3];
28extern unsigned char rtswitch;
29extern unsigned char control_flag;
30extern unsigned char control_flag2;
31extern unsigned control_file_handle; /* !wrw */
32extern struct subst_list sublist; /*;AN000;6 Message substitution list */
33
34/***************** START OF SPECIFICATION ********************************
35/*
36/* SUBROUTINE NAME : Dorestore
37/*
38/* DESCRIPTIVE NAME : Searching all disks and restore the matching files.
39/*
40/* FUNCTION: This routine does the following:
41/* 1. Initialize the buffer
42/* 2. Change directory to the one which will hold the first
43/* files to be restored.
44/* 3. If the source drive is removable
45/* Ouput the message to the screen for user to insert a
46/* diskette and hit a key when ready.
47/* 4. If the target drive is removable
48/* Ouput the message to the screen for user to insert a
49/* diskette and hit a key when ready.
50/* 5. Check whether the diskette contains old or new data
51/* format.
52/* 6. ouput "file were backup xx-xx-xx"
53/*
54/* For each diskette, do the following:
55/* 5. Call check_bkdisk_old or check_bkdisk_new to check whethe
56/* it is a backup diskette and whether it is in correct
57/* sequence number.
58/* 6. Call search_src_disk_old or search_src_disk_new to search
59/* the entire diskette to find matching files and
60/* restore them.
61/*
62/*
63/********************** END OF SPECIFICATIONS *******************************/
64void dorestore(srcd,destd,inpath,infname,infext,infspec,dt) /* wrw! */
65BYTE srcd;
66BYTE destd;
67BYTE *inpath;
68BYTE *infname;
69BYTE *infext;
70BYTE *infspec;
71struct timedate *dt;
72{
73 BYTE string[MAXPATH+2];
74 struct disk_header_old dheadold;
75 struct disk_header_new dheadnew;
76 struct file_header_new fheadnew;
77 struct disk_info dinfo;
78 struct file_info finfo;
79 unsigned int control_bufsize;
80 unsigned dirlen = MAXPATH;
81 WORD dyear;
82 WORD dmonth;
83 WORD dday;
84
85 BYTE c;
86 BYTE done; /*;AN000;p????*/
87 BYTE path_to_be_chdir[MAXPATH];
88 WORD srcd_num;
89 BYTE temp_srcddir[MAXPATH];
90 unsigned int dnumwant = 1;
91 DWORD bufsize;
92 BYTE temp_array1[4]; /*temparary array to build parameters for substitution list */
93 BYTE temp_array2[4];
94
95 /*declaration for dosfindfirst */
96 unsigned dirhandle = 1;
97 unsigned attribute = NOTV;
98 unsigned search_cnt = 1; /* # of entries to find */
99 unsigned buf_len = sizeof(struct FileFindBuf);
100 BYTE search_string[MAXPATHF+2];
101 WORD retcode;
102 /*end decleration for ffirst and fnext*/
103
104 union REGS qregs; /*;AN000;8*/
105 DWORD date; /*;AN000;6*/
106
107 /****************************************************************/
108 /* change dest drive directory to the one which will hold the */
109 /* first file to be restored */
110 /****************************************************************/
111 string[0] = destd;
112 string[1] = ':';
113 string[2] = NULLC;
114 strcat(string,inpath);
115 /*if chdir sucessful, save the directory in finfo->curdir*/
116 /*if fail, the path is not exist, and needs to be rebuild*/
117 if(chdir(string)==0)
118 strcpy(finfo.curdir,inpath);
119
120 /*****************************************************************/
121 /*if the source disk is hard disk get the current dir of the srcd*/
122 /* chdir the source disk to be in \backup directory */
123 /*****************************************************************/
124 /**************************************/
125 /* if the source disk is a hard disk */
126 /**************************************/
127 /* save current directory of source disk to be reset back later */
128 /* convert character srcd into integer form */
129 /**************************************/
130
131 srcd_num = (WORD)(srcd - 'A' +1);
132
133 /**************************************/
134 /* get current directory of srcd (DosQCurDir) */
135 /**************************************/
136 if ((retcode = DOSQCURDIR(srcd_num,(char far *) srcddir,(unsigned far *)&dirlen)) != 0)
137 {
138 display_it(INVALID_DRIVE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
139 usererror(INVALIDDRIVE);
140 }
141
142 temp_srcddir[0] = srcd;
143 temp_srcddir[1] = ':';
144 temp_srcddir[2] = NULLC;
145 if (strlen(srcddir) != 1)
146 strcat(temp_srcddir,"\\");
147 strcat(temp_srcddir,srcddir);
148 strcpy(srcddir,temp_srcddir);
149
150 path_to_be_chdir[0] = srcd;
151 path_to_be_chdir[1] = ':';
152 path_to_be_chdir[2] = NULLC;
153 if (set_reset_test_flag(&control_flag2,SRC_HDISK,TEST) == TRUE)
154 strcat(path_to_be_chdir,"\\BACKUP");
155 else
156 strcat(path_to_be_chdir,"\\");
157
158 if(chdir(path_to_be_chdir)!=0)
159 { display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
160 usererror(NOBACKUPFILE);
161 }
162
163 /*****************************************************************/
164 /* Identify whether the inserted diskette is a old format backup */
165 /* diskette or a new format backup diskette */
166 /* BACKUP.@@@ or BACKUP.xxx with xxx numeric characters has */
167 /* to be on the diskette */
168 /*****************************************************************/
169 search_string[0] = srcd;
170 search_string[1] = ':';
171 search_string[2] = NULLC;
172 strcat(search_string, "BACKUP*.???");
173
174 /***********************/
175 /* Find the first file */
176 /***********************/
177 done = FFALSE; /*;AN000;p????*/
178
179 retcode = /*;AN000;p????*/
180 DOSFINDFIRST /*;AN000;p????*/
181 ( /*;AN000;p????*/
182 (char far *)search_string, /*;AN000;p????*/
183 (unsigned far *)&dirhandle, /*;AN000;p????*/
184 attribute, /*;AN000;p????*/
185 (struct FileFindBuf far *)&filefindbuf, /*;AN000;p????*/
186 buf_len, /*;AN000;p????*/
187 (unsigned far *)&search_cnt, /*;AN000;p????*/
188 (DWORD) 0 /*;AN000;p????*/
189 ); /*;AN000;p????*/
190
191 if (retcode != NOERROR) /*;AN000;p????*/
192 { display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;p????*/
193 usererror(NOBACKUPFILE); /*;AN000;p????*/
194 } /*;AN000;p????*/
195
196 /*****************************/
197 /* Skip over subdirectories */
198 while((retcode = filefindbuf.attributes & SUBDIR) == SUBDIR) /*;AN000;p????*/
199 { /*;AN000;p????*/
200 search_cnt = 1; /*;AN000;p????*/
201
202 retcode = /*;AN000;p????*/
203 DOSFINDNEXT /*;AN000;p????*/
204 ( dirhandle, /*;AN000;p????*/
205 (struct FileFindBuf far *)&filefindbuf, /*;AN000;p????*/
206 buf_len, /*;AN000;p????*/
207 (unsigned far *)&search_cnt /*;AN000;p????*/
208 ); /*;AN000;p????*/
209
210 if (retcode != NOERROR) /*;AN000;p????*/
211 { display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;p????*/
212 usererror(NOBACKUPFILE); /*;AN000;p????*/
213 } /*;AN000;p????*/
214 } /*;AN000;p????*/
215
216 /****************************************/
217 /* Loop through looking at file names */
218 /****************************************/
219 do /*;AN000;p????*/
220 { /* Is it old BACKUP ??? */ /*;AN000;p????*/
221 if (strcmp(filefindbuf.file_name,BACKUPID)==0) /*;AN000;p????*/
222 { /*;AN000;p????*/
223 set_reset_test_flag(&control_flag,OLDNEW,SET); /*;AN000;p????*/
224 done = TTRUE; /*;AN000;p????*/
225 } /*;AN000;p????*/
226 else /*;AN000;p????*/
227 { /* Is it new BACKUP ??? */ /*;AN000;p????*/
228 if ((filefindbuf.file_name[6] == '.') && /*;AN000;p????*/
229 (filefindbuf.file_name[7] >= '0') && /*;AN000;p????*/
230 (filefindbuf.file_name[7] <= '9') && /*;AN000;p????*/
231 (filefindbuf.file_name[8] >= '0') && /*;AN000;p????*/
232 (filefindbuf.file_name[8] <= '9') && /*;AN000;p????*/
233 (filefindbuf.file_name[9] >= '0') && /*;AN000;p????*/
234 (filefindbuf.file_name[9] <= '9') && /*;AN000;p????*/
235 (filefindbuf.file_name[10] == NULLC) ) /*;AN000;p????*/
236 { /*;AN000;p????*/
237 set_reset_test_flag(&control_flag,OLDNEW,RESET); /*;AN000;p????*/
238 init_control_buf((unsigned long)0,&control_bufsize);/*;AN000;p????*/
239 done = TTRUE; /*;AN000;p????*/
240 } /*;AN000;p????*/
241 }
242
243 if (!done)
244 do
245 { /*;AN000;p????*/
246 search_cnt = 1; /*;AN000;p????*/
247 retcode = /*;AN000;p????*/
248 DOSFINDNEXT /*;AN000;p????*/
249 ( dirhandle, /*;AN000;p????*/
250 (struct FileFindBuf far *)&filefindbuf, /*;AN000;p????*/
251 buf_len, /*;AN000;p????*/
252 (unsigned far *)&search_cnt /*;AN000;p????*/
253 ); /*;AN000;p????*/
254
255 if (retcode != NOERROR) /*;AN000;p????*/
256 { display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;p????*/
257 usererror(NOBACKUPFILE); /*;AN000;p????*/
258 } /*;AN000;p????*/
259
260 } /* end while */ /*;AN000;p????*/
261 while(filefindbuf.attributes & SUBDIR == SUBDIR);
262
263 } /* end DO loop */ /*;AN000;p????*/
264 while (!done); /*;AN000;p????*/
265
266
267 retcode = DOSFINDCLOSE(dirhandle);
268
269 /***************************************/
270 /* Display the date of the backup disk */
271 /***************************************/
272 dyear = (filefindbuf.write_date >> YRSHIFT & YRMASK) + LOYR;
273 dmonth = filefindbuf.write_date >> MOSHIFT & MOMASK;
274 dday = filefindbuf.write_date & DYMASK;
275 date = dyear + (dday*16777216) + (dmonth*65536); /*;AN000;6*/
276
277 sublist.value1 = (char far *)date; /*;AN000;6*/
278 sublist.flags1 = LEFT_ALIGN + DATE_MDY_4; /*;AN000;6*/
279 sublist.max_width1 = (BYTE)10; /*;AN000;6*/
280 sublist.min_width1 = sublist.max_width1; /*;AN000;6*/
281 display_it(FILES_WERE_BACKUP_ON,STND_OUT_DEV,1,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
282
283 /*****************************************************************/
284 /*start a loop to check and restore each diskette */
285 /*****************************************************************/
286 initbuf(&bufsize); /* !wrw */
287
288 for (;;)
289 {
290
291 /*****************************************************************/
292 /* check whether the inserted diskette is a backup diskette */
293 /*****************************************************************/
294 /*if old, check_bkdisk_old else check_bkdisk_new*/
295
296 if (set_reset_test_flag(&control_flag,OLDNEW,TEST) == TRUE)
297 check_bkdisk_old(&dheadold, &dinfo, srcd, &dnumwant);
298 else
299 check_bkdisk_new((struct disk_header_new far *)&dheadnew, &dinfo, srcd, &dnumwant,&control_bufsize);
300
301 /*****************************************************************/
302 /* At this point a real backup diskette which is in correct sequence number */
303 /* has been found. In the case of new format, the file CONTROL.xxx is open.*/
304 /*****************************************************************/
305 /* restored the diskette */
306 /*****************************************************************/
307
308 /*if old*/
309 if (set_reset_test_flag(&control_flag,OLDNEW,TEST) == TRUE)
310 search_src_disk_old(&dinfo,&finfo,&dheadold,(struct disk_header_new far *)&dheadnew,
311 (struct file_header_new far *)&fheadnew,srcd,destd,bufsize,&dnumwant,
312 inpath,infname,infext,infspec,dt);
313 else
314 search_src_disk_new(&dinfo,&finfo,&dheadold,(struct disk_header_new far *)&dheadnew,
315 (struct file_header_new far *)&fheadnew,srcd,destd,&dnumwant,bufsize,
316 inpath,infname,infspec,&control_bufsize,dt);
317
318 printf("\n");
319 set_reset_test_flag(&control_flag2,OUTOF_SEQ,RESET);
320 /************************************************************************/
321 /*if ( bk disk is not the last one && (the file spec is WILDCARD or file*/
322 /*not found yet or SUB flag in rtswitches is on)), then prompt for user */
323 /*to insert another diskette and loop again. */
324 /************************************************************************/
325 if ((dinfo.dflag!=0xff) &&
326 ((set_reset_test_flag(&control_flag,WILDCARD,TEST) == TRUE) ||
327 (set_reset_test_flag(&control_flag,FOUND,TEST) == FALSE) ||
328 (set_reset_test_flag(&rtswitch,SUB,TEST) == TRUE)))
329 {
330 /**********************************************************/
331 /* output message for user to insert another diskette and */
332 /* "strike any key when ready" */
333 /* with response type 4 (wait for a key to be hit) */
334 /**********************************************************/
335
336 if (control_file_handle != 0xffff) /* !wrw */
337 { /* !wrw */
338 DOSCLOSE(control_file_handle); /* !wrw */
339 control_file_handle = 0xffff; /* !wrw */
340 } /* !wrw */
341
342 temp_array1[0] = (char)((dnumwant / 10) + '0');
343 temp_array1[1] = (char)((dnumwant % 10) + '0');
344 temp_array1[2] = NULLC;
345 temp_array2[0] = srcd;
346 temp_array2[1] = NULLC;
347
348 sublist.value1 = (char far *)temp_array1; /*;AN000;6 */
349 sublist.flags1 = LEFT_ALIGN + CHAR_FIELD_ASCIIZ; /*;AN000;6 */
350 sublist.max_width1 = (BYTE)strlen(temp_array1); /*;AN000;6 */
351 sublist.min_width1 = sublist.max_width1; /*;AN000;6 */
352
353 sublist.value2 = (char far *)temp_array2; /*;AN000;6 */
354 sublist.flags2 = LEFT_ALIGN + CHAR_FIELD_ASCIIZ; /*;AN000;6 */
355 sublist.max_width2 = (BYTE)strlen(temp_array2); /*;AN000;6 */
356 sublist.min_width2 = sublist.max_width2; /*;AN000;6 */
357
358 display_it(INSERT_SOURCE_DISK,STND_ERR_DEV,2,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
359 display_it(PRESS_ANY_KEY,STND_ERR_DEV,0,ANY_KEY_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
360
361 /* If single drive system, eliminates double prompting */
362 /* for user to "Insert diskette for drive %1" */
363 qregs.x.ax = SETLOGICALDRIVE; /*;AN000;8*/
364 qregs.h.bl = srcddir[0] - 'A' + 1; /*;AN000;8*/
365 intdos(&qregs,&qregs); /*;AN000;8*/
366
367 continue;
368 }
369 else
370 break;
371
372 } /*end of for loop*/
373
374
375 return;
376} /*;AN000;*/