| @@ -1,144 +1,115 @@ | | | @@ -1,144 +1,115 @@ |
1 | $NetBSD: patch-cf,v 1.9 2009/05/17 21:29:34 dholland Exp $ | | 1 | $NetBSD: patch-cf,v 1.10 2009/05/19 00:36:06 dholland Exp $ |
2 | | | 2 | |
3 | --- interface/scan_devices.c.orig 2001-03-26 00:44:01.000000000 -0500 | | 3 | --- interface/scan_devices.c.orig 2001-03-26 00:44:01.000000000 -0500 |
4 | +++ interface/scan_devices.c 2009-05-17 16:47:49.000000000 -0400 | | 4 | +++ interface/scan_devices.c 2009-05-18 20:11:24.000000000 -0400 |
5 | @@ -1,6 +1,8 @@ | | 5 | @@ -1,6 +1,8 @@ |
6 | /****************************************************************** | | 6 | /****************************************************************** |
7 | * CopyPolicy: GNU Public License 2 applies | | 7 | * CopyPolicy: GNU Public License 2 applies |
8 | * Copyright (C) 1998 Monty xiphmont@mit.edu | | 8 | * Copyright (C) 1998 Monty xiphmont@mit.edu |
9 | + * FreeBSD porting (c) 2003 | | 9 | + * FreeBSD porting (c) 2003 |
10 | + * Simon 'corecode' Schubert <corecode@corecode.ath.cx> | | 10 | + * Simon 'corecode' Schubert <corecode@corecode.ath.cx> |
11 | * | | 11 | * |
12 | * Autoscan for or verify presence of a cdrom device | | 12 | * Autoscan for or verify presence of a cdrom device |
13 | * | | 13 | * |
14 | @@ -14,11 +16,18 @@ | | 14 | @@ -19,6 +21,8 @@ |
15 | #include <pwd.h> | | | |
16 | #include <sys/stat.h> | | | |
17 | #include <sys/types.h> | | | |
18 | + | | | |
19 | +#ifdef HAVE_GETRAWPARTITION | | | |
20 | +#include <util.h> | | | |
21 | +#endif | | | |
22 | + | | | |
23 | #include "cdda_interface.h" | | | |
24 | #include "low_interface.h" | | | |
25 | #include "common_interface.h" | | 15 | #include "common_interface.h" |
26 | #include "utils.h" | | 16 | #include "utils.h" |
27 | | | 17 | |
28 | +#ifdef __linux__ | | 18 | +#ifdef __linux__ |
29 | + | | 19 | + |
30 | #define MAX_DEV_LEN 20 /* Safe because strings only come from below */ | | 20 | #define MAX_DEV_LEN 20 /* Safe because strings only come from below */ |
31 | /* must be absolute paths! */ | | 21 | /* must be absolute paths! */ |
32 | static char *scsi_cdrom_prefixes[]={ | | 22 | static char *scsi_cdrom_prefixes[]={ |
33 | @@ -49,15 +58,43 @@ static char *cdrom_devices[]={ | | 23 | @@ -49,11 +53,30 @@ static char *cdrom_devices[]={ |
34 | "/dev/cm206cd", | | 24 | "/dev/cm206cd", |
35 | "/dev/gscd", | | 25 | "/dev/gscd", |
36 | "/dev/optcd",NULL}; | | 26 | "/dev/optcd",NULL}; |
37 | +#elif defined(__FreeBSD__) || defined(__DragonFly__) | | 27 | +#elif defined(__FreeBSD__) || defined(__DragonFly__) |
38 | +static char *cdrom_devices[] = { | | 28 | +static char *cdrom_devices[] = { |
39 | + "/dev/cd?c", | | 29 | + "/dev/cd?c", |
40 | + "/dev/acd?c", | | 30 | + "/dev/acd?c", |
41 | + "/dev/wcd?c", | | 31 | + "/dev/wcd?c", |
42 | + "/dev/mcd?c", NULL}; | | 32 | + "/dev/mcd?c", NULL}; |
43 | +#elif defined(__NetBSD__) | | 33 | +#elif defined(__NetBSD__) |
44 | +static char *cdrom_devices[] = { | | 34 | +static char *cdrom_devices[] = { |
45 | + "/dev/rcd?c", | | 35 | + "/dev/rcd?c", |
46 | + "/dev/cd?c", NULL}; | | 36 | + "/dev/rcd?d", |
| | | 37 | + "/dev/cd?c", |
| | | 38 | + "/dev/cd?d", NULL}; |
47 | +#endif | | 39 | +#endif |
48 | | | 40 | |
49 | /* Functions here look for a cdrom drive; full init of a drive type | | 41 | /* Functions here look for a cdrom drive; full init of a drive type |
50 | happens in interface.c */ | | 42 | happens in interface.c */ |
51 | | | 43 | |
52 | +#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || (defined(__APPLE__) && defined(__MACH__)) | | 44 | +#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || (defined(__APPLE__) && defined(__MACH__)) |
53 | cdrom_drive *cdda_find_a_cdrom(int messagedest,char **messages){ | | 45 | cdrom_drive *cdda_find_a_cdrom(int messagedest,char **messages){ |
54 | +#if defined(__APPLE__) && defined(__MACH__) | | 46 | +#if defined(__APPLE__) && defined(__MACH__) |
55 | + cdrom_drive *d = calloc(1, sizeof(cdrom_drive)); | | 47 | + cdrom_drive *d = calloc(1, sizeof(cdrom_drive)); |
56 | + d->interface = OSX_IOKIT; | | 48 | + d->interface = OSX_IOKIT; |
57 | + return d; | | 49 | + return d; |
58 | +#else | | 50 | +#else |
59 | /* Brute force... */ | | 51 | /* Brute force... */ |
60 | | | 52 | |
61 | int i=0; | | 53 | int i=0; |
62 | cdrom_drive *d; | | 54 | @@ -75,10 +98,12 @@ cdrom_drive *cdda_find_a_cdrom(int messa |
63 | +#ifdef __NetBSD__ | | | |
64 | + int rawpartition; | | | |
65 | +#endif | | | |
66 | + | | | |
67 | +#ifdef __NetBSD__ | | | |
68 | +#ifdef HAVE_GETRAWPARTITION | | | |
69 | + rawpartition = getrawpartition(); | | | |
70 | +#else | | | |
71 | + rawpartition = 'c' - 'a'; | | | |
72 | +#endif | | | |
73 | +#endif | | | |
74 | | | | |
75 | while(cdrom_devices[i]!=NULL){ | | | |
76 | | | | |
77 | @@ -72,13 +109,18 @@ cdrom_drive *cdda_find_a_cdrom(int messa | | | |
78 | /* number, then letter */ | | | |
79 | | | | |
80 | buffer[pos-(cdrom_devices[i])]=j+48; | | | |
81 | +#ifdef __NetBSD__ | | | |
82 | + buffer[(pos+1)-(cdrom_devices[i])]='a'+rawpartition; | | | |
83 | +#endif | | | |
84 | if((d=cdda_identify(buffer,messagedest,messages))) | | 55 | if((d=cdda_identify(buffer,messagedest,messages))) |
85 | return(d); | | 56 | return(d); |
86 | idmessage(messagedest,messages,"",NULL); | | 57 | idmessage(messagedest,messages,"",NULL); |
87 | +#ifdef __linux__ | | 58 | +#ifdef __linux__ |
88 | buffer[pos-(cdrom_devices[i])]=j+97; | | 59 | buffer[pos-(cdrom_devices[i])]=j+97; |
89 | if((d=cdda_identify(buffer,messagedest,messages))) | | 60 | if((d=cdda_identify(buffer,messagedest,messages))) |
90 | return(d); | | 61 | return(d); |
91 | idmessage(messagedest,messages,"",NULL); | | 62 | idmessage(messagedest,messages,"",NULL); |
92 | +#endif | | 63 | +#endif |
93 | } | | 64 | } |
94 | }else{ | | 65 | }else{ |
95 | /* Name. Go for it. */ | | 66 | /* Name. Go for it. */ |
96 | @@ -97,8 +139,11 @@ cdrom_drive *cdda_find_a_cdrom(int messa | | 67 | @@ -97,8 +122,11 @@ cdrom_drive *cdda_find_a_cdrom(int messa |
97 | temp->pw_name); | | 68 | temp->pw_name); |
98 | } | | 69 | } |
99 | return(NULL); | | 70 | return(NULL); |
100 | +#endif | | 71 | +#endif |
101 | } | | 72 | } |
102 | +#endif /* __linux__ */ | | 73 | +#endif /* __linux__ */ |
103 | | | 74 | |
104 | +#if !(defined(__APPLE__) && defined(__MACH__)) | | 75 | +#if !(defined(__APPLE__) && defined(__MACH__)) |
105 | cdrom_drive *cdda_identify(const char *device, int messagedest,char **messages){ | | 76 | cdrom_drive *cdda_identify(const char *device, int messagedest,char **messages){ |
106 | struct stat st; | | 77 | struct stat st; |
107 | cdrom_drive *d=NULL; | | 78 | cdrom_drive *d=NULL; |
108 | @@ -117,8 +162,14 @@ cdrom_drive *cdda_identify(const char *d | | 79 | @@ -117,8 +145,14 @@ cdrom_drive *cdda_identify(const char *d |
109 | } | | 80 | } |
110 | #endif | | 81 | #endif |
111 | | | 82 | |
112 | +#if defined(__linux__) || defined(__NetBSD__) | | 83 | +#if defined(__linux__) || defined(__NetBSD__) |
113 | d=cdda_identify_cooked(device,messagedest,messages); | | 84 | d=cdda_identify_cooked(device,messagedest,messages); |
114 | if(!d)d=cdda_identify_scsi(device,NULL,messagedest,messages); | | 85 | if(!d)d=cdda_identify_scsi(device,NULL,messagedest,messages); |
115 | +#elif defined(__FreeBSD__) || defined(__DragonFly__) | | 86 | +#elif defined(__FreeBSD__) || defined(__DragonFly__) |
116 | + d = cdda_identify_scsi(device, NULL, messagedest, messages); | | 87 | + d = cdda_identify_scsi(device, NULL, messagedest, messages); |
117 | + if (d == NULL) | | 88 | + if (d == NULL) |
118 | + d = cdda_identify_cooked(device, messagedest, messages); | | 89 | + d = cdda_identify_cooked(device, messagedest, messages); |
119 | +#endif | | 90 | +#endif |
120 | | | 91 | |
121 | #ifdef CDDA_TEST | | 92 | #ifdef CDDA_TEST |
122 | if(!d)d=cdda_identify_test(device,messagedest,messages); | | 93 | if(!d)d=cdda_identify_test(device,messagedest,messages); |
123 | @@ -146,6 +197,7 @@ char *test_resolve_symlink(const char *f | | 94 | @@ -146,6 +180,7 @@ char *test_resolve_symlink(const char *f |
124 | cdrom_drive *cdda_identify_cooked(const char *dev, int messagedest, | | 95 | cdrom_drive *cdda_identify_cooked(const char *dev, int messagedest, |
125 | char **messages){ | | 96 | char **messages){ |
126 | | | 97 | |
127 | +#ifdef __linux__ | | 98 | +#ifdef __linux__ |
128 | cdrom_drive *d=NULL; | | 99 | cdrom_drive *d=NULL; |
129 | struct stat st; | | 100 | struct stat st; |
130 | int fd=-1; | | 101 | int fd=-1; |
131 | @@ -273,8 +325,60 @@ cdrom_drive *cdda_identify_cooked(const | | 102 | @@ -273,8 +308,60 @@ cdrom_drive *cdda_identify_cooked(const |
132 | idmessage(messagedest,messages,"\t\tCDROM sensed: %s\n",description); | | 103 | idmessage(messagedest,messages,"\t\tCDROM sensed: %s\n",description); |
133 | | | 104 | |
134 | return(d); | | 105 | return(d); |
135 | +#elif defined(__NetBSD__) | | 106 | +#elif defined(__NetBSD__) |
136 | + /* no kernel support for CD-DA */ | | 107 | + /* no kernel support for CD-DA */ |
137 | + return NULL; | | 108 | + return NULL; |
138 | +#elif defined(__FreeBSD__) || defined(__DragonFly__) | | 109 | +#elif defined(__FreeBSD__) || defined(__DragonFly__) |
139 | + cdrom_drive *d; | | 110 | + cdrom_drive *d; |
140 | + struct stat st; | | 111 | + struct stat st; |
141 | + | | 112 | + |
142 | + if (stat(dev, &st)) { | | 113 | + if (stat(dev, &st)) { |
143 | + idperror(messagedest, messages, "\t\tCould not stat %s", dev); | | 114 | + idperror(messagedest, messages, "\t\tCould not stat %s", dev); |
144 | + return NULL; | | 115 | + return NULL; |
| @@ -179,202 +150,202 @@ $NetBSD: patch-cf,v 1.9 2009/05/17 21:29 | | | @@ -179,202 +150,202 @@ $NetBSD: patch-cf,v 1.9 2009/05/17 21:29 |
179 | + if (d != NULL) { | | 150 | + if (d != NULL) { |
180 | + if (d->ioctl_fd != -1) | | 151 | + if (d->ioctl_fd != -1) |
181 | + close(d->ioctl_fd); | | 152 | + close(d->ioctl_fd); |
182 | + free(d); | | 153 | + free(d); |
183 | + } | | 154 | + } |
184 | + return NULL; | | 155 | + return NULL; |
185 | +#endif | | 156 | +#endif |
186 | } | | 157 | } |
187 | | | 158 | |
188 | +#if !defined(__FreeBSD__) || defined(__DragonFly__) | | 159 | +#if !defined(__FreeBSD__) || defined(__DragonFly__) |
189 | struct sg_id { | | 160 | struct sg_id { |
190 | long l1; /* target | lun << 8 | channel << 16 | low_ino << 24 */ | | 161 | long l1; /* target | lun << 8 | channel << 16 | low_ino << 24 */ |
191 | long l2; /* Unique id */ | | 162 | long l2; /* Unique id */ |
192 | @@ -289,12 +393,18 @@ typedef struct scsiid{ | | 163 | @@ -289,12 +376,18 @@ typedef struct scsiid{ |
193 | /* Even *this* isn't as simple as it bloody well should be :-P */ | | 164 | /* Even *this* isn't as simple as it bloody well should be :-P */ |
194 | /* SG has an easy interface, but SCSI overall does not */ | | 165 | /* SG has an easy interface, but SCSI overall does not */ |
195 | static int get_scsi_id(int fd, scsiid *id){ | | 166 | static int get_scsi_id(int fd, scsiid *id){ |
196 | +#ifdef __linux__ | | 167 | +#ifdef __linux__ |
197 | struct sg_id argid; | | 168 | struct sg_id argid; |
198 | +#endif | | 169 | +#endif |
199 | +#ifdef __NetBSD__ | | 170 | +#ifdef __NetBSD__ |
200 | + struct scsi_addr argid; | | 171 | + struct scsi_addr argid; |
201 | +#endif | | 172 | +#endif |
202 | int busarg; | | 173 | int busarg; |
203 | | | 174 | |
204 | /* get the host/id/lun */ | | 175 | /* get the host/id/lun */ |
205 | | | 176 | |
206 | if(fd==-1)return(-1); | | 177 | if(fd==-1)return(-1); |
207 | +#ifdef __linux__ | | 178 | +#ifdef __linux__ |
208 | if(ioctl(fd,SCSI_IOCTL_GET_IDLUN,&argid))return(-1); | | 179 | if(ioctl(fd,SCSI_IOCTL_GET_IDLUN,&argid))return(-1); |
209 | id->bus=argid.l2; /* for now */ | | 180 | id->bus=argid.l2; /* for now */ |
210 | id->id=argid.l1&0xff; | | 181 | id->id=argid.l1&0xff; |
211 | @@ -302,6 +412,13 @@ static int get_scsi_id(int fd, scsiid *i | | 182 | @@ -302,6 +395,13 @@ static int get_scsi_id(int fd, scsiid *i |
212 | | | 183 | |
213 | if(ioctl(fd,SCSI_IOCTL_GET_BUS_NUMBER,&busarg)==0) | | 184 | if(ioctl(fd,SCSI_IOCTL_GET_BUS_NUMBER,&busarg)==0) |
214 | id->bus=busarg; | | 185 | id->bus=busarg; |
215 | +#endif | | 186 | +#endif |
216 | +#ifdef __NetBSD__ | | 187 | +#ifdef __NetBSD__ |
217 | + if(ioctl(fd,SCIOCIDENTIFY,&argid))return(-1); | | 188 | + if(ioctl(fd,SCIOCIDENTIFY,&argid))return(-1); |
218 | + id->bus=argid.addr.scsi.scbus; | | 189 | + id->bus=argid.addr.scsi.scbus; |
219 | + id->id=argid.addr.scsi.target; | | 190 | + id->id=argid.addr.scsi.target; |
220 | + id->lun=argid.addr.scsi.lun; | | 191 | + id->lun=argid.addr.scsi.lun; |
221 | +#endif | | 192 | +#endif |
222 | | | 193 | |
223 | return(0); | | 194 | return(0); |
224 | } | | 195 | } |
225 | @@ -390,6 +507,7 @@ matchfail: | | 196 | @@ -390,6 +490,7 @@ matchfail: |
226 | if(dev!=-1)close(dev); | | 197 | if(dev!=-1)close(dev); |
227 | return(NULL); | | 198 | return(NULL); |
228 | } | | 199 | } |
229 | +#endif | | 200 | +#endif |
230 | | | 201 | |
231 | void strscat(char *a,char *b,int n){ | | 202 | void strscat(char *a,char *b,int n){ |
232 | int i; | | 203 | int i; |
233 | @@ -401,6 +519,7 @@ void strscat(char *a,char *b,int n){ | | 204 | @@ -401,6 +502,7 @@ void strscat(char *a,char *b,int n){ |
234 | strcat(a," "); | | 205 | strcat(a," "); |
235 | } | | 206 | } |
236 | | | 207 | |
237 | +#ifdef __linux__ | | 208 | +#ifdef __linux__ |
238 | /* At this point, we're going to punt compatability before SG2, and | | 209 | /* At this point, we're going to punt compatability before SG2, and |
239 | allow only SG2 and SG3 */ | | 210 | allow only SG2 and SG3 */ |
240 | static int verify_SG_version(cdrom_drive *d,int messagedest, | | 211 | static int verify_SG_version(cdrom_drive *d,int messagedest, |
241 | @@ -430,7 +549,9 @@ static int verify_SG_version(cdrom_drive | | 212 | @@ -430,7 +532,9 @@ static int verify_SG_version(cdrom_drive |
242 | idmessage(messagedest,messages,buffer,""); | | 213 | idmessage(messagedest,messages,buffer,""); |
243 | return(major); | | 214 | return(major); |
244 | } | | 215 | } |
245 | +#endif | | 216 | +#endif |
246 | | | 217 | |
247 | +#if defined(__linux__) || defined(__NetBSD__) | | 218 | +#if defined(__linux__) || defined(__NetBSD__) |
248 | cdrom_drive *cdda_identify_scsi(const char *generic_device, | | 219 | cdrom_drive *cdda_identify_scsi(const char *generic_device, |
249 | const char *ioctl_device, int messagedest, | | 220 | const char *ioctl_device, int messagedest, |
250 | char **messages){ | | 221 | char **messages){ |
251 | @@ -460,6 +581,7 @@ cdrom_drive *cdda_identify_scsi(const ch | | 222 | @@ -460,6 +564,7 @@ cdrom_drive *cdda_identify_scsi(const ch |
252 | generic_device); | | 223 | generic_device); |
253 | return(NULL); | | 224 | return(NULL); |
254 | } | | 225 | } |
255 | +#ifdef __linux__ | | 226 | +#ifdef __linux__ |
256 | if((int)(g_st.st_rdev>>8)!=SCSI_GENERIC_MAJOR){ | | 227 | if((int)(g_st.st_rdev>>8)!=SCSI_GENERIC_MAJOR){ |
257 | if((int)(g_st.st_rdev>>8)!=SCSI_CDROM_MAJOR){ | | 228 | if((int)(g_st.st_rdev>>8)!=SCSI_CDROM_MAJOR){ |
258 | idmessage(messagedest,messages,"\t\t%s is not a SCSI device", | | 229 | idmessage(messagedest,messages,"\t\t%s is not a SCSI device", |
259 | @@ -471,6 +593,7 @@ cdrom_drive *cdda_identify_scsi(const ch | | 230 | @@ -471,6 +576,7 @@ cdrom_drive *cdda_identify_scsi(const ch |
260 | ioctl_device=temp; | | 231 | ioctl_device=temp; |
261 | } | | 232 | } |
262 | } | | 233 | } |
263 | +#endif | | 234 | +#endif |
264 | } | | 235 | } |
265 | if(ioctl_device){ | | 236 | if(ioctl_device){ |
266 | if(stat(ioctl_device,&i_st)){ | | 237 | if(stat(ioctl_device,&i_st)){ |
267 | @@ -478,6 +601,7 @@ cdrom_drive *cdda_identify_scsi(const ch | | 238 | @@ -478,6 +584,7 @@ cdrom_drive *cdda_identify_scsi(const ch |
268 | ioctl_device); | | 239 | ioctl_device); |
269 | return(NULL); | | 240 | return(NULL); |
270 | } | | 241 | } |
271 | +#ifdef __linux__ | | 242 | +#ifdef __linux__ |
272 | if((int)(i_st.st_rdev>>8)!=SCSI_CDROM_MAJOR){ | | 243 | if((int)(i_st.st_rdev>>8)!=SCSI_CDROM_MAJOR){ |
273 | if((int)(i_st.st_rdev>>8)!=SCSI_GENERIC_MAJOR){ | | 244 | if((int)(i_st.st_rdev>>8)!=SCSI_GENERIC_MAJOR){ |
274 | idmessage(messagedest,messages,"\t\t%s is not a SCSI device", | | 245 | idmessage(messagedest,messages,"\t\t%s is not a SCSI device", |
275 | @@ -489,6 +613,7 @@ cdrom_drive *cdda_identify_scsi(const ch | | 246 | @@ -489,6 +596,7 @@ cdrom_drive *cdda_identify_scsi(const ch |
276 | ioctl_device=temp; | | 247 | ioctl_device=temp; |
277 | } | | 248 | } |
278 | } | | 249 | } |
279 | +#endif | | 250 | +#endif |
280 | } | | 251 | } |
281 | | | 252 | |
282 | /* we need to resolve any symlinks for the lookup code to work */ | | 253 | /* we need to resolve any symlinks for the lookup code to work */ |
283 | @@ -505,6 +630,7 @@ cdrom_drive *cdda_identify_scsi(const ch | | 254 | @@ -505,6 +613,7 @@ cdrom_drive *cdda_identify_scsi(const ch |
284 | } | | 255 | } |
285 | | | 256 | |
286 | if(!generic_device || !ioctl_device){ | | 257 | if(!generic_device || !ioctl_device){ |
287 | +#ifdef __linux__ | | 258 | +#ifdef __linux__ |
288 | if(generic_device){ | | 259 | if(generic_device){ |
289 | ioctl_device= | | 260 | ioctl_device= |
290 | scsi_match(generic_device,scsi_cdrom_prefixes, | | 261 | scsi_match(generic_device,scsi_cdrom_prefixes, |
291 | @@ -520,6 +646,12 @@ cdrom_drive *cdda_identify_scsi(const ch | | 262 | @@ -520,6 +629,12 @@ cdrom_drive *cdda_identify_scsi(const ch |
292 | if(!generic_device) | | 263 | if(!generic_device) |
293 | goto cdda_identify_scsi_fail; | | 264 | goto cdda_identify_scsi_fail; |
294 | } | | 265 | } |
295 | +#else | | 266 | +#else |
296 | + if(!generic_device) | | 267 | + if(!generic_device) |
297 | + generic_device = strdup(ioctl_device); | | 268 | + generic_device = strdup(ioctl_device); |
298 | + else | | 269 | + else |
299 | + ioctl_device = strdup(generic_device); | | 270 | + ioctl_device = strdup(generic_device); |
300 | +#endif | | 271 | +#endif |
301 | } | | 272 | } |
302 | | | 273 | |
303 | idmessage(messagedest,messages,"\t\tgeneric device: %s",generic_device); | | 274 | idmessage(messagedest,messages,"\t\tgeneric device: %s",generic_device); |
304 | @@ -556,6 +688,7 @@ cdrom_drive *cdda_identify_scsi(const ch | | 275 | @@ -556,6 +671,7 @@ cdrom_drive *cdda_identify_scsi(const ch |
305 | | | 276 | |
306 | type=(int)(i_st.st_rdev>>8); | | 277 | type=(int)(i_st.st_rdev>>8); |
307 | | | 278 | |
308 | +#ifdef __linux__ | | 279 | +#ifdef __linux__ |
309 | if(type==SCSI_CDROM_MAJOR){ | | 280 | if(type==SCSI_CDROM_MAJOR){ |
310 | if (!S_ISBLK(i_st.st_mode)) { | | 281 | if (!S_ISBLK(i_st.st_mode)) { |
311 | idmessage(messagedest,messages,"\t\tSCSI CDROM device %s not a " | | 282 | idmessage(messagedest,messages,"\t\tSCSI CDROM device %s not a " |
312 | @@ -567,8 +700,10 @@ cdrom_drive *cdda_identify_scsi(const ch | | 283 | @@ -567,8 +683,10 @@ cdrom_drive *cdda_identify_scsi(const ch |
313 | "major number",ioctl_device); | | 284 | "major number",ioctl_device); |
314 | goto cdda_identify_scsi_fail; | | 285 | goto cdda_identify_scsi_fail; |
315 | } | | 286 | } |
316 | +#endif | | 287 | +#endif |
317 | } | | 288 | } |
318 | | | 289 | |
319 | +#ifdef __linux__ | | 290 | +#ifdef __linux__ |
320 | if((int)(g_st.st_rdev>>8)==SCSI_GENERIC_MAJOR){ | | 291 | if((int)(g_st.st_rdev>>8)==SCSI_GENERIC_MAJOR){ |
321 | if (!S_ISCHR(g_st.st_mode)) { | | 292 | if (!S_ISCHR(g_st.st_mode)) { |
322 | idmessage(messagedest,messages,"\t\tGeneric SCSI device %s not a " | | 293 | idmessage(messagedest,messages,"\t\tGeneric SCSI device %s not a " |
323 | @@ -580,6 +715,7 @@ cdrom_drive *cdda_identify_scsi(const ch | | 294 | @@ -580,6 +698,7 @@ cdrom_drive *cdda_identify_scsi(const ch |
324 | "major number",generic_device); | | 295 | "major number",generic_device); |
325 | goto cdda_identify_scsi_fail; | | 296 | goto cdda_identify_scsi_fail; |
326 | } | | 297 | } |
327 | +#endif | | 298 | +#endif |
328 | | | 299 | |
329 | | | 300 | |
330 | d=calloc(1,sizeof(cdrom_drive)); | | 301 | d=calloc(1,sizeof(cdrom_drive)); |
331 | @@ -590,6 +726,7 @@ cdrom_drive *cdda_identify_scsi(const ch | | 302 | @@ -590,6 +709,7 @@ cdrom_drive *cdda_identify_scsi(const ch |
332 | d->bigendianp=-1; /* We don't know yet... */ | | 303 | d->bigendianp=-1; /* We don't know yet... */ |
333 | d->nsectors=-1; | | 304 | d->nsectors=-1; |
334 | | | 305 | |
335 | +#ifdef __linux__ | | 306 | +#ifdef __linux__ |
336 | version=verify_SG_version(d,messagedest,messages); | | 307 | version=verify_SG_version(d,messagedest,messages); |
337 | switch(version){ | | 308 | switch(version){ |
338 | case -1:case 0:case 1: | | 309 | case -1:case 0:case 1: |
339 | @@ -599,6 +736,9 @@ cdrom_drive *cdda_identify_scsi(const ch | | 310 | @@ -599,6 +719,9 @@ cdrom_drive *cdda_identify_scsi(const ch |
340 | d->interface=GENERIC_SCSI; | | 311 | d->interface=GENERIC_SCSI; |
341 | break; | | 312 | break; |
342 | } | | 313 | } |
343 | +#else | | 314 | +#else |
344 | + d->interface=GENERIC_SCSI; | | 315 | + d->interface=GENERIC_SCSI; |
345 | +#endif | | 316 | +#endif |
346 | | | 317 | |
347 | /* malloc our big buffer for scsi commands */ | | 318 | /* malloc our big buffer for scsi commands */ |
348 | d->sg=malloc(MAX_BIG_BUFF_SIZE); | | 319 | d->sg=malloc(MAX_BIG_BUFF_SIZE); |
349 | @@ -617,7 +757,16 @@ cdrom_drive *cdda_identify_scsi(const ch | | 320 | @@ -617,7 +740,16 @@ cdrom_drive *cdda_identify_scsi(const ch |
350 | | | 321 | |
351 | /* It would seem some TOSHIBA CDROMs gets things wrong */ | | 322 | /* It would seem some TOSHIBA CDROMs gets things wrong */ |
352 | | | 323 | |
353 | - if (!strncmp (p + 8, "TOSHIBA", 7) && | | 324 | - if (!strncmp (p + 8, "TOSHIBA", 7) && |
354 | +#ifndef TYPE_DISK | | 325 | +#ifndef TYPE_DISK |
355 | +#define TYPE_DISK 0 /* direct */ | | 326 | +#define TYPE_DISK 0 /* direct */ |
356 | +#endif | | 327 | +#endif |
357 | +#ifndef TYPE_WORM | | 328 | +#ifndef TYPE_WORM |
358 | +#define TYPE_WORM 4 /* write once, read many */ | | 329 | +#define TYPE_WORM 4 /* write once, read many */ |
359 | +#endif | | 330 | +#endif |
360 | +#ifndef TYPE_ROM | | 331 | +#ifndef TYPE_ROM |
361 | +#define TYPE_ROM 5 /* CD-ROM */ | | 332 | +#define TYPE_ROM 5 /* CD-ROM */ |
362 | +#endif | | 333 | +#endif |
363 | + if (p && !strncmp (p + 8, "TOSHIBA", 7) && | | 334 | + if (p && !strncmp (p + 8, "TOSHIBA", 7) && |
364 | !strncmp (p + 16, "CD-ROM", 6) && | | 335 | !strncmp (p + 16, "CD-ROM", 6) && |
365 | p[0] == TYPE_DISK) { | | 336 | p[0] == TYPE_DISK) { |
366 | p[0] = TYPE_ROM; | | 337 | p[0] = TYPE_ROM; |
367 | @@ -653,6 +802,88 @@ cdda_identify_scsi_fail: | | 338 | @@ -653,6 +785,88 @@ cdda_identify_scsi_fail: |
368 | if(g_fd!=-1)close(g_fd); | | 339 | if(g_fd!=-1)close(g_fd); |
369 | return(NULL); | | 340 | return(NULL); |
370 | } | | 341 | } |
371 | +#elif defined(__FreeBSD__) || defined(__DragonFly__) | | 342 | +#elif defined(__FreeBSD__) || defined(__DragonFly__) |
372 | +cdrom_drive *cdda_identify_scsi(const char *device, | | 343 | +cdrom_drive *cdda_identify_scsi(const char *device, |
373 | + const char *dummy, | | 344 | + const char *dummy, |
374 | + int messagedest, | | 345 | + int messagedest, |
375 | + char **messages) | | 346 | + char **messages) |
376 | +{ | | 347 | +{ |
377 | + char *devname; | | 348 | + char *devname; |
378 | + cdrom_drive *d = NULL; | | 349 | + cdrom_drive *d = NULL; |
379 | + | | 350 | + |
380 | + if (device == NULL) { | | 351 | + if (device == NULL) { |
| @@ -443,18 +414,18 @@ $NetBSD: patch-cf,v 1.9 2009/05/17 21:29 | | | @@ -443,18 +414,18 @@ $NetBSD: patch-cf,v 1.9 2009/05/17 21:29 |
443 | + if (d) { | | 414 | + if (d) { |
444 | + if (d->ccb) | | 415 | + if (d->ccb) |
445 | + cam_freeccb(d->ccb); | | 416 | + cam_freeccb(d->ccb); |
446 | + if (d->dev) | | 417 | + if (d->dev) |
447 | + cam_close_device(d->dev); | | 418 | + cam_close_device(d->dev); |
448 | + free(d); | | 419 | + free(d); |
449 | + } | | 420 | + } |
450 | + return NULL; | | 421 | + return NULL; |
451 | +} | | 422 | +} |
452 | +#endif | | 423 | +#endif |
453 | | | 424 | |
454 | #ifdef CDDA_TEST | | 425 | #ifdef CDDA_TEST |
455 | | | 426 | |
456 | @@ -702,3 +933,4 @@ cdrom_drive *cdda_identify_test(const ch | | 427 | @@ -702,3 +916,4 @@ cdrom_drive *cdda_identify_test(const ch |
457 | } | | 428 | } |
458 | | | 429 | |
459 | #endif | | 430 | #endif |
460 | +#endif /* __APPLE__ && __MACH__ */ | | 431 | +#endif /* __APPLE__ && __MACH__ */ |