home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************
- *
- * Low Level Read/Write routines to access the info on the disk
- * and the contents of the CMOS RAM chip
- *
- * init( unit ) initialize the specified drive
- * done( unit ) close down the specified drive
- * read_sector( unit, buf, cyl, head, sector)
- * write_sector( unit, buf, cyl, head, sector)
- * raw_io( unit, buf, cyl, head, sector, op)
- *
- * readCMOS( buffer ) read the contents of the CMOS RAM
- * writeCMOS( buffer ) write to the CMOS RAM
- *
- ***************************************************************
- *
- * Revision Control Information
- *
- * By: $Author: root $
- * $Revision: 1.2 $
- * Last modified: $Date: 87/09/16 02:12:24 $
- * $Source: /u/src/microport/newfdisk/test/RCS/getput.c,v $
- *
- * Release state: $State: Exp $
- *
- ***************************************************************
- *
- * Modification Log
- * ----------------
- * $Log: getput.c,v $
- * Revision 1.2 87/09/16 02:12:24 root
- * maintenance update
- *
- * Revision 1.1 88/04/07 23:11:20 root
- * Initial revision
- *
- ***************************************************************
- */
-
- #ifndef lint
- static char rcsid[] =
- "$Header: getput.c,v 1.2 87/09/16 02:12:24 root Exp $";
- #endif
-
- #include <fcntl.h>
- #include <errno.h>
- #include <sys/param.h>
- #include <sys/types.h>
- #include <malloc.h>
- #include "cmos.h" /* cmos layout */
-
- /* #define PRODUCTION /* Define to eliminate error messages on stderr */
- #define NOWRITE /* Define to DISABLE absolute writes to the disk */
-
- #ifdef PRODUCTION
- # ifdef NOWRITE
- ERROR: Why do you want a production version which can not write to the disk?
- # endif
- #endif
-
- static int fds[2] = { -1, -1 }; /* fds for both hard disk drives */
-
- static char *unitname[] = { /* entire disk... */
- "/dev/rdsk/0s0",
- "/dev/rdsk/1s0"
- };
-
- /*
- ** Open a file which corrosponds to the entire disk.
- ** All other operations require that this be done before they call
- ** any disk I/O routines!
- */
-
- int init( unit )
- int unit;
- {
- char dummyblock[512];
-
- if (unit < 0 || unit > 1)
- return ERROR;
-
- if ( fds[unit] != -1 )
- closeunit( unit );
-
- if ((fds[unit] = open(unitname[unit], O_RDWR)) == -1) {
- fprintf(stderr, "Can't open %s, errno=%d\n", unitname[unit], errno);
- exit(errno);
- }
-
- /*
- ** WHY is this needed???
- */
-
- read(fds[unit],dummyblock,512); /* dummy read to force wnsweep */
-
- return OK;
- }
-
- done( unit )
- int unit;
- {
- close( fds[unit] );
- fds[unit] = -1;
- return OK;
- }
-
- readCMOS( cmosp )
- struct cmos *cmosp;
- {
- int cmosfd;
-
- if ((cmosfd = open(CMOSDEV, 0)) == -1) {
- perror("Opening cmos device");
- exit(1);
- }
- if ( sizeof(struct cmos) != read(cmosfd, cmosp, sizeof(struct cmos))) {
- perror("Reading cmos device");
- exit(1);
- }
- close(cmosfd);
- }
-
- writeCMOS( cmosp )
- struct cmos *cmosp;
- {
- unsigned int cksum, i;
- unsigned char *c;
- int cmosfds[unit];
-
- /* calculate new checksum */
- c = (unsigned char *) &cmos;
- cksum = 0;
- for(i=0x10; i<0x21; i++)
- cksum += *(c+i);
- /* Set new checksum */
- *(c + 0x2e ) = cksum >> 8; /* this is also known as cmos.cksum */
- *(c + 0x2f ) = cksum ;
-
- if ((cmosfd = open(CMOSDEV, 1)) == -1) {
- perror("Opening cmos device");
- exit(1);
- }
- if ( sizeof(struct cmos) != write(cmosfd, cmosp, sizeof(struct cmos))) {
- perror("writing cmos device");
- exit(1);
- }
- close(cmosfd);
- }
-
- /*
- * read or write a sector by disk address (cyl,head,sector)
- */
-
- read_sector(unit, buf, cyl, head, sector)
- int unit; /* NOTE THIS CHANGE! */
- byte *buf,head,sector;
- int cyl;
- {
- int i;
- struct i1010iopb *io, iopb;
-
- if (fds[unit] == -1) {
- init( unit );
- }
- io = &iopb;
- io->i_addr = (long) buf;
- io->i_actcylinder = cyl;
- io->i_acthead = head;
- io->i_sector = sector;
- io->i_funct = WD_READ_OP;
- i = ioctl(fds[unit],I1010_RAWIO,io);
- #ifndef PRODUCTION
- if (i)
- fprintf(stderr, "\nread_sector(U=%d, C=%d, H=%d, S=%d) errno= %d\n",
- unit, cyl, head, sector, i);
- #endif
- return(i);
- }
-
- write_sector(unit,buf,cyl,head,sector)
- int unit;
- byte *buf,head,sector;
- int cyl;
- {
- int i;
- struct i1010iopb *io, iopb;
-
- if (fds[unit] == -1) {
- init( unit );
- }
-
- #ifdef NOWRITE
- return(0);
- #endif
-
- io = &iopb;
- io->i_addr = (long) buf;
- io->i_actcylinder = cyl;
- io->i_acthead = head;
- io->i_sector = sector;
- io->i_funct = WD_WRITE_OP;
- i = ioctl(fds[ unit ], I1010_RAWIO, io);
- #ifndef PRODUCTION
- if (i)
- fprintf(stderr, "\nwrite_sector(U=%d, C=%d, H=%d, S=%d) errno= %d\n",
- unit, cyl, head, sector, i);
- #endif
- return(i);
- }
-
- raw_io(unit,buf,cyl,head,sector,op)
- int unit;
- byte *buf,head,sector;
- int cyl,op;
- {
- int i;
- struct i1010iopb *io, iopb;
-
- if (fds[unit] == -1) {
- init( unit );
- }
- io = &iopb;
- io->i_addr = (long) buf;
- io->i_actcylinder = cyl;
- io->i_acthead = head;
- io->i_sector = sector;
- io->i_funct = op;
- i = ioctl(fds[ unit ], I1010_RAWIO, io);
- #ifndef PRODUCTION
- if (i) printf("\nRaw I/O( U=%d C=%d H=%d S=%d op=%d) errno= %d\n",
- unit, cyl, head, sector, op, i);
- #endif
- return(i);
- }
-
-