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.18 by cebix, 2002-04-28T14:06:17Z vs.
Revision 1.22 by nigel, 2004-01-26T11:08:52Z

# 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 77 | Line 77 | struct file_handle {
77          int cdrom_cap;          // CD-ROM capability flags (only valid if is_cdrom is true)
78   #elif defined(__FreeBSD__)
79          struct ioc_capability cdrom_cap;
80 + #elif defined(__APPLE__) && defined(__MACH__)
81 +        char    *ioctl_name;    // For CDs on OS X - a device for special ioctls
82 +        int             ioctl_fd;
83   #endif
84   };
85  
# Line 141 | Line 144 | void SysAddFloppyPrefs(void)
144   #elif defined(__NetBSD__)
145          PrefsAddString("floppy", "/dev/fd0a");
146          PrefsAddString("floppy", "/dev/fd1a");
147 + #elif defined(__APPLE__) && defined(__MACH__)
148 +  #ifdef AQUA
149 +        extern  void DarwinAddFloppyPrefs(void);
150 +
151 +        DarwinAddFloppyPrefs();
152 +  #else
153 +        // Until I can convince the other guys that my Darwin code is useful,
154 +        // we just add something safe (a non-existant device):
155 +        PrefsAddString("floppy", "/dev/null");
156 +  #endif
157   #else
158          PrefsAddString("floppy", "/dev/fd0");
159          PrefsAddString("floppy", "/dev/fd1");
# Line 151 | Line 164 | void SysAddFloppyPrefs(void)
164   /*
165   *  This gets called when no "disk" prefs items are found
166   *  It scans for available HFS volumes and adds appropriate prefs items
167 + *      On OS X, we could do the same, but on an OS X machine I think it is
168 + *      very unlikely that any mounted volumes would contain a system which
169 + *      is old enough to boot a 68k Mac, so we just do nothing here for now.
170   */
171  
172   void SysAddDiskPrefs(void)
# Line 208 | Line 224 | void SysAddCDROMPrefs(void)
224                          closedir(cd_dir);
225                  }
226          }
227 + #elif defined(__APPLE__) && defined(__MACH__)
228 +  #ifdef AQUA
229 +        extern  void DarwinAddCDROMPrefs(void);
230 +
231 +        DarwinAddCDROMPrefs();
232 +  #else
233 +        // Until I can convince the other guys that my Darwin code is useful,
234 +        // we just do nothing (it is safe to have no cdrom device)
235 +  #endif
236   #elif defined(__FreeBSD__) || defined(__NetBSD__)
237          PrefsAddString("cdrom", "/dev/cd0c");
238   #endif
# Line 234 | Line 259 | void SysAddSerialPrefs(void)
259   #elif defined(__NetBSD__)
260          PrefsAddString("seriala", "/dev/tty00");
261          PrefsAddString("serialb", "/dev/tty01");
262 + #elif defined(__APPLE__) && defined(__MACH__)
263 +  #ifdef AQUA
264 +        extern  void DarwinAddSerialPrefs(void);
265 +
266 +        DarwinAddSerialPrefs();
267 +  #else
268 +        // Until I can convince the other guys that my Darwin code is useful,
269 +        // we just add something safe (non-existant devices):
270 +        PrefsAddString("seriala", "/dev/null");
271 +        PrefsAddString("serialb", "/dev/null");
272 +  #endif
273   #endif
274   }
275  
# Line 286 | Line 322 | void *Sys_open(const char *name, bool re
322          bool is_cdrom = strncmp(name, "/dev/cd", 7) == 0;
323   #endif
324  
325 + #if defined(__APPLE__) && defined(__MACH__)
326 +        //
327 +        // There is no set filename in /dev which is the cdrom,
328 +        // so we have to see if it is any of the devices that we found earlier
329 +        //
330 +        const char      *cdrom;
331 +        int                     tmp = 0;
332 +
333 +        while ( (cdrom = PrefsFindString("cdrom", tmp) ) != NULL )
334 +        {
335 +                if ( strcmp(name, cdrom) == 0 )
336 +                {
337 +                        is_cdrom = 1;
338 +                        read_only = 1;
339 +                        break;
340 +                }
341 +                ++tmp;
342 +        }
343 + #endif
344 +
345          D(bug("Sys_open(%s, %s)\n", name, read_only ? "read-only" : "read/write"));
346  
347          // Check if write access is allowed, set read-only flag if not
# Line 368 | Line 424 | void *Sys_open(const char *name, bool re
424                                          fh->is_floppy = ((st.st_rdev >> 16) == 2);
425   #endif
426                                  }
427 + #if defined(__APPLE__) && defined(__MACH__)
428 +
429 +                                // In OS X, the device name is OK for sending ioctls to,
430 +                                // but not for reading raw CDROM data from.
431 +                                // (it seems to have extra data padded in)
432 +                                //
433 +                                // So, we keep the already opened fiole handle,
434 +                                // and open a slightly different file for CDROM data
435 +                                //
436 +                                if ( is_cdrom )
437 +                                {
438 +                                        fh->ioctl_name  = fh->name;
439 +                                        fh->ioctl_fd    = fh->fd;
440 +
441 +                                        fh->name = (char *) malloc(strlen(name) + 2);
442 +                                        if ( fh->name )
443 +                                        {
444 +                                                *fh->name = '\0';
445 +                                                strcat(fh->name, name);
446 +                                                strcat(fh->name, "s1");
447 +                                                fh->fd = open(fh->name, (read_only ? O_RDONLY : O_RDWR));
448 +                                                if ( fh->fd < 0 ) {
449 +                                                        printf("WARNING: Cannot open %s (%s)\n",
450 +                                                                                        fh->name, strerror(errno));
451 +                                                        return NULL;
452 +                                                }
453 +                                        }
454 +                                }
455 + #endif
456                          }
457                  }
458                  if (fh->is_floppy && first_floppy == NULL)
# Line 505 | Line 590 | void SysEject(void *arg)
590                  close(fh->fd);  // Close and reopen so the driver will see the media change
591                  fh->fd = open(fh->name, O_RDONLY | O_NONBLOCK);
592          }
593 + #elif defined(__APPLE__) && defined(__MACH__)
594 +        if ( fh->is_cdrom ) {
595 +
596 +                // Stolen from IOKit/storage/IOMediaBSDClient.h
597 +                #define DKIOCEJECT _IO('d', 21)
598 +
599 +                close(fh->fd);
600 +                if ( ioctl(fh->ioctl_fd, DKIOCEJECT) < 0 )
601 +                {
602 +                        printf("ioctl(DKIOCEJECT) failed on file %s: %s\n",
603 +                                                                fh->ioctl_name, strerror(errno));
604 +
605 +                        // If we are running OSX, the device may be is busy
606 +                        // due to the Finder having the disk mounted and open,
607 +                        // so we have to use another method.
608 +
609 +                        // The only problem is that this takes about 5 seconds:
610 +
611 +                        char    *cmd = (char *) malloc(30+sizeof(fh->name));
612 +
613 +                        if ( ! cmd )
614 +                                return;
615 +                        close(fh->ioctl_fd);
616 +                        sprintf(cmd, "diskutil eject %s 2>&1 >/dev/null", fh->name);
617 +                        system(cmd);
618 +                }
619 +        }
620   #endif
621   }
622  
# Line 711 | Line 823 | bool SysCDReadTOC(void *arg, uint8 *toc)
823                  *toc++ = toc_size >> 8;
824                  *toc++ = toc_size & 0xff;
825                  return true;
826 + #elif defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_10_2)
827 +                extern  bool    DarwinCDReadTOC(char *name, uint8 *toc);
828 +
829 +                return  DarwinCDReadTOC(fh->name, toc);
830   #elif defined(__FreeBSD__)
831                  uint8 *p = toc + 2;
832  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines