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 <afs/param.h>
21 #include <rx/rx_globals.h>
26 typedef long afs_int32;
27 typedef unsigned long afs_uint32;
28 typedef short afs_int16;
29 typedef unsigned short afs_uint16;
41 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
42 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
44 static char space[MAXSIZE];
45 static char tspace[1024];
48 static struct ubik_client *uclient;
49 #endif /* not WIN32 */
52 extern afs_int32 VL_GetEntryByNameO();
54 static char pn[] = "fs";
55 static int rxInitDone = 0;
59 #define MAXCELLCHARS 64
60 #define MAXHOSTCHARS 64
61 #define MAXHOSTSPERCELL 8
64 char name[MAXCELLCHARS];
67 struct sockaddr_in hostAddr[MAXHOSTSPERCELL];
68 char hostName[MAXHOSTSPERCELL][MAXHOSTCHARS];
74 * Character to use between name and rights in printed representation for
77 #define DFS_SEPARATOR ' '
79 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
82 int dfs; /* Originally true if a dfs acl; now also the type
83 of the acl (1, 2, or 3, corresponding to object,
84 initial dir, or initial object). */
85 sec_rgy_name_t cell; /* DFS cell name */
88 struct AclEntry *pluslist;
89 struct AclEntry *minuslist;
93 struct AclEntry *next;
100 ZapList(acl->pluslist);
101 ZapList(acl->minuslist);
112 if (t >= 'A' && t <= 'Z') t += 0x20;
113 if (u >= 'A' && u <= 'Z') u += 0x20;
114 if (t != u) return 1;
115 if (t == 0) return 0;
120 * Mods for the AFS/DFS protocol translator.
122 * DFS rights. It's ugly to put these definitions here, but they
123 * *cannot* change, because they're part of the wire protocol.
124 * In any event, the protocol translator will guarantee these
125 * assignments for AFS cache managers.
127 #define DFS_READ 0x01
128 #define DFS_WRITE 0x02
129 #define DFS_EXECUTE 0x04
130 #define DFS_CONTROL 0x08
131 #define DFS_INSERT 0x10
132 #define DFS_DELETE 0x20
134 /* the application definable ones (backwards from AFS) */
135 #define DFS_USR0 0x80000000 /* "A" bit */
136 #define DFS_USR1 0x40000000 /* "B" bit */
137 #define DFS_USR2 0x20000000 /* "C" bit */
138 #define DFS_USR3 0x10000000 /* "D" bit */
139 #define DFS_USR4 0x08000000 /* "E" bit */
140 #define DFS_USR5 0x04000000 /* "F" bit */
141 #define DFS_USR6 0x02000000 /* "G" bit */
142 #define DFS_USR7 0x01000000 /* "H" bit */
143 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
144 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
147 * Offset of -id switch in command structure for various commands.
148 * The -if switch is the next switch always.
150 int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
153 * Determine whether either the -id or -if switches are present, and
154 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
157 struct cmd_syndesc *as;
158 int id; /* Offset of -id switch; -if is next switch */
162 if (as->parms[id].items) {
165 if (as->parms[id + 1].items) {
171 "%s: you may specify either -id or -if, but not both switches\n",
178 void PRights (arights, dfs)
179 register afs_int32 arights;
183 if (arights & PRSFS_READ) printf("r");
184 if (arights & PRSFS_LOOKUP) printf("l");
185 if (arights & PRSFS_INSERT) printf("i");
186 if (arights & PRSFS_DELETE) printf("d");
187 if (arights & PRSFS_WRITE) printf("w");
188 if (arights & PRSFS_LOCK) printf("k");
189 if (arights & PRSFS_ADMINISTER) printf("a");
190 if (arights & PRSFS_USR0) printf("A");
191 if (arights & PRSFS_USR1) printf("B");
192 if (arights & PRSFS_USR2) printf("C");
193 if (arights & PRSFS_USR3) printf("D");
194 if (arights & PRSFS_USR4) printf("E");
195 if (arights & PRSFS_USR5) printf("F");
196 if (arights & PRSFS_USR6) printf("G");
197 if (arights & PRSFS_USR7) printf("H");
199 if (arights & DFS_READ) printf("r"); else printf("-");
200 if (arights & DFS_WRITE) printf("w"); else printf("-");
201 if (arights & DFS_EXECUTE) printf("x"); else printf("-");
202 if (arights & DFS_CONTROL) printf("c"); else printf("-");
203 if (arights & DFS_INSERT) printf("i"); else printf("-");
204 if (arights & DFS_DELETE) printf("d"); else printf("-");
205 if (arights & (DFS_USRALL)) printf("+");
206 if (arights & DFS_USR0) printf("A");
207 if (arights & DFS_USR1) printf("B");
208 if (arights & DFS_USR2) printf("C");
209 if (arights & DFS_USR3) printf("D");
210 if (arights & DFS_USR4) printf("E");
211 if (arights & DFS_USR5) printf("F");
212 if (arights & DFS_USR6) printf("G");
213 if (arights & DFS_USR7) printf("H");
217 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
218 static int InAFS(apath)
219 register char *apath; {
220 struct ViceIoctl blob;
221 register afs_int32 code;
224 blob.out_size = MAXSIZE;
227 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
229 if ((errno == EINVAL) || (errno == ENOENT)) return 0;
234 /* return a static pointer to a buffer */
235 static char *Parent(apath)
238 strcpy(tspace, apath);
239 tp = strrchr(tspace, '\\');
241 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
244 fs_ExtractDriveLetter(apath, tspace);
250 enum rtype {add, destroy, deny};
252 afs_int32 Convert(arights, dfs, rtypep)
253 register char *arights;
261 *rtypep = add; /* add rights, by default */
264 if (!strcmp(arights, "null")) {
268 if (!strcmp(arights,"read")) return DFS_READ | DFS_EXECUTE;
269 if (!strcmp(arights, "write")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE;
270 if (!strcmp(arights, "all")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE | DFS_CONTROL;
272 if (!strcmp(arights,"read")) return PRSFS_READ | PRSFS_LOOKUP;
273 if (!strcmp(arights, "write")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK;
274 if (!strcmp(arights, "mail")) return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
275 if (!strcmp(arights, "all")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
277 if (!strcmp(arights, "none")) {
278 *rtypep = destroy; /* Remove entire entry */
281 len = strlen(arights);
286 if (tc == '-') continue;
287 else if (tc == 'r') mode |= DFS_READ;
288 else if (tc == 'w') mode |= DFS_WRITE;
289 else if (tc == 'x') mode |= DFS_EXECUTE;
290 else if (tc == 'c') mode |= DFS_CONTROL;
291 else if (tc == 'i') mode |= DFS_INSERT;
292 else if (tc == 'd') mode |= DFS_DELETE;
293 else if (tc == 'A') mode |= DFS_USR0;
294 else if (tc == 'B') mode |= DFS_USR1;
295 else if (tc == 'C') mode |= DFS_USR2;
296 else if (tc == 'D') mode |= DFS_USR3;
297 else if (tc == 'E') mode |= DFS_USR4;
298 else if (tc == 'F') mode |= DFS_USR5;
299 else if (tc == 'G') mode |= DFS_USR6;
300 else if (tc == 'H') mode |= DFS_USR7;
302 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n", pn, tc);
306 if (tc == 'r') mode |= PRSFS_READ;
307 else if (tc == 'l') mode |= PRSFS_LOOKUP;
308 else if (tc == 'i') mode |= PRSFS_INSERT;
309 else if (tc == 'd') mode |= PRSFS_DELETE;
310 else if (tc == 'w') mode |= PRSFS_WRITE;
311 else if (tc == 'k') mode |= PRSFS_LOCK;
312 else if (tc == 'a') mode |= PRSFS_ADMINISTER;
313 else if (tc == 'A') mode |= PRSFS_USR0;
314 else if (tc == 'B') mode |= PRSFS_USR1;
315 else if (tc == 'C') mode |= PRSFS_USR2;
316 else if (tc == 'D') mode |= PRSFS_USR3;
317 else if (tc == 'E') mode |= PRSFS_USR4;
318 else if (tc == 'F') mode |= PRSFS_USR5;
319 else if (tc == 'G') mode |= PRSFS_USR6;
320 else if (tc == 'H') mode |= PRSFS_USR7;
322 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn, tc);
330 struct AclEntry *FindList (alist, aname)
332 register struct AclEntry *alist; {
334 if (!foldcmp(alist->name, aname)) return alist;
340 /* if no parm specified in a particular slot, set parm to be "." instead */
341 static void SetDotDefault(aitemp)
342 struct cmd_item **aitemp; {
343 register struct cmd_item *ti;
344 if (*aitemp) return; /* already has value */
345 /* otherwise, allocate an item representing "." */
346 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
347 ti->next = (struct cmd_item *) 0;
348 ti->data = (char *) malloc(2);
349 strcpy(ti->data, ".");
353 void ChangeList (al, plus, aname, arights)
356 afs_int32 arights, plus; {
357 struct AclEntry *tlist;
358 tlist = (plus ? al->pluslist : al->minuslist);
359 tlist = FindList (tlist, aname);
361 /* Found the item already in the list. */
362 tlist->rights = arights;
364 al->nplus -= PruneList(&al->pluslist, al->dfs);
366 al->nminus -= PruneList(&al->minuslist, al->dfs);
369 /* Otherwise we make a new item and plug in the new data. */
370 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
371 strcpy(tlist->name, aname);
372 tlist->rights = arights;
374 tlist->next = al->pluslist;
375 al->pluslist = tlist;
377 if (arights == 0 || arights == -1)
378 al->nplus -= PruneList(&al->pluslist, al->dfs);
381 tlist->next = al->minuslist;
382 al->minuslist = tlist;
384 if (arights == 0) al->nminus -= PruneList(&al->minuslist, al->dfs);
389 struct AclEntry *alist; {
390 register struct AclEntry *tp, *np;
391 for (tp = alist; tp; tp = np) {
397 int PruneList (ae, dfs)
398 struct AclEntry **ae;
401 struct AclEntry **lp;
402 struct AclEntry *te, *ne;
406 for(te = *ae;te;te=ne) {
407 if ((!dfs && te->rights == 0) || te->rights == -1) {
421 char *SkipLine (astr)
422 register char *astr; {
423 while (*astr !='\n') astr++;
429 * Create an empty acl, taking into account whether the acl pointed
430 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
431 * can recover from problems caused by bogus ACL's (in that case, always
432 * assume that the acl is AFS: for DFS, the user can always resort to
433 * acl_edit, but for AFS there may be no other way out).
435 struct Acl *EmptyAcl(astr)
438 register struct Acl *tp;
441 tp = (struct Acl *)malloc(sizeof (struct Acl));
442 tp->nplus = tp->nminus = 0;
443 tp->pluslist = tp->minuslist = 0;
445 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
449 struct Acl *ParseAcl (astr)
451 int nplus, nminus, i, trights;
453 struct AclEntry *first, *last, *tl;
456 ta = (struct Acl *) malloc (sizeof (struct Acl));
458 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
459 astr = SkipLine(astr);
460 sscanf(astr, "%d", &ta->nminus);
461 astr = SkipLine(astr);
468 for(i=0;i<nplus;i++) {
469 sscanf(astr, "%100s %d", tname, &trights);
470 astr = SkipLine(astr);
471 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
472 if (!first) first = tl;
473 strcpy(tl->name, tname);
474 tl->rights = trights;
476 if (last) last->next = tl;
479 ta->pluslist = first;
483 for(i=0;i<nminus;i++) {
484 sscanf(astr, "%100s %d", tname, &trights);
485 astr = SkipLine(astr);
486 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
487 if (!first) first = tl;
488 strcpy(tl->name, tname);
489 tl->rights = trights;
491 if (last) last->next = tl;
494 ta->minuslist = first;
499 void PrintStatus(status, name, motd, offmsg)
500 VolumeStatus *status;
504 printf("Volume status for vid = %u named %s\n",status->Vid, name);
506 printf("Current offline message is %s\n",offmsg);
508 printf("Current message of the day is %s\n",motd);
509 printf("Current disk quota is ");
510 if (status->MaxQuota != 0) printf("%d\n", status->MaxQuota);
511 else printf("unlimited\n");
512 printf("Current blocks used are %d\n",status->BlocksInUse);
513 printf("The partition has %d blocks available out of %d\n\n",status->PartBlocksAvail, status->PartMaxBlocks);
516 void QuickPrintStatus(status, name)
517 VolumeStatus *status;
519 double QuotaUsed =0.0;
520 double PartUsed =0.0;
522 printf("%-20s",name);
524 if (status->MaxQuota != 0) {
525 printf("%8d%8d", status->MaxQuota, status->BlocksInUse);
526 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
528 printf("no limit%8d", status->BlocksInUse);
530 if (QuotaUsed > 90.0){
531 printf(" %8.0f%%<<", QuotaUsed);
534 else printf(" %8.0f%% ", QuotaUsed);
535 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
536 if (PartUsed > 97.0){
537 printf(" %8.0f%%<<", PartUsed);
540 else printf(" %8.0f%% ", PartUsed);
542 printf("\t<<WARNING\n");
547 void QuickPrintSpace(status, name)
548 VolumeStatus *status;
550 double PartUsed =0.0;
552 printf("%-20s",name);
554 printf("%8d%8d%8d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
556 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
557 if (PartUsed > 90.0){
558 printf(" %8.0f%%<<", PartUsed);
561 else printf(" %8.0f%% ", PartUsed);
563 printf("\t<<WARNING\n");
568 char *AclToString(acl)
570 static char mydata[MAXSIZE];
571 char tstring[MAXSIZE];
575 if (acl->dfs) sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
576 else dfsstring[0] = '\0';
577 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
578 for(tp = acl->pluslist;tp;tp=tp->next) {
579 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
580 strcat(mydata, tstring);
582 for(tp = acl->minuslist;tp;tp=tp->next) {
583 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
584 strcat(mydata, tstring);
590 struct cmd_syndesc *as; {
591 register afs_int32 code;
592 struct ViceIoctl blob;
594 register struct cmd_item *ti, *ui;
598 int idf = getidf(as, parm_setacl_id);
600 if (as->parms[2].items) clear=1;
602 plusp = !(as->parms[3].items);
603 for(ti=as->parms[0].items; ti;ti=ti->next) {
604 blob.out_size = MAXSIZE;
606 blob.in = blob.out = space;
607 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
609 Die(errno, ti->data);
612 ta = ParseAcl(space);
613 if (!plusp && ta->dfs) {
615 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
617 "(you may specify \"null\" to revoke all rights, however)\n");
620 if (clear) ta = EmptyAcl(space);
621 else ta = ParseAcl(space);
623 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
626 fprintf(stderr,"%s: Missing second half of user/access pair.\n", pn);
629 rights = Convert(ui->next->data, ta->dfs, &rtype);
630 if (rtype == destroy && !ta->dfs) {
631 if (!FindList(ta->pluslist, ui->data)) {
632 fprintf(stderr,"%s: Invalid arg (%s doesn't exist in the current acl)\n", pn, ui->data);
636 if (rtype == deny && !ta->dfs) plusp = 0;
637 if (rtype == destroy && ta->dfs) rights = -1;
638 ChangeList(ta, plusp, ui->data, rights);
640 blob.in = AclToString(ta);
642 blob.in_size = 1+strlen(blob.in);
643 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
645 if (errno == EINVAL) {
647 static char *fsenv = 0;
649 fsenv = (char *)getenv("FS_EXPERT");
651 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
654 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
655 "\nPossible reasons for this include:\n\n",
656 " -You may have specified an inappropriate combination of rights.\n",
657 " For example, some DFS-supported filesystems may not allow you to\n",
658 " drop the \"c\" right from \"user_obj\".\n\n",
659 " -A mask_obj may be required (it is likely required by the underlying\n",
660 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
661 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
662 " does not automatically create or update the mask_obj. Try setting\n",
663 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
664 " users or groups. You can do this with a single command, such as\n",
665 " \"fs sa mask_obj all user:somename read\"\n\n",
666 " -A specified user or group may not exist.\n\n",
667 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
668 " This is probably not allowed by the underlying file system.\n\n",
669 " -If you add a user or group to a DFS ACL, remember that it must be\n",
670 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
671 " may be local requirements on the format of the user or group name.\n",
672 " Check with your cell administrator.\n\n",
673 " -Or numerous other possibilities. It would be great if we could be more\n",
674 " precise about the actual problem, but for various reasons, this is\n",
675 " impractical via this interface. If you can't figure it out, you\n",
676 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
677 " whatever is provided). You may get better results. Good luck!\n\n",
678 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
681 fprintf(stderr,"%s: Invalid argument, possible reasons include:\n", pn);
682 fprintf(stderr,"\t-File not in AFS\n");
683 fprintf(stderr,"\t-Too many users on access control list\n");
684 fprintf(stderr,"\t-Tried to add non-existent user to access control list\n");
689 Die(errno, ti->data);
698 static CopyACLCmd(as)
699 struct cmd_syndesc *as; {
700 register afs_int32 code;
701 struct ViceIoctl blob;
704 register struct cmd_item *ti;
706 int idf = getidf(as, parm_copyacl_id);
708 if (as->parms[2].items) clear=1;
710 blob.out_size = MAXSIZE;
712 blob.in = blob.out = space;
713 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
715 Die(errno, as->parms[0].items->data);
718 fa = ParseAcl(space);
720 for (ti=as->parms[1].items; ti;ti=ti->next) {
721 blob.out_size = MAXSIZE;
723 blob.in = blob.out = space;
724 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
726 Die(errno, ti->data);
729 if (clear) ta = EmptyAcl(space);
730 else ta = ParseAcl(space);
732 if (ta->dfs != fa->dfs) {
733 fprintf(stderr, "fs: incompatible file system types: acl not copied to %s; aborted\n", ti->data);
737 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
738 fprintf(stderr, "fs: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n", ti->data);
741 strcpy(ta->cell, fa->cell);
743 for (tp = fa->pluslist;tp;tp=tp->next)
744 ChangeList(ta, 1, tp->name, tp->rights);
745 for (tp = fa->minuslist;tp;tp=tp->next)
746 ChangeList(ta, 0, tp->name, tp->rights);
747 blob.in = AclToString(ta);
749 blob.in_size = 1+strlen(blob.in);
750 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
752 if (errno == EINVAL) {
753 fprintf(stderr,"%s: Invalid argument, possible reasons include:\n", pn);
754 fprintf(stderr,"\t-File not in AFS\n");
758 Die(errno, ti->data);
770 /* tell if a name is 23 or -45 (digits or minus digits), which are bad names we must prune */
771 static BadName(aname)
772 register char *aname; {
774 while(tc = *aname++) {
775 /* all must be '-' or digit to be bad */
776 if (tc != '-' && (tc < '0' || tc > '9')) return 0;
782 /* clean up an access control list of its bad entries; return 1 if we made
783 any changes to the list, and 0 otherwise */
786 register struct AclEntry *te, **le, *ne;
789 /* Don't correct DFS ACL's for now */
793 /* prune out bad entries */
794 changes = 0; /* count deleted entries */
796 for(te = aa->pluslist; te; te=ne) {
798 if (BadName(te->name)) {
810 for(te = aa->minuslist; te; te=ne) {
812 if (BadName(te->name)) {
827 /* clean up an acl to not have bogus entries */
828 static CleanACLCmd(as)
829 register struct cmd_syndesc *as; {
830 register afs_int32 code;
831 register struct Acl *ta;
832 struct ViceIoctl blob;
834 register struct cmd_item *ti;
835 register struct AclEntry *te;
837 SetDotDefault(&as->parms[0].items);
838 for(ti=as->parms[0].items; ti; ti=ti->next) {
839 blob.out_size = MAXSIZE;
842 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
844 Die(errno, ti->data);
847 ta = ParseAcl(space);
851 "%s: cleanacl is not supported for DFS access lists.\n",
856 changes = CleanAcl(ta);
859 /* now set the acl */
860 blob.in=AclToString(ta);
861 blob.in_size = strlen(blob.in)+1;
863 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
865 if (errno == EINVAL) {
866 fprintf(stderr,"%s: Invalid argument, possible reasons include\n", pn);
867 fprintf(stderr,"%s: File not in vice or\n", pn);
868 fprintf(stderr,"%s: Too many users on access control list or\n", pn);
872 Die(errno, ti->data);
877 /* now list the updated acl */
878 printf("Access list for %s is now\n", ti->data);
880 if (!ta->dfs) printf("Normal rights:\n");
881 for(te = ta->pluslist;te;te=te->next) {
882 printf(" %s ", te->name);
883 PRights(te->rights, ta->dfs);
887 if (ta->nminus > 0) {
888 printf("Negative rights:\n");
889 for(te = ta->minuslist;te;te=te->next) {
890 printf(" %s ", te->name);
891 PRights(te->rights, ta->dfs);
895 if (ti->next) printf("\n");
898 printf("Access list for %s is fine.\n", ti->data);
903 static ListACLCmd(as)
904 register struct cmd_syndesc *as; {
905 register afs_int32 code;
906 register struct Acl *ta;
907 struct ViceIoctl blob;
909 register struct cmd_item *ti;
910 int idf = getidf(as, parm_listacl_id);
912 SetDotDefault(&as->parms[0].items);
913 for(ti=as->parms[0].items; ti; ti=ti->next) {
915 blob.out_size = MAXSIZE;
917 blob.in = blob.out = space;
918 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
920 Die(errno, ti->data);
923 ta = ParseAcl(space);
926 printf("Access list for %s is\n", ti->data);
929 printf("DFS access list for %s is\n", ti->data);
932 printf("DFS initial directory access list of %s is\n", ti->data);
935 printf("DFS initial file access list of %s is\n", ti->data);
939 printf(" Default cell = %s\n", ta->cell);
941 separator = ta->dfs? DFS_SEPARATOR : ' ';
943 if (!ta->dfs) printf("Normal rights:\n");
944 for(te = ta->pluslist;te;te=te->next) {
945 printf(" %s%c", te->name, separator);
946 PRights(te->rights, ta->dfs);
950 if (ta->nminus > 0) {
951 printf("Negative rights:\n");
952 for(te = ta->minuslist;te;te=te->next) {
953 printf(" %s ", te->name);
954 PRights(te->rights, ta->dfs);
958 if (ti->next) printf("\n");
963 static FlushVolumeCmd(as)
964 register struct cmd_syndesc *as; {
965 register afs_int32 code;
966 struct ViceIoctl blob;
967 register struct cmd_item *ti;
969 for(ti=as->parms[0].items; ti; ti=ti->next) {
970 blob.in_size = blob.out_size = 0;
971 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
973 fprintf(stderr, "Error flushing volume\n");
982 register struct cmd_syndesc *as; {
983 register afs_int32 code;
984 struct ViceIoctl blob;
986 register struct cmd_item *ti;
989 for(ti=as->parms[0].items; ti; ti=ti->next) {
990 blob.in_size = blob.out_size = 0;
991 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
994 if (errno == EMFILE) {
995 fprintf(stderr,"%s: Can't flush active file %s\n", pn, ti->data);
999 fprintf(stderr, "Error flushing file\n");
1000 Die(errno,ti->data);
1008 /* all this command does is repackage its args and call SetVolCmd */
1009 static SetQuotaCmd(as)
1010 register struct cmd_syndesc *as; {
1011 struct cmd_syndesc ts;
1013 /* copy useful stuff from our command slot; we may later have to reorder */
1014 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1015 return SetVolCmd(&ts);
1018 static SetVolCmd(as)
1019 register struct cmd_syndesc *as; {
1020 register afs_int32 code;
1021 struct ViceIoctl blob;
1022 register struct cmd_item *ti;
1023 struct VolumeStatus *status;
1024 char *motd, *offmsg, *input;
1026 SetDotDefault(&as->parms[0].items);
1027 for(ti=as->parms[0].items; ti; ti=ti->next) {
1029 blob.out_size = MAXSIZE;
1030 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1033 status = (VolumeStatus *)space;
1034 status->MinQuota = status->MaxQuota = -1;
1035 motd = offmsg = (char *) 0;
1036 if (as->parms[1].items) {
1037 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1039 fprintf(stderr,"fs: bad integer specified for quota.\n");
1043 if (as->parms[2].items) motd = as->parms[2].items->data;
1044 if (as->parms[3].items) offmsg = as->parms[3].items->data;
1045 input = (char *)status + sizeof(*status);
1046 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1048 if (strlen(offmsg) >= VMSGSIZE) {
1049 fprintf(stderr,"fs: message must be shorter than %d characters\n",
1053 strcpy(input,offmsg);
1054 blob.in_size += strlen(offmsg);
1055 input += strlen(offmsg) + 1;
1057 else *(input++) = '\0';
1059 if (strlen(motd) >= VMSGSIZE) {
1060 fprintf(stderr,"fs: message must be shorter than %d characters\n",
1065 blob.in_size += strlen(motd);
1066 input += strlen(motd) + 1;
1068 else *(input++) = '\0';
1069 code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1);
1071 Die(errno, ti->data);
1078 static ExamineCmd(as)
1079 register struct cmd_syndesc *as; {
1080 register afs_int32 code;
1081 struct ViceIoctl blob;
1082 register struct cmd_item *ti;
1083 struct VolumeStatus *status;
1084 char *name, *offmsg, *motd;
1088 SetDotDefault(&as->parms[0].items);
1089 for(ti=as->parms[0].items; ti; ti=ti->next) {
1091 blob.out_size = MAXSIZE;
1094 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1096 Die(errno, ti->data);
1100 status = (VolumeStatus *)space;
1101 name = (char *)status + sizeof(*status);
1102 offmsg = name + strlen(name) + 1;
1103 motd = offmsg + strlen(offmsg) + 1;
1104 PrintStatus(status, name, motd, offmsg);
1109 static ListQuotaCmd(as)
1110 register struct cmd_syndesc *as; {
1111 register afs_int32 code;
1112 struct ViceIoctl blob;
1113 register struct cmd_item *ti;
1114 struct VolumeStatus *status;
1117 printf("%-20s%-9s%-8s%-11s%-11s\n",
1118 "Volume Name"," Quota", " Used", " % Used", " Partition");
1119 SetDotDefault(&as->parms[0].items);
1120 for(ti=as->parms[0].items; ti; ti=ti->next) {
1122 blob.out_size = MAXSIZE;
1125 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1127 Die(errno, ti->data);
1130 status = (VolumeStatus *)space;
1131 name = (char *)status + sizeof(*status);
1132 QuickPrintStatus(status, name);
1137 static WhereIsCmd(as)
1138 register struct cmd_syndesc *as; {
1139 register afs_int32 code;
1140 struct ViceIoctl blob;
1141 register struct cmd_item *ti;
1146 SetDotDefault(&as->parms[0].items);
1147 for(ti=as->parms[0].items; ti; ti=ti->next) {
1149 blob.out_size = MAXSIZE;
1152 memset(space, 0, sizeof(space));
1153 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1155 Die(errno, ti->data);
1158 hosts = (afs_int32 *) space;
1159 printf("File %s is on host%s ", ti->data, (hosts[0] && !hosts[1]) ? "": "s");
1160 for(j=0; j<MAXHOSTS; j++) {
1161 if (hosts[j] == 0) break;
1162 tp = hostutil_GetNameByINet(hosts[j]);
1171 static DiskFreeCmd(as)
1172 register struct cmd_syndesc *as; {
1173 register afs_int32 code;
1174 struct ViceIoctl blob;
1175 register struct cmd_item *ti;
1177 struct VolumeStatus *status;
1179 printf("%-20s%-9s%-8s%-11s%-11s\n",
1180 "Volume Name"," kbytes ", " used", " avail ", " %used");
1181 SetDotDefault(&as->parms[0].items);
1182 for(ti=as->parms[0].items; ti; ti=ti->next) {
1184 blob.out_size = MAXSIZE;
1187 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1189 Die(errno, ti->data);
1192 status = (VolumeStatus *)space;
1193 name = (char *)status + sizeof(*status);
1194 QuickPrintSpace(status, name);
1200 register struct cmd_syndesc *as; {
1201 register afs_int32 code;
1202 struct ViceIoctl blob;
1203 register struct cmd_item *ti;
1205 struct VolumeStatus *status;
1207 SetDotDefault(&as->parms[0].items);
1208 for(ti=as->parms[0].items; ti; ti=ti->next) {
1210 blob.out_size = MAXSIZE;
1213 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1215 Die(errno, ti->data);
1218 status = (VolumeStatus *)space;
1219 if (status->MaxQuota) quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1220 else quotaPct = 0.0;
1221 printf("%2.0f%% of quota used.\n", quotaPct);
1226 static ListMountCmd(as)
1227 register struct cmd_syndesc *as; {
1228 register afs_int32 code;
1229 struct ViceIoctl blob;
1231 register struct cmd_item *ti;
1232 char orig_name[1024]; /*Original name, may be modified*/
1233 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1234 char parent_dir[1024]; /*Parent directory of true name*/
1235 register char *last_component; /*Last component of true name*/
1237 struct stat statbuff; /*Buffer for status info*/
1238 #endif /* not WIN32 */
1240 int link_chars_read; /*Num chars read in readlink()*/
1241 #endif /* not WIN32 */
1242 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1245 for(ti=as->parms[0].items; ti; ti=ti->next) {
1249 strcpy(orig_name, ti->data);
1250 #else /* not WIN32 */
1251 sprintf(orig_name, "%s%s",
1252 (ti->data[0] == '/') ? "" : "./",
1254 #endif /* not WIN32 */
1257 if (lstat(orig_name, &statbuff) < 0) {
1258 /* if lstat fails, we should still try the pioctl, since it
1259 may work (for example, lstat will fail, but pioctl will
1260 work if the volume of offline (returning ENODEV). */
1261 statbuff.st_mode = S_IFDIR; /* lie like pros */
1265 * The lstat succeeded. If the given file is a symlink, substitute
1266 * the file name with the link name.
1268 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1271 * Read name of resolved file.
1273 link_chars_read = readlink(orig_name, true_name, 1024);
1274 if (link_chars_read <= 0) {
1275 fprintf(stderr,"%s: Can't read target name for '%s' symbolic link!\n",
1281 * Add a trailing null to what was read, bump the length.
1283 true_name[link_chars_read++] = 0;
1286 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1287 * have to create a full pathname using the original name and the
1288 * relative symlink name. Find the rightmost slash in the original
1289 * name (we know there is one) and splice in the symlink value.
1291 if (true_name[0] != '\\') {
1292 last_component = (char *) strrchr(orig_name, '\\');
1293 strcpy(++last_component, true_name);
1294 strcpy(true_name, orig_name);
1298 strcpy(true_name, orig_name);
1300 strcpy(true_name, orig_name);
1304 * Find rightmost slash, if any.
1306 last_component = (char *) strrchr(true_name, '\\');
1307 if (!last_component)
1308 last_component = (char *) strrchr(true_name, '/');
1309 if (last_component) {
1311 * Found it. Designate everything before it as the parent directory,
1312 * everything after it as the final component.
1314 strncpy(parent_dir, true_name, last_component - true_name + 1);
1315 parent_dir[last_component - true_name + 1] = 0;
1316 last_component++; /*Skip the slash*/
1320 * No slash appears in the given file name. Set parent_dir to the current
1321 * directory, and the last component as the given name.
1323 fs_ExtractDriveLetter(true_name, parent_dir);
1324 strcat(parent_dir, ".");
1325 last_component = true_name;
1326 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
1329 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1330 fprintf(stderr,"fs: you may not use '.' or '..' as the last component\n");
1331 fprintf(stderr,"fs: of a name in the 'fs lsmount' command.\n");
1336 blob.in = last_component;
1337 blob.in_size = strlen(last_component)+1;
1338 blob.out_size = MAXSIZE;
1340 memset(space, 0, MAXSIZE);
1342 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1345 printf("'%s' is a %smount point for volume '%s'\n",
1347 (thru_symlink ? "symbolic link, leading to a " : ""),
1352 if (errno == EINVAL)
1353 fprintf(stderr,"'%s' is not a mount point.\n",
1356 Die(errno, (ti->data ? ti->data : parent_dir));
1363 static MakeMountCmd(as)
1364 register struct cmd_syndesc *as; {
1365 register afs_int32 code;
1366 register char *cellName, *volName, *tmpName;
1368 char localCellName[1000];
1369 #else /* not WIN32 */
1370 struct afsconf_cell info;
1371 struct vldbentry vldbEntry;
1372 #endif /* not WIN32 */
1373 struct ViceIoctl blob;
1379 if (as->parms[5].items && !as->parms[2].items) {
1380 fprintf(stderr,"fs: must provide cell when creating cellular mount point.\n");
1385 if (as->parms[2].items) /* cell name specified */
1386 cellName = as->parms[2].items->data;
1388 cellName = (char *) 0;
1389 volName = as->parms[1].items->data;
1391 if (strlen(volName) >= 64) {
1392 fprintf(stderr,"fs: volume name too long (length must be < 64 characters)\n");
1396 /* Check for a cellname in the volume specification, and complain
1397 * if it doesn't match what was specified with -cell */
1398 if (tmpName = strchr(volName, ':')) {
1401 if (foldcmp(cellName,volName)) {
1402 fprintf(stderr,"fs: cellnames do not match.\n");
1407 volName = ++tmpName;
1410 if (!InAFS(Parent(as->parms[0].items->data))) {
1411 fprintf(stderr,"fs: mount points must be created within the AFS file system\n");
1417 blob.out_size = MAXSIZE;
1419 code = pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME, &blob, 1);
1423 strcpy(localCellName, (cellName? cellName : space));
1424 #else /* not win32 */
1425 code = GetCellName(cellName?cellName:space, &info);
1429 if (!(as->parms[4].items)) {
1430 /* not fast, check which cell the mountpoint is being created in */
1432 /* not fast, check name with VLDB */
1434 code = VLDBInit(1, &info);
1436 /* make the check. Don't complain if there are problems with init */
1437 code = ubik_Call(VL_GetEntryByNameO, uclient, 0, volName, &vldbEntry);
1438 if (code == VL_NOENT) {
1439 fprintf(stderr,"fs: warning, volume %s does not exist in cell %s.\n",
1440 volName, cellName ? cellName : space);
1444 #endif /* not WIN32 */
1446 if (as->parms[3].items) /* if -rw specified */
1451 /* cellular mount point, prepend cell prefix */
1453 strcat(space, localCellName);
1454 #else /* not WIN32 */
1455 strcat(space, info.name);
1456 #endif /* not WIN32 */
1459 strcat(space, volName); /* append volume name */
1460 strcat(space, "."); /* stupid convention; these end with a period */
1462 /* create symlink with a special pioctl for Windows NT, since it doesn't
1463 * have a symlink system call.
1466 blob.in_size = 1 + strlen(space);
1469 code = pioctl(as->parms[0].items->data, VIOC_AFS_CREATE_MT_PT, &blob, 0);
1470 #else /* not WIN32 */
1471 code = symlink(space, as->parms[0].items->data);
1472 #endif /* not WIN32 */
1474 Die(errno, as->parms[0].items->data);
1481 * Delete AFS mount points. Variables are used as follows:
1482 * tbuffer: Set to point to the null-terminated directory name of the mount point
1483 * (or ``.'' if none is provided)
1484 * tp: Set to point to the actual name of the mount point to nuke.
1486 static RemoveMountCmd(as)
1487 register struct cmd_syndesc *as; {
1488 register afs_int32 code=0;
1489 struct ViceIoctl blob;
1490 register struct cmd_item *ti;
1492 char lsbuffer[1024];
1495 for(ti=as->parms[0].items; ti; ti=ti->next) {
1497 tp = (char *) strrchr(ti->data, '\\');
1499 tp = (char *) strrchr(ti->data, '/');
1501 strncpy(tbuffer, ti->data, code=tp-ti->data+1); /* the dir name */
1503 tp++; /* skip the slash */
1506 fs_ExtractDriveLetter(ti->data, tbuffer);
1507 strcat(tbuffer, ".");
1509 fs_StripDriveLetter(tp, tp, 0);
1512 blob.in_size = strlen(tp)+1;
1513 blob.out = lsbuffer;
1514 blob.out_size = sizeof(lsbuffer);
1515 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1517 if (errno == EINVAL)
1518 fprintf(stderr,"fs: '%s' is not a mount point.\n", ti->data);
1520 Die(errno, ti->data);
1522 continue; /* don't bother trying */
1526 blob.in_size = strlen(tp)+1;
1527 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1529 Die(errno, ti->data);
1539 static CheckServersCmd(as)
1540 register struct cmd_syndesc *as; {
1541 register afs_int32 code;
1542 struct ViceIoctl blob;
1543 register afs_int32 j;
1546 struct afsconf_cell info;
1547 struct chservinfo checkserv;
1549 memset(&checkserv, 0, sizeof(struct chservinfo));
1550 blob.in_size=sizeof(struct chservinfo);
1551 blob.in=(caddr_t)&checkserv;
1553 blob.out_size = MAXSIZE;
1555 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1557 /* prepare flags for checkservers command */
1558 temp = 2; /* default to checking local cell only */
1559 if (as->parms[2].items) temp |= 1; /* set fast flag */
1560 if (as->parms[1].items) temp &= ~2; /* turn off local cell check */
1562 checkserv.magic = 0x12345678; /* XXX */
1563 checkserv.tflags=temp;
1565 /* now copy in optional cell name, if specified */
1566 if (as->parms[0].items) {
1567 code = GetCellName(as->parms[0].items->data, &info);
1571 strcpy(checkserv.tbuffer,info.name);
1572 checkserv.tsize=strlen(info.name)+1;
1576 strcpy(checkserv.tbuffer,"\0");
1580 if(as->parms[3].items)
1582 checkserv.tinterval=atol(as->parms[3].items->data);
1585 if(checkserv.tinterval<0) {
1586 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
1587 checkserv.tinterval=0;
1588 } else if(checkserv.tinterval> 600) {
1589 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1590 checkserv.tinterval=600; /* 10 min max interval */
1594 checkserv.tinterval = -1; /* don't change current interval */
1597 code = pioctl(0, VIOCCKSERV, &blob, 1);
1599 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1600 printf("Must be root to change -interval\n");
1606 memcpy(&temp, space, sizeof(afs_int32));
1607 if (checkserv.tinterval >= 0) {
1608 if (checkserv.tinterval > 0)
1609 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1610 checkserv.tinterval, temp);
1612 printf("The current down server probe interval is %d secs\n", temp);
1616 printf("All servers are running.\n");
1619 printf("These servers unavailable due to network or server problems: ");
1620 for(j=0; j < MAXHOSTS; j++) {
1621 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
1622 if (temp == 0) break;
1623 tp = hostutil_GetNameByINet(temp);
1633 register struct cmd_syndesc *as; {
1634 register afs_int32 code=0;
1635 struct ViceIoctl blob;
1636 struct gaginfo gagflags;
1637 struct cmd_item *show;
1639 memset(&gagflags, 0, sizeof(struct gaginfo));
1640 blob.in_size = sizeof(struct gaginfo);
1641 blob.in = (caddr_t ) &gagflags;
1642 blob.out_size = MAXSIZE;
1644 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1646 if (show = as->parms[0].items)
1647 if (!foldcmp (show->data, "user"))
1648 gagflags.showflags |= GAGUSER;
1649 else if (!foldcmp (show->data, "console"))
1650 gagflags.showflags |= GAGCONSOLE;
1651 else if (!foldcmp (show->data, "all"))
1652 gagflags.showflags |= GAGCONSOLE | GAGUSER;
1653 else if (!foldcmp (show->data, "none"))
1657 "unrecognized flag %s: must be in {user,console,all,none}\n",
1665 code = pioctl(0, VIOC_GAG, &blob, 1);
1673 static CheckVolumesCmd(as)
1674 register struct cmd_syndesc *as; {
1675 register afs_int32 code;
1676 struct ViceIoctl blob;
1680 code = pioctl(0, VIOCCKBACK, &blob, 1);
1685 else printf("All volumeID/name mappings checked.\n");
1690 static SetCacheSizeCmd(as)
1691 register struct cmd_syndesc *as; {
1692 register afs_int32 code;
1693 struct ViceIoctl blob;
1696 if (!as->parms[0].items && !as->parms[1].items) {
1697 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
1700 if (as->parms[0].items) {
1701 code = util_GetInt32(as->parms[0].items->data, &temp);
1703 fprintf(stderr,"fs: bad integer specified for cache size.\n");
1709 blob.in = (char *) &temp;
1710 blob.in_size = sizeof(afs_int32);
1712 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
1714 Die(errno, (char *) 0);
1716 printf("New cache size set.\n");
1720 #define MAXGCSIZE 16
1721 static GetCacheParmsCmd(as)
1722 register struct cmd_syndesc *as; {
1723 register afs_int32 code;
1724 struct ViceIoctl blob;
1725 afs_int32 parms[MAXGCSIZE];
1727 blob.in = (char *) 0;
1729 blob.out_size = sizeof(parms);
1730 blob.out = (char *) parms;
1731 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
1733 Die(errno, (char *) 0);
1735 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
1736 parms[1], parms[0]);
1737 if (parms[1] > parms[0])
1738 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
1743 static ListCellsCmd(as)
1744 register struct cmd_syndesc *as; {
1745 register afs_int32 code;
1746 afs_int32 i, j, *lp, magic, size;
1748 afs_int32 clear, maxa = OMAXHOSTS;
1749 struct ViceIoctl blob;
1751 for(i=0;i<1000;i++) {
1753 memcpy(tp, &i, sizeof(afs_int32));
1754 tp = (char *)(space + sizeof(afs_int32));
1755 lp = (afs_int32 *)tp;
1757 size == sizeof(afs_int32) + sizeof(afs_int32);
1758 blob.out_size = MAXSIZE;
1759 blob.in_size = sizeof(afs_int32);
1762 code = pioctl(0, VIOCGETCELL, &blob, 1);
1764 if (errno == EDOM) break; /* done with the list */
1771 memcpy(&magic, tp, sizeof(afs_int32));
1772 if (magic == 0x12345678) {
1774 tp += sizeof(afs_int32);
1776 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
1777 for(j=0; j < maxa; j++) {
1778 memcpy(&clear, tp + j*sizeof(afs_int32), sizeof(afs_int32));
1779 if (clear == 0) break;
1780 tcp = hostutil_GetNameByINet(clear);
1788 static NewCellCmd(as)
1789 register struct cmd_syndesc *as; {
1791 register afs_int32 code, linkedstate=0, size=0, *lp;
1792 struct ViceIoctl blob;
1793 register struct cmd_item *ti;
1794 register char *tp, *cellname=0;
1795 register struct hostent *thp;
1796 afs_int32 fsport = 0, vlport = 0;
1798 memset(space, 0, MAXHOSTS * sizeof(afs_int32));
1800 lp = (afs_int32 *)tp;
1802 tp += sizeof(afs_int32);
1803 for(ti=as->parms[1].items; ti; ti=ti->next) {
1804 thp = hostutil_GetHostByName(ti->data);
1806 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
1810 memcpy(tp, thp->h_addr, sizeof(afs_int32));
1811 tp += sizeof(afs_int32);
1814 if (as->parms[2].items) {
1816 * Link the cell, for the purposes of volume location, to the specified
1819 cellname = as->parms[2].items->data;
1822 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
1823 if (as->parms[3].items) {
1824 code = util_GetInt32(as->parms[3].items->data, &vlport);
1826 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
1830 if (as->parms[4].items) {
1831 code = util_GetInt32(as->parms[4].items->data, &fsport);
1833 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
1838 tp = (char *)(space + (MAXHOSTS+1) *sizeof(afs_int32));
1839 lp = (afs_int32 *)tp;
1843 strcpy(space + ((MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
1844 size = ((MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
1845 tp = (char *)(space + size);
1847 strcpy(tp, cellname);
1848 size += strlen(cellname) + 1;
1850 blob.in_size = size;
1853 code = pioctl(0, VIOCNEWCELL, &blob, 1);
1858 fprintf(stderr, "fs: 'newcell' not implemented, since afsdcell.ini is\n");
1859 fprintf(stderr, "fs: re-read on every reference to a new cell, on Windows/NT.\n");
1864 static WhichCellCmd(as)
1865 register struct cmd_syndesc *as; {
1866 register afs_int32 code;
1867 struct ViceIoctl blob;
1868 register struct cmd_item *ti;
1871 error = 0; /* no error occurred */
1872 SetDotDefault(&as->parms[0].items);
1873 for(ti=as->parms[0].items; ti; ti=ti->next) {
1876 blob.out_size = MAXSIZE;
1879 code = pioctl(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
1881 if (errno == ENOENT)
1882 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
1884 Die(errno, ti->data);
1889 printf("File %s lives in cell '%s'\n", ti->data, space);
1894 static WSCellCmd(as)
1895 register struct cmd_syndesc *as; {
1896 register afs_int32 code;
1897 struct ViceIoctl blob;
1900 blob.in = (char *) 0;
1901 blob.out_size = MAXSIZE;
1904 code = pioctl((char *) 0, VIOC_GET_WS_CELL, &blob, 1);
1907 Die(errno, (char *) 0);
1910 printf("This workstation belongs to cell '%s'\n", space);
1914 static PrimaryCellCmd(as)
1915 register struct cmd_syndesc *as; {
1917 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
1922 static MonitorCmd(as)
1923 register struct cmd_syndesc *as; {
1924 register afs_int32 code;
1925 struct ViceIoctl blob;
1926 register struct cmd_item *ti;
1928 register struct hostent *thp;
1932 ti = as->parms[0].items;
1936 if (!strcmp(ti->data, "off"))
1937 hostAddr = 0xffffffff;
1939 thp = hostutil_GetHostByName(ti->data);
1941 if (!strcmp(ti->data, "localhost")) {
1942 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
1943 hostAddr = htonl(0x7f000001);
1946 fprintf(stderr,"host %s not found in host table.\n", ti->data);
1950 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
1954 hostAddr = 0; /* means don't set host */
1955 setp = 0; /* aren't setting host */
1958 /* now do operation */
1959 blob.in_size = sizeof(afs_int32);
1960 blob.out_size = sizeof(afs_int32);
1961 blob.in = (char *) &hostAddr;
1962 blob.out = (char *) &hostAddr;
1963 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
1969 printf("%s: new monitor host set.\n", pn);
1972 /* now decode old address */
1973 if (hostAddr == 0xffffffff) {
1974 printf("Cache monitoring is currently disabled.\n");
1977 tp = hostutil_GetNameByINet(hostAddr);
1978 printf("Using host %s for monitor services.\n", tp);
1984 static SysNameCmd(as)
1985 register struct cmd_syndesc *as; {
1986 register afs_int32 code;
1987 struct ViceIoctl blob;
1988 register struct cmd_item *ti;
1989 char *input = space;
1992 ti = as->parms[0].items;
1996 blob.out_size = MAXSIZE;
1997 blob.in_size = sizeof(afs_int32);
1998 memcpy(input, &setp, sizeof(afs_int32));
1999 input += sizeof(afs_int32);
2001 strcpy(input, ti->data);
2002 blob.in_size += strlen(ti->data) + 1;
2003 input += strlen(ti->data);
2006 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2012 printf("%s: new sysname set.\n", pn);
2016 memcpy(&setp, input, sizeof(afs_int32));
2017 input += sizeof(afs_int32);
2019 fprintf(stderr,"No sysname name value was found\n");
2021 printf("Current sysname is '%s'\n", input);
2027 char *exported_types[] = {"null", "nfs", ""};
2028 static ExportAfsCmd(as)
2029 register struct cmd_syndesc *as; {
2030 register afs_int32 code;
2031 struct ViceIoctl blob;
2032 register struct cmd_item *ti;
2033 int export=0, type=0, mode = 0, exp = 0, gstat = 0, exportcall, pwsync=0, smounts=0;
2035 ti = as->parms[0].items;
2036 if (strcmp(ti->data, "nfs") == 0) type = 0x71; /* NFS */
2038 fprintf(stderr,"Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
2041 ti = as->parms[1].items;
2043 if (strcmp(ti->data, "on") == 0) export = 3;
2044 else if (strcmp(ti->data, "off") == 0) export = 2;
2046 printf("Illegal argument %s\n", ti->data);
2051 if (ti = as->parms[2].items) { /* -noconvert */
2052 if (strcmp(ti->data, "on") == 0) mode = 2;
2053 else if (strcmp(ti->data, "off") == 0) mode = 3;
2055 printf("Illegal argument %s\n", ti->data);
2059 if (ti = as->parms[3].items) { /* -uidcheck */
2060 if (strcmp(ti->data, "on") == 0) pwsync = 3;
2061 else if (strcmp(ti->data, "off") == 0) pwsync = 2;
2063 printf("Illegal argument %s\n", ti->data);
2067 if (ti = as->parms[4].items) { /* -submounts */
2068 if (strcmp(ti->data, "on") == 0) smounts = 3;
2069 else if (strcmp(ti->data, "off") == 0) smounts = 2;
2071 printf("Illegal argument %s\n", ti->data);
2075 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2078 blob.in = (char *) &exportcall;
2079 blob.in_size = sizeof(afs_int32);
2080 blob.out = (char *) &exportcall;
2081 blob.out_size = sizeof(afs_int32);
2082 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2084 if (errno == ENODEV) {
2085 fprintf(stderr,"Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
2092 if (exportcall & 1) {
2093 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
2094 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
2095 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
2096 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
2098 printf("'%s' translator is disabled\n", exported_types[type]);
2105 static GetCellCmd(as)
2106 register struct cmd_syndesc *as; {
2107 register afs_int32 code;
2108 struct ViceIoctl blob;
2109 struct afsconf_cell info;
2110 register struct cmd_item *ti;
2116 for(ti=as->parms[0].items; ti; ti=ti->next) {
2118 blob.out_size = sizeof(args);
2119 blob.out = (caddr_t) &args;
2120 code = GetCellName(ti->data, &info);
2124 blob.in_size = 1+strlen(info.name);
2125 blob.in = info.name;
2126 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2128 if (errno == ENOENT)
2129 fprintf(stderr,"fs: the cell named '%s' does not exist\n", info.name);
2131 Die(errno, info.name);
2134 printf("Cell %s status: ", info.name);
2136 if (args.stat & 1) printf("primary ");
2138 if (args.stat & 2) printf("no setuid allowed");
2139 else printf("setuid allowed");
2140 if (args.stat & 4) printf(", using old VLDB");
2146 static SetCellCmd(as)
2147 register struct cmd_syndesc *as; {
2148 register afs_int32 code;
2149 struct ViceIoctl blob;
2150 struct afsconf_cell info;
2151 register struct cmd_item *ti;
2158 /* figure stuff to set */
2162 if (! as->parms[1].items) args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
2164 /* set stat for all listed cells */
2165 for(ti=as->parms[0].items; ti; ti=ti->next) {
2167 code = GetCellName(ti->data, &info);
2171 strcpy(args.cname, info.name);
2172 blob.in_size = sizeof(args);
2173 blob.in = (caddr_t) &args;
2175 blob.out = (caddr_t) 0;
2176 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2186 static GetCellName(char *cellNamep, struct afsconf_cell *infop)
2188 strcpy(infop->name, cellNamep);
2192 static VLDBInit(int noAuthFlag, struct afsconf_cell *infop)
2197 #else /* not WIN32 */
2199 static GetCellName(cellName, info)
2201 struct afsconf_cell *info;
2203 struct afsconf_dir *tdir;
2206 tdir = afsconf_Open(AFSCONF_CLIENTNAME);
2208 fprintf(stderr,"Could not process files in configuration directory (%s).\n",AFSCONF_CLIENTNAME);
2212 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2214 fprintf(stderr,"fs: cell %s not in %s/CellServDB\n", cellName, AFSCONF_CLIENTNAME);
2222 static VLDBInit(noAuthFlag, info)
2224 struct afsconf_cell *info;
2226 struct ktc_principal sname;
2227 struct ktc_token ttoken;
2229 struct rx_securityClass *sc;
2230 struct rx_connection *serverconns[VLDB_MAXSERVERS];
2235 fprintf(stderr,"fs: could not initialize rx.\n");
2239 rx_SetRxDeadTime(50);
2240 if (!noAuthFlag) { /* we don't need tickets for null */
2241 strcpy(sname.cell, info->name);
2242 sname.instance[0] = 0;
2243 strcpy(sname.name, "afs");
2244 code = ktc_GetToken(&sname,&ttoken, sizeof(ttoken), (char *)0);
2246 fprintf(stderr,"fs: Could not get afs tokens, running unauthenticated.\n");
2251 if (ttoken.kvno >= 0 && ttoken.kvno <= 255) scIndex = 2; /* kerberos */
2253 fprintf (stderr, "fs: funny kvno (%d) in ticket, proceeding\n",
2259 else scIndex = 0; /* don't authenticate */
2262 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
2268 sc = (struct rx_securityClass *)
2269 rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
2270 ttoken.kvno, ttoken.ticketLen,
2274 if (info->numServers > VLDB_MAXSERVERS) {
2275 fprintf(stderr, "fs: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n",
2276 info->numServers, VLDB_MAXSERVERS);
2279 memset(serverconns, 0, sizeof(serverconns));
2280 for (i = 0;i<info->numServers;i++)
2281 serverconns[i] = rx_NewConnection(info->hostAddr[i].sin_addr.s_addr,
2282 info->hostAddr[i].sin_port, USER_SERVICE_ID,
2285 code = ubik_ClientInit(serverconns, &uclient);
2288 fprintf(stderr,"fs: ubik client init failed.\n");
2293 #endif /* not WIN32 */
2295 static struct ViceIoctl gblob;
2296 static int debug = 0;
2298 * here follow some routines in suport of the setserverprefs and
2299 * getserverprefs commands. They are:
2300 * SetPrefCmd "top-level" routine
2301 * addServer adds a server to the list of servers to be poked into the
2302 * kernel. Will poke the list into the kernel if it threatens
2304 * pokeServers pokes the existing list of servers and ranks into the kernel
2305 * GetPrefCmd reads the Cache Manager's current list of server ranks
2308 static pokeServers()
2313 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2315 ssp = (cm_SSetPref_t *)space;
2316 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
2321 static addServer(name, rank)
2323 unsigned short rank;
2328 struct hostent *thostent;
2332 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
2334 #define MAXUSHORT ((unsigned short) ~0)
2339 thostent = hostutil_GetHostByName(name);
2341 fprintf (stderr, "%s: couldn't resolve name.\n", name);
2345 ssp = (cm_SSetPref_t *)(gblob.in);
2347 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
2348 code = pokeServers();
2349 ssp->num_servers = 0;
2352 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
2353 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
2354 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
2355 gblob.in_size += sizeof(cm_SPref_t);
2358 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
2364 static SetPrefCmd(as)
2365 register struct cmd_syndesc *as; {
2368 struct cmd_item *ti;
2373 ssp = (cm_SSetPref_t *)space;
2375 ssp->num_servers = 0;
2376 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
2379 gblob.out_size = MAXSIZE;
2384 fprintf (stderr,"Permission denied: requires root access.\n");
2391 ti = as->parms[2].items; /* -file */
2393 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
2394 if (!(infd = fopen(ti->data,"r" ))) {
2396 Die(errno,ti->data);
2399 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
2400 code = addServer (name, (unsigned short) rank);
2404 ti = as->parms[3].items; /* -stdin */
2406 while ( scanf("%79s%ld", name, &rank) != EOF) {
2407 code = addServer (name, (unsigned short) rank);
2411 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
2416 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
2418 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
2422 code = pokeServers();
2424 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
2426 ssp = (cm_SSetPref_t *)space;
2427 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
2429 ssp->flags = CM_SPREF_VLONLY;
2430 ssp->num_servers = 0;
2432 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
2437 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
2439 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
2444 if (as->parms[1].items) {
2446 printf("now poking vlservers\n");
2447 code = pokeServers();
2457 static GetPrefCmd(as)
2458 register struct cmd_syndesc *as; {
2460 struct cmd_item *ti;
2461 char *name, tbuffer[20];
2466 struct ViceIoctl blob;
2467 struct cm_SPrefRequest *in;
2468 struct cm_SPrefInfo *out;
2472 ti = as->parms[0].items; /* -file */
2474 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
2475 if (!(outfd = freopen(ti->data,"w",stdout))) {
2476 Die(errno,ti->data);
2481 ti = as->parms[1].items; /* -numeric */
2483 ti = as->parms[2].items; /* -vlservers */
2484 vlservers = (ti ? CM_SPREF_VLONLY : 0);
2485 /* ti = as->parms[3].items; -cell */
2487 in = (struct cm_SPrefRequest *)space;
2491 blob.in_size=sizeof(struct cm_SPrefRequest);
2492 blob.in = (char *)in;
2494 blob.out_size = MAXSIZE;
2496 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
2497 in->flags = vlservers;
2499 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
2501 perror("getserverprefs pioctl");
2505 out = (struct cm_SPrefInfo *) blob.out;
2507 for (i=0;i<out->num_servers;i++) {
2509 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
2512 addr = ntohl(out->servers[i].host.s_addr);
2513 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
2514 (addr>>8) & 0xff, addr & 0xff);
2517 printf ("%-50s %5u\n",name,out->servers[i].rank);
2520 in->offset = out->next_offset;
2522 } while (!code && out->next_offset > 0);
2527 static TraceCmd(struct cmd_syndesc *asp)
2530 struct ViceIoctl blob;
2534 if ((asp->parms[0].items && asp->parms[1].items)) {
2535 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
2539 /* determine if we're turning this tracing on or off */
2541 if (asp->parms[0].items)
2542 inValue = 3; /* enable */
2543 else if (asp->parms[1].items) inValue = 2; /* disable */
2544 if (asp->parms[2].items) inValue |= 4; /* do reset */
2545 if (asp->parms[3].items) inValue |= 8; /* dump */
2547 blob.in_size = sizeof(long);
2548 blob.in = (char *) &inValue;
2549 blob.out_size = sizeof(long);
2550 blob.out = (char *) &outValue;
2552 code = pioctl(NULL, VIOC_TRACECTL, &blob, 1);
2558 if (outValue) printf("AFS tracing enabled.\n");
2559 else printf("AFS tracing disabled.\n");
2564 static void sbusage()
2566 fprintf(stderr, "example usage: fs storebehind -files *.o -kb 99999 -default 0\n");
2567 fprintf(stderr, " fs sb 50000 *.[ao] -default 10\n");
2570 static StoreBehindCmd(as) /* fs sb -kbytes 9999 -files *.o -default 64 */
2571 struct cmd_syndesc *as; {
2573 struct ViceIoctl blob;
2574 struct cmd_item *ti;
2575 struct sbstruct tsb;
2578 if ((as->parms[0].items && as->parms[1].items) ||
2579 (!as->parms[0].items && !as->parms[1].items)) /* same as logical xor */
2586 ti=as->parms[2].items;
2587 if (ti && ti->data) {
2588 kb = atoi (ti->data);
2591 tsb.sb_default = kb;
2593 ti=as->parms[1].items;
2594 if (ti && ti->data) {
2595 kb = atoi (ti->data);
2598 tsb.sb_thisfile = kb;
2600 ti=as->parms[0].items;
2605 blob.in_size = sizeof(tsb);
2606 blob.out_size = sizeof(tsb);
2607 fprintf (stderr, "storbehind %s %d %d\n", (ti?ti->data:0),
2608 tsb.sb_thisfile, tsb.sb_default);
2609 code = pioctl((ti ? ti->data : 0) , VIOC_STOREBEHIND, &blob, 1);
2611 Die(errno, (ti ? ti->data : 0));
2614 if (blob.out_size == sizeof(tsb)) {
2615 fprintf (stderr, "storbehind %s is now %d (default %d)\n", (ti?ti->data:0),
2616 tsb.sb_thisfile, tsb.sb_default);
2618 ti = (ti ? ti->next : ti);
2624 static afs_int32 SetCryptCmd(as)
2625 struct cmd_syndesc *as;
2627 afs_int32 code = 0, flag;
2628 struct ViceIoctl blob;
2631 tp = as->parms[0].items->data;
2632 if (strcmp(tp, "on") == 0)
2634 else if (strcmp(tp, "off") == 0)
2637 fprintf (stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
2641 blob.in = (char *) &flag;
2642 blob.in_size = sizeof(flag);
2644 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
2646 Die(code, (char *) 0);
2650 static afs_int32 GetCryptCmd(as)
2651 struct cmd_syndesc *as;
2653 afs_int32 code = 0, flag;
2654 struct ViceIoctl blob;
2657 blob.in = (char *) 0;
2659 blob.out_size = sizeof(flag);
2662 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
2664 if (code) Die(code, (char *) 0);
2667 memcpy(&flag, tp, sizeof(afs_int32));
2668 printf("Security level is currently ");
2670 printf("crypt (data security).\n");
2680 register afs_int32 code;
2681 register struct cmd_syndesc *ts;
2683 #ifdef AFS_AIX32_ENV
2685 * The following signal action for AIX is necessary so that in case of a
2686 * crash (i.e. core is generated) we can include the user's data section
2687 * in the core dump. Unfortunately, by default, only a partial core is
2688 * generated which, in many cases, isn't too useful.
2690 struct sigaction nsa;
2692 sigemptyset(&nsa.sa_mask);
2693 nsa.sa_handler = SIG_DFL;
2694 nsa.sa_flags = SA_FULLDUMP;
2695 sigaction(SIGSEGV, &nsa, NULL);
2700 WSAStartup(0x0101, &WSAjunk);
2703 /* try to find volume location information */
2708 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0, "set server ranks");
2709 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
2710 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
2711 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
2712 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
2713 cmd_CreateAlias(ts, "sp");
2715 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0, "get server ranks");
2716 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
2717 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
2718 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
2719 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
2720 cmd_CreateAlias(ts, "gp");
2722 ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list");
2723 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
2724 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
2725 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
2726 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
2727 parm_setacl_id = ts->nParms;
2728 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
2729 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
2730 cmd_CreateAlias(ts, "sa");
2732 ts = cmd_CreateSyntax("listacl", ListACLCmd, 0, "list access control list");
2733 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2734 parm_listacl_id = ts->nParms;
2735 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
2736 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
2737 cmd_CreateAlias(ts, "la");
2739 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0, "clean up access control list");
2740 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2742 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0, "copy access control list");
2743 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
2744 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
2745 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
2746 parm_copyacl_id = ts->nParms;
2747 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
2748 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
2750 cmd_CreateAlias(ts, "ca");
2752 ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache");
2753 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2755 ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status");
2756 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2757 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
2759 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
2761 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
2762 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
2763 cmd_CreateAlias(ts, "sv");
2765 ts = cmd_CreateSyntax("messages", GagCmd, 0, "control Cache Manager messages");
2766 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
2768 ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display volume status");
2769 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2770 cmd_CreateAlias(ts, "lv");
2771 cmd_CreateAlias(ts, "listvol");
2773 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota");
2774 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2775 cmd_CreateAlias(ts, "lq");
2777 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0, "show server disk space usage");
2778 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2779 cmd_CreateAlias(ts, "df");
2781 ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage");
2782 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2784 ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point");
2785 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
2787 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point");
2788 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
2789 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
2790 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
2791 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
2792 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
2798 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
2802 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point");
2803 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
2805 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0, "check local cell's servers");
2806 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
2807 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
2808 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
2809 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
2811 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd,0, "check volumeID/name mappings");
2812 cmd_CreateAlias(ts, "checkbackups");
2815 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0, "set cache size");
2816 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
2817 cmd_CreateAlias(ts, "cachesize");
2819 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
2821 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0, "get cache usage info");
2823 ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0, "list configured cells");
2825 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota");
2826 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
2827 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
2829 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
2831 cmd_CreateAlias(ts, "sq");
2833 ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell");
2834 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
2835 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
2836 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
2838 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2840 * Turn this on only if you wish to be able to talk to a server which is listening
2841 * on alternative ports. This is not intended for general use and may not be
2842 * supported in the cache manager. It is not a way to run two servers at the
2843 * same host, since the cache manager cannot properly distinguish those two hosts.
2845 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
2846 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
2849 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell");
2850 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2852 ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location");
2853 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2855 ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell");
2858 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
2861 ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, "set cache monitor host address");
2862 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
2863 cmd_CreateAlias(ts, "mariner");
2866 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status");
2867 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
2869 ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status");
2870 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
2871 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
2872 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
2874 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0, "flush all data in volume");
2875 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2877 ts = cmd_CreateSyntax("sysname", SysNameCmd, 0, "get/set sysname (i.e. @sys) value");
2878 cmd_AddParm(ts, "-newsys", CMD_SINGLE, CMD_OPTIONAL, "new sysname");
2880 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0, "enable/disable translators to AFS");
2881 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
2882 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
2883 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
2884 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
2885 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
2888 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0,
2889 "store to server after file close");
2890 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
2891 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
2892 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
2893 cmd_CreateAlias(ts, "sb");
2895 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0, "set cache manager encryption flag");
2896 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
2898 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0, "get cache manager encryption flag");
2900 ts = cmd_CreateSyntax("trace", TraceCmd, 0, "enable or disable CM tracing");
2901 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
2902 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
2903 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
2904 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
2905 cmd_CreateAlias(ts, "tr");
2907 code = cmd_Dispatch(argc, argv);
2910 if (rxInitDone) rx_Finalize();
2911 #endif /* not WIN32 */
2916 void Die(code, filename)
2921 if (code == EINVAL) {
2923 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
2924 else fprintf(stderr,"%s: Invalid argument.\n", pn);
2926 else if (code == ENOENT) {
2927 if (filename) fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
2928 else fprintf(stderr,"%s: no such file returned\n", pn);
2930 else if (code == EROFS) fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
2931 else if (code == EACCES || code == EPERM) {
2932 if (filename) fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
2933 else fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
2935 else if (code == ENODEV) {
2936 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
2938 else if (code == ESRCH) {
2939 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
2941 else if (code == EPIPE) {
2942 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
2944 else if (code == EFBIG) {
2945 fprintf(stderr,"%s: Cache size too large.\n", pn);
2947 else if (code == ETIMEDOUT) {
2949 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
2951 fprintf(stderr,"%s: Connection timed out", pn);
2954 if (filename) fprintf(stderr,"%s:'%s'", pn, filename);
2955 else fprintf(stderr,"%s", pn);
2957 fprintf(stderr, ": code 0x%x\n", code);
2958 #else /* not WIN32 */
2959 fprintf(stderr,": %s\n", error_message(code));
2960 #endif /* not WIN32 */