~ubuntu-branches/ubuntu/feisty/basilisk2/feisty

« back to all changes in this revision

Viewing changes to src/MacOSX/sys_darwin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2005-07-30 20:42:20 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050730204220-1nl1cg2jkjvy63ry
Tags: 0.9.20050730-1
* New upstream CVS snapshot.
* Build-depend on virtual libsdl-dev (not libsdl1.2-dev).
* Invoke init rules also on clean (to separate better from official
  builds).
* Update URL of upstream source in debian/copyright.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *      $Id: sys_darwin.cpp,v 1.1 2003/03/21 07:05:28 nigel Exp $
 
2
 *      $Id: sys_darwin.cpp,v 1.8 2005/06/12 23:36:33 gbeauche Exp $
3
3
 *
4
4
 *      sys_darwin.cpp - Extra Darwin system dependant routines. Called by:
5
5
 *
7
7
 *
8
8
 *      Based on Apple's CDROMSample.c and Evan Jones' cd-discid.c patches
9
9
 *
10
 
 *  Basilisk II (C) 1997-2003 Christian Bauer
 
10
 *  Basilisk II (C) 1997-2005 Christian Bauer
11
11
 *
12
12
 *  This program is free software; you can redistribute it and/or modify
13
13
 *  it under the terms of the GNU General Public License as published by
28
28
#import <sys/param.h>
29
29
#import <IOKit/IOKitLib.h>
30
30
#import <IOKit/IOBSD.h>
 
31
#import <IOKit/serial/IOSerialKeys.h>
31
32
#import <IOKit/storage/IOMedia.h>
32
33
#import <IOKit/storage/IOMediaBSDClient.h>
 
34
#ifdef HAVE_IOKIT_STORAGE_IOBLOCKSTORAGEDEVICE_H
 
35
        #import <IOKit/storage/IOBlockStorageDevice.h>
 
36
#endif
33
37
#import <IOKit/storage/IOCDMedia.h>
34
38
#import <IOKit/storage/IOCDMediaBSDClient.h>
35
39
#import <CoreFoundation/CoreFoundation.h>
63
67
 
64
68
        // Let this task talk to the guts of the kernel:
65
69
        if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS )
66
 
                bug("IOMasterPort failed. Won't be able to do anything with CD drives");
 
70
                bug("IOMasterPort failed. Won't be able to do anything with CD drives\n");
67
71
 
68
72
 
69
73
        // CD media are instances of class kIOCDMediaClass
74
78
                // has a property with key kIOMediaEjectable.  We limit
75
79
                // the match only to those CDs that are actually ejectable
76
80
                CFDictionarySetValue(classesToMatch,
77
 
                                                         CFSTR(kIOMediaEjectable), kCFBooleanTrue); 
 
81
                                                         CFSTR(kIOMediaEjectableKey), kCFBooleanTrue); 
78
82
        }
79
83
 
80
84
        if ( IOServiceGetMatchingServices(masterPort,
90
94
        {
91
95
                char            bsdPath[MAXPATHLEN];
92
96
                CFTypeRef       bsdPathAsCFString =
93
 
                                                IORegistryEntryCreateCFProperty(nextCD, CFSTR(kIOBSDName),
94
 
                                                                                                                        kCFAllocatorDefault, 0);
 
97
                                                IORegistryEntryCreateCFProperty(nextCD,
 
98
                                                                                                                CFSTR(kIOBSDNameKey),
 
99
                                                                                                                kCFAllocatorDefault, 0);
95
100
                *bsdPath = '\0';
96
101
                if ( bsdPathAsCFString )
97
102
                {
105
110
                                                                         MAXPATHLEN - devPathLength,
106
111
                                                                         kCFStringEncodingASCII) )
107
112
                        {
108
 
                                // If we try to do raw reads on the file bsdPath (e.g. /dev/disk5),
109
 
                                // we get a lot of extra padding in the data. For some reason,
110
 
                                // the device we need has a different name (e.g. /dev/disk5s1)
111
 
                                //strcat(bsdPath, "s1");
112
113
                                D(bug("CDROM BSD path: %s\n", bsdPath));
 
114
                                PrefsAddString("cdrom", bsdPath);
113
115
                        }
114
116
                        else
115
117
                                D(bug("Could not get BSD device path for CD\n"));
116
118
 
117
119
                        CFRelease(bsdPathAsCFString);
118
120
                }
119
 
 
120
 
                PrefsAddString("cdrom", bsdPath);
 
121
                else
 
122
                        D(bug("Cannot determine bsdPath for CD\n"));
121
123
        }
