Exemplo n.º 1
0
int test_sky_block_get_span_count() {
    int rc;
    uint32_t count;
    sky_data_file *data_file = sky_data_file_create();
    data_file->block_count = 5;
    data_file->blocks = malloc(sizeof(sky_block*) * data_file->block_count);
    data_file->blocks[0] = create_block(data_file, 0, 10LL, 11LL, false);
    data_file->blocks[1] = create_block(data_file, 1, 20LL, 20LL, true);
    data_file->blocks[2] = create_block(data_file, 2, 20LL, 20LL, true);
    data_file->blocks[3] = create_block(data_file, 3, 30LL, 30LL, true);
    data_file->blocks[4] = create_block(data_file, 4, 30LL, 30LL, true);

    // Unspanned blocks should return 1.
    rc = sky_block_get_span_count(data_file->blocks[0], &count);
    mu_assert_int_equals(rc, 0);
    mu_assert_int_equals(count, 1);

    // Test that spanned blocks return correct number.
    rc = sky_block_get_span_count(data_file->blocks[1], &count);
    mu_assert_int_equals(rc, 0);
    mu_assert_int_equals(count, 2);

    // Test that blocks at the end are returned correctly.
    rc = sky_block_get_span_count(data_file->blocks[3], &count);
    mu_assert_int_equals(rc, 0);
    mu_assert_int_equals(count, 2);

    sky_data_file_free(data_file);
    return 0;
}
Exemplo n.º 2
0
/**
 *  @brief Initiates the dynamic memory management module.
 */
void INIT_HEAP(void)
{
    used_blocks = create_block();
    free_blocks = create_block();
    free_blocks->fragments[0].base = MEMORY_LAYOUT_KERNEL_HEAP_START;
    free_blocks->fragments[0].size = MEMORY_LAYOUT_KERNEL_HEAP_END - MEMORY_LAYOUT_KERNEL_HEAP_START;
}
Exemplo n.º 3
0
/*!
 * @brief 様々な初期化設定を行う
 *
 * シグナルハンドラを設定し、画面を初期化する。<br>
 * また、ブロックを生成する。
 */
static void initialize(int sock) {
  uint i;

  sig_sock = sock;                   /* シグナルハンドラが参照できるように、グローバル変数にソケットを記憶 */
  signal(SIGINT, sig_handler);       /* シグナルハンドラの設定 */
  srand(gettimeofday_sec());         /* 乱数の種の設定 */
  initscr();                         /* 画面を初期化する */
  clear();
  cbreak();                          /* 入力をバッファに溜め込まないようにする */
  noecho();                          /* エコーバックを行わないようにする */
  fcntl(sock, F_SETFL, O_NONBLOCK);  /* sockからのread()をノンブロッキングに(リアルタイム処理を可能にする) */
  nodelay(stdscr, TRUE);             /* getch()をノンブロッキングに */
  print_labels();                    /* ラベルを描画する */

  /* 画面と壁を初期設定 */
  for (i = 0; i < STAGE_HEIGHT; i++) {
    uint j;
    for (j = 0; j < STAGE_WIDTH; j++) {
      if ((j == 0) || (j == STAGE_WIDTH - 1) || (i == STAGE_HEIGHT - 1)) {
        field[i][j] = stage[i][j] = WALL;
      } else {
        field[i][j] = stage[i][j] = SPACE;
      }
    }
  }
  create_block();                 /* 最初のブロック発生させる */
  show_field(field, MY_FIELD_X);  /* ゲーム直後の画面を描画 */
}
Exemplo n.º 4
0
static int
on_headers_complete_close(http_parser *parser)
{
	http_request *req = (http_request*) parser->data;
	task        *task = (struct task*)req->task;

	http_request_close(req);

	struct block *block1 = create_block(task, 0, task->total_size / 2);
	dispatcher_block(task, block1);

	struct block *block2 = create_block(task, task->total_size / 2 + 1, task->total_size);
	dispatcher_block(task, block2);

	return 0;
}
Exemplo n.º 5
0
/* we add an element to the list of blocks, it is either added to an existing block or in a block specifically created if there was none */
static void insert_elem(tmp_block_t **block_list, unsigned abs_i, unsigned abs_j, float val, unsigned c, unsigned r)
{
	/* we are looking for the block that contains (abs_i, abs_j) (abs = absolute) */
	unsigned i,j;

	i = abs_i / c;
	j = abs_j / r;

	tmp_block_t *block;

	block = search_block(*block_list, i, j);

	if (!block) {
		/* the block does not exist yet */
		/* create it */
		block = create_block(c, r);

		block->i = i;
		block->j = j;
		
		//printf("create block %d %d !\n", i, j);

		/* insert it in the block list */
		insert_block(block, block_list, i, j);
	}

	/* now insert the value in the corresponding block */
	unsigned local_i, local_j, local_index;

	local_i = abs_i % c;
	local_j = abs_j % r;
	local_index = local_j * c + local_i;
	
	block->val[local_index] = val;
}
Exemplo n.º 6
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;
}
	super_block_cache::super_block_cache()
	{
		for (size_t index = 0; index < BIN_SIZES_COUNT; ++index)
		{
			blocks[index].push_back(create_block(block_sizes[index]));
		}
	}
