X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/blobdiff_plain/7edecbfd8488f049760d68a9bc5e846c4811f83d..75973af27108786afc7a63cbb2efa6a33ae386dc:/emufs/fsc.c diff --git a/emufs/fsc.c b/emufs/fsc.c index 43dc627..e71d13d 100644 --- a/emufs/fsc.c +++ b/emufs/fsc.c @@ -148,14 +148,20 @@ int emufs_fsc_agregar_gap(EMUFS *emu, EMUFS_OFFSET n_marker, EMUFS_FREE n_freesp 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); @@ -171,7 +177,7 @@ int emufs_fsc_agregar_gap(EMUFS *emu, EMUFS_OFFSET n_marker, EMUFS_FREE n_freesp ++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; @@ -325,3 +331,23 @@ EMUFS_FREE emufs_fsc_get_fs(EMUFS *emu, EMUFS_BLOCK_ID n_marker) 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; +}