Mac OS matches drivers to devices by using the following algorithm:
Each device node should have just one compatible property, containing one or more C-formatted name strings as its value. The strings must be packed in sequence with no unused bytes between them and should be arranged with the more compatible names first.
The DLL routines GetDriverForDevice, InstallDriverForDevice, and FindDriversForDevice use the following algorithm to match or install the "best" driver for a device:
If you still have candidates with which to attempt an installation, do the following:
The routines that use this algorithm are described in detail in the sections that start with Loading and Unloading.
Listing 7-1 File-based driver sorting
SInt16 CandidateCompareRoutine
(FileBasedDriverInfoPtr Driver1,
FileBasedDriverInfoPtr Driver2,
StringPtr CompatibleNames,
ItemCount nCompatibleNames)
{
SInt16 matchResults = 0;
if ( Driver1 and Driver2 matched using same property (name or compatible))
{
if ( both drivers matched using compatible property )
{
if ( drivers not matched with identical compatible name )
{
/* Which compatible name (by number) did driver1/driver2 match? */
Driver1CompatibleName = WhichCompatibleName(Driver1,...);
Driver2CompatibleName = WhichCompatibleName(Driver2,...);
if ( Driver1CompatibleName != Driver2CompatibleName )
{
if ( Driver1CompatibleName < Driver2CompatibleName )
return 1; /* driver1 is "more compatible" */
else
return -1; /* driver2 is "more compatible" */
}
}
}
/* Break tie with version numbers, if possible. */
matchResults = HigherDriverVersion (&Driver1 ->
info.theType.version, &Driver2 -> info.theType.version);
/* Same version number too? */
if ( matchResults == 0 )
{
/* Final tie breaker is their filenames */
/* Reverse the compare with RelString */
matchResults = RelString (Driver2 -> info.theSpec.name,
Driver1 -> info.theSpec.name, true, true );
}
return matchResults;
}
/* Matched using different property */
if ( Driver1 matched using compatible property )
return -1; /* driver 2 is higher */
return 1; /* else driver 1 is higher */
}