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>
15 #include <sys/types.h>
19 #include "cnvldb.h" /* CHANGEME! */
20 #include <netinet/in.h>
21 #include <afs/venus.h>
28 #include "afs/prs_fs.h"
29 #include <afs/afsint.h>
30 #include <afs/cellconfig.h>
35 #define MAXSIZE 2048 /* most I'll get back from PIOCTL */
38 static char pn[] = "cnvldb";
39 static char tempname[] = "XXnewvldb";
40 static char space[MAXSIZE];
41 static int MaxServers[2] = { 30, 254 }; /* max server # permitted in this version */
43 #ifdef notdef /* postpone this... */
45 saferead(fd, addr, osize)
59 rc = read(fd, ptr, size)) {
73 saferead(fd, addr, osize)
79 rc = read(fd, addr, osize);
80 if (rc != osize && rc != EOF) {
87 #define saferead(fd,addr,siz) read((fd),(addr),(siz))
90 static char tspace[1024]; /* chdir can't handle anything bigger, anyway */
91 /* return a static pointer to a buffer */
97 strcpy(tspace, apath);
98 tp = strrchr(tspace, '/');
108 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
111 register char *apath;
113 struct ViceIoctl blob;
114 register afs_int32 code;
117 blob.out_size = MAXSIZE;
120 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
122 if ((errno == EINVAL) || (errno == ENOENT))
128 QuickPrintStatus(status, name)
129 struct VolumeStatus *status;
132 double QuotaUsed = 0.0;
133 double PartUsed = 0.0;
136 if (status->MaxQuota != 0) {
138 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
144 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
150 ListQuotaCmd(register struct cmd_syndesc *as, void *arock)
152 register afs_int32 code;
153 struct ViceIoctl blob;
154 register struct cmd_item *ti;
155 struct VolumeStatus *status;
158 for (ti = as->parms[0].items; ti; ti = ti->next) {
160 blob.out_size = MAXSIZE;
163 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
168 status = (struct VolumeStatus *)space;
169 name = (char *)status + sizeof(*status);
170 QuickPrintStatus(status, name);
176 int gc = 1, fromvers = 1, tovers = 2;
177 char *pathname = NULL, *defaultpath = "/usr/afs/db/vl.DB0";
181 fprintf(stderr, "usage: %s ", pn);
182 fprintf(stderr, "[-name <pathname>] [-help]\n");
192 for (i = 1; i < argc; i++) {
195 else if (*(argv[i]) != '-') { /* positional params */
199 fprintf(stderr, "%s: Too many parameters!\n");
203 } else /* keyword params */
204 switch (argv[i][1]) {
207 fprintf(stderr, "%s: can't specify version with this tool!\n",
212 case 'f': /* -from */
213 fprintf(stderr, "%s: can't specify version with this tool!\n",
217 case 'n': /* -name */
220 "%s: -name specified (or implied) twice!\n", pn);
223 pathname = argv[++i];
226 case 'h': /* -help */
231 case 'g': /* -gc == No GC */
242 pathname = defaultpath;
245 #include "AFS_component_version_number.c"
251 register afs_int32 code;
254 char ubik[80]; /* space for some ubik header */
257 struct vlheader_1 header1;
258 struct vlheader_2 header2;
259 } oldheader, newheader; /* large enough for either */
262 struct vlentry_1 entry1;
263 struct vlentry_2 entry2;
269 /* should stat() the old vldb, get its size, and see if there's */
270 /* room for another. It might be in AFS, so check the quota, too */
271 if (!(old = open(pathname, O_RDONLY))) {
276 if (chdir(Parent(pathname))) {
281 if (!(new = open(tempname, O_WRONLY | O_CREAT | O_TRUNC, 0600))) {
286 if (fromvers == 0) { /* not set */
287 lseek(old, 64, L_SET);
288 read(old, &fromvers, sizeof(int));
289 fromvers = ntohl(fromvers);
290 lseek(old, 0, L_SET); /* go back to beginning */
293 /* skip the UBIK data */
296 uvers = ntohs(uvers);
297 uvers += 10; /* hey, if you screw with the VLDB, you lose */
298 uvers = htons(uvers);
300 write(new, ubik, 64);
302 readheader(old, fromvers, &oldheader);
303 convert_header(new, fromvers, tovers, &oldheader, &newheader);
304 while ((rc = read(old, &vlentry, sizeof(struct vlentry_1))) && rc != EOF) {
305 convert_vlentry(new, fromvers, tovers, &oldheader, &newheader,
311 rewrite_header(new, tovers, &newheader);
320 rename(tempname, pathname);
324 readheader(fd, version, addr)
330 read(fd, addr, sizeof(struct vlheader_2)); /* it's not a bug, it's SAS */
331 } else if (version == 2) {
332 read(fd, addr, sizeof(struct vlheader_2));
340 convert_header(fd, fromv, tov, fromaddr, toaddr)
342 char *fromaddr, *toaddr;
344 struct vlheader_2 *tvp1;
345 struct vlheader_2 *tvp2;
348 memcpy(toaddr, fromaddr, sizeof(struct vlheader_2));
349 tvp2 = (struct vlheader_2 *)toaddr;
350 tvp2->vital_header.vldbversion = htonl(2);
352 write(fd, tvp2, sizeof(struct vlheader_2));
354 /* for garbage-collecting... */
356 for (i = 0; i < 254; i++)
357 tvp2->IpMappedAddr[i] = 0;
363 convert_vlentry(new, fromvers, tovers, oldheader, newheader, vlentry)
364 int new, fromvers, tovers;
365 struct vlheader_1 *oldheader, *newheader; /* close enough */
366 struct vlentry_1 *vlentry; /* 1 and 2 are identical */
371 if (fromvers != tovers) { /* only supports 1 and 2 currently */
376 1 ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2))
378 1 ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2));
380 for (i = 0; i < 3; i++)
381 vlentry->nextIdHash[i] =
382 htonl(ntohl(vlentry->nextIdHash[i]) + diff);
384 vlentry->nextNameHash = htonl(ntohl(vlentry->nextNameHash) + diff);
388 ; /* no change, we're just in it for the GC */
392 for (i = 0; i < 8; i++) {
393 s = vlentry->serverNumber[i];
397 "%s: Too Many Servers (%d) for this version!\n", pn,
401 newheader->IpMappedAddr[s] = oldheader->IpMappedAddr[s];
405 write(new, vlentry, sizeof(struct vlentry_2));
411 rewrite_header(new, tovers, newheader)
417 pos = lseek(new, 64, L_SET); /* leave room for ubik */
421 fprintf(stderr, "%s: no garbage collection\n", pn);
423 } else if (pos != 64) {
424 fprintf(stderr, "%s: Can't rewind: no garbage collection\n", pn);
429 write(new, newheader, sizeof(struct vlheader_1));
431 write(new, newheader, sizeof(struct vlheader_2));