2
* This file is part of WorkMan, the civilized CD player library
3
* (c) 1991-1997 by Steven Grimm (original author)
4
* (c) by Dirk Fļæ½rsterling (current 'author' = maintainer)
5
* The maintainer can be contacted by his e-mail address:
6
* milliByte@DeathsDoor.com
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Library General Public
10
* License as published by the Free Software Foundation; either
11
* version 2 of the License, or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Library General Public License for more details.
18
* You should have received a copy of the GNU Library General Public
19
* License along with this library; if not, write to the Free
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
* OSF drive control routines.
27
static char plat_osf_id[] = "$Id: plat_osf1.c,v 1.9 2001/04/10 17:34:52 dfoerste Exp $";
29
#if defined(__osf__) || defined(__osf)
34
#include <sys/types.h>
36
#include <sys/param.h>
41
/* #include <sys/rzdisk.h>
42
#include <sys/cdrom.h> */
43
#include <io/cam/rzdisk.h>
44
#include <io/cam/cdrom.h>
46
#include "include/wm_config.h"
47
#include "include/wm_struct.h"
48
#include "include/wm_helpers.h"
49
#include "include/wm_cdtext.h"
52
#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM
55
* This structure will be filled with the TOC header and all entries.
56
* Ultrix doesn't seem to allow getting single TOC entries.
57
* - Chris Ross (cross@eng.umd.edu)
59
struct cd_toc_header_and_entries
61
struct cd_toc_header cdth;
62
struct cd_toc_entry cdte[CDROM_MAX_TRACK+1];
71
extern char *cd_device;
76
* Simulate fgets, but joining continued lines in the output of uerf.
78
* platform specific internal function
82
#define BUF_SIZE 85 /* Max length of a (real) line */
87
static char *retval = NULL;
88
static char holdbuf[BUF_SIZE + 1];
89
char tmp[BUF_SIZE + 1];
94
retval = malloc(BUF_SIZE * 3); /* 3 lines can be joined */
103
strcpy(retval, holdbuf);
104
retval[strlen(retval)-1] = '\0';
105
memset(holdbuf, 0, BUF_SIZE+1);
108
while (fgets(tmp, BUF_SIZE, fp))
110
stmp = tmp + strspn(tmp, " \t");
111
if (*stmp == '_') { /* Continuation line */
112
retval[strlen(retval)-1] = '\0'; /* Trim off C/R */
113
strcat(retval, stmp+1);
117
strcpy(holdbuf, tmp);
118
holdbuf[strlen(holdbuf)-1] = -1;
120
} else { /* First line read, keep reading */
121
strcat(retval, stmp);
122
retval[strlen(retval)-1] = '\0';
133
* Determine the name of the CD-ROM device.
135
* Read through the boot records (via a call to uerf) and find the SCSI
136
* address of the CD-ROM.
145
extern char *getenv();
149
cd_device = getenv("CDROM");
151
** the path of the device has to start w/ /dev
152
** otherwise we are vulnerable to race conditions
153
** Thomas Biege <thomas@suse.de>
155
if ( cd_device == NULL ||
156
strncmp("/dev/", cd_device, 5) ||
157
strstr(cd_device, "/../")
161
if ((pid = fork()) == 0)
165
execl("/etc/uerf", "uerf", "-R", "-r", "300", NULL);
166
execl("/usr/sbin/uerf", "uerf", "-R", "-r", "300", NULL);
167
return 0; /* _exit(1); */
168
} else if (pid < 0) {
174
uerf = fdopen(fds[0], "r");
176
while (data = fgetline(uerf))
177
if (strstr(data, "RRD42"))
181
cd_device = (char *)malloc(sizeof("/dev/rrz##c"));
182
strcpy(cd_device, "/dev/r");
183
device = strstr(data, "rz");
184
device[(int)(strchr(device, ' ') - device)] = '\0';
185
strcat(cd_device, device);
186
strcat(cd_device, "c");
192
if (cd_device == NULL)
195
"No cdrom (RRD42) is installed on this system\n");
200
(void)wait((int *)NULL);
205
* Initialize the drive. A no-op for the generic driver.
208
gen_init( struct wm_drive *d )
214
* Open the CD device and figure out what kind of drive is attached.
217
wmcd_open( struct wm_drive *d )
220
static int warned = 0;
222
if (d->fd >= 0) /* Device already open? */
224
wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "wmcd_open(): [device is open (fd=%d)]\n", d->fd);
228
if (cd_device == NULL)
231
d->fd = open(cd_device, O_RDWR);
238
else if (errno != EINTR)
243
/* No CD in drive. */
247
/* Now fill in the relevant parts of the wm_drive structure. */
249
*d = *(find_drive_struct("", "", ""));
258
* Re-Open the device if it is open.
261
wmcd_reopen( struct wm_drive *d )
266
wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "wmcd_reopen\n");
267
if (d->fd >= 0) /* Device really open? */
269
wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device\n");
270
status = close( d->fd ); /* close it! */
271
/* we know, that the file is closed, do we? */
275
wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "calling wmcd_open()\n");
276
status = wmcd_open( d ); /* open it as usual */
278
} while ( status != 0 );
280
} /* wmcd_reopen() */
283
* Send an arbitrary SCSI command to a device.
286
wm_scsi(struct wm_drive *d, unsigned char *cdb, int cdblen,
287
void *retbuf, int retbuflen, int getreply)
289
/* OSF1 doesn't have a SCSI passthrough interface, does it? */
294
* Get the current status of the drive: the current play mode, the absolute
295
* position from start of disc (in frames), and the current track and index
296
* numbers if the CD is playing or paused.
299
gen_get_drive_status(struct wm_drive *d, enum wm_cd_modes oldmode,
300
enum wm_cd_modes *mode, int *pos, int *track, int *index)
302
struct cd_sub_channel sc;
303
struct cd_subc_channel_data scd;
305
/* If we can't get status, the CD is ejected, so default to that. */
306
*mode = WM_CDM_EJECTED;
308
sc.sch_address_format = CDROM_MSF_FORMAT;
309
sc.sch_data_format = CDROM_CURRENT_POSITION;
310
sc.sch_track_number = 0;
311
sc.sch_alloc_length = sizeof(scd);
312
sc.sch_buffer = (caddr_t)&scd;
314
/* Is the device open? */
317
switch (wmcd_open(d))
327
if (ioctl(d->fd, CDROM_READ_SUBCHANNEL, &sc))
328
return (0); /* ejected */
330
switch (scd.scd_header.sh_audio_status)
332
case AS_PLAY_IN_PROGRESS:
333
*mode = WM_CDM_PLAYING;
335
*pos = scd.scd_position_data.scp_absaddr.msf.m_units * 60 * 75 +
336
scd.scd_position_data.scp_absaddr.msf.s_units * 75 +
337
scd.scd_position_data.scp_absaddr.msf.f_units;
338
*track = scd.scd_position_data.scp_track_number;
339
*index = scd.scd_position_data.scp_index_number;
343
if (oldmode == WM_CDM_PLAYING || oldmode == WM_CDM_PAUSED)
345
*mode = WM_CDM_PAUSED;
349
*mode = WM_CDM_STOPPED;
352
case AS_PLAY_COMPLETED:
353
*mode = WM_CDM_TRACK_DONE; /* waiting for next track. */
357
*mode = WM_CDM_STOPPED;
364
} /* gen_get_drive_status() */
367
* Play the CD from one position to another (both in frames.)
370
gen_play( struct wm_drive *d, int start, int end )
372
struct cd_play_audio_msf msf;
374
msf.msf_starting_M_unit = start / (60*75);
375
msf.msf_starting_S_unit = (start % (60*75)) / 75;
376
msf.msf_starting_F_unit = start % 75;
377
msf.msf_ending_M_unit = end / (60*75);
378
msf.msf_ending_S_unit = (end % (60*75)) / 75;
379
msf.msf_ending_F_unit = end % 75;
381
if (ioctl(d->fd, SCSI_START_UNIT))
383
if (ioctl(d->fd, CDROM_PLAY_AUDIO_MSF, &msf))
393
gen_pause( struct wm_drive *d )
395
return (ioctl(d->fd, CDROM_PAUSE_PLAY, 0));
399
* Resume playing the CD (assuming it was paused.)
402
gen_resume( struct wm_drive *d )
404
return (ioctl(d->fd, CDROM_RESUME_PLAY, 0));
411
gen_stop( struct wm_drive *d )
413
return (ioctl(d->fd, SCSI_STOP_UNIT, 0));
417
* Eject the current CD, if there is one.
420
gen_eject(struct wm_drive *d)
422
/* On some systems, we can check to see if the CD is mounted. */
426
if (fstat(d->fd, &stbuf) != 0)
429
/* Is this a mounted filesystem? */
430
if (ustat(stbuf.st_rdev, &ust) == 0)
433
return (ioctl(d->fd, CDROM_EJECT_CADDY, 0));
436
/*----------------------------------------*
439
* Please edit and send changes to
440
* milliByte@DeathsDoor.com
441
*----------------------------------------*/
444
gen_closetray(struct wm_drive *d)
450
return(wmcd_reopen(d));
455
/* Always succeed if the drive can't close */
457
#endif /* CAN_CLOSE */
458
} /* gen_closetray() */
461
* Get the number of tracks on the CD.
464
gen_get_trackcount(struct wm_drive *d, int *tracks)
466
struct cd_toc_header hdr;
468
if (ioctl(d->fd, CDROM_TOC_HEADER, &hdr))
471
*tracks = hdr.th_ending_track;
474
} /* gen_get_trackcount() */
477
* Get the start time and mode (data or audio) of a track.
479
* XXX - this should get cached, but that means keeping track of ejects.
482
gen_get_trackinfo(struct wm_drive *d, int track, int *data, int *startframe)
485
struct cd_toc_header hdr;
486
struct cd_toc_header_and_entries toc_buffer;
488
if (ioctl(d->fd, CDROM_TOC_HEADER, &hdr))
491
bzero((char *)&toc_buffer, sizeof(toc_buffer));
492
toc.toc_address_format = CDROM_MSF_FORMAT;
493
toc.toc_starting_track = 0;
494
toc.toc_alloc_length = (u_short)(((hdr.th_data_len1 << 8) +
495
hdr.th_data_len0) & 0xfff) + 2;
496
toc.toc_buffer = (caddr_t)&toc_buffer;
498
if (ioctl(d->fd, CDROM_TOC_ENTRYS, &toc))
502
track = hdr.th_ending_track + 1;
504
*data = (toc_buffer.cdte[track-1].te_control & CDROM_DATA_TRACK) ? 1:0;
505
*startframe = toc_buffer.cdte[track - 1].te_absaddr.msf.m_units*60*75 +
506
toc_buffer.cdte[track - 1].te_absaddr.msf.s_units * 75 +
507
toc_buffer.cdte[track - 1].te_absaddr.msf.f_units;
510
} /* gen_get_trackinfo() */
513
* Get the number of frames on the CD.
516
gen_get_cdlen( struct wm_drive *d, int *frames )
520
return (gen_get_trackinfo(d, 0, &tmp, frames));
521
} /* gen_get_cdlen() */
524
* scale_volume(vol, max)
526
* Return a volume value suitable for passing to the CD-ROM drive. "vol"
527
* is a volume slider setting; "max" is the slider's maximum value.
529
* On Sun and DEC CD-ROM drives, the amount of sound coming out the jack
530
* increases much faster toward the top end of the volume scale than it
531
* does at the bottom. To make up for this, we make the volume scale look
532
* sort of logarithmic (actually an upside-down inverse square curve) so
533
* that the volume value passed to the drive changes less and less as you
534
* approach the maximum slider setting. The actual formula looks like
536
* (max^2 - (max - vol)^2) * (max_volume - min_volume)
537
* v = --------------------------------------------------- + min_volume
540
* If your system's volume settings aren't broken in this way, something
541
* like the following should work:
543
* return ((vol * (max_volume - min_volume)) / max + min_volume);
545
scale_volume(int vol, int max)
547
return ((max * max - (max - vol) * (max - vol)) *
548
(max_volume - min_volume) / (max * max) + min_volume);
549
} /* scale_volume() */
552
* unscale_volume(cd_vol, max)
554
* Given a value between min_volume and max_volume, return the volume slider
555
* value needed to achieve that value.
557
* Rather than perform floating-point calculations to reverse the above
558
* formula, we simply do a binary search of scale_volume()'s return values.
561
unscale_volume( int cd_vol, int max )
563
int vol = 0, top = max, bot = 0, scaled;
567
vol = (top + bot) / 2;
568
scaled = scale_volume(vol, max);
569
if (cd_vol == scaled)
583
} /* unscale_volume() */
586
* Set the volume level for the left and right channels. Their values
587
* range from 0 to 100.
590
gen_set_volume(struct wm_drive *d, int left, int right)
592
struct cd_playback pb;
593
struct cd_playback_status ps;
594
struct cd_playback_control pc;
596
left = scale_volume(left, 100);
597
right = scale_volume(right, 100);
599
bzero((char *)&pb, sizeof(pb));
600
bzero((char *)&ps, sizeof(ps));
601
bzero((char *)&pc, sizeof(pc));
603
pb.pb_alloc_length = sizeof(ps);
604
pb.pb_buffer = (caddr_t)&ps;
606
if (ioctl(d->fd, CDROM_PLAYBACK_STATUS, &pb))
609
pc.pc_chan0_select = ps.ps_chan0_select;
610
pc.pc_chan0_volume = (left < CDROM_MIN_VOLUME) ?
611
CDROM_MIN_VOLUME : (left > CDROM_MAX_VOLUME) ?
612
CDROM_MAX_VOLUME : left;
613
pc.pc_chan1_select = ps.ps_chan1_select;
614
pc.pc_chan1_volume = (right < CDROM_MIN_VOLUME) ?
615
CDROM_MIN_VOLUME : (right > CDROM_MAX_VOLUME) ?
616
CDROM_MAX_VOLUME : right;
618
pb.pb_alloc_length = sizeof(pc);
619
pb.pb_buffer = (caddr_t)&pc;
621
if (ioctl(d->fd, CDROM_PLAYBACK_CONTROL, &pb))
625
} /* gen_set_volume() */
629
* Read the initial volume from the drive, if available. Each channel
630
* ranges from 0 to 100, with -1 indicating data not available.
633
gen_get_volume( struct wm_drive *d, int *left, int *right )
635
struct cd_playback pb;
636
struct cd_playback_status ps;
638
bzero((char *)&pb, sizeof(pb));
639
bzero((char *)&ps, sizeof(ps));
641
pb.pb_alloc_length = sizeof(ps);
642
pb.pb_buffer = (caddr_t)&ps;
646
if (ioctl(d->fd, CDROM_PLAYBACK_STATUS, &pb))
650
*left = unscale_volume(ps.ps_chan0_volume, 100);
651
*right = unscale_volume(ps.ps_chan1_volume, 100);
658
} /* gen_get_volume() */
660
/*------------------------------------------------------------------------*
661
* gen_get_cdtext(drive, buffer, lenght)
662
*------------------------------------------------------------------------*/
665
gen_get_cdtext(struct wm_drive *d, unsigned char **pp_buffer, int *p_buffer_lenght)
667
return -1; /* no SCSI, no CDTEXT */
668
} /* gen_get_cdtext() */