2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 #include <afs/bubasics.h>
15 typedef afs_uint32 dbadr;
18 afs_int32 functionType; /* type of hash function */
19 afs_int32 threadOffset; /* Byte offset of hash thread */
20 afs_int32 entries; /* number of entries in hash table */
21 afs_int32 length; /* number of hash table slots */
22 dbadr table; /* pointer to actual table */
23 afs_int32 progress; /* number empty buckets in oldTable */
24 afs_int32 oldLength; /* slots in old table */
25 dbadr oldTable; /* old table */
28 /* text blocks and related structures */
31 afs_uint32 version; /* for access consistency checks */
32 afs_int32 size; /* size in bytes */
33 dbadr textAddr; /* list of blocks */
34 afs_int32 newsize; /* replacement size */
35 dbadr newTextAddr; /* list of new blocks */
39 afs_int32 type; /* user defined - for consistency checks */
40 afs_int32 lockState; /* locked/free */
41 afs_int32 lockTime; /* when locked */
42 afs_int32 expires; /* when timeout expires */
43 afs_int32 instanceId; /* user instance id */
44 int lockHost; /* locking host, if possible */
47 typedef struct db_lockS db_lockT;
48 typedef db_lockT *db_lockP;
50 /* hash table function types */
51 #define HT_dumpIden_FUNCTION 1
52 #define HT_dumpName_FUNCTION 2
53 #define HT_tapeName_FUNCTION 3
54 #define HT_volName_FUNCTION 4
56 #define HT_MAX_FUNCTION 4
61 #define volFragment_BLOCK 1
62 #define volInfo_BLOCK 2
65 #define MAX_STRUCTURE_BLOCK_TYPE 4
66 #define hashTable_BLOCK 5
70 /* This defines root pointers to all parts of the database. It is allocated
71 starting at location zero. */
73 #define BUDB_VERSION 1
76 afs_int32 version; /* database version number */
77 dumpId lastDumpId; /* last dump id value */
78 afs_uint32 lastTapeId; /* last tape id allocated */
79 afs_uint32 lastInstanceId; /* last instance Id handed out */
80 dbadr freePtrs[NBLOCKTYPES]; /* pointers to free blocks */
81 dbadr eofPtr; /* first free byte in db */
82 afs_int32 nHTBuckets; /* size of hashtable blocks */
83 Date lastUpdate; /* time of last change to database */
84 afs_int32 ptrs[10]; /* spare pointers */
85 struct hashTable volName; /* hash tables */
86 struct hashTable tapeName;
87 struct hashTable dumpName;
88 struct hashTable dumpIden;
89 db_lockT textLocks[TB_MAX]; /* locks for text blocks */
90 struct textBlock textBlock[TB_MAX]; /* raw text information */
91 afs_int32 words[10]; /* spare words */
92 afs_int32 checkVersion; /* version# for consistency checking */
95 /* The database is composed of several types of structures of different sizes.
96 To simplify recovery from crashes, allocation is done in fixed size blocks.
97 All structures in a block are of the same type. Each block has a header
98 which identifies its type, a count of the number of free structures, and a
99 pointer to the next block of the same type. */
101 #define BLOCKSIZE 2048
102 #define BlockBase(a) \
103 ((((a) - sizeof(struct dbHeader)) & ~(BLOCKSIZE-1)) + \
104 sizeof(struct dbHeader))
107 char type; /* type: implies structure size */
108 char flags; /* miscellaneous bits */
109 short nFree; /* number of free structures */
110 dbadr next; /* next free block same type */
113 #define BLOCK_DATA_SIZE (BLOCKSIZE-sizeof(struct blockHeader))
116 struct blockHeader h;
117 char a[BLOCKSIZE - sizeof(struct blockHeader)];
120 #define NhtBucketS ((BLOCKSIZE-sizeof(struct blockHeader))/sizeof(dbadr))
122 struct blockHeader h;
123 dbadr bucket[NhtBucketS];
126 /* The database contains one volFragment for every occurence of volume data on
129 #define VOLFRAGMENTFLAGS 0xffff
131 dbadr vol; /* full volume info */
132 dbadr sameNameChain; /* next with same vol info */
133 dbadr tape; /* tape containing this fragment */
134 dbadr sameTapeChain; /* next fragment on tape */
136 afs_int32 position; /* on tape */
137 Date clone; /* clone date of volume */
138 Date incTime; /* time for incremental; 0 => full */
139 afs_int32 startByte; /* first byte of volume in this frag */
140 afs_uint32 nBytes; /* bytes in fragment */
141 short flags; /* miscellaneous bits */
142 short sequence; /* seq of frag in dumped volume */
144 #define NvolFragmentS 45
146 struct blockHeader h;
148 struct volFragment s;
154 /* This represents additional information about a file system volume that
155 * changes relatively infrequently. Its purpose is to minimize the size of the
156 * folFragment structure. */
158 #define VOLINFOFLAGS 0xffff0000
160 char name[BU_MAXNAMELEN]; /* name of volume: the hash key */
161 afs_int32 flags; /* miscellaneous bits */
162 afs_int32 id; /* read-write volume's id */
163 char server[BU_MAXHOSTLEN]; /* file server */
164 afs_int32 partition; /* disk partition on server */
165 afs_int32 nFrags; /* number of fragments on list */
167 dbadr nameHashChain; /* for volume name hash table */
168 dbadr sameNameHead; /* volInfo of first struct this name */
169 dbadr sameNameChain; /* next volume with this name */
170 dbadr firstFragment; /* all volFragment with this volInfo */
174 struct blockHeader h;
182 /* The tape structure represents information of every physical tape in the
183 * backup system. Some of the data may persist event though the tape's
184 * contents are repeatedly overwritten. */
187 char name[BU_MAXTAPELEN]; /* name of physical tape */
188 afs_int32 flags; /* miscellaneous bits */
189 Date written; /* tape writing started */
190 Date expires; /* expiration date */
191 afs_uint32 nMBytes; /* length of tape in Mbytes */
192 afs_uint32 nBytes; /* remainder of Mbytes */
193 afs_int32 nFiles; /* ditto for EOFs */
194 afs_int32 nVolumes; /* ditto for volume fragments */
195 afs_int32 seq; /* sequence in tapeSet */
197 afs_uint32 labelpos; /* Position of the tape label */
198 afs_int32 useCount; /* # of times used */
199 afs_int32 useKBytes; /* How much of tape is used (in KBytes) */
201 dbadr nameHashChain; /* for tape name hash table */
202 dbadr dump; /* dump (tapeSet) this is part of */
203 dbadr nextTape; /* next tape in dump (tapeSet) */
204 dbadr firstVol; /* first volume fragment on tape */
209 struct blockHeader h;
216 /* The structure describes every dump operation whose contents are still availe
217 * on at least one tape.
221 /* similar to budb_dumpEntry */
222 afs_int32 id; /* unique identifier for dump */
223 dumpId parent; /* parent dump */
224 afs_int32 level; /* dump level */
225 afs_int32 flags; /* miscellaneous bits */
226 char volumeSet[BU_MAXNAMELEN]; /* name of volume that was dumped */
227 char dumpPath[BU_MAX_DUMP_PATH]; /* "path" name of dump level */
228 char dumpName[BU_MAXNAMELEN]; /* dump name */
229 Date created; /* time dump initiated */
230 /* Date incTime; target time for incremental dumps */
231 afs_int32 nVolumes; /* number of volumes in dump */
232 struct budb_tapeSet tapes; /* tapes for this dump */
233 struct ktc_principal dumper; /* user doing dump */
234 afs_uint32 initialDumpID; /* The dumpid of the initisl dump (for appended dumps) */
235 dbadr appendedDumpChain; /* Ptr to dump appended to this dump */
237 dbadr idHashChain; /* for dump id hash table */
238 dbadr nameHashChain; /* for dump name hash table */
239 dbadr firstTape; /* first tape in dump (tapeSet) */
242 typedef struct dump dbDumpT;
243 typedef dbDumpT *dbDumpP;
247 struct blockHeader h;
254 /* This structure is used to cache the hash table blocks for a database hash
255 table. The htBlock structure is modified slightly to accomodate this
256 mechanism. On disk the next ptr links the consecutive blocks of the hash
257 table together. In memory this information is inferred */
259 struct memoryHTBlock {
260 int valid; /* block needs to be read in */
261 dbadr a; /* where stored in db */
265 struct memoryHashTable {
266 struct hashTable *ht; /* ptr to appropriate db.h hashtable */
267 /* these are host byte order version of the corresponding HT fields */
268 int threadOffset; /* Byte offset of hash thread */
269 int length; /* number of hash table slots */
270 int oldLength; /* slots in old table */
271 int progress; /* number empty buckets in oldTable */
272 /* these are the memory copies of the hash table buckets */
273 int size; /* allocated size of array */
274 struct memoryHTBlock *(*blocks); /* ptr to array of ht block pointers */
275 int oldSize; /* ditto for old HT */
276 struct memoryHTBlock *(*oldBlocks);
279 struct memoryDB { /* in core copies of database structures */
283 struct memoryHashTable volName;
284 struct memoryHashTable tapeName;
285 struct memoryHashTable dumpName;
286 struct memoryHashTable dumpIden;
287 struct textBlock textBlock[TB_NUM];
289 extern struct memoryDB db;
291 #define set_header_word(ut,field,value) \
292 dbwrite ((ut), ((char *)&(db.h.field) - (char *)&db.h), \
293 ((db.h.field = (value)), (char *)&(db.h.field)), \
296 #define set_word_offset(ut,a,b,offset,value) \
297 dbwrite ((ut), (a)+(offset), \
298 (*(afs_int32 *)((char *)(b) + (offset)) = (value), \
299 (char *)((char *)(b) + (offset))), \
302 #define set_word_addr(ut,a,b,addr,value) \
303 dbwrite ((ut), (a)+((char *)(addr) - (char *)(b)), \
304 (*(afs_int32 *)(addr) = (value), \
309 /* simple min/max macros */
310 #define MIN(x,y) ((x) < (y) ? (x) : (y))
311 #define MAX(x,y) ((x) > (y) ? (x) : (y))
314 struct memoryHashTable *ht_GetType();
315 extern afs_uint32 ht_HashEntry();
316 extern dbadr ht_LookupBucket();