~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kscd/libwm/plat_osf1.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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 
 
7
 *
 
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.
 
12
 *
 
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.
 
17
 *
 
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
 
21
 *
 
22
 *
 
23
 * OSF  drive control routines.
 
24
 */
 
25
 
 
26
 
 
27
static char plat_osf_id[] = "$Id: plat_osf1.c,v 1.9 2001/04/10 17:34:52 dfoerste Exp $";
 
28
 
 
29
#if defined(__osf__) || defined(__osf)
 
30
 
 
31
 
 
32
#include <errno.h>
 
33
#include <stdio.h>
 
34
#include <sys/types.h>
 
35
#include <fcntl.h>
 
36
#include <sys/param.h>
 
37
#include <sys/stat.h>
 
38
#include <sys/time.h>
 
39
#include <ustat.h>
 
40
#include <string.h>
 
41
/* #include <sys/rzdisk.h>
 
42
#include <sys/cdrom.h>  */
 
43
#include <io/cam/rzdisk.h>
 
44
#include <io/cam/cdrom.h>
 
45
 
 
46
#include "include/wm_config.h"
 
47
#include "include/wm_struct.h"
 
48
#include "include/wm_helpers.h"
 
49
#include "include/wm_cdtext.h"
 
50
 
 
51
 
 
52
#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM
 
53
 
 
54
/*
 
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)
 
58
 */
 
59
struct cd_toc_header_and_entries 
 
60
{
 
61
  struct cd_toc_header  cdth;
 
62
  struct cd_toc_entry           cdte[CDROM_MAX_TRACK+1];
 
63
};
 
64
 
 
65
void *malloc();
 
66
char *strchr();
 
67
 
 
68
int     min_volume = 128;
 
69
int     max_volume = 255;
 
70
 
 
71
extern char     *cd_device;
 
72
 
 
73
/*
 
74
 * fgetline()
 
75
 *
 
76
 *   Simulate fgets, but joining continued lines in the output of uerf.
 
77
 *
 
78
 * platform specific internal function
 
79
 *
 
80
 */
 
81
 
 
82
#define BUF_SIZE        85              /* Max length of a (real) line */
 
83
 
 
84
char *
 
85
fgetline( FILE *fp )
 
86
{
 
87
  static char     *retval = NULL;
 
88
  static char     holdbuf[BUF_SIZE + 1];
 
89
  char            tmp[BUF_SIZE + 1];
 
90
  char            *stmp;
 
91
  
 
92
  if (!retval) 
 
93
    {
 
94
      retval = malloc(BUF_SIZE * 3);  /* 3 lines can be joined */
 
95
      if (!retval)
 
96
        return(NULL);
 
97
      else
 
98
        *retval = '\0';
 
99
    }
 
100
  
 
101
  if (*holdbuf) 
 
102
    {
 
103
      strcpy(retval, holdbuf);
 
104
      retval[strlen(retval)-1] = '\0';
 
105
      memset(holdbuf, 0, BUF_SIZE+1);
 
106
    }
 
107
 
 
108
  while (fgets(tmp, BUF_SIZE, fp)) 
 
109
    {
 
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);
 
114
      } else {
 
115
        if (*retval) 
 
116
          {
 
117
            strcpy(holdbuf, tmp);
 
118
            holdbuf[strlen(holdbuf)-1] = -1;
 
119
            return retval;
 
120
          } else {             /* First line read, keep reading */
 
121
            strcat(retval, stmp);
 
122
            retval[strlen(retval)-1] = '\0';
 
123
          }
 
124
      }
 
125
    }
 
126
  return NULL;
 
127
} /* fgetline() */
 
128
 
 
129
 
 
130
/*
 
131
 * find_cdrom
 
132
 *
 
133
 * Determine the name of the CD-ROM device.
 
134
 *
 
135
 * Read through the boot records (via a call to uerf) and find the SCSI
 
136
 * address of the CD-ROM.
 
137
 */
 
138
int
 
139
find_cdrom()
 
