2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include <afs/param.h>
17 #include <sys/types.h>
23 #include "cnvldb.h" /* CHANGEME! */
24 #include <netinet/in.h>
25 #include <afs/venus.h>
27 #include <afs/afsutil.h>
28 #include <afs/fileutil.h>
32 #define MAXSIZE 2048 /* most I'll get back from PIOCTL */
33 #define BADSERVERID 255 /* XXX */
36 extern struct cmd_syndesc *cmd_CreateSyntax();
37 static char pn[] = "cnvldb";
38 static char tempname[] = "XXnewvldb";
39 static char space[MAXSIZE];
40 static int MaxServers[3] = { 30, 254, 254 }; /* max server # permitted in this version */
42 static afs_int32 Conv4to3();
44 static int convert_vlentry();
45 static int rewrite_header();
47 static char tspace[1024]; /* chdir can't handle anything bigger, anyway */
48 /* return a static pointer to a buffer */
54 strcpy(tspace, apath);
55 tp = strrchr(tspace, '/');
64 int fromvers = 0, tovers = 0, showversion = 0;
67 char *pathname = NULL;
72 struct cmd_syndesc *as;
74 register struct cmd_item *ti;
75 register afs_int32 code;
76 int w, old, new, rc, dump = 0, fromv = 0;
78 char ubik[80]; /* space for some ubik header */
80 struct vlheader_1 header1;
81 struct vlheader_2 header2;
82 struct vlheader_3 header3;
83 } oldheader, oldheader1, newheader; /* large enough for either */
86 struct vlentry_1 entry1;
87 struct vlentry_2 entry2;
88 struct vlentry_3 entry3;
89 char mhinfo_block[VL_ADDREXTBLK_SIZE];
92 pathname = (as->parms[2].items ? as->parms[2].items->data : dbPath); /* -name */
93 showversion = (as->parms[3].items ? 1 : 0); /* -showversion */
94 dump = (as->parms[4].items ? 1 : 0); /* -dumpvldb */
95 fromvers = (as->parms[1].items ? atoi(as->parms[1].items->data) : 0); /* -fromversion */
96 tovers = (as->parms[0].items ? atoi(as->parms[0].items->data) : 0); /* -toversion */
98 /* should stat() the old vldb, get its size, and see if there's */
99 /* room for another. It might be in AFS, so check the quota, too */
100 old = open(pathname, O_RDONLY);
106 /* Read the version */
107 lseek(old, 64, L_SET);
108 read(old, &fromv, sizeof(int));
109 fromv = ntohl(fromv);
110 if ((fromv < 1) || (fromv > 4)) {
112 fprintf(stderr, ": Unrecognized VLDB version %d.\n", fromv);
116 /* Sequentially read the database converting the entries as we go */
117 lseek(old, 0, L_SET);
119 readheader(old, fromv, &oldheader);
121 dbsize = ntohl(oldheader.header1.vital_header.eofPtr);
122 fromv = ntohl(oldheader.header1.vital_header.vldbversion);
124 } else if (fromv == 2) {
125 dbsize = ntohl(oldheader.header2.vital_header.eofPtr);
126 fromv = ntohl(oldheader.header2.vital_header.vldbversion);
131 dbsize = ntohl(oldheader.header3.vital_header.eofPtr);
132 fromv = ntohl(oldheader.header3.vital_header.vldbversion);
133 mhaddr = ntohl(oldheader.header3.SIT);
135 /* Read the multihomed extent blocks in */
137 read_mhentries(mhaddr, old);
139 /* Position back to this after header */
140 lseek(old, pos + 64, L_SET);
144 if (showversion || dump) {
146 fprintf(stdout, "%s has a version of %d\n", pathname, fromv);
148 while (oldpos < dbsize) {
149 rc = readentry(old, fromv, &xvlentry);
150 if ((rc == 0) || (rc == EOF))
152 printentry(fromv, &xvlentry);
158 if (!fromvers) { /* not set */
160 } else if (fromvers != fromv) {
162 "%s has a version of %d while the -fromversion specified was %d - aborting\n",
163 pathname, fromv, fromvers);
167 if ((fromvers < 1) || (fromvers > 4)) {
169 fprintf(stderr, ": VLDB version %d is not supported.\n", fromvers);
171 fprintf(stderr, ": Only versions 1-4 are currently supported.\n");
176 tovers = fromvers + 1;
178 if (tovers < 1 || tovers > 4) {
180 fprintf(stderr, ": VLDB version %d is not supported.\n", tovers);
182 fprintf(stderr, ": Only versions 1 - 4 are currently supported.\n");
186 if (mhaddr && (tovers < 3)) {
188 fprintf(stderr, ": Cannot convert. VLDB contains multihome info.\n");
192 /* OK! let's get down to business... */
194 if (chdir(Parent(pathname))) {
199 new = open(tempname, O_WRONLY | O_CREAT | O_TRUNC, 0600);
205 /* Write the UBIK data */
206 w = write(new, ubik, 64);
208 printf("Write of ubik header failed %d; error %u\n", w, errno);
212 /* Because we know that all the vldb entries are the same size and type we
213 * can just read them sequentially, fiddle with the fields, and write
214 * them out again. If we invent a vldb format that has different
215 * types of entries, then we're going to have to invent new logic for
216 * converting the vldb-- we'll probably have to chase down the various
217 * linked lists in turn, doing lseeks and the like.
220 convert_header(old, new, fromvers, tovers, &oldheader, &newheader);
221 while (oldpos < dbsize) {
222 rc = readentry(old, fromvers, &xvlentry);
223 if ((rc == 0) || (rc == EOF))
225 convert_vlentry(new, fromvers, tovers, &oldheader, &newheader,
229 /* We have now finished sequentially reading and writing the database.
230 * Now randomly offset into database and update multihome entries.
232 convert_mhentries(old, new, &newheader, fromvers, tovers);
233 rewrite_header(new, tovers, &newheader);
242 renamefile(tempname, pathname);
248 readheader(fd, version, addr)
253 int hdrsize, size = 0;
257 hdrsize = sizeof(struct vlheader_1);
259 hdrsize = sizeof(struct vlheader_2);
261 size = read(fd, addr, hdrsize);
268 readentry(fd, version, addr)
274 struct vlentry_3 *vl3p = (struct vlentry_3 *)addr;
279 1) ? sizeof(struct vlentry_1) : sizeof(struct vlentry_2));
280 rc = read(fd, addr, toread);
282 printf("Partial read of vlentry at pos %u: %d\n", oldpos, rc);
286 /* Read a mhblock entry if there is one */
287 if ((rc > 0) && (vl3p->flags == VLCONTBLOCK)) {
288 if (!mhaddr) /* Remember first mh block */
289 mhaddr = oldpos - rc;
291 rc1 = read(fd, &addr[rc], VL_ADDREXTBLK_SIZE - rc);
292 if (rc1 != VL_ADDREXTBLK_SIZE - rc)
293 printf("Partial read of mhblock at pos %u: %d\n", oldpos + rc,
304 printentry(version, addr)
308 struct vlentry_2 *vl2p = (struct vlentry_2 *)addr;
309 struct vlentry_3 *vl3p = (struct vlentry_3 *)addr;
312 /* Don't print anything if the entry is a mh info block */
313 if (vl3p->flags == VLCONTBLOCK) {
317 if (version == 1 || version == 2) {
318 printf("%s\t%5d [%10d:%10d:%10d]%8X%8d\n", vl2p->name, vl2p->spares3,
319 vl2p->volumeId[0], vl2p->volumeId[1], vl2p->volumeId[2],
320 vl2p->flags, vl2p->LockAfsId);
321 printf("\t%8d%8d%8d [%7d%7d%7d]%7d% [%4d%4d%4d%4d][%4d%4d%4d%4d]\n",
322 vl2p->LockTimestamp, vl2p->cloneId, vl2p->spares0,
323 vl2p->nextIdHash[0], vl2p->nextIdHash[1], vl2p->nextIdHash[2],
324 vl2p->nextNameHash, vl2p->serverNumber[0],
325 vl2p->serverNumber[1], vl2p->serverNumber[2],
326 vl2p->serverNumber[3], vl2p->serverPartition[0],
327 vl2p->serverPartition[1], vl2p->serverPartition[2],
328 vl2p->serverPartition[3]);
329 printf("\t[%4d%4d%4d%4d]\n", vl2p->serverFlags[0],
330 vl2p->serverFlags[1], vl2p->serverFlags[2],
331 vl2p->serverFlags[3]);
332 } else { /* if (version >= 3) */
334 if (vl3p->flags == VLFREE)
336 printf("%s\tPos=%d NextIdHash=[%d:%d:%d] NextNameHash=%d\n",
337 vl3p->name, (oldpos - sizeof(struct vlentry_3)),
338 vl3p->nextIdHash[0], vl3p->nextIdHash[1], vl3p->nextIdHash[2],
340 printf("\tRW=%u RO=%u BK=%u CL=%u flags=0x%X lockBy=%d lockTime=%u\n",
341 vl3p->volumeId[0], vl3p->volumeId[1], vl3p->volumeId[2],
342 vl3p->cloneId, vl3p->flags, vl3p->LockAfsId,
343 vl3p->LockTimestamp);
344 for (i = 0; i < OMAXNSERVERS; i++) {
345 if ((vl3p->serverNumber[i] & 0xff) != 0xff) {
346 printf("\tServer=%d Partition=%d flags=%X\n",
347 vl3p->serverNumber[i], vl3p->serverPartition[i],
348 vl3p->serverFlags[i]);
355 int readmhentries = 0;
356 struct extentaddr *base[VL_MAX_ADDREXTBLKS];
358 /* Read the multihome extent blocks in. Check if they are good by
359 * verifying their address is not pass the EOF and the flags are good.
360 * If it's not good, then don't read the block in.
362 read_mhentries(mh_addr, oldfd)
374 /* Initialize base pointers */
375 for (j = 0; j < VL_MAX_ADDREXTBLKS; j++)
381 /* Check if the first extent block is beyond eof. If
382 * it is, it's not real.
384 if (mh_addr > dbsize - VL_ADDREXTBLK_SIZE)
387 /* Now read the first mh extent block */
388 code = lseek(oldfd, mh_addr + 64, L_SET);
390 perror("seek MH block");
393 base[0] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE);
398 code = read(oldfd, (char *)base[0], VL_ADDREXTBLK_SIZE);
399 if (code != VL_ADDREXTBLK_SIZE) {
400 perror("read MH block");
406 /* Verify that this block is the right one */
407 if (ntohl(base[0]->ex_flags) != VLCONTBLOCK) { /* check if flag is correct */
413 /* The first block contains pointers to the other extent blocks.
414 * Check to see if the pointers are good and read them in if they are.
417 for (j = 1; j < VL_MAX_ADDREXTBLKS; j++) {
418 if (!base[0]->ex_contaddrs[j])
421 sit = ntohl(base[0]->ex_contaddrs[j]);
423 /* Every time we allocate a new extent block, it is allocated after
424 * the previous ones. But it must be before the EOF.
426 if ((sit < (a + VL_ADDREXTBLK_SIZE))
427 || (sit > dbsize - VL_ADDREXTBLK_SIZE)) {
431 /* Read the extent block in */
433 code = lseek(oldfd, sit, L_SET);
435 perror("seek MH block");
438 base[j] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE);
443 code = read(oldfd, (char *)base[j], VL_ADDREXTBLK_SIZE);
444 if (code != VL_ADDREXTBLK_SIZE) {
445 perror("read MH block");
449 /* Verify that this block knows its an extent block */
450 if (ntohl(base[j]->ex_flags) != VLCONTBLOCK) {
456 /* The extent block passed our tests */
457 a = ntohl(base[0]->ex_contaddrs[j]);
461 /* Follow the SIT pointer in the header (mhaddr) to the multihomed
462 * extent blocks and verify that the pointers are good. And fix.
463 * Then convert the multihomed addresses to single address if we
464 * are converting back from version 4.
466 * Before this can be called, the routine read_mhentries must be called.
468 convert_mhentries(oldfd, newfd, header, fromver, tover)
470 struct vlheader_2 *header;
475 int i, j, modified = 0, w;
476 afs_uint32 raddr, addr;
477 struct extentaddr *exp;
480 /* Check if the header says the extent block exists. If
481 * it does, then read_mhentries should have read it in.
483 if (mhaddr && !base[0]) {
484 printf("Fix Bad base extent block pointer\n");
485 header->SIT = mhaddr = 0;
486 } else if (mhaddr && base[0]) {
488 if ((ntohl(header->SIT) != mhaddr) && (tover == 4)) {
490 ("Fix pointer to first base extent block. Was 0x%x, now 0x%x\n",
491 ntohl(header->SIT), mhaddr);
492 header->SIT = htonl(mhaddr);
495 /* Check if the first block points to itself. If not, then fix it */
496 if (ntohl(base[0]->ex_contaddrs[0]) != mhaddr) {
497 printf("Fix bad pointer in base extent block: Base 0\n");
498 base[0]->ex_contaddrs[0] = htonl(mhaddr);
502 /* The first block contains pointers to the other extent blocks.
503 * Check to see if the pointers are good.
505 for (j = 1; j < VL_MAX_ADDREXTBLKS; j++) {
506 /* Check if the base extent block says the extent blocks exist.
507 * If it does, then read_mhentries should have read it in.
509 if (base[0]->ex_contaddrs[j] && !base[j]) {
510 printf("Fix bad pointer in base extent block: Base %d\n", j);
511 base[0]->ex_contaddrs[j] = 0;
516 /* Now write out the base extent blocks if it changed */
518 code = lseek(newfd, mhaddr + 64, L_SET);
520 perror("seek MH Block");
523 w = write(newfd, (char *)base[0], VL_ADDREXTBLK_SIZE);
524 if (w != VL_ADDREXTBLK_SIZE) {
525 perror("write MH Block");
531 /* If we are converting from version 4 to version 3, then
532 * translate any multihome ptrs in the IpMappedAddr array
533 * to true IP addresses.
535 if ((fromver == 4) && (tover == 3)) {
536 /* Step through the fileserver addresses in the VLDB header
537 * and convert the pointers back to IP addresses.
539 for (i = 0; i < 254; i++) {
540 addr = ntohl(header->IpMappedAddr[i]);
541 if (addr && ((addr & 0xff000000) == 0xff000000)) {
542 basei = (addr >> 16) & 0xff;
543 index = addr & 0xffff;
545 if ((basei >= VL_ADDREXTBLK_SIZE) || !base[basei]) {
547 "Warning: mh entry %d has no IP address; ignored!!\n",
549 header->IpMappedAddr[i] = 0;
552 exp = &base[basei][index];
554 /* For now return the first ip address back */
555 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
556 if (exp->ex_addrs[j]) {
557 raddr = ntohl(exp->ex_addrs[j]);
561 if (j >= VL_MAXIPADDRS_PERMH) {
563 "Warning: mh entry %d has no ip address; ignored!!\n",
568 ("Multi-homed addr: converting to single ip address %d.%d.%d.%d\n",
569 (raddr >> 24 & 0xff), (raddr >> 16 & 0xff),
570 (raddr >> 8 & 0xff), (raddr & 0xff));
572 header->IpMappedAddr[i] = htonl(raddr);
575 header->SIT = mhaddr = 0; /* mhinfo block has been removed */
577 /* Now step through the hash tables in header updating them.
578 * Because we removed the mh info blocks and some entries they
579 * point to may have changed position.
582 for (i = 0; i < 8191; i++) {
583 header->VolnameHash[i] = Conv4to3(header->VolnameHash[i]);
586 for (i = 0; i < 3; i++) {
587 for (j = 0; j < 8191; j++) {
588 header->VolidHash[i][j] = Conv4to3(header->VolidHash[i][j]);
592 /* Update eofptr to take into account the removal of the mhinfo blocks */
593 header->vital_header.eofPtr = htonl(Conv4to3(dbsize));
598 convert_header(ofd, fd, fromv, tov, fromaddr, toaddr)
599 int ofd, fd, fromv, tov;
600 char *fromaddr, *toaddr;
602 struct vlheader_1 *tvp1;
603 struct vlheader_2 *tvp2;
608 memcpy(toaddr, fromaddr, sizeof(struct vlheader_1));
609 tvp1 = (struct vlheader_1 *)toaddr;
611 w = write(fd, tvp1, sizeof(struct vlheader_1));
612 if (w != sizeof(struct vlheader_1)) {
613 printf("Write of header failed %d; error %u\n", w, errno);
617 /* for garbage-collecting... */
618 for (i = 0; i < 31; i++)
619 tvp1->IpMappedAddr[i] = 0;
621 } else if (tov == 2 || tov == 3) {
622 tvp1 = (struct vlheader_1 *)fromaddr;
623 tvp2 = (struct vlheader_2 *)toaddr;
624 memset(tvp2, 0, sizeof(struct vlheader_2));
625 tvp2->vital_header.vldbversion = htonl(tov);
626 tvp2->vital_header.headersize = htonl(sizeof(struct vlheader_2));
628 ntohl(tvp2->vital_header.headersize) -
629 ntohl(tvp1->vital_header.headersize);
630 if (ntohl(tvp1->vital_header.freePtr))
631 tvp2->vital_header.freePtr =
632 htonl(ntohl(tvp1->vital_header.freePtr) + diff);
633 if (ntohl(tvp1->vital_header.eofPtr))
634 tvp2->vital_header.eofPtr =
635 htonl(ntohl(tvp1->vital_header.eofPtr) + diff);
636 tvp2->vital_header.allocs = tvp1->vital_header.allocs;
637 tvp2->vital_header.frees = tvp1->vital_header.frees;
638 tvp2->vital_header.MaxVolumeId = tvp1->vital_header.MaxVolumeId;
639 for (i = 0; i < 3; i++)
640 tvp2->vital_header.totalEntries[i] =
641 tvp1->vital_header.totalEntries[i];
643 for (i = 0; i < 31; i++)
644 tvp2->IpMappedAddr[i] = tvp1->IpMappedAddr[i];
646 for (i = 0; i < 8191; i++) {
647 if (ntohl(tvp1->VolnameHash[i]))
648 tvp2->VolnameHash[i] =
649 htonl(ntohl(tvp1->VolnameHash[i]) + diff);
652 for (i = 0; i < 3; i++) {
653 for (j = 0; j < 8191; j++) {
654 if (ntohl(tvp1->VolidHash[i][j]))
655 tvp2->VolidHash[i][j] =
656 htonl(ntohl(tvp1->VolidHash[i][j]) + diff);
660 w = write(fd, tvp2, sizeof(struct vlheader_2));
661 if (w != sizeof(struct vlheader_2)) {
662 printf("Write of header failed %d; error %u\n", w, errno);
666 /* for garbage-collecting... */
667 for (i = 0; i < 31; i++)
668 tvp2->IpMappedAddr[i] = 0;
671 } else if (fromv == 2 || fromv == 3 || fromv == 4) {
672 if (tov == 2 || tov == 3 || tov == 4) {
673 memcpy(toaddr, fromaddr, sizeof(struct vlheader_2));
674 tvp2 = (struct vlheader_2 *)toaddr;
675 tvp2->vital_header.vldbversion = htonl(tov);
676 w = write(fd, tvp2, sizeof(struct vlheader_2));
677 if (w != sizeof(struct vlheader_2)) {
678 printf("Write of header failed %d; error %u\n", w, errno);
682 } else if (tov == 1) {
683 tvp2 = (struct vlheader_2 *)fromaddr;
684 tvp1 = (struct vlheader_1 *)toaddr;
685 memset(tvp1, 0, sizeof(struct vlheader_1));
686 tvp1->vital_header.vldbversion = htonl(1);
687 tvp1->vital_header.headersize = htonl(sizeof(struct vlheader_1));
689 ntohl(tvp1->vital_header.headersize) -
690 ntohl(tvp2->vital_header.headersize);
691 if (ntohl(tvp2->vital_header.freePtr))
692 tvp1->vital_header.freePtr =
693 htonl(ntohl(tvp2->vital_header.freePtr) + diff);
694 if (ntohl(tvp2->vital_header.eofPtr))
695 tvp1->vital_header.eofPtr =
696 htonl(ntohl(tvp2->vital_header.eofPtr) + diff);
697 tvp1->vital_header.allocs = tvp2->vital_header.allocs;
698 tvp1->vital_header.frees = tvp2->vital_header.frees;
699 tvp1->vital_header.MaxVolumeId = tvp2->vital_header.MaxVolumeId;
700 for (i = 0; i < 3; i++)
701 tvp1->vital_header.totalEntries[i] =
702 tvp2->vital_header.totalEntries[i];
704 for (i = 0; i < 31; i++)
705 tvp1->IpMappedAddr[i] = tvp2->IpMappedAddr[i];
707 for (i = 0; i < 8191; i++) {
708 if (ntohl(tvp2->VolnameHash[i]))
709 tvp1->VolnameHash[i] =
710 htonl(ntohl(tvp2->VolnameHash[i]) + diff);
713 for (i = 0; i < 3; i++) {
714 for (j = 0; j < 8191; j++) {
715 if (ntohl(tvp2->VolidHash[i][j]))
716 tvp1->VolidHash[i][j] =
717 htonl(ntohl(tvp2->VolidHash[i][j]) + diff);
721 w = write(fd, tvp1, sizeof(struct vlheader_1));
722 if (w != sizeof(struct vlheader_2)) {
723 printf("Write of header failed %d; error %u\n", w, errno);
727 /* for garbage-collecting... */
728 for (i = 0; i < 31; i++)
729 tvp1->IpMappedAddr[i] = 0;
738 /* Convert an address pointer to a vlentry from version 4 to version 3.
739 * This involves checking if the address is after any of the four
740 * MH block and if it is, subtract the size of the MH block.
742 * In going from version 4 to 3, the mh blocks go away and all entries
743 * move up in their place. The adresses then need to be updated.
745 * Before this can be called, the routine read_mhentries must be called.
754 if (!base[0] || !addr)
758 for (i = 0; i < VL_MAX_ADDREXTBLKS; i++) {
759 if (base[i] && base[0]->ex_contaddrs[i]
760 && (addr > base[0]->ex_contaddrs[i]))
761 raddr -= VL_ADDREXTBLK_SIZE;
767 /* this only works because the vlheader struct is essentially the same
768 * from version 1 to version 2 -- that is, the first bunch of fields
769 * aren't any more or any larger, so they match up pretty well.
773 convert_vlentry(new, fromvers, tovers, oldheader, newheader, vlentryp)
774 int new, fromvers, tovers;
775 struct vlheader_1 *oldheader, *newheader; /* close enough */
776 struct vlentry_1 *vlentryp; /* 1 and 2 are identical */
779 struct vlentry_3 *vl3p = (struct vlentry_3 *)vlentryp;
781 /* For mh information blocks,
782 * If going to version 4 or greater, keep the mh info block.
783 * Otherwise, don't keep it (version 3 and earlier don't have them).
785 if (vl3p->flags == VLCONTBLOCK) {
787 w = write(new, vlentryp, VL_ADDREXTBLK_SIZE);
788 if (w != VL_ADDREXTBLK_SIZE) {
789 printf("Write of mh info block failed %d; error %u\n", w,
797 if (fromvers == 2 && tovers == 3) {
800 vl.volumeId[0] = vlentryp->volumeId[0];
801 vl.volumeId[1] = vlentryp->volumeId[1];
802 vl.volumeId[2] = vlentryp->volumeId[2];
803 vl.flags = vlentryp->flags;
804 vl.LockAfsId = vlentryp->LockAfsId;
805 vl.LockTimestamp = vlentryp->LockTimestamp;
806 vl.cloneId = vlentryp->cloneId;
807 vl.nextIdHash[0] = vlentryp->nextIdHash[0];
808 vl.nextIdHash[1] = vlentryp->nextIdHash[1];
809 vl.nextIdHash[2] = vlentryp->nextIdHash[2];
810 vl.nextNameHash = vlentryp->nextNameHash;
811 memcpy(vl.name, vlentryp->name, 65);
812 for (i = 0; i < 8; i++) {
813 vl.serverNumber[i] = vlentryp->serverNumber[i];
814 vl.serverPartition[i] = vlentryp->serverPartition[i];
815 vl.serverFlags[i] = vlentryp->serverFlags[i];
818 vl.serverNumber[i] = vl.serverPartition[i] = vl.serverFlags[i] =
820 w = write(new, &vl, sizeof(struct vlentry_3));
821 if (w != sizeof(struct vlentry_3)) {
822 printf("Write of entry failed %d; error %u\n", w, errno);
827 } else if (fromvers == 3 && tovers == 2) {
829 struct vlentry_3 *xnvlentry = (struct vlentry_3 *)vlentryp;
831 memset((char *)&vl, 0, sizeof(struct vlentry_2));
832 vl.volumeId[0] = xnvlentry->volumeId[0];
833 vl.volumeId[1] = xnvlentry->volumeId[1];
834 vl.volumeId[2] = xnvlentry->volumeId[2];
835 vl.flags = xnvlentry->flags;
836 vl.LockAfsId = xnvlentry->LockAfsId;
837 vl.LockTimestamp = xnvlentry->LockTimestamp;
838 vl.cloneId = xnvlentry->cloneId;
839 for (i = 0; i < 3; i++) {
840 if (ntohl(xnvlentry->nextIdHash[i]))
841 vl.nextIdHash[i] = xnvlentry->nextIdHash[i];
843 if (ntohl(xnvlentry->nextNameHash))
844 vl.nextNameHash = xnvlentry->nextNameHash;
845 memcpy(vl.name, xnvlentry->name, 65);
846 for (i = 0; i < 8; i++) {
847 vl.serverNumber[i] = xnvlentry->serverNumber[i];
848 vl.serverPartition[i] = xnvlentry->serverPartition[i];
849 vl.serverFlags[i] = xnvlentry->serverFlags[i];
851 w = write(new, &vl, sizeof(struct vlentry_2));
852 if (w != sizeof(struct vlentry_2)) {
853 printf("Write of entry failed %d; error %u\n", w, errno);
857 } else if (fromvers == 3 && tovers == 1) {
859 struct vlentry_3 *xnvlentry = (struct vlentry_3 *)vlentryp;
863 1 ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2))
865 1 ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2));
866 memset((char *)&vl, 0, sizeof(struct vlentry_1));
867 vl.volumeId[0] = xnvlentry->volumeId[0];
868 vl.volumeId[1] = xnvlentry->volumeId[1];
869 vl.volumeId[2] = xnvlentry->volumeId[2];
870 vl.flags = xnvlentry->flags;
871 vl.LockAfsId = xnvlentry->LockAfsId;
872 vl.LockTimestamp = xnvlentry->LockTimestamp;
873 vl.cloneId = xnvlentry->cloneId;
874 for (i = 0; i < 3; i++) {
875 if (ntohl(xnvlentry->nextIdHash[i]))
877 htonl(ntohl(xnvlentry->nextIdHash[i]) + diff);
879 if (ntohl(xnvlentry->nextNameHash))
880 vl.nextNameHash = htonl(ntohl(xnvlentry->nextNameHash) + diff);
882 memcpy(vl.name, xnvlentry->name, 65);
883 for (i = 0; i < 8; i++) {
884 vl.serverNumber[i] = xnvlentry->serverNumber[i];
885 vl.serverPartition[i] = xnvlentry->serverPartition[i];
886 vl.serverFlags[i] = xnvlentry->serverFlags[i];
888 for (i = 0; i < 8; i++) {
889 s = xnvlentry->serverNumber[i];
891 if (s > MaxServers[tovers - 1]) {
893 "%s: Too Many Servers (%d) for this version!\n",
897 newheader->IpMappedAddr[s] = oldheader->IpMappedAddr[s];
900 w = write(new, &vl, sizeof(struct vlentry_1));
901 if (w != sizeof(struct vlentry_1)) {
902 printf("Write of entry failed %d; error %u\n", w, errno);
906 } else if (fromvers == 4 && tovers == 3) {
908 /* We are converting from version 4 to 3. In this conversion, mh info
909 * blocks go away and all vlentries after them move up in the vldb file.
910 * When this happens, the linked list pointers need to be updated.
912 memcpy(&vl, vlentryp, sizeof(vl));
913 for (i = 0; i < 3; i++) {
914 vl.nextIdHash[i] = Conv4to3(vl.nextIdHash[i]);
916 vl.nextNameHash = Conv4to3(vl.nextNameHash);
918 w = write(new, &vl, sizeof(vl));
919 if (w != sizeof(vl)) {
920 printf("Write of entry failed %d; error %u\n", w, errno);
927 w = write(new, vlentryp, sizeof(struct vlentry_1));
928 if (w != sizeof(struct vlentry_1)) {
929 printf("Write of entry failed %d; error %u\n", w, errno);
932 } else if (tovers == 2) {
933 w = write(new, vlentryp, sizeof(struct vlentry_2));
934 if (w != sizeof(struct vlentry_2)) {
935 printf("Write of entry failed %d; error %u\n", w, errno);
938 } else if (tovers == 3 || tovers == 4) {
939 w = write(new, vlentryp, sizeof(struct vlentry_3));
940 if (w != sizeof(struct vlentry_3)) {
941 printf("Write of entry failed %d; error %u\n", w, errno);
947 "Skipping vlentry write - db corrupted - bad toversion %d\n",
955 rewrite_header(new, tovers, newheader)
961 pos = lseek(new, 64, L_SET); /* leave room for ubik */
964 fprintf(stderr, "%s: no garbage colection\n", pn);
966 } else if (pos != 64) {
967 fprintf(stderr, "%s: Can't rewind: no garbage collection\n", pn);
973 1) ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2));
974 w = write(new, newheader, towrite);
976 printf("Write of entry failed %d; error %u\n", w, errno);
984 #include "AFS_component_version_number.c"
990 register struct cmd_syndesc *ts;
993 ts = cmd_CreateSyntax("initcmd", handleit, 0, "optional");
994 cmd_AddParm(ts, "-to", CMD_SINGLE, CMD_OPTIONAL, "goal version");
995 cmd_AddParm(ts, "-from", CMD_SINGLE, CMD_OPTIONAL, "current version");
996 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "pathname");
997 cmd_AddParm(ts, "-showversion", CMD_FLAG, CMD_OPTIONAL,
998 "Just display version of current vldb");
999 cmd_AddParm(ts, "-dumpvldb", CMD_FLAG, CMD_OPTIONAL,
1000 "display all vldb entries");
1003 cmd_AddParm(ts, "-noGC", CMD_FLAG, CMD_OPTIONAL,
1004 "Don't do garbage collection");
1007 dbPath = AFSDIR_SERVER_VLDB_FILEPATH;
1009 code = cmd_Dispatch(argc, argv);