Skip to content

Commit

Permalink
apple: macOS 12.0 deprecated things called "master" for "main".
Browse files Browse the repository at this point in the history
Try to look for the new name in the process's namespace before falling back
to the old one (and giving up on CD-ROM detection if everything falls apart).

iOS has PHYSFS_NO_CDROM_SUPPORT defined, so this isn't used there.
  • Loading branch information
icculus committed Sep 29, 2022
1 parent 49662cd commit 6a7625c
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/physfs_platform_apple.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#ifdef PHYSFS_PLATFORM_APPLE

#include <Foundation/Foundation.h>
#include <dlfcn.h>

#include "physfs_internal.h"

Expand Down Expand Up @@ -99,18 +100,18 @@ static int darwinIsWholeMedia(io_service_t service)
} /* darwinIsWholeMedia */


static int darwinIsMountedDisc(char *bsdName, mach_port_t masterPort)
static int darwinIsMountedDisc(char *bsdName, mach_port_t mainPort)
{
int retval = 0;
CFMutableDictionaryRef matchingDict;
kern_return_t rc;
io_iterator_t iter;
io_service_t service;

if ((matchingDict = IOBSDNameMatching(masterPort, 0, bsdName)) == NULL)
if ((matchingDict = IOBSDNameMatching(mainPort, 0, bsdName)) == NULL)
return 0;

rc = IOServiceGetMatchingServices(masterPort, matchingDict, &iter);
rc = IOServiceGetMatchingServices(mainPort, matchingDict, &iter);
if ((rc != KERN_SUCCESS) || (!iter))
return 0;

Expand Down Expand Up @@ -158,13 +159,25 @@ static int darwinIsMountedDisc(char *bsdName, mach_port_t masterPort)
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
{
#if !defined(PHYSFS_NO_CDROM_SUPPORT)
/* macOS 12.0 changed "master" names to "main". */
typedef kern_return_t (*ioMainPortFn)(mach_port_t, mach_port_t *);
static ioMainPortFn ioMainPort = NULL;
const char *devPrefix = "/dev/";
const int prefixLen = strlen(devPrefix);
mach_port_t masterPort = 0;
mach_port_t mainPort = 0;
struct statfs *mntbufp;
int i, mounts;

if (IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS)
if (ioMainPort == NULL)
{
ioMainPort = (ioMainPortFn) dlsym(RTLD_DEFAULT, "IOMainPort");
if (!ioMainPort)
ioMainPort = (ioMainPortFn) dlsym(RTLD_DEFAULT, "IOMasterPort");
if (!ioMainPort)
return; /* oh well, no CD-ROMs for you. */
} /* if */

if (ioMainPort(MACH_PORT_NULL, &mainPort) != KERN_SUCCESS)
BAIL(PHYSFS_ERR_OS_ERROR, ) /*return void*/;

mounts = getmntinfo(&mntbufp, MNT_WAIT); /* NOT THREAD SAFE! */
Expand All @@ -176,7 +189,7 @@ void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
continue;

dev += prefixLen;
if (darwinIsMountedDisc(dev, masterPort))
if (darwinIsMountedDisc(dev, mainPort))
cb(data, mnt);
} /* for */
#endif /* !defined(PHYSFS_NO_CDROM_SUPPORT) */
Expand Down

0 comments on commit 6a7625c

Please sign in to comment.