140
{
 
141
  char  *data;
 
142
  FILE  *uerf;
 
143
  int   fds[2];
 
144
  int   pid;
 
145
  extern char *getenv();
 
146
  
 
147
  pipe(fds);
 
148
  
 
149
  cd_device = getenv("CDROM");
 
150
  /*
 
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>
 
154
  */
 
155
  if ( cd_device == NULL || 
 
156
       strncmp("/dev/", cd_device, 5) || 
 
157
       strstr(cd_device, "/../") 
 
158
       )
 
159
    return 0;
 
160
  
 
161
  if ((pid = fork()) == 0) 
 
162
    {
 
163
      close(fds[0]);
 
164
      dup2(fds[1], 1);
 
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) {
 
169
      perror("fork");
 
170
      return 0;
 
171
    }
 
172
  
 
173
  close(fds[1]);
 
174
  uerf = fdopen(fds[0], "r");
 
175
  
 
176
  while (data = fgetline(uerf))
 
177
    if (strstr(data, "RRD42")) 
 
178
      {
 
179
        char    *device;
 
180
        
 
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");
 
187
        break;
 
188
      }
 
189
  
 
190
  fclose(uerf);
 
191
  
 
192
  if (cd_device == NULL) 
 
193
    {
 
194
      fprintf(stderr,
 
195
              "No cdrom (RRD42) is installed on this system\n");
 
196
      return 0;
 
197
    }
 
198
  
 
199
  kill(pid, 15);
 
200
  (void)wait((int *)NULL);
 
201
  return 1;
 
202
} /* find_cdrom() */
 
203
 
 
204
/*
 
205
 * Initialize the drive.  A no-op for the generic driver.
 
206
 */
 
207
int
 
208
gen_init( struct wm_drive *d )
 
209
{
 
210
  return (0);
 
211
} /* gen_init() */
 
212
 
 
213
/*
 
214
 * Open the CD device and figure out what kind of drive is attached.
 
215
 */
 
216
int
 
217
wmcd_open( struct wm_drive *d )
 
218
{
 
219
  int           fd;
 
220
  static int    warned = 0;
 
221
  
 
222
  if (d->fd >= 0)               /* Device already open? */
 
223
    {
 
224
      wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "wmcd_open(): [device is open (fd=%d)]\n", d->fd);
 
225
      return (0);
 
226
    }
 
227
 
 
228
  if (cd_device == NULL)
 
229
    find_cdrom();
 
230
  
 
231
  d->fd = open(cd_device, O_RDWR);
 
232
  if (d->fd < 0)
 
233
    {
 
234
      if (errno == EACCES)
 
235
        {
 
236
          return -EACCES;
 
237
        }
 
238
      else if (errno != EINTR)
 
239
        {
 
240
          return (-6);
 
241
        }
 
242
      
 
243
      /* No CD in drive. */
 
244
      return (1);
 
245
    }
 
246
  
 
247
  /* Now fill in the relevant parts of the wm_drive structure. */
 
248
  fd = d->fd;
 
249
  *d = *(find_drive_struct("", "", ""));
 
250
  d->fd = fd;
 
251
  
 
252
  (d->init)(d);
 
253
  
 
254
  return (0);
 
255
} /* wmcd_open() */
 
256
 
 
257
/*
 
258
 * Re-Open the device if it is open.
 
259
 */
 
260
int
 
261
wmcd_reopen( struct wm_drive *d )
 
262
{
 
263
  int status;
 
264
  
 
265
  do {
 
266
    wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "wmcd_reopen\n");
 
267
    if (d->fd >= 0)             /* Device really open? */
 
268
      {
 
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? */
 
272
        d->fd = -1;
 
273
      }
 
274
    wm_susleep( 1000 );
 
275
    wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "calling wmcd_open()\n");
 
276
    status = wmcd_open( d ); /* open it as usual */
 
277
    wm_susleep( 1000 );
 
278
  } while ( status != 0 );
 
279
  return status;
 
280
} /* wmcd_reopen() */
 
281
 
 
282
/*
 
283
 * Send an arbitrary SCSI command to a device.
 
284
 */
 
285
int
 
286
wm_scsi(struct wm_drive *d, unsigned char *cdb, int cdblen, 
 
287
        void *retbuf, int retbuflen, int getreply)
 
