- }
- return( bestKey );
-}
-
-const char * IORegistryEntry::dealiasPath(
- const char ** opath,
- const IORegistryPlane * plane )
-{
- IORegistryEntry * entry;
- OSData * data;
- const char * path = *opath;
- const char * rpath = 0;
- const char * end;
- char c;
- char temp[ kIOMaxPlaneName + 1 ];
-
- if( path[0] == '/')
- return( rpath );
-
- // check for alias
- end = path;
- while( (c = *end++) && (c != '/') && (c != ':'))
- {}
- end--;
- if( (end - path) < kIOMaxPlaneName) {
- strncpy( temp, path, end - path );
- temp[ end - path ] = 0;
-
- RLOCK;
- entry = IORegistryEntry::fromPath( "/aliases", plane );
- if( entry) {
- data = (OSData *) entry->getProperty( temp );
- if( data ) {
- rpath = (const char *) data->getBytesNoCopy();
- if( rpath)
- *opath = end;
- }
- entry->release();
- }
- UNLOCK;
- }
-
- return( rpath );
-}
-
-IORegistryEntry * IORegistryEntry::fromPath(
- const char * path,
- const IORegistryPlane * plane = 0,
- char * opath = 0,
- int * length = 0,
- IORegistryEntry * fromEntry = 0 )
-{
- IORegistryEntry * where = 0;
- IORegistryEntry * aliasEntry = 0;
- IORegistryEntry * next;
- const char * alias;
- const char * end;
- int len = 0;
- int len2;
- char c;
- char temp[ kIOMaxPlaneName + 1 ];
-
- if( 0 == path)
- return( 0 );
-
- if( 0 == plane) {
- // get plane name
- end = strchr( path, ':' );
- if( end && ((end - path) < kIOMaxPlaneName)) {
- strncpy( temp, path, end - path );
- temp[ end - path ] = 0;
- plane = getPlane( temp );
- path = end + 1;
- }
- }
- if( 0 == plane)
- return( 0 );
-
- // check for alias
- end = path;
- if( (alias = dealiasPath( &end, plane))) {
- if( length)
- len = *length;
- aliasEntry = IORegistryEntry::fromPath( alias, plane,
- opath, &len, fromEntry );
- where = aliasEntry;
- if( where)
- path = end;
- else
- len = 0;
- }
-
- RLOCK;
-
- do {
- if( 0 == where) {
- if( (0 == fromEntry) && (*path++ == '/'))
- fromEntry = gRegistryRoot->getChildEntry( plane );
- where = fromEntry;
- if( 0 == where)
- break;
- } else {
- c = *path++;
- if( c != '/') {
- if( c && (c != ':')) // check valid terminator
- where = 0;
- break;
- }
- }
- next = where->getChildFromComponent( &path, plane );
- if( next)
- where = next;
- } while( next );
-
- if( where) {
- // check residual path
- if( where != fromEntry)
- path--;
-
- if( opath && length) {
- // copy out residual path
- len2 = len + strlen( path );
- if( len2 < *length)
- strcpy( opath + len, path );
- *length = len2;
-
- } else if( path[0])
- // no residual path => must be no tail for success
- where = 0;
- }
-
- if( where)
- where->retain();
- if( aliasEntry)
- aliasEntry->release();
-
- UNLOCK;
-
- return( where );
-}
-
-IORegistryEntry * IORegistryEntry::childFromPath(
- const char * path,
- const IORegistryPlane * plane = 0,
- char * opath = 0,
- int * len = 0 )
-{
- return( IORegistryEntry::fromPath( path, plane, opath, len, this ));