comparison libmpdvdkit2/bsdi_ioctl.c @ 7027:c9a4dfaa9868

importing libdvdcss 1.2.2 files
author arpi
date Fri, 16 Aug 2002 22:35:45 +0000
parents
children f0f0f176d298
comparison
equal deleted inserted replaced
7026:a3126e9099b4 7027:c9a4dfaa9868
1 #include "config.h"
2
3 /*
4 * Hacked version of the linux cdrom.c kernel module - everything except the
5 * DVD handling ripped out and the rest rewritten to use raw SCSI commands
6 * on BSD/OS 4.2 (but should work with earlier versions as well).
7 */
8
9 #include <sys/types.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <errno.h>
13 #include <unistd.h>
14 #include <sys/ioctl.h>
15 #include </sys/dev/scsi/scsi.h>
16 #include </sys/dev/scsi/scsi_ioctl.h>
17
18 #include "bsdi_dvd.h"
19
20 /*
21 * Now get rid of the override/intercept macro so we can call the real ioctl()
22 * routine!
23 */
24 #undef ioctl
25
26 #define CMD_READ_10 0x28
27 #define CMD_READ_TOC_PMA_ATIP 0x43
28 #define CMD_READ_CD 0xbe
29 #define CMD_START_STOP_UNIT 0x1b
30
31 #define CMD_SEND_KEY 0xa3
32 #define CMD_REPORT_KEY 0xa4
33 #define CMD_READ_DVD_STRUCTURE 0xad
34
35 #define copy_key(dest,src) memcpy((dest), (src), sizeof(dvd_key))
36 #define copy_chal(dest,src) memcpy((dest), (src), sizeof(dvd_challenge))
37
38 /* Define the Cdrom Generic Command structure */
39 typedef struct cgc
40 {
41 u_char cdb[12];
42 u_char *buf;
43 int buflen;
44 int rw;
45 int timeout;
46 scsi_user_sense_t *sus;
47 } cgc_t;
48
49 static int scsi_cmd(int, cgc_t *);
50 static int cdrom_ioctl(int, u_long, void *);
51 static int cdrom_tray_move(int, int);
52 static int dvd_ioctl(int, u_long, void *);
53 static int debug;
54
55 void dvd_cdrom_debug(int flag)
56 {
57 debug = flag;
58 }
59
60 /*
61 * This is the published entry point. Actually applications should simply
62 * include <dvd.h> and not refer to this at all.
63 */
64 int dvd_cdrom_ioctl(int fd, unsigned long cmd, void *arg)
65 {
66 switch (cmd)
67 {
68 case DVD_AUTH:
69 case DVD_READ_STRUCT:
70 return(dvd_ioctl(fd, cmd, arg));
71 case CDROMREADTOCHDR:
72 case CDROMREADTOCENTRY:
73 case CDROMEJECT:
74 case CDROMREADRAW:
75 case CDROMREADMODE2:
76 case CDROMCLOSETRAY:
77 case CDROM_DRIVE_STATUS:
78 return(cdrom_ioctl(fd, cmd, arg));
79 default:
80 return(ioctl(fd, cmd, arg));
81 }
82 }
83
84 static void setup_report_key(cgc_t *cgc, u_int agid, u_int type)
85 {
86
87 cgc->cdb[0] = CMD_REPORT_KEY;
88 cgc->cdb[10] = type | (agid << 6);
89 switch (type)
90 {
91 case 0:
92 case 5:
93 case 8:
94 cgc->buflen = 8;
95 break;
96 case 1:
97 cgc->buflen = 16;
98 break;
99 case 2:
100 case 4:
101 cgc->buflen = 12;
102 break;
103 }
104 cgc->cdb[9] = cgc->buflen;
105 cgc->rw = SUC_READ;;
106 }
107
108 static void setup_send_key(cgc_t *cgc, u_int agid, u_int type)
109 {
110
111 cgc->cdb[0] = CMD_SEND_KEY;
112 cgc->cdb[10] = type | (agid << 6);
113 switch (type)
114 {
115 case 1:
116 cgc->buflen = 16;
117 break;
118 case 3:
119 cgc->buflen = 12;
120 break;
121 case 6:
122 cgc->buflen = 8;
123 break;
124 }
125 cgc->cdb[9] = cgc->buflen;
126 cgc->rw = SUC_WRITE;
127 }
128
129 static void cgc_init(cgc_t *cgc, void *buf, int len, int type)
130 {
131
132 memset(cgc, 0, sizeof (*cgc));
133 if (buf)
134 memset(buf, 0, len);
135 cgc->buf = (u_char *)buf;
136 cgc->buflen = len;
137 cgc->rw = type;
138 cgc->timeout = 5; /* 5 second timeout */
139 }
140
141 static int dvd_do_auth(int fd, dvd_authinfo *ai)
142 {
143 int ret;
144 u_char buf[20];
145 cgc_t cgc;
146 rpc_state_t rpc_state;
147
148 memset(buf, 0, sizeof(buf));
149 cgc_init(&cgc, buf, 0, SUC_READ);
150
151 switch (ai->type)
152 {
153 case DVD_LU_SEND_AGID: /* LU data send */
154 setup_report_key(&cgc, ai->lsa.agid, 0);
155 if (ret = scsi_cmd(fd, &cgc))
156 return ret;
157 ai->lsa.agid = buf[7] >> 6;
158 break;
159 case DVD_LU_SEND_KEY1:
160 setup_report_key(&cgc, ai->lsk.agid, 2);
161 if (ret = scsi_cmd(fd, &cgc))
162 return ret;
163 copy_key(ai->lsk.key, &buf[4]);
164 break;
165 case DVD_LU_SEND_CHALLENGE:
166 setup_report_key(&cgc, ai->lsc.agid, 1);
167 if (ret = scsi_cmd(fd, &cgc))
168 return ret;
169 copy_chal(ai->lsc.chal, &buf[4]);
170 break;
171 case DVD_LU_SEND_TITLE_KEY: /* Post-auth key */
172 setup_report_key(&cgc, ai->lstk.agid, 4);
173 cgc.cdb[5] = ai->lstk.lba;
174 cgc.cdb[4] = ai->lstk.lba >> 8;
175 cgc.cdb[3] = ai->lstk.lba >> 16;
176 cgc.cdb[2] = ai->lstk.lba >> 24;
177 if (ret = scsi_cmd(fd, &cgc))
178 return ret;
179 ai->lstk.cpm = (buf[4] >> 7) & 1;
180 ai->lstk.cp_sec = (buf[4] >> 6) & 1;
181 ai->lstk.cgms = (buf[4] >> 4) & 3;
182 copy_key(ai->lstk.title_key, &buf[5]);
183 break;
184 case DVD_LU_SEND_ASF:
185 setup_report_key(&cgc, ai->lsasf.agid, 5);
186 if (ret = scsi_cmd(fd, &cgc))
187 return ret;
188 ai->lsasf.asf = buf[7] & 1;
189 break;
190 case DVD_HOST_SEND_CHALLENGE: /* LU data receive (LU changes state) */
191 setup_send_key(&cgc, ai->hsc.agid, 1);
192 buf[1] = 0xe;
193 copy_chal(&buf[4], ai->hsc.chal);
194 if (ret = scsi_cmd(fd, &cgc))
195 return ret;
196 ai->type = DVD_LU_SEND_KEY1;
197 break;
198 case DVD_HOST_SEND_KEY2:
199 setup_send_key(&cgc, ai->hsk.agid, 3);
200 buf[1] = 0xa;
201 copy_key(&buf[4], ai->hsk.key);
202 if (ret = scsi_cmd(fd, &cgc))
203 {
204 ai->type = DVD_AUTH_FAILURE;
205 return ret;
206 }
207 ai->type = DVD_AUTH_ESTABLISHED;
208 break;
209 case DVD_INVALIDATE_AGID:
210 setup_report_key(&cgc, ai->lsa.agid, 0x3f);
211 if (ret = scsi_cmd(fd, &cgc))
212 return ret;
213 break;
214 case DVD_LU_SEND_RPC_STATE: /* Get region settings */
215 setup_report_key(&cgc, 0, 8);
216 memset(&rpc_state, 0, sizeof(rpc_state_t));
217 cgc.buf = (char *) &rpc_state;
218 if (ret = scsi_cmd(fd, &cgc))
219 {
220 ai->lrpcs.type = 0;
221 ai->lrpcs.rpc_scheme = 0;
222 }
223 else
224 {
225 ai->lrpcs.type = rpc_state.type_code;
226 ai->lrpcs.vra = rpc_state.vra;
227 ai->lrpcs.ucca = rpc_state.ucca;
228 ai->lrpcs.region_mask = rpc_state.region_mask;
229 ai->lrpcs.rpc_scheme = rpc_state.rpc_scheme;
230 }
231 break;
232 case DVD_HOST_SEND_RPC_STATE: /* Set region settings */
233 setup_send_key(&cgc, 0, 6);
234 buf[1] = 6;
235 buf[4] = ai->hrpcs.pdrc;
236 if (ret = scsi_cmd(fd, &cgc))
237 return ret;
238 break;
239 default:
240 return EINVAL;
241 }
242 return 0;
243 }
244
245 static int dvd_read_physical(int fd, dvd_struct *s)
246 {
247 int ret, i;
248 u_char buf[4 + 4 * 20], *base;
249 struct dvd_layer *layer;
250 cgc_t cgc;
251
252 cgc_init(&cgc, buf, sizeof(buf), SUC_READ);
253 cgc.cdb[0] = CMD_READ_DVD_STRUCTURE;
254 cgc.cdb[6] = s->physical.layer_num;
255 cgc.cdb[7] = s->type;
256 cgc.cdb[9] = cgc.buflen & 0xff;
257
258 if (ret = scsi_cmd(fd, &cgc))
259 return ret;
260
261 base = &buf[4];
262 layer = &s->physical.layer[0];
263
264 /* place the data... really ugly, but at least we won't have to
265 worry about endianess in userspace or here. */
266 for (i = 0; i < 4; ++i, base += 20, ++layer)
267 {
268 memset(layer, 0, sizeof(*layer));
269 layer->book_version = base[0] & 0xf;
270 layer->book_type = base[0] >> 4;
271 layer->min_rate = base[1] & 0xf;
272 layer->disc_size = base[1] >> 4;
273 layer->layer_type = base[2] & 0xf;
274 layer->track_path = (base[2] >> 4) & 1;
275 layer->nlayers = (base[2] >> 5) & 3;
276 layer->track_density = base[3] & 0xf;
277 layer->linear_density = base[3] >> 4;
278 layer->start_sector = base[5] << 16 | base[6] << 8 | base[7];
279 layer->end_sector = base[9] << 16 | base[10] << 8 | base[11];
280 layer->end_sector_l0 = base[13] << 16 | base[14] << 8 | base[15];
281 layer->bca = base[16] >> 7;
282 }
283 return 0;
284 }
285
286 static int dvd_read_copyright(int fd, dvd_struct *s)
287 {
288 int ret;
289 u_char buf[8];
290 cgc_t cgc;
291
292 cgc_init(&cgc, buf, sizeof(buf), SUC_READ);
293 cgc.cdb[0] = CMD_READ_DVD_STRUCTURE;
294 cgc.cdb[6] = s->copyright.layer_num;
295 cgc.cdb[7] = s->type;
296 cgc.cdb[8] = cgc.buflen >> 8;
297 cgc.cdb[9] = cgc.buflen & 0xff;
298
299 if (ret = scsi_cmd(fd, &cgc))
300 return ret;
301 s->copyright.cpst = buf[4];
302 s->copyright.rmi = buf[5];
303 return 0;
304 }
305
306 static int dvd_read_disckey(int fd, dvd_struct *s)
307 {
308 int ret, size;
309 u_char *buf;
310 cgc_t cgc;
311
312 size = sizeof(s->disckey.value) + 4;
313
314 if ((buf = (u_char *) malloc(size)) == NULL)
315 return ENOMEM;
316
317 cgc_init(&cgc, buf, size, SUC_READ);
318 cgc.cdb[0] = CMD_READ_DVD_STRUCTURE;
319 cgc.cdb[7] = s->type;
320 cgc.cdb[8] = size >> 8;
321 cgc.cdb[9] = size & 0xff;
322 cgc.cdb[10] = s->disckey.agid << 6;
323
324 if (!(ret = scsi_cmd(fd, &cgc)))
325 memcpy(s->disckey.value, &buf[4], sizeof(s->disckey.value));
326 free(buf);
327 return ret;
328 }
329
330 static int dvd_read_bca(int fd, dvd_struct *s)
331 {
332 int ret;
333 u_char buf[4 + 188];
334 cgc_t cgc;
335
336 cgc_init(&cgc, buf, sizeof(buf), SUC_READ);
337 cgc.cdb[0] = CMD_READ_DVD_STRUCTURE;
338 cgc.cdb[7] = s->type;
339 cgc.cdb[9] = cgc.buflen = 0xff;
340
341 if (ret = scsi_cmd(fd, &cgc))
342 return ret;
343 s->bca.len = buf[0] << 8 | buf[1];
344 if (s->bca.len < 12 || s->bca.len > 188)
345 return EIO;
346 memcpy(s->bca.value, &buf[4], s->bca.len);
347 return 0;
348 }
349
350 static int dvd_read_manufact(int fd, dvd_struct *s)
351 {
352 int ret = 0, size;
353 u_char *buf;
354 cgc_t cgc;
355
356 size = sizeof(s->manufact.value) + 4;
357
358 if ((buf = (u_char *) malloc(size)) == NULL)
359 return ENOMEM;
360
361 cgc_init(&cgc, buf, size, SUC_READ);
362 cgc.cdb[0] = CMD_READ_DVD_STRUCTURE;
363 cgc.cdb[7] = s->type;
364 cgc.cdb[8] = size >> 8;
365 cgc.cdb[9] = size & 0xff;
366
367 if (ret = scsi_cmd(fd, &cgc))
368 {
369 free(buf);
370 return ret;
371 }
372 s->manufact.len = buf[0] << 8 | buf[1];
373 if (s->manufact.len < 0 || s->manufact.len > 2048)
374 ret = -EIO;
375 else
376 memcpy(s->manufact.value, &buf[4], s->manufact.len);
377 free(buf);
378 return ret;
379 }
380
381 static int dvd_read_struct(int fd, dvd_struct *s)
382 {
383 switch (s->type)
384 {
385 case DVD_STRUCT_PHYSICAL:
386 return dvd_read_physical(fd, s);
387 case DVD_STRUCT_COPYRIGHT:
388 return dvd_read_copyright(fd, s);
389 case DVD_STRUCT_DISCKEY:
390 return dvd_read_disckey(fd, s);
391 case DVD_STRUCT_BCA:
392 return dvd_read_bca(fd, s);
393 case DVD_STRUCT_MANUFACT:
394 return dvd_read_manufact(fd, s);
395 default:
396 return EINVAL;
397 }
398 }
399
400 static u_char scsi_cdblen[8] = {6, 10, 10, 12, 12, 12, 10, 10};
401
402 static int scsi_cmd(int fd, cgc_t *cgc)
403 {
404 int scsistatus, cdblen;
405 unsigned char *cp;
406 struct scsi_user_cdb suc;
407
408 /* safety checks */
409 if (cgc->rw != SUC_READ && cgc->rw != SUC_WRITE)
410 return(EINVAL);
411
412 suc.suc_flags = cgc->rw;
413 cdblen = scsi_cdblen[(cgc->cdb[0] >> 5) & 7];
414 suc.suc_cdblen = cdblen;
415 bcopy(cgc->cdb, suc.suc_cdb, cdblen);
416 suc.suc_data = cgc->buf;
417 suc.suc_datalen = cgc->buflen;
418 suc.suc_timeout = cgc->timeout;
419 if (ioctl(fd, SCSIRAWCDB, &suc) == -1)
420 return(errno);
421 scsistatus = suc.suc_sus.sus_status;
422
423 /*
424 * If the device returns a scsi sense error and debugging is enabled print
425 * some hopefully useful information on stderr.
426 */
427 if (scsistatus && debug)
428 {
429 cp = suc.suc_sus.sus_sense;
430 fprintf(stderr,"scsistatus = %x cmd = %x\n",
431 scsistatus, cgc->cdb[0]);
432 fprintf(stderr, "sense %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n",
433 cp[0], cp[1], cp[2], cp[3], cp[4], cp[5],
434 cp[6], cp[7], cp[8], cp[9], cp[10], cp[11],
435 cp[12], cp[13], cp[14], cp[15]);
436 }
437 if (cgc->sus)
438 bcopy(&suc.suc_sus, cgc->sus, sizeof (struct scsi_user_sense));
439 if (scsistatus)
440 return(EIO); /* generic i/o error for unsuccessful status */
441 return(0);
442 }
443
444 /*
445 * The entry point for the DVDioctls for BSD/OS.
446 */
447 static int dvd_ioctl(int fd, u_long cmd, void *arg)
448 {
449 int ret;
450
451 switch (cmd)
452 {
453 case DVD_READ_STRUCT:
454 ret = dvd_read_struct(fd, (dvd_struct *)arg);
455 if (ret)
456 errno = ret;
457 return(ret ? -1 : 0);
458 case DVD_AUTH:
459 ret = dvd_do_auth (fd, (dvd_authinfo *)arg);
460 if (ret)
461 errno = ret;
462 return(ret ? -1 : 0);
463 default:
464 errno = EINVAL;
465 return(-1);
466 }
467 }
468
469 /*
470 * The entry point for the CDROMioctls for BSD/OS
471 */
472 static int cdrom_read_block(int, cgc_t *, int, int, int, int);
473 static int cdrom_read_cd(int, cgc_t *, int, int, int );
474 int cdrom_blocksize(int, int );
475
476 static inline
477 int msf_to_lba(char m, char s, char f)
478 {
479 return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
480 }
481
482 cdrom_ioctl(int fd, u_long cmd, void *arg)
483 {
484 int ret;
485 cgc_t cgc;
486
487 switch (cmd)
488 {
489 case CDROMREADRAW:
490 case CDROMREADMODE1:
491 case CDROMREADMODE2:
492 {
493 struct cdrom_msf *msf;
494 int blocksize = 0, format = 0, lba;
495
496 switch (cmd)
497 {
498 case CDROMREADRAW:
499 blocksize = CD_FRAMESIZE_RAW;
500 break;
501 case CDROMREADMODE1:
502 blocksize = CD_FRAMESIZE;
503 format = 2;
504 break;
505 case CDROMREADMODE2:
506 blocksize = CD_FRAMESIZE_RAW0;
507 break;
508 }
509 msf = (struct cdrom_msf *)arg;
510 lba = msf_to_lba(msf->cdmsf_min0,msf->cdmsf_sec0,
511 msf->cdmsf_frame0);
512 ret = EINVAL;
513 if (lba < 0)
514 break;
515
516 cgc_init(&cgc, arg, blocksize, SUC_READ);
517 ret = cdrom_read_block(fd, &cgc, lba, 1, format, blocksize);
518 if (ret)
519 {
520 /*
521 * SCSI-II devices are not required to support CMD_READ_CD (which specifies
522 * the blocksize to read) so try switching the block size with a mode select,
523 * doing the normal read sector command and then changing the sector size back
524 * to 2048.
525 *
526 * If the program dies before changing the blocksize back sdopen()
527 * in the kernel will fail opens with a message that looks something like:
528 *
529 * "sr1: blksize 2336 not multiple of 512: cannot use"
530 *
531 * At that point the drive has to be power cycled (or reset in some other way).
532 */
533 if (ret = cdrom_blocksize(fd, blocksize))
534 break;
535 ret = cdrom_read_cd(fd, &cgc, lba, blocksize, 1);
536 ret |= cdrom_blocksize(fd, 2048);
537 }
538 break;
539 }
540 case CDROMREADTOCHDR:
541 {
542 struct cdrom_tochdr *tochdr = (struct cdrom_tochdr *) arg;
543 u_char buffer[12];
544
545 cgc_init(&cgc, buffer, sizeof (buffer), SUC_READ);
546 cgc.cdb[0] = CMD_READ_TOC_PMA_ATIP;
547 cgc.cdb[1] = 0x2; /* MSF */
548 cgc.cdb[8] = 12; /* LSB of length */
549
550 ret = scsi_cmd(fd, &cgc);
551 if (!ret)
552 {
553 tochdr->cdth_trk0 = buffer[2];
554 tochdr->cdth_trk1 = buffer[3];
555 }
556 break;
557 }
558 case CDROMREADTOCENTRY:
559 {
560 struct cdrom_tocentry *tocentry = (struct cdrom_tocentry *) arg;
561 u_char buffer[12];
562
563 cgc_init(&cgc, buffer, sizeof (buffer), SUC_READ);
564 cgc.cdb[0] = CMD_READ_TOC_PMA_ATIP;
565 cgc.cdb[1] = (tocentry->cdte_format == CDROM_MSF) ? 0x02 : 0;
566 cgc.cdb[6] = tocentry->cdte_track;
567 cgc.cdb[8] = 12; /* LSB of length */
568
569 ret = scsi_cmd(fd, &cgc);
570 if (ret)
571 break;
572
573 tocentry->cdte_ctrl = buffer[5] & 0xf;
574 tocentry->cdte_adr = buffer[5] >> 4;
575 tocentry->cdte_datamode = (tocentry->cdte_ctrl & 0x04) ? 1 : 0;
576 if (tocentry->cdte_format == CDROM_MSF)
577 {
578 tocentry->cdte_addr.msf.minute = buffer[9];
579 tocentry->cdte_addr.msf.second = buffer[10];
580 tocentry->cdte_addr.msf.frame = buffer[11];
581 }
582 else
583 tocentry->cdte_addr.lba = (((((buffer[8] << 8)
584 + buffer[9]) << 8)
585 + buffer[10]) << 8)
586 + buffer[11];
587 break;
588 }
589 case CDROMEJECT: /* NO-OP for now */
590 ret = cdrom_tray_move(fd, 1);
591 break;
592 case CDROMCLOSETRAY:
593 ret = cdrom_tray_move(fd, 0);
594 break;
595 /*
596 * This sucks but emulates the expected behaviour. Instead of the return
597 * value being the actual status a success/fail indicator should have been
598 * returned and the 3rd arg to the ioctl should have been an 'int *' to update
599 * with the actual status.
600 */
601 case CDROM_DRIVE_STATUS:
602 return(CDS_NO_INFO);
603 break;
604 }
605 errno = ret;
606 return(ret ? -1 : 0);
607 }
608
609 static int cdrom_read_cd(int fd, cgc_t *cgc, int lba, int blocksize, int nblocks)
610 {
611
612 memset(&cgc->cdb, 0, sizeof(cgc->cdb));
613 cgc->cdb[0] = CMD_READ_10;
614 cgc->cdb[2] = (lba >> 24) & 0xff;
615 cgc->cdb[3] = (lba >> 16) & 0xff;
616 cgc->cdb[4] = (lba >> 8) & 0xff;
617 cgc->cdb[5] = lba & 0xff;
618 cgc->cdb[6] = (nblocks >> 16) & 0xff;
619 cgc->cdb[7] = (nblocks >> 8) & 0xff;
620 cgc->cdb[8] = nblocks & 0xff;
621 cgc->buflen = blocksize * nblocks;
622 return(scsi_cmd(fd, cgc));
623 }
624
625 static int cdrom_read_block(int fd, cgc_t *cgc,
626 int lba, int nblocks, int format, int blksize)
627 {
628
629 memset(&cgc->cdb, 0, sizeof(cgc->cdb));
630 cgc->cdb[0] = CMD_READ_CD;
631 /* expected sector size - cdda,mode1,etc. */
632 cgc->cdb[1] = format << 2;
633 /* starting address */
634 cgc->cdb[2] = (lba >> 24) & 0xff;
635 cgc->cdb[3] = (lba >> 16) & 0xff;
636 cgc->cdb[4] = (lba >> 8) & 0xff;
637 cgc->cdb[5] = lba & 0xff;
638 /* number of blocks */
639 cgc->cdb[6] = (nblocks >> 16) & 0xff;
640 cgc->cdb[7] = (nblocks >> 8) & 0xff;
641 cgc->cdb[8] = nblocks & 0xff;
642 cgc->buflen = blksize * nblocks;
643
644 /* set the header info returned */
645 switch (blksize)
646 {
647 case CD_FRAMESIZE_RAW0:
648 cgc->cdb[9] = 0x58;
649 break;
650 case CD_FRAMESIZE_RAW1:
651 cgc->cdb[9] = 0x78;
652 break;
653 case CD_FRAMESIZE_RAW:
654 cgc->cdb[9] = 0xf8;
655 break;
656 default:
657 cgc->cdb[9] = 0x10;
658 }
659 return(scsi_cmd(fd, cgc));
660 }
661
662 static int cdrom_tray_move(int fd, int flag)
663 {
664 cgc_t cgc;
665
666 cgc_init(&cgc, NULL, 0, SUC_READ);
667 cgc.cdb[0] = CMD_START_STOP_UNIT;
668 cgc.cdb[1] = 1; /* immediate */
669 cgc.cdb[4] = flag ? 0x2 : 0x3; /* eject : close */
670 return(scsi_cmd(fd, &cgc));
671 }
672
673 /*
674 * Required when we need to use READ_10 to issue other than 2048 block
675 * reads
676 */
677 int cdrom_blocksize(int fd, int size)
678 {
679 cgc_t cgc;
680 struct modesel_head mh;
681
682 memset(&mh, 0, sizeof(mh));
683 mh.block_desc_length = 0x08;
684 mh.block_length_med = (size >> 8) & 0xff;
685 mh.block_length_lo = size & 0xff;
686
687 memset(&cgc, 0, sizeof(cgc));
688 cgc.cdb[0] = 0x15;
689 cgc.cdb[1] = 1 << 4;
690 cgc.cdb[4] = 12;
691 cgc.buflen = sizeof(mh);
692 cgc.buf = (u_char *) &mh;
693 cgc.rw = SUC_WRITE;
694 mh.block_desc_length = 0x08;
695 mh.block_length_med = (size >> 8) & 0xff;
696 mh.block_length_lo = size & 0xff;
697 return(scsi_cmd(fd, &cgc));
698 }