[net.sources] RT-11 floppy -- disc.c

jrb@wdl1.UUCP (John R Blaker) (02/17/84)

/*==========================================================================*
 *		       == D I S C   I N T E R F A C E ==		    *
 *==========================================================================*
 * John R Blaker -- Ford Aerospace & Communications Corporation -- Oct 1982 *
 *==========================================================================*
 * This file contains those routines which interface with the disc directly *
 * It contains the following routines:				    	    *
 *	getblock()	Reads in a specified block from the disc	    *
 *	putblock()	Puts a specified block on the disc		    *
 *	getsegment()	Reads in a specified segment from the disc	    *
 *	putsegment()	Puts a specified segment on the disc		    *
 *	disc_open()	Opens the correct drive and sets a variable to the  *
 *			descriptor					    *
 *	disc_close()	Closes the disc again				    *
 * Other copies of this program are locked out whenever the disc is open.   *
 * They will go into a busy wait until the drive is released.		    *
 *==========================================================================*
 */

/*
 * Include files
 */

#include	"rt11.h"	/* Global variables */

/*
 * Global (local) definitions
 */

int	disc;	/* File descriptor of the disc */

/*
 * getblock()
 * Get a block from a specified place on the disc
 */

getblock(loc, info)
int	loc;	/* Block number on the disc */
char	*info;	/* Information retrieved from the disc */
{
	lseek(disc, (long)(loc * BLOCKSIZE), 0);
	read(disc, info, BLOCKSIZE);
} /* getblock */

/*
 * putblock()
 * Put a block on a specified place on the disc
 */

putblock(loc, info)
int	loc;	/* Block number on the disc */
char	*info;	/* Information to be written on the disc */
{
	lseek(disc, (long)(loc * BLOCKSIZE), 0);
	write(disc, info, BLOCKSIZE);
} /* putblock */

/*
 * getsegment()
 * Get a segment from a specified area on the disc
 */

getsegment(loc, info)
int	loc;	/* Block number on the disc */
char	*info;	/* Holds information read from the disc */
{
	lseek(disc, (long)(loc * BLOCKSIZE), 0);
	read(disc, info, SEGSIZE);
} /* getsegment */

/*
 * putsegment()
 * Put a segment on the disc
 */

putsegment(loc, info)
int	loc;	/* Block number on the disc */
char	*info;	/* Information to be written to the disc */
{
	lseek(disc, (long)(loc * BLOCKSIZE), 0);
	write(disc, info, SEGSIZE);
} /* putsegment */

/*
 * disc_open()
 * Open the appropriate disc drive
 * Aborts the program with a message if
 * a bad drive number is given
 */

disc_open(drive_no)
int	drive_no;	/* Drive number */
{
	trace("Got to disc_open()");
	lock("/tmp/disc_lock");
	switch (drive_no) {
		case ZERO:
			if (LIST || EXTRACT)
				disc = open("/dev/rx2", IO_RD);
			else 
				disc = open("/dev/rx2", IO_WT);
			break;
		case ONE:
			if (LIST || EXTRACT)
				disc = open("/dev/rx3", IO_RD);
			else 
				disc = open("/dev/rx3", IO_WT);
			break;
		default:
			error("Bad drive number specified");
			unlock("/tmp/disc_lock");
			exit(1);
	} /* switch */
	if (disc < 0) {
		error("Can't open drive");
		unlock("/tmp/disc_lock");
		exit(1);
	} /* if */
} /* disc_open */

/*
 * disc_close()
 * This routine closes the disc
 * and removes the lockfile
 */

disc_close()
{
	close(disc);
	unlock("/tmp/disc_lock");
} /* disc_close */