void	CSoundRender_TargetD::render			()
{
	fill_block		();
	fill_block		();

    R_CHK			(pBuffer->SetCurrentPosition	(0));
	HRESULT _hr		= pBuffer->Play(0,0,DSBPLAY_LOOPING);
	if (DSERR_BUFFERLOST==_hr)	{
		R_CHK(pBuffer->Restore());
		R_CHK(pBuffer->Play(0,0,DSBPLAY_LOOPING));
	}else{
		R_CHK		(_hr);
	}
    inherited::render();
}
void	CSoundRender_TargetA::update			()
{
	inherited::update();

	ALint			processed;
    // Get status
    A_CHK			(alGetSourcei(pSource, AL_BUFFERS_PROCESSED, &processed));

    if (processed > 0){
        while (processed){
			ALuint	BufferID;
            A_CHK	(alSourceUnqueueBuffers(pSource, 1, &BufferID));
            fill_block(BufferID);
            A_CHK	(alSourceQueueBuffers(pSource, 1, &BufferID));
            processed--;
        }
    }else{ 
    	// processed == 0
        // check play status -- if stopped then queue is not being filled fast enough
        ALint state;
	    A_CHK		(alGetSourcei(pSource, AL_SOURCE_STATE, &state));
        if (state != AL_PLAYING){
//			Log		("Queuing underrun detected.");
			A_CHK	(alSourcePlay(pSource));
        }
    }
}
void	CSoundRender_TargetA::render		()
{
	for (u32 buf_idx=0; buf_idx<sdef_target_count; buf_idx++)
		fill_block	(pBuffers[buf_idx]);

	A_CHK			(alSourceQueueBuffers	(pSource, sdef_target_count, pBuffers));	
	A_CHK			(alSourcePlay			(pSource));

    inherited::render();
}
void	CSoundRender_TargetA::rewind			()
{
	inherited::rewind();

	A_CHK			(alSourceStop(pSource));
	A_CHK			(alSourcei	(pSource, AL_BUFFER,   NULL));
	for (u32 buf_idx=0; buf_idx<sdef_target_count; buf_idx++)
		fill_block	(pBuffers[buf_idx]);
	A_CHK			(alSourceQueueBuffers	(pSource, sdef_target_count, pBuffers));	
	A_CHK			(alSourcePlay			(pSource));
}
void	CSoundRender_TargetD::update			()
{
	inherited::update();

	// Analyze if we really need more data to stream them ahead
	u32				cursor_write;
	R_CHK			(pBuffer->GetCurrentPosition(0,LPDWORD(&cursor_write)));
	u32				r_write		= calc_interval(pos_write);
	u32				r_cursor	= (calc_interval(cursor_write)+1)%sdef_target_count;
	if (r_write==r_cursor)	fill_block	();     
//	Msg				("write: 0x%8x",cursor_write);
}
Exemple #6
0
// Print fancy 2D view of memory
// Note, This is limited to memory_sizes of under 16MB
void vlad_reveal(void *alpha[26])
{
    vlad_stats();

    int i, j;
    vlink_t offset;
    char graph[STAT_HEIGHT][STAT_WIDTH][20];
    char free_sizes[26][32];
    char alloc_sizes[26][32];
    char label[3]; // letters for used memory, numbers for free memory
    int free_count, alloc_count, max_count;
    free_header_t * block;


    // initilise size lists
    for (i=0; i<26; i++) {
        free_sizes[i][0]= '\0';
        alloc_sizes[i][0]= '\0';
    }

    // Fill graph with free memory
    offset = 0;
    i = 1;
    free_count = 0;
    while (offset < memory_size){
        block = (free_header_t *)(memory + offset);
        if (block->magic == MAGIC_FREE) {
            snprintf(free_sizes[free_count++], 32, 
                "%d) %d bytes", i, block->size);
            snprintf(label, 3, "%d", i++);
            fill_block(graph, offset,label);
        }
        offset += block->size;
    }

    // Fill graph with allocated memory
    alloc_count = 0;
    for (i=0; i<26; i++) {
        if (alpha[i] != NULL) {
            offset = ((byte *) alpha[i] - (byte *) memory) - HEADER_SIZE;
            block = (free_header_t *)(memory + offset);
            snprintf(alloc_sizes[alloc_count++], 32, 
                "%c) %d bytes", 'a' + i, block->size);
            snprintf(label, 3, "%c", 'a' + i);
            fill_block(graph, offset,label);
        }
    }

    // Print all the memory!
    for (i=0; i<STAT_HEIGHT; i++) {
        for (j=0; j<STAT_WIDTH; j++) {
            printf("%s", graph[i][j]);
        }
        printf("\n");
    }

    //Print table of sizes
    max_count = (free_count > alloc_count)? free_count: alloc_count;
    printf(FG_FREE"%-32s"CL_RESET, "Free");
    if (alloc_count > 0){
        printf(FG_ALLOC"%s\n"CL_RESET, "Allocated");
    } else {
        printf("\n");
    }
    for (i=0; i<max_count;i++) {
        printf("%-32s%s\n", free_sizes[i], alloc_sizes[i]);
    }

}
Exemple #7
0
void fill_segment(const argon2_instance_t *instance,
                  argon2_position_t position)
{
    block *ref_block = NULL, *curr_block = NULL;
    uint64_t pseudo_rand, ref_index;
    uint32_t prev_offset, curr_offset;
    uint8_t i;
    __m128i state[64];
    int data_independent_addressing = (instance->type == Argon2_i);

    /* Pseudo-random values that determine the reference block position */
    uint64_t *pseudo_rands = NULL;

    pseudo_rands = (uint64_t *)malloc(/*sizeof(uint64_t) * 4*/32);

    if (data_independent_addressing) {
        generate_addresses(instance, &position, pseudo_rands);
    }

    i = 0;

    if ((0 == position.pass) && (0 == position.slice)) {
        i = 2; /* we have already generated the first two blocks */
    }

    /*printf("Position.lane = %d\nPosition.slice = %d\nStarting index : %d\n", position.lane, position.slice, starting_index);*/
    /* Offset of the current block */
    curr_offset = position.slice * 4 + i;

    if (0 == curr_offset % 16) {
        /* Last block in this lane */
        prev_offset = curr_offset + /*instance->lane_length - 1*/15;
    } else {
        /* Previous block */
        prev_offset = curr_offset - 1;
    }

    memcpy(state, ((instance->memory + prev_offset)->v), ARGON2_BLOCK_SIZE);

    for (; i < SEGMENT_LENGTH;
         ++i, ++curr_offset, ++prev_offset) {
        /*1.1 Rotating prev_offset if needed */
        if (curr_offset % LANE_LENGTH == 1) {
            prev_offset = curr_offset - 1;
        }

        /* 1.2 Computing the index of the reference block */
        /* 1.2.1 Taking pseudo-random value from the previous block */
        if (data_independent_addressing) {
            pseudo_rand = pseudo_rands[i];
        } else {
            pseudo_rand = instance->memory[prev_offset].v[0];
        }

        /* 1.2.2 Computing the lane of the reference block */

        /* 1.2.3 Computing the number of possible reference block within the
         * lane.
         */
        position.index = i;
        ref_index = index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF,1);

        /* 2 Creating a new block */
        ref_block = instance->memory + ref_index;
        curr_block = instance->memory + curr_offset;
        fill_block(state, (__m128i const *)ref_block->v, (__m128i *)curr_block->v);
    }

    free(pseudo_rands);
}
Exemple #8
0
int main(int argc, char* argv[]){
    uint32_t temp;
    int a,i,nb,npart,mf,first,pemplacement=0;
    char* name;
    disk_id* id;
    error e;
    block *block0;
    // block* block_navigation = malloc(sizeof(block));
    //block *block_file_table;
    TTTFS_File_Table_Entry* entry_root = malloc(sizeof(TTTFS_File_Table_Entry));
    
    if (argc < 5){
        fprintf(stderr, "Error : wrong number of arguments.\n");
        return -1;
    }
    
    name = malloc(sizeof(char));
    strcpy(name,"disk.tfs");
    nb = argc;
    
    // Si le nombre d'argument est pair, i.e le nom du disque est indiqué
    if (argc % 2 == 0) {
        strcpy(name,argv[argc-1]);
        nb--;
    }
    //recuperation du numero de la partition
    if (strcmp(argv[1],"-p") != 0){
        fprintf(stderr, "Error : wrong option mode \"-p\" .\n");
        return -1;
    }
    npart=atoi(argv[2]);
    //recuperation du nombre de file demandé
    if (strcmp(argv[3],"-mf") != 0){
        fprintf(stderr, "Error : wrong option mode \"-mf\".\n");
        return -1;
    }
    mf=atoi(argv[4]);
    
    //démarage du disque
    id = malloc(sizeof(disk_id));
    e = start_disk(name,id);
    if (e.val != 0){
        fprintf(stderr, "Error while reading disk.\n");
        return -1;
    }
    
    //recuperation du block 0
    block0 = malloc(sizeof(block));
    read_block(id,block0,0);
    
    //verification de l'existance de la partition
    memcpy(&temp,(block0->octets)+(sizeof(uint32_t)),sizeof(uint32_t));
    if ((a=uitoi(temp))< npart) {
        fprintf(stderr, "Non-existing partition number .\n");
        return -1;
    }
    
    //recuperation du decalage de la partition
    for (i=0; i<npart; i++) {
        memcpy(&temp,(block0->octets)+((2+i)*sizeof(uint32_t)),sizeof(uint32_t));
        pemplacement+=uitoi(temp);
    }
    pemplacement++;
    //printf("decalage pour part: %i \n",pemplacement);
    
    //mise à jour de l'entête de la partition
    memcpy(&temp,(block0->octets) + ((npart+2)*sizeof(uint32_t)),sizeof(uint32_t));
    a=uitoi(temp);
    //printf("a:%i\n",a);
    
    first = 2+(mf/FILE_TABLE_BLOCK_SIZE);
    if (a-first<0) {// file count trop grand
        fprintf(stderr, "Error file_count too big .\n");
        return -1;
    }
    
    else if(a-first<mf){//file count trop grand mais tiens dans la memoire
        fprintf(stderr, "file_count of %i too big for this partition .\n",mf);
        mf=a-first;
        printf("changing file_count to %i\n",mf);
    }
    
    //printf("cas n : \n\t mf/ftb:%i \n\t mf:%i \n\t first:%i \n\t a:%i\n",mf/FILE_TABLE_BLOCK_SIZE+1,mf,first,a);
    read_block(id,block0,pemplacement);
    //first = 2+(mf/FILE_TABLE_BLOCK_SIZE);
    a-=first;
    //printf("a : %i\n",a);
    
    temp = itoui(a);//nombre de blocks libres
    memcpy((block0->octets) + (3*sizeof(uint32_t)),&temp,sizeof(uint32_t));
    temp = itoui(first); // premier block libre
    memcpy((block0->octets) + (4*sizeof(uint32_t)),&temp,sizeof(uint32_t));
    // le nombre de fichiers supportables
    if (a<mf) {// verification du nombre de fichier max
        temp = itoui(a);
        
    }
    else{
        temp = itoui(mf);
        //printf("temp: %i\n",temp);
    }
    memcpy((block0->octets) + (5*sizeof(uint32_t)),&temp,sizeof(uint32_t));
    // le nombre de fichiers actuellement libres
    if (a<mf) {// verification du nombre de fichier max
        temp = itoui(a);
    }
    else{
        temp = itoui(mf);
    }
    memcpy((block0->octets) + (6*sizeof(uint32_t)),&temp,sizeof(uint32_t));
    temp = itoui(0); // le numero du premier fichier libre du volume
    memcpy((block0->octets) + (7*sizeof(uint32_t)),&temp,sizeof(uint32_t));
    // Next free file
    
    int j;
    block *partition_sub_block = malloc(sizeof(block));
    for (j = first; j < a; j++){
        if (j == a-1){
            a = itoui(j);
        }
        else{
            a = itoui(j+1);
        }
        read_block(id,partition_sub_block,j);
        memcpy((partition_sub_block->octets) + (TTTFS_VOLUME_BLOCK_SIZE-sizeof(uint32_t)),&a,sizeof(uint32_t));
        write_block(id,partition_sub_block,j);
    }
    write_block(id,block0,pemplacement);
    
    for (i = 0; i < (mf/FILE_TABLE_BLOCK_SIZE); i++){
        if (i == (mf/FILE_TABLE_BLOCK_SIZE)-1){
            a = itoui(i);
        }
        else{
            a = itoui(i+1);
        }
        // Pour chaque bloc...
        read_block(id,partition_sub_block,pemplacement+1+i);
        for (j = 0; j < FILE_TABLE_BLOCK_SIZE; j++){
            memcpy((partition_sub_block->octets) + ((j+1)*sizeof(uint32_t))-sizeof(uint32_t),&a,sizeof(uint32_t));
        }
        write_block(id,partition_sub_block,pemplacement+1+i);
    }
    
    
    // ---------------- Construction du répertoire racine
    
    // On récuppère le numéro de bloc qui sera occupé par la racine
    read_block(id,block0,pemplacement);
    memcpy(&temp,(block0->octets)+(4*sizeof(uint32_t)),sizeof(uint32_t));
    first = uitoi(temp);
    
    // Création de l'entrée
    //block_file_table = malloc(sizeof(block));
    //read_block(id,block_file_table,pemplacement+1);
    entry_root->size = TFS_DIRECTORIES_SIZE*2;
    entry_root->type = 0;
    entry_root->sub_type = 1;
    entry_root->tfs_direct[0] = first;
    for (i = 1; i < 10; i++){
        entry_root->tfs_direct[i] = 0;
    }
    entry_root->tfs_indirect1 = 0;
    entry_root->tfs_indirect2 = 0;
    
    // Remplissage
    if (fill_block(id,pemplacement).val != 0){
        fprintf(stderr, "Error while filling block.\n");
        return -1;
    }
    if (fill_entry(id,pemplacement,entry_root).val != 0){
        fprintf(stderr, "Error while writing on File Table.\n");
        return -1;
    }
    //write_block(id,block_file_table,pemplacement+1);
    char* buf_d = malloc(sizeof(uint32_t)+28);
    read_block(id,block0,first);
    temp = itoui(0);
    memcpy(buf_d,&temp,sizeof(uint32_t));
    strncpy(&buf_d[sizeof(uint32_t)],".\0",28);
    memcpy((block0->octets),buf_d,sizeof(uint32_t)+28);
    strncpy(&buf_d[sizeof(uint32_t)],"..\0",28);
    memcpy((block0->octets)+(sizeof(uint32_t)+28),buf_d,sizeof(uint32_t)+28);
    write_block(id,block0,first);
    
    sync_disk(id);
    printf("Partition %i formated !\n",npart);
    return 0;
}
void update(void* instance)
{
  InstancePtr inst = (InstancePtr) instance;
  MyInstancePtr my = inst->my;

  FrameBufferAttributes attribs;

  int xsize = inst->in_src->xsize;
  int ysize = inst->in_src->ysize;
  int bsizex = trim_int(inst->in_bsize->number, 1, xsize);
  int bsizey = trim_int(inst->in_bsizey->number, 0, ysize);

  int blocks_x;
  int blocks_y;
  int xrest;
  int yrest;

  int xi, yi;
  const uint_32* src;
  uint_32* dst;
  int offset;

  if (bsizey == 0)
    bsizey = min(ysize, bsizex);

  blocks_x = xsize / bsizex;
  blocks_y = ysize / bsizey;
  xrest = xsize - blocks_x*bsizex;
  yrest = ysize - blocks_y*bsizey;

  

  if (bsizex == 1 && bsizey == 1)
    return;

  attribs.xsize = xsize;
  attribs.ysize = ysize;
  framebuffer_changeAttributes(inst->out_r, &attribs);

  src = inst->in_src->framebuffer;
  dst = inst->out_r->framebuffer;
  offset = 0;
  for (yi = 0; yi < blocks_y; ++yi)
  {	  
	  offset = yi*bsizey*xsize;
	  for (xi = 0; xi < blocks_x; ++xi)
	  {
		  uint_32 col = average(src + offset, bsizex, bsizey, xsize);
		  fill_block(dst + offset, bsizex, bsizey, xsize, col);
		  offset += bsizex;
	  }
	  if (xrest > 0)
	  {
		  uint_32 col = average(src + offset, xrest, bsizey, xsize);
		  fill_block(dst + offset, xrest, bsizey, xsize, col);
	  }
  }
  if (yrest > 0)
  {
      offset = blocks_y*bsizey*xsize;
	  for (xi = 0; xi < blocks_x; ++xi)
	  {
		  uint_32 col = average(src + offset, bsizex, yrest, xsize);
		  fill_block(dst + offset, bsizex, yrest, xsize, col);
		  offset += bsizex;
	  }
	  if (xrest > 0)
	  {
		  uint_32 col = average(src + offset, xrest, yrest, xsize);
		  fill_block(dst + offset, xrest, yrest, xsize, col);
	  }
  }
}
Exemple #10
0
void demo_res (int Screen_Mode, int X_max, int Y_max)
{

char 	*Error1 = "Failure while calling SET_MODEX";
char	*Error2 = "Failure during READ_PIXEL test";

char	*Abort_Msg = "Demo aborted by User";

char	*Demo_Msg = " This is a MODE X demo ";
char	*Scrn_Msg = "Screen Resolution is     by    ";
char	*Cont_Msg = "Press <ANY KEY> to Continue";

char    *Line_Msg = "LINE TEST";
char	*Fill_Msg = "FILL TEST";
char	*Pixel_Msg = "PIXEL TEST";

char	Text[10];

int		x1, y1, x2, y2 = 0;
int		x, y, z = 0;
int		X_Center, gap = 0;


	if (set_modex (Screen_Mode) == 0)
	{
		error_out (Error1);
	}

	X_Center = X_max / 2;

	x1 = 10;
	y1 = 10;
	x2 = X_max - 1;
	y2 = Y_max - 1;

	for (z = 0; z <= 3; z++)
	{
		y = 31 - z -z;
		draw_line (x1+z, y1+z, x2-z, y1+z, y);
		draw_line (x1+z, y1+z, x1+z, y2-z, y);
		draw_line (x1+z, y2-z, x2-z, y2-z, y);
		draw_line (x2-z, y1+z, x2-z, y2-z, y);
	}

	for (x = 0; x < (X_max / 10); x++)
	{
		tgprintc (48 + ((x+1) % 10), x*10+1, 1, 9 + ((x/8) % 7) );
		draw_line (x*10+9, 0, x*10+9, 3, c_bWHITE);
	}

	for (y = 0; y < (Y_max / 10); y++)
	{
		tgprintc (48 + ((y+1) % 10), 1, y*10+1, 9 + ((y/10) % 7) );
		draw_line (0, y*10+9, 3, y*10+9, c_bWHITE);
	}

	for (x = 0; x <= 63; x++)
	{
		z = 15 + (x * 3 / 4);
		set_dac_register (64+x, z, z, z);
		set_dac_register (128+x, 0, z, z);

		draw_line (103-x, 60, 40+x, 123, 64+x);
		draw_line (40, 60+x, 103, 123-x, 128+x);

	}

	tprint_str (Line_Msg, 9, 37, 130, c_BLUE);

	y = 60;
	gap = 0;
	for (x = 0; x <= 9; x++)
	{
		fill_block (120, y, 120+x, y+gap, 64+x);
		fill_block (140 - (15-x), y, 150+x, y+gap, 230+x);
		fill_block (170 - (15-x), y, 170, y+gap, 128+x);
		y = y + gap + 2;
		gap++;
	}

	tprint_str (Fill_Msg, 9, 110, 46, c_GREEN);

	for (x = 190; x <= 250; x+=2)
	{
		for (y = 60; y <= 122; y+=2)
		{
			z = (x+x+y+y) & 0xff;
			set_point (x, y, z);
		}
	}

	tprint_str (Pixel_Msg, 10, 182, 130, c_RED);

	for (x = 190; x <= 250; x+=2)
	{
		for (y = 60; y <= 122; y+=2)
		{
			z = (x+x+y+y) & 0xff;
			if (read_point(x, y) != z)
			{
				error_out (Error2);
			}
		}
	}

	print_str (Demo_Msg, 23, X_Center - 92, 20, c_bRED, c_BLUE);

	x = X_Center - 124;
	print_str (Scrn_Msg, 28, x, 30, c_bGREEN, c_BLACK);

	sprintf (Text, "%3d", X_max);
	print_str (Text, 3, x+168, 30, c_bPURPLE, c_BLACK);

	sprintf (Text, "%3d", Y_max);
	print_str (Text, 3, x + 224, 30, c_bWHITE, c_BLACK);

	for (x = 0; x <= 15; x++)
	{
		set_dac_register (230+x, 63-x*4, 0, 15+x*3);
		draw_line (30+x, Y_max-6-x, X_max-20-x, Y_max-6-x, 230+x);
	}

	tprint_str (Cont_Msg, 27, X_Center - 103, Y_max-18, c_YELLOW);

	if (get_key () == Ky_ESC)
	{
		error_out (Abort_Msg);
	}

	return ;

}
Exemple #11
0
/**
 * \brief mjpeg encode an image
 *
 * This routine will take a 3-plane YUV422 image and encoded it with MJPEG
 * base line format, as suitable as input for the Zoran hardare MJPEG chips.
 *
 * It requires that the \a j parameter points the structure set up by the
 * jpeg_enc_init() routine.
 *
 * \param j pointer to jpeg_enc_t structure as created by jpeg_enc_init()
 * \param y_data pointer to Y component plane, packed one byte/pixel
 * \param u_data pointer to U component plane, packed one byte per every
 *		 other pixel
 * \param v_data pointer to V component plane, packed one byte per every
 *		 other pixel
 * \param bufr pointer to the buffer where the mjpeg encoded code is stored
 *
 * \returns the number of bytes stored into \a bufr
 *
 * If \a j->s->mjpeg_write_tables is set, it will also emit the mjpeg tables,
 * otherwise it will just emit the data. The \a j->s->mjpeg_write_tables
 * variable will be reset to 0 by the routine.
 */
