home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * INQUIREPAGE.C
- *
- * InquirePage -Ddevice -Uunit <pageno>
- *
- */
-
- #include <exec/types.h>
- #include <exec/ports.h>
- #include <exec/io.h>
- #include <exec/memory.h>
- #include <devices/scsidisk.h>
- #include <libraries/dos.h>
- #include <libraries/dosextens.h>
- #include <libraries/filehandler.h>
- #include <clib/exec_protos.h>
- #include <clib/alib_protos.h>
- #include <ctype.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- typedef unsigned char ubyte;
-
- typedef struct MsgPort MsgPort;
- typedef struct IOStdReq IOStdReq;
- typedef struct IORequest IORequest;
- typedef struct SCSICmd SCSICmd;
-
- typedef struct SCSIReq {
- IOStdReq sr_Req;
- SCSICmd sr_Cmd;
- } SCSIReq;
-
- MsgPort *IoSink;
- SCSIReq Ios;
-
- char *ErrorAry[] = {
- "No Sense",
- "Recovered Error",
- "Not Ready",
- "Medium Error",
- "Hardware Error",
- "Illegal Request",
- "Unit Attention",
- "Data Protect",
- "Blank Check",
- "Vendor Specific",
- "Copy Aborted",
- "Aborted Command",
- "Equal (search_data)",
- "Volume Overflow",
- "MisCompare",
- "Reserved"
- };
-
- char *PeripheralType[] = {
- "Direct Access Device (e.g. magnetic disk)",
- "Sequential Access Device (e.g. magnetic tape)",
- "Printer Device",
- "Processor Device",
- "Write-Once Device (e.g. WORM drive)",
- "CD-ROM Device",
- "Scanner Device",
- "Optical Memory Device (e.g. optical disks)",
- "Medium Changer Device (e.g. juke box)",
- "Communications Device",
- "TYPE 0x0A (Graphics Arts Pre-Press Devices)",
- "TYPE 0x0B (Graphics Arts Pre-Press Devices)",
- "TYPE 0x0C Reserved",
- "TYPE 0x0D Reserved",
- "TYPE 0x0E Reserved",
- "TYPE 0x0F Reserved",
- "TYPE 0x10 Reserved",
- "TYPE 0x11 Reserved",
- "TYPE 0x12 Reserved",
- "TYPE 0x13 Reserved",
- "TYPE 0x14 Reserved",
- "TYPE 0x15 Reserved",
- "TYPE 0x16 Reserved",
- "TYPE 0x17 Reserved",
- "TYPE 0x18 Reserved",
- "TYPE 0x19 Reserved",
- "TYPE 0x1A Reserved",
- "TYPE 0x1B Reserved",
- "TYPE 0x1C Reserved",
- "TYPE 0x1D Reserved",
- "TYPE 0x1E Reserved",
- "TYPE 0x1F Unknown or no Device type"
- };
-
- void myexit(void);
- int InquirePage(short);
- int SCSIOpen(char *, long);
- void SCSIClose(void);
- int DoSCSI(char *, char *, long, ubyte, long *);
-
- main(ac, av)
- char *av[];
- {
- short pageNo[64];
- short i;
- short j;
- char *deviceName = "scsi.device";
- long unitNoBeg = -1;
- long unitNoEnd = -1;
-
- atexit(myexit);
-
- IoSink = CreatePort(NULL, 0);
-
- for (i = 1, j = 0; i < ac; ++i) {
- char *ptr = av[i];
-
- if (*ptr != '-') {
- if (stricmp(ptr, "all") == 0) {
- unitNoBeg = 0;
- unitNoEnd = 7;
- } else {
- pageNo[j++] = strtol(ptr, NULL, 0);
- }
- continue;
- }
- ptr += 2;
- switch(ptr[-1]) {
- case 'D':
- deviceName = (*ptr) ? ptr : av[++i];
- break;
- case 'U':
- unitNoBeg = strtol((*ptr) ? ptr : av[++i], NULL, 0);
- unitNoEnd = unitNoBeg;
- break;
- default:
- puts("bad option");
- break;
- }
- }
- if (unitNoBeg < 0) {
- puts("InquirePage [-D device] -U unit [page_number]");
- puts("InquirePage all");
- exit(0);
- }
- if (unitNoBeg != unitNoEnd && j == 0)
- pageNo[j++] = 0;
-
- while (unitNoBeg <= unitNoEnd) {
- if (SCSIOpen(deviceName, unitNoBeg) < 0) {
- printf("Unable to open device %s unit %d\n", deviceName, unitNoBeg);
- } else {
- printf("DEVICE %s UNIT %d\n", deviceName, unitNoBeg);
- if (j == 0) {
- puts(" Reading all pages");
- for (i = 0; i < 0x100; ++i)
- InquirePage(i);
- } else {
- for (i = 0; i < j; ++i)
- InquirePage(pageNo[i]);
- }
- }
- ++unitNoBeg;
- SCSIClose();
- }
- return(0);
- }
-
- InquirePage(pageNo)
- short pageNo;
- {
- __aligned char inquireSenseCmd[] = { 0x12, 0x00, pageNo, 0x00, 0xFF, 0x00 };
- unsigned char buf[512];
- int error;
- long len;
-
- printf(" Inquire Page 0x%02x ", pageNo);
- if (error = DoSCSI(inquireSenseCmd, buf, sizeof(buf), SCSIF_READ, &len)) {
- char *errorStr = (error > 0 && error < 16) ? ErrorAry[error] : "?";
- printf("error code %2d (0x%02x) %s\n", error, error, errorStr);
- } else {
- short i;
- short j;
-
- printf("\n\t");
- for (i = 0; i < len; ++i) {
- if (i && (i & 7) == 0) {
- printf("\t");
- for (j = i - 8; j < i; ++j)
- printf("%c", isprint(buf[j]) ? buf[j] : '-');
- printf("\n\t");
- }
- printf(" %02x", buf[i]);
- }
- if (i) {
- for (j = i; j & 7; ++j)
- printf(" ");
- printf("\t");
- for (j = j - 8; j < i; ++j)
- printf("%c", isprint(buf[j]) ? buf[j] : '-');
- }
- puts("");
-
- if (pageNo == 0) {
- printf("\tPeripheral Device Type: %s\n", PeripheralType[buf[0] & 0x1F]);
- printf("\tRelAdr: %d (relative addressing mode supported)\n", (buf[7] & 128) ? 1 : 0);
- printf("\tWBus32: %d (32 bit wide transfers supported)\n", (buf[7] & 64) ? 1 : 0);
- printf("\tWBus16: %d (16 bit wide transfers supported)\n", (buf[7] & 32) ? 1 : 0);
- printf("\tSync: %d (synchronous transfers supported)\n", (buf[7] & 16) ? 1 : 0);
- printf("\tLinked: %d (linked commands supported)\n", (buf[7] & 8 ) ? 1 : 0);
- printf("\tReserved: %d\n", (buf[7] & 4) ? 1 : 0);
- printf("\tCmdQue: %d (tagged command queuing supported)\n",(buf[7] & 2 ) ? 1 : 0);
- printf("\tSftRe: %d (Soft-reset on RESET cond, else hard)\n", (buf[7] & 1) ? 1 : 0);
- }
- }
- return(error);
- }
-
- void
- myexit(void)
- {
- SCSIClose();
- if (IoSink)
- DeletePort(IoSink);
- }
-
-
- int
- SCSIOpen(devName, unitNo)
- char *devName;
- long unitNo;
- {
- int error;
-
- Ios.sr_Req.io_Message.mn_ReplyPort = IoSink;
- if (error = OpenDevice(devName, unitNo, (IORequest *)&Ios.sr_Req, 0))
- error = -1;
- return(error);
- }
-
- void
- SCSIClose()
- {
- if (Ios.sr_Req.io_Device) {
- CloseDevice((IORequest *)&Ios);
- Ios.sr_Req.io_Device = NULL;
- }
- }
-
- int
- DoSCSI(cmd, buf, bytes, flags, len)
- char *cmd;
- char *buf;
- long bytes;
- ubyte flags;
- long *len;
- {
- static ubyte senseCmd[] = { 0x03, 0x00, 0x00, 0x00, 20, 0 };
- SCSIReq *ios = &Ios;
- char senseBuf[20];
- int error;
-
- ios->sr_Cmd.scsi_Command = cmd;
- ios->sr_Cmd.scsi_CmdLength = 6;
- ios->sr_Cmd.scsi_Data = buf;
- ios->sr_Cmd.scsi_Length = bytes;
- ios->sr_Cmd.scsi_Flags = flags;
-
- ios->sr_Req.io_Command = 28;
- ios->sr_Req.io_Data = &ios->sr_Cmd;
- ios->sr_Req.io_Length = sizeof(ios->sr_Cmd);
-
- error = DoIO((IORequest *)&ios->sr_Req);
- if (len)
- *len = ios->sr_Cmd.scsi_Actual;
-
- switch(error) {
- case 0:
- break;
- case HFERR_BadStatus:
- ios->sr_Cmd.scsi_Command = senseCmd;
- ios->sr_Cmd.scsi_CmdLength = 6;
- ios->sr_Cmd.scsi_Data = (UWORD *)senseBuf;
- ios->sr_Cmd.scsi_Length = sizeof(senseBuf);
- ios->sr_Cmd.scsi_Flags = SCSIF_READ;
-
- if (DoIO((IORequest *)&ios->sr_Req)) {
- error = -256;
- break;
- }
- if (ios->sr_Cmd.scsi_Actual < 4) {
- error = -257;
- break;
- }
- error = senseBuf[2];
- break;
- default:
- error = -error;
- break;
- }
- return(error);
- }
-
-