示例#1
0
int search_inode_in_folder(int folder_number, const char *node_name)
{
    int result = -1;
    if (folder_number >= 0 && node_name != NULL)
    {
        inode_t *folder = (inode_t *)get_block(folder_number);
        if (folder != NULL)
        {
            if (folder->status == BLOCK_STATUS_FOLDER)
            {
                char name[NODE_NAME_MAX_SIZE];
                int *start = (int *)folder->content;
                int *end = (int *)((void *)folder + size_of_block);
                while (start < end)
                {
                    if (*start > 0 && get_inode_name(*start, name) == 0 && strcmp(node_name, name) == 0)
                    {
                        result = *start;
                        break;
                    }
                    start++;
                }
            }
            destroy_block(folder);
        }
    }
    return result;
}
示例#2
0
static void destroy_value(struct lp_value *v) {
  int d;
  switch(v->t) {
  case S:
    free(v->v.s); 
    break;
    
  case LIST:
    destroy_list(v->v.l);
    break;
    
  case I: 
  case D: break;

  case TOPOSPEC:
    for(d = 0; d < v->v.t.len; d++)
      destroy_topospec(&v->v.t.l[d]);

    free(v->v.t.l);
    break;
      
  default:
    destroy_block(v->v.b);
  }

  free(v);
}
示例#3
0
int remove_node_from_folder(int folder_number, int node_number)
{
    int result = -1;
    if (folder_number >= 0 && node_number > 0)
    {
        inode_t *folder = (inode_t *)get_block(folder_number);
        if (folder != NULL)
        {
            if (folder->status == BLOCK_STATUS_FOLDER)
            {
                int *start = (int *)folder->content;
                int *end = (int *)((void *)folder + size_of_block);
                while (start < end)
                {
                    if (*start == node_number)
                    {
                        *start = 0;
                        break;
                    }
                    start++;
                }
                if (start < end)
                {
                    result = write_block(folder_number, folder);
                }
                else
                {
                    result = 0;
                }
            }
            destroy_block(folder);
        }
    }
    return result;
}
示例#4
0
int create_file(const char *name, mode_t mode, dev_t dev)
{
    int number = search_free_block();
    if (number >= 0)
    {
        inode_t *file = (inode_t *)create_block();
        if (file != NULL)
        {
            int name_size = strlen(name) + 1;
            if (name_size > NODE_NAME_MAX_SIZE)
            {
                name_size = NODE_NAME_MAX_SIZE;
            }
            file->status = BLOCK_STATUS_FILE;
            memcpy(file->name, name, name_size);
            file->stat.st_mode = S_IFREG | mode;
            file->stat.st_rdev = dev;
            file->stat.st_nlink = 1;
            if (write_block(number, file) != 0)
            {
                number = -1;
            }
            destroy_block(file);
        }
    }
    return number;
}
示例#5
0
int create_folder(const char *name, mode_t mode)
{
    int number = search_free_block();
    if (number >= 0)
    {
        inode_t *folder = (inode_t *)create_block();
        if (folder != NULL)
        {
            int name_size = strlen(name) + 1;
            if (name_size > NODE_NAME_MAX_SIZE)
            {
                name_size = NODE_NAME_MAX_SIZE;
            }
            folder->status = BLOCK_STATUS_FOLDER;
            memcpy(folder->name, name, name_size);
            folder->stat.st_mode = S_IFDIR | mode;
            folder->stat.st_nlink = 2;
            if (write_block(number, folder) != 0)
            {
                number = -1;
            }
            destroy_block(folder);
        }
    }
    return number;
}
示例#6
0
bool FunctionBlockLoader::unloadFunctionBlock(brics_3d::rsg::FunctionBlockModuleInfo& module) {

	if ((module.functionBlock) == 0 || (module.moduleHandle == 0)) {
		LOG(ERROR) << "FunctionBlockLoader::unloadFunctionBlock invalid module meta-data for block " << module.name;
		return false;
	}

	destroy_t* destroy_block = (destroy_t*) dlsym(module.moduleHandle, "destroy");
	const char* dlsym_error = dlerror();
	if (dlsym_error) {
		LOG(ERROR) << "FunctionBlockLoader: Cannot load symbol destroy: " << dlsym_error << '\n';
		return false;
	}

	// destroy the class
	destroy_block(FunctionBlockLoader::moduleToBlock(module));
	module.functionBlock = 0;

	// unload
	dlclose(module.moduleHandle);
	module.moduleHandle = 0;

	LOG(DEBUG) << "FunctionBlockLoader: block " << module.name << " successfully unloaded.";
	return true;
}
示例#7
0
文件: group.c 项目: lilliemarck/kloss
void delete_blocks(struct group *group, block **blocks, size_t count)
{
    detatch_blocks(group, blocks, count);

    for (size_t i = 0; i < count; ++i)
    {
        destroy_block(blocks[i]);
    }
}
示例#8
0
文件: main.c 项目: tthimm/c_sim
void place_and_destroy_blocks(SDL_Surface *scr, int x, int y, struct Player *p) {
	// if mouse button is pressed and player moves cursor out of the screen, x and y could be negative
	if((x > 0) && (y > 0)) {
		if(input.mleft) {
			destroy_block(scr, x, y);
		}
		if(input.mright) {
			place_block(x, y, p);
		}
	}
}
/*
Returns 0 if it is a destructable block, 1 if it is indestructable, 2 otherwise.
If the block is destructable, a function is called to destroy it.

Matt Woodske
Jerrod Hudson
*/
int
block_here(const int x, const int y)
{
if (grid[y][x] == GRID_DBLOCK) {
	destroy_block(x,y);
	return 0;
}
	
if (grid[y][x] == GRID_UBLOCK)
	return 1;
else
	return 2;
}
示例#10
0
void *get_block(int number)
{
    void *block = NULL;
    if (number >= 0)
    {
        block = create_block();
        if (block != NULL && read_block(number, block) != 0)
        {
            destroy_block(block);
            block = NULL;
        }
    }
    return block;
}
示例#11
0
void cleanup_outbreak(Outbreak * outbreak) {
  int i;
  for (i = 0; i < outbreak->num_blocks; i++) {
    destroy_block(outbreak->blocks[i]);
    outbreak->blocks[i] = NULL;
  }
  outbreak->num_blocks = 0;

  destroy_ball(outbreak->ball);
  outbreak->ball = NULL;

  destroy_player(outbreak->player);
  outbreak->player = NULL;
}
示例#12
0
int clear_block(int number)
{
    int result = -1;
    if (number >= 0 && lseek(filesystem_fd, size_of_block * number, SEEK_SET) >= 0)
    {
        void *block = create_block();
        if (block != NULL)
        {
            if (write_block(number, block) == 0)
            {
                result = 0;
            }
            destroy_block(block);
        }
    }
    return result;
}
示例#13
0
int create_root()
{
    int result = -1;
    inode_t *root = (inode_t *)create_block();
    if (root != NULL)
    {
        root->status = BLOCK_STATUS_FOLDER;
        root->name[0] = '\0';
        root->stat.st_mode = S_IFDIR | 0777;
        root->stat.st_nlink = 2;
        if (write_block(number_of_root_block, root) == 0)
        {
            result = 0;
        }
        destroy_block(root);
    }
    return result;
}
示例#14
0
文件: util.c 项目: Anurag461/disksim
void lp_release_typetbl(void) {
  int c;

  for(c = 0; c < lp_typetbl_len; c++) {
    if(!lp_typetbl[c]) continue;

    if(lp_typetbl[c]->spec)
      destroy_block(lp_typetbl[c]->spec);

    if(lp_typetbl[c]->sub)
      free(lp_typetbl[c]->sub);

    if(lp_typetbl[c]->super) 
      free(lp_typetbl[c]->super); 

    free(lp_typetbl[c]);
  }

  free(lp_typetbl);
}
示例#15
0
int remove_folder(int number)
{
    int result = -1;
    inode_t *folder = (inode_t *)get_block(number);
    if (folder != NULL)
    {
        int *start = (int *)folder->content;
        int *end = (int *)((void *)folder + size_of_block);
        while (start < end)
        {
            if (*start > 0)
            {
                remove_block(*start);
            }
            start++;
        }
        destroy_block(folder);
        result = set_block_status(number, BLOCK_STATUS_FREE);
    }
    return result;
}
示例#16
0
文件: group.c 项目: lilliemarck/kloss
static void release_groupdata(struct groupdata *groupdata)
{
    if (groupdata && --groupdata->refcount == 0)
    {
        size_t blockcount = ptrarray_count(groupdata->blocks);
        for (size_t i = 0; i < blockcount; ++i)
        {
            destroy_block(get_ptrarray(groupdata->blocks, i));
        }

        size_t groupcount = ptrarray_count(groupdata->groups);
        for (size_t i = 0; i < groupcount; ++i)
        {
            destroy_group(get_ptrarray(groupdata->groups, i));
        }

        destroy_ptrarray(groupdata->blocks);
        destroy_ptrarray(groupdata->groups);
        destroy_buffer(groupdata->vertices);

        free(groupdata);
    }
}
示例#17
0
文件: terminal.c 项目: aolesky/Shell
/**
* Main program execution
*/
int main (int argc, char *argv[]) {
	TOKENIZER *tokenizer;
	char string[1024] = "";
	char *tok;
	int br;

	int most_recent_job = 0;

	ProcessMap *jobs = new_map();

	//Set up signal handling
	signal(SIGINT, SIG_IGN);
	signal(SIGTSTP, SIG_IGN);
	signal(SIGTTOU, SIG_IGN);
	signal(SIGTTIN, SIG_IGN);
	signal(SIGTERM, SIG_IGN);


	string[1023] = '\0';	   /* ensure that string is always null-terminated */
	printf("\nEnter a command or type ctrl-d to end session.\n" );
	write(1, "\nmy-sh$ ", 8);

	//Input loop
	while ((br = read( STDIN_FILENO, string, 1023 )) > 0) {

		if (br <= 1) {
			write(1, "my-sh$ ", 8);
			continue;
		}

		string[br-1] = '\0';
		tokenizer = init_tokenizer(string);

		//Create linked list of tokens
		LinkedList *input_command = new_list(256);
		while( (tok = get_next_token( tokenizer )) != NULL ) {
			push_back(input_command, tok);
			free(tok);
		}
		free_tokenizer(tokenizer);


		int executed = 0;
		int error = 0;
		//Checks for fg or bg
		if (get_length(input_command) == 1) {
			char *only_token = pop_back(input_command);

			if (compare_strings(only_token, "fg")) {
				if (move_to_foreground(jobs, &most_recent_job) == -1)
					error = 1;
				executed = 1;
					
			} else if (compare_strings(only_token, "bg")) {
				if (move_to_background(jobs, &most_recent_job) == -1)
					error = 1;
				executed = 1;
			} else {
				push_back(input_command, only_token);
			}
			free(only_token);
		}


		//Process input for pipes or background if an error has already been detected, go to the next command
		if (!executed && !error) {

			//Sees if a background ampersand is detected
			bool is_background = determine_background(input_command);

			LinkedList *full_command = copy_list(input_command);

			if (is_background) {
				printf("Running: ");
				print_list(input_command);
			}

			//Test for pipes
			bool is_pipe = false;
			LinkedList *first_command_list = new_list(50);
			LinkedList *second_command_list = new_list(50);
			int valid_pipe = find_piping(input_command, &is_pipe, first_command_list, second_command_list);

			//Command blocks are created from the command lists
			CommandBlock *first_command = new_command_block(first_command_list);
			CommandBlock *second_command = new_command_block(second_command_list);

			//Runs a function to check that there are no invalid redirections in the case of a piping
			if (is_pipe) {
				valid_pipe = valid_pipe && check_pipe(first_command, second_command);
			}

			//Notifies user of any incorrect pipe commands
			if (!is_pipe && !first_command->valid) {
				printf("Invalid command structure\n");
			} else if (is_pipe && (!first_command->valid || !second_command->valid || !valid_pipe) ) {
				printf("Invalid command structure\n");
			}


			//If it is a pipe and all necessary conditions are valid, then the piping occurs
			if (is_pipe && first_command->valid && second_command->valid && valid_pipe) {
				
				if (pipe_job (first_command, second_command, is_background, full_command, jobs, &most_recent_job) 
					== -1)
					error = 1;

			} 
			// No piping
			else if (!is_pipe && first_command->valid) {

				if (job (first_command, is_background, full_command, jobs, &most_recent_job) == -1)
					error = 1;
			}

			destroy_list(first_command_list);
			destroy_list(second_command_list);
			destroy_block(first_command);
			destroy_block(second_command);
			destroy_list(full_command);
		}

		destroy_list(input_command);

		
		monitor_background_jobs (jobs, &most_recent_job);

		if (error)
			perror("ERROR ");

		write(1, "my-sh$ ", 8);
	}

	destroy_map(jobs);

	
	
	printf( "\nSession ended\n" );
	return 0;
}