X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/blobdiff_plain/6c5fe1e15e441c27ba01b22b91bf1e5843ae53f2..b172089853a56455742c11dfaf940544f57fef70:/emufs/fsc.c diff --git a/emufs/fsc.c b/emufs/fsc.c index c0c026f..05218a6 100644 --- a/emufs/fsc.c +++ b/emufs/fsc.c @@ -20,6 +20,7 @@ *---------------------------------------------------------------------------- * Creado: vie abr 9 16:17:50 ART 2004 * Autores: Nicolás Dimov + * Leandro Lucarella *---------------------------------------------------------------------------- * * $Id$ @@ -38,14 +39,12 @@ #include #include -#define EMUFS_FSC_EXT ".fsc" - -typedef struct emufs_fsc_t { - int block; - int free_space; -} EMUFS_FSC; +int emufs_fsc_crear(EMUFS* efs) +{ + return emufs_crear_archivo_auxiliar(efs->nombre, EMUFS_FSC_EXT); +} -int emufs_fsc_agregar(EMUFS *emu, int num_bloque, int fs) +int emufs_fsc_agregar(EMUFS *emu, EMUFS_BLOCK_ID num_bloque, EMUFS_FREE fs) { FILE *f_fsc; EMUFS_FSC reg; @@ -65,7 +64,7 @@ int emufs_fsc_agregar(EMUFS *emu, int num_bloque, int fs) } /* busca el bloque y le resta fs de espacio libre */ -int emufs_fsc_actualizar(EMUFS *emu, int num_bloque, int fs) +int emufs_fsc_actualizar(EMUFS *emu, EMUFS_BLOCK_ID num_bloque, EMUFS_FREE fs) { FILE *f_fsc; EMUFS_FSC reg; @@ -90,7 +89,7 @@ int emufs_fsc_actualizar(EMUFS *emu, int num_bloque, int fs) } /* me devuelve el ID del bloque donde quepa un registro, y guarda en fs el espacio libre que queda en el bloque */ -int emufs_fsc_buscar_lugar(EMUFS *emu, unsigned long tam, int *fs) +EMUFS_BLOCK_ID emufs_fsc_buscar_lugar(EMUFS *emu, EMUFS_FREE tam, EMUFS_FREE *fs) { FILE *f_fsc; EMUFS_FSC reg; @@ -108,9 +107,9 @@ int emufs_fsc_buscar_lugar(EMUFS *emu, unsigned long tam, int *fs) *fs = emu->tam_bloque; while( !feof(f_fsc) ){ if (fread(®,sizeof(EMUFS_FSC),1,f_fsc) != 1) continue; - if ( reg.free_space >= tam+sizeof(int)) + if (reg.free_space >= tam) { break; - else { + } else { reg.block = -1; *fs = emu->tam_bloque; } @@ -122,7 +121,7 @@ int emufs_fsc_buscar_lugar(EMUFS *emu, unsigned long tam, int *fs) return reg.block; } -int emufs_fsc_get_fs(EMUFS *emu, int num_bloque) +EMUFS_FREE emufs_fsc_get_fs(EMUFS *emu, EMUFS_BLOCK_ID num_bloque) { FILE *f_fsc; EMUFS_FSC reg; @@ -142,3 +141,4 @@ int emufs_fsc_get_fs(EMUFS *emu, int num_bloque) fclose(f_fsc); return reg.free_space; } +