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)
12 if (s == NULL) return NULL;
13 char *tmp = (char *)malloc(sizeof(char)*(strlen(s)+1));
19 EMUFS *emufs_crear(const char *filename, char tipo, unsigned int tam_bloque, unsigned int tam_reg)
23 EMUFS *tmp = (EMUFS *)malloc(sizeof(EMUFS));
32 tmp->tam_bloque = tam_bloque;
33 tmp->leer_bloque = leer_bloque;
34 tmp->leer_registro = leer_registro;
35 tmp->grabar_registro = grabar_registro;
36 tmp->borrar_registro = NULL;
37 tmp->nombre = str_dup(filename);
39 strcpy(name, filename);
40 strcat(name, EXT_TIPO3_DATA);
41 fp = fopen(name, "w");
48 /* Guardo el Header */
49 fwrite(&tipo, sizeof(char), 1, fp);
50 fwrite(&tam_bloque, sizeof(unsigned int), 1, fp);
51 fwrite(&tam_reg, sizeof(unsigned int), 1, fp);
54 strcpy(name, filename);
55 strcat(name, EXT_TIPO3_ID);
56 fp = fopen(name, "w");
59 strcpy(name, filename);
60 strcat(name, EXT_TIPO3_DISP);
61 fp = fopen(name, "w");
64 strcpy(name, filename);
65 strcat(name, EXT_TIPO3_IDS);
66 fp = fopen(name, "w");
78 EMUFS *emufs_abrir(const char *filename)
85 strcpy(name, filename);
86 strcat(name, EXT_TIPO3_DATA);
87 fp = fopen(name, "r");
88 if (fp == NULL) return NULL;
89 fread(&tipo, sizeof(char), 1, fp);
90 if ((tipo < 0) || (tipo > 2)) {
95 tmp = (EMUFS *)malloc(sizeof(EMUFS));
96 if (tmp == NULL) return NULL;
105 fread(&tmp->tam_bloque, sizeof(int), 1, fp);
106 tmp->leer_bloque = leer_bloque;
107 tmp->leer_registro = leer_registro;
108 tmp->grabar_registro = grabar_registro;
109 tmp->borrar_registro = NULL;
110 tmp->nombre = str_dup(filename);
117 int emufs_destruir(EMUFS *e)
119 if (e == NULL) return 1;
125 int ver_archivo_FS(EMUFS *emu)
129 char name_f_block_free[255];
131 strcpy(name_f_block_free,emu->nombre);
132 strcat(name_f_block_free,".fsc");
134 if ( (f_block_free = fopen(name_f_block_free,"r"))==NULL ){
135 printf("no pude abrir el archivo %s\n",name_f_block_free);
138 fread(®,sizeof(reg),1,f_block_free);
139 while ( !feof(f_block_free) ){
140 printf(" Bloque = %d Espacio libre = %d\n",reg.block, reg.free_space);
141 fread(®,sizeof(reg),1,f_block_free);
144 fclose(f_block_free);
146 /* Imprimo la lista de bloques/registros */
147 strcpy(name_f_block_free,emu->nombre);
148 strcat(name_f_block_free,".fsc");
151 f_block_free = fopen(name_f_block_free, "r");
152 fread(&r, sizeof(BLOCK_REG_T), 1, f_block_free);
153 while (!feof(f_block_free)) {
154 printf("ID %ld en bloque %d\n", r.id_reg, r.block);
155 fread(&r, sizeof(BLOCK_REG_T), 1, f_block_free);
157 fclose(f_block_free);