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