122
124
 
123
125
        IOObjectRelease(nextCD);
125
127
}
126
128
 
127
129
 
 
130
void DarwinAddFloppyPrefs(void)
 
131
{
 
132
        mach_port_t                             masterPort;             // The way to talk to the kernel
 
133
        io_iterator_t                   allFloppies;    // List of possible floppys
 
134
        CFMutableDictionaryRef  classesToMatch;
 
135
        io_object_t                             nextFloppy;
 
136
 
 
137
 
 
138
        if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS )
 
139
                bug("IOMasterPort failed. Won't be able to do anything with floppy drives\n");
 
140
 
 
141
 
 
142
        // This selects all partitions of all disks
 
143
        classesToMatch = IOServiceMatching(kIOMediaClass); 
 
144
        if ( classesToMatch )
 
145
        {
 
146
                // Skip drivers and partitions
 
147
                CFDictionarySetValue(classesToMatch,
 
148
                                                         CFSTR(kIOMediaWholeKey), kCFBooleanTrue); 
 
149
        
 
150
                // Skip fixed drives (hard disks?)
 
151
                CFDictionarySetValue(classesToMatch,
 
152
                                                         CFSTR(kIOMediaEjectableKey), kCFBooleanTrue); 
 
153
        }
 
154
 
 
155
        if ( IOServiceGetMatchingServices(masterPort,
 
156
                                                                          classesToMatch, &allFloppies) != KERN_SUCCESS )
 
157
        {
 
158
                D(bug("IOServiceGetMatchingServices failed. No removable drives found?\n"));
 
159
                return;
 
160
        }
 
161
 
 
162
 
 
163
        // Iterate through each floppy
 
164
        while ( nextFloppy = IOIteratorNext(allFloppies))
 
165
        {
 
166
                char            bsdPath[MAXPATHLEN];
 
167
                CFTypeRef       bsdPathAsCFString =
 
168
                                                IORegistryEntryCreateCFProperty(nextFloppy,
 
169
                                                                                                                CFSTR(kIOBSDNameKey),
 
170
                                                                                                                kCFAllocatorDefault, 0);
 
171
                long            size;
 
172
                CFTypeRef       sizeAsCFNumber =
 
173
                                                IORegistryEntryCreateCFProperty(nextFloppy,
 
174
                                                                                                                CFSTR(kIOMediaSizeKey),
 
175
                                                                                                                kCFAllocatorDefault, 0);
 
176
 
 
177
                if ( CFNumberGetValue((CFNumberRef)sizeAsCFNumber,
 
178
                                                                kCFNumberSInt32Type, &size) )
 
179
                {
 
180
                        D(bug("Got size of %ld\n", size));
 
181
                        if ( size < 800 * 1024 || size > 1440 * 1024 )
 
182
                        {
 
183
                                D(puts("Device does not appear to be 800k or 1440k"));
 
184
                                continue;
 
185
                        }
 
186
                }
 
187
                else
 
188
                        bug("Couldn't get kIOMediaSizeKey of device");
 
189
                
 
190
                
 
191
                *bsdPath = '\0';
 
192
                if ( bsdPathAsCFString )
 
193
                {
 
194
                        size_t devPathLength;
 
195
 
 
196
                        strcpy(bsdPath, "/dev/");
 
197
                        devPathLength = strlen(bsdPath);
 
198
 
 
199
                        if ( CFStringGetCString((const __CFString *)bsdPathAsCFString,
 
200
                                                                         bsdPath + devPathLength,
 
201
                                                                         MAXPATHLEN - devPathLength,
 
202
                                                                         kCFStringEncodingASCII) )
 
203
                        {
 
204
                                D(bug("Floppy BSD path: %s\n", bsdPath));
 
205
                                PrefsAddString("floppy", bsdPath);
 
206
                        }
 
207
                        else
 
208
                                D(bug("Could not get BSD device path for floppy\n"));
 
209
 
 
210
                        CFRelease(bsdPathAsCFString);
 
211
                }
 
212
                else
 
213
                        D(bug("Cannot determine bsdPath for floppy\n"));
 
214
        }
 
