//------------------------------------------------------------------------- // Delete a crate from the crate db //------------------------------------------------------------------------- int DelCrate() { char crateName[CRATE_NAME_SIZE + 1]; int index, numOfEntries; int status = SUCCESS; static DESCRIPTOR( phy_name_p, "PHY_NAME" ); static DYNAMIC_DESCRIPTOR( phy_name ); // get user input str_free1_dx(&phy_name); // per twf -- clear out field cli_get_value( &phy_name_p, &phy_name ); str_upcase( &phy_name, &phy_name ); // trim it... sprintf(crateName, "%.6s", phy_name.pointer); // check to see if db file memory mapped if( CRATEdbFileIsMapped == FALSE ) { // is not, so try if( map_data_file(CRATE_DB) != SUCCESS ) { // we're dead in the water status = FAILURE; // MAP_ERROR; [2001.07.12] goto DelCrate_Exit; } } // get number of current entries if( (numOfEntries = get_file_count(CRATE_DB)) == 0 ) { // no entries in crate db file if( MSGLVL(IMPORTANT) ) fprintf( stderr, "db file empty, no entries to remove\n" ); status = FAILURE; // DELCRATE_ERROR; [2001.07.12] goto DelCrate_Exit; } // try to remove from crate.db if( (index = lookup_entry(CRATE_DB, crateName)) >= 0 ) { // module does exist if( remove_entry(CRATE_DB, index) != SUCCESS ) { // removal failed status = FAILURE; // DELCRATE_ERROR; [2001.07.12] goto DelCrate_Exit; } } else { // no such module if( MSGLVL(IMPORTANT) ) fprintf( stderr, "delcrate(): entry '%s' not found\n", crateName); status = FAILURE; // DELCRATE_ERROR; [2001.07.12] goto DelCrate_Exit; } DelCrate_Exit: if( MSGLVL(DETAILS) ) { printf("DelCrate() status = %d\n", status); } return SUCCESS; }
//------------------------------------------------------------------------- // set a crate on-line or off-line //------------------------------------------------------------------------- int SetCrate() { int status; char *cratename; void *ctx=0; static DESCRIPTOR( crate_p, "CRATE" ); static DESCRIPTOR( quietq, "QUIET" ); static DYNAMIC_DESCRIPTOR( wild ); static DYNAMIC_DESCRIPTOR( crate ); static DESCRIPTOR( offq, "OFFLINE" ); static DESCRIPTOR( onq, "ONLINE" ); int off = cli_present(&offq) & 1; int on = cli_present(&onq ) & 1; int quiet = cli_present(&quietq) & 1; cli_get_value( &crate_p, &wild ); str_upcase( &wild, &wild ); // check to see if db file memory mapped if( CRATEdbFileIsMapped == FALSE ) { // is not, so try if( map_data_file(CRATE_DB) != SUCCESS ) { // we're dead in the water if( MSGLVL(IMPORTANT) ) fprintf( stderr, "error memory mapping crate db file\n" ); status = FAILURE; // MAP_ERROR; [2001.07.12] goto SetCrate_Exit; } } while (find_crate(wild.pointer,&cratename,&ctx)) { status = turn_crate_on_off_line( cratename , (on) ? ON : OFF ); if (!(status & 1) && !quiet) printf("Error turning crate %s %s\n",cratename,on ? "online" : "offline"); free(cratename); } find_crate_end(&ctx); SetCrate_Exit: return SUCCESS; }
static int upcase_interpret(string_list_ty *result, const string_list_ty *args, const expr_position_ty *pp, const struct opcode_context_ty *ocp) { size_t j; trace(("upcase\n")); (void)pp; (void)ocp; assert(result); assert(args); assert(args->nstrings); for (j = 1; j < args->nstrings; j++) { string_ty *s; s = str_upcase(args->string[j]); string_list_append(result, s); str_free(s); } return 0; }
//------------------------------------------------------------------------- // assign a new module to CTS database //------------------------------------------------------------------------- int Assign() { char line[MODULE_ENTRY+1]; int dbFileSize, fd, i, nullMask, numOfEntries, rc; int status = SUCCESS; // assume the best static DESCRIPTOR( phy_name_p, "PHY_NAME" ); static DYNAMIC_DESCRIPTOR( phy_name ); static DESCRIPTOR( log_name_p, "LOG_NAME" ); static DYNAMIC_DESCRIPTOR( log_name ); static DESCRIPTOR( comment_p, "COMMENT" ); static DYNAMIC_DESCRIPTOR( comment ); // get user input cli_get_value( &phy_name_p, &phy_name ); str_upcase( &phy_name, &phy_name ); cli_get_value( &log_name_p, &log_name ); str_upcase( &log_name, &log_name ); str_free1_dx(&comment); // per twf -- clear out comment field cli_get_value( &comment_p, &comment ); // check to see if db file exists if( check_for_file(CTS_DB_FILE) != SUCCESS ) { // does not exist, yet // try to creat (sic) it if( (fd = Creat(CTS_DB_FILE, 0666)) == ERROR ) { status = FAILURE; // FILE_ERROR; [2001.07.12] goto Assign_Exit; // we're done :< } else close(fd); } // check to see if db file is memory mapped if( CTSdbFileIsMapped == FALSE ) { // is not, so try if( map_data_file(CTS_DB) != SUCCESS ) { // we're dead in the water status = FAILURE; // MAP_ERROR; [2001.07.12] goto Assign_Exit; } } // get current db file count if( (numOfEntries = get_file_count(CTS_DB)) < 0 ) { status = FAILURE; // FILE_ERROR; [2001.07.12] goto Assign_Exit; } if( numOfEntries ) { // 1 or more if( lookup_entry(CTS_DB, log_name.pointer) >= 0 ) { // duplicate ! if( MSGLVL(IMPORTANT) ) fprintf( stderr, "duplicate module name '%s' -- not allowed\n", log_name.pointer ); status = FAILURE; // DUPLICATE; [2001.07.12] goto Assign_Exit; } } // get db file size if( (dbFileSize = get_db_file_size(CTS_DB_FILE)) == ERROR ) { status = FAILURE; // FILE_ERROR; [2001.07.12] goto Assign_Exit; } dbFileSize /= MODULE_ENTRY; // .. current maximum number of possible module entries // do we need to expand db file? if( (dbFileSize == 0) || (numOfEntries == dbFileSize) ) { // ... yes if( expand_db(CTS_DB, numOfEntries) != SUCCESS ) { // expand ... status = FAILURE; // EXPAND_ERROR; [2001.07.12] // ... failure goto Assign_Exit; } } // else OK // create a temporary string sprintf( line, "%-32s %-10s %-40s\n", log_name.pointer, // these were entered by the user phy_name.pointer, comment.pointer ? comment.pointer : "" ); // check comment field for null string, ie "(null)" nullMask = (1 << strlen(nullStr)) - 1; // set all mask bits for( i = COMMENT_INDEX; i < COMMENT_INDEX + strlen(nullStr); ++i ) if( line[i] == nullStr[i - COMMENT_INDEX] ) nullMask &= ~(1 << (i - COMMENT_INDEX)); // clear a bit in mask if( nullMask == 0 ) // all mask bit have been reset, ie matched for( i = COMMENT_INDEX; i < COMMENT_INDEX + strlen(nullStr); ++i ) line[i] = ' '; // make it spaces // add it ... if( add_entry(CTS_DB, line) != SUCCESS ) { status = FAILURE; // ASSIGN_ERROR; [2001.07.12] goto Assign_Exit; } #if NEED_WARM_N_FUZZY // write to a buffer file for a warm fuzzy ... if( (fd = Creat("buffer.db", 0666)) == ERROR ) { if( MSGLVL(ALWAYS) ) perror("creat()"); status = FAILURE; // FILE_ERROR; [2001.07.12] goto Assign_Exit; } rc = write(fd, line, sizeof(line)); close(fd); if( rc != sizeof(line) ) { if( MSGLVL(ALWAYS) ) perror("write()"); status = FAILURE; // FILE_ERROR; [2001.07.12] } #endif Assign_Exit: // we're done, so out'a here! if( MSGLVL(DETAILS) ) { printf("Assign(): "); ShowStatus(status); } return status; }
//------------------------------------------------------------------------- // Add a crate to the crate db //------------------------------------------------------------------------- int AddCrate() { char line[CRATE_ENTRY + 1]; int dbFileSize, fd, numOfEntries; int status = SUCCESS; // assume the best static DESCRIPTOR( phy_name_p, "PHY_NAME" ); static DYNAMIC_DESCRIPTOR( phy_name ); // get user input str_free1_dx(&phy_name); // per twf -- clear out field cli_get_value( &phy_name_p, &phy_name ); str_upcase( &phy_name, &phy_name ); // [2002.01.08] if( CRATEdbFileIsMapped == FALSE ) { // ... no if( check_for_file(CRATE_DB_FILE) != SUCCESS ) { // ... no if( (fd = Creat(CRATE_DB_FILE, 0666)) == ERROR ) { // no status = FAILURE; goto AddCrate_Exit; } else close(fd); // yes } if( map_data_file(CRATE_DB) != SUCCESS ) { // failure :( status = MAP_ERROR; goto AddCrate_Exit; } // else OK :) } // get current db file count if( (numOfEntries = get_file_count(CRATE_DB)) == FILE_ERROR ) { status = FAILURE; // FILE_ERROR; [2001.07.12] goto AddCrate_Exit; } if( numOfEntries ) { // 1 or more char pname[7]; sprintf(pname,"%.6s",phy_name.pointer); if( lookup_entry(CRATE_DB, pname) >= 0 ) { // duplicate ! if( MSGLVL(IMPORTANT) ) fprintf( stderr, "duplicate crate name '%.6s' -- not allowed\n", phy_name.pointer ); status = FAILURE; // DUPLICATE; [2001.07.12] goto AddCrate_Exit; } } // get db file size if( (dbFileSize = get_db_file_size(CRATE_DB_FILE)) == ERROR ) { status = FAILURE; // FILE_ERROR; [2001.07.12] goto AddCrate_Exit; } dbFileSize /= CRATE_ENTRY; // .. current maximum number of possible crate entries // do we need to expand db file? if( (dbFileSize == 0) || (numOfEntries == dbFileSize) ) { // ... yes if( (status = expand_db(CRATE_DB, numOfEntries)) != SUCCESS ) { // expand status = FAILURE; // EXPAND_ERROR; [2001.07.12] // failure goto AddCrate_Exit; } } // else OK // make an entry line, with online and enhanced set as undefined sprintf( line, "%-.6s:...:.:.:.\n", phy_name.pointer ); // add it ... if( (status = add_entry(CRATE_DB, line)) != SUCCESS ) { status = FAILURE; // ASSIGN_ERROR; [2001.07.12] goto AddCrate_Exit; } AddCrate_Exit: if( MSGLVL(DETAILS) ) { printf("AddCrate(): "); ShowStatus(status); } if( status == SUCCESS ) // if everything is OK ... Autoconfig(); // ... map crate to /dev/sg# //ShowCrate(); return status; }
//------------------------------------------------------------------------- //------------------------------------------------------------------------- // show crate status, using crates in 'crate.db' file //------------------------------------------------------------------------- int ShowCrate() { char colorENH[9], colorON[9]; char tmp[7]; char tmp2[11]; int enhanced, i, j, online, moduleFound, numOfCrates, numOfModules; int crateStatus; int status; struct Crate_ Cr8, *pCr8; struct Module_ Mod, *pMod; static DESCRIPTOR( crate_p, "MODULE" ); static DESCRIPTOR( heading1, " CRATE ONL LAM PRV ENH" ); static DESCRIPTOR( heading2, "======= === === === ===" ); static DYNAMIC_DESCRIPTOR( wild ); static DYNAMIC_DESCRIPTOR( crate ); if( ScsiSystemStatus() == 0 ) { status = SUCCESS; // this is the function's status printf("scsi system is %sdown!%s\n", RED, NORMAL); goto ShowCrate_Exit; } if( MSGLVL(DETAILS) ) printf("scsi system is %sup!%s\n", GREEN, NORMAL); // user input cli_get_value( &crate_p, &wild ); str_upcase( &wild, &wild ); // check to see if crate db file memory mapped if( CRATEdbFileIsMapped == FALSE ) { // is not, so try if( map_data_file(CRATE_DB) != SUCCESS ) { // we're dead in the water if( MSGLVL(IMPORTANT) ) fprintf( stderr, "error memory mapping crate.db file\n" ); status = FAILURE; // MAP_ERROR; [2001.07.12] goto ShowCrate_Exit; } } // check to see if module 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 cts.db file\n" ); status = FAILURE; // MAP_ERROR; [2001.07.12] goto ShowCrate_Exit; } } printf( "%s\n", heading1.pointer ); // header printf( "%s\n", heading2.pointer ); // header pCr8 = &Cr8; // point to some actual storage pMod = &Mod; // get number of crates in db file if( (numOfCrates = get_file_count(CRATE_DB)) > 0 ) { // possibly something to show if( (numOfModules = get_file_count(CTS_DB)) > 0 ) { // maybe some crates controllers .. for( i = 0; i < numOfCrates; i++ ) { parse_crate_db(CRATEdb+i, pCr8); if( wildcard_match( wild.pointer, pCr8->name, 0,0,0 ) ) { // moduleFound = FALSE; // // for( j = 0; j < numOfModules; ++j ) { // parse_cts_db(CTSdb+j, pMod); // sprintf(tmp, "GK%c%d%02d", // pMod->adapter + 'A', // pMod->id, // pMod->crate // ); // // if( strcmp(tmp, pCr8->name) == EQUAL ) { // if( pMod->slot == 30 ) { // found a crate controller // moduleFound = TRUE; // break; // } // } // } // end of for(modules) ... moduleFound = TRUE; if( moduleFound ) { crateStatus = 0; if(MSGLVL(8)) printf("checking '%s'\n", pCr8->name); status = get_crate_status(pCr8->name, &crateStatus); if( MSGLVL(DETAILS) ) printf("gcs(%s) returned %d, crate 0x%x\n", pCr8->name, status, crateStatus); if( status == SUCCESS ) { // online = !(crateStatus & 0x3c00) ? TRUE : FALSE; // [2002.12.09] // online = !(crateStatus & 0x1000) ? TRUE : FALSE; // [2002.12.09] online = ((crateStatus & 0x1000) != 0x1000) ? TRUE : FALSE; // [2002.12.09] if( !crateStatus || crateStatus == 0x3 ) // [2001.09.10] // [2002.12.09] online = FALSE; // [2002.12.09] sprintf(colorON, "%s", (online) ? GREEN : RED); // enhanced = (online && (crateStatus & 0x4030)) ? TRUE : FALSE; // [2002.12.09] enhanced = (online && (crateStatus & 0x4000)) ? TRUE : FALSE; // [2002.12.09] sprintf(colorENH, "%s", (enhanced) ? GREEN : RED); printf("%s: %s%c%s . . %s%c%s", pCr8->name, colorON, (online) ? '*' : 'X', NORMAL, colorENH, (enhanced) ? '*' : '-', NORMAL ); if( MSGLVL(4) ) printf( " 0x%04x", crateStatus ); printf("\n"); } } // end of if(moduleFound) ... else { printf("%.6s: . . . .\n", pCr8->name); } } // end of if(wildcard) ... } // end of for(crates) ... } // crates, but no modules (ie no controllers) } printf( "%s\n", heading2.pointer ); // header status = SUCCESS; // always (???) ShowCrate_Exit: return status; }