288
{
 
289
        /* OSF1 doesn't have a SCSI passthrough interface, does it? */
 
290
        return (-1);
 
291
} /* wm_scsi() */
 
292
 
 
293
/*
 
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.
 
297
 */
 
298
int
 
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)
 
301
{
 
302
  struct cd_sub_channel         sc;
 
303
  struct cd_subc_channel_data   scd;
 
304
  
 
305
  /* If we can't get status, the CD is ejected, so default to that. */
 
306
  *mode = WM_CDM_EJECTED;
 
307
  
 
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;
 
313
  
 
314
  /* Is the device open? */
 
315
  if (d->fd < 0)
 
316
    {
 
317
      switch (wmcd_open(d)) 
 
318
        {
 
319
        case -1:        /* error */
 
320
          return (-1);
 
321
          
 
322
        case 1:         /* retry */
 
323
          return (0);
 
324
        }
 
325
    }
 
326
  
 
327
  if (ioctl(d->fd, CDROM_READ_SUBCHANNEL, &sc))
 
328
    return (0); /* ejected */
 
329
  
 
330
  switch (scd.scd_header.sh_audio_status) 
 
331
    {
 
332
    case AS_PLAY_IN_PROGRESS:
 
333
      *mode = WM_CDM_PLAYING;
 
334
    dopos:
 
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;
 
340
      break;
 
341
      
 
342
    case AS_PLAY_PAUSED:
 
343
      if (oldmode == WM_CDM_PLAYING || oldmode == WM_CDM_PAUSED)
 
344
        {
 
345
          *mode = WM_CDM_PAUSED;
 
346
          goto dopos;
 
347
        }
 
348
      else
 
349
        *mode = WM_CDM_STOPPED;
 
350
      break;
 
351
      
 
352
    case AS_PLAY_COMPLETED:
 
353
      *mode = WM_CDM_TRACK_DONE; /* waiting for next track. */
 
354
      break;
 
355
      
 
356
    case AS_NO_STATUS:
 
357
      *mode = WM_CDM_STOPPED;
 
358
      break;
 
359
    default:
 
360
      abort();
 
361
    }
 
362
  
 
363
  return (0);
 
364
} /* gen_get_drive_status() */
 
365
 
 
366
/*
 
367
 * Play the CD from one position to another (both in frames.)
 
368
 */
 
369
int
 
370
gen_play( struct wm_drive *d, int start, int end )
 
371
{
 
372
  struct cd_play_audio_msf      msf;
 
373
  
 
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;
 
380
  
 
381
  if (ioctl(d->fd, SCSI_START_UNIT))
 
382
    return (-1);
 
383
  if (ioctl(d->fd, CDROM_PLAY_AUDIO_MSF, &msf))
 
384
    return (-2);
 
385
  
 
386
  return (0);
 
387
} /* gen_play() */
 
388
 
 
389
/*
 
390
 * Pause the CD.
 
391
 */
 
392
int
 
393
gen_pause( struct wm_drive *d )
 
394
{
 
395
  return (ioctl(d->fd, CDROM_PAUSE_PLAY, 0));
 
396
} /* gen_pause() */
 
397
 
 
398
/*
 
399
 * Resume playing the CD (assuming it was paused.)
 
400
 */
 
401
int
 
402
gen_resume( struct wm_drive *d )
 
403
{
 
404
  return (ioctl(d->fd, CDROM_RESUME_PLAY, 0));
 
405
} /* gen_resume() */
 
406
 
 
407
/*
 
408
 * Stop the CD.
 
409
 */
 
410
int
 
411
gen_stop( struct wm_drive *d )
 
412
{
 
413
  return (ioctl(d->fd, SCSI_STOP_UNIT, 0));
 
414
} /* gen_stop() */
 
415
 
 
416
/*
 
417
 * Eject the current CD, if there is one.
 
418
 */
 
419
int
 
420
gen_eject(struct wm_drive *d)
 
