/** The BUS_next function does a general search. This function continues from the previous search state (held in struct device_search). The search state can be reset by using the BUS_first function. Returns: 0=No problems, 1=Problems Sets LastDevice=1 if no more */ enum search_status BUS_next(struct device_search *ds, const struct parsedname *pn) { switch ( BUS_next_3try(ds, pn) ) { case search_good: // found a device in a directory search, add to "presence" cache LEVEL_DEBUG("Device found: " SNformat, SNvar(ds->sn)); Cache_Add_Device(pn->selected_connection->index,ds->sn) ; return search_good ; case search_done: BUS_next_cleanup(ds); return search_done; case search_error: default: BUS_next_cleanup(ds); return search_error; } }
static GOOD_OR_BAD PresenceFromDirblob( struct parsedname * pn ) { struct dirblob db; // cached dirblob if ( GOOD( Cache_Get_Dir( &db , pn ) ) ) { // Use the dirblob from the cache GOOD_OR_BAD ret = ( DirblobSearch(pn->sn, &db ) >= 0 ) ? gbGOOD : gbBAD ; DirblobClear( &db ) ; return ret ; } else { // look through actual directory struct device_search ds ; enum search_status nextboth = BUS_first( &ds, pn ) ; while ( nextboth == search_good ) { if ( memcmp( ds.sn, pn->sn, SERIAL_NUMBER_SIZE ) == 0 ) { // found it. Early exit. BUS_next_cleanup( &ds ); return gbGOOD ; } // Not found. Clean up done by BUS_next in this case nextboth = BUS_next( &ds, pn ) ; } return gbBAD ; } }