🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sources.atari.st
Article #363

v01i016: Fast disk eraser

#363
From: Steven Grimm
Date: Mon, 18 Apr 1988 16:31
141 lines
3588 bytes
Submitted-by: braner@tcgould.tn.cornell.edu (Moshe Braner)
Posting-number: Volume 1, Issue 16
Archive-name: blank


Here is a very simple little utility.
If you want to recycle a previously-used diskette, you can either
delete all the files and folders on it (slow) or reformat it (also
slow).  Or you can use this program, BLANK.TOS.  It zeros out the
FATs (excluding the first 3 bytes) and the root directory.  The
disk then looks just like a freshly formatted one to TOS.
You specify the drive letter, and BLANK will handle TOS or MS-DOS
disks of all sizes and formats.

The source (Laser C) follows.  It should compile with any ST C
compiler, just make sure 'WORD' is defined to 'int' or 'short', whatever
is 16 bits long.

- Moshe Braner

~~~~~~~~~~~~~~~ cut here ~~~~~~~~~~~~~~~~
/*
 *	BLANK
 *
 *	A program to blank out a floppy disk.
 *	The disk must have been formatted before.
 *	Much faster than reformatting or even
 *	deleting all that's on the disk by files.
 *
 *	For the Atari ST.
 *
 *	By Moshe Braner, 880406
 */

#include <osbind.h>
#undef  Getbpb
#define Getbpb(a)	bios(7, a)

#define WORD int	/* 16 bits, 'int' in Laser C */

#define OK	0

#define READ	0
#define WRITE	1

typedef struct bpb {
	WORD	recsiz;
	WORD	clsiz;
	WORD	clsizb;
	WORD	rdlen;
	WORD	fsiz;
	WORD	fatrec;
	WORD	datrec;
	WORD	numcl;
	WORD	bflags;
} BPB;

char buf[7*512];

/*
 * Print message and quit.
 */
error(msg)
	char msg[];
{
	Cconws(msg);
	Cconws("\007\r\n\n\tHit any key ");
	Bconin(2);
	exit(0);
}

main()
{
	int	i, bps, spc, fats, dir, spd, spf, dat, sec, secs, drv;
	BPB	*bpb;

	char	*msg1 = "\r\n\tError reading!";
	char	*msg2 = "\r\n\tError writing!";

	Cconws("\033E\r\n\n\tBLANK 1.0\tby Moshe Braner");

loop:	Cconws("\r\n\n\tEnter letter label of drive to blank: ");
	drv = Bconin(2);
	if (drv == 0x1B)
		exit(0);
	if (drv>='a' && drv<='p')
		drv += 'A'-'a';
	Bconout(2, drv);
	if (drv < 'A' || drv > 'P')
		goto loop;
	drv -= 'A';		/* 0=A, 1=B, ... */

	/* get disk parameters from bios parameter block */

	Cconws("\r\n\tInsert disk to blank, hit any key: ");
	i = Bconin(2);
	if (i == 0x1B)
		exit(0);
	bpb = (BPB *) Getbpb(drv);
	if (bpb==0)
		error(msg1);
	dir = bpb->rdlen;		/* length of dir in sectors	*/
	spf = bpb->fsiz;		/* sectors per FAT		*/
	dat = bpb->datrec;		/* no. of first data sector	*/

	/* read FAT from disk to RAM */

	sec = dat - dir - 2*spf;
	if (Rwabs (READ, buf, spf, sec, drv) != OK)
		error(msg1);

	/* zero out everything beyond the first 3 bytes */

	for (i=3; i<7*512; i++)
		buf[i] = 0;

	/* write it back, to both FATs */

	Cconws("\007\r\n\n\t\tWARNING:");
	Cconws("\r\n\tAbout to erase ALL data in drive ");
	Bconout(2,drv+'A');
	Cconws(".\r\n\n\t\tProceed (y/n)? ");
	i = Bconin(2);
	if (i!='y' && i!='Y')
		exit(0);

	if (Rwabs (WRITE, buf, spf, sec, drv) != OK)
		error(msg2);
	sec += spf;
	if (Rwabs (WRITE, buf, spf, sec, drv) != OK)
		error(msg2);

	/* zero out root directory */

	buf[0] = buf[1] = buf[2] = 0;
	sec = dat - dir;
	if (Rwabs (WRITE, buf, dir, sec, drv) != OK)
		error(msg2);

	error(".\r\n\n\tBLANK finished, no errors.");
}
Technical Details
Message-ID: <2882@saturn.ucsc.edu>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!cmcl2!nrl-cmf!ames!pasteur!agate!saturn!ssyx!koreth

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!cmcl2!nrl-cmf!ames!pasteur!agate!saturn!ssyx!koreth
From: koreth@ssyx.ucsc.edu (Steven Grimm)
Newsgroups: comp.sources.atari.st
Subject: v01i016: Fast disk eraser
Message-ID: <2882@saturn.ucsc.edu>
Date: 18 Apr 88 16:31:14 GMT
Sender: usenet@saturn.ucsc.edu
Lines: 141
Keywords: Laser
Approved: koreth@ssyx.ucsc.edu