Exemplo n.º 1
0
//-------------------------------------------------------------------------
// 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;
}
Exemplo n.º 2
0
//-------------------------------------------------------------------------
// 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;
}
Exemplo n.º 3
0
//-------------------------------------------------------------------------
// 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;
}
Exemplo n.º 4
0
//-------------------------------------------------------------------------
// contract_db()
// Wed Jan 30 10:44:01 EST 2002
//-------------------------------------------------------------------------
// Contract the CTS or CRATE db files
//
// input:	db type,
// 			current number of entries in CTS data file
// output:	status
//-------------------------------------------------------------------------
int contract_db( int dbType, int numOfEntries )
{
	char	*FileName;
	int		FileIncr, newCount; 
	int		status = SUCCESS;		// optimistic, aren't we ... :>
        char    tmpfile[1024];
        strcpy(tmpfile,get_file_name("mdscts_temp_file_XXXXXX"));

	if( MSGLVL(FUNCTION_NAME) )
		printf( "contract_db()\n" );

	// assimilate db specific information ...
	switch( dbType ) {
		case CTS_DB:
			FileName = CTS_DB_FILE;
			FileIncr = CTS_DB_INCREMENT;
			break;

		case CRATE_DB:
			FileName = CRATE_DB_FILE;
			FileIncr = CRATE_DB_INCREMENT;
			break;
	}

	// make db file smaller ....  [2002.01.30]
	//
	//
	// calculate new db file size
	newCount = (((int)numOfEntries / FileIncr) + 1) * FileIncr;

	// create a TMP file
	if( (status = create_tmp_file( dbType, newCount, tmpfile )) != SUCCESS ) {
		if( MSGLVL(ALWAYS) )
			fprintf( stderr, "error creating TMP file\n" );

		goto ContractDB_Exit;
	}

	// only need to copy old data if there is any
	if( numOfEntries ) { 				// copy current db file to TMP file
		if( (status = copy( dbType, FileName, tmpfile, numOfEntries )) != SUCCESS ) {
			if( MSGLVL(ALWAYS) )
				fprintf( stderr, "error copying db to TMP file\n" );

			goto ContractDB_Exit;
		}

		// remove old db file
		if( Remove( FileName ) ) {		// non-zero is an error
			if( MSGLVL(ALWAYS) ) {
				fprintf( stderr, "error removing old db file\n" );
				perror("remove()");
			}

			status = CONTRACT_ERROR;
			goto ContractDB_Exit;
		}
	}

	if( rename(tmpfile, get_file_name( FileName )) ) {	// non-zero is an error
		if( MSGLVL(ALWAYS) ) {
			fprintf( stderr, "error renaming temp db file\n" );
			perror("rename()");
		}

		status = CONTRACT_ERROR;
		goto ContractDB_Exit;
	}
        chmod(get_file_name( FileName ), O666);
	// re-map file
	if( map_data_file( dbType ) != SUCCESS ) {
		if( MSGLVL(ALWAYS) )
			fprintf( stderr, "unable to map contracted file\n" );

		status = MAP_ERROR;
		goto ContractDB_Exit;
	}

ContractDB_Exit:
	if( MSGLVL(DETAILS) ) {
		printf( "contract_db('%s'): ", get_file_name( FileName )); ShowStatus( status );
	}

	return status;
}
Exemplo n.º 5
0
//-------------------------------------------------------------------------
// get_file_count()
// Thu Jan  4 12:06:05 EST 2001
// Wed Apr 18 11:22:47 EDT 2001 -- use macro support, ie 'Open()'
// Thu Sep  6 13:43:00 EDT 2001	-- fixed debug printout
// Wed Sep 19 12:19:00 EDT 2001	-- switched to memory mapped file use; faster
// Tue Jan  8 17:16:18 EST 2002	-- fixed end of dbfile problem
//-------------------------------------------------------------------------
// Get number of entries in database file. Unused records have a leading
// 	space character. Uses memory mapped 'version' of db file.
//
// input:	db type
// output:	number of entries [0..n]; FILE_ERROR [-2 * 2] if error
//-------------------------------------------------------------------------
int get_file_count( int dbType )
{
	void 				 *dbptr;	// generic pointer to struct's
	char 				 dbFileName[16];
	int					 dbFileSize, entrySize, i, numOfEntries;
	int 				 *FileIsMapped;
	extern struct MODULE *CTSdb;
	extern struct CRATE  *CRATEdb;
	extern int 			 CTSdbFileIsMapped;
	extern int 			 CRATEdbFileIsMapped;

	switch( dbType ) {
		case CTS_DB:
			dbptr = (void *)CTSdb;
			entrySize              = MODULE_ENTRY;
			FileIsMapped           = &CTSdbFileIsMapped;
			sprintf(dbFileName, "%s", CTS_DB_FILE);
			break;

		case CRATE_DB:
			dbptr  = (void *)CRATEdb;
			entrySize              = CRATE_ENTRY;
			FileIsMapped           = &CRATEdbFileIsMapped;
			sprintf(dbFileName, "%s", CRATE_DB_FILE);
			break;
	}

	if( MSGLVL(FUNCTION_NAME) )
		printf( "get_file_count()\n" );

	// check for memory mapped file
	if( *FileIsMapped == FALSE ) {
		if( map_data_file(dbType) != SUCCESS ) {
			numOfEntries = MAP_ERROR;
			goto GetFileCount_Exit;
		}
	}

	// get total db file size in bytes
	if(( dbFileSize = get_db_file_size(dbFileName)) < 0 ) {
		numOfEntries = FAILURE;
		goto GetFileCount_Exit;
	}

	// get the appropriate count
	numOfEntries = 0;
	for( i = 0; ; i += entrySize ) {
		if( (i + entrySize) > dbFileSize )	// make sure we don't fall off the end ...
			break;

		//		sprintf(&ch, "%.1s", (char *)(dbptr+i));

		if( *(char *)(dbptr+i) == ' ' )						// we're done, so out'a here
			break;

		++numOfEntries;
	}

GetFileCount_Exit:
	if( MSGLVL(DETAILS) )
		printf( "get_file_count(%d):\n", numOfEntries );

	return numOfEntries;
}
Exemplo n.º 6
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;
}
Exemplo n.º 7
0
//-------------------------------------------------------------------------
// 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;
}
Exemplo n.º 8
0
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
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;
}
Exemplo n.º 9
0
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// 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;
}
Exemplo n.º 10
0
//-------------------------------------------------------------------------
// 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;
}  
Exemplo n.º 11
0
//-------------------------------------------------------------------------
// map generic scsi device names to crate table names 
//-------------------------------------------------------------------------
int Autoconfig()
{
	char	highway_name[CRATE_NAME_SIZE + 1], *pHighwayName;
	char	line[CRATE_ENTRY];
	int		i, numOfEntries;
	int		status = SUCCESS;		// optimistic
	FILE	*fp;

	int j;
	int found, retries;

	// 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 = MAP_ERROR;
			goto AutoConfig_Exit;							// we're done  :<
		}
	}

	// get current db file count
	if( (numOfEntries = get_file_count(CRATE_DB)) <= 0 ) {	// nothing to do ...
		status = FILE_ERROR;
		goto AutoConfig_Exit;								// we're done  :<
	}

	// open file for read-only
	if( (fp = Fopen(CRATE_DB_FILE, "r")) == NULL ) {
		if( MSGLVL(2) )
			fprintf( stderr, "crate.db does not exist\n" );

		status = FILE_ERROR;
		goto AutoConfig_Exit;
	}

	pHighwayName = highway_name;	// point to real memory ...

	// loop thru list
	for( i = 0; i < numOfEntries; ++i ) {
		fscanf(fp, "%s", line);								// get a crate.db entry
		sprintf(pHighwayName, "%.6s", line);				// trim it

		// NB! this is a work-around -- seems necessary for the moment
		for( j = 0; j < 2; j++ ) {
			if( map_scsi_device(pHighwayName) != SUCCESS ) {	// map it if possible
				if( MSGLVL(IMPORTANT) )
					fprintf( stderr, "error mapping scsi device '%s'\n", pHighwayName );
			}
		}

// NB! this is a work-around -- seems necessary for the moment	[2001.11.02] -- see above
//		retries = 2;	// maximum retry count
//		found = FALSE;
//		while( !found && retries-- ) {
//			if( (found = map_scsi_device(pHighwayName)) != SUCCESS ) {	// map it if possible
//				fprintf( stderr, "error mapping scsi device '%s'\n", pHighwayName );
//			}
//		}

	}
	// end of for()...

AutoConfig_Exit:
	status = SUCCESS;

	return status;
}