Exemple #1
0
static int btree_lookup_raw(struct ro_spine *s, dm_block_t block, uint64_t key,
			    int (*search_fn)(struct btree_node *, uint64_t),
			    uint64_t *result_key, void *v, size_t value_size)
{
	int i, r;
	uint32_t flags, nr_entries;

	do {
		r = ro_step(s, block);
		if (r < 0)
			return r;

		i = search_fn(ro_node(s), key);

		flags = le32_to_cpu(ro_node(s)->header.flags);
		nr_entries = le32_to_cpu(ro_node(s)->header.nr_entries);
		if (i < 0 || i >= nr_entries)
			return -ENODATA;

		if (flags & INTERNAL_NODE)
			block = value64(ro_node(s), i);

	} while (!(flags & LEAF_NODE));

	*result_key = le64_to_cpu(ro_node(s)->keys[i]);
	memcpy(v, value_ptr(ro_node(s), i), value_size);

	return 0;
}
MemoryChunk*	get_bigger_chunk(BinaryTree	*tree,uint32	size,tree_search_callback search_fn)
{
	MemoryChunk	*chunk;
	MemoryChunk	*node;
	MemoryChunk	*n;

	/*the callback function gets called when search_fn returns TRUE*/

	if(tree == 0 || tree->root == 0 || search_fn == 0)
	{
		return 0;
	}
	
	chunk	=	0;
	node = tree->root;

	while(node)
	{
		if(GET_SIZE(node->size)>= size)
		{
			uint32	flg = CONTINUE_SEARCH;

			search_fn(node,&flg,size);

			chunk = node;

			if(flg == ABORT_SEARCH)
			{
				break;
			}
		}

		n = node;
		node = node->right;

		if(node == 0)
		{
			node = n->left;
		}

		if(node == 0)
		{
			node = n->parent;
			if(node)
			{
				node = node->left;
			}

			if(node == n)
			{
				node = 0;
			}
		}

	}

	return	chunk;
}
Exemple #3
0
ot_u8 vl_delete(vlBLOCK block_id, ot_u8 data_id, id_tmpl* user_id) {
#if (OT_FEATURE(VLNEW) == ENABLED)
    vaddr header = NULL_vaddr;
    sub_vaddr   search_fn;
    sub_check   check_fn;

    /// 1. Get the header from the supplied Block ID & Data ID
    block_id--;
    switch (block_id) {
        case 0: check_fn    = &sub_gfb_delete_check;
                search_fn   = &sub_gfb_search;
                break;
                
        case 1: check_fn    = &sub_isfs_delete_check;
                search_fn   = &sub_isfs_search;
                break;
                
        case 2: check_fn    = &sub_isf_delete_check;
                search_fn   = &sub_isf_search;
                break;
                
       default: return 255;
    }
    
    if (check_fn(data_id) != 0) {
        header = search_fn(data_id);
    }
    
    /// 2. Bail if header is NULL
    if (header == NULL_vaddr) {
        return 0x01;
    }
    
    /// 3. Authenticate, when it's not a su call
    if (user_id != NULL) {
        Twobytes filemod;
        filemod.ushort = vworm_read(header + 4);
         
        if ( auth_check(filemod.ubyte[1], VL_ACCESS_RW, user_id) == 0 ) {
            return 0x04;
        }
    }
    
    sub_delete_file(header);
    return 0;
#else
    return 255; //error, delete disabled
#endif
}
Exemple #4
0
ot_u8 vl_new(vlFILE** fp_new, vlBLOCK block_id, ot_u8 data_id, ot_u8 mod, ot_uint max_length, id_tmpl* user_id) {
#if (OT_FEATURE(VLNEW) == ENABLED)
    vaddr header;
    sub_vaddr search_fn;
    sub_new   new_fn;
    
    /// 1. Authenticate, when it's not a su call
    if (user_id != NULL) {
        if ( auth_check(VL_ACCESS_USER, VL_ACCESS_W, user_id) == 0 ) {
            return 0x04;
        }
    }

    /// 2. Make sure the file is not already there
    block_id--;
    switch (block_id) {
        case 0: search_fn   = &sub_gfb_search;
                new_fn      = &sub_gfb_new;
                break;
                
        case 1: search_fn   = &sub_isfs_search;
                new_fn      = &sub_isfs_new;
                break;
                
        case 2: search_fn   = &sub_isf_search;
                new_fn      = &sub_isf_new;
                break;
                
       default: return 0xFF;
    }
    
    header = search_fn(data_id);
    if (header != NULL_vaddr) {
        return 0x02;
    }
    
    *fp_new = new_fn(data_id, mod, max_length);
    if (*fp_new == NULL) {
        return 0x06;
    }
    
    return 0;
#else
    return 255;
#endif
}
Exemple #5
0
/**
 * list_search()
 *  Searches for an item in the list (O(list_size))
 *  @list -- pointer to the list to search in
 *  @compare -- pointer to the data to search for in the list
 *  @search_fn -- pointer to function that takes two args, the first being the
                  data in the list and the second being supplied in *compare,
                  and returns non-zero on a match.
 *  @ret -- index of found item, or -1 on not found
 */
int list_search(linked_list *list, void *compare, int (*search_fn)(void *, void *))
{
    list_node *p = list->head;
    int result = -1, n = 0;

    while(p)
    {
        if(search_fn(p->data, compare))
        {
            result = n;
            break;
        }
    	n++; p = p->next;
    }

    return result;
}