421
{
 
422
  /* On some systems, we can check to see if the CD is mounted. */
 
423
  struct stat   stbuf;
 
424
  struct ustat  ust;
 
425
  
 
426
  if (fstat(d->fd, &stbuf) != 0)
 
427
    return (-2);
 
428
  
 
429
  /* Is this a mounted filesystem? */
 
430
  if (ustat(stbuf.st_rdev, &ust) == 0)
 
431
    return (-3);
 
432
  
 
433
  return (ioctl(d->fd, CDROM_EJECT_CADDY, 0));
 
434
} /* gen_eject() */
 
435
 
 
436
/*----------------------------------------*
 
437
 * Close the CD tray
 
438
 *
 
439
 * Please edit and send changes to
 
440
 * milliByte@DeathsDoor.com
 
441
 *----------------------------------------*/
 
442
 
 
443
int 
 
444
gen_closetray(struct wm_drive *d)
 
445
{
 
446
#ifdef CAN_CLOSE
 
447
  if(!close(d->fd))
 
448
    {
 
449
      d->fd=-1;
 
450
      return(wmcd_reopen(d));
 
451
    } else {
 
452
      return(-1);
 
453
    }
 
454
#else
 
455
  /* Always succeed if the drive can't close */
 
456
  return(0);
 
457
#endif /* CAN_CLOSE */
 
458
} /* gen_closetray() */
 
459
 
 
460
/*
 
461
 * Get the number of tracks on the CD.
 
462
 */
 
463
int
 
464
gen_get_trackcount(struct wm_drive *d, int *tracks)
 
465
{
 
466
  struct cd_toc_header  hdr;
 
467
  
 
468
  if (ioctl(d->fd, CDROM_TOC_HEADER, &hdr))
 
469
    return (-1);
 
470
  
 
471
  *tracks = hdr.th_ending_track;
 
472
  
 
473
  return (0);
 
474
} /* gen_get_trackcount() */
 
475
 
 
476
/*
 
477
 * Get the start time and mode (data or audio) of a track.
 
478
 *
 
479
 * XXX - this should get cached, but that means keeping track of ejects.
 
480
 */
 
481
int
 
482
gen_get_trackinfo(struct wm_drive *d, int track, int *data, int *startframe)
 
483
{
 
484
  struct cd_toc                         toc;
 
485
  struct cd_toc_header                  hdr;
 
486
  struct cd_toc_header_and_entries      toc_buffer;
 
487
  
 
488
  if (ioctl(d->fd, CDROM_TOC_HEADER, &hdr))
 
489
    return (-1);
 
490
  
 
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;
 
497
  
 
498
  if (ioctl(d->fd, CDROM_TOC_ENTRYS, &toc))
 
499
    return (-1);
 
500
  
 
501
  if (track == 0)
 
502
    track = hdr.th_ending_track + 1;
 
503
  
 
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;
 
508
  
 
509
  return (0);
 
510
} /* gen_get_trackinfo() */
 
511
 
 
512
/*
 
513
 * Get the number of frames on the CD.
 
514
 */
 
515
int
 
516
gen_get_cdlen( struct wm_drive *d,  int *frames )
 
517
{
 
518
  int           tmp;
 
519
  
 
520
  return (gen_get_trackinfo(d, 0, &tmp, frames));
 
521
} /* gen_get_cdlen() */
 
522
 
 
523
/*
 
524
 * scale_volume(vol, max)
 
525
 *
 
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.
 
528
 *
 
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
 
535
 *
 
536
 *     (max^2 - (max - vol)^2) * (max_volume - min_volume)
 
537
 * v = --------------------------------------------------- + min_volume
 
538
 *                           max^2
 
539
 *
 
540
 * If your system's volume settings aren't broken in this way, something
 
541
 * like the following should work:
 
542
 *
 
543
 *      return ((vol * (max_volume - min_volume)) / max + min_volume);
 
544
 */
 
545
scale_volume(int vol, int max)
 
546
{
 
547
  return ((max * max - (max - vol) * (max - vol)) *
 
548
          (max_volume - min_volume) / (max * max) + min_volume);
 
549
} /* scale_volume() */
 
