X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/blobdiff_plain/e7e2badf7ebc4b6aeaf03366ad6fe6b919713d54..2b317be73e4cfc0751df22597752cd98ce51740c:/emufs/did.c diff --git a/emufs/did.c b/emufs/did.c index 0e3b79f..5c386b5 100644 --- a/emufs/did.c +++ b/emufs/did.c @@ -1,33 +1,97 @@ +/* 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: jue abr 8 18:07:57 ART 2004 + * Autores: Nicolás Dimov + * Leandro Lucarella + *---------------------------------------------------------------------------- + * + * $Id$ + * + */ + +/** \file + * + * Manejo de archivos de índices de registros borrados (reutilizables). + * + * Implementación del manejo de archivos de índices de registros borrados + * (reutilizables). + * + */ + #include "did.h" +#include +#include + +/* Crea un archivo de ID's Liberados. */ +int emufs_did_crear(EMUFS* efs) +{ + return emufs_crear_archivo_auxiliar(efs->nombre, EMUFS_DID_EXT); +} -int emufs_did_get_last(EMUFS *emu) +/* Devuelve el ID Libre, liberado mas recientemente (pila) */ +EMUFS_REG_ID emufs_did_get_last(EMUFS *efs) { - FILE * f_did; - int id, offset; + FILE *f_did; + EMUFS_REG_ID n_RegId; + EMUFS_OFFSET n_Offset; char name_f_did[255]; - strcpy(name_f_did, emu->nombre); - strcat(name_f_did, ".did"); + strcpy(name_f_did, efs->nombre); + strcat(name_f_did, EMUFS_DID_EXT); if ( (f_did = fopen(name_f_did,"r")) == NULL) return -1; /*ERROR*/ fseek(f_did, 0, SEEK_END); if (ftell(f_did) > 0){ /* si el archivo no esta vacio es porque hay un nro disponible*/ - fseek(f_did, -sizeof(int),SEEK_END); + fseek(f_did, -sizeof(EMUFS_REG_ID),SEEK_END); /* leo el ultimo numero */ - fread(&id,sizeof(int),1,f_did); + fread(&n_RegId,sizeof(EMUFS_REG_ID),1,f_did); /* voy al final */ fseek(f_did, 0, SEEK_END); /* mido el tamaño del archivo*/ - offset = ftell(f_did); + n_Offset = ftell(f_did); fclose(f_did); /*lo trunco */ - truncate(name_f_did, offset - sizeof(int)); + truncate(name_f_did, n_Offset - sizeof(EMUFS_REG_ID)); } else { fclose(f_did); /* si el archivo esta vacio */ - id = -1; + n_RegId = -1; } - return id; + return n_RegId; +} + +/* Agrega un registro al archivo de ID's Libres (pila) */ +int emufs_did_agregar(EMUFS *efs, EMUFS_REG_ID n_RegId) +{ + FILE *f_did; + char name_f_did[255]; + + strcpy(name_f_did, efs->nombre); + strcat(name_f_did, EMUFS_DID_EXT); + + if ( (f_did = fopen(name_f_did,"a+")) == NULL) return -1; + fwrite(&n_RegId, sizeof(EMUFS_REG_ID), 1, f_did); + fclose(f_did); + + return 0; }