215
 
 
216
        IOObjectRelease(nextFloppy);
 
217
        IOObjectRelease(allFloppies);
 
218
}
 
219
 
 
220
 
 
221
void DarwinAddSerialPrefs(void)
 
222
{
 
223
        mach_port_t                             masterPort;             // The way to talk to the kernel
 
224
        io_iterator_t                   allModems;              // List of modems on the system
 
225
        CFMutableDictionaryRef  classesToMatch;
 
226
        io_object_t                             nextModem;
 
227
 
 
228
 
 
229
        if ( IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS )
 
230
                bug("IOMasterPort failed. Won't be able to do anything with modems\n");
 
231
 
 
232
 
 
233
    // Serial devices are instances of class IOSerialBSDClient
 
234
    classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue);
 
235
        if ( classesToMatch )
 
236
        {
 
237
                // Narrow the search a little further. Each serial device object has
 
238
                // a property with key kIOSerialBSDTypeKey and a value that is one of
 
239
                // kIOSerialBSDAllTypes, kIOSerialBSDModemType, or kIOSerialBSDRS232Type.
 
240
 
 
241
        CFDictionarySetValue(classesToMatch,
 
242
                             CFSTR(kIOSerialBSDTypeKey),
 
243
                             CFSTR(kIOSerialBSDModemType));
 
244
 
 
245
        // This will find built-in and USB modems, but not serial modems.
 
246
        }
 
247
 
 
248
        if ( IOServiceGetMatchingServices(masterPort,
 
249
                                                                          classesToMatch, &allModems) != KERN_SUCCESS )
 
250
        {
 
251
                D(bug("IOServiceGetMatchingServices failed. No modems found?\n"));
 
252
                return;
 
253
        }
 
254
 
 
255
        // Iterate through each modem
 
256
        while ( nextModem = IOIteratorNext(allModems))
 
257
        {
 
258
                char            bsdPath[MAXPATHLEN];
 
259
                CFTypeRef       bsdPathAsCFString =
 
260
                                                IORegistryEntryCreateCFProperty(nextModem,
 
261
                                                                                                                CFSTR(kIOCalloutDeviceKey),
 
262
                                                                                                                // kIODialinDeviceKey?
 
263
                                                                                                                kCFAllocatorDefault, 0);
 
264
                *bsdPath = '\0';
 
265
                if ( bsdPathAsCFString )
 
266
                {
 
267
                        if ( CFStringGetCString((const __CFString *)bsdPathAsCFString,
 
268
                                                                         bsdPath, MAXPATHLEN,
 
269
                                                                         kCFStringEncodingASCII) )
 
270
                        {
 
271
                                D(bug("Modem BSD path: %s\n", bsdPath));
 
272
 
 
273
                                // Note that if there are multiple modems, we only get the last
 
274
                                PrefsAddString("seriala", bsdPath);
 
275
                        }
 
276
                        else
 
277
                                D(bug("Could not get BSD device path for modem\n"));
 
278
 
 
279
                        CFRelease(bsdPathAsCFString);
 
280
                }
 
281
                else
 
282
                        D(puts("Cannot determine bsdPath for modem\n"));
 
283
        }
 
284
 
 
285
        IOObjectRelease(nextModem);
 
286
        IOObjectRelease(allModems);
 
287
 
 
288
 
 
289
        // Getting a printer device is a bit harder. Creating a fake device
 
290
        // that emulates a simple printer (e.g. a HP DeskJet) is one possibility,
 
291
        // but for now I will just create a fake, safe, device entry:
 
292
 
 
293
        PrefsAddString("serialb", "/dev/null");
 
294
}
 
295
 
 
296
 
128
297
#ifdef MAC_OS_X_VERSION_10_2
129
298
/*
130
299
 *  Read CD-ROM TOC (binary MSF format, 804 bytes max.)