5 /* Defino las extenciones que usan cada tipo de archivo */
6 #define EXT_TIPO3_ID ".id3"
7 #define EXT_TIPO3_DATA ".dat"
8 #define EXT_TIPO3_DISP ".fsc"
9 #define EXT_TIPO3_IDS ".idc"
10 #define EXT_TIPO3_EXTRA ".ids"
12 char *str_dup(const char *s)
14 if (s == NULL) return NULL;
15 char *tmp = (char *)malloc(sizeof(char)*(strlen(s)+1));
21 EMUFS *emufs_crear(const char *filename, char tipo, unsigned int tam_bloque, unsigned int tam_reg)
25 EMUFS *tmp = (EMUFS *)malloc(sizeof(EMUFS));
34 tmp->tam_bloque = tam_bloque;
35 tmp->leer_bloque = leer_bloque;
36 tmp->leer_registro = leer_registro;
37 tmp->grabar_registro = grabar_registro;
38 tmp->borrar_registro = NULL;
39 tmp->nombre = str_dup(filename);
41 strcpy(name, filename);
42 strcat(name, EXT_TIPO3_DATA);
43 fp = fopen(name, "w");
50 /* Guardo el Header */
51 fwrite(&tipo, sizeof(char), 1, fp);
52 fwrite(&tam_bloque, sizeof(unsigned int), 1, fp);
53 fwrite(&tam_reg, sizeof(unsigned int), 1, fp);
56 strcpy(name, filename);
57 strcat(name, EXT_TIPO3_ID);
58 fp = fopen(name, "w");
61 strcpy(name, filename);
62 strcat(name, EXT_TIPO3_DISP);
63 fp = fopen(name, "w");
66 strcpy(name, filename);
67 strcat(name, EXT_TIPO3_IDS);
68 fp = fopen(name, "w");
71 strcpy(name, filename);
72 strcat(name, EXT_TIPO3_EXTRA);
73 fp = fopen(name, "w");
84 EMUFS *emufs_abrir(const char *filename)
91 strcpy(name, filename);
92 strcat(name, EXT_TIPO3_DATA);
93 fp = fopen(name, "r");
94 if (fp == NULL) return NULL;
95 fread(&tipo, sizeof(char), 1, fp);
96 if ((tipo < 0) || (tipo > 2)) {
101 tmp = (EMUFS *)malloc(sizeof(EMUFS));
102 if (tmp == NULL) return NULL;
111 fread(&tmp->tam_bloque, sizeof(int), 1, fp);
112 tmp->leer_bloque = leer_bloque;
113 tmp->leer_registro = leer_registro;
114 tmp->grabar_registro = grabar_registro;
115 tmp->borrar_registro = NULL;
116 tmp->nombre = str_dup(filename);
123 int emufs_destruir(EMUFS *e)
125 if (e == NULL) return 1;
131 int ver_archivo_FS(EMUFS *emu)
135 char name_f_block_free[255];
137 strcpy(name_f_block_free,emu->nombre);
138 strcat(name_f_block_free,".fsc");
140 if ( (f_block_free = fopen(name_f_block_free,"r"))==NULL ){
141 printf("no pude abrir el archivo %s\n",name_f_block_free);
144 fread(®,sizeof(reg),1,f_block_free);
145 while ( !feof(f_block_free) ){
146 printf(" Bloque = %d Espacio libre = %d\n",reg.block, reg.free_space);
147 fread(®,sizeof(reg),1,f_block_free);
150 fclose(f_block_free);
152 /* Imprimo la lista de bloques/registros */
153 strcpy(name_f_block_free,emu->nombre);
154 strcat(name_f_block_free,".id3");
157 f_block_free = fopen(name_f_block_free, "r");
158 fread(&r, sizeof(BLOCK_REG_T), 1, f_block_free);
159 while (!feof(f_block_free)) {
160 printf("ID %d en bloque %d\n", r.id_reg, r.block);
161 fread(&r, sizeof(BLOCK_REG_T), 1, f_block_free);
163 fclose(f_block_free);