]> git.llucax.com Git - z.facultad/75.06/emufs.git/blobdiff - emufs/fsc.c
Borrado de registros ya funciona entero dado que se arreglo el idx_borrar. Rutina...
[z.facultad/75.06/emufs.git] / emufs / fsc.c
index 43dc627552949b1cb33341c812d1c82a56473947..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;
@@ -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(&reg, sizeof(EMUFS_FSC), 1, f_fsc) != 1) continue;
+               total += reg.n_freespace;
+       }
+       fclose(f_fsc);
+       return total;
+}