4 /* Defino las extenciones que usan cada tipo de archivo */
5 #define EXT_TIPO3_ID ".idx"
6 #define EXT_TIPO3_DATA ".dat"
7 #define EXT_TIPO3_DISP ".fsc"
8 #define EXT_TIPO3_IDS ".ids"
10 char *str_dup(const char *s)
13 if (s == NULL) return NULL;
14 tmp = (char *)malloc(sizeof(char)*(strlen(s)+1));
20 EMUFS *emufs_crear(const char *filename, char tipo, unsigned int tam_bloque, unsigned int tam_reg)
24 EMUFS *tmp = (EMUFS *)malloc(sizeof(EMUFS));
33 tmp->tam_bloque = tam_bloque;
34 tmp->leer_bloque = leer_bloque;
35 tmp->leer_registro = leer_registro;
36 tmp->grabar_registro = grabar_registro;
37 tmp->borrar_registro = NULL;
38 tmp->nombre = str_dup(filename);
40 strcpy(name, filename);
41 strcat(name, EXT_TIPO3_DATA);
42 fp = fopen(name, "w");
49 /* Guardo el Header */
50 fwrite(&tipo, sizeof(char), 1, fp);
51 fwrite(&tam_bloque, sizeof(unsigned int), 1, fp);
52 fwrite(&tam_reg, sizeof(unsigned int), 1, fp);
55 strcpy(name, filename);
56 strcat(name, EXT_TIPO3_ID);
57 fp = fopen(name, "w");
60 strcpy(name, filename);
61 strcat(name, EXT_TIPO3_DISP);
62 fp = fopen(name, "w");
65 strcpy(name, filename);
66 strcat(name, EXT_TIPO3_IDS);
67 fp = fopen(name, "w");
79 EMUFS *emufs_abrir(const char *filename)
86 strcpy(name, filename);
87 strcat(name, EXT_TIPO3_DATA);
88 fp = fopen(name, "r");
89 if (fp == NULL) return NULL;
90 fread(&tipo, sizeof(char), 1, fp);
91 if ((tipo < 0) || (tipo > 2)) {
96 tmp = (EMUFS *)malloc(sizeof(EMUFS));
97 if (tmp == NULL) return NULL;
106 fread(&tmp->tam_bloque, sizeof(int), 1, fp);
107 tmp->leer_bloque = leer_bloque;
108 tmp->leer_registro = leer_registro;
109 tmp->grabar_registro = grabar_registro;
110 tmp->borrar_registro = NULL;
111 tmp->nombre = str_dup(filename);
118 int emufs_destruir(EMUFS *e)
120 if (e == NULL) return 1;
126 int ver_archivo_FS(EMUFS *emu)
130 char name_f_block_free[255];
132 strcpy(name_f_block_free,emu->nombre);
133 strcat(name_f_block_free,".fsc");
135 if ( (f_block_free = fopen(name_f_block_free,"r"))==NULL ){
136 printf("no pude abrir el archivo %s\n",name_f_block_free);
139 fread(®,sizeof(reg),1,f_block_free);
140 while ( !feof(f_block_free) ){
141 printf(" Bloque = %d Espacio libre = %d\n",reg.block, reg.free_space);
142 fread(®,sizeof(reg),1,f_block_free);
145 fclose(f_block_free);
147 /* Imprimo la lista de bloques/registros */
148 strcpy(name_f_block_free,emu->nombre);
149 strcat(name_f_block_free,".idx");
152 f_block_free = fopen(name_f_block_free, "r");
153 fread(&r, sizeof(BLOCK_REG_T), 1, f_block_free);
154 while (!feof(f_block_free)) {
155 printf("ID %ld en bloque %d\n", r.id_reg, r.block);
156 fread(&r, sizeof(BLOCK_REG_T), 1, f_block_free);
158 fclose(f_block_free);