printf("fsc.c >> Pre Gap found is reg number %lu in .fsc file\n",n_gap_before);
printf("fsc.c >> Post Gap found is reg number %lu in .fsc file\n",n_gap_after);
/* Guardo el nuevo GAP que posee los tres espacios sumados */
- fseek(f_fsc,sizeof(EMUFS_FSC)*n_gap_before,0);
+ if (n_gap_before < n_gap_after) {
+ fseek(f_fsc,sizeof(EMUFS_FSC)*n_gap_before,0);
+ n_destination = sizeof(EMUFS_FSC)*n_gap_after;
+ }
+ else {
+ fseek(f_fsc,sizeof(EMUFS_FSC)*n_gap_after,0);
+ n_destination = sizeof(EMUFS_FSC)*n_gap_before;
+ }
gap_new.n_marker = gap_before.n_marker;
gap_new.n_freespace = gap_before.n_freespace + n_freespace + gap_after.n_freespace;
fwrite(&gap_new,sizeof(EMUFS_FSC),1,f_fsc);
/* Preparo el escenario para la movida de registros */
- n_destination = sizeof(EMUFS_FSC)*n_gap_after;
- n_source = n_destination+sizeof(EMUFS_FSC); /* Salteo el gap_after! */
+ n_source = n_destination+sizeof(EMUFS_FSC); /* Salteo el gap que elimino! */
fseek(f_fsc,0,SEEK_END);
n_filesize = ftell(f_fsc);
n_reg_count = (n_filesize - n_source) / sizeof(EMUFS_FSC);
++n_moved;
}
fclose(f_fsc);
- truncate(name_f_fsc, n_filesize - sizeof(EMUFS_FSC));
+ truncate(name_f_fsc, n_filesize - sizeof(EMUFS_FSC));
}
return 0;
fclose(f_fsc);
return reg.n_freespace;
}
+
+EMUFS_FREE emufs_fsc_get_total_fs(EMUFS *emu)
+{
+ FILE *f_fsc;
+ EMUFS_FSC reg;
+ char name_f_fsc[255];
+ EMUFS_FREE total;
+
+ strcpy(name_f_fsc,emu->nombre);
+ strcat(name_f_fsc, EMUFS_FSC_EXT);
+
+ if ( (f_fsc = fopen(name_f_fsc,"r"))==NULL ) return -1;
+ total = 0;
+ while ( !feof(f_fsc) ){
+ if ( fread(®, sizeof(EMUFS_FSC), 1, f_fsc) != 1) continue;
+ total += reg.n_freespace;
+ }
+ fclose(f_fsc);
+ return total;
+}