summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/RESTORE/RTOLD.C
blob: a345d7642c698b88c0c54baaac549376e937e608 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*----------------------------
/* SOURCE FILE NAME:   RTOLD.C
/*----------------------------
/*  0 */

#include "rt.h"
#include "rt1.h"
#include "rt2.h"
#include "restpars.h"                                                    /*;AN000;4*/
#include "string.h"
#include "dos.h"                                                      /*;AN000;2*/
#include "comsub.h"             /* common subroutine def'n */
#include "doscalls.h"
#include "error.h"

extern BYTE rtswitch;
extern BYTE control_flag;
extern BYTE control_flag2;
extern BYTE far *buf_pointer;
extern unsigned src_file_handle;
extern struct FileFindBuf filefindbuf;
extern struct  subst_list sublist;				      /*;AN000;6 Message substitution list */

/*****************  START OF SPECIFICATION  *********************************/
/*									    */
/*  SUBROUTINE NAME :  search_src_disk_old				    */
/*									    */
/*  DESCRIPTIVE NAME : For old format only, search the entire disk for	    */
/*		       matching files.					    */
/*									    */
/*  FUNCTION: Using find first and find next to find all the files	    */
/*	      which match the filename specified in the input		    */
/*	      cammand line.						    */
/*									    */
/*	      Whenever there is a file found, subroutine filespecmatch	    */
/*	      is called to match the file path, and file extension.	    */
/*	      If file path and file extension match the specification,	    */
/*	      subroutine switchmatch is called to match the file	    */
/*	      attributes, file modes, time, and date, then file sequence    */
/*	      number is checked.					    */
/*									    */
/*	      If the file matches all the specification, subroutine	    */
/*	      restore_a_file is called to actually restore the file.	    */
/*									    */
/*									    */
/********************** END OF SPECIFICATIONS *******************************/
void search_src_disk_old(dinfo,finfo,dheadold,dheadnew,fheadnew, /* wrw! */
		    srcd,destd,buf_size,dnumwant,
		    inpath,infname,infext,infspec,td)

     struct disk_info *dinfo;
     struct file_info *finfo;
     struct disk_header_old *dheadold;
     struct file_header_new far *fheadnew;
     struct disk_header_new far *dheadnew;
     BYTE   srcd;
     BYTE   destd;
     unsigned long buf_size;
     unsigned int *dnumwant;
     unsigned char *inpath;
     unsigned char *infname;
     unsigned char *infext;
     unsigned char *infspec;
     struct timedate *td;

{
     BYTE outstring[MAXPATH+MAXFSPEC];
     WORD    file_seq_num=1;
     WORD    first_file_on_diskette = TRUE;
     WORD    first_time_in_loop = TRUE;
     WORD return_code;
     DWORD partsize;
     unsigned int control_bufsize;
     BYTE temp_fname[MAXFNAME];
     BYTE temp_path[MAXPATH];
     WORD  temp_dirhandle;


