merge tip with montulli branch and create montulli1 montulli1
authormontulli
Thu, 18 Jun 1998 00:52:47 +0000
branchmontulli1
changeset 31 d52bceaf115d9a988fc5d7418a9f13b50a67b839
parent 26 6150d3cfd3a8ee4c3c1bf695191bbf7a1738579e
child 13992 6d64cfd46d937ea31c160eba781e276cbd429e24
push idunknown
push userunknown
push dateunknown
merge tip with montulli branch and create montulli1
dbm/include/hash.h
dbm/src/hash.c
--- a/dbm/include/hash.h
+++ b/dbm/include/hash.h
@@ -118,16 +118,17 @@ typedef struct htab	 {		/* Memory reside
 	int		cndx;		/* Index of next item on cpage */
 	int		dbmerrno;		/* Error Number -- for DBM 
 					 * compatability */
 	int		new_file;	/* Indicates if fd is backing store 
 					 * or no */
 	int		save_file;	/* Indicates whether we need to flush 
 					 * file at
 					 * exit */
+	int             dirty_bit;	/* has db changed */
 	uint32	*mapp[NCACHED];	/* Pointers to page maps */
 	int		nmaps;		/* Initial number of bitmaps */
 	int		nbufs;		/* Number of buffers left to 
 					 * allocate */
 	BUFHEAD 	bufhead;	/* Header of buffer lru list */
 	SEGMENT 	*dir;		/* Hash Bucket directory */
 } HTAB;
 
--- a/dbm/src/hash.c
+++ b/dbm/src/hash.c
@@ -156,16 +156,17 @@ extern DB *
 	 * we can check it for a non-zero
 	 * date to see if stat succeeded
 	 */
 	memset(&statbuf, 0, sizeof(struct stat));
 
 	if (!(hashp = (HTAB *)calloc(1, sizeof(HTAB))))
 		RETURN_ERROR(ENOMEM, error0);
 	hashp->fp = NO_FILE;
+	hashp->dirty_bit = 0;
 	if(file)
 		hashp->filename = strdup(file);
 
 	/*
 	 * Even if user wants write only, we need to be able to read
 	 * the actual file, so we need to open it read/write. But, the
 	 * field in the hashp structure needs to be accurate so that
 	 * we can check accesses.
@@ -606,17 +607,17 @@ static int
 flush_meta(HTAB *hashp)
 {
 	HASHHDR *whdrp;
 #if BYTE_ORDER == LITTLE_ENDIAN
 	HASHHDR whdr;
 #endif
 	int fp, i, wsize;
 
-	if (!hashp->save_file)
+	if (!hashp->save_file || !hashp->dirty_bit)
 		return (0);
 	hashp->MAGIC = HASHMAGIC;
 	hashp->VERSION = HASHVERSION;
 	hashp->H_CHARKEY = hashp->hash(CHARKEY, sizeof(CHARKEY));
 
 	fp = hashp->fp;
 	whdrp = &hashp->hdr;
 #if BYTE_ORDER == LITTLE_ENDIAN
@@ -690,16 +691,18 @@ hash_put(
 {
 	HTAB *hashp;
 	int rv;
 
 	hashp = (HTAB *)dbp->internal;
 	if (!hashp)
 		return (DBM_ERROR);
 
+	hashp->dirty_bit = 1;
+
 	if (flag && flag != R_NOOVERWRITE) {
 		hashp->dbmerrno = errno = EINVAL;
 		return (DBM_ERROR);
 	}
 	if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
 		hashp->dbmerrno = errno = EPERM;
 		return (DBM_ERROR);
 	}
@@ -726,16 +729,18 @@ hash_delete(
 {
 	HTAB *hashp;
 	int rv;
 
 	hashp = (HTAB *)dbp->internal;
 	if (!hashp)
 		return (DBM_ERROR);
 
+	hashp->dirty_bit = 1;
+
 	if (flag && flag != R_CURSOR) {
 		hashp->dbmerrno = errno = EINVAL;
 		return (DBM_ERROR);
 	}
 	if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
 		hashp->dbmerrno = errno = EPERM;
 		return (DBM_ERROR);
 	}