]> git.llucax.com Git - z.facultad/75.06/emufs.git/commitdiff
Fixee el get_max_min y get_media que si el .fsc estaba vacio devolvian valores basura
authorAlan Kennedy <kennedya@3dgames.com.ar>
Sat, 17 Apr 2004 18:15:40 +0000 (18:15 +0000)
committerAlan Kennedy <kennedya@3dgames.com.ar>
Sat, 17 Apr 2004 18:15:40 +0000 (18:15 +0000)
emufs/fsc.c

index 4c5008abfdec7a95e2671af7c2d2af5f845b4691..562ae32fa2bd905b597718761a15cd1a6733365e 100644 (file)
@@ -374,20 +374,31 @@ int emufs_fsc_get_max_min_fs(EMUFS *emu, EMUFS_FREE *min, EMUFS_FREE *max)
        strcpy(name_f_fsc,emu->nombre);
        strcat(name_f_fsc, EMUFS_FSC_EXT);
 
-       *min = ULONG_MAX;
-       *max = 0;
        if ( (f_fsc = fopen(name_f_fsc,"r"))==NULL ) return -1;
-       
-       while ( !feof(f_fsc) ){
-               fread(&reg, sizeof(EMUFS_FSC), 1, f_fsc);
-               if (  reg.freespace < *min )
-                       *min = reg.freespace;
-               if ( reg.freespace > *max )
-                       *max = reg.freespace;
+               
+       /* Si el file esta vacio, devuelvo valores nulos */
+       fseek(f_fsc,0,SEEK_END);
+       if (ftell(f_fsc) == 0) {
+               *min = 0;
+               *max = 0;
+               return 0;               
+       }
+       else
+       {
+               /* Busco Min y Max */
+               *min = ULONG_MAX;
+               *max = 0;               
+               fseek(f_fsc,0,SEEK_SET);                
+               while ( !feof(f_fsc) ){
+                       if ( fread(&reg, sizeof(EMUFS_FSC), 1, f_fsc) != 1) continue;
+                       if (  reg.freespace < *min )
+                               *min = reg.freespace;
+                       if ( reg.freespace > *max )
+                               *max = reg.freespace;
+               }
+               fclose(f_fsc);
+               return 0;               
        }
-
-       fclose(f_fsc);
-       return 0;
 }
 
 EMUFS_FREE emufs_fsc_get_media_fs(EMUFS *emu)
@@ -404,13 +415,15 @@ EMUFS_FREE emufs_fsc_get_media_fs(EMUFS *emu)
        if ( (f_fsc = fopen(name_f_fsc,"r"))==NULL ) return -1;
        
        while ( !feof(f_fsc) ){
-               fread(&reg, sizeof(EMUFS_FSC), 1, f_fsc);
+               if ( fread(&reg, sizeof(EMUFS_FSC), 1, f_fsc) != 1) continue;           
                total_fs += reg.freespace;
                ++gap_count;
        }
 
        fclose(f_fsc);
-       return total_fs/gap_count;
+       
+       if (gap_count > 0) return total_fs/gap_count;
+       else return 0;
 }
 
 int emufs_fsc_get_cant_bloques_vacios(EMUFS *emu)