static int jpeg_enc_frame(jpeg_enc_t *j, uint8_t *y_data,
		   uint8_t *u_data, uint8_t *v_data, uint8_t *bufr) {
	int mb_x, mb_y, overflow;
	/* initialize the buffer */

	init_put_bits(&j->s->pb, bufr, 1024*256);

	// Emit the mjpeg header blocks
	ff_mjpeg_encode_picture_header(j->s);

	j->s->header_bits = put_bits_count(&j->s->pb);

	j->s->last_dc[0] = 128;
	j->s->last_dc[1] = 128;
	j->s->last_dc[2] = 128;

	for (mb_y = 0; mb_y < j->s->mb_height; mb_y++) {
		for (mb_x = 0; mb_x < j->s->mb_width; mb_x++) {
			/*
			 * Fill one DCT block (8x8 pixels) from
			 * 2 Y macroblocks and one U and one V
			 */
			fill_block(j, mb_x, mb_y, y_data, u_data, v_data);
			emms_c(); /* is this really needed? */

			j->s->block_last_index[0] =
				j->s->dct_quantize(j->s, j->s->block[0],
						0, 8, &overflow);
			if (overflow) clip_coeffs(j->s, j->s->block[0],
					j->s->block_last_index[0]);
			j->s->block_last_index[1] =
				j->s->dct_quantize(j->s, j->s->block[1],
						1, 8, &overflow);
			if (overflow) clip_coeffs(j->s, j->s->block[1],
					j->s->block_last_index[1]);

			if (!j->bw) {
				j->s->block_last_index[4] =
					j->s->dct_quantize(j->s, j->s->block[2],
							4, 8, &overflow);
				if (overflow) clip_coeffs(j->s, j->s->block[2],
						j->s->block_last_index[2]);
				j->s->block_last_index[5] =
					j->s->dct_quantize(j->s, j->s->block[3],
							5, 8, &overflow);
				if (overflow) clip_coeffs(j->s, j->s->block[3],
						j->s->block_last_index[3]);
			}
			zr_mjpeg_encode_mb(j);
		}
	}
	emms_c();
	ff_mjpeg_encode_picture_trailer(j->s);
	flush_put_bits(&j->s->pb);

	//FIXME
	//if (j->s->mjpeg_write_tables == 1)
	//	j->s->mjpeg_write_tables = 0;

	return put_bits_ptr(&(j->s->pb)) - j->s->pb.buf;
}
Exemple #12
0
/**
 *\fn main(int argc, char *argv[]){
 *\brief on initialise une partition, c'est a dire on remplie son premier block avec toutes les informations nécessaires, puis on construit le file table, avec le chainage des fichiers libres, puis on construit le dossier racine(on ajoute aussi son entrée dans la table des fichiers), et enfin on initialise le chainage des blocks libres.
 **/
