summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/CHKDSK/CHKDSK2.ASM
blob: 45838da49b0e006063fe9175ed67b544731c5135 (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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
TITLE	CHKDSK - MS-DOS Disk consistancy checker
page	,132					;

	.xlist
	include chkseg.inc
	INCLUDE CHKCHNG.INC
	INCLUDE DOSSYM.INC
	INCLUDE CHKEQU.INC
	INCLUDE CHKMACRO.INC
	include pathmac.inc
	.list

SUBTTL	Initialized Data
PAGE
CONST	SEGMENT PUBLIC PARA 'DATA'
	EXTRN  BADVER:byte,BADDRV_ARG:word,INVPATH_ARG:word
	EXTRN  FILE_ARG:word
	EXTRN  BADCD_ARG:word,BADSUBDIR:byte
	EXTRN  BADDRVM:byte
	EXTRN  BADIDBYT:byte
	EXTRN  OPNERR_ARG:word,NOEXT_ARG:word,EXTENT_ARG:word
	EXTRN  IDMES_ARG:WORD
	EXTRN  FILE_ARG1:WORD,FILE_ARG2:WORD
	EXTRN  badrw_num:word,BADRW_STR:WORD,BLOCK_NUM:WORD
	EXTRN  BADSW_ARG:WORD,DSKSPC:WORD
	EXTRN  HIDMES:WORD,DIRMES:WORD,FILEMES:WORD,ORPHMES2:WORD
	EXTRN  ORPHMES3:WORD,BADSPC:WORD,FRESPC:WORD
	EXTRN  TOTMEM:WORD,FREMEM:WORD,REPORT_ARG:WORD,CRLF_ARG:WORD
	EXTRN  RARG1:dWORD,RARG3:dWORD,ORPHCNT:dWORD		    ;an049;bgb
	EXTRN  SubstErr:BYTE
	extrn  tot_bytes_lo:word, tot_bytes_hi:word

	extrn	SWITCHAR:byte,TCHAR:byte,HECODE:byte,CONBUF:byte
	extrn	DOTMES:byte,NOISY:byte,HAVFIX:byte
	extrn	DOFIX:byte,DIRBUF:near,PARSTR:byte
	extrn	NUL:byte,ERRSUB:word,ALLFILE:byte
	extrn	ORPHFCB:byte,ORPHEXT:byte,HIDCNT:dword
	extrn	HIDSIZ:word,FILCNT:dword,FILSIZ:word,DIRCNT:dword		 ;an049;bgb
	extrn	DIRSIZ:word,CROSSCNT:dword,BADSIZ:word			     ;an049;bgb
	extrn	ORPHSIZ:word						    ;an049;bgb
	extrn	LCLUS:word						    ;an049;bgb
	extrn	USERDIR:byte,FRAGMENT:byte
	extrn	ALLDRV:byte,FIXMFLG:byte,DIRCHAR:byte
	extrn	EOFVAL:word						     ;an050;bgb
	extrn	Idmes2:Byte,Idmes1:Byte,idmes3:byte				;an017;bgb
CONST	ENDS

SUBTTL	Un-initialized Data
PAGE
DATA	SEGMENT PUBLIC PARA 'DATA'
	extrn	THISDPB:dword,DOTSNOGOOD:byte,NUL_ARG:byte
	extrn	NAMBUF:byte,SRFCBPT:word
	extrn	ISCROSS:byte,MCLUS:word,CSIZE:byte,SSIZE:word
	extrn	DSIZE:word,ARG1:word,ARG_BUF:byte,ERRCNT:byte
	extrn	USERDEV:byte,HARDCH:dword,CONTCH:dword
	extrn	mem_size:word							;an055;bgb
	extrn	psp_segment:word						;an030;bgb
	extrn	write_fault:byte						;an045;bgb
DATA	ENDS

CODE	SEGMENT PUBLIC PARA 'CODE'
ASSUME	CS:DG,DS:DG,ES:DG,SS:DG
	EXTRN	INT_23:NEAR
	EXTRN	PROMPTYN:NEAR,GET_CURRDIRERR:NEAR,GET_CURRDIR:NEAR
	EXTRN	FINDCHAIN:NEAR,CHECKERR:NEAR
	EXTRN	Write_Disk:Near, multiply_32_bits:near

	PUBLIC	PRINTF_CRLF,DOCRLF,SUBERRP,FCB_TO_ASCZ,EPRINT
	PUBLIC	DOINT26,DOTCOMBMES,REPORT
	public	ramcarv


;EPRINT:
;	 CALL	 CHECKERR
;	 JNZ	 RET14
;	 cmp	 byte ptr [nul_arg],0
;	 jnz	 hav_eprint_arg
;	 mov	 [file_arg2],offset dg:nul
;hav_eprint_arg:
;	 mov	 [file_arg1],dx
;	;mov	 dx,offset dg:file_arg
;	 mov	 dx,file_arg			 ;Get offset of message 	 ;AC000;
;	 call	 printf_crlf
;	 mov	 byte ptr [nul_arg],0
;RET14:  ret


EPrint:
	call	CheckErr			;See if we should display msg
	pathlabl chkdsk2
;	$IF	Z				;Yes if Z set			;AC000;
	JNZ $$IF1
	push	dx				;Save message			;AC000;
	Message File_Arg			;Put out file in question	;AC000;
	pop	dx				;Get back message		;AC000;
	call	Printf_CRLF			;Print it
	cmp	byte ptr [nul_arg],0		;Is there a second message?
;	$IF	NZ				;Yes if not nul 		;AC000;
	JZ $$IF2
	mov	dx,File_Arg2			;Display it			;AN000;
	call	Printf_CRLF			;				;AN000;
;	$ENDIF					;				;AC000;
$$IF2:
	mov	byte ptr [nul_arg],0		;Re-init this field
;	$ENDIF
$$IF1:
	ret					;

DOTCOMBMES:
	CMP	[NOISY],0
	JZ	SUBERRP
	mov	[file_arg2],dx
	CALL	get_currdirERR
       ;MOV	DX,OFFSET DG:CENTRY		;Centry got split into 3 msg's
       ;inc	byte ptr [nul_arg]		;
	CALL	EPRINT
	RET

SUBERRP:
	MOV	AL,1			;found a subdir error
	XCHG	AL,BYTE PTR [ERRSUB]	;set error flag and get old flag
	CMP	AL,0			;were any errors found before?
;	$if	z			;no errors found yet
	JNZ $$IF5
					 ;JNZ	  RET32
	    MOV     SI,OFFSET DG:NUL	   ;display error msgs
	    CALL    get_currdirERR
	    MOV     DX,OFFSET DG:BADSUBdir
	    CALL    EPRINT
;	$endif
$$IF5:
RET32:	RET

;****************************************************************************
; called by:  get_thisel2
; inputs:   DS:SI - pointer to file name
;****************************************************************************
FCB_TO_ASCZ:				;Convert DS:SI to ASCIZ ES:DI
	PUSH	CX
;move filename from ds:si to es:di
	MOV	CX,8			; Pack the name
	REP	MOVSB			; Move all of it
main_kill_tail:
; delete trailing spaces in name
	CMP	BYTE PTR ES:[DI-1]," "	;was the last char in name a space?
	JNZ	find_check_dot
	DEC	DI			; Back up over trailing space
	INC	CX
	CMP	CX,8
	JB	main_kill_tail
find_check_dot:
; ???
	CMP	WORD PTR [SI],(" " SHL 8) OR " "
	JNZ	got_ext 		; Some chars in extension
	CMP	BYTE PTR [SI+2]," "
	JZ	find_done		; No extension
got_ext:
; move period for extension
	MOV	AL,"."
	STOSB
; move 3 byte extension
	MOV	CX,3
	REP	MOVSB
ext_kill_tail:
;delete trailing blanks
	CMP	BYTE PTR ES:[DI-1]," "	;
	JNZ	find_done		;
	DEC	DI			; Back up over trailing space
	JMP	ext_kill_tail		;
find_done:				;
; put hex zero at the end
	XOR	AL,AL			;
	STOSB				; NUL terminate
	POP	CX
	RET


DOINT26:
;	PUSH	CX			;reg saves are handled in write_disk	;ac048;bgb;an045;bgb
;	PUSH	DX			;reg saves are handled in write_disk	;ac048;bgb;an045;bgb
;	PUSH	BX			;reg saves are handled in write_disk	;ac048;bgb;an045;bgb
	call	Write_Disk		;					;an045;bgb;AC000;
;	POP	BX			;reg saves are handled in write_disk	;ac048;bgb;an045;bgb
;	POP	DX			;reg saves are handled in write_disk	;ac048;bgb;an045;bgb
;	POP	CX			;reg saves are handled in write_disk	;ac048;bgb;an045;bgb
;	JNC	RET23								;ac048;bgb;an045;bgb
       ;MOV	SI,OFFSET DG:WRITING						;ac048;bgb;an045;bgb
       ;CALL	DSKERR								;ac048;bgb;an045;bgb
;      $IF	C								;ac048;bgb;an045;bgb
       JNC $$IF7
	   mov	   dx,offset dg:write_fault					;ac048;bgb;an045;bgb
	   invoke  printf_crlf							;ac048;bgb;an045;bgb
;      $ENDIF									;ac048;bgb;an045;bgb
$$IF7:
;										;ac048;bgb;ac048;bgb;an045;bgb
;Need to handle 'Fail' option of critical error here.				;ac048;bgb;an045;bgb
;										;ac048;bgb;an045;bgb
										;ac048;bgb;an045;bgb
;	JZ	DOINT26 							;ac048;bgb;an045;bgb
RET23:	RET									;ac048;bgb;an045;bgb



;**************************************
; Prints all reporting data
;**************************************

REPORT:
;total disk space
    mov     bx,offset dg:dskspc
    mov     dx,tot_bytes_hi		;total bytes   in disk		;AN006;bgb
    mov     ax,tot_bytes_lo		;total bytes   in disk		;AN006;bgb
    xor     si,si			;no file count
    xor     di,di			;no file count
    call    Report_Mes_2		;				;AN006;bgb
;hidden files
    mov     ax,hidsiz			;get cluster count		;an049;bgb
    or	    ax,ax			;are there any hidden files?
;   $IF     NZ				;yes				       ;AC000;
    JZ $$IF9
	mov	si,word ptr hidcnt	;si=low file count		    ;an049;bgb
	mov	di,word ptr hidcnt+2	;di=hi file count		    ;an049;bgb
	mov	bx,offset dg:hidmes	;bx=msg ;
	call	report_mes_1			;
;   $ENDIF				    ;				    ;AC000;
$$IF9:
;space in subdirectories
    mov     ax,dirsiz			;get cluster count
    or	    ax,ax			;Are there any directories?    ;an049;bgb
;   $IF     NZ				;yes				       ;AC000;
    JZ $$IF11
	mov	si,word ptr dircnt	;si=low file count		    ;an049;bgb
	mov	di,word ptr dircnt+2	;di=hi file count		    ;an049;bgb
	mov	bx,offset dg:dirmes	;bx=msg
	call	report_mes_1						    ;an049;bgb
;   $ENDIF				    ;				    ;AC000;
$$IF11:
;user files
    mov     ax,filsiz			;get cluster count
    or	    ax,ax			;Are there any user files?    ;an049;bgb
;   $IF     NZ				;yes				       ;AC000;
    JZ $$IF13
	mov	si,word ptr filcnt	;si=lo file count		    ;an049;bgb
	mov	di,word ptr filcnt+2	;di=hi file count		    ;an049;bgb
	mov	bx,offset dg:filemes	;bx=msg
	call	report_mes_1
;   $ENDIF				    ;				    ;AC000;
$$IF13:
;chains of lost clusters
    mov     ax,orphsiz			;get cluster count
    or	    ax,ax			;Are there any lost clusters?	;an049;bgb
;   $IF     NZ				;yes				       ;AC000;
    JZ $$IF15
	mov	si,word ptr orphcnt	;si=lo file count
	mov	di,word ptr orphcnt+2	;di=hi file count
	cmp	dofix,0 		;/F entered?
;	$IF	Z			;no				;AC000;
	JNZ $$IF16
	    mov     bx,offset dg:orphmes3 ;bytes would be recovered
;	$else
	JMP SHORT $$EN16
$$IF16:
	    mov     bx,offset dg:orphmes2 ;bytes were	recovered
;	$ENDIF					;				;AC000;
$$EN16:
	call	report_mes_1
;   $ENDIF				    ;				    ;AC000;
$$IF15:
;clusters of bad spots
    mov     ax,badsiz			;get cluster count
    or	    ax,ax			;Are there any bad spots on disk?
;   $IF     NZ				;if low word > zero, then yes	       ;AC000;
    JZ $$IF20
	xor	si,si			;no files to count
	xor	di,di			;no files to count
	mov	bx,offset dg:badspc		;Issue report
	call	report_mes_1
;   $ENDIF				    ;				    ;AC000;
$$IF20:
;bytes on disk left - free space
	mov	ax,[dsize]		;get total disk clusters
	sub	ax,[dirsiz]		; - dirs
	sub	ax,[filsiz]		; - files
	sub	ax,[hidsiz]		; - hidden files
	sub	ax,[badsiz]		; - bad spots
	sub	ax,[orphsiz]		; - lost clusters recovered
	sub	ax,[lclus]		; - lost clusters not recovered
	xor	si,si
	xor	di,di
	mov	bx,offset dg:frespc
	call	report_mes_1		;Free space is whats left
	call	docrlf				;				;AN000;
;size of each allocation unit
	xor	dx,dx				;Figure out cluster size	;AN000;
	xor	ah,ah				;				;AN000;
	mov	cx,SSize			;Bytes/sector * 		;AN000;
	mov	al,CSize			; Sectors/cluster		;AN000;
	mul	cx				; = Bytes/Cluster in AX 	;AN000;
	mov	bx,offset dg:idmes2		;Allocation size message	;AN000;
	xor	si,si
	xor	di,di
	call	Report_Mes_2			;				;AN000;
;total clusters
	mov	ax,Mclus			;Allocation units available	;AN000;
	dec	ax				;MCLUS is # clusters+1
	xor	dx,dx				;				;AN000;
	mov	bx,offset dg:idmes1		;				;AN000;
	xor	si,si
	xor	di,di
	call	Report_Mes_2			;				;AN000;
;;;;;;;;call	docrlf			;					;an017;bgb
;avail clusters 								;an017;bgb
public avail_clus
avail_clus:
	mov	ax,[dsize]		;total clusters on disk 		;an017;bgb
	sub	ax,[dirsiz]		; - clusters in subdirs 		;an017;bgb
	sub	ax,[filsiz]		; - user files				;an017;bgb
	sub	ax,[hidsiz]		; - hidden files			;an017;bgb
	sub	ax,[badsiz]		; - bad spots				;an017;bgb
	sub	ax,[orphsiz]		; - lost clusters recovered					   ;an017;bgb
	sub	ax,[lclus]		; - lost clusters not recovered 	;an017;bgb
	mov	bx,offset dg:idmes3		;				;an017;bgb
	xor	dx,dx				;				;AN017;bgb
	xor	si,si
	xor	di,di
	call	Report_Mes_2		;dont convert to bytes! 		;an017;bgb
	call	docrlf								;an017;bgb


;dcl Jan 8, 87 Compensate for RAM Carving - Start

ramcarv:
	push	es								;AN000;
	xor	bx,bx								;AN000;
	mov	ah,0c1h 		; return Ext'd Bios Data Seg Address    ;AN000;
	int	15h								;AN000;
;	$IF	NC			; ram carving exists if no carry	;AC000; 				;AN000;
	JC $$IF22
	   xor	   ax,ax		; zero out ax
	   mov	   al,byte ptr es:[0]	; pointer to # of 1k blocks of RAM Carve;AN000;
	   mov	   dx,64		; convert 1k blocks to paras		;AN000;
	   mul	   dx								   ;AN000;
	   mov	   bx,ax		   ; save value in BX			   ;AN000;
;	$ENDIF					;				;AC000; 				;AN000;
$$IF22:
	pop	es								;AN000;

;dcl Jan 8, 87 Compensate for RAM Carving - End

	mov	ax,[mem_size]	     ;Find out about memory
	add	ax,bx			; dcl Jan 8, 87 Compensate for RAM Carving
	mov	dx,16			;Mul to convert kbytes to bytes
	mul	dx
	mov	bx,offset dg:totmem
	call	report_mes_2
	mov	ax,[mem_size]
;;;;;;; mov	dx,psp_segment							;an030;bgb
	sub	ax,psp_segment							;an030;bgb
	mov	dx,16
	mul	dx
	mov	bx,offset dg:fremem
	call	report_mes_2
	ret

;*************************************************************
;
;  Print the message specified by the control string.
;
; REPORT_MES_1
; On entry:
;     BX contains the address of the control string.
;     AX contains a cluster count for the %ld argument in the control string.
;     CX contains a word count for the %d argument in the control string
;	 or is meaningless.
;
; REPORT_MES_2
; On entry:
;     BX contains the address of the control string.
;     AX,DX contain a long integer.
;     CX contains a word count for the %d argument in the control string
;	 or is meaningless.
;
;*************************************************************

;*****************************************************************************
; REPORT_MES_1 -  Print the report messages.  Display the file count and
;		 translate the number of clusters into the number of bytes.
;
; WARNING!! NOTE!! -->
;
; called by - PROCEDURE NAME
;
; inputs: AX - cluster count (1-ffff)
;	  BX - offset of control string
;	  CX -
;	  DX - high word of cluster count is zero'd out here.
;	  SP -
;	  BP -
;	  SI - low word of file count
;	  DI - hi  word of file count
;	  DS - segment of control string
;	  ES -
;
; output: DISPLAY OF DATA TO SCREEN
;
; Regs abused - ALL
;
;logic: 1. zero out hi word of cluster count, and multiply by sectors per
;	   cluster.  This gives number of sectors, which is a double word.
;
;	2. multiply by bytes per sector to give number of bytes.
;
;	3. place values in diplay fields, and call the msg. retriever.
;
;*****************************************************************************
report_mes_1:
	push	bx			;save it
	xor	dx,dx			;zero out hi word for multiply
	mov	cl,csize		;get sectors per cluster
	xor	ch,ch			;zero out hi byte of word
	mul	cx			;Convert cluster count to sector count ax/dx

	mov	bx,dx			;bx:ax is number to be mult;bgb
	mov	cx,ssize		;cx is number to mult with  ;bgb
	call	multiply_32_bits		       ;bgb
	mov	dx,bx			;move hi value to dx
	pop	bx			;retore pointer;bgb

report_mes_2:
	mov	word ptr rarg1,ax	;Lo word of bytes in ax
	mov	word ptr rarg1+2,dx	;Hi word of bytes in dx
	mov	word ptr rarg3,si	;lo word of file count in si
	mov	word ptr rarg3+2,di	;hi word of file count in di
	mov	report_arg,bx		;Store the offset of the ctrl string
	mov	dx,bx			;dx has ptr to msg for disp_interface  ;AC000;
	call	printf_crlf		;print msg, then carraige return
	ret

PRINTF_CRLF:
	call	display_interface   ;					    ;AC000;
DOCRLF: mov	dx,offset dg:crlf_arg
	call	Display_Interface	;Replace old printf call with SysDispMsg;AN000;
	ret				;					;AN000;


	pathlabl chkdsk2
CODE	ENDS
	END