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.33 by asvitkine, 2010-10-19T03:21:52Z vs.
Revision 1.34 by asvitkine, 2012-03-01T04:22:27Z

# Line 70 | Line 70
70   #include "debug.h"
71  
72   // File handles are pointers to these structures
73 < struct file_handle {
73 > struct mac_file_handle {
74          char *name;             // Copy of device/file name
75          int fd;
76  
# Line 105 | Line 105 | struct file_handle {
105   };
106  
107   // Open file handles
108 < struct open_file_handle {
109 <        file_handle *fh;
110 <        open_file_handle *next;
108 > struct open_mac_file_handle {
109 >        mac_file_handle *fh;
110 >        open_mac_file_handle *next;
111   };
112 < static open_file_handle *open_file_handles = NULL;
112 > static open_mac_file_handle *open_mac_file_handles = NULL;
113  
114   // File handle of first floppy drive (for SysMountFirstFloppy())
115 < static file_handle *first_floppy = NULL;
115 > static mac_file_handle *first_floppy = NULL;
116  
117   // Prototypes
118 < static void cdrom_close(file_handle *fh);
119 < static bool cdrom_open(file_handle *fh, const char *path = NULL);
118 > static void cdrom_close(mac_file_handle *fh);
119 > static bool cdrom_open(mac_file_handle *fh, const char *path = NULL);
120  
121  
122   /*
# Line 149 | Line 149 | void SysExit(void)
149   *  Manage open file handles
150   */
151  
152 < static void sys_add_file_handle(file_handle *fh)
152 > static void sys_add_mac_file_handle(mac_file_handle *fh)
153   {
154 <        open_file_handle *p = new open_file_handle;
154 >        open_mac_file_handle *p = new open_mac_file_handle;
155          p->fh = fh;
156 <        p->next = open_file_handles;
157 <        open_file_handles = p;
156 >        p->next = open_mac_file_handles;
157 >        open_mac_file_handles = p;
158   }
159  
160 < static void sys_remove_file_handle(file_handle *fh)
160 > static void sys_remove_mac_file_handle(mac_file_handle *fh)
161   {
162 <        open_file_handle *p = open_file_handles;
163 <        open_file_handle *q = NULL;
162 >        open_mac_file_handle *p = open_mac_file_handles;
163 >        open_mac_file_handle *q = NULL;
164  
165          while (p) {
166                  if (p->fh == fh) {
167                          if (q)
168                                  q->next = p->next;
169                          else
170 <                                open_file_handles = p->next;
170 >                                open_mac_file_handles = p->next;
171                          delete p;
172                          break;
173                  }
# Line 188 | Line 188 | void SysMediaArrived(const char *path, i
188                  PrefsReplaceString("cdrom", path);
189  
190          // Wait for media to be available for reading
191 <        if (open_file_handles) {
191 >        if (open_mac_file_handles) {
192                  const int MAX_WAIT = 5;
193                  for (int i = 0; i < MAX_WAIT; i++) {
194                          if (access(path, R_OK) == 0)
# Line 204 | Line 204 | void SysMediaArrived(const char *path, i
204                  }
205          }
206  
207 <        for (open_file_handle *p = open_file_handles; p != NULL; p = p->next) {
208 <                file_handle * const fh = p->fh;
207 >        for (open_mac_file_handle *p = open_mac_file_handles; p != NULL; p = p->next) {
208 >                mac_file_handle * const fh = p->fh;
209  
210                  // Re-open CD-ROM device
211                  if (fh->is_cdrom && type == MEDIA_CD) {
# Line 228 | Line 228 | void SysMediaRemoved(const char *path, i
228          if ((type & MEDIA_REMOVABLE) != MEDIA_CD)
229                  return;
230  
231 <        for (open_file_handle *p = open_file_handles; p != NULL; p = p->next) {
232 <                file_handle * const fh = p->fh;
231 >        for (open_mac_file_handle *p = open_mac_file_handles; p != NULL; p = p->next) {
232 >                mac_file_handle * const fh = p->fh;
233  
234                  // Mark media as not available
235                  if (!fh->is_cdrom || !fh->is_media_present)
# Line 416 | Line 416 | void SysAddSerialPrefs(void)
416   *  Open CD-ROM device and initialize internal data
417   */
418  
419 < static bool cdrom_open_1(file_handle *fh)
419 > static bool cdrom_open_1(mac_file_handle *fh)
420   {
421   #if defined __MACOSX__
422          // In OS X, the device name is OK for sending ioctls to,
# Line 441 | Line 441 | static bool cdrom_open_1(file_handle *fh
441          return true;
442   }
443  
444 < bool cdrom_open(file_handle *fh, const char *path)
444 > bool cdrom_open(mac_file_handle *fh, const char *path)
445   {
446          if (path)
447                  fh->name = strdup(path);
# Line 457 | Line 457 | bool cdrom_open(file_handle *fh, const c
457   *  Close a CD-ROM device
458   */
459  
460 < void cdrom_close(file_handle *fh)
460 > void cdrom_close(mac_file_handle *fh)
461   {
462  
463          if (fh->fd >= 0) {
# Line 519 | Line 519 | static bool is_drive_mounted(const char
519   *  Open file/device, create new file handle (returns NULL on error)
520   */
521  
522 < static file_handle *open_filehandle(const char *name)
522 > static mac_file_handle *open_filehandle(const char *name)
523   {
524 <                file_handle *fh = new file_handle;
525 <                memset(fh, 0, sizeof(file_handle));
524 >                mac_file_handle *fh = new mac_file_handle;
525 >                memset(fh, 0, sizeof(mac_file_handle));
526                  fh->name = strdup(name);
527                  fh->fd = -1;
528   #if defined __MACOSX__
# Line 588 | Line 588 | void *Sys_open(const char *name, bool re
588   #if defined(BINCUE)
589          void *binfd = open_bincue(name);
590          if (binfd) {
591 <                file_handle *fh = open_filehandle(name);
591 >                mac_file_handle *fh = open_filehandle(name);
592                  D(bug("opening %s as bincue\n", name));
593                  fh->bincue_fd = binfd;
594                  fh->is_bincue = true;
595                  fh->read_only = true;
596                  fh->is_media_present = true;
597 <                sys_add_file_handle(fh);
597 >                sys_add_mac_file_handle(fh);
598                  return fh;
599          }
600   #endif
# Line 604 | Line 604 | void *Sys_open(const char *name, bool re
604          int vhdsize;
605          void *vhdfd = vhd_unix_open(name, &vhdsize, read_only);
606          if (vhdfd) {
607 <                file_handle *fh = open_filehandle(name);
607 >                mac_file_handle *fh = open_filehandle(name);
608                  D(bug("opening %s as vnd\n", name));
609                  fh->is_vhd = true;
610                  fh->vhd_fd = vhdfd;
611                  fh->read_only = read_only;
612                  fh->file_size = vhdsize;
613                  fh->is_media_present = true;
614 <                sys_add_file_handle(fh);
614 >                sys_add_mac_file_handle(fh);
615                  return fh;
616          }
617   #endif
# Line 627 | Line 627 | void *Sys_open(const char *name, bool re
627                  fd = open(name, O_RDONLY);
628          }
629          if (fd >= 0 || is_polled_media) {
630 <                file_handle *fh = open_filehandle(name);
630 >                mac_file_handle *fh = open_filehandle(name);
631                  fh->fd = fd;
632                  fh->is_file = is_file;
633                  fh->read_only = read_only;
# Line 681 | Line 681 | void *Sys_open(const char *name, bool re
681                  }
682                  if (fh->is_floppy && first_floppy == NULL)
683                          first_floppy = fh;
684 <                sys_add_file_handle(fh);
684 >                sys_add_mac_file_handle(fh);
685                  return fh;
686          } else {
687                  printf("WARNING: Cannot open %s (%s)\n", name, strerror(errno));
# Line 696 | Line 696 | void *Sys_open(const char *name, bool re
696  
697   void Sys_close(void *arg)
698   {
699 <        file_handle *fh = (file_handle *)arg;
699 >        mac_file_handle *fh = (mac_file_handle *)arg;
700          if (!fh)
701                  return;
702  
703 <        sys_remove_file_handle(fh);
703 >        sys_remove_mac_file_handle(fh);
704  
705   #if defined(HAVE_LIBVHD)
706          if (fh->is_vhd)
# Line 729 | Line 729 | void Sys_close(void *arg)
729  
730   size_t Sys_read(void *arg, void *buffer, loff_t offset, size_t length)
731   {
732 <        file_handle *fh = (file_handle *)arg;
732 >        mac_file_handle *fh = (mac_file_handle *)arg;
733          if (!fh)
734                  return 0;
735  
# Line 759 | Line 759 | size_t Sys_read(void *arg, void *buffer,
759  
760   size_t Sys_write(void *arg, void *buffer, loff_t offset, size_t length)
761   {
762 <        file_handle *fh = (file_handle *)arg;
762 >        mac_file_handle *fh = (mac_file_handle *)arg;
763          if (!fh)
764                  return 0;
765  
# Line 783 | Line 783 | size_t Sys_write(void *arg, void *buffer
783  
784   loff_t SysGetFileSize(void *arg)
785   {
786 <        file_handle *fh = (file_handle *)arg;
786 >        mac_file_handle *fh = (mac_file_handle *)arg;
787          if (!fh)
788                  return true;
789  
# Line 829 | Line 829 | loff_t SysGetFileSize(void *arg)
829  
830   void SysEject(void *arg)
831   {
832 <        file_handle *fh = (file_handle *)arg;
832 >        mac_file_handle *fh = (mac_file_handle *)arg;
833          if (!fh)
834                  return;
835  
# Line 887 | Line 887 | void SysEject(void *arg)
887  
888   bool SysFormat(void *arg)
889   {
890 <        file_handle *fh = (file_handle *)arg;
890 >        mac_file_handle *fh = (mac_file_handle *)arg;
891          if (!fh)
892                  return false;
893  
# Line 902 | Line 902 | bool SysFormat(void *arg)
902  
903   bool SysIsReadOnly(void *arg)
904   {
905 <        file_handle *fh = (file_handle *)arg;
905 >        mac_file_handle *fh = (mac_file_handle *)arg;
906          if (!fh)
907                  return true;
908  
# Line 926 | Line 926 | bool SysIsReadOnly(void *arg)
926  
927   bool SysIsFixedDisk(void *arg)
928   {
929 <        file_handle *fh = (file_handle *)arg;
929 >        mac_file_handle *fh = (mac_file_handle *)arg;
930          if (!fh)
931                  return true;
932  
# Line 950 | Line 950 | bool SysIsFixedDisk(void *arg)
950  
951   bool SysIsDiskInserted(void *arg)
952   {
953 <        file_handle *fh = (file_handle *)arg;
953 >        mac_file_handle *fh = (mac_file_handle *)arg;
954          if (!fh)
955                  return false;
956  
# Line 1014 | Line 1014 | bool SysIsDiskInserted(void *arg)
1014  
1015   void SysPreventRemoval(void *arg)
1016   {
1017 <        file_handle *fh = (file_handle *)arg;
1017 >        mac_file_handle *fh = (mac_file_handle *)arg;
1018          if (!fh)
1019                  return;
1020  
# Line 1031 | Line 1031 | void SysPreventRemoval(void *arg)
1031  
1032   void SysAllowRemoval(void *arg)
1033   {
1034 <        file_handle *fh = (file_handle *)arg;
1034 >        mac_file_handle *fh = (mac_file_handle *)arg;
1035          if (!fh)
1036                  return;
1037  
# Line 1048 | Line 1048 | void SysAllowRemoval(void *arg)
1048  
1049   bool SysCDReadTOC(void *arg, uint8 *toc)
1050   {
1051 <        file_handle *fh = (file_handle *)arg;
1051 >        mac_file_handle *fh = (mac_file_handle *)arg;
1052          if (!fh)
1053                  return false;
1054  
# Line 1195 | Line 1195 | bool SysCDReadTOC(void *arg, uint8 *toc)
1195  
1196   bool SysCDGetPosition(void *arg, uint8 *pos)
1197   {
1198 <        file_handle *fh = (file_handle *)arg;
1198 >        mac_file_handle *fh = (mac_file_handle *)arg;
1199          if (!fh)
1200                  return false;
1201  
# Line 1265 | Line 1265 | bool SysCDGetPosition(void *arg, uint8 *
1265  
1266   bool SysCDPlay(void *arg, uint8 start_m, uint8 start_s, uint8 start_f, uint8 end_m, uint8 end_s, uint8 end_f)
1267   {
1268 <        file_handle *fh = (file_handle *)arg;
1268 >        mac_file_handle *fh = (mac_file_handle *)arg;
1269          if (!fh)
1270                  return false;
1271  
# Line 1307 | Line 1307 | bool SysCDPlay(void *arg, uint8 start_m,
1307  
1308   bool SysCDPause(void *arg)
1309   {
1310 <        file_handle *fh = (file_handle *)arg;
1310 >        mac_file_handle *fh = (mac_file_handle *)arg;
1311          if (!fh)
1312                  return false;
1313  
# Line 1335 | Line 1335 | bool SysCDPause(void *arg)
1335  
1336   bool SysCDResume(void *arg)
1337   {
1338 <        file_handle *fh = (file_handle *)arg;
1338 >        mac_file_handle *fh = (mac_file_handle *)arg;
1339          if (!fh)
1340                  return false;
1341  
# Line 1364 | Line 1364 | bool SysCDResume(void *arg)
1364  
1365   bool SysCDStop(void *arg, uint8 lead_out_m, uint8 lead_out_s, uint8 lead_out_f)
1366   {
1367 <        file_handle *fh = (file_handle *)arg;
1367 >        mac_file_handle *fh = (mac_file_handle *)arg;
1368          if (!fh)
1369                  return false;
1370  
# Line 1393 | Line 1393 | bool SysCDStop(void *arg, uint8 lead_out
1393  
1394   bool SysCDScan(void *arg, uint8 start_m, uint8 start_s, uint8 start_f, bool reverse)
1395   {
1396 <        file_handle *fh = (file_handle *)arg;
1396 >        mac_file_handle *fh = (mac_file_handle *)arg;
1397          if (!fh)
1398                  return false;
1399  
# Line 1408 | Line 1408 | bool SysCDScan(void *arg, uint8 start_m,
1408  
1409   void SysCDSetVolume(void *arg, uint8 left, uint8 right)
1410   {
1411 <        file_handle *fh = (file_handle *)arg;
1411 >        mac_file_handle *fh = (mac_file_handle *)arg;
1412          if (!fh)
1413                  return;
1414  
# Line 1434 | Line 1434 | void SysCDSetVolume(void *arg, uint8 lef
1434  
1435   void SysCDGetVolume(void *arg, uint8 &left, uint8 &right)
1436   {
1437 <        file_handle *fh = (file_handle *)arg;
1437 >        mac_file_handle *fh = (mac_file_handle *)arg;
1438          if (!fh)
1439                  return;
1440  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines