X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/blobdiff_plain/71ee5a3bb6632a2e8b5a6f104f1e1d93e2df9871..defa938b3f327a42634161a5815e06f94b20b554:/emufs/fsc.c?ds=inline diff --git a/emufs/fsc.c b/emufs/fsc.c index d0d9124..84746a8 100644 --- a/emufs/fsc.c +++ b/emufs/fsc.c @@ -359,7 +359,7 @@ EMUFS_BLOCK_ID emufs_fsc_buscar_lugar(EMUFS *emu, EMUFS_FREE reg_size, EMUFS_FRE /** Busca n lugares consecutivos devolviendo el id del primer bloque. */ EMUFS_BLOCK_ID emufs_fsc_buscar_n_lugares(EMUFS* efs, size_t n, - EMUFS_FREE reg_size, EMUFS_FREE *freespace, int* err) + EMUFS_FREE size, EMUFS_FREE *freespace, int* err) { FILE *f_fsc; EMUFS_FSC reg; @@ -387,9 +387,10 @@ EMUFS_BLOCK_ID emufs_fsc_buscar_n_lugares(EMUFS* efs, size_t n, if (feof(f_fsc)) break; PERR("No se puede leer el archivo"); *err = EMUFS_ERROR_FILE_READ; + fclose(f_fsc); return EMUFS_NOT_FOUND; } - if (reg.freespace >= reg_size) { + if (reg.freespace >= size) { int found = 1; EMUFS_BLOCK_ID first_id = reg.marker; *freespace = reg.freespace; @@ -398,10 +399,11 @@ EMUFS_BLOCK_ID emufs_fsc_buscar_n_lugares(EMUFS* efs, size_t n, if (feof(f_fsc)) break; PERR("No se puede leer el archivo"); *err = EMUFS_ERROR_FILE_READ; + fclose(f_fsc); return EMUFS_NOT_FOUND; } /* no hay otro lugar consecutivo */ - if (reg.freespace < reg_size) { + if (reg.freespace < size) { found = 0; break; } @@ -453,7 +455,8 @@ EMUFS_FREE emufs_fsc_get_total_fs(EMUFS *emu) total = 0; while ( !feof(f_fsc) ){ if ( fread(®, sizeof(EMUFS_FSC), 1, f_fsc) != 1) continue; - total += reg.freespace; + if ( reg.freespace > 0 ) + total += reg.freespace; } fclose(f_fsc); return total; @@ -575,4 +578,3 @@ long emufs_fsc_get_file_size(EMUFS* efs, int* err) strcat(name, EMUFS_FSC_EXT); return emufs_common_get_file_size(name, err); } -