/[pearpc]/src/system/osapi/beos/syscdrom.cc
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /src/system/osapi/beos/syscdrom.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (hide annotations)
Wed Sep 5 17:11:21 2007 UTC (16 years, 8 months ago) by dpavlin
File size: 4361 byte(s)
import upstream CVS
1 dpavlin 1 /*
2     * PearPC
3     * syscdrom.cc
4     *
5     * Copyright (C) 2003 Sebastian Biallas (sb@biallas.net)
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License version 2 as
9     * published by the Free Software Foundation.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19     */
20    
21     #include <cstdio>
22     #include <cstring>
23     #include <device/scsi.h>
24     #include <drivers/Drivers.h>
25     #include <drivers/CAM.h>
26     #include <unistd.h>
27     #include <fcntl.h>
28     #include "errno.h"
29    
30     #include "debug/tracers.h"
31     #include "io/ide/cd.h"
32    
33     #define IO_NCD_TRACE(msg...) IO_IDE_TRACE("[CDROM/BEOS] "msg)
34     #define IO_NCD_WARN(msg...) IO_IDE_WARN("[CDROM/BEOS] "msg)
35    
36     #define SCSI_CMD_DIR_IN 1
37     #define SCSI_CMD_DIR_OUT 2
38    
39     #define CD_FRAMESIZE 2048
40    
41     /// BeOS ATAPI-based CD-ROM implementation
42     class CDROMDeviceBeOS:public CDROMDeviceSCSI
43     {
44     private:
45     int fd;
46     public:
47     CDROMDeviceBeOS(const char *name);
48     virtual ~CDROMDeviceBeOS();
49     virtual byte SCSI_ExecCmd(byte command, byte dir, byte params[11], byte *buffer, unsigned int buffer_len);
50    
51     virtual void eject();
52     };
53    
54     CDROMDeviceBeOS::CDROMDeviceBeOS(const char *name)
55     : CDROMDeviceSCSI(name)
56     {
57     IO_NCD_TRACE("%s()\n", __FUNCTION__);
58     fd = ::open(name, O_RDONLY);
59     }
60    
61     CDROMDeviceBeOS::~CDROMDeviceBeOS()
62     {
63     ::close(fd);
64     }
65    
66     /// SCSI command pass-through function
67     /// @author Alexander Stockinger
68     /// @date 07/18/2004
69     /// @param command The SCSI command to be sent
70     /// @param dir The data direcion flags
71     /// @param params byte[11] array containing command dependent parameters
72     /// @param buffer Buffer for data exchange
73     /// @param buffer_len The size of buffer in bytes
74     /// @return If the call could be executed it returns the status from the device, else it returns 0xff
75     byte CDROMDeviceBeOS::SCSI_ExecCmd(byte command, byte dir, byte params[11], byte *buffer, unsigned int buffer_len)
76     {
77     raw_device_command cmd;
78     int ret;
79     int i;
80    
81     memset(&cmd, 0, sizeof(cmd));
82     cmd.flags = B_RAW_DEVICE_SHORT_READ_VALID;
83     if (dir & SCSI_CMD_DIR_IN)
84     cmd.flags |= B_RAW_DEVICE_DATA_IN;
85    
86     cmd.command[0] = command;
87     if (command < 0x20)
88     cmd.command_length = 6;
89     else if (command < 0xa0)
90     cmd.command_length = 10;
91     else
92     cmd.command_length = 12;
93     //cmd.command_length = 10; //XXX: force
94     for (i = 0; i + 1 < cmd.command_length; i++)
95     cmd.command[i+1] = params[i];
96     cmd.data = buffer;
97     cmd.data_length = buffer_len;
98     cmd.timeout = 5000000;
99     ret = ::ioctl(fd, B_RAW_DEVICE_COMMAND, &cmd, sizeof(cmd));
100     //IO_NCD_TRACE("command done. scsi status: 0x%08lx cam status: 0x%08lx\n", cmd.scsi_status, cmd.cam_status);
101     if (ret < 0 /*|| cmd.scsi_status || cmd.cam_status*/) {
102     IO_NCD_WARN("ioctl() returned error 0x%08lx (%s)\n", errno, strerror(errno));
103     IO_NCD_WARN("command: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x:\n",
104     command, params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8], params[9]);
105     return 0xff;
106     }
107     return cmd.scsi_status;
108     }
109    
110    
111     void CDROMDeviceBeOS::eject()
112     {
113     IO_NCD_TRACE("%s()\n", __FUNCTION__);
114     ::ioctl(fd, B_EJECT_DEVICE, NULL, 0);
115     }
116    
117     /// Creates a native CDROM device
118     /// @param device_name The PearPC internal device name for the drive
119     /// @param image_name The image / device name to identify the real hardware
120     /// @return On success a pointer to a CDROMDevice is returned, else NULL
121     /// @author Alexander Stockinger
122     /// @date 07/19/2004
123     CDROMDevice* createNativeCDROMDevice(const char* device_name, const char* image_name)
124     {
125     // IO_NCD_WARN("No native CDROMs supported on BeOS\n");
126     // check for a real cdrom drive...
127     device_geometry geom;
128     int err;
129     int fd = open(image_name, O_RDONLY);
130     err = ioctl(fd, B_GET_GEOMETRY, &geom, sizeof(geom));
131     close(fd);
132     if (err < 0) {
133     IO_NCD_WARN("Can't open CDROM '%s'\n", image_name);
134     return NULL;
135     }
136     if (geom.device_type != B_CD) {
137     IO_NCD_WARN("File '%s' not a CDROM device\n", image_name);
138     return NULL;
139     }
140     // create it
141     CDROMDevice *dev = new CDROMDeviceBeOS(image_name);
142     return dev;
143     }

  ViewVC Help
Powered by ViewVC 1.1.26