    /*declaration for dosfindfirst */
    unsigned	dirhandle = 0xffff;	    /* directory handle 	    */
    unsigned	search_cnt = 1; 	    /* # of entries to find	    */
    unsigned	buf_len = sizeof(struct FileFindBuf);
    BYTE search_string[MAXPATHF+2];
    WORD retcode;
    /*end decleration for ffirst and fnext*/
    union REGS qregs;						      /*;AN000;8*/
    int    x;							      /*;AN000;8*/

/*************************************************************************/
/*  FIND THE FIRST FILE ON SOURCE					 */
/*************************************************************************/
  search_string[0] = srcd;
  search_string[1] = ':';
  search_string[2] = NULLC;
  strcat(search_string, infname);
  strcat(search_string, ".*");

retcode =				/* Find the 1st filename that	*/
  DOSFINDFIRST( 			/*   matches specified file spec*/
     ( char far * ) search_string,	/* File path name		*/
     ( unsigned far * ) &dirhandle,	/* Directory search handle	*/
     (unsigned) NOTV,			 /* Search attribute		*/
     (struct FileFindBuf far *) &filefindbuf,
     buf_len,				/* Result buffer length 	*/
     ( unsigned far * ) &search_cnt,	/* Number of entries to find	*/
     ( DWORD) 0
  );


/*************************************************************************/
/*  IF CANNOT FIND ANY FILES ON SOURCE, RETURN				 */
/*************************************************************************/
  if (retcode != 0)
     return;




/*************************************************************************/
/* start DO loop to find next until no more file found			 */
/*************************************************************************/
do
{
	/*if the directory found is a subdirectory, find next one*/
	if((retcode = filefindbuf.attributes & 0x0010) != 0x0010)
	{
	   /* SKIP BACKUPID */
	  if (strcmp(filefindbuf.file_name,BACKUPID) != 0)
	  {
	       if (first_time_in_loop == FALSE)
		 DOSCLOSE(src_file_handle);
	       else
		 first_time_in_loop = FALSE;

	       /*************************************************************************/
	       /*check_flheader_old: open and read file header, 			*/
	       /*************************************************************************/
	       strcpy(temp_fname,filefindbuf.file_name);
	       retcode = check_flheader_old( finfo, temp_fname,
		     filefindbuf.write_date, filefindbuf.write_time,
		     filefindbuf.attributes, filefindbuf.file_size,
		     file_seq_num, srcd, destd, infspec, inpath, dnumwant);

	    if (retcode == 0) {

	       /*************************/
	       /* SKIP SYSTEM FILES	*/
	    if ((set_reset_test_flag(&control_flag2,CPPC,TEST) == FALSE) &&
	       (strcmp(finfo->fname,"IBMBIO.COM")==0 ||
		strcmp(finfo->fname,"IBMDOS.COM")==0 ||
		strcmp(finfo->fname,"COMMAND.COM")==0 ))
	    {}
	    else {

	       /*************************************************************************/
	       /*if there is any switches set in the input line 			*/
	       /*switchmatch (this subroutine search the hard disk for the dest 	*/
	       /*************************************************************************/
	    if ((set_reset_test_flag(&control_flag,SWITCHES,TEST) == FALSE) ||
	       (set_reset_test_flag(&control_flag,SWITCHES,TEST) == TRUE &&
	       ((retcode = switchmatch(finfo, srcd, destd, td)) == TRUE) )) {

	       /*************************************************************************/
	       /*if dnum in fheadold.disknum is not 1 and is not in sequence, error    */
	       /*************************************************************************/
	    if (set_reset_test_flag(&control_flag2,OUTOF_SEQ,TEST) == TRUE &&
	       first_file_on_diskette == TRUE && finfo->dnum != 1)
	    {}
	    else
	    {
		if (finfo->dnum != 1 || finfo->dnum != file_seq_num)
		{
		   display_it(FILE_SEQUENCE_ERROR,STND_ERR_DEV,0,NO_RESPTYPE,(BYTE)UTIL_MSG); /*;AN000;6*/
		   unexperror(FILESEQERROR);
		}
		   /*endif*/
	       /*************************************************************************/
	       /* output msg to indicate which file is to be restored			*/
	       /*************************************************************************/
		/*outstring = inpath\infspec*/
		strcpy(outstring,finfo->path);
		if (strlen(finfo->path) != 1 )
		   strcat(outstring,"\\");

		strcat(outstring,finfo->fname);
		x = strlen(outstring);
		outstring[x] = CR;						  /*;AN000;6*/
		outstring[x+1] = LF;						  /*;AN000;6*/
		outstring[x+2] = NUL;						  /*;AN000;6*/
		qregs.x.ax = 0x4000;						  /*;AN000;6*/
		qregs.x.bx = 0x0001;						  /*;AN000;6*/
		qregs.x.cx = (WORD)strlen(outstring);				  /*;AN000;6*/
		qregs.x.dx = (unsigned int)&outstring[0];			  /*;AN000;6*/
		intdos(&qregs,&qregs);						  /*;AN000;6*/


	       /*************************************************************************/
	       /* call restore_a_file to restore the file				*/
	       /*************************************************************************/
		restore_a_file(finfo,dinfo,buf_size,&control_bufsize,
			  fheadnew,dheadold,dheadnew,
			  srcd,destd,inpath,infname,infspec,dnumwant,&dirhandle);

	       first_file_on_diskette = FALSE;

	       /*************************************************************************/
	       /* if the file just restored is a split file, and last file, exit loop	*/
	       /*************************************************************************/
	       if (set_reset_test_flag(&control_flag,SPLITFILE,TEST)==TRUE)
	       {
		  set_reset_test_flag(&control_flag,SPLITFILE,RESET);

		  if (dirhandle == 0xffff)
		    break;
		  else
		  {
		    retcode = 0;
		    continue;
		  }
	       } /*end of if file splitted*/


	    } /*end of if disk and file out of sequence*/
	    } /*end of switch match fail*/
	    } /*end of PC/DOS and it is system files*/
	    } /*end of if check file header is ok */
	  } /*end of if file name is not BACKUPID*/
	} /*end of if the directory found is a subdirectory*/

	    search_cnt = 1;

	    retcode =
	      DOSFINDNEXT
		(dirhandle,
		 (struct FileFindBuf far *)&filefindbuf,
		 buf_len,
		 (unsigned far *)&search_cnt
		);

}
while(retcode == 0);	/* END MAIN DO LOOP */

DOSCLOSE(src_file_handle);
/*************************************************************************/
/* if error during findnext, error exit 				 */
/*************************************************************************/
    if (retcode != ERROR_NO_MORE_FILES && retcode != 0)
    {
      com_msg(retcode);
      unexperror(retcode);
    }


    if (dirhandle != 0xffff)
    {
       if ((retcode = DOSFINDCLOSE(dirhandle)) != 0)
       {
	 com_msg(retcode);
	 unexperror(retcode);
       }
    }


return;
} /*end of subroutine*/