1 /* Mammoth 2 Debug Buffer Dumper
2 Copyright 2000 Enhanced Software Technologies Inc.
4 $Date: 2001/06/05 17:10:21 $
7 Written by Eric Lee Green <eric@estinc.com>
8 Released under the terms of the GNU General Public License v2 or
11 This is an example of how to use the mtx library file 'mtxl.c' to
12 do a special-purpose task -- dump the Mammoth2 debug buffer, in this case.
13 Note that this debug buffer is 1M-4M in size, thus may overwhelm the
14 SCSI generic subsystem on some supported platforms...
18 mam2debug generic-filename output-filename.
24 #include <sys/types.h>
31 /* This is a TOTALLY UNDOCUMENTED feature to read the debug data buffer
32 * in an Exabyte Mammoth II and dump it to a file:
35 static RequestSense_T *DumpM2DebugBuff(DEVICE_TYPE MediumChangerFD, int outfile)
37 RequestSense_T *RequestSense = xmalloc(sizeof(RequestSense_T));
40 unsigned char *databuffer;
41 unsigned char buff_descriptor[4];
45 CDB[0]=0x3c; /* command. */
46 CDB[1]=0x03; /* mode - read buff_descriptor! */
47 CDB[2]=0x01; /* page. */
48 CDB[3]=0; /* offset. */
51 CDB[6]=0; /* length. */
53 CDB[8]=4; /* the descriptor is 4 long. */
56 if ((testbytes=SCSI_ExecuteCommand(MediumChangerFD, Input, &CDB, 10,
57 buff_descriptor, 4, RequestSense)) != 0){
58 fprintf(stderr,"mam2debug: could not read buff_descriptor. [%d]\n",testbytes);
59 return RequestSense; /* couldn't do it. */
62 /* okay, read numbytes: */
63 numbytes=(buff_descriptor[1]<<16) + (buff_descriptor[2]<<8) + buff_descriptor[3];
64 databuffer=(unsigned char *) xmalloc(numbytes+1000000); /* see if this helps :-(. */
65 CDB[6]=buff_descriptor[1];
66 CDB[7]=buff_descriptor[2];
67 CDB[8]=buff_descriptor[3];
69 CDB[1]=0x02; /* mode -- read buffer! */
71 if (SCSI_ExecuteCommand(MediumChangerFD, Input, &CDB, 10,
72 databuffer, numbytes, RequestSense) != 0){
73 fprintf(stderr,"mam2debug: could not read buffer.\n");
75 return RequestSense; /* couldn't do it. */
78 write(outfile,databuffer,numbytes);
82 return NULL; /* okay! */
85 static void usage(void) {
86 fprintf(stderr,"Usage: mam2debug scsi-generic-file output-file-name\n");
90 /* Now for the actual main() routine: */
92 int main(int argc,char** argv) {
93 DEVICE_TYPE changer_fd;
94 static RequestSense_T *result;
101 changer_fd=SCSI_OpenDevice(argv[1]);
103 if (changer_fd <= 0) {
104 fprintf(stderr,"Could not open input device\n");
108 outfile=open(argv[2],O_CREAT|O_WRONLY);
110 fprintf(stderr,"Could not open output file\n");
114 result=DumpM2DebugBuff(changer_fd, outfile);
117 PrintRequestSense(result);