X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/blobdiff_plain/d43fee2497586978337034b2ebd963cfeb1929ff..6c5fe1e15e441c27ba01b22b91bf1e5843ae53f2:/emufs/fsc.c diff --git a/emufs/fsc.c b/emufs/fsc.c index f5d6d06..c0c026f 100644 --- a/emufs/fsc.c +++ b/emufs/fsc.c @@ -1,21 +1,65 @@ +/* vim: set noexpandtab tabstop=4 shiftwidth=4: + *---------------------------------------------------------------------------- + * emufs + *---------------------------------------------------------------------------- + * This file is part of emufs. + * + * emufs is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * emufs is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along + * with emufs; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + *---------------------------------------------------------------------------- + * Creado: vie abr 9 16:17:50 ART 2004 + * Autores: Nicolás Dimov + *---------------------------------------------------------------------------- + * + * $Id$ + * + */ + +/** \file + * + * Archivo para administrar el espacio libre disponible. + * + * Implementación del archivo para administrar el espacio libre disponible. + * + */ + #include "fsc.h" -#include "tipo3.h" +#include +#include + +#define EMUFS_FSC_EXT ".fsc" + +typedef struct emufs_fsc_t { + int block; + int free_space; +} EMUFS_FSC; int emufs_fsc_agregar(EMUFS *emu, int num_bloque, int fs) { FILE *f_fsc; - BLOCK_FREE_T reg; + EMUFS_FSC reg; char name_f_fsc[255]; strcpy(name_f_fsc,emu->nombre); - strcat(name_f_fsc,".fsc"); + strcat(name_f_fsc, EMUFS_FSC_EXT); /*cargo el registro*/ reg.block = num_bloque; reg.free_space = fs; /*lo guardo en el archivo al final "a+"*/ if ( (f_fsc = fopen(name_f_fsc,"a+"))==NULL ) return -1; - fwrite(®,sizeof(BLOCK_FREE_T),1,f_fsc); + fwrite(®,sizeof(EMUFS_FSC),1,f_fsc); fclose(f_fsc); return 0; } @@ -24,20 +68,20 @@ int emufs_fsc_agregar(EMUFS *emu, int num_bloque, int fs) int emufs_fsc_actualizar(EMUFS *emu, int num_bloque, int fs) { FILE *f_fsc; - BLOCK_FREE_T reg; + EMUFS_FSC reg; char name_f_fsc[255]; strcpy(name_f_fsc,emu->nombre); - strcat(name_f_fsc,".fsc"); + strcat(name_f_fsc, EMUFS_FSC_EXT); /*busco el bloque que modifique*/ if ( (f_fsc = fopen(name_f_fsc,"r+")) == NULL) return -1; while ( !feof(f_fsc) ){ - if ( fread(®,sizeof(BLOCK_FREE_T),1,f_fsc) != 1) continue; + if ( fread(®,sizeof(EMUFS_FSC),1,f_fsc) != 1) continue; if ( reg.block == num_bloque ){ reg.free_space = fs; - fseek(f_fsc,-sizeof(BLOCK_FREE_T),SEEK_CUR); - fwrite(®,sizeof(BLOCK_FREE_T),1,f_fsc); + fseek(f_fsc,-sizeof(EMUFS_FSC),SEEK_CUR); + fwrite(®,sizeof(EMUFS_FSC),1,f_fsc); break; } } @@ -49,11 +93,11 @@ int emufs_fsc_actualizar(EMUFS *emu, int num_bloque, int fs) int emufs_fsc_buscar_lugar(EMUFS *emu, unsigned long tam, int *fs) { FILE *f_fsc; - BLOCK_FREE_T reg; + EMUFS_FSC reg; char name_f_fsc[255]; strcpy(name_f_fsc,emu->nombre); - strcat(name_f_fsc,".fsc"); + strcat(name_f_fsc, EMUFS_FSC_EXT); if ( (f_fsc = fopen(name_f_fsc,"r"))==NULL ) return -1; @@ -63,7 +107,7 @@ int emufs_fsc_buscar_lugar(EMUFS *emu, unsigned long tam, int *fs) reg.block = -1; *fs = emu->tam_bloque; while( !feof(f_fsc) ){ - if (fread(®,sizeof(BLOCK_FREE_T),1,f_fsc) != 1) continue; + if (fread(®,sizeof(EMUFS_FSC),1,f_fsc) != 1) continue; if ( reg.free_space >= tam+sizeof(int)) break; else { @@ -81,16 +125,16 @@ int emufs_fsc_buscar_lugar(EMUFS *emu, unsigned long tam, int *fs) int emufs_fsc_get_fs(EMUFS *emu, int num_bloque) { FILE *f_fsc; - BLOCK_FREE_T reg; + EMUFS_FSC reg; char name_f_fsc[255]; strcpy(name_f_fsc,emu->nombre); - strcat(name_f_fsc,".fsc"); + strcat(name_f_fsc, EMUFS_FSC_EXT); if ( (f_fsc = fopen(name_f_fsc,"r"))==NULL ) return -1; while ( !feof(f_fsc) ){ - if ( fread(®,sizeof(BLOCK_FREE_T),1,f_fsc) != 1 ) continue; + if ( fread(®,sizeof(EMUFS_FSC),1,f_fsc) != 1 ) continue; if ( reg.block == num_bloque ) break; }