X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/blobdiff_plain/30325d1797a0a3ecaf622c261d07366801040c88..03906f9085993640c8cccdd07574d9b9c71209a0:/tipo3/emufs.c diff --git a/tipo3/emufs.c b/tipo3/emufs.c index a19ded7..a06ad13 100644 --- a/tipo3/emufs.c +++ b/tipo3/emufs.c @@ -1,8 +1,26 @@ #include "emufs.h" +#include "param_cte.h" -EMUFS *emufs_crear(const char *filename, int tipo) +/* Defino las extenciones que usan cada tipo de archivo */ +#define EXT_TIPO3_ID ".id3" +#define EXT_TIPO3_DATA ".dat" +#define EXT_TIPO3_DISP ".fsc" +#define EXT_TIPO3_IDS ".idc" + +char *str_dup(const char *s) +{ + if (s == NULL) return NULL; + char *tmp = (char *)malloc(sizeof(char)*(strlen(s)+1)); + strcpy(tmp, s); + return tmp; +} + + +EMUFS *emufs_crear(const char *filename, char tipo, unsigned int tam_bloque, unsigned int tam_reg) { + char name[255]; + FILE *fp; EMUFS *tmp = (EMUFS *)malloc(sizeof(EMUFS)); switch (tipo) { @@ -11,6 +29,43 @@ EMUFS *emufs_crear(const char *filename, int tipo) case T2: break; case T3: + tmp->tipo = T3; + tmp->tam_bloque = tam_bloque; + tmp->leer_bloque = leer_bloque; + tmp->leer_registro = leer_registro; + tmp->grabar_registro = grabar_registro; + tmp->borrar_registro = NULL; + tmp->nombre = str_dup(filename); + + strcpy(name, filename); + strcat(name, EXT_TIPO3_DATA); + fp = fopen(name, "w"); + if (fp == NULL) { + /* ERROR */ + free(tmp->nombre); + free(tmp); + return NULL; + } + /* Guardo el Header */ + fwrite(&tipo, sizeof(char), 1, fp); + 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); @@ -21,3 +76,11 @@ EMUFS *emufs_crear(const char *filename, int tipo) } +int emufs_destruir(EMUFS *e) +{ + if (e == NULL) return 1; + free(e->nombre); + free(e); + return 0; +} +