X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/blobdiff_plain/8a6f628c163936c6f0852c398694f2d5fc946c37..885b60b3ea2aed49543ea87490ff971a68a5c2f1:/tipo3/emufs.c diff --git a/tipo3/emufs.c b/tipo3/emufs.c index b559489..4d74097 100644 --- a/tipo3/emufs.c +++ b/tipo3/emufs.c @@ -1,16 +1,17 @@ - #include "emufs.h" #include "param_cte.h" /* Defino las extenciones que usan cada tipo de archivo */ -#define EXT_TIPO3_ID ".id3" +#define EXT_TIPO3_ID ".idx" #define EXT_TIPO3_DATA ".dat" #define EXT_TIPO3_DISP ".fsc" +#define EXT_TIPO3_IDS ".ids" char *str_dup(const char *s) { + char *tmp; if (s == NULL) return NULL; - char *tmp = (char *)malloc(sizeof(char)*(strlen(s)+1)); + tmp = (char *)malloc(sizeof(char)*(strlen(s)+1)); strcpy(tmp, s); return tmp; } @@ -50,6 +51,22 @@ EMUFS *emufs_crear(const char *filename, char tipo, unsigned int tam_bloque, uns fwrite(&tam_bloque, sizeof(unsigned int), 1, fp); fwrite(&tam_reg, sizeof(unsigned int), 1, fp); fclose(fp); + + strcpy(name, filename); + strcat(name, EXT_TIPO3_ID); + fp = fopen(name, "w"); + fclose(fp); + + strcpy(name, filename); + strcat(name, EXT_TIPO3_DISP); + fp = fopen(name, "w"); + fclose(fp); + + strcpy(name, filename); + strcat(name, EXT_TIPO3_IDS); + fp = fopen(name, "w"); + fclose(fp); + break; default: free(tmp); @@ -59,6 +76,44 @@ EMUFS *emufs_crear(const char *filename, char tipo, unsigned int tam_bloque, uns return tmp; } +EMUFS *emufs_abrir(const char *filename) +{ + EMUFS *tmp; + char name[255]; + char tipo; + FILE *fp; + + strcpy(name, filename); + strcat(name, EXT_TIPO3_DATA); + fp = fopen(name, "r"); + if (fp == NULL) return NULL; + fread(&tipo, sizeof(char), 1, fp); + if ((tipo < 0) || (tipo > 2)) { + fclose(fp); + return NULL; + } + + tmp = (EMUFS *)malloc(sizeof(EMUFS)); + if (tmp == NULL) return NULL; + + switch (tipo) { + case T1: + break; + case T2: + break; + case T3: + tmp->tipo = tipo; + fread(&tmp->tam_bloque, sizeof(int), 1, fp); + tmp->leer_bloque = leer_bloque; + tmp->leer_registro = leer_registro; + tmp->grabar_registro = grabar_registro; + tmp->borrar_registro = NULL; + tmp->nombre = str_dup(filename); + } + + fclose(fp); + return tmp; +} int emufs_destruir(EMUFS *e) { @@ -68,3 +123,41 @@ int emufs_destruir(EMUFS *e) return 0; } +int ver_archivo_FS(EMUFS *emu) +{ + FILE *f_block_free; + BLOCK_FREE_T reg; + char name_f_block_free[255]; + + strcpy(name_f_block_free,emu->nombre); + strcat(name_f_block_free,".fsc"); + + if ( (f_block_free = fopen(name_f_block_free,"r"))==NULL ){ + printf("no pude abrir el archivo %s\n",name_f_block_free); + return -1; + } + fread(®,sizeof(reg),1,f_block_free); + while ( !feof(f_block_free) ){ + printf(" Bloque = %d Espacio libre = %d\n",reg.block, reg.free_space); + fread(®,sizeof(reg),1,f_block_free); + } + + fclose(f_block_free); + + /* Imprimo la lista de bloques/registros */ + strcpy(name_f_block_free,emu->nombre); + strcat(name_f_block_free,".idx"); + { + BLOCK_REG_T r; + 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 %ld en bloque %d\n", r.id_reg, r.block); + fread(&r, sizeof(BLOCK_REG_T), 1, f_block_free); + } + fclose(f_block_free); + } + + + return 0; +}