2 * $Id: plat_svr4.c,v 1.7 1999/03/07 08:36:41 dirk Exp $
4 * This file is part of WorkMan, the civilized CD player library
5 * (c) 1991-1997 by Steven Grimm (original author)
6 * (c) by Dirk Försterling (current 'author' = maintainer)
7 * The maintainer can be contacted by his e-mail address:
8 * milliByte@DeathsDoor.com
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the Free
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * SVR4 specific. Much of this is similar to plat_hpux.c.
28 #if defined(SVR4) && !defined(sun) && !defined(__sun__) && !defined(__sony_news)
30 static char plat_svr4_id
[] = "$Id: plat_svr4.c,v 1.7 1999/03/07 08:36:41 dirk Exp $";
32 #include <sys/types.h>
40 #include <sys/mkdev.h>
43 #include <sys/sdi_edt.h>
47 #include "include/wm_config.h"
48 #include "include/wm_struct.h"
50 #define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM
59 extern char *cd_device
;
62 * Initialize the drive. A no-op for the generic driver.
72 * Get the number of tracks on the CD.
75 gen_get_trackcount(d
, tracks
)
79 return (wm_scsi2_get_trackcount(d
, tracks
));
83 * Get the start time and mode (data or audio) of a track.
86 gen_get_trackinfo(d
, track
, data
, startframe
)
88 int track
, *data
, *startframe
;
90 return (wm_scsi2_get_trackinfo(d
, track
, data
, startframe
));
94 * Get the number of frames on the CD.
97 gen_get_cdlen(d
, frames
)
103 return (wm_scsi2_get_cdlen(d
, frames
));
107 * Get the current status of the drive: the current play mode, the absolute
108 * position from start of disc (in frames), and the current track and index
109 * numbers if the CD is playing or paused.
112 gen_get_drive_status(d
, oldmode
, mode
, pos
, track
, index
)
114 enum wm_cd_modes oldmode
, *mode
;
115 int *pos
, *track
, *index
;
117 return (wm_scsi2_get_drive_status(d
, oldmode
, mode
, pos
, track
, index
));
121 * Set the volume level for the left and right channels. Their values
122 * range from 0 to 100.
125 gen_set_volume(d
, left
, right
)
129 return (wm_scsi2_set_volume(d
, left
, right
));
133 * Read the initial volume from the drive, if available. Each channel
134 * ranges from 0 to 100, with -1 indicating data not available.
137 gen_get_volume(d
, left
, right
)
141 return (wm_scsi2_get_volume(d
, left
, right
));
151 return (wm_scsi2_pause(d
));
155 * Resume playing the CD (assuming it was paused.)
161 return (wm_scsi2_resume(d
));
171 return (wm_scsi2_stop(d
));
175 * Play the CD from one position to another (both in frames.)
178 gen_play(d
, start
, end
)
182 return (wm_scsi2_play(d
, start
, end
));
186 * Eject the current CD, if there is one.
189 gen_eject(struct wm_drive
*d
)
191 return (wm_scsi2_eject(d
));
196 * please review scsi.c / wm_scsi2_closetray()
197 * and send changes to milliByte@DeathsDoor.com
200 gen_closetray( struct wm_drive
*d
)
202 return(wm_scsi2_closetray(d
));
203 } /* gen_closetray() */
206 create_cdrom_node(char *dev_name
)
208 char pass_through
[100];
210 dev_t pass_thru_device
;
215 strcpy(pass_through
, dev_name
);
216 strcat(pass_through
, "p" );
218 if (setreuid(-1,0) < 0)
220 perror("setregid/setreuid/access");
224 ccode
= access(pass_through
, F_OK
);
228 if ((file_des
= open(dev_name
, O_RDONLY
)) < 0)
230 perror("open cdrom devices failed");
234 if (ioctl(file_des
, B_GETDEV
, &pass_thru_device
) < 0)
236 perror("Call to get pass-through device number failed");
240 (void)close(file_des
);
242 if (mknod(pass_through
, (S_IFCHR
| S_IREAD
| S_IWRITE
),
243 pass_thru_device
) < 0)
245 perror("Unable to make pass-through node");
249 if (chown(pass_through
, 0 , 0) < 0)
255 if (chmod(pass_through
, 0660 ) < 0)
262 file_des
= open( pass_through
, O_RDWR
);
265 if ( (setreuid(-1,getuid()) < 0) || (setregid(-1,getgid()) < 0) )
267 perror("setreuid/setregid");
275 * Open the CD and figure out which kind of drive is attached.
282 static int warned
= 0;
283 char vendor
[32] = WM_STR_GENVENDOR
;
284 char model
[32] = WM_STR_GENMODEL
;
285 char rev
[32] = WM_STR_GENREV
;
287 if (d
->fd
>= 0) /* Device already open? */
290 if (cd_device
== NULL
)
291 cd_device
= DEFAULT_CD_DEVICE
;
293 d
->fd
= create_cdrom_node(cd_device
); /* this will do open */
301 fprintf(stderr
,"Cannot access %s\n",cd_device
);
305 else if (errno
!= EINTR
)
311 /* No CD in drive. (Is this true also for svr4 ? XXX ) */
318 fprintf(stderr
, "Thank you.\n");
321 /* Now fill in the relevant parts of the wm_drive structure. */
325 if (wm_scsi_get_drive_type(d
, vendor
, model
, rev
) < 0)
327 perror("Cannot inquiry drive for it's type");
330 *d
= *(find_drive_struct(vendor
, model
, rev
));
331 wm_drive_settype(vendor
, model
, rev
);
339 * Re-Open the device if it is open.
342 wmcd_reopen( struct wm_drive
*d
)
347 wm_lib_message(WM_MSG_LEVEL_DEBUG
|WM_MSG_CLASS
, "wmcd_reopen ");
348 if (d
->fd
>= 0) /* Device really open? */
350 wm_lib_message(WM_MSG_LEVEL_DEBUG
|WM_MSG_CLASS
, "closes the device and ");
351 status
= close( d
->fd
); /* close it! */
352 /* we know, that the file is closed, do we? */
356 wm_lib_message(WM_MSG_LEVEL_DEBUG
|WM_MSG_CLASS
, "calls wmcd_open()\n");
357 status
= wmcd_open( d
); /* open it as usual */
359 } while ( status
!= 0 );
361 } /* wmcd_reopen() */
367 * Send a SCSI command out the bus.
370 wm_scsi(d
, xcdb
, cdblen
, retbuf
, retbuflen
, getreply
)
379 int file_des
= d
->fd
;
381 unsigned char sense_buffer
[ SENSE_SZ
];
384 /* getreply == 1 is read, == 0 is write */
389 sb
.sb_type
= ISCB_TYPE
;
391 sb
.SCB
.sc_comp_code
= SDI_PROGRES
;
392 sb
.SCB
.sc_int
= NULL
;
394 sb
.SCB
.sc_dev
.sa_major
= 0;
395 sb
.SCB
.sc_dev
.sa_minor
= 0;
396 sb
.SCB
.sc_dev
.sa_lun
= 0;
397 sb
.SCB
.sc_dev
.sa_exlun
= 0;
398 sb
.SCB
.sc_status
= 0;
399 sb
.SCB
.sc_link
= (struct sb
*) NULL
;
402 sb
.SCB
.sc_cmdpt
= (void *)xcdb
;
403 sb
.SCB
.sc_cmdsz
= cdblen
;
405 sb
.SCB
.sc_datapt
= retbuf
;
406 sb
.SCB
.sc_datasz
= retbuflen
;
409 sb
.SCB
.sc_mode
= SCB_READ
;
411 sb
.SCB
.sc_mode
= SCB_WRITE
;
413 sb
.SCB
.sc_time
= 500;
415 ccode
= ioctl(file_des
, SDI_SEND
, &sb
);
417 if ( (sb
.SCB
.sc_comp_code
!= 0xd000000e ) ||
418 ( sb
.SCB
.sc_status
!= 02) )
423 sb
.SCB
.sc_comp_code
= SDI_PROGRES
;
424 sb
.SCB
.sc_int
= NULL
;
426 sb
.SCB
.sc_dev
.sa_major
= 0;
427 sb
.SCB
.sc_dev
.sa_minor
= 0;
428 sb
.SCB
.sc_dev
.sa_lun
= 0;
429 sb
.SCB
.sc_dev
.sa_exlun
= 0;
430 sb
.SCB
.sc_status
= 0;
431 sb
.SCB
.sc_link
= (struct sb
*) NULL
;
434 scs
.ss_op
= SS_REQSEN
;
438 scs
.ss_len
= SENSE_SZ
;
441 sb
.SCB
.sc_cmdpt
= SCS_AD(&scs
);
442 sb
.SCB
.sc_cmdsz
= SCS_SZ
;
443 sb
.SCB
.sc_datapt
= sense_buffer
;
444 sb
.SCB
.sc_datasz
= 18;
445 sb
.SCB
.sc_mode
= SCB_READ
;
446 sb
.SCB
.sc_time
= 5000;
448 if (ioctl(file_des
, SDI_SEND
, &sb
) < 0)
450 fprintf(stderr
,"Cannot read sense.\n");