strcat(name_f_reg_exist,".ids");
if ( (f_reg_exist = fopen(name_f_reg_exist,"r")) == NULL) return -1; /*ERROR*/
while ( !feof(f_reg_exist) ){
- fread(®,sizeof(reg),1,f_reg_exist);
+ fread(®,sizeof(int),1,f_reg_exist);
if ( reg == ID ){
fclose(f_reg_exist);
return 0;
if ( (f_block_reg = fopen(name_f_block_reg,"r")) == NULL) return -1; /*ERROR*/
while ( !feof(f_block_reg) ){
- if (fread(®,sizeof(reg),1,f_block_reg) != 1) continue;
+ if (fread(®,sizeof(BLOCK_REG_T),1,f_block_reg) != 1) continue;
if ( reg.id_reg == ID ){
fclose(f_block_reg);
return reg.block;
{
int ID_aux, fs, num_bloque, cant;
FILE *file;
- FILE *f_id;
FILE *f_block_reg;
FILE *f_block_free;
BLOCK_FREE_T reg;
BLOCK_REG_T reg_b;
char name_f[255];
char name_f_block_reg[255];
- char name_f_id[255];
char name_f_free[255];
char* bloque;
strcpy(name_f,emu->nombre);
strcpy(name_f_block_reg,emu->nombre);
strcat(name_f_block_reg,".idx");
-
- strcpy(name_f_id,emu->nombre);
- strcat(name_f_id,".ids");
strcpy(name_f_free,emu->nombre);
strcat(name_f_free,".fsc");
reg.free_space = emu->tam_bloque - tam;
/*lo guardo en el archivo al final "a+"*/
if ( (f_block_free = fopen(name_f_free,"a+"))==NULL ) return -1; /*ERROR*/
- fwrite(®,sizeof(reg),1,f_block_free);
+ fwrite(®,sizeof(BLOCK_FREE_T),1,f_block_free);
fclose(f_block_free);
} else {
/*cargo el bloque en "bloque"*/
/*busco el bloque que modifique*/
if ( (f_block_free = fopen(name_f_free,"r+")) == NULL) return -1; /*ERROR*/
while ( !feof(f_block_free) ){
- fread(®,sizeof(reg),1,f_block_free);
+ fread(®,sizeof(BLOCK_FREE_T),1,f_block_free);
if ( reg.block == num_bloque ){
reg.free_space -= tam;
- fseek(f_block_free,-sizeof(reg),SEEK_CUR);
- fwrite(®,sizeof(reg),1,f_block_free);
+ fseek(f_block_free,-sizeof(BLOCK_FREE_T),SEEK_CUR);
+ fwrite(®,sizeof(BLOCK_FREE_T),1,f_block_free);
break;
}
}
fclose(f_block_free);
}
- /*actualizo el archivo de id`s*/
- if ( (f_id = fopen(name_f_id,"a+"))==NULL ) return -1; /*ERROR*/
- fwrite(&ID_aux,sizeof(ID_aux),1,f_id);
+ /*actualizo el archivo de id`s
+ if ( (f_id = fopen(name_f_id,"a+"))==NULL ) return -1;
+ fwrite(&ID_aux,sizeof(int),1,f_id);
fclose(f_id);
-
+ */
/*actualizo el archivo de bloques y registros*/
if ( (f_block_reg = fopen(name_f_block_reg,"ab+"))==NULL ) return -1; /*ERROR*/
reg_b.block = reg.block;
reg_b.id_reg = ID_aux;
- fwrite(®_b,sizeof(reg_b),1,f_block_reg);
+ fwrite(®_b,sizeof(BLOCK_REG_T),1,f_block_reg);
fclose(f_block_reg);
free(bloque);
reg.block = -1;
*fs = emu->tam_bloque;
while( !feof(f_block_free) ){
- fread(®,sizeof(reg),1,f_block_free);
+ if (fread(®,sizeof(BLOCK_FREE_T),1,f_block_free) != 1) continue;
if ( reg.free_space >= tam )
break;
else {
if (ftell(f_reg_exist) > 0){
/* si el archivo no esta vacio es porque hay un nro disponible*/
- fseek(f_reg_exist, -sizeof(id),SEEK_END);
- fread(&id,sizeof(id),1,f_reg_exist);
+ fseek(f_reg_exist, -sizeof(int),SEEK_END);
+ fread(&id,sizeof(int),1,f_reg_exist);
/* FIXME: tengo que truncar el archivo*/
/* FIXME: tengo que truncar el archivo*/
/* FIXME: tengo que truncar el archivo*/
if ( (f_block_reg = fopen(name_f_block_reg,"r")) == NULL) return -1; /*ERROR*/
while ( !feof(f_block_reg) ){
/* Me aseguro de leer la cantidad de bytes correcta */
- if (fread(®,sizeof(reg),1,f_block_reg) != 1) continue;
+ if (fread(®,sizeof(BLOCK_REG_T),1,f_block_reg) != 1) continue;
if ( reg.id_reg >= max )
max = reg.id_reg;
}