X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/blobdiff_plain/1e96d89cf3c42131b8a8731a3fb76eb111550a52..3a8f34126fd2b8cf8b2ae8822a800aa62003625d:/emufs/idx.c diff --git a/emufs/idx.c b/emufs/idx.c index d0dd436..6ee1b87 100644 --- a/emufs/idx.c +++ b/emufs/idx.c @@ -68,30 +68,31 @@ int emufs_idx_crear(EMUFS *efs) /* Devuelve el mayor id de registro utilizado so far en el archivo de datos, revisando el indice. */ EMUFS_REG_ID emufs_idx_buscar_mayor_id(EMUFS *emu) { - EMUFS_REG_ID n_IdReg, max = 0; + EMUFS_REG_ID n_idreg, max = 0; FILE *f_idx; EMUFS_IDX reg; char name_f_idx[255]; /* TODO usar malloc para no limitar el tamaƱo de nombre de archivo */ - unsigned short int b_Found = 0; + unsigned short int b_found = 0; strcpy(name_f_idx,emu->nombre); strcat(name_f_idx, EMUFS_IDX_EXT); if ( (f_idx = fopen(name_f_idx,"r")) == NULL) return -1; /*ERROR*/ - n_IdReg = -1; + n_idreg = -1; while ( !feof(f_idx) ){ /* Me aseguro de leer la cantidad de bytes correcta */ if (fread(®,sizeof(EMUFS_IDX),1,f_idx) != 1) continue; - if ( reg.n_IdReg >= max ) { - max = reg.n_IdReg; - b_Found = 1; + if ( reg.n_idreg >= max ) { + max = reg.n_idreg; + b_found = 1; } } fclose(f_idx); - if (!b_Found) return (0); - else return(max+1); - return n_IdReg; + if (!b_found) + return (0); + else + return(max+1); } /* busca el registro ID en el archivo ".idx" y devuelve el nro de bloque en el que se encuentra */ @@ -109,18 +110,20 @@ EMUFS_BLOCK_ID emufs_idx_buscar_registro(EMUFS *emu, EMUFS_REG_ID n_IdReg) while (!feof(f_idx) && !b_Found){ if (fread(®,sizeof(EMUFS_IDX),1,f_idx) != 1) continue; - if (reg.n_IdReg == n_IdReg) b_Found = 1; + if (reg.n_idreg == n_IdReg) b_Found = 1; } fclose(f_idx); /* Sino lo encontre devuelvo uno, otherwise el offset o bloque */ - if (!b_Found) return(-1); - else return(reg.n_Location); + if (!b_Found) + return(-1); + else + return(reg.n_location); } /* agrega un registro al final del archivo */ -int emufs_idx_agregar(EMUFS *emu, EMUFS_REG_ID n_IdReg, EMUFS_BLOCK_ID n_Location) +int emufs_idx_agregar(EMUFS *emu, EMUFS_REG_ID n_idreg, EMUFS_BLOCK_ID n_location) { FILE *f_idx; EMUFS_IDX reg; @@ -132,8 +135,8 @@ int emufs_idx_agregar(EMUFS *emu, EMUFS_REG_ID n_IdReg, EMUFS_BLOCK_ID n_Locatio if ( (f_idx = fopen(name_f_idx,"a+"))==NULL ) return -1; /* Note: Location = Bloque para Tipo 1 y 3, Offset para Tipo 2 */ - reg.n_IdReg = n_IdReg; - reg.n_Location = n_Location; + reg.n_idreg = n_idreg; + reg.n_location = n_location; fwrite(®,sizeof(EMUFS_IDX),1,f_idx); fclose(f_idx); return 0; @@ -155,7 +158,7 @@ int emufs_idx_borrar(EMUFS *emu, EMUFS_REG_ID n_IdReg) while ( !feof(f_idx) ){ /*busco cual tengo que borrar*/ if ( fread(®, sizeof(EMUFS_IDX), 1, f_idx) != 1 ) continue; - if ( reg.n_IdReg == n_IdReg ) + if ( reg.n_idreg == n_IdReg ) break; }