wmmisc: Bump to version 1.2.
[dockapps.git] / ascd / libworkman / plat_hpux.c
blobb199cb0db056d3b03f89f9963e3a6af4077b0ecd
1 /*
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 $";
32 #include <errno.h>
33 #include <stdio.h>
34 #include <fcntl.h>
35 #include <ustat.h>
36 #include <unistd.h>
37 #include <sys/types.h>
38 #include <sys/param.h>
39 #include <sys/stat.h>
41 #include "include/wm_config.h"
44 * this is for glibc 2.x which the ust structure in
45 * ustat.h not stat.h
47 #ifdef __GLIBC__
48 #include <sys/ustat.h>
49 #endif
51 #include <sys/time.h>
52 #include <sys/scsi.h>
54 #include "include/wm_struct.h"
55 #include "include/wm_helpers.h"
57 #define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM
59 void *malloc();
60 char *strchr();
62 int min_volume = 0;
63 int max_volume = 255;
65 extern char *cd_device;
67 /*--------------------------------------------------------*
68 * Initialize the drive. A no-op for the generic driver.
69 *--------------------------------------------------------*/
70 int
71 gen_init( struct wm_drive *d )
73 return (0);
76 /*-------------------------------------*
77 * Get the number of tracks on the CD.
78 *-------------------------------------*/
79 int
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 *---------------------------------------------------------*/
88 int
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 *-------------------------------------*/
97 int
98 gen_get_cdlen(struct wm_drive *d, int *frames)
100 int tmp;
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 )
113 struct wm_drive *d;
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));
140 /*---------------*
141 * Pause the CD.
142 *---------------*/
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));
158 /*--------------*
159 * Stop the CD.
160 *--------------*/
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 )
182 struct stat stbuf;
183 struct ustat ust;
185 if (fstat(d->fd, &stbuf) != 0)
186 return (-2);
188 /* Is this a mounted filesystem? */
189 if (ustat(stbuf.st_rdev, &ust) == 0)
190 return (-3);
192 return (wm_scsi2_eject(d));
195 /*----------------------------------------*
196 * Close the CD tray
197 *----------------------------------------*/
199 int gen_closetray(struct wm_drive *d)
201 #ifdef CAN_CLOSE
202 return (wm_scsi2_closetray(d));
203 #else
204 /* Always succeed if the drive can't close */
205 return(0);
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 )
216 #ifdef SIOC_IO
217 struct sctl_io cmd;
219 memset(&cmd, 0, sizeof(cmd));
220 cmd.cdb_length = cdblen;
221 cmd.data = retbuf;
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));
228 #else
229 /* this code, for pre-9.0, is BROKEN! ugh. */
230 char reply_buf[12];
231 struct scsi_cmd_parms cmd;
233 memset(&cmd, 0, sizeof(cmd));
234 cmd.clock_ticks = 500;
235 cmd.cmd_mode = 1;
236 cmd.cmd_type = cdblen;
237 memcpy(cmd.command, cdb, cdblen);
238 if (ioctl(d->fd, SIOC_SET_CMD, &cmd) < 0)
239 return (-1);
241 if (! retbuf || ! retbuflen)
242 (void) read(d->fd, reply_buf, sizeof(reply_buf));
243 else if (getreply)
245 if (read(d->fd, retbuf, retbuflen) < 0)
246 return (-1);
248 else
249 if (write(d->fd, retbuf, retbuflen) < 0)
250 return (-1);
252 return (0);
253 #endif
256 /*-------------------------------------------------------------*
257 * Open the CD and figure out which kind of drive is attached.
258 *-------------------------------------------------------------*/
260 wmcd_open( struct wm_drive *d )
262 int fd, flag = 1;
263 static int warned = 0;
264 /* unsigned ? */
265 char vendor[32], model[32], rev[32];
267 if (d->fd >= 0) /* Device already open? */
268 return (0);
270 if (cd_device == NULL)
271 cd_device = DEFAULT_CD_DEVICE;
273 d->fd = open(cd_device, O_RDWR);
274 if (d->fd < 0)
276 if (errno == EACCES)
278 if (! warned)
280 fprintf(stderr,
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.");
283 warned++;
286 else if (errno != EINTR)
288 perror(cd_device);
289 exit(1);
292 /* No CD in drive. */
293 return (1);
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));
301 /*exit(1);*/
304 if (warned)
306 warned = 0;
307 fprintf(stderr, "Thank you.\n");
310 /* Now fill in the relevant parts of the wm_drive structure. */
311 fd = d->fd;
313 /* Default drive is the HP one, which might not respond to INQUIRY */
314 strcpy(&vendor, "TOSHIBA");
315 strcpy(&model, "XM-3301");
316 rev[0] = '\0';
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);
321 d->fd = fd;
323 (d->init)(d);
325 return (0);
326 } /* wmcd_open() */
329 * Re-Open the device if it is open.
332 wmcd_reopen( struct wm_drive *d )
334 int status;
336 do {
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? */
343 d->fd = -1;
345 wm_susleep( 1000 );
346 wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "calls wmcd_open()\n");
347 status = wmcd_open( d ); /* open it as usual */
348 wm_susleep( 1000 );
349 } while ( status != 0 );
350 return status;
351 } /* wmcd_reopen() */
355 #endif