Пример #1
0
void removal_case_5(cardDeck_s *tree, rbNode_s *node)/*#{{{*/
{
    rbNode_s *sibling = find_sibling(node);
    int32_t cLeft = find_rbcolor(sibling -> child[LEFT]);
    int32_t cRight = find_rbcolor(sibling -> child[RIGHT]);

    if(sibling -> cflag == BLACK)
    {
        if( (node == node -> parent -> child[LEFT]) &&
            (cRight == BLACK) &&
            (cLeft == RED)) 
        { /* start if */
            sibling -> cflag = RED;
            sibling -> child[LEFT] -> cflag = BLACK;
            right_rotate(tree, sibling);
        } /* end if */
        else
        {
            if( (node == node -> parent -> child[RIGHT]) &&
                (cLeft == BLACK) &&
                (cRight == RED))
            { /* start if */
                sibling -> cflag = RED;
                sibling -> child[RIGHT] -> cflag = BLACK;
                left_rotate(tree, sibling);
            } /* end if */
        } /* end else */
    } /* end if */

    removal_case_6(tree, node);
} /* end removal_case_5 #}}} */
Пример #2
0
void removal_case_2(cardDeck_s *tree, rbNode_s *node)/*#{{{*/
{
    rbNode_s *sibling = NULL;
    sibling = find_sibling(node);
    
    /* if sibling is red */
    if(sibling -> cflag == RED)
    {
        node -> parent -> cflag = RED;
        sibling -> cflag = BLACK;
        if(node == node -> parent -> child[LEFT]){
            left_rotate(tree, node -> parent);}  /* end if */
        else{
            right_rotate(tree, node -> parent);} /* end else */
    } /* end if */

    removal_case_3(tree, node);
} /* end removal_case_2 #}}} */
Пример #3
0
void removal_case_4(cardDeck_s *tree, rbNode_s *node)/*#{{{*/
{
    rbNode_s *sibling = find_sibling(node);
    int32_t cLeft = find_rbcolor(sibling -> child[LEFT]);
    int32_t cRight = find_rbcolor(sibling -> child[RIGHT]);
    
    if( (node -> parent -> cflag == RED) &&
        (sibling -> cflag == BLACK) &&
        (cLeft == BLACK) &&
        (cRight == BLACK))
    { /* start if */
        sibling -> cflag = RED;
        node -> parent -> cflag = BLACK;
    } /* end if */
    else
    {
        removal_case_5(tree, node);
    } /* end else */
} /* end removal_case_4 #}}} */
Пример #4
0
void removal_case_6(cardDeck_s *tree, rbNode_s *node)/*#{{{*/
{
    rbNode_s *sibling = find_sibling(node);

    sibling -> cflag = node -> parent -> cflag;
    node -> parent -> cflag = BLACK;

    if(node == node -> parent -> child[LEFT])
    {
        assert(sibling -> child[RIGHT] -> cflag == RED);

        sibling -> child[RIGHT] -> cflag = BLACK;
        left_rotate(tree, node -> parent);
    }
    else
    {
        assert(sibling -> child[LEFT] -> cflag == RED);

        sibling -> child[LEFT] -> cflag = BLACK;
        right_rotate(tree, node -> parent);
    } /* end else */
} /* end removal_case_6 #}}} */
Пример #5
0
static void write_f3s(ffs_sort_t *sort, int block_size){

	block_info_t		*block_info;
	uint32_t			size_of_entry;
	ffs_sort_t			*sort_temp_ptr;
	uint16_t			unit_flags;

	//
	//	setup generic buffer
	//

	if ((blk_buffer_ptr = (char *)malloc(0x4000)) == NULL)
		mk_flash_exit("malloc failed: %s\n",strerror(errno));	

	//
	//	create a temporary file
	//

	tmp_name = mk_tmpfile();
	
	if ((flashimage = open(tmp_name,O_BINARY | O_RDWR | O_CREAT | O_TRUNC,
				S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH)) == -1)
			mk_flash_exit("create of %s failed: %s\n",tmp_name,strerror(errno));

	unit_flags = ((~F3S_UNIT_MASK | F3S_UNIT_READY) & ~F3S_UNIT_NO_LOGI);
	block_info = init_block(block_size, unit_flags);

	//
	// first block requires a boot record
	//

	write_boot_record (block_info, spare_blocks,sort);

	//
	// write the initialized block to the file.  each entry will be written  
	// to disk individually.
	//
	// check if this entry has been written to the file yet
	// run through the list until we get to the end
	//

	while(sort){
		if (!(sort->status & FFS_SORT_ENTRY_SET)){

			switch(sort->mode & S_IFMT){

			case S_IFDIR:
				if(verbose)
					fprintf(debug_fp,"writing directory entry -> %s\n",sort->name);
				block_info = write_dir_entry(sort, block_info);
				break;
			case S_IFREG:
				if(verbose)
					fprintf(debug_fp,"writing file entry      -> %s ",sort->name);
				block_info = write_file(sort,block_info);
				break;	        
			case S_IFLNK:
				if(verbose)
					fprintf(debug_fp,"writing link entry      -> %s ",sort->name);
				block_info = write_lnk(sort,block_info);
				break;	        
			case S_IFIFO:
				if(verbose)
					fprintf(debug_fp,"writing fifo entry      -> %s\n",sort->name);
				block_info = write_dir_entry(sort, block_info);
				break;
			} 
		}

		//
		// check for a child, only a directory can have a child  
		//

		if (!sort->child && (sort->mode & (S_IFDIR|S_IFIFO))){


		//
		//	directory entry under f3s can not have a NULL first extent.  The extent pointer must
		//  refer to an extent that in turn points to 0 sized data.
		//

			child_extent(sort,0,block_info);
		
		}      

		if (sort->child && (sort->mode & S_IFDIR)){

			// 
			//child			
			//	

			if ((sort_temp_ptr = find_child(sort)) == NULL)
				mk_flash_exit("find_child failed\n");
		

			size_of_entry = sizeof(f3s_dirent_t) + F3S_NAME_ALIGN(strlen(sort_temp_ptr->name)+1) + sizeof(f3s_stat_t);
			sort_temp_ptr->size_of_entry = size_of_entry;

			if (block_info->available_space < (size_of_entry + sizeof(f3s_head_t)))
		        block_info = init_block(block_size, unit_flags);

			child_extent(sort,sort_temp_ptr->size_of_entry,block_info);

			
			//
			//check the mode of our child
			//

			switch(sort_temp_ptr->mode & S_IFMT){
			
			case S_IFDIR:
				if(verbose)
					fprintf(debug_fp,"writing directory entry -> %s\n",sort_temp_ptr->name);

				block_info = write_dir_entry(sort_temp_ptr, block_info);
				break;

			case S_IFREG:
				if(verbose)
					fprintf(debug_fp,"writing file entry      -> %s ",sort_temp_ptr->name);

				block_info = write_file(sort_temp_ptr,block_info);
			    break;
				
			case S_IFLNK:
				if(verbose)
					fprintf(debug_fp,"writing link entry      -> %s ",sort_temp_ptr->name);

				block_info = write_lnk(sort_temp_ptr,block_info);
				break;
			
			case S_IFIFO:
				if(verbose)
					fprintf(debug_fp,"writing FIFO entry      -> %s\n",sort_temp_ptr->name);

				block_info = write_dir_entry(sort_temp_ptr, block_info);
				break;

			}			
       	}

		//
		//check for a sibling
		//

		if (sort->sibling){
	     	if ((sort_temp_ptr = find_sibling(sort)) == NULL)
				mk_flash_exit("find_sibling failed\n");
				
		
			size_of_entry = sizeof(f3s_dirent_t) + F3S_NAME_ALIGN(strlen(sort_temp_ptr->name)+1) + sizeof(f3s_stat_t);
			sort_temp_ptr->size_of_entry = size_of_entry;

			if (block_info->available_space < (size_of_entry + sizeof(f3s_head_t)))
			       block_info = init_block(block_size, unit_flags);
			sibling_extent(sort,sort_temp_ptr->size_of_entry,block_info);
          		

			switch(sort_temp_ptr->mode & S_IFMT){
				
			case S_IFDIR:
				if(verbose)
					fprintf(debug_fp,"writing directory entry -> %s\n",sort_temp_ptr->name);

				block_info = write_dir_entry(sort_temp_ptr, block_info);
				break;
						
			case S_IFREG:
				if(verbose)
					fprintf(debug_fp,"writing file entry      -> %s ",sort_temp_ptr->name);

				block_info = write_file(sort_temp_ptr,block_info);
				break;

			case S_IFLNK:
				if(verbose)
					fprintf(debug_fp,"writing link entry      -> %s ",sort_temp_ptr->name);

				block_info = write_lnk(sort_temp_ptr,block_info);
				break;

			case S_IFIFO:
				if(verbose)
					fprintf(debug_fp,"writing fifo entry      -> %s\n",sort_temp_ptr->name);

				block_info = write_dir_entry(sort_temp_ptr, block_info);
				break;
						
			}
		}
		sort=sort->next;
	}	

	//
	//	write out the rest of the filesystem.  This includes the spare block(s) and formatting
	//	additional blocks
	//

	spare_block_alloc(block_info);
	
	//
	//	free our malloc buffer
	//

	free(blk_buffer_ptr);
}