a8f5ccc0756beaced60df91f09bd42e6e823b7ae
[openafs.git] / src / budb / struct_ops.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 #include <afs/param.h>
11 #include <afsconfig.h>
12
13 RCSID("$Header$");
14
15 #include <stdio.h>
16 #ifdef AFS_NT40_ENV
17 #include <winsock2.h>
18 #else
19 #include <netinet/in.h>
20 #include <sys/file.h>
21 #endif
22 #include <sys/types.h>
23 #include <afs/stds.h>
24 #include <afs/bubasics.h>
25 #include <rx/xdr.h>
26 #include <rx/rx.h>
27 #include <string.h>
28 #include "budb.h"
29 #include "budb_errs.h"
30 #include "database.h"
31
32
33 /* ----------------------------------
34  * structure printing utilities
35  * ----------------------------------
36  */
37
38 printDbHeader(ptr)
39      struct DbHeader *ptr;
40 {
41     printf("version = %d\n", ptr->dbversion);
42     printf("created = %s", ctime((time_t *)&ptr->created));
43     printf("cell = %s\n",ptr->cell);
44     printf("lastDumpId = %u\n", ptr->lastDumpId);
45     printf("lastInstanceId = %d\n", ptr->lastInstanceId);
46     printf("lastTapeId = %d\n", ptr->lastTapeId);
47 }
48
49 printDump(fid, dptr)
50      FILE *fid;
51      struct dump *dptr;
52 {
53     fprintf(fid,"id = %u\n", dptr->id);
54     fprintf(fid,"idHashChain = %d\n", dptr->idHashChain);
55     fprintf(fid,"name = %s\n", dptr->dumpName);
56     fprintf(fid,"vsname = %s\n", dptr->volumeSet);
57     fprintf(fid,"dumpPath = %s\n", dptr->dumpPath);
58     fprintf(fid,"nameHashChain = %d\n", dptr->nameHashChain);
59     fprintf(fid,"flags = 0x%x\n", dptr->flags);
60     fprintf(fid,"parent = %u\n", dptr->parent);
61     fprintf(fid,"created = %s", ctime((time_t *)&dptr->created));
62     fprintf(fid,"nVolumes = %d\n", dptr->nVolumes);
63     /* printTapeSet(&dptr->tapes); */
64     fprintf(fid,"firstTape = %d\n", dptr->firstTape);
65     /* printKtcPrincipal(&dptr->dumper); */
66
67 }
68
69 printDumpEntry(deptr)
70      struct budb_dumpEntry *deptr;
71 {
72     printf("id = %u\n", deptr->id);
73     printf("Initial id = %u\n", deptr->initialDumpID);
74     printf("Appended id = %u\n", deptr->appendedDumpID);
75     printf("parent = %u\n", deptr->parent);
76     printf("level = %d\n", deptr->level);
77     printf("flags = 0x%x", deptr->flags);
78        if (deptr->flags == 0)                   printf(": Successful");
79        if (deptr->flags & BUDB_DUMP_INCOMPLETE) printf(": Incomplete");
80        if (deptr->flags & BUDB_DUMP_TAPEERROR)  printf(": Tape error");
81        if (deptr->flags & BUDB_DUMP_INPROGRESS) printf(": In progress");
82        if (deptr->flags & BUDB_DUMP_ABORTED)    printf(": Aborted");
83        if (deptr->flags & BUDB_DUMP_ADSM)       printf(": (ADSM)");       /* XBSA interface to ADSM */
84        if (deptr->flags & BUDB_DUMP_BUTA)       printf(": (BUTA)");       /* buta dump */
85        printf("\n");
86     printf("volumeSet = %s\n", deptr->volumeSetName);
87     printf("dump path = %s\n", deptr->dumpPath);
88     printf("name = %s\n", deptr->name);
89     printf("created = %s", ctime((time_t *)&deptr->created));
90     printf("nVolumes = %d\n", deptr->nVolumes);
91
92     printTapeSet(&deptr->tapes, (deptr->flags & BUDB_DUMP_XBSA_NSS));
93     printPrincipal(&deptr->dumper);
94 }
95
96 /* printHashTable
97  *      print the hash table structure, i.e. the header structure.
98  */
99
100 printHashTable(fid, htptr)
101      FILE *fid;
102      struct hashTable *htptr;
103 {
104     fprintf(fid,"functionType = %d\n", htptr->functionType);
105     fprintf(fid,"threadOffset = %d\n", htptr->threadOffset);
106     fprintf(fid,"entries = %d\n", htptr->entries);
107     fprintf(fid,"length = %d\n", htptr->length);
108     fprintf(fid,"table = %d\n", htptr->table);
109     fprintf(fid,"progress = %d\n", htptr->progress);
110     fprintf(fid,"oldLength = %d\n", htptr->oldLength);
111     fprintf(fid,"oldTable = %d\n", htptr->oldTable);
112 }
113
114 /* printMemoryHashTable
115  *      print the hash table structure, i.e. the header structure.
116  */
117 printMemoryHashTable(fid, mhtptr)
118      FILE *fid;
119      struct memoryHashTable *mhtptr;
120 {
121     fprintf(fid,"threadOffset = %d\n", mhtptr->threadOffset);
122     fprintf(fid,"length = %d\n", mhtptr->length);
123     fprintf(fid,"progress = %d\n", mhtptr->progress);
124     fprintf(fid,"size = %d\n", mhtptr->size);
125     fprintf(fid,"oldsize = %d\n", mhtptr->oldSize);
126 }
127
128 printPrincipal(ptr)
129      struct ktc_principal *ptr;
130 {
131     printf("name = %s\n", ptr->name);
132     printf("instance = %s\n", ptr->instance);
133     printf("cell = %s\n", ptr->cell);
134 }
135
136 printStructDumpHeader(ptr)
137      struct structDumpHeader *ptr;
138 {
139     printf("type = %d\n", ptr->type);
140     printf("structure version = %d\n", ptr->structversion);
141     printf("size = %d bytes\n", ptr->size);
142 }
143
144 printTape(fid, tptr)
145      FILE *fid;
146      struct tape *tptr;
147 {
148     fprintf(fid,"name = %s\n", tptr->name);
149     fprintf(fid,"nameHashChain = %d\n", tptr->nameHashChain);
150     fprintf(fid,"flags = 0x%x\n", tptr->flags);
151     fprintf(fid,"written = %s", ctime((time_t *)&tptr->written));
152     fprintf(fid,"nMBytes = %d\n", tptr->nMBytes);
153     fprintf(fid,"nBytes = %d\n", tptr->nBytes);
154     fprintf(fid,"nFiles = %d\n", tptr->nFiles);
155     fprintf(fid,"nVolumes = %d\n", tptr->nVolumes);
156     fprintf(fid,"seq = %d\n", tptr->seq);
157     fprintf(fid,"dump = %d\n", tptr->dump);
158     fprintf(fid,"nextTape = %d\n", tptr->nextTape);
159     fprintf(fid,"firstVol = %d\n", tptr->firstVol);
160     fprintf(fid,"labelPos = %d\n", tptr->labelpos);
161     fprintf(fid,"useCount = %d\n", tptr->useCount);
162 }
163
164 printTapeEntry(teptr)
165      struct budb_tapeEntry *teptr;
166 {
167     printf("name = %s\n", teptr->name);
168     printf("flags = 0x%x", teptr->flags);
169        if (teptr->flags & BUDB_TAPE_TAPEERROR)    printf(": Error");
170        if (teptr->flags & BUDB_TAPE_DELETED)      printf(": Deleted");
171        if (teptr->flags & BUDB_TAPE_BEINGWRITTEN) printf(": In progress");
172        if (teptr->flags & BUDB_TAPE_ABORTED)      printf(": Aborted");
173        if (teptr->flags & BUDB_TAPE_STAGED)       printf(": Staged");
174        if (teptr->flags & BUDB_TAPE_WRITTEN)      printf(": Successful");
175        printf("\n");
176     printf("written = %s", ctime((time_t *)&teptr->written));
177     printf("expires = %s", cTIME((time_t *)&teptr->expires));
178     printf("kBytes Tape Used = %u\n", teptr->useKBytes);
179     printf("nMBytes Data = %d\n", teptr->nMBytes);
180     printf("nBytes  Data = %d\n", teptr->nBytes);
181     printf("nFiles = %d\n", teptr->nFiles);
182     printf("nVolumes = %d\n", teptr->nVolumes);
183     printf("seq = %d\n", teptr->seq);
184     printf("labelPos = %d\n", teptr->labelpos);
185     printf("useCount = %d\n", teptr->useCount);
186     printf("dump = %d\n", teptr->dump);
187 }
188
189 printTapeSet(tsptr, nss)
190      struct budb_tapeSet *tsptr;
191      afs_int32 nss;                 /* is the tapeserver name an accurate name */
192 {
193     printf("Group id  = %d\n",tsptr->id );
194     printf("tapeServer = %s%s\n",
195            tsptr->tapeServer, (nss?" (single server)":""));
196     printf("format = %s\n",tsptr->format);
197     printf("maxTapes = %d\n",tsptr->maxTapes);
198 /*  printf("a  = %d\n",tsptr->a ); */
199 /*  printf("b = %d\n",tsptr->b);   */
200     printf("Start Tape Seq = %d\n",tsptr->b);
201 }
202
203 printVolumeEntry(veptr)
204      struct budb_volumeEntry *veptr;
205 {
206     printf("name = %s\n", veptr->name);
207     printf("flags = 0x%x", veptr->flags);
208        if (veptr->flags & BUDB_VOL_TAPEERROR) printf(": Tape Error");
209        if (veptr->flags & BUDB_VOL_FILEERROR) printf(": File Error");
210        if (veptr->flags & BUDB_VOL_BEINGWRITTEN) printf(": In progress");
211        if (veptr->flags & BUDB_VOL_FIRSTFRAG)    printf(": First fragment");
212        if (veptr->flags & BUDB_VOL_LASTFRAG)     printf(": Last fragment");
213        if (veptr->flags & BUDB_VOL_ABORTED)      printf(": Aborted");
214        printf("\n");
215     printf("id = %d\n", veptr->id);
216     printf("server = %s\n", veptr->server);
217     printf("partition = %d\n", veptr->partition);
218     printf("tapeSeq = %d\n", veptr->tapeSeq);
219
220     printf("position = %d\n", veptr->position);
221     printf("clone = %s", ctime((time_t *)&veptr->clone));
222     printf("startByte = %d\n", veptr->startByte);
223     printf("nBytes = %d\n", veptr->nBytes);
224     printf("seq = %d\n", veptr->seq);
225
226     printf("dump = %d\n", veptr->dump);
227     printf("tape = %s\n", veptr->tape);
228 }
229   
230 printVolFragment(fid, vfptr)
231      FILE *fid;
232      struct volFragment *vfptr;
233 {
234     fprintf(fid,"vol = %d\n", vfptr->vol);
235     fprintf(fid,"sameNameChain = %d\n", vfptr->sameNameChain);
236     fprintf(fid,"tape = %d\n", vfptr->tape);
237     fprintf(fid,"sameTapeChain = %d\n", vfptr->sameTapeChain);
238     fprintf(fid,"position = %d\n", vfptr->position);
239     fprintf(fid,"clone = %s", ctime((time_t *)&vfptr->clone));
240     fprintf(fid,"incTime = %s", ctime((time_t *)&vfptr->incTime));
241     fprintf(fid,"startByte = %d\n", vfptr->startByte);
242     fprintf(fid,"nBytes = %d\n", vfptr->nBytes);
243     fprintf(fid,"flags = %d\n", vfptr->flags);
244     fprintf(fid,"sequence = %d\n", vfptr->sequence);
245 }
246
247 printVolInfo(fid, viptr)
248      FILE *fid;
249      struct volInfo *viptr;
250 {
251     fprintf(fid,"name = %s\n", viptr->name);
252     fprintf(fid,"nameHashChain = %d\n", viptr->nameHashChain);
253     fprintf(fid,"id = %d\n", viptr->id);
254     fprintf(fid,"server = %s\n", viptr->server);
255     fprintf(fid,"partition = %d\n", viptr->partition);
256     fprintf(fid,"flags = 0x%x\n", viptr->flags);
257     fprintf(fid,"sameNameHead = %d\n", viptr->sameNameHead);
258     fprintf(fid,"sameNameChain = %d\n", viptr->sameNameChain);
259     fprintf(fid,"firstFragment = %d\n", viptr->firstFragment);
260     fprintf(fid,"nFrags = %d\n", viptr->nFrags);
261 }
262
263
264 /* -----------------------------------------
265  * structure xdr routines
266  * ----------------------------------------- 
267  */
268
269 /* utilities - network to host conversion
270  *      currently used for debug only
271  */
272
273 volFragment_ntoh(netVfPtr, hostVfPtr)
274      struct volFragment *netVfPtr, *hostVfPtr;
275 {
276     hostVfPtr->vol = ntohl(netVfPtr->vol);
277     hostVfPtr->sameNameChain = ntohl(netVfPtr->sameNameChain);
278     hostVfPtr->tape = ntohl(netVfPtr->tape);
279     hostVfPtr->sameTapeChain = ntohl(netVfPtr->sameTapeChain);
280     hostVfPtr->position = ntohl(netVfPtr->position);
281     hostVfPtr->clone = ntohl(netVfPtr->clone);
282     hostVfPtr->incTime = ntohl(netVfPtr->incTime);
283     hostVfPtr->startByte = ntohl(netVfPtr->startByte);
284     hostVfPtr->nBytes = ntohl(netVfPtr->nBytes);
285     hostVfPtr->flags = ntohs(netVfPtr->flags);
286     hostVfPtr->sequence = ntohs(netVfPtr->sequence);
287 }
288
289 volInfo_ntoh(netViPtr, hostViPtr)
290      struct volInfo *netViPtr, *hostViPtr;
291 {
292     strcpy(hostViPtr->name, netViPtr->name);
293     hostViPtr->nameHashChain = ntohl(netViPtr->nameHashChain);
294     hostViPtr->id = ntohl(netViPtr->id);
295     strcpy(hostViPtr->server, netViPtr->server);
296     hostViPtr->partition = ntohl(netViPtr->partition);
297     hostViPtr->flags = ntohl(netViPtr->flags);
298     hostViPtr->sameNameHead = ntohl(netViPtr->sameNameHead);
299     hostViPtr->sameNameChain = ntohl(netViPtr->sameNameChain);
300     hostViPtr->firstFragment = ntohl(netViPtr->firstFragment);
301     hostViPtr->nFrags = ntohl(netViPtr->nFrags);
302 }
303
304 tape_ntoh(netTapePtr, hostTapePtr)
305      struct tape *netTapePtr, *hostTapePtr;
306 {
307     strcpy(hostTapePtr->name, netTapePtr->name);
308     hostTapePtr->nameHashChain = ntohl(netTapePtr->nameHashChain);
309     hostTapePtr->flags = ntohl(netTapePtr->flags);
310
311     /* tape id conversion here */
312     hostTapePtr->written = ntohl(netTapePtr->written);
313     hostTapePtr->nMBytes = ntohl(netTapePtr->nMBytes);
314     hostTapePtr->nBytes = ntohl(netTapePtr->nBytes);
315     hostTapePtr->nFiles = ntohl(netTapePtr->nFiles);
316     hostTapePtr->nVolumes = ntohl(netTapePtr->nVolumes);
317     hostTapePtr->seq = ntohl(netTapePtr->seq);
318     hostTapePtr->dump = ntohl(netTapePtr->dump);
319     hostTapePtr->nextTape = ntohl(netTapePtr->nextTape);
320     hostTapePtr->labelpos = ntohl(netTapePtr->labelpos);
321     hostTapePtr->firstVol = ntohl(netTapePtr->firstVol);
322     hostTapePtr->useCount = ntohl(netTapePtr->useCount);
323 }
324
325 dump_ntoh(netDumpPtr, hostDumpPtr)
326      struct dump *netDumpPtr, *hostDumpPtr;
327 {
328     hostDumpPtr->id = ntohl(netDumpPtr->id);    
329     hostDumpPtr->idHashChain = ntohl(netDumpPtr->idHashChain);
330     strcpy(hostDumpPtr->dumpName, netDumpPtr->dumpName);
331     strcpy(hostDumpPtr->dumpPath, netDumpPtr->dumpPath);
332     strcpy(hostDumpPtr->volumeSet, netDumpPtr->volumeSet);
333     hostDumpPtr->nameHashChain = ntohl(netDumpPtr->nameHashChain);
334     hostDumpPtr->flags = ntohl(netDumpPtr->flags);
335     hostDumpPtr->parent = ntohl(netDumpPtr->parent);
336     hostDumpPtr->created = ntohl(netDumpPtr->created);
337     hostDumpPtr->nVolumes = ntohl(netDumpPtr->nVolumes);
338     hostDumpPtr->level = ntohl(netDumpPtr->level);
339
340     tapeSet_ntoh(&netDumpPtr->tapes, &hostDumpPtr->tapes);
341
342     hostDumpPtr->firstTape = ntohl(netDumpPtr->firstTape);
343
344     principal_ntoh(&netDumpPtr->dumper, &hostDumpPtr->dumper);
345 }
346
347 DbHeader_ntoh(netptr, hostptr)
348      struct DbHeader *netptr, *hostptr;
349 {
350     hostptr->dbversion = ntohl(netptr->dbversion);
351     hostptr->created = ntohl(netptr->created);
352     strcpy(hostptr->cell, netptr->cell);
353     hostptr->lastDumpId = ntohl(netptr->lastDumpId);
354     hostptr->lastInstanceId = ntohl(netptr->lastInstanceId);
355     hostptr->lastTapeId = ntohl(netptr->lastTapeId);
356 }
357
358 dumpEntry_ntoh(netptr, hostptr)
359      struct budb_dumpEntry *netptr, *hostptr;
360 {
361     hostptr->id = ntohl(netptr->id);
362     hostptr->initialDumpID = ntohl(netptr->initialDumpID);
363     hostptr->appendedDumpID = ntohl(netptr->appendedDumpID);
364     hostptr->parent = ntohl(netptr->parent);
365     hostptr->level = ntohl(netptr->level);
366     hostptr->flags = ntohl(netptr->flags);
367     strcpy(hostptr->volumeSetName, netptr->volumeSetName);
368     strcpy(hostptr->dumpPath, netptr->dumpPath);
369     strcpy(hostptr->name, netptr->name);
370     hostptr->created = ntohl(netptr->created);
371     hostptr->incTime = ntohl(netptr->incTime);
372     hostptr->nVolumes = ntohl(netptr->nVolumes);
373
374     tapeSet_ntoh(&netptr->tapes, &hostptr->tapes);
375     principal_ntoh(&netptr->dumper, &hostptr->dumper);
376 }
377
378 principal_hton(hostptr, netptr)
379      struct ktc_principal *hostptr, *netptr;
380 {
381     strcpy(netptr->name, hostptr->name);
382     strcpy(netptr->instance, hostptr->instance);
383     strcpy(netptr->cell, hostptr->cell);
384 }
385
386 principal_ntoh(netptr, hostptr)
387      struct ktc_principal *netptr, *hostptr;
388 {
389     strcpy(hostptr->name, netptr->name);
390     strcpy(hostptr->instance, netptr->instance);
391     strcpy(hostptr->cell, netptr->cell);
392 }
393
394 structDumpHeader_hton(hostPtr, netPtr)
395      struct structDumpHeader *hostPtr, *netPtr;
396 {
397     netPtr->type = htonl(hostPtr->type);
398     netPtr->structversion = htonl(hostPtr->structversion);
399     netPtr->size = htonl(hostPtr->size);
400 }
401
402 structDumpHeader_ntoh(netPtr, hostPtr)
403      struct structDumpHeader *hostPtr, *netPtr;
404 {
405     hostPtr->type = ntohl(netPtr->type);
406     hostPtr->structversion = ntohl(netPtr->structversion);
407     hostPtr->size = ntohl(netPtr->size);
408 }
409
410 tapeEntry_ntoh(netptr, hostptr)
411      struct budb_tapeEntry *netptr, *hostptr;
412 {
413     strcpy(hostptr->name, netptr->name);
414     hostptr->flags = ntohl(netptr->flags);
415     hostptr->written = ntohl(netptr->written);
416     hostptr->expires = ntohl(netptr->expires);
417     hostptr->nMBytes = ntohl(netptr->nMBytes);
418     hostptr->nBytes = ntohl(netptr->nBytes);
419     hostptr->nFiles = ntohl(netptr->nFiles);
420     hostptr->nVolumes = ntohl(netptr->nVolumes);
421     hostptr->seq = ntohl(netptr->seq);
422     hostptr->labelpos = ntohl(netptr->labelpos);
423     hostptr->useCount = ntohl(netptr->useCount);
424     hostptr->useKBytes = ntohl(netptr->useKBytes);
425     hostptr->dump = ntohl(netptr->dump);
426 }
427
428 tapeSet_hton(hostptr, netptr)
429      struct budb_tapeSet *hostptr, *netptr;
430 {
431     netptr->id = htonl(hostptr->id);
432     strcpy(netptr->tapeServer, hostptr->tapeServer);    
433     strcpy(netptr->format, hostptr->format);    
434     netptr->maxTapes = htonl(hostptr->maxTapes);
435     netptr->a = htonl(hostptr->a);
436     netptr->b = htonl(hostptr->b);
437 }
438
439 tapeSet_ntoh(netptr, hostptr)
440      struct budb_tapeSet *netptr, *hostptr;
441 {
442     hostptr->id = ntohl(netptr->id);
443     strcpy(hostptr->tapeServer, netptr->tapeServer);    
444     strcpy(hostptr->format, netptr->format);    
445     hostptr->maxTapes = ntohl(netptr->maxTapes);
446     hostptr->a = ntohl(netptr->a);
447     hostptr->b = ntohl(netptr->b);
448 }
449
450 textBlock_hton(hostptr, netptr)
451      struct textBlock *hostptr, *netptr;
452 {
453     netptr->version = htonl(hostptr->version);
454     netptr->size = htonl(hostptr->size);
455     netptr->textAddr = htonl(hostptr->textAddr);
456     netptr->newsize = htonl(hostptr->newsize);
457     netptr->newTextAddr = htonl(hostptr->newTextAddr);
458 }
459
460 textBlock_ntoh(netptr, hostptr)
461      struct textBlock *netptr, *hostptr;
462 {
463     hostptr->version = ntohl(netptr->version);
464     hostptr->size = ntohl(netptr->size);
465     hostptr->textAddr = ntohl(netptr->textAddr);
466     hostptr->newsize = ntohl(netptr->newsize);
467     hostptr->newTextAddr = ntohl(netptr->newTextAddr);
468 }
469
470 textLock_hton(hostptr, netptr)
471      db_lockP   hostptr, netptr;
472 {
473     netptr->type = htonl(hostptr->type);
474     netptr->lockState = htonl(hostptr->lockState);
475     netptr->lockTime = htonl(hostptr->lockTime);
476     netptr->expires = htonl(hostptr->expires);
477     netptr->instanceId = htonl(hostptr->instanceId);
478     netptr->lockHost = htonl(hostptr->lockHost);
479 }
480
481 textLock_ntoh(netptr, hostptr)
482      db_lockP   netptr, hostptr;
483 {
484     hostptr->type = ntohl(netptr->type);
485     hostptr->lockState = ntohl(netptr->lockState);
486     hostptr->lockTime = ntohl(netptr->lockTime);
487     hostptr->expires = ntohl(netptr->expires);
488     hostptr->instanceId = ntohl(netptr->instanceId);
489     hostptr->lockHost = ntohl(netptr->lockHost);
490 }
491
492 volumeEntry_ntoh(netptr, hostptr)
493      struct budb_volumeEntry *netptr, *hostptr;
494 {
495     strcpy(hostptr->name, netptr->name);
496     hostptr->flags = ntohl(netptr->flags);
497     hostptr->id = ntohl(netptr->id);
498     strcpy(hostptr->server, netptr->server);
499     hostptr->partition = ntohl(netptr->partition);
500     hostptr->tapeSeq = ntohl(netptr->tapeSeq);
501
502     hostptr->position  = ntohl(netptr->position);
503     hostptr->clone = ntohl(netptr->clone);
504     hostptr->incTime = ntohl(netptr->incTime);
505     hostptr->startByte = ntohl(netptr->startByte);
506     hostptr->nBytes = ntohl(netptr->nBytes);
507     hostptr->seq = ntohl(netptr->seq);
508
509     hostptr->dump = ntohl(netptr->dump);
510     strcpy(hostptr->tape, netptr->tape);
511 }
512
513 /* -------------------------------------
514  * structure conversion & copy routines 
515  * -------------------------------------
516  */
517
518
519 copy_ktcPrincipal_to_budbPrincipal(ktcPtr, budbPtr)
520      struct ktc_principal *ktcPtr;
521      struct budb_principal *budbPtr;
522 {
523     strncpy(budbPtr->name, ktcPtr->name, sizeof(budbPtr->name));
524     strncpy(budbPtr->instance, ktcPtr->instance, sizeof(budbPtr->instance));
525     strncpy(budbPtr->cell, ktcPtr->cell, sizeof(budbPtr->cell));
526 }
527
528 /* dumpToBudbDump
529  * entry:
530  *      dumpPtr - host format
531  */
532
533 dumpToBudbDump(dumpPtr, budbDumpPtr)
534      dbDumpP dumpPtr;
535      struct budb_dumpEntry *budbDumpPtr;
536 {
537     budbDumpPtr->id = dumpPtr->id;
538     budbDumpPtr->initialDumpID = dumpPtr->initialDumpID;
539     budbDumpPtr->parent = dumpPtr->parent;
540     budbDumpPtr->level = dumpPtr->level;
541     budbDumpPtr->flags = dumpPtr->flags;
542
543     strcpy(budbDumpPtr->volumeSetName, dumpPtr->volumeSet);
544     strcpy(budbDumpPtr->dumpPath, dumpPtr->dumpPath);
545     strcpy(budbDumpPtr->name, dumpPtr->dumpName);
546
547     budbDumpPtr->created = dumpPtr->created;
548     budbDumpPtr->nVolumes = dumpPtr->nVolumes;
549
550     bcopy(&dumpPtr->tapes, &budbDumpPtr->tapes, sizeof(struct budb_tapeSet));
551     copy_ktcPrincipal_to_budbPrincipal(&dumpPtr->dumper, &budbDumpPtr->dumper);
552     return(0);
553 }
554
555 tapeToBudbTape(tapePtr, budbTapePtr)
556      struct tape *tapePtr;
557      struct budb_tapeEntry *budbTapePtr;
558 {
559     strcpy(budbTapePtr->name, tapePtr->name);
560     budbTapePtr->flags = tapePtr->flags;
561     budbTapePtr->written = tapePtr->written;
562     budbTapePtr->expires = tapePtr->expires;
563     budbTapePtr->nMBytes = tapePtr->nMBytes;
564     budbTapePtr->nBytes = tapePtr->nBytes;
565     budbTapePtr->nFiles = tapePtr->nFiles;
566     budbTapePtr->nVolumes = tapePtr->nVolumes;
567     budbTapePtr->seq = tapePtr->seq;
568     budbTapePtr->labelpos = tapePtr->labelpos;
569     budbTapePtr->useCount = tapePtr->useCount;
570     budbTapePtr->useKBytes = tapePtr->useKBytes;
571     return(0);
572 }
573
574 volsToBudbVol(volFragPtr, volInfoPtr, budbVolPtr)
575      struct volFragment *volFragPtr;
576      struct volInfo *volInfoPtr;
577      struct budb_volumeEntry *budbVolPtr;
578 {
579     strcpy(budbVolPtr->name, volInfoPtr->name);
580     budbVolPtr->flags = volInfoPtr->flags;
581     budbVolPtr->id = volInfoPtr->id;
582     strcpy(budbVolPtr->server, volInfoPtr->server);
583     budbVolPtr->partition = volInfoPtr->partition;
584     budbVolPtr->tapeSeq = 0;      /* Don't know it so mark invalid */
585
586     budbVolPtr->position = volFragPtr->position;
587     budbVolPtr->clone = volFragPtr->clone;
588     budbVolPtr->incTime = volFragPtr->incTime;
589     budbVolPtr->startByte = volFragPtr->startByte;
590     budbVolPtr->nBytes = volFragPtr->nBytes;
591     budbVolPtr->seq = volFragPtr->sequence;
592     return(0);
593 }
594
595 /* ----------------------------------
596  * structure initialization routines 
597  *  ---------------------------------
598  */
599
600 /* default_tapeset
601  *      this fills in the tape set with the current default tapeset
602  *      format;
603  * entry:
604  *      dumpname - volset.dumplevel
605  * exit:
606  *      0 - ok
607  *      n - error
608  */
609
610 default_tapeset(tapesetPtr, dumpname)
611      struct budb_tapeSet *tapesetPtr;
612      char *dumpname;
613 {
614     bzero(tapesetPtr, sizeof(*tapesetPtr));
615
616     strcpy(tapesetPtr->format, dumpname);
617     strcat(tapesetPtr->format, ".%d");
618     tapesetPtr->a = 1;
619     tapesetPtr->b = 1;
620     tapesetPtr->maxTapes = 0;
621 }