X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/blobdiff_plain/1b02a88830b3f4d2bc0e1518cd4c80ac276f7089..3a8f53e24ee5a692394590f6b9d4f135f6ca9d44:/tipo3/param_cte.c diff --git a/tipo3/param_cte.c b/tipo3/param_cte.c index a32db33..5ef131f 100644 --- a/tipo3/param_cte.c +++ b/tipo3/param_cte.c @@ -61,7 +61,7 @@ int existe_registro(EMUFS *emu, int ID) 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; @@ -84,7 +84,7 @@ int buscar_registro(EMUFS *emu, int ID) 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; @@ -119,14 +119,12 @@ int grabar_registro(EMUFS *emu, void *ptr, unsigned long tam) { 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); @@ -134,9 +132,6 @@ int grabar_registro(EMUFS *emu, void *ptr, unsigned long tam) 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"); @@ -174,7 +169,7 @@ int grabar_registro(EMUFS *emu, void *ptr, unsigned long tam) 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"*/ @@ -198,27 +193,27 @@ int grabar_registro(EMUFS *emu, void *ptr, unsigned long tam) /*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); @@ -263,7 +258,7 @@ int buscar_lugar(EMUFS *emu, unsigned long tam, int *fs) 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 { @@ -298,8 +293,8 @@ int get_id(EMUFS *emu) 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*/ @@ -312,7 +307,7 @@ int get_id(EMUFS *emu) 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; }