2 * $Id: plat_hpux.c,v 1.8 1999/06/17 06:48:03 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 * HP/UX-specific drive control routines.
28 #if defined(hpux) || defined(__hpux)
30 static char plat_hpux_id
[] = "$Id: plat_hpux.c,v 1.8 1999/06/17 06:48:03 dirk Exp $";
37 #include <sys/types.h>
38 #include <sys/param.h>
41 #include "include/wm_config.h"
44 * this is for glibc 2.x which the ust structure in
48 #include <sys/ustat.h>
54 #include "include/wm_struct.h"
55 #include "include/wm_helpers.h"
57 #define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM
65 extern char *cd_device
;
67 /*--------------------------------------------------------*
68 * Initialize the drive. A no-op for the generic driver.
69 *--------------------------------------------------------*/
71 gen_init( struct wm_drive
*d
)
76 /*-------------------------------------*
77 * Get the number of tracks on the CD.
78 *-------------------------------------*/
80 gen_get_trackcount(struct wm_drive
*d
, int *tracks
)
82 return (wm_scsi2_get_trackcount(d
, tracks
));
85 /*---------------------------------------------------------*
86 * Get the start time and mode (data or audio) of a track.
87 *---------------------------------------------------------*/
89 gen_get_trackinfo( struct wm_drive
*d
, int *track
, int *data
, int *startframe
)
91 return (wm_scsi2_get_trackinfo(d
, track
, data
, startframe
));
94 /*-------------------------------------*
95 * Get the number of frames on the CD.
96 *-------------------------------------*/
98 gen_get_cdlen(struct wm_drive
*d
, int *frames
)
102 return (wm_scsi2_get_cdlen(d
, frames
));
105 /*--------------------------------------------------------------------------*
106 * Get the current status of the drive: the current play mode, the absolute
107 * position from start of disc (in frames), and the current track and index
108 * numbers if the CD is playing or paused.
109 *--------------------------------------------------------------------------*/
111 gen_get_drive_status( struct wm_drive
*d
, enum wm_cd_modes oldmode
, enum wm_cd_modes
*mode
,
112 int *pos
, int *track
, int *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
));
120 /*---------------------------------------------------------------------*
121 * Set the volume level for the left and right channels. Their values
122 * range from 0 to 100.
123 *---------------------------------------------------------------------*/
125 gen_set_volume( struct wm_drive
*d
, int left
, int right
)
127 return (wm_scsi2_set_volume(d
, left
, right
));
130 /*---------------------------------------------------------------------*
131 * Read the initial volume from the drive, if available. Each channel
132 * ranges from 0 to 100, with -1 indicating data not available.
133 *---------------------------------------------------------------------*/
135 gen_get_volume( struct wm_drive
*d
, int *left
, int *right
)
137 return (wm_scsi2_get_volume(d
, left
, right
));
144 gen_pause( struct wm_drive
*d
)
146 return (wm_scsi2_pause(d
));
149 /*-------------------------------------------------*
150 * Resume playing the CD (assuming it was paused.)
151 *-------------------------------------------------*/
153 gen_resume( struct wm_drive
*d
)
155 return (wm_scsi2_resume(d
));
162 gen_stop( struct wm_drive
*d
)
164 return (wm_scsi2_stop(d
));
167 /*------------------------------------------------------------*
168 * Play the CD from one position to another (both in frames.)
169 *------------------------------------------------------------*/
171 gen_play( struct wm_drive
*d
, int start
, int end
)
173 return (wm_scsi2_play(d
, start
, end
));
176 /*----------------------------------------*
177 * Eject the current CD, if there is one.
178 *----------------------------------------*/
180 gen_eject( struct wm_drive
*d
)
185 if (fstat(d
->fd
, &stbuf
) != 0)
188 /* Is this a mounted filesystem? */
189 if (ustat(stbuf
.st_rdev
, &ust
) == 0)
192 return (wm_scsi2_eject(d
));
195 /*----------------------------------------*
197 *----------------------------------------*/
199 int gen_closetray(struct wm_drive
*d
)
202 return (wm_scsi2_closetray(d
));
204 /* Always succeed if the drive can't close */
206 #endif /* CAN_CLOSE */
207 } /* gen_closetray() */
209 /*----------------------------------*
210 * Send a SCSI command out the bus.
211 *----------------------------------*/
213 wm_scsi( struct wm_drive
*d
, unsigned char *cdb
, int cdblen
,
214 void *retbuf
, int retbuflen
, int getreply
)
219 memset(&cmd
, 0, sizeof(cmd
));
220 cmd
.cdb_length
= cdblen
;
222 cmd
.data_length
= retbuflen
;
223 cmd
.max_msecs
= 1000;
224 cmd
.flags
= getreply
? SCTL_READ
: 0;
225 memcpy(cmd
.cdb
, cdb
, cdblen
);
227 return (ioctl(d
->fd
, SIOC_IO
, &cmd
));
229 /* this code, for pre-9.0, is BROKEN! ugh. */
231 struct scsi_cmd_parms cmd
;
233 memset(&cmd
, 0, sizeof(cmd
));
234 cmd
.clock_ticks
= 500;
236 cmd
.cmd_type
= cdblen
;
237 memcpy(cmd
.command
, cdb
, cdblen
);
238 if (ioctl(d
->fd
, SIOC_SET_CMD
, &cmd
) < 0)
241 if (! retbuf
|| ! retbuflen
)
242 (void) read(d
->fd
, reply_buf
, sizeof(reply_buf
));
245 if (read(d
->fd
, retbuf
, retbuflen
) < 0)
249 if (write(d
->fd
, retbuf
, retbuflen
) < 0)
256 /*-------------------------------------------------------------*
257 * Open the CD and figure out which kind of drive is attached.
258 *-------------------------------------------------------------*/
260 wmcd_open( struct wm_drive
*d
)
263 static int warned
= 0;
265 char vendor
[32], model
[32], rev
[32];
267 if (d
->fd
>= 0) /* Device already open? */
270 if (cd_device
== NULL
)
271 cd_device
= DEFAULT_CD_DEVICE
;
273 d
->fd
= open(cd_device
, O_RDWR
);
281 "As root, please run\n\nchmod 666 %s\n\n%s\n", cd_device
,
282 "to give yourself permission to access the CD-ROM device.");
286 else if (errno
!= EINTR
)
292 /* No CD in drive. */
296 /* Prepare the device to receive raw SCSI commands. */
297 if (ioctl(d
->fd
, SIOC_CMD_MODE
, &flag
) < 0)
299 fprintf(stderr
, "%s: SIOC_CMD_MODE: true: %s\n",
300 cd_device
, strerror(errno
));
307 fprintf(stderr
, "Thank you.\n");
310 /* Now fill in the relevant parts of the wm_drive structure. */
313 /* Default drive is the HP one, which might not respond to INQUIRY */
314 strcpy(&vendor
, "TOSHIBA");
315 strcpy(&model
, "XM-3301");
317 wm_scsi_get_drive_type(d
, vendor
, model
, rev
);
318 *d
= *(find_drive_struct(vendor
, model
, rev
));
319 wm_drive_settype(vendor
, model
, rev
);
329 * Re-Open the device if it is open.
332 wmcd_reopen( struct wm_drive
*d
)
337 wm_lib_message(WM_MSG_LEVEL_DEBUG
|WM_MSG_CLASS
, "wmcd_reopen ");
338 if (d
->fd
>= 0) /* Device really open? */
340 wm_lib_message(WM_MSG_LEVEL_DEBUG
|WM_MSG_CLASS
, "closes the device and ");
341 status
= close( d
->fd
); /* close it! */
342 /* we know, that the file is closed, do we? */
346 wm_lib_message(WM_MSG_LEVEL_DEBUG
|WM_MSG_CLASS
, "calls wmcd_open()\n");
347 status
= wmcd_open( d
); /* open it as usual */
349 } while ( status
!= 0 );
351 } /* wmcd_reopen() */