Ejemplo n.º 1
0
/* Create a series of blocks, and optionally the single-, double-, and/or
   triple-indirect blocks that refer to them. level specifies how many steps
   away from data blocks we are (between 0 and 3), map is an array into which
   the logical/physical associations of data blocks should be stored, next
   refers to the next logical block number, and nblocks is the number of logical
   blocks that are to be created. */
static int create_blocks(ext2_filesystem *fs, int level, uint32_t *map,
                         int *next, int nblocks)
{
  if (*next >= nblocks)
    return 0;

  /* Allocate the next block */
  int blockno = alloc_block(fs);
  if (0 == level) {

    /* If this is a data block (as opposed to an indirect block), record the
       logical->physical mapping, and increment the next logical block number */
    if (map)
      map[*next] = blockno;
    (*next)++;
  }
  if (0 < level) {
    /* Create a series of data or indirect blocks one level down, and store
       references to them in the current indirect block */
    buffer *indirect_buf;
    try(bufcache_get(fs->bc,blockno,&indirect_buf));
    int i;
    uint32_t *table = (uint32_t*)indirect_buf->data;
    for (i = 0; i < RPB; i++)
      table[i] = create_blocks(fs,level-1,map,next,nblocks);
    bufcache_release(fs->bc,indirect_buf,1);
  }
  return blockno;
}
Ejemplo n.º 2
0
/* Create a fake i-node with the specified size. The data blocks are not
   initialised. If map is non-NULL, the logical->physical block associations
   will be recorded in this array (the caller must allocate an appropriate
   amount of memory to this) */
inode *create_test_inode(ext2_filesystem *fs, int size, uint32_t *map)
{
  int nblocks = divroundup(size,BLOCKSIZE);
  assert(nblocks <= MAX_INODE_BLOCKS);
  inode *ino = (inode*)calloc(1,sizeof(inode));
  ino->fs = fs;
  int next = 0;
  int i;
  nextblock = 1;
  /* Direct block references */
  for (i = 0; i < 12; i++)
    ino->in.block[i] = create_blocks(fs,0,map,&next,nblocks);
  /* Single-indirect block */
  ino->in.block[12] = create_blocks(fs,1,map,&next,nblocks);
  /* Double-indirect block */
  ino->in.block[13] = create_blocks(fs,2,map,&next,nblocks);
  /* Triple-indirect block */
  ino->in.block[14] = create_blocks(fs,3,map,&next,nblocks);
  ino->in.size = size;
  return ino;
}
/** Initialisation de l'environnement à chaque épisode 
 *  @param *p_env paramètre
 */
state_t env_start(env_t* p_env) {
  assert(p_env!=NULL);
  //p_env->cell = p_env->n_cells-1;
  // Put agent at random position (but not in a terminal state)
  create_blocks(p_env);
  do {
    p_env->cell = rand()%p_env->n_cells;
   // printf("Mur : %d\nnumero de la cellule:%llu\nligne:%llu\ncolonne:%llu\n",is_a_wall_here(p_env),p_env->cell,p_env->cell/p_env->n_cols,p_env->cell%p_env->n_rows);
  } while (is_terminal_state(p_env,p_env->cell) || is_a_wall_here(p_env));
  // Return first observed state
  return env_observe_state(p_env);
}
Ejemplo n.º 4
0
void qr_code_generation ( char *input, char *output )
{
	int i;
	int version;
	int size;
	char *str_source_bin;
	char *data;
	char **blocks;
	char **pattern;
	int  **correction_blocks;

	str_source_bin = convert_to_utf8( input ); //convert string to utf8 ascii

	version = optimal_version( strlen( str_source_bin ) ); //optimal version

	str_source_bin = add_service_inf(str_source_bin, &version); //add service information into string

	blocks = create_blocks( str_source_bin, version ); //create blocks
	
	correction_blocks = create_correction_block( blocks, version ); //create correction blocks
	
	data = create_data ( blocks, correction_blocks, version ); //create data for qr code
	
	pattern = create_canvas_pattern ( data, version ); //create pattern for bmp
	
	create_bmp( pattern, output, version ); //create bmp

	//free str_source_bin
	free ( str_source_bin );

	//free blocks
	//free correction_blocks
	for ( i = 0; i < number_of_blocks[version]; i++ )
	{
			free( blocks[i] );
			free( correction_blocks[i] );
	}
	free( blocks );
	free( correction_blocks ); 

	//free data
	free( data );

	//free pattern
	size = ( ( ( version - 1 ) * 4 ) + 21 );
	size+=8; //white border
	for ( i = 0; i < size; i++ )
		free( pattern[i] );
	free( pattern );

}
Ejemplo n.º 5
0
void Ebu3264SubtitleFormat::WriteFile(const AssFile *src, wxString const& filename, wxString const& encoding) const
{
	// collect data from user
	EbuExportSettings export_settings = get_export_config(0);
	AssFile copy(*src);

	std::vector<EbuSubtitle> subs_list = convert_subtitles(copy, export_settings);
	std::vector<BlockTTI> tti = create_blocks(subs_list, export_settings);
	BlockGSI gsi = create_header(copy, export_settings);

	BlockTTI &block0 = tti.front();
	snprintf(gsi.tcf, 8, "%02u%02u%02u%02u", (unsigned int)block0.tci.h, (unsigned int)block0.tci.m, (unsigned int)block0.tci.s, (unsigned int)block0.tci.f);
	snprintf(gsi.tnb, 5, "%5u", (unsigned int)tti.size());
	snprintf(gsi.tns, 5, "%5u", (unsigned int)subs_list.size());

	// write file
	agi::io::Save f(from_wx(filename), true);
	f.Get().write((const char *)&gsi, sizeof(gsi));
	for (auto const& block : tti)
		f.Get().write((const char *)&block, sizeof(block));
}