Exemplo n.º 1
0
void bfpath_set_filename(bfpath *bfp, const char *filename)
{
    xfree(bfp->filename);
    bfp->filename = xstrdup(filename);
    xfree(bfp->filepath);
    bfp->filepath = mxcat(bfp->dirname, DIRSEP_S, bfp->filename, NULL);
    check_for_file(bfp);
    return;
}
Exemplo n.º 2
0
bool bfpath_check_mode(bfpath *bfp, bfpath_mode m)
{
    bool ok = true;

    bfp->checked = true;

    if (bfp->filepath != NULL && bfp->dirname == NULL && bfp->filename == NULL) {
	char *t = strrchr(bfp->filepath, DIRSEP_C);
	if (t == NULL)
	    bfp->filename = xstrdup(bfp->filepath);
	else {
	    bfp->dirname = xstrdup(bfp->filepath);
	    bfp->dirname[t - bfp->filepath] = '\0';
	    bfp->filename = xstrdup(t+1);
	}
    }

    check_for_file(bfp);

    switch (m)
    {
    case BFP_MUST_EXIST:
	if (!bfp->exists)
	    ok = false;
	break;
    case BFP_MAY_CREATE:
	break;
    case BFP_ERROR:
	/* can't get here */
	abort();
    }

    if (bfp->dirname != NULL && bogohome == NULL)
	set_bogohome(bfp->dirname);

    return ok;
}
Exemplo n.º 3
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.º 4
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;
}