From c17ce9e5c76c4de8f575b23c68146bf9076e6bb5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicol=C3=A1s=20Dimov?= Date: Mon, 5 Apr 2004 21:55:35 +0000 Subject: [PATCH] locura total, no cambie nada y anda --- tipo3/emufs.c | 2 +- tipo3/param_cte.c | 35 +++++++++++++++-------------------- tipo3/param_cte.h | 2 +- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/tipo3/emufs.c b/tipo3/emufs.c index 49cb4b4..68ca044 100644 --- a/tipo3/emufs.c +++ b/tipo3/emufs.c @@ -151,7 +151,7 @@ int ver_archivo_FS(EMUFS *emu) f_block_free = fopen(name_f_block_free, "r"); fread(&r, sizeof(BLOCK_REG_T), 1, f_block_free); while (!feof(f_block_free)) { - printf("ID %d en bloque %d\n", r.id_reg, r.block); + printf("ID %ld en bloque %d\n", r.id_reg, r.block); fread(&r, sizeof(BLOCK_REG_T), 1, f_block_free); } fclose(f_block_free); diff --git a/tipo3/param_cte.c b/tipo3/param_cte.c index a32db33..b5787b6 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); + fread(®,sizeof(BLOCK_FREE_T),1,f_block_free); 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; } diff --git a/tipo3/param_cte.h b/tipo3/param_cte.h index bb17c06..de2e423 100644 --- a/tipo3/param_cte.h +++ b/tipo3/param_cte.h @@ -12,7 +12,7 @@ typedef struct block_free_t{ typedef struct block_reg_t{ int block; - int id_reg; + long int id_reg; }BLOCK_REG_T; int leer_registro(EMUFS *emu, int ID, void *, unsigned long tam); -- 2.43.0