示例#1
0
static int
postgresqlfs_mkdir(const char *path, mode_t mode __attribute__((unused)))
{
	struct dbpath dbpath;

	split_path(path, &dbpath);

	// TODO: use mode sensibly

	if (dbpath_is_root(dbpath))
		return -EEXIST;
	else if (dbpath_is_database(dbpath))
		return db_command(dbconn, "CREATE DATABASE %s;", dbpath.database);
	else {
		/* Note: Don't switch the database when creating a database. */
		if (!switch_database(&dbpath))
			return -EIO;

		if (dbpath_is_schema(dbpath))
			return db_command(dbconn, "CREATE SCHEMA %s;", dbpath.schema);
		else if (dbpath_is_table(dbpath))
			return -ENOSYS; /* maybe: create zero column table */
		else if (dbpath_is_row(dbpath))
			return -ENOSYS; /* maybe: translate to INSERT with primary key and default values? */
		else
			return -ENOENT;
	}
}
示例#2
0
/* This function is called from machine trap code. */
void
db_command_loop(void)
{
	label_t	db_jmpbuf;
	label_t	*savejmp;

	/*
	 * Initialize 'prev' and 'next' to dot.
	 */
	db_prev = db_dot;
	db_next = db_dot;

	db_cmd_loop_done = false;

	/* Init default command tables add machine, base,
	   show command tables to the list */
	db_init_commands();

	/* save context for return from ddb */
	savejmp = db_recover;
	db_recover = &db_jmpbuf;
	(void) setjmp(&db_jmpbuf);

	/*
	 * Execute default ddb start commands only if this is the
	 * first entry into DDB, in case the start commands fault
	 * and we recurse into here.
	 */
	if (!savejmp)
		db_execute_commandlist(db_cmd_on_enter);

	(void) setjmp(&db_jmpbuf);
	while (!db_cmd_loop_done) {
		if (db_print_position() != 0)
			db_printf("\n");
		db_output_line = 0;
		(void) db_read_line();
		db_command(&db_last_command);
	}

	db_recover = savejmp;
}
示例#3
0
/*
 * Execute commandlist after ddb start
 * This function goes through the command list created from commands and ';'
 */
