1 USING: alien.syntax alien.c-types core-foundation
2 core-foundation.bundles system combinators kernel sequences
3 debugger io accessors ;
8 [ "/System/Library/Frameworks/IOKit.framework" load-framework ]
12 : kIOKitBuildVersionKey "IOKitBuildVersion" ; inline
13 : kIOKitDiagnosticsKey "IOKitDiagnostics" ; inline
15 : kIORegistryPlanesKey "IORegistryPlanes" ; inline
16 : kIOCatalogueKey "IOCatalogue" ; inline
18 : kIOServicePlane "IOService" ; inline
19 : kIOPowerPlane "IOPower" ; inline
20 : kIODeviceTreePlane "IODeviceTree" ; inline
21 : kIOAudioPlane "IOAudio" ; inline
22 : kIOFireWirePlane "IOFireWire" ; inline
23 : kIOUSBPlane "IOUSB" ; inline
25 : kIOServiceClass "IOService" ; inline
27 : kIOResourcesClass "IOResources" ; inline
29 : kIOClassKey "IOClass" ; inline
30 : kIOProbeScoreKey "IOProbeScore" ; inline
31 : kIOKitDebugKey "IOKitDebug" ; inline
33 : kIOProviderClassKey "IOProviderClass" ; inline
34 : kIONameMatchKey "IONameMatch" ; inline
35 : kIOPropertyMatchKey "IOPropertyMatch" ; inline
36 : kIOPathMatchKey "IOPathMatch" ; inline
37 : kIOLocationMatchKey "IOLocationMatch" ; inline
38 : kIOParentMatchKey "IOParentMatch" ; inline
39 : kIOResourceMatchKey "IOResourceMatch" ; inline
40 : kIOMatchedServiceCountKey "IOMatchedServiceCountMatch" ; inline
42 : kIONameMatchedKey "IONameMatched" ; inline
44 : kIOMatchCategoryKey "IOMatchCategory" ; inline
45 : kIODefaultMatchCategoryKey "IODefaultMatchCategory" ; inline
47 : kIOUserClientClassKey "IOUserClientClass" ; inline
49 : kIOUserClientCrossEndianKey "IOUserClientCrossEndian" ; inline
50 : kIOUserClientCrossEndianCompatibleKey "IOUserClientCrossEndianCompatible" ; inline
51 : kIOUserClientSharedInstanceKey "IOUserClientSharedInstance" ; inline
53 : kIOPublishNotification "IOServicePublish" ; inline
54 : kIOFirstPublishNotification "IOServiceFirstPublish" ; inline
55 : kIOMatchedNotification "IOServiceMatched" ; inline
56 : kIOFirstMatchNotification "IOServiceFirstMatch" ; inline
57 : kIOTerminatedNotification "IOServiceTerminate" ; inline
59 : kIOGeneralInterest "IOGeneralInterest" ; inline
60 : kIOBusyInterest "IOBusyInterest" ; inline
61 : kIOAppPowerStateInterest "IOAppPowerStateInterest" ; inline
62 : kIOPriorityPowerStateInterest "IOPriorityPowerStateInterest" ; inline
64 : kIOPlatformDeviceMessageKey "IOPlatformDeviceMessage" ; inline
66 : kIOCFPlugInTypesKey "IOCFPlugInTypes" ; inline
68 : kIOCommandPoolSizeKey "IOCommandPoolSize" ; inline
70 : kIOMaximumBlockCountReadKey "IOMaximumBlockCountRead" ; inline
71 : kIOMaximumBlockCountWriteKey "IOMaximumBlockCountWrite" ; inline
72 : kIOMaximumByteCountReadKey "IOMaximumByteCountRead" ; inline
73 : kIOMaximumByteCountWriteKey "IOMaximumByteCountWrite" ; inline
74 : kIOMaximumSegmentCountReadKey "IOMaximumSegmentCountRead" ; inline
75 : kIOMaximumSegmentCountWriteKey "IOMaximumSegmentCountWrite" ; inline
76 : kIOMaximumSegmentByteCountReadKey "IOMaximumSegmentByteCountRead" ; inline
77 : kIOMaximumSegmentByteCountWriteKey "IOMaximumSegmentByteCountWrite" ; inline
78 : kIOMinimumSegmentAlignmentByteCountKey "IOMinimumSegmentAlignmentByteCount" ; inline
79 : kIOMaximumSegmentAddressableBitCountKey "IOMaximumSegmentAddressableBitCount" ; inline
81 : kIOIconKey "IOIcon" ; inline
82 : kIOBundleResourceFileKey "IOBundleResourceFile" ; inline
84 : kIOBusBadgeKey "IOBusBadge" ; inline
85 : kIODeviceIconKey "IODeviceIcon" ; inline
87 : kIOPlatformSerialNumberKey "IOPlatformSerialNumber" ; inline
89 : kIOPlatformUUIDKey "IOPlatformUUID" ; inline
91 : kIONVRAMDeletePropertyKey "IONVRAM-DELETE-PROPERTY" ; inline
92 : kIODTNVRAMPanicInfoKey "aapl,panic-info" ; inline
94 : kIOBootDeviceKey "IOBootDevice" ; inline
95 : kIOBootDevicePathKey "IOBootDevicePath" ; inline
96 : kIOBootDeviceSizeKey "IOBootDeviceSize" ; inline
98 : kOSBuildVersionKey "OS Build Version" ; inline
100 : kNilOptions 0 ; inline
102 TYPEDEF: uint mach_port_t
103 TYPEDEF: int kern_return_t
104 TYPEDEF: int boolean_t
105 TYPEDEF: mach_port_t io_object_t
106 TYPEDEF: io_object_t io_iterator_t
107 TYPEDEF: io_object_t io_registry_entry_t
108 TYPEDEF: io_object_t io_service_t
109 TYPEDEF: char[128] io_name_t
110 TYPEDEF: char[512] io_string_t
111 TYPEDEF: kern_return_t IOReturn
113 TYPEDEF: uint IOOptionBits
115 : MACH_PORT_NULL 0 ; inline
116 : KERN_SUCCESS 0 ; inline
118 FUNCTION: IOReturn IOMasterPort ( mach_port_t bootstrap, mach_port_t* master ) ;
120 FUNCTION: CFDictionaryRef IOServiceMatching ( char* name ) ;
121 FUNCTION: CFDictionaryRef IOServiceNameMatching ( char* name ) ;
122 FUNCTION: CFDictionaryRef IOBSDNameMatching ( char* name ) ;
124 FUNCTION: IOReturn IOObjectRetain ( io_object_t o ) ;
125 FUNCTION: IOReturn IOObjectRelease ( io_object_t o ) ;
127 FUNCTION: IOReturn IOServiceGetMatchingServices ( mach_port_t master, CFDictionaryRef matchingDict, io_iterator_t* iterator ) ;
129 FUNCTION: io_object_t IOIteratorNext ( io_iterator_t i ) ;
130 FUNCTION: void IOIteratorReset ( io_iterator_t i ) ;
131 FUNCTION: boolean_t IOIteratorIsValid ( io_iterator_t i ) ;
133 FUNCTION: IOReturn IORegistryEntryGetPath ( io_registry_entry_t entry, io_name_t plane, io_string_t path ) ;
135 FUNCTION: IOReturn IORegistryEntryCreateCFProperties ( io_registry_entry_t entry, CFMutableDictionaryRef properties, CFAllocatorRef allocator, IOOptionBits options ) ;
137 FUNCTION: char* mach_error_string ( IOReturn error ) ;
139 TUPLE: mach-error error-code ;
140 C: <mach-error> mach-error
143 "IOKit call failed: " print error-code>> mach_error_string print ;
145 : mach-error ( return -- )
146 dup KERN_SUCCESS = [ drop ] [ <mach-error> throw ] if ;
148 : master-port ( -- port )
149 MACH_PORT_NULL 0 <uint> [ IOMasterPort mach-error ] keep *uint ;
151 : io-services-matching-dictionary ( nsdictionary -- iterator )
152 master-port swap 0 <uint>
153 [ IOServiceGetMatchingServices mach-error ] keep
156 : io-services-matching-service ( service -- iterator )
157 IOServiceMatching io-services-matching-dictionary ;
158 : io-services-matching-service-name ( service-name -- iterator )
159 IOServiceNameMatching io-services-matching-dictionary ;
160 : io-services-matching-bsd-name ( bsd-name -- iterator )
161 IOBSDNameMatching io-services-matching-dictionary ;
163 : retain-io-object ( o -- o )
164 [ IOObjectRetain mach-error ] keep ;
165 : release-io-object ( o -- )
166 IOObjectRelease mach-error ;
168 : io-objects-from-iterator* ( i -- i array )
169 [ dup IOIteratorNext dup MACH_PORT_NULL = not ]
173 : io-objects-from-iterator ( i -- array )
174 io-objects-from-iterator* [ release-io-object ] dip ;
176 : properties-from-io-object ( o -- o nsdictionary )
178 kCFAllocatorDefault kNilOptions
179 IORegistryEntryCreateCFProperties mach-error