1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* db_vers.cc
*
* Copyright (c) 1988-2000 by Sun Microsystems, Inc.
* All Rights Reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <string.h>
#include "db_headers.h"
#include "db_vers.h"
#include "nisdb_mt.h"
const long unsigned MAXLOW = 32768*32768;
/* Constructor that makes copy of 'other'. */
vers::vers(vers* other)
{
INITRW(vers);
assign(other);
}
void
vers::assign(vers* other)
{
WRITELOCKV(this, "w vers::assign");
if (other == NULL) {
syslog(LOG_ERR, "vers::vers: making copy of null vers?");
vers_high = vers_low = time_sec = time_usec = 0;
} else {
time_sec = other->time_sec;
time_usec = other->time_usec;
vers_low = other->vers_low;
vers_high = other->vers_high;
}
WRITEUNLOCKV(this, "wu vers::assign");
}
/*
* Creates new 'vers' with next higher minor version.
* If minor version exceeds MAXLOW, bump up major version instead.
* Set timestamp to that of the current time.
*/
vers*
vers::nextminor()
{
READLOCK(this, NULL, "r vers::nextminor");
vers * newvers = new vers;
if (newvers == NULL) {
READUNLOCK(this, NULL, "ru vers::nextminor DB_MEMORY_LIMIT");
FATAL3("vers::nextminor: cannot allocation space",
DB_MEMORY_LIMIT, NULL);
}
struct timeval mt;
gettimeofday(&mt, NULL);
newvers->time_sec = (unsigned int) mt.tv_sec;
newvers->time_usec = (unsigned int) mt.tv_usec;
newvers->vers_low = (this->vers_low + 1);
newvers->vers_high = (this->vers_high);
if (newvers->vers_low >= MAXLOW){
newvers->vers_high++;
newvers->vers_low = 0;
}
READUNLOCK(this, newvers, "ru vers::nextminor");
return (newvers);
}
/*
* Creates new 'vers' with next higher major version.
* Set timestamp to that of the current time.
*/
vers*
vers::nextmajor()
{
READLOCK(this, NULL, "r vers::nextmajor");
vers * newvers = new vers;
if (newvers == NULL) {
READUNLOCK(this, NULL, "ru vers::nextmajor DB_MEMORY_LIMIT");
FATAL3("vers::nextminor: cannot allocation space",
DB_MEMORY_LIMIT, NULL);
}
struct timeval mt;
gettimeofday(&mt, NULL);
newvers->time_sec = (unsigned int) mt.tv_sec;
newvers->time_usec = (unsigned int) mt.tv_usec;
newvers->vers_low = 0;
newvers->vers_high = (this->vers_high+1);
READUNLOCK(this, newvers, "ru vers::nextmajor");
return (newvers);
}
/*
* Predicate indicating whether this vers is earlier than 'other' in
* terms of version numbers.
*/
bool_t
vers::earlier_than(vers *other)
{
int ret, lret;
if (other == NULL) {
syslog(LOG_ERR,
"vers::earlier_than: comparing against null vers");
return (FALSE);
}
READLOCK(this, FALSE, "r vers::earlier_than");
READLOCKNR(other, lret, "r other vers::earlier_than");
if (lret != 0) {
READUNLOCK(this, FALSE, "ru + r other vers::earlier_than");
return (FALSE);
}
if (other->vers_high > vers_high) ret = TRUE;
else if (other->vers_high < vers_high) ret = FALSE;
else if (other->vers_low > vers_low) ret = TRUE;
else ret = FALSE;
READUNLOCKNR(other, lret, "ru other vers::earlier_than");
READUNLOCK(this, ret, ((lret != 0) ?
"ru + ru other vers::earlier_than" :
"ru vers::earlier_than"));
return (ret);
}
/* Print the value of this 'vers' to specified file. */
void
vers::print(FILE* file)
{
char *thetime;
thetime = ctime((long *) (&(time_sec)));
thetime[strlen(thetime)-1] = 0;
READLOCKV(this, "r vers::print");
fprintf(file, "version=%u.%u %s:%u",
vers_high,
vers_low,
/* time_sec, */
thetime,
time_usec);
READUNLOCKV(this, "ru vers::print");
}
void
vers::zero() {
WRITELOCKV(this, "r vers::zero");
vers_high = vers_low = time_sec = time_usec = 0;
WRITEUNLOCKV(this, "ru vers::zero");
}
bool_t
vers::equal( vers *other) {
READLOCK(this, FALSE, "r vers::equal");
bool_t ret = other != NULL &&
vers_high == other->vers_high &&
vers_low == other->vers_low &&
time_sec == other->time_sec &&
time_usec == other->time_usec;
READUNLOCK(this, ret, "ru vers::equal");
return (ret);
};
|