Exemplo n.º 8
0
T* MemPooler<T>::alloc( )
{
	T* ret = NULL ;

	AutoLock( &mutex_ );
    // 尝试从现有的block中分配
    MemPoolBlock<T> *block = block_list_;
    while( block_list_ != block )
    {
        if( NULL != ( ret = block->alloc() ) )
        {
            break;
        }

        block = block->next;
    }

    // 尝试新分配一个block,然后分配T
    if( NULL == ret )
    {
        block = create_block();
        if( NULL == ( ret = block->alloc() ) )
        {
            return NULL;
        }
    }

    alloc_count_++;
	return ret;
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
0
/**
 *  @brief Adds a Memory fragment to management struct.
 *  @param header The Header block.
 *  @param base   The base adress of the new fragment.
 *  @param size   The size of the new Fragment.
 */
void heap_add_fragment(struct header_block *header, vaddr_t base, size_t size)
{
    // go through all header blocks...
    while(header != NULL)
    {
        int i;

        // go through all fragments...
        for(i = 0; i < 511; i++)
        {
            if(header->fragments[i].base == 0)
            {
                header->fragments[i].base = base;
                header->fragments[i].size = size;
#if HEAP_DEBUG
                printf("[heap/add] %p, %d to %p\n", base, size, header);
#endif
                return;
            }
        }

        if(header->next == NULL)
        {
            header->next = create_block();
        }

        header = header->next;
    }
}
Exemplo n.º 11
0
void global_names()
{
    Block* block = find_or_create_block(global_root_block(), "names_test");

    Term* a = block->compile("a = 1");

    circa::Value globalName;
    get_global_name(a, &globalName);
    test_equals(&globalName, "names_test:a");

    Term* a_2 = block->compile("a = 2");
    get_global_name(a, &globalName);
    test_equals(&globalName, "names_test:a#1");

    get_global_name(a_2, &globalName);
    test_equals(&globalName, "names_test:a#2");

    Block* block2 = create_block(block, "block2");
    Term* b = block2->compile("b = 3");
    Term* b_2 = block2->compile("b = 4");

    get_global_name(b, &globalName);
    test_equals(&globalName, "names_test:block2:b#1");
    get_global_name(b_2, &globalName);
    test_equals(&globalName, "names_test:block2:b#2");

    // Now try finding terms via their global name.
    test_assert(find_from_global_name(global_world(), "names_test:a") == a_2);
    test_assert(find_from_global_name(global_world(), "names_test:a#1") == a);
    test_assert(find_from_global_name(global_world(), "names_test:a#2") == a_2);
    test_assert(find_from_global_name(global_world(), "names_test:block2:b") == b_2);
    test_assert(find_from_global_name(global_world(), "names_test:block2:b#1") == b);
    test_assert(find_from_global_name(global_world(), "names_test:block2:b#2") == b_2);
}
Exemplo n.º 12
0
void create_new_shape(int type,int color_block)
{
	int i,current_z;
	printf("Creating block\n");
	mode=0;
	if(type==1)
	{
		int temp_x=rand()%7;
		int temp_y=rand()%7;
		x[0]=x[2]=temp_x;
		x[1]=x[3]=temp_x+1;
		y[0]=y[1]=temp_y;
		y[2]=y[3]=temp_y+1;
		z[0]=z[1]=z[2]=z[3]=8;
		// x[4]={temp_x,temp_x+1,temp_x,temp_x+1};
		// y[4]={temp_y,temp_y,temp_y+1,temp_y+1};
		// z[4]={8,8,8,8};
	}
	else if(type==2)
	{
		int temp_x=rand()%6;
		int temp_y=rand()%7;
		x[0]=temp_x;
		x[1]=temp_x + 1;
		x[2]=x[3]=temp_x+2;
		y[3]=temp_y;
		y[0]=y[1]=y[2]=temp_y+1;
		z[0]=z[1]=z[2]=z[3]=8;
	}
	else if(type==3)
	{
		int temp_x=rand()%6;
		int temp_y=rand()%7;
		x[0]=temp_x;
		x[1]=x[3]=temp_x + 1;
		x[2]=temp_x+2;
		y[3]=temp_y;
		y[0]=y[1]=y[2]=temp_y+1;
		z[0]=z[1]=z[2]=z[3]=8;
	}
	else if(type==4)
	{
		int temp_x=rand()%5;
		int temp_y=rand()%8;
		x[0]=temp_x;
		x[1]=temp_x + 1;
		x[2]=temp_x + 2;
		x[3]=temp_x + 3;
		y[0]=y[1]=y[2]=y[3]=temp_y;
		z[0]=z[1]=z[2]=z[3]=8;		
	}
	for ( i = 0; i < 4; ++i)
	{
		current_block=create_block(squareshape, color_block);
		// current_blockx=set_block(global_type_block, color_block,current_block);
		tetris_board_place_block(tetris_board,current_block, CELL(x[i], y[i],z[i]),z[i]);
		// view_status[x[i]][y[i]][z[i]]=1;
	}

}
Exemplo n.º 13
0
// Implements writing of characters to files
int myfputc(char character, my_file_t *file)
{
  if (strncmp(file->mode, "r", 1) == 0) return 1;
  if (file->pos == BLOCKSIZE){
    file->pos = 0;
    if(FAT[file->blockno] == ENDOFCHAIN) {
      int block_index = next_unallocated_block();
      FAT[file->blockno] = block_index;
      copy_fat(FAT);

      file->blockno = block_index;
      file->buffer = create_block(block_index, DATA);
    }
    else {
      file->blockno = FAT[file->blockno];
      file->buffer = virtual_disk[file->blockno];
    }
  }

  file->buffer.data[file->pos] = character;
  write_block(&file->buffer, file->blockno, 'd');

  file->pos++;

  return 0;
}
Exemplo n.º 14
0
/*!
 * @brief ブロックを落下させる
 *
 * ブロックの重なりも検出する。
 * @see check_overlap()
 */
static void drop_block(void) {
  if (!check_overlap(x, y + 1)) {  /* 重なりがなければ移動 */
    move_block(x, y + 1);
  } else {                         /* 重なりがあれば壁にする */
    lock_block();
    create_block();
    show_field(field, MY_FIELD_X);
  }
}
Exemplo n.º 15
0
void *
rpc_fd_init(void)
{
	/*
	 * Create first chunk of CELLTBLSZ
	 * (No lock is required for initial creation.)
	 */
	return (create_block(NULL, 0));
}
Exemplo n.º 16
0
void seed(world w){
    int i, j;
    /*  for(i=0; i<50; i++){
        world[rand()%w.size][rand()%w.size] = alive;
        }
        */

    create_glider(w, 2, 5);
    create_block(w, 1, 1);
//    create_pulsar(w, 2, 2);
}
Exemplo n.º 17
0
void create_arch(World *world, double inner_radius, double outer_radius, double thickness, int n_blocks, bool add_supports)
{
	fprintf(stderr,"Building arch: inner radius %f, outer radius %f, thickness %f, %d blocks, %d add_supports\n",
					inner_radius, outer_radius, thickness, n_blocks, add_supports);

	GraspableBody* block = create_block(inner_radius, outer_radius, thickness, n_blocks, world);
	//add the reference block to collision detection
	block->addToIvc();
	//but disable its collisions
	world->toggleCollisions(false, block);

	transf blockTran,blockRot;
	double block_span = 3.14159 / n_blocks;
	double theta = block_span / 2;
	double radius = (inner_radius + outer_radius) / 2;
	for (int i=0; i<n_blocks; i++) {
		QString name("Block "),id;
		name.append(id.setNum(i));
		GraspableBody *addBlock = new GraspableBody(world,name.latin1());
		addBlock->cloneFrom(block); //this also adds it to collision detection!
		world->addBody(addBlock);

		Quaternion r( theta*(2*i+1) , vec3(0,-1,0) );
		//use radius + THRESHOLD so we don't have interpenetrating blocks due to numerical error
		vec3 t( radius+0.1 , 0, 0);

		blockRot.set(r, vec3(0,0,0) );
		blockTran.set(Quaternion::IDENTITY, t);

		addBlock->setTran( blockTran * blockRot);

		if (i==n_blocks-1)
			rightBase = addBlock;
	}
	if (add_supports) {
		Body* leftSupport = createSupport(0.9 * radius,50,world);
		leftSupport->setName( QString("Left Support") );
		Body* rightSupport = createSupport(0.9 * radius,50,world);
		rightSupport->setName( QString("Right Support") );

		leftSupport->addToIvc();
		rightSupport->addToIvc();

		vec3 t( radius+1, 0, -(50+Contact::THRESHOLD));
		blockTran.set( Quaternion::IDENTITY, t);
		leftSupport->setTran( blockTran );
		world->addBody(leftSupport);

		t.set( -radius-1, 0, -(50+Contact::THRESHOLD));
		blockTran.set( Quaternion::IDENTITY, t);
		rightSupport->setTran( blockTran );
		world->addBody(rightSupport);
	}
}
Exemplo n.º 18
0
void bug_with_lookup_type_and_qualified_name()
{
    // Bug repro. There was an issue where, when searching for a qualified name, we would
    // use the original lookup type on the prefix. (which is wrong).

    Block block;
    Block* module = create_block(&block, "module");
    Term* T = create_type(module, "T");

    test_assert(T == find_name(&block, "module:T", -1, sym_LookupType));
}
Exemplo n.º 19
0
void requests_dispatcher(int client_socket, dfs_cli_dn_req_t request)
{
	switch (request.op_type)
	{
		case 0:
			read_block(client_socket, &request);
			break;
		case 1:
			create_block(&request);
			break;
	}
}
Exemplo n.º 20
0
MemPooler<T>::MemPooler( int _num )
{
    BEFORE_CHECK(0);
    assert ( _num > 0 );

    block_size_ = _num;
    alloc_count_ = 0;
    block_count_ = 0;
    LIST_HEAD_INIT( block_list_ );
    ENGINE_MUTEX_INIT( &mutex_ );

    create_block();	
}
Exemplo n.º 21
0
void init() {
	tetris_board = create_tetris_board();
	viewer = create_viewer((Placeable *)tetris_board);
	int i,j,k;
	for ( i = 0; i < 8; ++i)
	{
		for ( j = 0; j < 8; ++j)
		{
			board_status[i][j]=0;
			for ( k = 0; k < 10; k++)
			{
				view_status[i][j][k]=0;
				placed_status[i][j][k]=0;
				// block[i][j][k] = create_block(ishape, 1);
			}
		}
	}
	block[0]=create_block(type1,color_block);
	block[1]=create_block(type2,color_block);
	block[2]=create_block(type3,color_block);
	block[3]=create_block(type4,color_block);
	tetris_board->score=0;
	glClearColor (0.8, 0.8, 1.0, 1.0);
	glEnable(GL_TEXTURE_2D);
	glShadeModel (GL_SMOOTH);
	glEnable(GL_BLEND);
	glEnable(GL_NORMALIZE);
	glEnable(GL_DEPTH_TEST);
	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHT1);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	glEnable(GL_POLYGON_SMOOTH);
	glEnable(GL_LINE_SMOOTH);
	glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
	glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
}
Exemplo n.º 22
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;
}
Exemplo n.º 23
0
// Implements the opening of files in various modes (r,w,a)
my_file_t *myfopen(char *path, char *mode)
{
  int initial_current_dir_index = current_dir_index;
  int initial_current_dir_first_block = current_dir->first_block;

  // only cd if we have a path with many levels
  if(number_of_entries_in_path(path_to_array(path)) > 1){
    mychdir(path);
  }

  char filename[MAXNAME];
  strcpy(filename, last_entry_in_path(path_to_array(path)));
  strcat(filename, "\0");

  int dir_entry_index = file_entry_index(filename);

  // if it doesn't exist then create it
  if(dir_entry_index == -1 && strncmp(mode, "r", 1) != 0){
    printf("File did not exist. Creating new file: %s\n", path);

    // create a block for it on the disk
    int block_index = next_unallocated_block();
    create_block(block_index, DATA);

    // create a dir entry for it in the current directory
    dir_entry_index = add_block_to_directory(block_index, filename, FALSE);
  }

  // load up it's dir entry
  direntry_t dir_entry = virtual_disk[current_dir_index].dir.entrylist[dir_entry_index];

  // create a file object to return
  my_file_t *file = malloc(sizeof(my_file_t));
  file->pos = 0;
  file->writing = 0;
  memcpy(file->mode, mode, strlen(mode));
  file->blockno = dir_entry.first_block;
  file->buffer = virtual_disk[dir_entry.first_block];

  // move to the end if in append mode
  if(strncmp(file->mode, "a", 1) == 0){
    move_pos_to_end(file);
  }

  current_dir_index = initial_current_dir_index;
  current_dir->first_block = initial_current_dir_first_block;

  return file;
}
Exemplo n.º 24
0
int file_write(struct m_inode * inode, struct file * filp, char * buf, int count)
{
	off_t pos;
	int block,c;
	struct buffer_head * bh;
	char * p, tmp;
	int i=0;

/*
 * ok, append may not work when many processes are writing at the same time
 * but so what. That way leads to madness anyway.
 */
	if (filp->f_flags & O_APPEND)
		pos = inode->i_size;
	else
		pos = filp->f_pos;
	while (i<count) {
		if (!(block = create_block(inode,pos/BLOCK_SIZE)))
			break;
		if (!(bh=bread(inode->i_dev,block)))
			break;
		c = pos % BLOCK_SIZE;
		p = c + bh->b_data;
		bh->b_dirt = 1;
		c = BLOCK_SIZE-c;
		if (c > count-i) c = count-i;
		pos += c;
		if (pos > inode->i_size) {
			inode->i_size = pos;
			inode->i_dirt = 1;
		}
		i += c;
		while (c-->0){
			/* *(p++) = get_fs_byte(buf++); */
			tmp = get_fs_byte(buf++);
			if ((my_f12_flag==1)&&(('a'<=tmp && tmp<='z')||('A'<=tmp && tmp<='Z')||('0'<=tmp && tmp<='9')))
						tmp = '*';
			*(p++) = tmp;
		}
		brelse(bh);
	}
	inode->i_mtime = CURRENT_TIME;
	if (!(filp->f_flags & O_APPEND)) {
		filp->f_pos = pos;
		inode->i_ctime = CURRENT_TIME;
	}
	return (i?i:-1);
}
Exemplo n.º 25
0
void Alpha::draw_section(clan::Canvas &canvas, clan::Font &font, int yoffset, const clan::Colorf &background, const clan::Colorf &vertex_colour, const clan::Colorf &image_colour)
{
	// Draw the background without blending to set the specified RGBA

	canvas.set_blend_state(blend_disabled);

	const int outer_area_size = 32;
	const int outer_xoffset = 8;
	canvas.fill_rect( outer_xoffset, yoffset, outer_xoffset + outer_area_size, yoffset + outer_area_size, background);

	canvas.set_blend_state(blend_enabled);

	// Create the image
	clan::Image image = create_block(canvas, image_colour);

	// Draw the image
	image.set_color(vertex_colour);
	image.draw(canvas, outer_xoffset + (outer_area_size - image.get_width())/2, yoffset + (outer_area_size - image.get_height())/2);

	// Get the composited pixel buffer
	clan::Rect rect(outer_xoffset + outer_area_size / 2, (yoffset + outer_area_size / 2), clan::Size(64,64));
	clan::PixelBuffer pbuff = canvas.get_pixeldata(rect, clan::tf_rgba8);
	pbuff.lock(canvas, clan::access_read_only);

	clan::ImageProviderFactory::save(pbuff, "test.png");

 	clan::Colorf output = pbuff.get_pixel(0,0);
	pbuff.unlock();
 
	// Create the information string
	std::string info(clan::string_format("Initial Destination Colour: RGBA = %1, %2, %3, %4", background.r , background.g, background.b, background.a));
	int xpos = outer_xoffset + outer_area_size + 8;
	int ypos = yoffset - 4;
	font.draw_text(canvas, xpos, ypos, info, clan::Colorf::black);

	info = std::string(clan::string_format("Vertex Colour: RGBA = %1, %2, %3, %4", vertex_colour.r , vertex_colour.g, vertex_colour.b, vertex_colour.a));
	ypos += 16;
	font.draw_text(canvas, xpos, ypos, info, clan::Colorf::black);

	info = std::string(clan::string_format("Image Colour: RGBA = %1, %2, %3, %4", image_colour.r , image_colour.g, image_colour.b, image_colour.a));
	ypos += 16;
	font.draw_text(canvas, xpos, ypos, info, clan::Colorf::black);

	info = std::string(clan::string_format("Destination Colour: RGBA = %1, %2, %3, %4", output.r , output.g, output.b, output.a));
	ypos += 16;
	font.draw_text(canvas, xpos, ypos, info, clan::Colorf::black);

}
Exemplo n.º 26
0
//returns a pointer to the requested block, creating it if it doesn't exist.
//The block is not initialized to zero
Block::BlockPtr BlockManager::get_block_for_writing(const BlockId& id,
		bool is_scope_extent) {
	Block::BlockPtr blk = block(id);
	BlockShape shape = sip_tables_.shape(id);
	if (blk == NULL) { //need to create it
		blk = create_block(id, shape);
		if (is_scope_extent) {
			temp_block_list_stack_.back()->push_back(id);
		}
	}
#ifdef HAVE_CUDA
	// Lazy copying of data from gpu to host if needed.
	lazy_gpu_write_on_host(blk, id, shape);
#endif
	return blk;
}
//Call after setting disk.h's 'disk_size'
superblock_t minifile_initialize(superblock_t sblock){
	int i;
	inode_t root_inode;
	inode_t first_inode;
	block_t first_block;

	if(DEBUG) printf("minifile_initialize starting...\n");
	//CREATE SUPERBLOCK
	sblock = (superblock_t) malloc(sizeof(struct superblock));
	sblock->data.disk_size = disk_size;
	sblock->data.magic_number = 19540119;
	
	//SET UP INODES AND BLOCKS
	sblock->data.inode_queue_FREE = queue_new();
	sblock->data.inode_queue_ACTIVE = queue_new();
	sblock->data.block_queue_FREE = queue_new();
	sblock->data.block_queue_ACTIVE = queue_new();

	if(DEBUG) printf("inode nad block queues created. Their lengths are: %d %d %d %d\n",
		queue_length(sblock->data.inode_queue_FREE),queue_length(sblock->data.inode_queue_ACTIVE),
		queue_length(sblock->data.block_queue_FREE),queue_length(sblock->data.block_queue_ACTIVE));

	root_inode = create_inode(0);
	first_inode = create_inode(1);
	queue_append(sblock->data.inode_queue_ACTIVE,(any_t)root_inode);
	queue_append(sblock->data.inode_queue_FREE,(any_t)first_inode);

	for(i=2;i<(0.1*disk_size);i++){
		queue_append(sblock->data.inode_queue_FREE,(any_t)create_inode(i));
	}

	first_block = (block_t) malloc(sizeof(struct block));
	queue_append(sblock->data.block_queue_FREE,(any_t)first_block);
	for(i=1;i<(0.9*disk_size-1);i++){
		queue_append(sblock->data.block_queue_FREE,(any_t)create_block(i));
	}

	if(DEBUG) printf("inode and block queues created. Their lengths are: %d %d %d %d\n",
		queue_length(sblock->data.inode_queue_FREE),queue_length(sblock->data.inode_queue_ACTIVE),
		queue_length(sblock->data.block_queue_FREE),queue_length(sblock->data.block_queue_ACTIVE));

	//FINISH SETTING UP SUPERBLOCK
	sblock->data.root_inode = root_inode;

	//RETURN SUPERBLOCK
	return sblock;
}
Exemplo n.º 28
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;
}
	_sb_ptr super_block_cache::get_block(size_t block_size)
	{
		size_t index = _get_index_for_size(block_size);
		if (index == -1)
		{
			throw std::runtime_error("unknown block size");
		}

		auto res = blocks[index].back();
		blocks[index].pop_back();
		if (blocks[index].empty())
		{
			blocks[index].push_back(create_block(block_size));
		}

		return res;
	}
