home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- #include <fcntl.h>
- #include "sdce.h"
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- int fd;
- int target;
- int type;
- int i;
- union sdce_usr_data mydata;
- char *ptr;
- char kbd;
-
- target = 0;
- type = 0; /* if type == 0 then hard disk. if type == 5 then CDrom */
- ptr = mydata.fwv;
- if ((fd=open("/dev/host/rsDCE0", O_RDONLY))< 0){
- perror("OPEN: ");
- exit(-1);
- }
- printf("\n\tPlease enter your choice \n");
- printf("\n\tGet Version Number : 1\n");
- printf("\tGet Cache Statistics : 2\n");
- printf("\tGet Disk Paramters : 3\n");
- printf("\tFlush the Cache : 4\n");
- printf("\tSet Controller Params: 5\n");
-
- switch (kbd = getchar()){
-
- case 0x31 :
- /*
- * Display the hardware version number from the Card.
- * This will be the same number displayed by the driver
- * boot message.
- */
- strcpy(" ",ptr);
- if (ioctl(fd, FRMWR_VERSION, &mydata) < 0){
- perror("IOCTL: FRMWR_VERSION");
- exit(-1);
- }
- printf("DCE 376 firmware %s\n\n", mydata.fwv);
- break;
-
- case 0x32 :
- /*
- * Display the cache statistics for the card.
- */
- if (ioctl(fd, CACHE_STATS, &mydata) < 0){
- perror("IOCTL: CACHE_STATS");
- exit(-1);
- }
- printf("\n\t\tDCE 376 Cache Stats\n");
- printf("\tReads\t Cache Misses on Reads\t Writes\n");
- printf("\t===========================================\n");
- printf("\t%6d %6d %6d\n",
- mydata.cstat[0],mydata.cstat[1],mydata.cstat[2]);
- break;
-
- case 0x33 :
- /*
- * Display the drive paramters
- */
- mydata.dtype = type;
- if (ioctl(fd, DRIVE_PARAM, &mydata) < 0){
- perror("IOCTL: DRIVE_PARAM");
- exit(-1);
- }
- i = 0;
- printf("\n\t\tDCE 376 Disk Drive Params\n");
- printf("\tID Heads Cylinders Sec/Trk Bytes/Sec\n");
- printf("\t======================================================\n");
- while ( mydata.hd[i].id != -1 ){
- printf("\t %d\t %d\t %4d\t %2d\t\t%3d\n",
- mydata.hd[i].id,mydata.hd[i].hds,
- mydata.hd[i].cyl,mydata.hd[i].spt,
- mydata.hd[i].bps);
- i++;
- }
- printf("\n");
- break;
-
- case 0x34 :
- /*
- * Flush the Host Controller Cache memory. Much like
- * unix sync.
- */
- if (ioctl(fd, CACHE_FLUSH, &mydata) < 0){
- perror("IOCTL: CACHE_FLUSH");
- exit(-1);
- }
- printf("DCE 376 Cache Flushed\n");
- break;
-
- case 0x35 :
- /*
- * Set the Host Controller Cache Parameters.
- * Must be root to use this one.
- */
- mydata.cp.parameter = 0x02;/*0x02=8K blocks,0x00=4K blocks */
-
- /* flag contolls parameters to set */
- /* 0 value for bits means no change */
- mydata.cp.flag = 0x0e;/* 0x02 = set block size */
- /* 0x04 = set write threshold */
- /* 0x08 = set inactivity period */
-
- /* The number of updated (write) buffers */
- /* allowed before flushing to disk. The */
- mydata.cp.wrt_threshold = 26;/*Legal values are 1 - 31 */
- /* Default is 26. */
-
- mydata.cp.inactivity = 2;/* Flush the cache to disk if there*/
- /* have been no commands in this many */
- /* seconds. The legal values are 1 - 15.*/
- /* Default depending on firmware is */
- /* from 1 to 3 seconds. Usually 1 now. */
-
- if (ioctl(fd, SET_CTRL_PARM, &mydata) < 0){
- perror("IOCTL: SET_CTRL_PARM");
- exit(-1);
- }
- printf("DCE Cache Parameters Set\n");
- break;
-
- default : printf("Bad Option\n");
-
- }
- /*
- * The code below can kill your data on the drive !!!
-
- *
- * Recalibrate the driver ID.
- *
- mydata.target = 0;
- if (ioctl(fd, RECAL_DRIVE, &mydata) < 0){
- perror("IOCTL: DRIVE_DIAG");
- exit(-1);
- }
- printf("Recalibration of Drive %d Complete\n",mydata.target);
- sleep(2);
- *
- * Run Dianostics on drive ID.
- *
- mydata.target = 0;
- if (ioctl(fd, DRIVE_DIAG, &mydata) < 0){
- perror("IOCTL: DRIVE_DIAG");
- exit(-1);
- }
- printf("Diagnostics for Drive %d Complete\n",mydata.target);
- sleep(2);
- *
- * Format the drive ID. This can be a data killer!
- *
- mydata.target = 0;
- if (ioctl(fd, FORMAT_DRIVE, &mydata) < 0){
- perror("IOCTL: FORMAT_DRIVE");
- exit(-1);
- }
- printf("Format of Drive %d Complete\n",mydata.target);
- *
- */
- close(fd);
- }
-
- /******************************************************************
- *
- * FOR DEMO ONLY Don't try these unless you know your drives
- * have backups or you don't care! You will have to be root
- * to run these.
- *
- /******************************************************************
-
- if (ioctl(fd, SET_CTRL_PARM, &mydata) < 0){
- perror("IOCTL: SET_CTRL_PARMS");
- exit(-1);
- }
- printf("DCE Cache Paramters Set\n");
-
- mydata.target = 0;
- if (ioctl(fd, FORMAT_DRIVE, &mydata) < 0){
- perror("IOCTL: FORMAT_DRIVE");
- exit(-1);
- }
- printf("Format of Drive %d Complete\n",target);
-
- mydata.target = 0;
- if (ioctl(fd, DRIVE_DIAG, &mydata) < 0){
- perror("IOCTL: DRIVE_DIAG");
- exit(-1);
- }
- printf("Diagnostics for Drive %d Complete\n",target);
-
- mydata.target = 0;
- if (ioctl(fd, RECAL_DRIVE, &mydata) < 0){
- perror("IOCTL: DRIVE_DIAG");
- exit(-1);
- }
- printf("Recalibration of Drive %d Complete\n",target);
- */
-