X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/blobdiff_plain/cea6c333334aa778c0828c62821f4fafc099ea8c..7932b1f7bfc70a8e2d33416e2797b1e74144c21d:/tipo3/param_cte.c diff --git a/tipo3/param_cte.c b/tipo3/param_cte.c index 66be7e8..ab02873 100644 --- a/tipo3/param_cte.c +++ b/tipo3/param_cte.c @@ -323,11 +323,12 @@ int get_id(EMUFS *emu) /*borra un registro de un bloque y acomoda los registros que quedan*/ int borrar_registro(EMUFS *emu, int ID, int tam_reg) { - int num_bloque, ptr_elim, ptr_mov, ID_aux; + int num_bloque, ptr_elim, ptr_mov, ID_aux, cant, i; char *bloque; FILE *f_reg_exist, *f_block_reg, *f_block_free; BLOCK_REG_T reg_b; BLOCK_FREE_T reg_f; + BLOCK_REG_T buffer[10]; char name_f_reg_exist[255]; char name_f_block_reg[255]; char name_f_block_free[255]; @@ -365,7 +366,7 @@ int borrar_registro(EMUFS *emu, int ID, int tam_reg) ptr_elim = ptr_mov; ptr_mov += sizeof(int) + tam_reg; } - + /*grabo el bloque en el archivo*/ if ( grabar_bloque(emu, bloque, num_bloque) == -1 ){ printf("No se pudo grabar el bloque\n"); @@ -374,13 +375,14 @@ int borrar_registro(EMUFS *emu, int ID, int tam_reg) /*actualizo archivo .fsc*/ if ( (f_block_free = fopen(name_f_block_free,"r+")) == NULL ) return -1; + fread(®_f,sizeof(BLOCK_FREE_T),1,f_block_free); while ( !feof(f_block_free) ){ - fread(®_f,sizeof(BLOCK_FREE_T),1,f_block_free); if ( reg_f.block == num_bloque ){ - reg_f.free_space += tam_reg - sizeof(int); + reg_f.free_space += tam_reg + sizeof(int); fseek(f_block_free,-sizeof(BLOCK_FREE_T),SEEK_CUR); fwrite(®_f,sizeof(BLOCK_FREE_T),1,f_block_free); } + fread(®_f,sizeof(BLOCK_FREE_T),1,f_block_free); } fclose(f_block_free); @@ -389,11 +391,34 @@ int borrar_registro(EMUFS *emu, int ID, int tam_reg) fwrite(&ID, sizeof(int), 1, f_reg_exist); fclose(f_reg_exist); - + printf("pase %d\n",__LINE__); /*actualizo archivo .idx*/ + /*busco el registro que tengo que eliminar*/ + if ( (f_block_reg = fopen(name_f_block_reg,"r+")) == NULL ) return -1; + while ( !feof(f_block_reg) ){ + if ( fread(®_b,sizeof(BLOCK_REG_T),1,f_block_reg) != 1 ) continue; + if ( reg_b.id_reg == ID ) + break; + } + printf("registro borrado= %ld en bloque = %d\n",reg_b.id_reg,reg_b.block); + /*justifico en archivo a la izquieda*/ + while ( !feof(f_block_reg) ){ + cant = fread(&buffer,sizeof(BLOCK_REG_T),10,f_block_reg); + fseek(f_block_reg, -cant*sizeof(BLOCK_REG_T)-1, SEEK_CUR); + for (i=0; i