2 /*-----------------------------
3 /* SOURCE FILE NAME: RTDO1.C
4 /*-----------------------------
10 #include "restpars.h" /*;AN000;4*/
12 #include "dos.h" /*;AN000;2*/
13 #include "comsub.h" /* common subroutine def'n */
17 struct disk_header_new russ_disk_header; /* !wrw */
18 unsigned control_file_handle = 0xffff; /* !wrw */
20 extern BYTE control_flag2;
21 extern BYTE far *control_buf_pointer;
22 extern unsigned control_selector;
23 extern struct FileFindBuf filefindbuf;
24 extern struct internat ctry; /* data area for get country info */
25 extern struct subst_list sublist; /*;AN000;6 Message substitution list */
26 /***************** START OF SPECIFICATION ********************************
28 /* SUBROUTINE NAME : check_bkdisk_new
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
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
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.
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.
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.
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.
62 /********************** END OF SPECIFICATIONS *******************************/
63 void check_bkdisk_new(dheadnew, dinfo, srcd, dnumwant,control_bufsize) /* wrw! */
65 struct disk_header_new far *dheadnew;
66 struct disk_info *dinfo;
68 unsigned int *dnumwant;
69 unsigned int *control_bufsize;
72 WORD disknum; /*disk number carried by the file name backup.xxx*/
73 BYTE fname_to_be_opened[13];
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];
89 /*end decleration for ffirst and fnext*/
90 /*****************************/
91 /*search for control.xxx */
92 /*****************************/
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.???");
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 */
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);
120 /*if the directory found is a subdirectory, find next one*/
121 while((retcode = filefindbuf.attributes & SUBDIR) == SUBDIR)
124 retcode = DOSFINDNEXT(dirhandle,
125 (struct FileFindBuf far *)&filefindbuf,
127 (unsigned far *)&search_cnt);
129 { display_it(SOURCE_NO_BACKUP_FILE,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
130 usererror(NOBACKUPFILE);
133 } /*end of file control.xxx not found*/
135 retcode = DOSFINDCLOSE(dirhandle);
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);
149 /********************************************************************/
150 /* check the disk sequence number of the disk */
151 /********************************************************************/
154 if (disknum != *dnumwant)
155 set_reset_test_flag(&control_flag2,OUTOF_SEQ,SET);
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)
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*/
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.*/
175 } /*endif of dnumok = FALSE*/
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);
187 ( (char far *)&fname_to_be_opened[0],
188 (unsigned far *)&control_file_handle, /* !wrw */
189 (unsigned far *)&action,
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);
202 /********************************************************************/
203 /* READ DISK_HEADER INTO STATIC DISKHEADER STRUCTURE wrw */
204 /********************************************************************/
209 control_file_handle, /* !wrw */
210 (char far *)&russ_disk_header, /* !wrw */
211 (unsigned short)DHEADLEN, /* !wrw */
212 (unsigned far *)&read_count /* !wrw */
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);
220 /********************************************************************/
221 /* get and store dheadnew information into dinfo */
222 /********************************************************************/
223 dheadnew = (struct disk_header_new far *)&russ_disk_header; /* !wrw */
225 dinfo->disknum = dheadnew->sequence;
226 dinfo->dflag = dheadnew->lastdisk;
228 /* At this point, the diskette has passed all the checking, and */
229 /* should be a ok diskette. break out of the loop.*/
232 } /*end of "for (;;)" loop */
234 /********************************************************************/
235 /* output confirm msg "restore file from drive d:" */
236 /********************************************************************/
237 temp_array1[0] = srcd;
238 temp_array1[1] = NULLC;
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 */
245 display_it(RESTORE_FILE_FROM_DRIVE,STND_OUT_DEV,1,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
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)
252 temp_array2[0] = (dinfo->disknum / 10) + '0';
253 temp_array2[1] = (dinfo->disknum % 10) + '0';
254 temp_array2[2] = NULLC;
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*/
261 display_it(DISKETTE_NUM,STND_OUT_DEV,1,NO_RESPTYPE,(BYTE)UTIL_MSG);/*;AN000;6*/
264 *dnumwant = dinfo->disknum + 1;
267 } /*end of subroutine */
269 /***************** START OF SPECIFICATION ********************************
271 /* SUBROUTINE NAME : check_bkdisk_old
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
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
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.
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.
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.
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.
302 /********************** END OF SPECIFICATIONS *******************************/
303 void check_bkdisk_old(dheadold, dinfo, srcd, dnumwant) /* wrw! */
304 struct disk_header_old *dheadold;
305 struct disk_info *dinfo;
307 unsigned int *dnumwant;
313 unsigned file_pointer;
314 char fname_to_be_opened[13];
323 /********************************************************************/
324 /* open and read backupid.@@@. Store information in backupid.@@@ */
326 /********************************************************************/
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);
336 (char far *)&fname_to_be_opened[0],(unsigned far *)&file_pointer,
337 (unsigned far *)&action,(DWORD)0,0,0x01,0x00c0,(DWORD)0
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);
345 /*read BKIDLENG (7) bytes from the file and store into dheadold*/
346 retcode = DOSREAD( file_pointer,
347 (char far *)dheadold,
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);
356 dinfo->disknum = dheadold->disknum[0] + dheadold->disknum[1] * 10;
357 dyear = dheadold->diskyear[0] + dheadold->diskyear[1]*256;
358 dinfo->dflag = dheadold->diskflag;
361 DOSCLOSE(file_pointer);
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);
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*/
384 /*at this point, the diskette has passed all the checking, and
385 should be a ok diskette. break out of the loop.*/
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*/
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)
405 temp_array2[0] = (dinfo->disknum / 10) + '0';
406 temp_array2[1] = (dinfo->disknum % 10) + '0';
407 temp_array2[2] = NULLC;
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*/
416 *dnumwant = dinfo->disknum + 1;
418 } /*end of subroutine */