From 558540cc250c19c9617a3f3f12a0f5da38c9c84a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicol=C3=A1s=20Dimov?= Date: Sun, 11 Apr 2004 18:19:18 +0000 Subject: [PATCH] dos funciones estadisticas --- emufs/fsc.c | 20 ++++++++++++++++++++ emufs/fsc.h | 2 ++ emufs/idx.c | 14 ++++++++++++++ emufs/idx.h | 3 +++ emufs/tipo3_main.c | 11 ++++++++--- 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/emufs/fsc.c b/emufs/fsc.c index 43dc627..0b9449b 100644 --- a/emufs/fsc.c +++ b/emufs/fsc.c @@ -325,3 +325,23 @@ EMUFS_FREE emufs_fsc_get_fs(EMUFS *emu, EMUFS_BLOCK_ID n_marker) fclose(f_fsc); return reg.n_freespace; } + +EMUFS_FREE emufs_fsc_get_total_fs(EMUFS *emu) +{ + FILE *f_fsc; + EMUFS_FSC reg; + char name_f_fsc[255]; + EMUFS_FREE total; + + strcpy(name_f_fsc,emu->nombre); + strcat(name_f_fsc, EMUFS_FSC_EXT); + + if ( (f_fsc = fopen(name_f_fsc,"r"))==NULL ) return -1; + total = 0; + while ( !feof(f_fsc) ){ + if ( fread(®, sizeof(EMUFS_FSC), 1, f_fsc) != 1) continue; + total += reg.n_freespace; + } + fclose(f_fsc); + return total; +} diff --git a/emufs/fsc.h b/emufs/fsc.h index 657d0f1..230876c 100644 --- a/emufs/fsc.h +++ b/emufs/fsc.h @@ -55,5 +55,7 @@ int emufs_fsc_actualizar_gap(EMUFS *, EMUFS_OFFSET, EMUFS_FREE); int emufs_fsc_actualizar(EMUFS *, EMUFS_BLOCK_ID, EMUFS_FREE); EMUFS_BLOCK_ID emufs_fsc_buscar_lugar(EMUFS *, EMUFS_FREE, EMUFS_FREE *); EMUFS_FREE emufs_fsc_get_fs(EMUFS *, EMUFS_BLOCK_ID); +/*Devuelve el total de espacio libre que queda en el .dat*/ +EMUFS_FREE emufs_fsc_get_total_fs(EMUFS *); #endif /* _EMUFS_FSC_H */ diff --git a/emufs/idx.c b/emufs/idx.c index f5b1562..a46c46b 100644 --- a/emufs/idx.c +++ b/emufs/idx.c @@ -262,3 +262,17 @@ EMUFS_REG_ID emufs_idx_get_id_at(EMUFS *emu, long pos) return id.id_reg; } +int emufs_idx_get_cant_reg(EMUFS* emu) +{ + FILE *fp; + char name_f_idx[255]; + long cant; + strcpy(name_f_idx,emu->nombre); + strcat(name_f_idx, EMUFS_IDX_EXT); + + if ( (fp = fopen(name_f_idx, "r")) == NULL ) return -1;/*EMUFS_NOT_FOUND*/; + fseek(fp, 0, SEEK_END); + cant = ftell(fp)/sizeof(EMUFS_IDX); + fclose(fp); + return cant; +} diff --git a/emufs/idx.h b/emufs/idx.h index 605bf1b..4dfeda2 100644 --- a/emufs/idx.h +++ b/emufs/idx.h @@ -67,4 +67,7 @@ EMUFS_REG_ID emufs_idx_get_id_at(EMUFS *, long pos); EMUFS_REG_ID emufs_idx_get_new_id(EMUFS*, int*); +/*me informa la cantidad de registros existentes en .dat*/ +int emufs_idx_get_cant_reg(EMUFS*); + #endif /* _EMUFS_IDX_H */ diff --git a/emufs/tipo3_main.c b/emufs/tipo3_main.c index ab0e060..8aaf748 100644 --- a/emufs/tipo3_main.c +++ b/emufs/tipo3_main.c @@ -35,6 +35,8 @@ #include #include #include "emufs.h" +#include "idx.h" +#include "fsc.h" int main(int argc, char *argv[]) @@ -91,18 +93,21 @@ int main(int argc, char *argv[]) if ( fp->borrar_registro(fp, n3) == -1) printf("la cague %d\n",n3); if ( fp->borrar_registro(fp, n4) == -1) printf("la cague %d\n",n4); if ( fp->borrar_registro(fp, n5) == -1) printf("la cague %d\n",n5); - if ( fp->borrar_registro(fp, n6) == -1) printf("la cague %d\n",n6); +/* if ( fp->borrar_registro(fp, n6) == -1) printf("la cague %d\n",n6); if ( fp->borrar_registro(fp, n7) == -1) printf("la cague %d\n",n7); if ( fp->borrar_registro(fp, n8) == -1) printf("la cague %d\n",n8); + */ + b_ptr = fp->leer_registro(fp, n7, ®_size, &err); - b_ptr = fp->leer_registro(fp, n8, ®_size, &err); - printf("Recuperado : %s\n", b_ptr); free(b_ptr); ver_archivo_FS(fp); + printf("la cantidad de registros eeeeesssss: %d\n", emufs_idx_get_cant_reg(fp)); + printf("la cantidad de espacio libre es: %d\n", emufs_fsc_get_total_fs(fp)); + emufs_destruir(fp); return 0; -- 2.43.0