home *** CD-ROM | disk | FTP | other *** search
/ ftp.cdrom.com/pub/cdrom/ / cdrom.tar / cdrom / source / setreclen.c < prev    next >
Text File  |  1993-03-02  |  4KB  |  157 lines

  1. Article 8282 (28 more) in alt.cd-rom:
  2. From: kkaempf@didymus.rmi.de (Klaus Kaempf)
  3. Subject: Re: Sun/Solaris & Standard CD ROM Drives
  4. Message-ID: <C31xBC.LHt@didymus.rmi.de>
  5. Organization: Klaus Kaempf Softwareentwicklung
  6. References: <1m196oINNls2@usenet.INS.CWRU.Edu> <1me3h4INNj73@meaddata.meaddata.com>
  7. Date: Fri, 26 Feb 1993 10:33:11 GMT
  8. Lines: 147
  9.  
  10.  
  11. Hi folks !
  12.  
  13. This debate about CDROM drives and Suns is as old as this newsgroup.
  14. There is a cheap solution (at least for SunOS 4.x, don't know about
  15. Solaris 2 yet) and source is included below.
  16. You still can't boot with the drive since the *stupid* OpenProm Boot
  17. code doesn't set the record lenght to 512bytes. But what you can do
  18. is compile the following program (it expects /dev/rsr0 as the drive,
  19. change line 22 if it's something else) and put it in your 'rc.local'.
  20.  
  21. Ttttttthats all folks !
  22.  
  23. Klaus
  24. ------------->--cut here--<----------------
  25. /*
  26.  * setreclen.c
  27.  *
  28.  * set record length of CDROM to 512bytes
  29.  *
  30.  * This came along the net a while ago
  31.  * I cleaned it up and added some debug code
  32.  * Have fun !
  33.  * Klaus Kaempf, kkaempf@didymus.rmi.de
  34.  *
  35.  */
  36.  
  37. # include <sys/types.h>
  38. # include <sys/buf.h>
  39. # include <sun/dkio.h>
  40. # include <scsi/targets/srdef.h>
  41. # include <scsi/impl/uscsi.h>
  42. # include <strings.h>
  43.  
  44. # include <stdio.h>
  45.  
  46. char cdrom[] =  "/dev/rsr0";
  47.  
  48. extern char *   cdrom_status();
  49.  
  50. /* group 0 commands */
  51.  
  52. #define TEST            0x00
  53. #define REZERO          0x01
  54. #define SENSEREQ        0x03
  55. #define READ            0x08
  56. #define SEEK            0x0b
  57. #define NOP             0x0d
  58. #define INQ             0x12
  59. #define MODESEL         0x15
  60. #define RESERVE         0x16
  61. #define RELEASE         0x17
  62. #define MODESENSE       0x1a
  63. #define STARTSTOP       0x1b
  64. #define DIAGRCV         0x1c
  65. #define DIAGSND         0x1d
  66. #define MEDIUMLOCK      0x1e
  67.  
  68. /* group 1 commands */
  69.  
  70. #define READCAP         0x25
  71. #define READEXT         0x28
  72. #define SEEKEXT         0x2b
  73.  
  74. /* group 6 commands */
  75.  
  76. #define AUDIOTRACK      0xc0
  77. #define AUDIOPLAY       0xc1
  78. #define AUDIOSTILL      0xc2
  79. #define AUDIOSTOP       0xc3
  80. #define EJECT           0xc4
  81. #define CLOSE           0xc5
  82. #define AUDIOSUB        0xc6
  83. #define AUDIODISK       0xc7
  84. #define ROMMODE         0xc8
  85.  
  86. /***/
  87.  
  88. #define CMDLEN(cmd) ((cmd >= 0x20) ? 10 :  6)
  89.  
  90. /***/
  91. #define UBUFLEN 4096
  92.  
  93. static void showhex(why, what, len)
  94. char *why;
  95. unsigned char *what;
  96. int len;
  97. {
  98.         fprintf(stderr,"Showhex %s\n", why);
  99.         while (len > 0) {
  100.                 fprintf(stderr,"%02x ", *what++);
  101.                 len--;
  102.         }
  103.         fprintf(stderr,"\n");
  104.         return;
  105. }
  106.  
  107.  
  108. main() {
  109. int                     fd;
  110. int                     i;
  111. struct uscsi_cmd        ucmd;
  112. char *                  s_command;
  113. char *                  s_buffer;
  114.  
  115.         if ((fd = open(cdrom, 0)) == -1) {
  116.                 fprintf(stderr, "open: ");
  117.                 perror(cdrom);
  118.                 exit(1);
  119.         }
  120.         s_command = (char *) malloc(10);
  121.         if (s_command == NULL) {
  122.                 printf("malloc error (command)\n");
  123.                 exit(-1);
  124.         }
  125.         bzero(s_command, 10);
  126.         s_buffer = (char *) malloc(UBUFLEN);
  127.         if (s_buffer == NULL) {
  128.                 printf("malloc error (buffer)\n");
  129.                 exit(-1);
  130.         }
  131.         bzero(s_buffer, UBUFLEN);
  132.         s_command[0] = MODESEL;
  133.         s_command[1] = 0x10;
  134.         s_command[4] = 12;
  135.         s_buffer[3] = 0x08;
  136.         s_buffer[10] = 0x02;
  137.         ucmd.uscsi_cdb = s_command;
  138.         ucmd.uscsi_cdblen = 6;
  139.         ucmd.uscsi_bufaddr = s_buffer;
  140.         ucmd.uscsi_buflen = UBUFLEN;
  141.         ucmd.uscsi_flags = USCSI_WRITE;
  142.         i = ioctl(fd, USCSICMD, ucmd);
  143. #if 1
  144.         showhex("ucmd", &ucmd, sizeof ucmd);
  145.         showhex("s_buffer", s_buffer, 256);
  146. #endif
  147.         close(fd);
  148.         exit(i);
  149. }
  150.  
  151. -------->--and here --<---------------
  152. -- 
  153. Klaus Kaempf                 E-Mail: kkaempf@didymus.rmi.de
  154. Jakobstr. 181                Fax:    0241-403407
  155. D-5100 Aachen                Voice:  0241-403446
  156.  
  157.