1 /* Mammoth 2 Debug Buffer Dumper
2 Copyright 2000 Enhanced Software Technologies Inc.
3 Copyright 2007-2008 by Robert Nelson <robertn@the-nelsons.org>
5 $Date: 2008-08-19 03:03:38 -0700 (Tue, 19 Aug 2008) $
8 Written by Eric Lee Green <eric@badtux.org>
9 Released under the terms of the GNU General Public License v2 or
12 This is an example of how to use the mtx library file 'mtxl.c' to
13 do a special-purpose task -- dump the Mammoth2 debug buffer, in this case.
14 Note that this debug buffer is 1M-4M in size, thus may overwhelm the
15 SCSI generic subsystem on some supported platforms...
19 mam2debug generic-filename output-filename.
25 #include <sys/types.h>
32 /* This is a TOTALLY UNDOCUMENTED feature to read the debug data buffer
33 * in an Exabyte Mammoth II and dump it to a file:
36 static RequestSense_T *DumpM2DebugBuff(DEVICE_TYPE MediumChangerFD, int outfile)
38 RequestSense_T *RequestSense = xmalloc(sizeof(RequestSense_T));
41 unsigned char *databuffer;
42 unsigned char buff_descriptor[4];
46 CDB[0]=0x3c; /* command. */
47 CDB[1]=0x03; /* mode - read buff_descriptor! */
48 CDB[2]=0x00; /* page -- data. */
49 CDB[3]=0; /* offset. */
52 CDB[6]=0; /* length. */
54 CDB[8]=4; /* the descriptor is 4 long. */
57 if ((testbytes=SCSI_ExecuteCommand(MediumChangerFD, Input, &CDB, 10,
58 buff_descriptor, 4, RequestSense)) != 0){
59 fprintf(stderr,"mam2debug: could not read buff_descriptor. [%d]\n",testbytes);
60 return RequestSense; /* couldn't do it. */
63 /* okay, read numbytes: */
64 numbytes=(buff_descriptor[1]<<16) + (buff_descriptor[2]<<8) + buff_descriptor[3];
65 databuffer=(unsigned char *) xmalloc(numbytes+1000000); /* see if this helps :-(. */
66 CDB[6]=buff_descriptor[1];
67 CDB[7]=buff_descriptor[2];
68 CDB[8]=buff_descriptor[3];
70 CDB[1]=0x02; /* mode -- read buffer! */
72 if (SCSI_ExecuteCommand(MediumChangerFD, Input, &CDB, 10,
73 databuffer, numbytes, RequestSense) != 0){
74 fprintf(stderr,"mam2debug: could not read buffer.\n");
76 return RequestSense; /* couldn't do it. */
79 write(outfile,databuffer,numbytes);
83 return NULL; /* okay! */
86 static void usage(void) {
87 fprintf(stderr,"Usage: mam2debug scsi-generic-file output-file-name\n");
91 /* Now for the actual main() routine: */
93 int main(int argc,char** argv) {
94 DEVICE_TYPE changer_fd;
95 static RequestSense_T *result;
102 changer_fd=SCSI_OpenDevice(argv[1]);
104 if (changer_fd <= 0) {
105 fprintf(stderr,"Could not open input device\n");
109 outfile=open(argv[2],O_CREAT|O_WRONLY);
111 fprintf(stderr,"Could not open output file\n");
115 result=DumpM2DebugBuff(changer_fd, outfile);
118 PrintRequestSense(result);