1 /* vim: set noexpandtab tabstop=4 shiftwidth=4:
2 *----------------------------------------------------------------------------
4 *----------------------------------------------------------------------------
5 * This file is part of emufs.
7 * emufs is free software; you can redistribute it and/or modify it under the
8 * terms of the GNU General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option) any later
12 * emufs is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along
18 * with emufs; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
20 *----------------------------------------------------------------------------
21 * Creado: jue abr 8 18:07:57 ART 2004
22 * Autores: Nicolás Dimov <sagardua@uolsinectis.com.ar>
23 * Leandro Lucarella <llucare@fi.uba.ar>
24 *----------------------------------------------------------------------------
32 * Manejo de archivos de índices de registros borrados (reutilizables).
34 * Implementación del manejo de archivos de índices de registros borrados
43 int emufs_did_crear(EMUFS* efs)
45 return emufs_crear_archivo_auxiliar(efs->nombre, EMUFS_DID_EXT);
48 EMUFS_REG_ID emufs_did_get_last(EMUFS *efs)
52 EMUFS_OFFSET n_offset;
55 strcpy(name_f_did, efs->nombre);
56 strcat(name_f_did, EMUFS_DID_EXT);
58 if ( (f_did = fopen(name_f_did,"r")) == NULL) return -1; /*ERROR*/
59 fseek(f_did, 0, SEEK_END);
61 if (ftell(f_did) > 0){
62 /* si el archivo no esta vacio es porque hay un nro disponible*/
63 fseek(f_did, -sizeof(EMUFS_REG_ID),SEEK_END);
64 /* leo el ultimo numero */
65 fread(&n_regid,sizeof(EMUFS_REG_ID),1,f_did);
67 fseek(f_did, 0, SEEK_END);
68 /* mido el tamaño del archivo*/
69 n_offset = ftell(f_did);
72 truncate(name_f_did, n_offset - sizeof(EMUFS_REG_ID));
75 /* si el archivo esta vacio */
76 n_regid = EMUFS_NOT_FOUND;
81 int emufs_did_agregar(EMUFS *efs, EMUFS_REG_ID n_regid)
86 strcpy(name_f_did, efs->nombre);
87 strcat(name_f_did, EMUFS_DID_EXT);
89 if ( (f_did = fopen(name_f_did,"a+")) == NULL) return -1;
90 fwrite(&n_regid, sizeof(EMUFS_REG_ID), 1, f_did);