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