1 /* Copyright (C) 1989,1990 Transarc Corporation - All rights reserved */
3 * (C) COPYRIGHT IBM CORPORATION 1989
4 * LICENSED MATERIALS - PROPERTY OF IBM
9 #include <afs/bubasics.h>
13 typedef afs_uint32 dbadr;
16 afs_int32 functionType; /* type of hash function */
17 afs_int32 threadOffset; /* Byte offset of hash thread */
18 afs_int32 entries; /* number of entries in hash table */
19 afs_int32 length; /* number of hash table slots */
20 dbadr table; /* pointer to actual table */
21 afs_int32 progress; /* number empty buckets in oldTable */
22 afs_int32 oldLength; /* slots in old table */
23 dbadr oldTable; /* old table */
26 /* text blocks and related structures */
30 afs_uint32 version; /* for access consistency checks */
31 afs_int32 size; /* size in bytes */
32 dbadr textAddr; /* list of blocks */
33 afs_int32 newsize; /* replacement size */
34 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. */
188 char name[BU_MAXTAPELEN]; /* name of physical tape */
189 afs_int32 flags; /* miscellaneous bits */
190 Date written; /* tape writing started */
191 Date expires; /* expiration date */
192 afs_uint32 nMBytes; /* length of tape in Mbytes */
193 afs_uint32 nBytes; /* remainder of Mbytes */
194 afs_int32 nFiles; /* ditto for EOFs */
195 afs_int32 nVolumes; /* ditto for volume fragments */
196 afs_int32 seq; /* sequence in tapeSet */
198 afs_uint32 labelpos; /* Position of the tape label */
199 afs_int32 useCount; /* # of times used */
200 afs_int32 useKBytes; /* How much of tape is used (in KBytes) */
202 dbadr nameHashChain; /* for tape name hash table */
203 dbadr dump; /* dump (tapeSet) this is part of */
204 dbadr nextTape; /* next tape in dump (tapeSet) */
205 dbadr firstVol; /* first volume fragment on tape */
210 struct blockHeader h;
217 /* The structure describes every dump operation whose contents are still availe
218 * on at least one tape.
223 /* similar to budb_dumpEntry */
224 afs_int32 id; /* unique identifier for dump */
225 dumpId parent; /* parent dump */
226 afs_int32 level; /* dump level */
227 afs_int32 flags; /* miscellaneous bits */
228 char volumeSet[BU_MAXNAMELEN]; /* name of volume that was dumped */
229 char dumpPath[BU_MAX_DUMP_PATH]; /* "path" name of dump level */
230 char dumpName[BU_MAXNAMELEN]; /* dump name */
231 Date created; /* time dump initiated */
232 /* Date incTime; target time for incremental dumps */
233 afs_int32 nVolumes; /* number of volumes in dump */
234 struct budb_tapeSet tapes; /* tapes for this dump */
235 struct ktc_principal dumper; /* user doing dump */
236 afs_uint32 initialDumpID; /* The dumpid of the initisl dump (for appended dumps) */
237 dbadr appendedDumpChain; /* Ptr to dump appended to this dump */
239 dbadr idHashChain; /* for dump id hash table */
240 dbadr nameHashChain; /* for dump name hash table */
241 dbadr firstTape; /* first tape in dump (tapeSet) */
244 typedef struct dump dbDumpT;
245 typedef dbDumpT *dbDumpP;
249 struct blockHeader h;
256 /* This structure is used to cache the hash table blocks for a database hash
257 table. The htBlock structure is modified slightly to accomodate this
258 mechanism. On disk the next ptr links the consecutive blocks of the hash
259 table together. In memory this information is inferred */
261 struct memoryHTBlock {
262 int valid; /* block needs to be read in */
263 dbadr a; /* where stored in db */
267 struct memoryHashTable {
268 struct hashTable *ht; /* ptr to appropriate db.h hashtable */
269 /* these are host byte order version of the corresponding HT fields */
270 int threadOffset; /* Byte offset of hash thread */
271 int length; /* number of hash table slots */
272 int oldLength; /* slots in old table */
273 int progress; /* number empty buckets in oldTable */
274 /* these are the memory copies of the hash table buckets */
275 int size; /* allocated size of array */
276 struct memoryHTBlock *(*blocks); /* ptr to array of ht block pointers */
277 int oldSize; /* ditto for old HT */
278 struct memoryHTBlock *(*oldBlocks);
281 struct memoryDB { /* in core copies of database structures */
285 struct memoryHashTable volName;
286 struct memoryHashTable tapeName;
287 struct memoryHashTable dumpName;
288 struct memoryHashTable dumpIden;
289 struct textBlock textBlock[TB_NUM];
291 extern struct memoryDB db;
293 #define set_header_word(ut,field,value) \
294 dbwrite ((ut), ((char *)&(db.h.field) - (char *)&db.h), \
295 ((db.h.field = (value)), (char *)&(db.h.field)), \
298 #define set_word_offset(ut,a,b,offset,value) \
299 dbwrite ((ut), (a)+(offset), \
300 (*(afs_int32 *)((char *)(b) + (offset)) = (value), \
301 (char *)((char *)(b) + (offset))), \
304 #define set_word_addr(ut,a,b,addr,value) \
305 dbwrite ((ut), (a)+((char *)(addr) - (char *)(b)), \
306 (*(afs_int32 *)(addr) = (value), \
311 /* simple min/max macros */
312 #define MIN(x,y) ((x) < (y) ? (x) : (y))
313 #define MAX(x,y) ((x) > (y) ? (x) : (y))
316 struct memoryHashTable *ht_GetType ();
317 extern afs_uint32 ht_HashEntry ();
318 extern dbadr ht_LookupBucket ();