+#include "fsc.h"
+#include "tipo3.h"
+
+int emufs_fsc_agregar(EMUFS *emu, int num_bloque, int fs)
+{
+ FILE *f_fsc;
+ BLOCK_FREE_T reg;
+ char name_f_fsc[255];
+
+ strcpy(name_f_fsc,emu->nombre);
+ strcat(name_f_fsc,".fsc");
+
+ /*cargo el registro*/
+ reg.block = num_bloque; /*no incremento cant, porque grabe el nuevo bloque antes y no lo conte!!*/
+ reg.free_space = fs;
+ /*lo guardo en el archivo al final "a+"*/
+ if ( (f_fsc = fopen(name_f_fsc,"a+"))==NULL ) return -1;
+ fwrite(®,sizeof(BLOCK_FREE_T),1,f_fsc);
+ fclose(f_fsc);
+ return 0;
+}
+
+int emufs_fsc_actualizar(EMUFS *emu, int num_bloque, int fs)
+{
+ FILE *f_fsc;
+ BLOCK_FREE_T reg;
+ char name_f_fsc[255];
+
+ strcpy(name_f_fsc,emu->nombre);
+ strcat(name_f_fsc,".fsc");
+
+ /*busco el bloque que modifique*/
+ if ( (f_fsc = fopen(name_f_fsc,"r+")) == NULL) return -1;
+ while ( !feof(f_fsc) ){
+ if ( fread(®,sizeof(BLOCK_FREE_T),1,f_fsc) != 1) continue;
+ if ( reg.block == num_bloque ){
+ reg.free_space -= fs;
+ fseek(f_fsc,-sizeof(BLOCK_FREE_T),SEEK_CUR);
+ fwrite(®,sizeof(BLOCK_FREE_T),1,f_fsc);
+ break;
+ }
+ }
+ fclose(f_fsc);
+ return 0;
+}