+ fclose(datfile);
+ return;
+ }
+ fseek(fscfile,0,SEEK_END);
+ cant_gaps = ftell(fscfile)/sizeof(EMUFS_FSC);
+
+ if (cant_gaps == 0) {
+ fclose(datfile);
+ fclose(fscfile);
+ return;
+ }
+ if (cant_gaps == 1) {
+ /* Un solo gap, muevo toda la data luego del gap y trunco */
+ fseek(fscfile,0,SEEK_SET);
+ fread(®1,sizeof(EMUFS_FSC),1,fscfile);
+ source = reg1.marker + reg1.freespace;
+ destination = reg1.marker;
+ mustmove_bytes = datsize - source;
+ /*printf("Para recompactar, must move: %lu bytes\n",mustmove_bytes);
+ printf("Will move from: %lu to %lu\n",source,destination);*/
+ emufs_tipo2_movedata(datfile,&source,&destination,mustmove_bytes);
+ }
+ if (cant_gaps > 1)
+ {
+ /* Comienzo leyendo un gap */
+ fseek(fscfile,0,SEEK_SET);
+ fread(®1,sizeof(EMUFS_FSC),1,fscfile);
+ destination = reg1.marker;
+ --cant_gaps;
+
+ while (cant_gaps > 0)
+ {
+ /* El source siempre sera el fin del anteultimo gap leido */
+ source = reg1.marker + reg1.freespace;
+ /* Leemos otro gap para calcular cuanto debemos mover */
+ fread(®2,sizeof(EMUFS_FSC),1,fscfile);
+ mustmove_bytes = reg2.marker - source;
+ /*printf("Para recompactar, must move: %lu bytes\n",mustmove_bytes);
+ printf("Will move from: %lu to %lu\n",source,destination);*/
+ emufs_tipo2_movedata(datfile,&source,&destination,mustmove_bytes);
+ /* Guardo el nuevo destino que es donde termino de mover */
+ destination = ftell(datfile);
+ /* El ultimo gap leido, pasa a ser el de referencia ahora */
+ reg1.marker = reg2.marker;
+ reg1.freespace = reg2.freespace;
+ --cant_gaps;
+ }
+
+ /* Realizo el movimiento del ultimo chunk de datos */
+ source = reg1.marker + reg1.freespace;
+ mustmove_bytes = datsize - source;
+ emufs_tipo2_movedata(datfile,&source,&destination,mustmove_bytes);