PATH 
ADC Home > Documentation > Hardware > Device Managers and Drivers > PCI Card Services > Designing PCI Cards and Drivers for Power Macintosh Computers


  

LookupDrivers

LookupDrivers is used to iterate through the contents of the unit table.

OSErr LookupDrivers(
                     UnitNumber beginningUnit,
                     UnitNumber endingUnit,
                     Boolean emptyUnits,
                     ItemCount *returnedRefNums,
                     DriverRefNum *refNums);
beginningUnit
First unit in range of units to scan.
endingUnit
Last unit in range of units to scan.
emptyUnits
A value of true means return available units; a value of false means return allocated units.
returnedRefNums
Maximum number of reference numbers to return; on completion, contains actual number of reference numbers returned.
refNums
Resulting array of returned reference numbers.
DESCRIPTION

Given the first and last unit numbers to scan, LookupDrivers returns the reference numbers of both native and 68K drivers. The emptyUnits parameter tells it to return either available or allocated units, and returnedRefNums tells it the maximum number of reference numbers to return. When LookupDrivers finishes, returnedRefNums contains the actual number of reference numbers returned.

The sample code shown in Listing 9-3 uses HighestUnitNumber and LookupDrivers to print out the reference numbers of all installed drivers and obtain driver information.

RESULT CODES
noErr 0 No error
badUnitErr -21 Bad unit number
paramErr -50 Bad parameter

Listing 9-3 Using the LookupDrivers function

OSStatus FindAllDrivers (void)
{
    ItemCount       theCount        = 1;
    UnitNumber      theUnit         = 0;
    DriverRefNum    theRefNum,      *fullSizedRefNumBuffer;

    /* method #1: iterate with a small output buffer */

    while ( (theUnit <= HighestUnitNumber()) &&
     (LookupDrivers (theUnit, theUnit, false, &theCount, &theRefNum) ==noErr))
    {
        if (theCount == 1) printf ("Refnum #%d is allocated.\n",theRefNum);
        theCount = 1;
        theUnit++;
    }

    /* method #2: get all refnums with one call */

    fullSizedRefNumBuffer = NewPtr ((HighestUnitNumber() + 1) *
     sizeof(DriverRefNum));
    theCount = (HighestUnitNumber() + 1);
    LookupDrivers (0, HighestUnitNumber(), false, &theCount,
     fullSizedRefNumBuffer);

    for(theUnit=0,theUnit <theCount;theUnit++)
    {
        printf("Refnum #%d is allocated.\n", fullSizedRefNumBuffer [theUnit]);
        ShowDriverInfo (fullSizedRefNumBuffer [theUnit]);
    }
    DisposePtr(fullSizedRefNumBuffer);
    return noErr;
}

ShowDriverInfo (DriverRefNum *refNum)
{
    UnitNumber              theUnit;
    DriverRefNum            aRefNum;
    DriverFlags             theFlags;
    FSSpec                  driverFileSpec;
    RegEntryID              theDevice;
    CFragHFSLocator         theLoc;
    Str255                  theName;
    CFragConnectionID       fragmentConnID;
    DriverOpenCount         theOpenCount;
    DriverEntryPointPtr     fragmentMain;
    DriverDescription       theDriverDescription;

    theLoc.u.onDisk.fileSpec = &driverFileSpec; /* See note below */

    GetDriverInformation (  aRefNum,
                            &theUnit,
                            &theFlags,
                            &theOpenCount,
                            theName,
                            &theDevice,
                            &theLoc,
                            &fragmentConnID,
                            &fragmentMain,
                            &theDriverDescription);
    printf ("Driver's flags are: %x\n", theFlags);
}


IMPORTANT

When calling GetDriverInformation, always supply an FSSpec file specification as shown in the preceding sample. Failure to do so may cause the DLL or the CFM to crash the system or overwrite the system heap.

Note

You can also use the DLL to load a native driver without any associated hardware device. Just pass nil in RegEntryIDPtr to the DLL installation service.


© 1999 Apple Computer, Inc. – (Last Updated 26 March 99)