[net.micro.pc] Is my floppy diskette formated???

cdl@aluxs.UUCP (MITCHELL) (10/26/86)

A while a post a message requesting information on how one can check
a floppy diskette for blank/nonblank status.

To back track a little for those who might have missed my original request.
I wrote a DBASEIII application that includes formatting a diskette.
To ensure that a end-user doesn't format a disk that contains data
accidentally, I thought I would call the "DIR" DOS cammand.  Unfortunately
using "DIR" on a blank diskette yeild the infamous (A)bort, (R)etry,
(I)gnore  prompt.  Entering "A" at this point would abort the DBASE program
which would defeat the purpose.  Thanks to you wonderful people out there
I've solve the problem.  I am assuming that there are other people on the
net that may have similar problems so I've included the program that
I used.  This program leaves a lot to be desired eg: It does not tell you
if the diskette to be formatted is write protected however, since this
would not cause a fatal error I choose to leave it as is. *Actually I'm not
an assembly language programmer and I didn't have the time to figure
it out *

There are two program in this listing, the first is a C program,
the second is an assembly language program.

The C program <check.c> was compiled using Microsoft C compiler 3.0
which created an object file, the assembly language program <floppy.asm>
was then assembled and link with the C program object file eg:

MSC check,check		/* this created an object file name check.obj

MASM floppy,floppy	/* this created an object file name floppy.obj

LINK check floppy	/* this created an object file name check.exe

- Source program begins here.  

/* Check if floppy diskette in specified drive is formatted
and format the diskette at user request.
 */
#include <stdio.h>
#include <ctype.h>
#include <process.h>
extern int _check();
int a, c, d;

main()
{
	printf("Enter the Disk number to format: A<cr>, B<cr> ");
	if((c= getchar()) !='\n'){
		while( getchar() !='\n');
		c=toupper(c);
		if( c == 'A'|| c == 'B') {
			printf("\nChecking.. if diskette contains data\n");
			if (c == 'B') d = 1;
			else d = 0;
			d = check(d); /* call assembly function */
		}
	}
	if (d == 1) {
		printf("\n\nIf drive \"%c\" door is closed then its ",c);
		printf(" okay to format diskette\n");
		fmt_dsk();
	}
	else {
	     printf("\n\nThe diskette in drive \"%c\" contains data.\n",c);
	    printf("If you do format it you WILL LOOSE ALL INFORMATION\n");
		fmt_dsk();
	}
}


fmt_dsk()
{
	printf("\n\nEnter (C) to continue, anything else to stop: ");
	if((a = getchar()) !='\n'){
		a=toupper(a);
		while( getchar() !='\n');
		if(a == 'C') {
			if (c =='A')	system("format a:");
			else if(c == 'B') system("format b:");
		}
	        printf("\n\nNo formatting at this time\n");
	}
	else
		printf("\n\nNo formatting at this time\n");
}

-- Cut here and create an object file with  an assembler. I
-- used the Microsoft Assembler.

; this program sets the appropriate registers and
; call int13 function 4 (verify sector). If the sector cannot be
; verified the assumption is that its a blank diskette

; BUG!!
;A open drive door is interpreted as "OK to format therefore,
;one has to check the drive door.

_TEXT segment byte public 'CODE'
	assume cs:_TEXT
	public _check
_check proc near
	push bp		; save register used by C
	mov bp,sp
	push ds		
	push di
	push si
	mov ah,0	;reset controller
	int 13h
	mov ax,0402H	; verify 2 sector
	mov cx,0001h	; at track 0, sector 1
	mov dl,[bp+4]	; on drive specified
	mov dh,0	; head 0
	int 13h
	jc error
	mov ax,0000h
	pop si		;restore register used by C
	pop di
	pop ds
	pop bp
	ret
error:
	mov ax,0001h
	pop si
	pop di
	pop ds
	pop bp
	ret

_check endP

_TEXT	ends
	end