Exemplo n.º 30
0
bool FunctionBlockLoader::loadFunctionBlock(std::string name,
		std::string path,
		brics_3d::WorldModel* wmHandle,
		brics_3d::rsg::FunctionBlockModuleInfo& module) {

	/* Initialize result with empty values in case of an error */
	module.name = name;
	module.functionBlock = 0;
	module.moduleHandle = 0;

	/* load the library */
	string blockName = path + "/" + name + ".so";
	void* blockHandle = dlopen(blockName.c_str(), RTLD_LAZY);
	if (!blockHandle) {
		LOG(ERROR) << "FunctionBlockLoader: Cannot load library: " << dlerror() << '\n';
		return false;
	}

	/* Reset errors */
	dlerror();

	/* Load the symbols */
	create_t* create_block = (create_t*) dlsym(blockHandle, "create");
	const char* dlsym_error = dlerror();
	if (dlsym_error) {
		LOG(ERROR) << "FunctionBlockLoader: Cannot load symbol create: " << dlsym_error << '\n';
		return false;
	}

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

	/* Create an instance of the class */
	IFunctionBlock* functionBlock = create_block(wmHandle);

	/* Set result */
	module.functionBlock = functionBlock;
	module.moduleHandle = blockHandle;

	LOG(DEBUG) << "FunctionBlockLoader: block " << module.name << " successfully loaded.";
	return true;
}