//------------------------------------------------------------------------- // translate a logical module name to a physical representation (ie 'Key' format) //------------------------------------------------------------------------- // Fri May 25 12:23:23 EDT 2001 // Fri Feb 8 10:42:57 EST 2002 -- fixed type of 'key->scsi_port' //------------------------------------------------------------------------- // input: logical module name // output: status, and modified data referenced by pointer //------------------------------------------------------------------------- int xlate_logicalname( char *Name, CamKey *key ) { int i; int status = SUCCESS; // otpimistic struct Module_ Mod; extern struct MODULE *CTSdb; extern int CTSdbFileIsMapped; if( MSGLVL(FUNCTION_NAME) ) printf( "xlate_logicalname()\n" ); if( strchr(Name, ':') != NULL ) { // invalid logical name ... status = ERROR; // ... was passed a physical name goto Xlate_LogicalName_Exit; } // check to see if CTS db is memory mapped if( CTSdbFileIsMapped == FALSE ) { if( map_data_file( CTS_DB ) != SUCCESS ) { status = MAP_ERROR; // not mapped, we're done :< goto Xlate_LogicalName_Exit; } } // look up entry in db file if( (i = lookup_entry( CTS_DB, Name )) < 0 ) { status = NO_DEVICE; goto Xlate_LogicalName_Exit; } parse_cts_db( CTSdb+i, &Mod ); // get info ... // load up struct with vital info key->scsi_port = Mod.adapter +'A'; // SCSI host adapter [2002.02.08] key->scsi_address = Mod.id; // SCSI id key->crate = Mod.crate; // CAMAC crate number key->slot = Mod.slot; // CAMAC slot (ie station) Xlate_LogicalName_Exit: if( MSGLVL(DETAILS) ) { printf( "xlate(): name['%s'] ==>> HA[%c] id[%d] crate[%02d] slot[%d]\n", Name, key->scsi_port, key->scsi_address, key->crate, key->slot ); } return status; }
//------------------------------------------------------------------------- //------------------------------------------------------------------------- int ShowModule() { char db_tmp[64]; // enough space for a logical name and a cstring terminator [2002.02.20] int i, numOfEntries, status = SUCCESS; static DESCRIPTOR( physical, "PHYSICAL" ); static DESCRIPTOR( module_p, "MODULE" ); static DESCRIPTOR( format_p, "FORMAT" ); static DESCRIPTOR( blank, " " ); static DESCRIPTOR( heading1, " # Logical Name Physical Comment" ); // header static DESCRIPTOR( heading2, "==== ================================ ========== ========================================" ); static DYNAMIC_DESCRIPTOR( wild ); struct Module_ Mod, *pMod; struct descriptor pattern; int format = cli_present(&format_p) & 1; int physical_name = cli_present(&physical) & 1; // 2002.01.16 cli_get_value( &module_p, &wild ); StrUpcase( &wild, &wild ); // convert to upper case if( MSGLVL(DETAILS) ) printf("ShowModule(): in %s order\n", (physical_name) ? "physical" : "logical" ); // check to see if db file memory mapped if( CTSdbFileIsMapped == FALSE ) { // is not, so try if( map_data_file(CTS_DB) != SUCCESS ) { // we're dead in the water if( MSGLVL(IMPORTANT) ) fprintf( stderr, "error memory mapping database file\n" ); status = FAILURE; // MAP_ERROR; [2001.07.12] goto Showmodule_Exit; } } // db file now mapped, continue pMod = &Mod; // point to some actual storage if( (numOfEntries = get_file_count(CTS_DB)) > 0 ) { // something to show printf( "%s\n", heading1.pointer ); printf( "%s%d\n", heading2.pointer, numOfEntries ); for( i = 0; i < numOfEntries; i++ ) { parse_cts_db( CTSdb+i, pMod ); // extract info from db memset(db_tmp, ' ', 32); db_tmp[33] = '\0'; if( physical_name ) // duh, physical name sprintf( db_tmp, "GK%c%d%02d:N%d", pMod->adapter + 'A', pMod->id, pMod->crate, pMod->slot ); else sprintf( db_tmp, "%s", pMod->name ); pattern.pointer = db_tmp; pattern.length = strlen(db_tmp); if( StrMatchWild( &pattern, &wild ) & 1 ) { // printf( "%s%3d: %.84s<%s\n", CYAN, i+1, (char *)CTSdb+(i * MODULE_ENTRY), NORMAL ); // fancy, with color printf( "%3d: %.84s<\n", i+1, (char *)CTSdb+(i * MODULE_ENTRY) ); } } // end of for() loop printf( "%s\n", heading2.pointer ); } else { if( MSGLVL(IMPORTANT) ) fprintf( stderr, "db file is empty, no modules to show\n" ); status = SUCCESS; // Not necessarily an ERROR; [2002.02.19] goto Showmodule_Exit; } Showmodule_Exit: if( MSGLVL(DETAILS) ) { printf("ShowModule(): "); ShowStatus(status); } return status; }
//------------------------------------------------------------------------- // deassign a module //------------------------------------------------------------------------- int Deassign() { char db_tmp[64]; int i, index, modulesToDeassign, modulesDeassigned, numOfEntries, physical_name; int status = SUCCESS; struct Module_ Mod, *pMod; static DESCRIPTOR( physical, "PHYSICAL" ); static DESCRIPTOR( modname_p, "MODULE" ); static DYNAMIC_DESCRIPTOR( modname ); static DYNAMIC_DESCRIPTOR( wild ); struct descriptor pattern; // get user data cli_get_value( &modname_p, &wild ); StrUpcase( &wild, &wild ); physical_name = cli_present(&physical) & 1; if( MSGLVL(DETAILS) ) printf("Deassign(): %s module: <%s>\n", physical_name ? "physical" : "logical", wild.pointer); // check to see if db file memory mapped if( CTSdbFileIsMapped == FALSE ) { // is not, so try ... if( map_data_file(CTS_DB) != SUCCESS ) { // we're dead in the water status = MAP_ERROR; // [2002.02.21] goto Deassign_Exit; } } // get number of current entries if( (numOfEntries = get_file_count(CTS_DB)) == 0 ) { // no entries in cts db file if( MSGLVL(IMPORTANT) ) fprintf( stderr, "db file empty, no entries to remove\n" ); status = DEASSIGN_ERROR; // [2002.02.21] goto Deassign_Exit; } // if we get this far, then there are modules in the database modulesToDeassign = modulesDeassigned = 0; // initialize counts pMod = &Mod; // point to some actual storage // first, we need to count the number to deassign ... for( i = 0; i < numOfEntries; ++i ) { // scan entire list // look up module name(s). NB! more than one logical name may be // assigned to the same, unique physical name. parse_cts_db( CTSdb+i, pMod ); // extract info from db memset(db_tmp, ' ', 32); // clear out buffer db_tmp[33] = '\0'; // ensure buffer 'ends' if( physical_name ) // physical name sprintf( db_tmp, "GK%c%d%02d:N%d", pMod->adapter + 'A', pMod->id, pMod->crate, pMod->slot ); else // logical name sprintf( db_tmp, "%s", pMod->name ); // prepare for 'wild' match pattern.pointer = db_tmp; pattern.length = strlen(db_tmp); if( StrMatchWild( &pattern, &wild ) & 1 ) { ++modulesToDeassign; // } } // end of for() loop, all entries checked // now actually remove them while( modulesToDeassign ) { for( i = 0; i < get_file_count(CTS_DB); ++i ) { // look up module name(s). NB! more than one logical name may be // assigned to the same, unique physical name. parse_cts_db( CTSdb+i, pMod ); // extract info from db memset(db_tmp, ' ', 32); // clear out buffer db_tmp[33] = '\0'; // ensure buffer 'ends' if( physical_name ) // physical name sprintf( db_tmp, "GK%c%d%02d:N%d", pMod->adapter + 'A', pMod->id, pMod->crate, pMod->slot ); else // logical name sprintf( db_tmp, "%s", pMod->name ); // prepare for 'wild' match pattern.pointer = db_tmp; pattern.length = strlen(db_tmp); if( StrMatchWild( &pattern, &wild ) & 1 ) { if( remove_entry(CTS_DB, i) != SUCCESS ) { // removal failed status = DEASSIGN_ERROR; // [2002.02.21] goto Deassign_Exit; } else ++modulesDeassigned; // keep track of successes :) } } --modulesToDeassign; // one less to remove ... } Deassign_Exit: if( MSGLVL(DETAILS) ) { printf("Deassign(%d): ", modulesDeassigned); ShowStatus(status); } return status; }