static void
db_execute_commandlist(const char *cmdlist)
{
	const char *cmd = cmdlist;
	const struct db_command	*dummy = NULL;

	while (*cmd != '\0') {
		const char *ep = cmd;

		while (*ep != '\0' && *ep != DB_LINE_SEP) {
			ep++;
		}
		db_set_line(cmd, ep);
		db_command(&dummy);
		cmd = ep;
		if (*cmd == DB_LINE_SEP) {
			cmd++;
		}
	}
}
示例#4
0
void
db_command_loop(void)
{
	/*
	 * Initialize 'prev' and 'next' to dot.
	 */
	db_prev = db_dot;
	db_next = db_dot;

	db_cmd_loop_done = 0;
	while (!db_cmd_loop_done) {

	    setjmp(db_jmpbuf);
	    if (db_print_position() != 0)
		db_printf("\n");

	    db_printf("db> ");
	    db_read_line();

	    db_command(&db_last_command, db_command_table,
		    SET_BEGIN(db_cmd_set), SET_LIMIT(db_cmd_set));
	}
}
示例#5
0
static int
postgresqlfs_rmdir(const char *path)
{
	struct dbpath dbpath;

	split_path(path, &dbpath);

	if (!switch_database(&dbpath))
		return -EIO;

	if (dbpath_is_root(dbpath))
		return -EBUSY;
	else if (dbpath_is_database(dbpath))
		return -ENOTEMPTY;
	else if (dbpath_is_schema(dbpath))
		return db_command(dbconn, "DROP SCHEMA %s;", dbpath.schema);
	else if (dbpath_is_table(dbpath))
		return -ENOSYS; /* maybe: drop table if it has zero columns */
	else if (dbpath_is_row(dbpath))
		return -ENOSYS; /* maybe: remove row by ctid if table has zero columns */
	else
		return -ENOTDIR;
}
示例#6
0
void
db_command_loop(void)
{
	label_t		db_jmpbuf;
	label_t		*savejmp;
	extern int	db_output_line;

	/*
	 * Initialize 'prev' and 'next' to dot.
	 */
	db_prev = db_dot;
	db_next = db_dot;

	db_cmd_loop_done = 0;

	savejmp = db_recover;
	db_recover = &db_jmpbuf;
	(void) setjmp(&db_jmpbuf);

	while (!db_cmd_loop_done) {

		if (db_print_position() != 0)
			db_printf("\n");
		db_output_line = 0;

#ifdef MULTIPROCESSOR
		db_printf("ddb{%d}> ", CPU_INFO_UNIT(curcpu()));
#else
		db_printf("ddb> ");
#endif
		(void) db_read_line();

		db_command(&db_last_command, db_command_table);
	}

	db_recover = savejmp;
}
示例#7
0
void drive_frontend(){

	//printf("drive_frontend\n");

	set_option("follow_path", "true");
	set_option("single_step", "true");

	set<PathAndConds> frontier;

	load_heuristics();

	int n = 0;
	do {
		PathAndConds first;
		if(frontier.size()){

			bool pick_random = cmd_option_bool("random_branching");
			//bool pick_random = true;
			if(pick_random){
				int pick = rand() % frontier.size() - 1;
				set<PathAndConds>::iterator it = frontier.begin(); it++;
				while(pick > 0){
					it++; pick--;
				}
				first = *(it);
				frontier.erase(it);
			} else {
				first = *(frontier.begin());
				frontier.erase(frontier.begin());
			}
		}

		set_option("path", first.path);
		set_option("file_initializations", first.file_initializations);

		options_to_file();

		db_command("delete from frontend;");
		db_command("delete from results;");
		db_command("delete from last_bb;");
		db_command("delete from variables;");

		// Run resulting file
		stringstream cmd;
		cmd << "./" << cmd_option_str("output_file");
		systm(cmd.str().c_str());

		add_paths(frontier);

		if(n++ == cmd_option_int("max_depth"))
			exit(0);

		if(cmd_option_bool("show_frontier")){
			printf("last_bb %s\n", get_last_bb().c_str() ); // last one executed.
			// frontier contains the constraints to get to last_bb + the last constraint
			
			if(get_last_bb() == cmd_option_str("target_node")){
				printf("Node hitted\n");
				//exit(0);
				break;
			}

			print_frontier(frontier);

			if(cmd_option_bool("stop_in_frontier"))
				getchar();
		}


	} while(frontier.size());

}
示例#8
0
static int
postgresqlfs_rename(const char *oldpath, const char *newpath)
{
	struct dbpath olddbpath, newdbpath;

	split_path(oldpath, &olddbpath);
	split_path(newpath, &newdbpath);

	if (!dbpaths_are_same_level(&olddbpath, &newdbpath))
		return -EXDEV;

	if (dbpath_is_root(olddbpath))
		return -EINVAL;
	else if (dbpath_is_database(olddbpath))
	{
		// XXX check whether paths exist; clearer error codes
		return db_command(dbconn,
						  "ALTER DATABASE %s RENAME TO %s;",
						  olddbpath.database, newdbpath.database);
	}
	else if (dbpath_is_schema(olddbpath))
	{
		/* moving a schema to a different database is not possible */
		if (strcmp(olddbpath.database, newdbpath.database) != 0)
			return -EXDEV;

		return db_command(dbconn,
						  "ALTER SCHEMA %s RENAME TO %s;",
						  olddbpath.schema, newdbpath.schema);
	}
	else if (dbpath_is_table(olddbpath))
	{
		/* moving a table to a different database is not possible */
		if (strcmp(olddbpath.database, newdbpath.database) != 0)
			return -EXDEV;

		if (strcmp(olddbpath.schema, newdbpath.schema) != 0)
			return -ENOSYS; // XXX for the time being

		return db_command(dbconn,
						  "ALTER TABLE %s.%s RENAME TO %s;",
						  olddbpath.schema, olddbpath.table, newdbpath.table);
	}
	else if (dbpath_is_row(olddbpath))
		return -EINVAL; // XXX right code?
	else if (dbpath_is_column(olddbpath))
	{
		/* renaming a column to reappear in a different table doesn't make sense */
		if (strcmp(olddbpath.database, newdbpath.database) != 0
			|| strcmp(olddbpath.schema, newdbpath.schema) != 0
			|| strcmp(olddbpath.table, newdbpath.table) != 0
			|| strcmp(olddbpath.row, newdbpath.row) != 0)
			return -EINVAL;

		/* column number must stay the same (could be changed if
		 * PotgreSQL supported reordering) */
		if (strncmp(olddbpath.column, newdbpath.column, 3) != 0)
			return -EINVAL;

		return db_command(dbconn,
						  "ALTER TABLE %s.%s RENAME COLUMN %s TO %s;",
						  olddbpath.schema, olddbpath.table, olddbpath.column + 3, newdbpath.column + 3);
	}

	return -EINVAL;
}