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