summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/RESTORE/RTDO1.C
diff options
context:
space:
mode:
Diffstat (limited to 'v4.0/src/CMD/RESTORE/RTDO1.C')
-rw-r--r--v4.0/src/CMD/RESTORE/RTDO1.C420
1 files changed, 420 insertions, 0 deletions
diff --git a/v4.0/src/CMD/RESTORE/RTDO1.C b/v4.0/src/CMD/RESTORE/RTDO1.C
new file mode 100644
index 0000000..29bc973
--- /dev/null
+++ b/v4.0/src/CMD/RESTORE/RTDO1.C
@@ -0,0 +1,420 @@
1
2/*-----------------------------
3/* SOURCE FILE NAME: RTDO1.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 "dos.h" /*;AN000;2*/
13#include "comsub.h" /* common subroutine def'n */
14#include "doscalls.h"
15#include "error.h"
16
17struct disk_header_new russ_disk_header; /* !wrw */
18unsigned control_file_handle = 0xffff; /* !wrw */
19
20extern BYTE control_flag2;
21extern BYTE far *control_buf_pointer;
22extern unsigned control_selector;
23extern struct FileFindBuf filefindbuf;
24extern struct internat ctry; /* data area for get country info */
25extern struct subst_list sublist; /*;AN000;6 Message substitution list */
26/***************** START OF SPECIFICATION ********************************
27/*
28/* SUBROUTINE NAME : check_bkdisk_new
29/*
30/* DESCRIPTIVE NAME : For new format only, check to see whether the disk
31/* is a backup disk, and whether the disk is in right
32/* sequence.
33/*
34/* FUNCTION: The routine does the following:
35/* 1. Find the file CONTROL.xxx. If the file is not there
36/* the disk is not a backup disk.
37/* 2. validate the extension of control.xxx
38/* 3. Check the sequence number of the disk to make sure
39/* its in sequence.
40/* 4. Open the file CONTROL.xxx.
41/* 5. Read the file CONTROL.xxx in.
42/* 6. Fill dinfo with correct information.
43/* 7. Output a message to the screen to confirm that
44/* the disk is going to be restored.
45/*
46/* NOTES: This subroutine also take care of situation that user
47/* insert a old format diskette while the RESTORE started with
48/* new format diskettes.
49/*
50/* When the inserted disk does not contain the file CONTROL.xxx,
51/* a message "source file does not contains backup files" is
52/* output to the user. If the user wants to change diskette
53/* and try again, next diskette will be read.
54/*
55/* When disk is out of sequence, a 'warning' is given to user,
56/* if the user still wants to proceed the restoring by doing
57/* nothing but hit a key, the same diskette will be read again.
58/* In case of expanded file, another check for dnum of the expand
59/* file will guarantee the disk in sequence.
60/*
61/*
62/********************** END OF SPECIFICATIONS *******************************/
63void check_bkdisk_new(dheadnew, dinfo, srcd, dnumwant,control_bufsize) /* wrw! */
64
65struct disk_header_new far *dheadnew;
66struct disk_info *dinfo;
67BYTE srcd;
68unsigned int *dnumwant;
69unsigned int *control_bufsize;
70{
71 WORD dnumok = FALSE;
72 WORD disknum; /*disk number carried by the file name backup.xxx*/
73 BYTE fname_to_be_opened[13];
74 WORD numread;
75 BYTE temp_array1[4];
76 BYTE temp_array2[4];
77 BYTE c;
78 WORD read_count;
79 WORD action;
80
81
82 /*declaration for dosfindfirst */
83 unsigned dirhandle = 0xffff;
84 unsigned attribute = NOTV;
85 unsigned search_cnt = 1;
86 unsigned buf_len = sizeof(struct FileFindBuf);
87 BYTE search_string[MAXPATHF+2];
88 WORD retcode;
89 /*end decleration for ffirst and fnext*/
90 /*****************************/
91 /*search for control.xxx */
92 /*****************************/
93 for (;;)
94 {
95 /*DosFindFirst, using the filename CONTROL.???*/
96 search_string[0] = srcd;
97 search_string[1] = ':';
98 search_string[2] = NULLC;
99 strcat(search_string, "CONTROL.???");
100 dirhandle = 0xffff;
101 search_cnt = 1;
102
103 retcode = /* Find the 1st filename that */
104 DOSFINDFIRST( /* matches specified fspec*/
105 (char far *)search_string, /* File path name*/
106 (unsigned far *)&dirhandle, /* Directory search handle */
107 attribute, /* Search attribute */
108 (struct FileFindBuf far *)&filefindbuf,
109 buf_len, /* Result buffer length */
110 (unsigned far *)&search_cnt, /* Number of entries to find */
111 (DWORD) 0
112 );
113
114 if (retcode != NOERROR)
115 { display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
116 usererror(NOBACKUPFILE);
117 }
118 else
119 {
120 /*if the directory found is a subdirectory, find next one*/
121 while((retcode = filefindbuf.attributes & SUBDIR) == SUBDIR)
122 {
123 search_cnt = 1;
124 retcode = DOSFINDNEXT(dirhandle,
125 (struct FileFindBuf far *)&filefindbuf,
126 buf_len,
127 (unsigned far *)&search_cnt);
128 if (retcode != 0)
129 { display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
130 usererror(NOBACKUPFILE);
131 }
132 } /*end while */
133 } /*end of file control.xxx not found*/
134
135 retcode = DOSFINDCLOSE(dirhandle);
136
137 /********************************************************************/
138 /* validate the file extension of control.xxx to make sure they are */
139 /* three numeric characters */
140 /********************************************************************/
141 if ((filefindbuf.file_name[7] != '.') || (filefindbuf.file_name[8] < '0') ||
142 (filefindbuf.file_name[8] > '9') || (filefindbuf.file_name[9] < '0') ||
143 (filefindbuf.file_name[9] > '9') || (filefindbuf.file_name[10] < '0') ||
144 (filefindbuf.file_name[10] > '9') || (filefindbuf.file_name[11] != NULLC) )
145 { display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
146 usererror(NOBACKUPFILE);
147 }
148
149 /********************************************************************/
150 /* check the disk sequence number of the disk */
151 /********************************************************************/
152 if (dnumok == TRUE)
153 {
154 if (disknum != *dnumwant)
155 set_reset_test_flag(&control_flag2,OUTOF_SEQ,SET);
156 dnumok = FALSE;
157 }
158 else
159 {
160 disknum = (filefindbuf.file_name[8]-'0')*100 +
161 (filefindbuf.file_name[9]-'0')*10
162 +filefindbuf.file_name[10]-'0';
163 if (disknum != *dnumwant)
164 {
165 display_it(DISK_OUT_OF_SEQUENCE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
166 display_it(PRESS_ANY_KEY,STND_ERR_DEV,0,ANY_KEY_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
167
168 /* When disk is out of sequence, a 'warning' is given to user. */
169 /* If the user still wants to proceed the restoring by doing */
170 /* nothing but hit a key, the same diskette will be read again.*/
171 dnumok = TRUE;
172
173 continue;
174 } /*endif*/
175 } /*endif of dnumok = FALSE*/
176
177 /********************************************************************/
178 /* open control.xxx */
179 /********************************************************************/
180 fname_to_be_opened[0] = srcd;
181 fname_to_be_opened[1] = ':';
182 fname_to_be_opened[2] = NULLC;
183 strcat(fname_to_be_opened,filefindbuf.file_name);
184
185 retcode =
186 DOSOPEN
187 ( (char far *)&fname_to_be_opened[0],
188 (unsigned far *)&control_file_handle, /* !wrw */
189 (unsigned far *)&action,
190 (DWORD)0,
191 0,
192 0x01,
193 0x00c0,
194 (DWORD)0
195 );
196
197 if (retcode != NOERROR)
198 { display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
199 usererror(NOBACKUPFILE);
200 }
201
202 /********************************************************************/
203 /* READ DISK_HEADER INTO STATIC DISKHEADER STRUCTURE wrw */
204 /********************************************************************/
205
206 retcode =
207 DOSREAD
208 ( /* !wrw */
209 control_file_handle, /* !wrw */
210 (char far *)&russ_disk_header, /* !wrw */
211 (unsigned short)DHEADLEN, /* !wrw */
212 (unsigned far *)&read_count /* !wrw */
213 ); /* !wrw */
214
215 if (retcode != NOERROR || (DWORD)read_count != (DWORD)DHEADLEN) /* !wrw */
216 { display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
217 unexperror(NOBACKUPFILE);
218 }
219
220 /********************************************************************/
221 /* get and store dheadnew information into dinfo */
222 /********************************************************************/
223 dheadnew = (struct disk_header_new far *)&russ_disk_header; /* !wrw */
224
225 dinfo->disknum = dheadnew->sequence;
226 dinfo->dflag = dheadnew->lastdisk;
227
228 /* At this point, the diskette has passed all the checking, and */
229 /* should be a ok diskette. break out of the loop.*/
230 break;
231
232 } /*end of "for (;;)" loop */
233
234 /********************************************************************/
235 /* output confirm msg "restore file from drive d:" */
236 /********************************************************************/
237 temp_array1[0] = srcd;
238 temp_array1[1] = NULLC;
239
240 sublist.value1 = (char far *)temp_array1; /*;AN000;6 */
241 sublist.flags1 = LEFT_ALIGN + CHAR_FIELD_ASCIIZ; /*;AN000;6 */
242 sublist.max_width1 = (BYTE)strlen(temp_array1); /*;AN000;6 */
243 sublist.min_width1 = sublist.max_width1; /*;AN000;6 */
244
245 display_it(RESTORE_FILE_FROM_DRIVE,STND_OUT_DEV,1,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
246
247 /********************************************************************/
248 /* if the source disk is removable, output diskette number also */
249 /********************************************************************/
250 if (set_reset_test_flag(&control_flag2,SRC_HDISK,TEST) == FALSE)
251 {
252 temp_array2[0] = (dinfo->disknum / 10) + '0';
253 temp_array2[1] = (dinfo->disknum % 10) + '0';
254 temp_array2[2] = NULLC;
255
256 sublist.value1 = (char far *)temp_array2; /*;AN000;6*/
257 sublist.flags1 = LEFT_ALIGN + CHAR_FIELD_ASCIIZ; /*;AN000;6*/
258 sublist.max_width1 = (BYTE)strlen(temp_array2); /*;AN000;6*/
259 sublist.min_width1 = sublist.max_width1; /*;AN000;6*/
260
261 display_it(DISKETTE_NUM,STND_OUT_DEV,1,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
262 }
263
264 *dnumwant = dinfo->disknum + 1;
265
266 return; /*;AN000;*/
267} /*end of subroutine */
268
269/***************** START OF SPECIFICATION ********************************
270/*
271/* SUBROUTINE NAME : check_bkdisk_old
272/*
273/* DESCRIPTIVE NAME : For old format only, check to see whether the disk
274/* is a backup disk, and whether the disk is in right
275/* sequence.
276/*
277/* FUNCTION: The routine does the following:
278/* 1. Open the file BACKUPID.@@@. If the file is not there,
279/* the disk is not a backup disk.
280/* 3. Check the sequence number of the disk to make sure
281/* its in sequence.
282/* 4. Fill dinfo with correct information.
283/* 5. Output a message to the screen to confirm that
284/* the disk is going to be restored.
285/*
286/* NOTES: This subroutine also take care of situation that user
287/* insert a new format diskette while the RESTORE started with
288/* old format diskettes.
289/*
290/* When the inserted disk does not contain the file BACKUP.@@@,
291/* a message "source file does not contains backup files" is
292/* output to the user. If the user wants to change diskette
293/* and try again, next diskette will be read.
294/*
295/* When disk is out of sequence, a 'warning' is given to user,
296/* if the user still wants to proceed the restoring by doing
297/* nothing but hit a key, the same diskette will be read again.
298/* In case of expanded file, another check for dnum of the expand
299/* file will guarantee the disk in sequence.
300/*
301/*
302/********************** END OF SPECIFICATIONS *******************************/
303void check_bkdisk_old(dheadold, dinfo, srcd, dnumwant) /* wrw! */
304 struct disk_header_old *dheadold;
305 struct disk_info *dinfo;
306 BYTE srcd;
307 unsigned int *dnumwant;
308{
309 WORD retcode;
310 WORD action;
311
312 int dnumok = FALSE;
313 unsigned file_pointer;
314 char fname_to_be_opened[13];
315 int numread;
316 int dyear;
317 int dmonth;
318 int dday;
319 char temp_array1[4];
320 char temp_array2[4];
321 BYTE c;
322
323 /********************************************************************/
324 /* open and read backupid.@@@. Store information in backupid.@@@ */
325 /* into dinfo */
326 /********************************************************************/
327
328 for (;;)
329 {
330 fname_to_be_opened[0] = srcd;
331 fname_to_be_opened[1] = ':';
332 fname_to_be_opened[2] = NULLC;
333 strcat(fname_to_be_opened,BACKUPID);
334 retcode =
335 DOSOPEN(
336 (char far *)&fname_to_be_opened[0],(unsigned far *)&file_pointer,
337 (unsigned far *)&action,(DWORD)0,0,0x01,0x00c0,(DWORD)0
338 );
339
340 if (retcode != NOERROR)
341 { display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
342 usererror(NOBACKUPFILE);
343 }
344
345 /*read BKIDLENG (7) bytes from the file and store into dheadold*/
346 retcode = DOSREAD( file_pointer,
347 (char far *)dheadold,
348 BKIDLENG,
349 (unsigned far *)&numread);
350 /*if return code of read indicate less than 11 bytes been read*/
351 if (retcode != 0 || numread < BKIDLENG) {
352 /*unexperror "source file does not contains backup files"*/
353 display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
354 unexperror(NOBACKUPFILE);
355 } /*endif */
356 dinfo->disknum = dheadold->disknum[0] + dheadold->disknum[1] * 10;
357 dyear = dheadold->diskyear[0] + dheadold->diskyear[1]*256;
358 dinfo->dflag = dheadold->diskflag;
359
360 /*close the file*/
361 DOSCLOSE(file_pointer);
362
363 /********************************************************************/
364 /* check disk sequence number */
365 /********************************************************************/
366 if (dnumok == TRUE) {
367 if ((WORD)dinfo->disknum != *dnumwant) {
368 set_reset_test_flag(&control_flag2,OUTOF_SEQ,SET);
369 }
370 dnumok = FALSE;
371 }
372 else {
373 if ((WORD)dinfo->disknum != *dnumwant) {
374 /*When disk is out of sequence, a 'warning' is given to user,
375 if the user still wants to proceed the restoring by doing
376 nothing but hit a key, the same diskette will be read again.*/
377 display_it(DISK_OUT_OF_SEQUENCE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
378 display_it(PRESS_ANY_KEY,STND_ERR_DEV,0,ANY_KEY_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
379 dnumok = TRUE;
380 continue;
381 } /*endif*/
382 } /*endif*/
383
384 /*at this point, the diskette has passed all the checking, and
385 should be a ok diskette. break out of the loop.*/
386 break;
387 } /*end of loop*/
388
389 /********************************************************************/
390 /* output a confirm msg "restoring files from drive d:" */
391 /********************************************************************/
392 temp_array1[0] = srcd;
393 temp_array1[1] = NULLC;
394 sublist.value1 = (char far *)temp_array1; /*;AN000;6 */
395 sublist.flags1 = LEFT_ALIGN + CHAR_FIELD_ASCIIZ; /*;AN000;6 */
396 sublist.max_width1 = (BYTE)strlen(temp_array1); /*;AN000;6 */
397 sublist.min_width1 = sublist.max_width1; /*;AN000;6 */
398 display_it(RESTORE_FILE_FROM_DRIVE,STND_OUT_DEV,1,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
399
400 /********************************************************************/
401 /* if the source disk is removable, output msg "diskette xx" */
402 /********************************************************************/
403 if (set_reset_test_flag(&control_flag2,SRC_HDISK,TEST) == FALSE)
404 {
405 temp_array2[0] = (dinfo->disknum / 10) + '0';
406 temp_array2[1] = (dinfo->disknum % 10) + '0';
407 temp_array2[2] = NULLC;
408
409 sublist.value1 = (char far *)temp_array2; /*;AN000;6 */
410 sublist.flags1 = LEFT_ALIGN + CHAR_FIELD_ASCIIZ; /*;AN000;6 */
411 sublist.max_width1 = (BYTE)strlen(temp_array2); /*;AN000;6 */
412 sublist.min_width1 = sublist.max_width1; /*;AN000;6 */
413 display_it(DISKETTE_NUM,STND_OUT_DEV,1,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
414 }
415
416 *dnumwant = dinfo->disknum + 1;
417 return; /*;AN000;*/
418} /*end of subroutine */
419
420 \ No newline at end of file