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;