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