]> git.llucax.com Git - z.facultad/75.06/emufs.git/blobdiff - emufs/fsc.c
cambio los printf por PERR
[z.facultad/75.06/emufs.git] / emufs / fsc.c
index 0b9449bd1a12d2f0fa0201507f251191d8bc4d48..e71d13d2a5bcac2406e4e10bfcba248b41f8911a 100644 (file)
@@ -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;