ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/sys_unix.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/sys_unix.cpp (file contents):
Revision 1.17 by gbeauche, 2002-03-29T16:24:18Z vs.
Revision 1.23 by gbeauche, 2004-06-27T22:06:02Z

# Line 1 | Line 1
1   /*
2   *  sys_unix.cpp - System dependent routines, Unix implementation
3   *
4 < *  Basilisk II (C) 1997-2002 Christian Bauer
4 > *  Basilisk II (C) 1997-2004 Christian Bauer
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 24 | Line 24
24   #include <sys/stat.h>
25   #include <errno.h>
26  
27 + #ifdef HAVE_AVAILABILITYMACROS_H
28 + #include <AvailabilityMacros.h>
29 + #endif
30 +
31   #ifdef __linux__
32   #include <sys/mount.h>
33   #include <linux/cdrom.h>
# Line 77 | Line 81 | struct file_handle {
81          int cdrom_cap;          // CD-ROM capability flags (only valid if is_cdrom is true)
82   #elif defined(__FreeBSD__)
83          struct ioc_capability cdrom_cap;
84 + #elif defined(__APPLE__) && defined(__MACH__)
85 +        char    *ioctl_name;    // For CDs on OS X - a device for special ioctls
86 +        int             ioctl_fd;
87   #endif
88   };
89  
# Line 141 | Line 148 | void SysAddFloppyPrefs(void)
148   #elif defined(__NetBSD__)
149          PrefsAddString("floppy", "/dev/fd0a");
150          PrefsAddString("floppy", "/dev/fd1a");
151 + #elif defined(__APPLE__) && defined(__MACH__)
152 +  #if defined(AQUA) || defined(HAVE_FRAMEWORK_IOKIT)
153 +        extern  void DarwinAddFloppyPrefs(void);
154 +
155 +        DarwinAddFloppyPrefs();
156 +  #else
157 +        // Until I can convince the other guys that my Darwin code is useful,
158 +        // we just add something safe (a non-existant device):
159 +        PrefsAddString("floppy", "/dev/null");
160 +  #endif
161   #else
162          PrefsAddString("floppy", "/dev/fd0");
163          PrefsAddString("floppy", "/dev/fd1");
# Line 151 | Line 168 | void SysAddFloppyPrefs(void)
168   /*
169   *  This gets called when no "disk" prefs items are found
170   *  It scans for available HFS volumes and adds appropriate prefs items
171 + *      On OS X, we could do the same, but on an OS X machine I think it is
172 + *      very unlikely that any mounted volumes would contain a system which
173 + *      is old enough to boot a 68k Mac, so we just do nothing here for now.
174   */
175  
176   void SysAddDiskPrefs(void)
# Line 208 | Line 228 | void SysAddCDROMPrefs(void)
228                          closedir(cd_dir);
229                  }
230          }
231 < #elif defined(__FreeBSD__)
231 > #elif defined(__APPLE__) && defined(__MACH__)
232 >  #if defined(AQUA) || defined(HAVE_FRAMEWORK_IOKIT)
233 >        extern  void DarwinAddCDROMPrefs(void);
234 >
235 >        DarwinAddCDROMPrefs();
236 >  #else
237 >        // Until I can convince the other guys that my Darwin code is useful,
238 >        // we just do nothing (it is safe to have no cdrom device)
239 >  #endif
240 > #elif defined(__FreeBSD__) || defined(__NetBSD__)
241          PrefsAddString("cdrom", "/dev/cd0c");
213 #elif defined(__NetBSD__)
214        PrefsAddString("cdrom", "/dev/cd0d");
242   #endif
243   }
244  
# Line 236 | Line 263 | void SysAddSerialPrefs(void)
263   #elif defined(__NetBSD__)
264          PrefsAddString("seriala", "/dev/tty00");
265          PrefsAddString("serialb", "/dev/tty01");
266 + #elif defined(__APPLE__) && defined(__MACH__)
267 +  #if defined(AQUA) || defined(HAVE_FRAMEWORK_IOKIT)
268 +        extern  void DarwinAddSerialPrefs(void);
269 +
270 +        DarwinAddSerialPrefs();
271 +  #else
272 +        // Until I can convince the other guys that my Darwin code is useful,
273 +        // we just add something safe (non-existant devices):
274 +        PrefsAddString("seriala", "/dev/null");
275 +        PrefsAddString("serialb", "/dev/null");
276 +  #endif
277   #endif
278   }
279  
# Line 288 | Line 326 | void *Sys_open(const char *name, bool re
326          bool is_cdrom = strncmp(name, "/dev/cd", 7) == 0;
327   #endif
328  
329 + #if defined(__APPLE__) && defined(__MACH__)
330 +        //
331 +        // There is no set filename in /dev which is the cdrom,
332 +        // so we have to see if it is any of the devices that we found earlier
333 +        //
334 +        const char      *cdrom;
335 +        int                     tmp = 0;
336 +
337 +        while ( (cdrom = PrefsFindString("cdrom", tmp) ) != NULL )
338 +        {
339 +                if ( strcmp(name, cdrom) == 0 )
340 +                {
341 +                        is_cdrom = 1;
342 +                        read_only = 1;
343 +                        break;
344 +                }
345 +                ++tmp;
346 +        }
347 + #endif
348 +
349          D(bug("Sys_open(%s, %s)\n", name, read_only ? "read-only" : "read/write"));
350  
351          // Check if write access is allowed, set read-only flag if not
# Line 370 | Line 428 | void *Sys_open(const char *name, bool re
428                                          fh->is_floppy = ((st.st_rdev >> 16) == 2);
429   #endif
430                                  }
431 + #if defined(__APPLE__) && defined(__MACH__)
432 +
433 +                                // In OS X, the device name is OK for sending ioctls to,
434 +                                // but not for reading raw CDROM data from.
435 +                                // (it seems to have extra data padded in)
436 +                                //
437 +                                // So, we keep the already opened fiole handle,
438 +                                // and open a slightly different file for CDROM data
439 +                                //
440 +                                if ( is_cdrom )
441 +                                {
442 +                                        fh->ioctl_name  = fh->name;
443 +                                        fh->ioctl_fd    = fh->fd;
444 +
445 +                                        fh->name = (char *) malloc(strlen(name) + 2);
446 +                                        if ( fh->name )
447 +                                        {
448 +                                                *fh->name = '\0';
449 +                                                strcat(fh->name, name);
450 +                                                strcat(fh->name, "s1");
451 +                                                fh->fd = open(fh->name, (read_only ? O_RDONLY : O_RDWR));
452 +                                                if ( fh->fd < 0 ) {
453 +                                                        printf("WARNING: Cannot open %s (%s)\n",
454 +                                                                                        fh->name, strerror(errno));
455 +                                                        return NULL;
456 +                                                }
457 +                                        }
458 +                                }
459 + #endif
460                          }
461                  }
462                  if (fh->is_floppy && first_floppy == NULL)
# Line 507 | Line 594 | void SysEject(void *arg)
594                  close(fh->fd);  // Close and reopen so the driver will see the media change
595                  fh->fd = open(fh->name, O_RDONLY | O_NONBLOCK);
596          }
597 + #elif defined(__APPLE__) && defined(__MACH__)
598 +        if ( fh->is_cdrom ) {
599 +
600 +                // Stolen from IOKit/storage/IOMediaBSDClient.h
601 +                #define DKIOCEJECT _IO('d', 21)
602 +
603 +                close(fh->fd);
604 +                if ( ioctl(fh->ioctl_fd, DKIOCEJECT) < 0 )
605 +                {
606 +                        printf("ioctl(DKIOCEJECT) failed on file %s: %s\n",
607 +                                                                fh->ioctl_name, strerror(errno));
608 +
609 +                        // If we are running OSX, the device may be is busy
610 +                        // due to the Finder having the disk mounted and open,
611 +                        // so we have to use another method.
612 +
613 +                        // The only problem is that this takes about 5 seconds:
614 +
615 +                        char    *cmd = (char *) malloc(30+sizeof(fh->name));
616 +
617 +                        if ( ! cmd )
618 +                                return;
619 +                        close(fh->ioctl_fd);
620 +                        sprintf(cmd, "diskutil eject %s 2>&1 >/dev/null", fh->name);
621 +                        system(cmd);
622 +                }
623 +        }
624   #endif
625   }
626  
# Line 713 | Line 827 | bool SysCDReadTOC(void *arg, uint8 *toc)
827                  *toc++ = toc_size >> 8;
828                  *toc++ = toc_size & 0xff;
829                  return true;
830 + #elif defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_10_2)
831 +                extern  bool    DarwinCDReadTOC(char *name, uint8 *toc);
832 +
833 +                return  DarwinCDReadTOC(fh->name, toc);
834   #elif defined(__FreeBSD__)
835                  uint8 *p = toc + 2;
836  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines