budb-prototypes-20090316
[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 RCSID
14     ("$Header$");
15
16 #include <stdio.h>
17 #ifdef AFS_NT40_ENV
18 #include <winsock2.h>
19 #else
20 #include <netinet/in.h>
21 #include <sys/file.h>
22 #endif
23 #include <sys/types.h>
24 #include <afs/stds.h>
25 #include <afs/bubasics.h>
26 #include <rx/xdr.h>
27 #include <rx/rx.h>
28 #include <string.h>
29 #include "budb.h"
30 #include "budb_errs.h"
31 #include "database.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     strcpy(hostDumpPtr->dumpName, netDumpPtr->dumpName);
368     strcpy(hostDumpPtr->dumpPath, netDumpPtr->dumpPath);
369     strcpy(hostDumpPtr->volumeSet, netDumpPtr->volumeSet);
370     hostDumpPtr->nameHashChain = ntohl(netDumpPtr->nameHashChain);
371     hostDumpPtr->flags = ntohl(netDumpPtr->flags);
372     hostDumpPtr->parent = ntohl(netDumpPtr->parent);
373     hostDumpPtr->created = ntohl(netDumpPtr->created);
374     hostDumpPtr->nVolumes = ntohl(netDumpPtr->nVolumes);
375     hostDumpPtr->level = ntohl(netDumpPtr->level);
376
377     tapeSet_ntoh(&netDumpPtr->tapes, &hostDumpPtr->tapes);
378
379     hostDumpPtr->firstTape = ntohl(netDumpPtr->firstTape);
380
381     principal_ntoh(&netDumpPtr->dumper, &hostDumpPtr->dumper);
382 }
383
384 void
385 DbHeader_ntoh(struct DbHeader *netptr, 
386               struct DbHeader *hostptr)
387 {
388     hostptr->dbversion = ntohl(netptr->dbversion);
389     hostptr->created = ntohl(netptr->created);
390     strcpy(hostptr->cell, netptr->cell);
391     hostptr->lastDumpId = ntohl(netptr->lastDumpId);
392     hostptr->lastInstanceId = ntohl(netptr->lastInstanceId);
393     hostptr->lastTapeId = ntohl(netptr->lastTapeId);
394 }
395
396 void
397 dumpEntry_ntoh(struct budb_dumpEntry *netptr, 
398                struct budb_dumpEntry *hostptr)
399 {
400     hostptr->id = ntohl(netptr->id);
401     hostptr->initialDumpID = ntohl(netptr->initialDumpID);
402     hostptr->appendedDumpID = ntohl(netptr->appendedDumpID);
403     hostptr->parent = ntohl(netptr->parent);
404     hostptr->level = ntohl(netptr->level);
405     hostptr->flags = ntohl(netptr->flags);
406     strcpy(hostptr->volumeSetName, netptr->volumeSetName);
407     strcpy(hostptr->dumpPath, netptr->dumpPath);
408     strcpy(hostptr->name, netptr->name);
409     hostptr->created = ntohl(netptr->created);
410     hostptr->incTime = ntohl(netptr->incTime);
411     hostptr->nVolumes = ntohl(netptr->nVolumes);
412
413     tapeSet_ntoh(&netptr->tapes, &hostptr->tapes);
414     principal_ntoh(&netptr->dumper, &hostptr->dumper);
415 }
416
417 void
418 principal_hton(struct budb_principal *hostptr, 
419                struct budb_principal *netptr)
420 {
421     strcpy(netptr->name, hostptr->name);
422     strcpy(netptr->instance, hostptr->instance);
423     strcpy(netptr->cell, hostptr->cell);
424 }
425
426 void
427 principal_ntoh(struct budb_principal *netptr, 
428                struct budb_principal *hostptr)
429 {
430     strcpy(hostptr->name, netptr->name);
431     strcpy(hostptr->instance, netptr->instance);
432     strcpy(hostptr->cell, netptr->cell);
433 }
434
435 void
436 structDumpHeader_hton(struct structDumpHeader *hostPtr, 
437                       struct structDumpHeader *netPtr)
438 {
439     netPtr->type = htonl(hostPtr->type);
440     netPtr->structversion = htonl(hostPtr->structversion);
441     netPtr->size = htonl(hostPtr->size);
442 }
443
444 void
445 structDumpHeader_ntoh(struct structDumpHeader *netPtr, 
446                       struct structDumpHeader *hostPtr)
447 {
448     hostPtr->type = ntohl(netPtr->type);
449     hostPtr->structversion = ntohl(netPtr->structversion);
450     hostPtr->size = ntohl(netPtr->size);
451 }
452
453 void
454 tapeEntry_ntoh(struct budb_tapeEntry *netptr, 
455                struct budb_tapeEntry *hostptr)
456 {
457     strcpy(hostptr->name, netptr->name);
458     hostptr->flags = ntohl(netptr->flags);
459     hostptr->written = ntohl(netptr->written);
460     hostptr->expires = ntohl(netptr->expires);
461     hostptr->nMBytes = ntohl(netptr->nMBytes);
462     hostptr->nBytes = ntohl(netptr->nBytes);
463     hostptr->nFiles = ntohl(netptr->nFiles);
464     hostptr->nVolumes = ntohl(netptr->nVolumes);
465     hostptr->seq = ntohl(netptr->seq);
466     hostptr->labelpos = ntohl(netptr->labelpos);
467     hostptr->useCount = ntohl(netptr->useCount);
468     hostptr->useKBytes = ntohl(netptr->useKBytes);
469     hostptr->dump = ntohl(netptr->dump);
470 }
471
472 int
473 tapeSet_hton(struct budb_tapeSet *hostptr, 
474              struct budb_tapeSet *netptr)
475 {
476     netptr->id = htonl(hostptr->id);
477     strcpy(netptr->tapeServer, hostptr->tapeServer);
478     strcpy(netptr->format, hostptr->format);
479     netptr->maxTapes = htonl(hostptr->maxTapes);
480     netptr->a = htonl(hostptr->a);
481     netptr->b = htonl(hostptr->b);
482     return 0;
483 }
484
485 int
486 tapeSet_ntoh(struct budb_tapeSet *netptr, 
487              struct budb_tapeSet *hostptr)
488 {
489     hostptr->id = ntohl(netptr->id);
490     strcpy(hostptr->tapeServer, netptr->tapeServer);
491     strcpy(hostptr->format, netptr->format);
492     hostptr->maxTapes = ntohl(netptr->maxTapes);
493     hostptr->a = ntohl(netptr->a);
494     hostptr->b = ntohl(netptr->b);
495     return 0;
496 }
497
498 void
499 textBlock_hton(struct textBlock *hostptr, 
500                struct textBlock *netptr)
501 {
502     netptr->version = htonl(hostptr->version);
503     netptr->size = htonl(hostptr->size);
504     netptr->textAddr = htonl(hostptr->textAddr);
505     netptr->newsize = htonl(hostptr->newsize);
506     netptr->newTextAddr = htonl(hostptr->newTextAddr);
507 }
508
509 void
510 textBlock_ntoh(struct textBlock *netptr, 
511                struct textBlock *hostptr)
512 {
513     hostptr->version = ntohl(netptr->version);
514     hostptr->size = ntohl(netptr->size);
515     hostptr->textAddr = ntohl(netptr->textAddr);
516     hostptr->newsize = ntohl(netptr->newsize);
517     hostptr->newTextAddr = ntohl(netptr->newTextAddr);
518 }
519
520 void
521 textLock_hton(db_lockP hostptr, db_lockP netptr)
522 {
523     netptr->type = htonl(hostptr->type);
524     netptr->lockState = htonl(hostptr->lockState);
525     netptr->lockTime = htonl(hostptr->lockTime);
526     netptr->expires = htonl(hostptr->expires);
527     netptr->instanceId = htonl(hostptr->instanceId);
528     netptr->lockHost = htonl(hostptr->lockHost);
529 }
530
531 void
532 textLock_ntoh(db_lockP netptr, db_lockP hostptr)
533 {
534     hostptr->type = ntohl(netptr->type);
535     hostptr->lockState = ntohl(netptr->lockState);
536     hostptr->lockTime = ntohl(netptr->lockTime);
537     hostptr->expires = ntohl(netptr->expires);
538     hostptr->instanceId = ntohl(netptr->instanceId);
539     hostptr->lockHost = ntohl(netptr->lockHost);
540 }
541
542 void
543 volumeEntry_ntoh(struct budb_volumeEntry *netptr, 
544                  struct budb_volumeEntry *hostptr)
545 {
546     strcpy(hostptr->name, netptr->name);
547     hostptr->flags = ntohl(netptr->flags);
548     hostptr->id = ntohl(netptr->id);
549     strcpy(hostptr->server, netptr->server);
550     hostptr->partition = ntohl(netptr->partition);
551     hostptr->tapeSeq = ntohl(netptr->tapeSeq);
552
553     hostptr->position = ntohl(netptr->position);
554     hostptr->clone = ntohl(netptr->clone);
555     hostptr->incTime = ntohl(netptr->incTime);
556     hostptr->startByte = ntohl(netptr->startByte);
557     hostptr->nBytes = ntohl(netptr->nBytes);
558     hostptr->seq = ntohl(netptr->seq);
559
560     hostptr->dump = ntohl(netptr->dump);
561     strcpy(hostptr->tape, netptr->tape);
562 }
563
564 /* -------------------------------------
565  * structure conversion & copy routines 
566  * -------------------------------------
567  */
568
569 void
570 copy_ktcPrincipal_to_budbPrincipal(struct ktc_principal *ktcPtr,
571                                    struct budb_principal *budbPtr)
572 {
573     strncpy(budbPtr->name, ktcPtr->name, sizeof(budbPtr->name));
574     strncpy(budbPtr->instance, ktcPtr->instance, sizeof(budbPtr->instance));
575     strncpy(budbPtr->cell, ktcPtr->cell, sizeof(budbPtr->cell));
576 }
577
578 /* dumpToBudbDump
579  * entry:
580  *      dumpPtr - host format
581  */
582
583 int
584 dumpToBudbDump(dbDumpP dumpPtr, struct budb_dumpEntry *budbDumpPtr)
585 {
586     budbDumpPtr->id = dumpPtr->id;
587     budbDumpPtr->initialDumpID = dumpPtr->initialDumpID;
588     budbDumpPtr->parent = dumpPtr->parent;
589     budbDumpPtr->level = dumpPtr->level;
590     budbDumpPtr->flags = dumpPtr->flags;
591
592     strcpy(budbDumpPtr->volumeSetName, dumpPtr->volumeSet);
593     strcpy(budbDumpPtr->dumpPath, dumpPtr->dumpPath);
594     strcpy(budbDumpPtr->name, dumpPtr->dumpName);
595
596     budbDumpPtr->created = dumpPtr->created;
597     budbDumpPtr->nVolumes = dumpPtr->nVolumes;
598
599     memcpy(&budbDumpPtr->tapes, &dumpPtr->tapes, sizeof(struct budb_tapeSet));
600     copy_ktcPrincipal_to_budbPrincipal(&dumpPtr->dumper,
601                                        &budbDumpPtr->dumper);
602     return (0);
603 }
604
605 int
606 tapeToBudbTape(struct tape *tapePtr, struct budb_tapeEntry *budbTapePtr)
607 {
608     strcpy(budbTapePtr->name, tapePtr->name);
609     budbTapePtr->flags = tapePtr->flags;
610     budbTapePtr->written = tapePtr->written;
611     budbTapePtr->expires = tapePtr->expires;
612     budbTapePtr->nMBytes = tapePtr->nMBytes;
613     budbTapePtr->nBytes = tapePtr->nBytes;
614     budbTapePtr->nFiles = tapePtr->nFiles;
615     budbTapePtr->nVolumes = tapePtr->nVolumes;
616     budbTapePtr->seq = tapePtr->seq;
617     budbTapePtr->labelpos = tapePtr->labelpos;
618     budbTapePtr->useCount = tapePtr->useCount;
619     budbTapePtr->useKBytes = tapePtr->useKBytes;
620     return (0);
621 }
622
623 int
624 volsToBudbVol(struct volFragment *volFragPtr, struct volInfo *volInfoPtr,
625               struct budb_volumeEntry *budbVolPtr)
626 {
627     strcpy(budbVolPtr->name, volInfoPtr->name);
628     budbVolPtr->flags = volInfoPtr->flags;
629     budbVolPtr->id = volInfoPtr->id;
630     strcpy(budbVolPtr->server, volInfoPtr->server);
631     budbVolPtr->partition = volInfoPtr->partition;
632     budbVolPtr->tapeSeq = 0;    /* Don't know it so mark invalid */
633
634     budbVolPtr->position = volFragPtr->position;
635     budbVolPtr->clone = volFragPtr->clone;
636     budbVolPtr->incTime = volFragPtr->incTime;
637     budbVolPtr->startByte = volFragPtr->startByte;
638     budbVolPtr->nBytes = volFragPtr->nBytes;
639     budbVolPtr->seq = volFragPtr->sequence;
640     return (0);
641 }
642
643 /* ----------------------------------
644  * structure initialization routines 
645  *  ---------------------------------
646  */
647
648 /* default_tapeset
649  *      this fills in the tape set with the current default tapeset
650  *      format;
651  * entry:
652  *      dumpname - volset.dumplevel
653  * exit:
654  *      0 - ok
655  *      n - error
656  */
657
658 int
659 default_tapeset(struct budb_tapeSet *tapesetPtr, char *dumpname)
660 {
661     memset(tapesetPtr, 0, sizeof(*tapesetPtr));
662
663     strcpy(tapesetPtr->format, dumpname);
664     strcat(tapesetPtr->format, ".%d");
665     tapesetPtr->a = 1;
666     tapesetPtr->b = 1;
667     tapesetPtr->maxTapes = 0;
668     return 0;
669 }