- OSString * string;
- OSCollection * collection;
- OSIterator * iter = 0;
- bool result = false;
-
- if( (collection = OSDynamicCast( OSCollection, names))) {
- iter = OSCollectionIterator::withCollection( collection );
- string = 0;
- } else
- string = OSDynamicCast( OSString, names);
-
- do {
- if( string)
- result = compareName( string, matched );
-
- } while( (false == result)
- && iter && (string = OSDynamicCast( OSString, iter->getNextObject())));
-
- if( iter)
- iter->release();
-
- return( result);
-}
-
-
-bool IORegistryEntry::getPath( char * path, int * length,
- const IORegistryPlane * plane ) const
+ OSString * string;
+ OSCollection * collection;
+ OSIterator * iter = NULL;
+ bool result = false;
+
+ if ((collection = OSDynamicCast( OSCollection, names))) {
+ iter = OSCollectionIterator::withCollection( collection );
+ string = NULL;
+ } else {
+ string = OSDynamicCast( OSString, names);
+ }
+
+ do {
+ if (string) {
+ result = compareName( string, matched );
+ }
+ } while ((false == result)
+ && iter && (string = OSDynamicCast( OSString, iter->getNextObject())));
+
+ if (iter) {
+ iter->release();
+ }
+
+ return result;
+}
+
+
+bool
+IORegistryEntry::getPath( char * path, int * length,
+ const IORegistryPlane * plane ) const
+{
+ OSArray * stack;
+ IORegistryEntry * root;
+ const IORegistryEntry * entry;
+ const IORegistryEntry * parent;
+ const OSSymbol * alias;
+ int index;
+ int len, maxLength, compLen, aliasLen;
+ char * nextComp;
+ bool ok;
+
+ if (!path || !length || !plane) {
+ return false;
+ }
+
+ len = 0;
+ maxLength = *length - 2;
+ nextComp = path;
+
+ len = plane->nameKey->getLength();
+ if (len >= maxLength) {
+ return false;
+ }
+ strlcpy( nextComp, plane->nameKey->getCStringNoCopy(), len + 1);
+ nextComp[len++] = ':';
+ nextComp += len;
+
+ if ((alias = hasAlias( plane ))) {
+ aliasLen = alias->getLength();
+ len += aliasLen;
+ ok = (maxLength > len);
+ *length = len;
+ if (ok) {
+ strlcpy( nextComp, alias->getCStringNoCopy(), aliasLen + 1);
+ }
+ return ok;
+ }
+
+ stack = OSArray::withCapacity( getDepth( plane ));
+ if (!stack) {
+ return false;
+ }
+
+ RLOCK;
+
+ parent = entry = this;
+ root = gRegistryRoot->getChildEntry( plane );
+ while (parent && (parent != root)) {
+ // stop below root
+ entry = parent;
+ parent = entry->getParentEntry( plane );
+ stack->setObject((OSObject *) entry );
+ }
+
+ ok = (NULL != parent);
+ if (ok) {
+ index = stack->getCount();
+ if (0 == index) {
+ *nextComp++ = '/';
+ *nextComp = 0;
+ len++;
+ } else {
+ while (ok && ((--index) >= 0)) {
+ entry = (IORegistryEntry *) stack->getObject((unsigned int) index );
+ assert( entry );
+
+ if ((alias = entry->hasAlias( plane ))) {
+ len = plane->nameKey->getLength() + 1;
+ nextComp = path + len;
+
+ compLen = alias->getLength();
+ ok = (maxLength > (len + compLen));
+ if (ok) {
+ strlcpy( nextComp, alias->getCStringNoCopy(), compLen + 1);
+ }
+ } else {
+ compLen = maxLength - len;
+ ok = entry->getPathComponent( nextComp + 1, &compLen, plane );
+
+ if (ok && compLen) {
+ compLen++;
+ *nextComp = '/';
+ }
+ }
+
+ if (ok) {
+ len += compLen;
+ nextComp += compLen;
+ }
+ }
+ }
+ *length = len;
+ }
+ UNLOCK;
+ stack->release();
+
+ return ok;
+}
+
+bool
+IORegistryEntry::getPathComponent( char * path, int * length,
+ const IORegistryPlane * plane ) const