*/
#include "did.h"
+#include <string.h>
+#include <unistd.h>
+
+#define EMUFS_DID_EXT ".did"
int emufs_did_get_last(EMUFS *emu)
{
char name_f_did[255];
strcpy(name_f_did, emu->nombre);
- strcat(name_f_did, ".did");
+ 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);
char name_f_did[255];
strcpy(name_f_did, emu->nombre);
- strcat(name_f_did, ".did");
+ strcat(name_f_did, EMUFS_DID_EXT);
if ( (f_did = fopen(name_f_did,"a+")) == NULL) return -1;
fwrite(&ID, sizeof(int), 1, f_did);
*
*/
-#ifndef _DID_H_
-#define _DID_H_
+#ifndef _EMUFS_DID_H_
+#define _EMUFS_DID_H_
-#include <string.h>
-#include <unistd.h>
#include "emufs.h"
int emufs_did_get_last(EMUFS *);
int emufs_did_agregar(EMUFS *, int);
-#endif /* _DID_H */
+#endif /* _EMUFS_DID_H */
* Leandro Lucarella <llucare@fi.uba.ar>
*----------------------------------------------------------------------------
*
- * $Id: command.cpp 220 2003-11-19 23:10:40Z luca $
+ * $Id$
*
*/
#include "tipo3.h"
/* Defino las extenciones que usan cada tipo de archivo */
-#define EXT_TIPO3_ID ".idx"
#define EXT_TIPO3_DATA ".dat"
-#define EXT_TIPO3_DISP ".fsc"
-#define EXT_TIPO3_IDS ".did"
char *str_dup(const char *s);
+/* 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 <sagardua@uolsinectis.com.ar>
+ *----------------------------------------------------------------------------
+ *
+ * $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 <string.h>
+#include <unistd.h>
+
+#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;
}
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;
}
}
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;
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 {
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;
}
-#ifndef _FSC_H
-#define _FSC_H
-#include <string.h>
-#include <unistd.h>
+/* 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 <sagardua@uolsinectis.com.ar>
+ *----------------------------------------------------------------------------
+ *
+ * $Id$
+ *
+ */
+
+/** \file
+ *
+ * Archivo para administrar el espacio libre disponible.
+ *
+ * Interfaz del archivo para administrar el espacio libre disponible.
+ *
+ */
+
+#ifndef _EMUFS_FSC_H
+#define _EMUFS_FSC_H
+
#include "emufs.h"
int emufs_fsc_agregar(EMUFS *, int, int);
int emufs_fsc_get_fs(EMUFS *, int);
-#endif /* _FSC_H */
+#endif /* _EMUFS_FSC_H */
*/
#include "idx.h"
-#include "tipo3.h"
+
+#define EMUFS_IDX_EXT ".idx"
+
+typedef struct emufs_idx_t {
+ int block;
+ long int id_reg;
+} EMUFS_IDX;
int emufs_idx_buscar_mayor_id(EMUFS *emu)
{
int id, max = -1;
FILE *f_idx;
- BLOCK_REG_T reg;
- char name_f_idx[255];
+ EMUFS_IDX reg;
+ char name_f_idx[255]; /* TODO usar malloc para no limitar el tamaño de nombre de archivo */
strcpy(name_f_idx,emu->nombre);
- strcat(name_f_idx,".idx");
+ strcat(name_f_idx, EMUFS_IDX_EXT);
if ( (f_idx = fopen(name_f_idx,"r")) == NULL) return -1; /*ERROR*/
id = -1;
while ( !feof(f_idx) ){
/* Me aseguro de leer la cantidad de bytes correcta */
- if (fread(®,sizeof(BLOCK_REG_T),1,f_idx) != 1) continue;
+ if (fread(®,sizeof(EMUFS_IDX),1,f_idx) != 1) continue;
if ( reg.id_reg >= max )
max = reg.id_reg;
}
int emufs_idx_buscar_registro(EMUFS *emu, int ID)
{
FILE* f_idx;
- BLOCK_REG_T reg;
+ EMUFS_IDX reg;
char name_f_idx[255];
strcpy(name_f_idx,emu->nombre);
- strcat(name_f_idx,".idx");
+ strcat(name_f_idx, EMUFS_IDX_EXT);
if ( (f_idx = fopen(name_f_idx,"r")) == NULL) return -1; /*ERROR*/
while ( !feof(f_idx) ){
- if (fread(®,sizeof(BLOCK_REG_T),1,f_idx) != 1) continue;
+ if (fread(®,sizeof(EMUFS_IDX),1,f_idx) != 1) continue;
if ( reg.id_reg == ID ){
fclose(f_idx);
return reg.block;
}
/* agrega un registro al final del archivo */
-emufs_idx_agregar(EMUFS *emu, int num_bloque, int ID_aux)
+int emufs_idx_agregar(EMUFS *emu, int num_bloque, int ID_aux)
{
FILE *f_idx;
- BLOCK_REG_T reg;
+ EMUFS_IDX reg;
char name_f_idx[255];
strcpy(name_f_idx,emu->nombre);
- strcat(name_f_idx,".idx");
+ strcat(name_f_idx, EMUFS_IDX_EXT);
if ( (f_idx = fopen(name_f_idx,"ab+"))==NULL ) return -1;
reg.block = num_bloque;
reg.id_reg = ID_aux;
- fwrite(®,sizeof(BLOCK_REG_T),1,f_idx);
+ fwrite(®,sizeof(EMUFS_IDX),1,f_idx);
fclose(f_idx);
return 0;
}
*
*/
-#ifndef _IDX_H
-#define _IDX_H
+#ifndef _EMUFS_IDX_H
+#define _EMUFS_IDX_H
#include <string.h>
#include "emufs.h"
int emufs_idx_agregar(EMUFS *, int , int);
-#endif /* _IDX_H */
+#endif /* _EMUFS_IDX_H */
*
*/
-#ifndef _PARAM_CTE_H_
-#define _PARAM_CTE_H_
+#ifndef _EMUFS_TIPO3_H_
+#define _EMUFS_TIPO3_H_
#include <stdio.h>
#include <stdlib.h>
#include "idx.h"
#include "fsc.h"
-
-typedef struct block_free_t {
- int block;
- int free_space;
-} BLOCK_FREE_T;
-
-typedef struct block_reg_t {
- int block;
- long int id_reg;
-} BLOCK_REG_T;
-
int emufs_tipo3_leer_registro(EMUFS *, int , void *, unsigned long);
int emufs_tipo3_leer_bloque(EMUFS *, int , void *);
int emufs_tipo3_borrar_registro(EMUFS*, int, int);
-#endif /* _PARAM_CTE_H_ */
+#endif /* _EMUFS_TIPO3_H_ */