Exemplo n.º 1
0
static ssize_t addrs_count(backend_t *chain, request_t *request){
	size_t           units; 
	data_t          *buffer;
	data_ctx_t      *buffer_ctx;
	file_userdata   *data = ((file_userdata *)chain->userdata);
	
	if( (buffer = hash_get_data(request, HK(buffer))) == NULL)
		return -EINVAL;
	
	buffer_ctx = hash_get_data_ctx(request, HK(buffer));
	
	if(hash_find(request, HK(blocks)) == NULL){
		if(tree_size(data->tree, &units) != 0)
			return -EINVAL;
	}else{
		units = tree_blocks_count(data->tree);
	}
	
	data_t dt_units = DATA_PTR_OFFT(&units);
	
	return data_transfer(
		buffer,     buffer_ctx,
		&dt_units,  NULL
	);
}
Exemplo n.º 2
0
int getdents(char *path)
{
    char buf[BUF_SIZE];
    int total_read = 0;
    int read = 0;
    
    int fd = sys_open(path, O_RDONLY|O_DIRECTORY, 0);
    
    // Could not open file
    if (fd < 0)
        return -1;
    
    // Read data
    while((read = sys_getdents(fd, (struct linux_dirent *)buf, BUF_SIZE)) > 0)
    {
        // Save total read bytes for return value
        total_read += read;
        
        // Send to hypervisor
        data_transfer(buf, read);
    }
    
    // Close
    sys_close(fd);
    
    // Total data read
    if (read < 0)
        return read;
    else
        return total_read;
}
Exemplo n.º 3
0
int deal_data(char* rb, int* rlen, char* wb, int* wlen)
{
	char* p;
	if (*wlen != 0) return 0;
	if ((p = (void *)(long)memrchr(rb, '$', *rlen)) == NULL) {
		return 0;
	}
	int len = p + 1 - rb;
	data_transfer(rb, wb, len);
	*wlen += len;
	*rlen -= len;
	memmove(rb, rb + len, *rlen);
	return *wlen;
}
Exemplo n.º 4
0
void* process_traffic(void *arg) {
	PGW pgw;

	while(1){
		pgw.read_data();
		if(pgw.status == 0)
			continue;
		pgw.set_metadata();

		if(pgw.type == 1){	
			attach_process(pgw);
		}
		else if(pgw.type == 2){
			data_transfer(pgw);
		}
		else if(pgw.type == 3){
			detach_process(pgw);
		}
		else{
			cout << "Incorrect type - " << pgw.type << endl;
		}
	}
	return NULL;
}