int main(int argc, char *argv[]){
  int i; // i pour les for
  if(argc==6){
    if(strcmp(argv[1], "-p")==0){
      if(strcmp(argv[3], "-mf")==0){
	disk_id *id=malloc(sizeof(disk_id));
	error err = start_disk(argv[argc-1], id);
	if(err.errnb==0){
	  int partition =atoi(argv[2]); //la première partition à l'id 0
	  if(0<=partition && partition<=id->nbPart){
	    int file_count=atoi(argv[4]);
	    int taille=id->tabPart[partition].taille;
	    int taille_descripteur=((file_count-1)/16)+1;
	    if(0<file_count && taille>(1+taille_descripteur+file_count)){ //on vérifie qu'il y a bien assez de blocs dans la partition pour y mettre file_count fichiers.
	      //tout les tests sont faits, on commence a initialiser le premier bloc de la partition.
	      block b;
	      int l;
	      for(l=0;l<1024;l++){
		b.buff[l]='\0';
	      }	     	     
	      fill_block(&b, MAGIC_NUMBER, 0);
	      fill_block(&b, SIZEBLOCK, 4);
	      fill_block(&b, taille, 8);
	      fill_block(&b,taille-2-taille_descripteur , 12);
	      fill_block(&b, taille_descripteur+2, 16);
	      fill_block(&b, file_count, 20);
	      fill_block(&b, file_count-1, 24);
	      fill_block(&b,1, 28); //Il y a un fichier 0, le dossier racine.
	      
	      //trouver l'indice du premier block de la partition.
	      uint32_t id_first=1;
	      for(i=0;i<partition; i++){
		id_first+=id->tabPart[i].taille;
	      }
	      write_block(*id, b,int_to_little(id_first)); 
	 	      
	      //initialisation file table
	      block file_table;
	      int k;
	      for(k=0;k<1024;k++){
		file_table.buff[k]='\0';
	      }
	      printf("1 %d \n", taille_descripteur);
	      printf("2 %d \n", id_first);
	      for(i=1; i<=taille_descripteur; i++){
		if(i==1){
		  fill_block(&file_table, 64, 0);
		  fill_block(&file_table, 1, 4);
		  fill_block(&file_table, 0, 8);
		  fill_block(&file_table, taille_descripteur+1, 12);
		}else{
		  fill_block(&file_table, 16*(i-1)+1, 60);
		}
		int j;
		for(j=1; j<=15; j++){
		  if((16*(i-1)+j)<file_count){
		    fill_block(&file_table, (i-1)*16+j+1, j*64+60);
		  }else{
		    if(16*(i-1)+j==file_count){
		       fill_block(&file_table, (i-1)*16+j, j*64+60);
		    }

		  }
		}
		write_physical_block(*id, file_table,i+id_first);
		for(k=0;k<1024;k++){
		  file_table.buff[k]='\0';
		}
	      }
	      //initialisation du dossier racine
	      block racine;
	      for(k=0;k<1024;k++){
		racine.buff[k]='\0';
	      }
	      fill_block(&racine,0,0);
	      racine.buff[4]='.';
	      racine.buff[5]='0';
	      fill_block(&racine,0,32);
	      racine.buff[36]='.';
	      racine.buff[37]='.';
	      racine.buff[38]='0';
	      write_block(*id, racine,int_to_little(id_first+taille_descripteur+1));

	      //initialisation des blocs restants (chainage)
	      block reste;
	      for(i= taille_descripteur+2; i<taille;i++){
		int k;
                for(k=0;k<1024;k++){
                  reste.buff[k]='\0';
                }
		if(i!=(taille-1)){
		  fill_block(&reste,i+1, 1020);
		} else{
		  fill_block(&reste,i, 1020);
		}
		write_block(*id, reste,int_to_little(id_first+i));
		fill_block(&reste,0, 1020);
	      }
	      
 	    }else{
	      printf("tfs format : wrong arguments, too much files : %d \n", file_count);
	    }
	  }else{
	    printf("tfs format : wrong arguments, no partition %d \n", partition);
	  }
	}
	stop_disk(*id);
      }else{
	printf("tfs format : wrong arguments, miss -mf \n");
      }
    }else{
      printf("tfs format : wrong arguments, miss -p \n");
    }
  }else{
    printf("tfs format : wrong arguments number %d \n", (argc-1));

  }
  return 0;
}