|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T u
Length: 3696 (0xe70)
Types: TextFile
Names: »update.c«
└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89
└─⟦0befd2614⟧ »./gdbm-0.8.tar.Z«
└─⟦b993d2893⟧
└─⟦this⟧ »gdbm/update.c«
/* update.c - The routines for helping in crash recovery during an update. */
/* GNU DBM - DataBase Manager (database subroutines) by Philip A. Nelson
Copyright (C) 1989 Free Software Foundation, Inc.
This program 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.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
You may contact the author by:
e-mail: phil@wwu.edu
us-mail: Philip A. Nelson
Computer Science Department
Western Washington University
Bellingham, WA 98226
phone: (206) 676-3035
*************************************************************************/
#include <stdio.h>
#include <sys/file.h>
#include "gdbm.h"
/* At the start of any update that may cause an inconsistant state, the header
is updated with information about that update. */
_dbm_update (dbf, update, param1, param2, param3, param4)
dbm_file_info *dbf;
int update;
int param1;
int param2;
int param3;
int param4;
{
int num_bytes;
int write_header;
/* Set the values in the header. */
dbf->header.upd_param1 = param1;
dbf->header.upd_param2 = param2;
dbf->header.upd_param3 = param3;
dbf->header.upd_param4 = param4;
/* Check for approprate action. */
write_header = 1;
switch (update)
{
case -1: /* Turn error recovery off. */
dbf->header.update_state = update;
break;
case 0: /* End of an update,
write header back to disk regardless of update_state. */
if (dbf->header.update_state != -1)
dbf->header.update_state = 0;
break;
case 1: /* Start error recovery. */
dbf->header.update_state = 0;
break;
default: /* Some update value, write only if updating. */
if (dbf->header.update_state != -1)
dbf->header.update_state = update;
else
write_header = 0;
}
/* Write the header back to disk. */
if (write_header == 1)
{
num_bytes = lseek (dbf->desc, 0, L_SET);
if (num_bytes != 0) _dbm_fatal (dbf, "lseek error");
num_bytes = write (dbf->desc, &dbf->header, sizeof (dbm_file_header));
if (num_bytes != sizeof (dbf->header)) _dbm_fatal (dbf, "write error");
fsync (dbf->desc);
}
}
/* After the update is completed, we write the header back with a magic value
saying that the file is consistent. */
_dbm_end_update (dbf)
dbm_file_info *dbf;
{
_dbm_update (dbf, 0, 0, 0, 0, 0);
}
/* If a fatal error is detected, come here and exit. VAL tells which fatal
error occured. */
_dbm_fatal (dbf, val)
dbm_file_info *dbf;
char *val;
{
if (dbf->fatal_err != NULL)
(*dbf->fatal_err) (val);
else
fprintf (stderr, "dbm fatal: %s.\n", val);
exit (-1);
}
/* Set recovery procedures on or off. This will affect the file DBF and will
remain in effect until this procedure is called to change the state. */
gdbm_recovery (dbf, state)
dbm_file_info *dbf;
int state;
{
if ( state == 0 )
/* Turn error recovery off. */
_dbm_update (dbf, -1, 0, 0, 0, 0);
else
/* Turn error recovery on. */
_dbm_update (dbf, 1, 0, 0, 0, 0);
}