From: Leandro Lucarella Date: Fri, 9 Apr 2004 19:27:56 +0000 (+0000) Subject: Se emprolija un poco los archivos de indices. X-Git-Tag: svn_import_r684~598 X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/commitdiff_plain/6c5fe1e15e441c27ba01b22b91bf1e5843ae53f2?ds=sidebyside Se emprolija un poco los archivos de indices. --- diff --git a/emufs/did.c b/emufs/did.c index 939493b..f193025 100644 --- a/emufs/did.c +++ b/emufs/did.c @@ -36,6 +36,10 @@ */ #include "did.h" +#include +#include + +#define EMUFS_DID_EXT ".did" int emufs_did_get_last(EMUFS *emu) { @@ -44,7 +48,7 @@ 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); @@ -76,7 +80,7 @@ int emufs_did_agregar(EMUFS *emu, int ID) 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); diff --git a/emufs/did.h b/emufs/did.h index 46a7867..94770dd 100644 --- a/emufs/did.h +++ b/emufs/did.h @@ -35,15 +35,13 @@ * */ -#ifndef _DID_H_ -#define _DID_H_ +#ifndef _EMUFS_DID_H_ +#define _EMUFS_DID_H_ -#include -#include #include "emufs.h" int emufs_did_get_last(EMUFS *); int emufs_did_agregar(EMUFS *, int); -#endif /* _DID_H */ +#endif /* _EMUFS_DID_H */ diff --git a/emufs/emufs.c b/emufs/emufs.c index b62702b..9934374 100644 --- a/emufs/emufs.c +++ b/emufs/emufs.c @@ -24,7 +24,7 @@ * Leandro Lucarella *---------------------------------------------------------------------------- * - * $Id: command.cpp 220 2003-11-19 23:10:40Z luca $ + * $Id$ * */ @@ -42,10 +42,7 @@ #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); 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; } diff --git a/emufs/fsc.h b/emufs/fsc.h index 354273a..0216094 100644 --- a/emufs/fsc.h +++ b/emufs/fsc.h @@ -1,7 +1,42 @@ -#ifndef _FSC_H -#define _FSC_H -#include -#include +/* 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. + * + * 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); @@ -12,4 +47,4 @@ int emufs_fsc_buscar_lugar(EMUFS *, unsigned long, int *); int emufs_fsc_get_fs(EMUFS *, int); -#endif /* _FSC_H */ +#endif /* _EMUFS_FSC_H */ diff --git a/emufs/idx.c b/emufs/idx.c index a9efcaa..093c2ac 100644 --- a/emufs/idx.c +++ b/emufs/idx.c @@ -35,23 +35,29 @@ */ #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; } @@ -65,14 +71,14 @@ int emufs_idx_buscar_mayor_id(EMUFS *emu) 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; @@ -84,20 +90,20 @@ int emufs_idx_buscar_registro(EMUFS *emu, int ID) } /* 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; } diff --git a/emufs/idx.h b/emufs/idx.h index a2c9736..2ccef85 100644 --- a/emufs/idx.h +++ b/emufs/idx.h @@ -34,8 +34,8 @@ * */ -#ifndef _IDX_H -#define _IDX_H +#ifndef _EMUFS_IDX_H +#define _EMUFS_IDX_H #include #include "emufs.h" @@ -46,4 +46,4 @@ int emufs_idx_buscar_registro(EMUFS *, int); int emufs_idx_agregar(EMUFS *, int , int); -#endif /* _IDX_H */ +#endif /* _EMUFS_IDX_H */ diff --git a/emufs/tipo3.h b/emufs/tipo3.h index 0476666..9b64976 100644 --- a/emufs/tipo3.h +++ b/emufs/tipo3.h @@ -35,8 +35,8 @@ * */ -#ifndef _PARAM_CTE_H_ -#define _PARAM_CTE_H_ +#ifndef _EMUFS_TIPO3_H_ +#define _EMUFS_TIPO3_H_ #include #include @@ -47,17 +47,6 @@ #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 *); @@ -75,4 +64,4 @@ int emufs_tipo3_buscar_lugar(EMUFS *, unsigned long , int *); int emufs_tipo3_borrar_registro(EMUFS*, int, int); -#endif /* _PARAM_CTE_H_ */ +#endif /* _EMUFS_TIPO3_H_ */