550
 
 
551
/*
 
552
 * unscale_volume(cd_vol, max)
 
553
 *
 
554
 * Given a value between min_volume and max_volume, return the volume slider
 
555
 * value needed to achieve that value.
 
556
 *
 
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.
 
559
 */
 
560
static int
 
561
unscale_volume( int cd_vol, int max )
 
562
{
 
563
  int   vol = 0, top = max, bot = 0, scaled;
 
564
  
 
565
  while (bot <= top)
 
566
    {
 
567
      vol = (top + bot) / 2;
 
568
      scaled = scale_volume(vol, max);
 
569
      if (cd_vol == scaled)
 
570
        break;
 
571
      if (cd_vol < scaled)
 
572
        top = vol - 1;
 
573
      else
 
574
        bot = vol + 1;
 
575
    }
 
576
  
 
577
  if (vol < 0)
 
578
    vol = 0;
 
579
  else if (vol > max)
 
580
    vol = max;
 
581
  
 
582
  return (vol);
 
583
} /* unscale_volume() */
 
584
 
 
585
/*
 
586
 * Set the volume level for the left and right channels.  Their values
 
587
 * range from 0 to 100.
 
588
 */
 
589
int
 
590
gen_set_volume(struct wm_drive *d, int left, int right)
 
591
{
 
592
  struct cd_playback            pb;
 
593
  struct cd_playback_status     ps;
 
594
  struct cd_playback_control    pc;
 
595
  
 
596
  left = scale_volume(left, 100);
 
597
  right = scale_volume(right, 100);
 
598
  
 
599
  bzero((char *)&pb, sizeof(pb));
 
600
  bzero((char *)&ps, sizeof(ps));
 
601
  bzero((char *)&pc, sizeof(pc));
 
602
  
 
603
  pb.pb_alloc_length = sizeof(ps);
 
604
  pb.pb_buffer = (caddr_t)&ps;
 
605
  
 
606
  if (ioctl(d->fd, CDROM_PLAYBACK_STATUS, &pb))
 
607
    return (-1);
 
608
  
 
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;
 
617
  
 
618
  pb.pb_alloc_length = sizeof(pc);
 
619
  pb.pb_buffer = (caddr_t)&pc;
 
620
  
 
621
  if (ioctl(d->fd, CDROM_PLAYBACK_CONTROL, &pb))
 
622
    return (-1);
 
623
  
 
624
  return (0);
 
625
} /* gen_set_volume() */
 
626
 
 
627
 
 
628
/*
 
629
 * Read the initial volume from the drive, if available.  Each channel
 
630
 * ranges from 0 to 100, with -1 indicating data not available.
 
631
 */
 
632
int
 
633
gen_get_volume( struct wm_drive *d, int *left, int *right )
 
634
{
 
635
  struct cd_playback            pb;
 
636
  struct cd_playback_status     ps;
 
637
  
 
638
  bzero((char *)&pb, sizeof(pb));
 
639
  bzero((char *)&ps, sizeof(ps));
 
640
  
 
641
  pb.pb_alloc_length = sizeof(ps);
 
642
  pb.pb_buffer = (caddr_t)&ps;
 
643
  
 
644
  if (d->fd >= 0)
 
645
    {
 
646
      if (ioctl(d->fd, CDROM_PLAYBACK_STATUS, &pb))
 
647
        *left = *right = -1;
 
648
      else
 
649
        {
 
650
          *left = unscale_volume(ps.ps_chan0_volume, 100);
 
651
          *right = unscale_volume(ps.ps_chan1_volume, 100);
 
652
        }
 
653
    }
 
654
  else
 
655
    *left = *right = -1;
 
656
  
 
657
  return (0);
 
658
} /* gen_get_volume() */
 
659
 
 
660
/*------------------------------------------------------------------------*
 
661
 * gen_get_cdtext(drive, buffer, lenght)
 
662
 *------------------------------------------------------------------------*/
 
663
 
 
664
int
 
665
gen_get_cdtext(struct wm_drive *d, unsigned char **pp_buffer, int *p_buffer_lenght)
 
666
{
 
667
  return -1; /* no SCSI, no CDTEXT */
 
668
} /* gen_get_cdtext() */
 
669
 
 
670
 
 
671
#endif