-OSDictionary * IODiskMatching( const char * path, char * buf, int maxLen )
-{
- const char * look;
- const char * alias;
- char * comp;
- long unit = -1;
- long partition = -1;
- long lun = -1;
- char c;
- int len;
-
- // scan the tail of the path for "@unit:partition"
- do {
- // Have to get the full path to the controller - an alias may
- // tell us next to nothing, like "hd:8"
- alias = IORegistryEntry::dealiasPath( &path, gIODTPlane );
-
- look = path + strlen( path);
- c = ':';
- while( look != path) {
- if( *(--look) == c) {
- if( c == ':') {
- partition = strtol( look + 1, 0, 0 );
- c = '@';
- } else if( c == '@') {
- unit = strtol( look + 1, &comp, 16 );
-
- if( *comp == ',') {
- lun = strtol( comp + 1, 0, 16 );
- }
-
- c = '/';
- } else if( c == '/') {
- c = 0;
- break;
- }
- }
-
- if( alias && (look == path)) {
- path = alias;
- look = path + strlen( path);
- alias = 0;
- }
- }
- if( c || unit == -1 || partition == -1)
- continue;
-
- len = strlen( "{" kIOPathMatchKey "='" kIODeviceTreePlane ":" );
- maxLen -= len;
- if( maxLen <= 0)
- continue;
-
- snprintf( buf, len + 1, "{" kIOPathMatchKey "='" kIODeviceTreePlane ":" );
- comp = buf + len;
-
- if( alias) {
- len = strlen( alias );
- maxLen -= len;
- if( maxLen <= 0)
- continue;
-
- strlcpy( comp, alias, len + 1 );
- comp += len;
- }
-
- if ( (look - path)) {
- len = (look - path);
- maxLen -= len;
- if( maxLen <= 0)
- continue;
-
- strlcpy( comp, path, len + 1 );
- comp += len;
- }
-
- if ( lun != -1 )
- {
- len = strlen( "/@hhhhhhhh,hhhhhhhh:dddddddddd';}" );
- maxLen -= len;
- if( maxLen <= 0)
- continue;
-
- snprintf( comp, len + 1, "/@%lx,%lx:%ld';}", unit, lun, partition );
- }
- else
- {
- len = strlen( "/@hhhhhhhh:dddddddddd';}" );
- maxLen -= len;
- if( maxLen <= 0)
- continue;
-
- snprintf( comp, len + 1, "/@%lx:%ld';}", unit, partition );
- }
-
- return( OSDynamicCast(OSDictionary, OSUnserialize( buf, 0 )) );
-
- } while( false );
-
- return( 0 );
-}
-