block/file-posix: Remove a deprecation warning on macOS 12
RFC PATCH 1/1 block/file-posix: Remove a deprecation warning on macOS 12
When building on macOS 12 we get:
../block/file-posix.c:3335:18: warning: 'IOMasterPort' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
kernResult = IOMasterPort( MACH_PORT_NULL, &masterPort );
^~~~~~~~~~~~
IOMainPortUse IOMainPort (define it to IOMasterPort on macOS < 12), and replace 'master' by 'main' in a variable name.
--- block/file-posix.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
block/file-posix.c +9 -4
@@ -3324,17 +3324,22 @@ BlockDriver bdrv_file = {#if defined(__APPLE__) && defined(__MACH__)static kern_return_t GetBSDPath (io_iterator_t mediaIterator,char *bsdPath,CFIndex maxPathSize,int flags); + +#if !defined(MAC_OS_VERSION_12_0 ) +#define IOMainPort IOMasterPort +#endif +static char *FindEjectableOpticalMedia (io_iterator_t *mediaIterator) {kern_return_t kernResult =KERN_FAILURE ; -mach_port_t masterPort; +mach_port_t mainPort;CFMutableDictionaryRef classesToMatch;const char *matching_array[] = {kIODVDMediaClass, kIOCDMediaClass};char *mediaType =NULL ; - kernResult =IOMasterPort (MACH_PORT_NULL , &masterPort ); + kernResult =IOMainPort (MACH_PORT_NULL , &mainPort);if (KERN_SUCCESS != kernResult ) { -printf ("IOMasterPort returned %d\n" , kernResult ); +printf ("IOMainPort returned %d\n" , kernResult); }int index;
@@ -3347,7 +3352,7 @@ static char *FindEjectableOpticalMedia(io_iterator_t *mediaIterator) }CFDictionarySetValue (classesToMatch,CFSTR (kIOMediaEjectableKey), kCFBooleanTrue); - kernResult =IOServiceGetMatchingServices (masterPort, classesToMatch, + kernResult =IOServiceGetMatchingServices (mainPort, classesToMatch, mediaIterator);if (kernResult !=KERN_SUCCESS ) { error_report("Note: IOServiceGetMatchingServices returned %d",
Signature · 1 line
2.33.1
Quoted 7 lines · Philippe Mathieu-Daudé
When building on macOS 12 we get:
../block/file-posix.c:3335:18: warning: 'IOMasterPort' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations] kernResult = IOMasterPort( MACH_PORT_NULL, &masterPort ); ^~~~~~~~~~~~ IOMainPort
Quoted 7 lines
Use IOMainPort (define it to IOMasterPort on macOS < 12), and replace 'master' by 'main' in a variable name.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- block/file-posix.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
I hope the [RFC] tag isn’t directed at me.
Still, I can give my comment, of course.
block/file-posix.c BlockDriver bdrv_file = { · line 3328
Quoted 10 lines
block/file-posix.c +2
-0@@ -3324,17 +3324,22 @@ BlockDriver bdrv_file = {#if defined(__APPLE__) && defined(__MACH__)static kern_return_t GetBSDPath (io_iterator_t mediaIterator,char *bsdPath,CFIndex maxPathSize,int flags); + +#if !defined(MAC_OS_VERSION_12_0 )
So AFAIU from my quick rather fruit-less googling, this macro is defined (to some version-defining integer) on every macOS version starting from 12.0? (Just confirming because the name could also mean it’d be defined only on 12.0.)
Quoted 21 lines
block/file-posix.c +6
-3+#define IOMainPort IOMasterPort +#endif +static char *FindEjectableOpticalMedia (io_iterator_t *mediaIterator) {kern_return_t kernResult =KERN_FAILURE ; -mach_port_t masterPort; +mach_port_t mainPort;CFMutableDictionaryRef classesToMatch;const char *matching_array[] = {kIODVDMediaClass, kIOCDMediaClass};char *mediaType =NULL ; - kernResult =IOMasterPort (MACH_PORT_NULL , &masterPort ); + kernResult =IOMainPort (MACH_PORT_NULL , &mainPort);if (KERN_SUCCESS != kernResult ) { -printf ("IOMasterPort returned %d\n" , kernResult ); +printf ("IOMainPort returned %d\n" , kernResult); }int index;
block/file-posix.c static char *FindEjectableOpticalMedia(io_iterator_t *mediaIterator) · line 3358
Quoted 8 lines
block/file-posix.c +1
-1@@ -3347,7 +3352,7 @@ static char *FindEjectableOpticalMedia(io_iterator_t *mediaIterator) }CFDictionarySetValue (classesToMatch,CFSTR (kIOMediaEjectableKey), kCFBooleanTrue); - kernResult =IOServiceGetMatchingServices (masterPort, classesToMatch, + kernResult =IOServiceGetMatchingServices (mainPort, classesToMatch, mediaIterator);if (kernResult !=KERN_SUCCESS ) { error_report("Note: IOServiceGetMatchingServices returned %d",
“Looks good to me” ← here’s the comment you requested O:)
Hanna
Quoted 20 lines · Hanna Reitz
Quoted 7 lines · Philippe Mathieu-Daudé
When building on macOS 12 we get:
../block/file-posix.c:3335:18: warning: 'IOMasterPort' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations] kernResult =IOMasterPort( MACH_PORT_NULL, &masterPort );
^~~~~~~~~~~~
IOMainPortQuoted 7 lines
Use IOMainPort (define it to IOMasterPort on macOS < 12), and replace 'master' by 'main' in a variable name.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
block/file-posix.c| 13 +++++++++----1 file changed, 9 insertions(+), 4 deletions(-)I hope the [RFC] tag isn’t directed at me.
Still, I can give my comment, of course.
Quoted 12 lines
block/file-posix.c BlockDriver bdrv_file = { · line 3328
Quoted 10 lines
block/file-posix.c +2
-0@@ -3324,17 +3324,22 @@ BlockDriver bdrv_file = { #if defined(__APPLE__) && defined(__MACH__) static kern_return_t GetBSDPath(io_iterator_t mediaIterator, char *bsdPath, CFIndex maxPathSize, int flags); + +#if !defined(MAC_OS_VERSION_12_0 )So AFAIU from my quick rather fruit-less googling, this macro is defined (to some version-defining integer) on every macOS version starting from 12.0? (Just confirming because the name could also mean it’d be defined only on 12.0.)
Thanks, I posted up to v3 and macOS users helped me, I will post a v4 soon.
v3: https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 24 lines
Quoted 24 lines
block/file-posix.c +6
-4+#define IOMainPort IOMasterPort +#endif + static char *FindEjectableOpticalMedia(io_iterator_t *mediaIterator) { kern_return_t kernResult = KERN_FAILURE; - mach_port_t masterPort; + mach_port_t mainPort; CFMutableDictionaryRef classesToMatch; const char *matching_array[] = {kIODVDMediaClass, kIOCDMediaClass}; char *mediaType = NULL; - kernResult = IOMasterPort( MACH_PORT_NULL, &masterPort ); + kernResult = IOMainPort(MACH_PORT_NULL, &mainPort); if ( KERN_SUCCESS != kernResult ) { - printf( "IOMasterPort returned %d\n", kernResult ); + printf("IOMainPort returned %d\n", kernResult); } int index;@@ -3347,7 +3352,7 @@ static char *FindEjectableOpticalMedia (io_iterator_t *mediaIterator) } CFDictionarySetValue(classesToMatch, CFSTR(kIOMediaEjectableKey), kCFBooleanTrue); - kernResult = IOServiceGetMatchingServices(masterPort,
Quoted 8 lines
Quoted 6 lines
block/file-posix.c +1
-0classesToMatch, + kernResult = IOServiceGetMatchingServices(mainPort, classesToMatch,mediaIterator); if (kernResult !=
KERN_SUCCESS) {
error_report("Note: IOServiceGetMatchingServices returned %d",“Looks good to me” ← here’s the comment you requested O:)
Thanks :)
Quoted 34 lines · Philippe Mathieu-Daudé
Quoted 20 lines · Hanna Reitz
Quoted 7 lines · Philippe Mathieu-Daudé
When building on macOS 12 we get:
../block/file-posix.c:3335:18: warning: 'IOMasterPort' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations] kernResult =IOMasterPort( MACH_PORT_NULL, &masterPort );
^~~~~~~~~~~~
IOMainPortQuoted 7 lines
Use IOMainPort (define it to IOMasterPort on macOS < 12), and replace 'master' by 'main' in a variable name.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
block/file-posix.c| 13 +++++++++----1 file changed, 9 insertions(+), 4 deletions(-)I hope the [RFC] tag isn’t directed at me.
Still, I can give my comment, of course.
Quoted 12 lines
block/file-posix.c BlockDriver bdrv_file = { · line 3328
Quoted 10 lines
block/file-posix.c +2
-0@@ -3324,17 +3324,22 @@ BlockDriver bdrv_file = { #if defined(__APPLE__) && defined(__MACH__) static kern_return_t GetBSDPath(io_iterator_t mediaIterator, char *bsdPath, CFIndex maxPathSize, int flags); + +#if !defined(MAC_OS_VERSION_12_0 )So AFAIU from my quick rather fruit-less googling, this macro is defined (to some version-defining integer) on every macOS version starting from 12.0? (Just confirming because the name could also mean it’d be defined only on 12.0.)
Quoted 3 lines
Thanks, I posted up to v3 and macOS users helped me, I will post a v4 soon.
I see. The MAC_OS_X_VERSION_M{IN,AX}_REQUIRED thing was exactly what I didn’t really understand from said googling, but the important thing is that you do. (Something to do with what runtime is actually in use rather than what the system can provide? Well, I’ll just stop asking.) O:)
Hanna