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>
36 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
37 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
39 static char space[MAXSIZE];
40 static char tspace[1024];
43 static struct ubik_client *uclient;
44 #endif /* not WIN32 */
46 static MemDumpCmd(struct cmd_syndesc *asp);
48 extern afs_int32 VL_GetEntryByNameO();
50 static char pn[] = "fs";
51 static int rxInitDone = 0;
55 #define MAXCELLCHARS 64
56 #define MAXHOSTCHARS 64
57 #define MAXHOSTSPERCELL 8
60 char name[MAXCELLCHARS];
63 struct sockaddr_in hostAddr[MAXHOSTSPERCELL];
64 char hostName[MAXHOSTSPERCELL][MAXHOSTCHARS];
70 * Character to use between name and rights in printed representation for
73 #define DFS_SEPARATOR ' '
75 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
78 int dfs; /* Originally true if a dfs acl; now also the type
79 of the acl (1, 2, or 3, corresponding to object,
80 initial dir, or initial object). */
81 sec_rgy_name_t cell; /* DFS cell name */
84 struct AclEntry *pluslist;
85 struct AclEntry *minuslist;
89 struct AclEntry *next;
96 ZapList(acl->pluslist);
97 ZapList(acl->minuslist);
108 if (t >= 'A' && t <= 'Z') t += 0x20;
109 if (u >= 'A' && u <= 'Z') u += 0x20;
110 if (t != u) return 1;
111 if (t == 0) return 0;
116 * Mods for the AFS/DFS protocol translator.
118 * DFS rights. It's ugly to put these definitions here, but they
119 * *cannot* change, because they're part of the wire protocol.
120 * In any event, the protocol translator will guarantee these
121 * assignments for AFS cache managers.
123 #define DFS_READ 0x01
124 #define DFS_WRITE 0x02
125 #define DFS_EXECUTE 0x04
126 #define DFS_CONTROL 0x08
127 #define DFS_INSERT 0x10
128 #define DFS_DELETE 0x20
130 /* the application definable ones (backwards from AFS) */
131 #define DFS_USR0 0x80000000 /* "A" bit */
132 #define DFS_USR1 0x40000000 /* "B" bit */
133 #define DFS_USR2 0x20000000 /* "C" bit */
134 #define DFS_USR3 0x10000000 /* "D" bit */
135 #define DFS_USR4 0x08000000 /* "E" bit */
136 #define DFS_USR5 0x04000000 /* "F" bit */
137 #define DFS_USR6 0x02000000 /* "G" bit */
138 #define DFS_USR7 0x01000000 /* "H" bit */
139 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
140 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
143 * Offset of -id switch in command structure for various commands.
144 * The -if switch is the next switch always.
146 int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
149 * Determine whether either the -id or -if switches are present, and
150 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
153 struct cmd_syndesc *as;
154 int id; /* Offset of -id switch; -if is next switch */
158 if (as->parms[id].items) {
161 if (as->parms[id + 1].items) {
167 "%s: you may specify either -id or -if, but not both switches\n",
174 void PRights (arights, dfs)
175 register afs_int32 arights;
179 if (arights & PRSFS_READ) printf("r");
180 if (arights & PRSFS_LOOKUP) printf("l");
181 if (arights & PRSFS_INSERT) printf("i");
182 if (arights & PRSFS_DELETE) printf("d");
183 if (arights & PRSFS_WRITE) printf("w");
184 if (arights & PRSFS_LOCK) printf("k");
185 if (arights & PRSFS_ADMINISTER) printf("a");
186 if (arights & PRSFS_USR0) printf("A");
187 if (arights & PRSFS_USR1) printf("B");
188 if (arights & PRSFS_USR2) printf("C");
189 if (arights & PRSFS_USR3) printf("D");
190 if (arights & PRSFS_USR4) printf("E");
191 if (arights & PRSFS_USR5) printf("F");
192 if (arights & PRSFS_USR6) printf("G");
193 if (arights & PRSFS_USR7) printf("H");
195 if (arights & DFS_READ) printf("r"); else printf("-");
196 if (arights & DFS_WRITE) printf("w"); else printf("-");
197 if (arights & DFS_EXECUTE) printf("x"); else printf("-");
198 if (arights & DFS_CONTROL) printf("c"); else printf("-");
199 if (arights & DFS_INSERT) printf("i"); else printf("-");
200 if (arights & DFS_DELETE) printf("d"); else printf("-");
201 if (arights & (DFS_USRALL)) printf("+");
202 if (arights & DFS_USR0) printf("A");
203 if (arights & DFS_USR1) printf("B");
204 if (arights & DFS_USR2) printf("C");
205 if (arights & DFS_USR3) printf("D");
206 if (arights & DFS_USR4) printf("E");
207 if (arights & DFS_USR5) printf("F");
208 if (arights & DFS_USR6) printf("G");
209 if (arights & DFS_USR7) printf("H");
213 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
214 static int InAFS(apath)
215 register char *apath; {
216 struct ViceIoctl blob;
217 register afs_int32 code;
220 blob.out_size = MAXSIZE;
223 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
225 if ((errno == EINVAL) || (errno == ENOENT)) return 0;
230 /* return a static pointer to a buffer */
231 static char *Parent(apath)
234 strcpy(tspace, apath);
235 tp = strrchr(tspace, '\\');
237 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
240 fs_ExtractDriveLetter(apath, tspace);
246 enum rtype {add, destroy, deny};
248 afs_int32 Convert(arights, dfs, rtypep)
249 register char *arights;
257 *rtypep = add; /* add rights, by default */
260 if (!strcmp(arights, "null")) {
264 if (!strcmp(arights,"read")) return DFS_READ | DFS_EXECUTE;
265 if (!strcmp(arights, "write")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE;
266 if (!strcmp(arights, "all")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE | DFS_CONTROL;
268 if (!strcmp(arights,"read")) return PRSFS_READ | PRSFS_LOOKUP;
269 if (!strcmp(arights, "write")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK;
270 if (!strcmp(arights, "mail")) return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
271 if (!strcmp(arights, "all")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
273 if (!strcmp(arights, "none")) {
274 *rtypep = destroy; /* Remove entire entry */
277 len = strlen(arights);
282 if (tc == '-') continue;
283 else if (tc == 'r') mode |= DFS_READ;
284 else if (tc == 'w') mode |= DFS_WRITE;
285 else if (tc == 'x') mode |= DFS_EXECUTE;
286 else if (tc == 'c') mode |= DFS_CONTROL;
287 else if (tc == 'i') mode |= DFS_INSERT;
288 else if (tc == 'd') mode |= DFS_DELETE;
289 else if (tc == 'A') mode |= DFS_USR0;
290 else if (tc == 'B') mode |= DFS_USR1;
291 else if (tc == 'C') mode |= DFS_USR2;
292 else if (tc == 'D') mode |= DFS_USR3;
293 else if (tc == 'E') mode |= DFS_USR4;
294 else if (tc == 'F') mode |= DFS_USR5;
295 else if (tc == 'G') mode |= DFS_USR6;
296 else if (tc == 'H') mode |= DFS_USR7;
298 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n", pn, tc);
302 if (tc == 'r') mode |= PRSFS_READ;
303 else if (tc == 'l') mode |= PRSFS_LOOKUP;
304 else if (tc == 'i') mode |= PRSFS_INSERT;
305 else if (tc == 'd') mode |= PRSFS_DELETE;
306 else if (tc == 'w') mode |= PRSFS_WRITE;
307 else if (tc == 'k') mode |= PRSFS_LOCK;
308 else if (tc == 'a') mode |= PRSFS_ADMINISTER;
309 else if (tc == 'A') mode |= PRSFS_USR0;
310 else if (tc == 'B') mode |= PRSFS_USR1;
311 else if (tc == 'C') mode |= PRSFS_USR2;
312 else if (tc == 'D') mode |= PRSFS_USR3;
313 else if (tc == 'E') mode |= PRSFS_USR4;
314 else if (tc == 'F') mode |= PRSFS_USR5;
315 else if (tc == 'G') mode |= PRSFS_USR6;
316 else if (tc == 'H') mode |= PRSFS_USR7;
318 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn, tc);
326 struct AclEntry *FindList (alist, aname)
328 register struct AclEntry *alist; {
330 if (!foldcmp(alist->name, aname)) return alist;
336 /* if no parm specified in a particular slot, set parm to be "." instead */
337 static void SetDotDefault(aitemp)
338 struct cmd_item **aitemp; {
339 register struct cmd_item *ti;
340 if (*aitemp) return; /* already has value */
341 /* otherwise, allocate an item representing "." */
342 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
343 ti->next = (struct cmd_item *) 0;
344 ti->data = (char *) malloc(2);
345 strcpy(ti->data, ".");
349 void ChangeList (al, plus, aname, arights)
352 afs_int32 arights, plus; {
353 struct AclEntry *tlist;
354 tlist = (plus ? al->pluslist : al->minuslist);
355 tlist = FindList (tlist, aname);
357 /* Found the item already in the list. */
358 tlist->rights = arights;
360 al->nplus -= PruneList(&al->pluslist, al->dfs);
362 al->nminus -= PruneList(&al->minuslist, al->dfs);
365 /* Otherwise we make a new item and plug in the new data. */
366 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
367 strcpy(tlist->name, aname);
368 tlist->rights = arights;
370 tlist->next = al->pluslist;
371 al->pluslist = tlist;
373 if (arights == 0 || arights == -1)
374 al->nplus -= PruneList(&al->pluslist, al->dfs);
377 tlist->next = al->minuslist;
378 al->minuslist = tlist;
380 if (arights == 0) al->nminus -= PruneList(&al->minuslist, al->dfs);
385 struct AclEntry *alist; {
386 register struct AclEntry *tp, *np;
387 for (tp = alist; tp; tp = np) {
393 int PruneList (ae, dfs)
394 struct AclEntry **ae;
397 struct AclEntry **lp;
398 struct AclEntry *te, *ne;
402 for(te = *ae;te;te=ne) {
403 if ((!dfs && te->rights == 0) || te->rights == -1) {
417 char *SkipLine (astr)
418 register char *astr; {
419 while (*astr !='\n') astr++;
425 * Create an empty acl, taking into account whether the acl pointed
426 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
427 * can recover from problems caused by bogus ACL's (in that case, always
428 * assume that the acl is AFS: for DFS, the user can always resort to
429 * acl_edit, but for AFS there may be no other way out).
431 struct Acl *EmptyAcl(astr)
434 register struct Acl *tp;
437 tp = (struct Acl *)malloc(sizeof (struct Acl));
438 tp->nplus = tp->nminus = 0;
439 tp->pluslist = tp->minuslist = 0;
441 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
445 struct Acl *ParseAcl (astr)
447 int nplus, nminus, i, trights;
449 struct AclEntry *first, *last, *tl;
452 ta = (struct Acl *) malloc (sizeof (struct Acl));
454 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
455 astr = SkipLine(astr);
456 sscanf(astr, "%d", &ta->nminus);
457 astr = SkipLine(astr);
464 for(i=0;i<nplus;i++) {
465 sscanf(astr, "%100s %d", tname, &trights);
466 astr = SkipLine(astr);
467 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
468 if (!first) first = tl;
469 strcpy(tl->name, tname);
470 tl->rights = trights;
472 if (last) last->next = tl;
475 ta->pluslist = first;
479 for(i=0;i<nminus;i++) {
480 sscanf(astr, "%100s %d", tname, &trights);
481 astr = SkipLine(astr);
482 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
483 if (!first) first = tl;
484 strcpy(tl->name, tname);
485 tl->rights = trights;
487 if (last) last->next = tl;
490 ta->minuslist = first;
495 void PrintStatus(status, name, motd, offmsg)
496 VolumeStatus *status;
500 printf("Volume status for vid = %u named %s\n",status->Vid, name);
502 printf("Current offline message is %s\n",offmsg);
504 printf("Current message of the day is %s\n",motd);
505 printf("Current disk quota is ");
506 if (status->MaxQuota != 0) printf("%d\n", status->MaxQuota);
507 else printf("unlimited\n");
508 printf("Current blocks used are %d\n",status->BlocksInUse);
509 printf("The partition has %d blocks available out of %d\n\n",status->PartBlocksAvail, status->PartMaxBlocks);
512 void QuickPrintStatus(status, name)
513 VolumeStatus *status;
515 double QuotaUsed =0.0;
516 double PartUsed =0.0;
518 printf("%-25.25s",name);
520 if (status->MaxQuota != 0) {
521 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
522 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
524 printf("no limit%10d", status->BlocksInUse);
526 if (QuotaUsed > 90.0){
527 printf(" %5.0f%%<<", QuotaUsed);
530 else printf(" %5.0f%% ", QuotaUsed);
531 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
532 if (PartUsed > 97.0){
533 printf(" %9.0f%%<<", PartUsed);
536 else printf(" %9.0f%% ", PartUsed);
538 printf("\t<<WARNING\n");
543 void QuickPrintSpace(status, name)
544 VolumeStatus *status;
546 double PartUsed =0.0;
548 printf("%-25.25s",name);
550 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
552 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
553 if (PartUsed > 90.0){
554 printf(" %4.0f%%<<", PartUsed);
557 else printf(" %4.0f%% ", PartUsed);
559 printf("\t<<WARNING\n");
564 char *AclToString(acl)
566 static char mydata[MAXSIZE];
567 char tstring[MAXSIZE];
571 if (acl->dfs) sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
572 else dfsstring[0] = '\0';
573 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
574 for(tp = acl->pluslist;tp;tp=tp->next) {
575 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
576 strcat(mydata, tstring);
578 for(tp = acl->minuslist;tp;tp=tp->next) {
579 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
580 strcat(mydata, tstring);
586 struct cmd_syndesc *as; {
587 register afs_int32 code;
588 struct ViceIoctl blob;
590 register struct cmd_item *ti, *ui;
594 int idf = getidf(as, parm_setacl_id);
596 if (as->parms[2].items) clear=1;
598 plusp = !(as->parms[3].items);
599 for(ti=as->parms[0].items; ti;ti=ti->next) {
600 blob.out_size = MAXSIZE;
602 blob.in = blob.out = space;
603 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
605 Die(errno, ti->data);
608 ta = ParseAcl(space);
609 if (!plusp && ta->dfs) {
611 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
613 "(you may specify \"null\" to revoke all rights, however)\n");
616 if (clear) ta = EmptyAcl(space);
617 else ta = ParseAcl(space);
619 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
622 fprintf(stderr,"%s: Missing second half of user/access pair.\n", pn);
625 rights = Convert(ui->next->data, ta->dfs, &rtype);
626 if (rtype == destroy && !ta->dfs) {
627 if (!FindList(ta->pluslist, ui->data)) {
628 fprintf(stderr,"%s: Invalid arg (%s doesn't exist in the current acl)\n", pn, ui->data);
632 if (rtype == deny && !ta->dfs) plusp = 0;
633 if (rtype == destroy && ta->dfs) rights = -1;
634 ChangeList(ta, plusp, ui->data, rights);
636 blob.in = AclToString(ta);
638 blob.in_size = 1+strlen(blob.in);
639 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
641 if (errno == EINVAL) {
643 static char *fsenv = 0;
645 fsenv = (char *)getenv("FS_EXPERT");
647 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
650 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
651 "\nPossible reasons for this include:\n\n",
652 " -You may have specified an inappropriate combination of rights.\n",
653 " For example, some DFS-supported filesystems may not allow you to\n",
654 " drop the \"c\" right from \"user_obj\".\n\n",
655 " -A mask_obj may be required (it is likely required by the underlying\n",
656 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
657 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
658 " does not automatically create or update the mask_obj. Try setting\n",
659 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
660 " users or groups. You can do this with a single command, such as\n",
661 " \"fs sa mask_obj all user:somename read\"\n\n",
662 " -A specified user or group may not exist.\n\n",
663 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
664 " This is probably not allowed by the underlying file system.\n\n",
665 " -If you add a user or group to a DFS ACL, remember that it must be\n",
666 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
667 " may be local requirements on the format of the user or group name.\n",
668 " Check with your cell administrator.\n\n",
669 " -Or numerous other possibilities. It would be great if we could be more\n",
670 " precise about the actual problem, but for various reasons, this is\n",
671 " impractical via this interface. If you can't figure it out, you\n",
672 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
673 " whatever is provided). You may get better results. Good luck!\n\n",
674 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
677 fprintf(stderr,"%s: Invalid argument, possible reasons include:\n", pn);
678 fprintf(stderr,"\t-File not in AFS\n");
679 fprintf(stderr,"\t-Too many users on access control list\n");
680 fprintf(stderr,"\t-Tried to add non-existent user to access control list\n");
685 Die(errno, ti->data);
694 static CopyACLCmd(as)
695 struct cmd_syndesc *as; {
696 register afs_int32 code;
697 struct ViceIoctl blob;
700 register struct cmd_item *ti;
702 int idf = getidf(as, parm_copyacl_id);
704 if (as->parms[2].items) clear=1;
706 blob.out_size = MAXSIZE;
708 blob.in = blob.out = space;
709 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
711 Die(errno, as->parms[0].items->data);
714 fa = ParseAcl(space);
716 for (ti=as->parms[1].items; ti;ti=ti->next) {
717 blob.out_size = MAXSIZE;
719 blob.in = blob.out = space;
720 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
722 Die(errno, ti->data);
725 if (clear) ta = EmptyAcl(space);
726 else ta = ParseAcl(space);
728 if (ta->dfs != fa->dfs) {
729 fprintf(stderr, "fs: incompatible file system types: acl not copied to %s; aborted\n", ti->data);
733 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
734 fprintf(stderr, "fs: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n", ti->data);
737 strcpy(ta->cell, fa->cell);
739 for (tp = fa->pluslist;tp;tp=tp->next)
740 ChangeList(ta, 1, tp->name, tp->rights);
741 for (tp = fa->minuslist;tp;tp=tp->next)
742 ChangeList(ta, 0, tp->name, tp->rights);
743 blob.in = AclToString(ta);
745 blob.in_size = 1+strlen(blob.in);
746 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
748 if (errno == EINVAL) {
749 fprintf(stderr,"%s: Invalid argument, possible reasons include:\n", pn);
750 fprintf(stderr,"\t-File not in AFS\n");
754 Die(errno, ti->data);
766 /* tell if a name is 23 or -45 (digits or minus digits), which are bad names we must prune */
767 static BadName(aname)
768 register char *aname; {
770 while(tc = *aname++) {
771 /* all must be '-' or digit to be bad */
772 if (tc != '-' && (tc < '0' || tc > '9')) return 0;
778 /* clean up an access control list of its bad entries; return 1 if we made
779 any changes to the list, and 0 otherwise */
782 register struct AclEntry *te, **le, *ne;
785 /* Don't correct DFS ACL's for now */
789 /* prune out bad entries */
790 changes = 0; /* count deleted entries */
792 for(te = aa->pluslist; te; te=ne) {
794 if (BadName(te->name)) {
806 for(te = aa->minuslist; te; te=ne) {
808 if (BadName(te->name)) {
823 /* clean up an acl to not have bogus entries */
824 static CleanACLCmd(as)
825 register struct cmd_syndesc *as; {
826 register afs_int32 code;
827 register struct Acl *ta;
828 struct ViceIoctl blob;
830 register struct cmd_item *ti;
831 register struct AclEntry *te;
833 SetDotDefault(&as->parms[0].items);
834 for(ti=as->parms[0].items; ti; ti=ti->next) {
835 blob.out_size = MAXSIZE;
838 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
840 Die(errno, ti->data);
843 ta = ParseAcl(space);
847 "%s: cleanacl is not supported for DFS access lists.\n",
852 changes = CleanAcl(ta);
855 /* now set the acl */
856 blob.in=AclToString(ta);
857 blob.in_size = strlen(blob.in)+1;
859 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
861 if (errno == EINVAL) {
862 fprintf(stderr,"%s: Invalid argument, possible reasons include\n", pn);
863 fprintf(stderr,"%s: File not in vice or\n", pn);
864 fprintf(stderr,"%s: Too many users on access control list or\n", pn);
868 Die(errno, ti->data);
873 /* now list the updated acl */
874 printf("Access list for %s is now\n", ti->data);
876 if (!ta->dfs) printf("Normal rights:\n");
877 for(te = ta->pluslist;te;te=te->next) {
878 printf(" %s ", te->name);
879 PRights(te->rights, ta->dfs);
883 if (ta->nminus > 0) {
884 printf("Negative rights:\n");
885 for(te = ta->minuslist;te;te=te->next) {
886 printf(" %s ", te->name);
887 PRights(te->rights, ta->dfs);
891 if (ti->next) printf("\n");
894 printf("Access list for %s is fine.\n", ti->data);
899 static ListACLCmd(as)
900 register struct cmd_syndesc *as; {
901 register afs_int32 code;
902 register struct Acl *ta;
903 struct ViceIoctl blob;
905 register struct cmd_item *ti;
906 int idf = getidf(as, parm_listacl_id);
908 SetDotDefault(&as->parms[0].items);
909 for(ti=as->parms[0].items; ti; ti=ti->next) {
911 blob.out_size = MAXSIZE;
913 blob.in = blob.out = space;
914 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
916 Die(errno, ti->data);
919 ta = ParseAcl(space);
922 printf("Access list for %s is\n", ti->data);
925 printf("DFS access list for %s is\n", ti->data);
928 printf("DFS initial directory access list of %s is\n", ti->data);
931 printf("DFS initial file access list of %s is\n", ti->data);
935 printf(" Default cell = %s\n", ta->cell);
937 separator = ta->dfs? DFS_SEPARATOR : ' ';
939 if (!ta->dfs) printf("Normal rights:\n");
940 for(te = ta->pluslist;te;te=te->next) {
941 printf(" %s%c", te->name, separator);
942 PRights(te->rights, ta->dfs);
946 if (ta->nminus > 0) {
947 printf("Negative rights:\n");
948 for(te = ta->minuslist;te;te=te->next) {
949 printf(" %s ", te->name);
950 PRights(te->rights, ta->dfs);
954 if (ti->next) printf("\n");
959 static FlushVolumeCmd(as)
960 register struct cmd_syndesc *as; {
961 register afs_int32 code;
962 struct ViceIoctl blob;
963 register struct cmd_item *ti;
965 for(ti=as->parms[0].items; ti; ti=ti->next) {
966 blob.in_size = blob.out_size = 0;
967 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
969 fprintf(stderr, "Error flushing volume\n");
978 register struct cmd_syndesc *as; {
979 register afs_int32 code;
980 struct ViceIoctl blob;
982 register struct cmd_item *ti;
985 for(ti=as->parms[0].items; ti; ti=ti->next) {
986 blob.in_size = blob.out_size = 0;
987 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
990 if (errno == EMFILE) {
991 fprintf(stderr,"%s: Can't flush active file %s\n", pn, ti->data);
995 fprintf(stderr, "Error flushing file\n");
1004 /* all this command does is repackage its args and call SetVolCmd */
1005 static SetQuotaCmd(as)
1006 register struct cmd_syndesc *as; {
1007 struct cmd_syndesc ts;
1009 /* copy useful stuff from our command slot; we may later have to reorder */
1010 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1011 return SetVolCmd(&ts);
1014 static SetVolCmd(as)
1015 register struct cmd_syndesc *as; {
1016 register afs_int32 code;
1017 struct ViceIoctl blob;
1018 register struct cmd_item *ti;
1019 struct VolumeStatus *status;
1020 char *motd, *offmsg, *input;
1022 SetDotDefault(&as->parms[0].items);
1023 for(ti=as->parms[0].items; ti; ti=ti->next) {
1025 blob.out_size = MAXSIZE;
1026 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1029 status = (VolumeStatus *)space;
1030 status->MinQuota = status->MaxQuota = -1;
1031 motd = offmsg = (char *) 0;
1032 if (as->parms[1].items) {
1033 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1035 fprintf(stderr,"fs: bad integer specified for quota.\n");
1039 if (as->parms[2].items) motd = as->parms[2].items->data;
1040 if (as->parms[3].items) offmsg = as->parms[3].items->data;
1041 input = (char *)status + sizeof(*status);
1042 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1044 if (strlen(offmsg) >= VMSGSIZE) {
1045 fprintf(stderr,"fs: message must be shorter than %d characters\n",
1049 strcpy(input,offmsg);
1050 blob.in_size += strlen(offmsg);
1051 input += strlen(offmsg) + 1;
1053 else *(input++) = '\0';
1055 if (strlen(motd) >= VMSGSIZE) {
1056 fprintf(stderr,"fs: message must be shorter than %d characters\n",
1061 blob.in_size += strlen(motd);
1062 input += strlen(motd) + 1;
1064 else *(input++) = '\0';
1065 code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1);
1067 Die(errno, ti->data);
1074 static ExamineCmd(as)
1075 register struct cmd_syndesc *as; {
1076 register afs_int32 code;
1077 struct ViceIoctl blob;
1078 register struct cmd_item *ti;
1079 struct VolumeStatus *status;
1080 char *name, *offmsg, *motd;
1084 SetDotDefault(&as->parms[0].items);
1085 for(ti=as->parms[0].items; ti; ti=ti->next) {
1087 blob.out_size = MAXSIZE;
1090 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1092 Die(errno, ti->data);
1096 status = (VolumeStatus *)space;
1097 name = (char *)status + sizeof(*status);
1098 offmsg = name + strlen(name) + 1;
1099 motd = offmsg + strlen(offmsg) + 1;
1100 PrintStatus(status, name, motd, offmsg);
1105 static ListQuotaCmd(as)
1106 register struct cmd_syndesc *as; {
1107 register afs_int32 code;
1108 struct ViceIoctl blob;
1109 register struct cmd_item *ti;
1110 struct VolumeStatus *status;
1113 printf("%-25s%-10s%-10s%-7s%-13s\n",
1114 "Volume Name", " Quota", " Used", " %Used", " Partition");
1115 SetDotDefault(&as->parms[0].items);
1116 for(ti=as->parms[0].items; ti; ti=ti->next) {
1118 blob.out_size = MAXSIZE;
1121 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1123 Die(errno, ti->data);
1126 status = (VolumeStatus *)space;
1127 name = (char *)status + sizeof(*status);
1128 QuickPrintStatus(status, name);
1133 static WhereIsCmd(as)
1134 register struct cmd_syndesc *as; {
1135 register afs_int32 code;
1136 struct ViceIoctl blob;
1137 register struct cmd_item *ti;
1142 SetDotDefault(&as->parms[0].items);
1143 for(ti=as->parms[0].items; ti; ti=ti->next) {
1145 blob.out_size = MAXSIZE;
1148 memset(space, 0, sizeof(space));
1149 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1151 Die(errno, ti->data);
1154 hosts = (afs_int32 *) space;
1155 printf("File %s is on host%s ", ti->data, (hosts[0] && !hosts[1]) ? "": "s");
1156 for(j=0; j<MAXHOSTS; j++) {
1157 if (hosts[j] == 0) break;
1158 tp = hostutil_GetNameByINet(hosts[j]);
1167 static DiskFreeCmd(as)
1168 register struct cmd_syndesc *as; {
1169 register afs_int32 code;
1170 struct ViceIoctl blob;
1171 register struct cmd_item *ti;
1173 struct VolumeStatus *status;
1175 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1176 " used", " avail", " %used");
1177 SetDotDefault(&as->parms[0].items);
1178 for(ti=as->parms[0].items; ti; ti=ti->next) {
1180 blob.out_size = MAXSIZE;
1183 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1185 Die(errno, ti->data);
1188 status = (VolumeStatus *)space;
1189 name = (char *)status + sizeof(*status);
1190 QuickPrintSpace(status, name);
1196 register struct cmd_syndesc *as; {
1197 register afs_int32 code;
1198 struct ViceIoctl blob;
1199 register struct cmd_item *ti;
1201 struct VolumeStatus *status;
1203 SetDotDefault(&as->parms[0].items);
1204 for(ti=as->parms[0].items; ti; ti=ti->next) {
1206 blob.out_size = MAXSIZE;
1209 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1211 Die(errno, ti->data);
1214 status = (VolumeStatus *)space;
1215 if (status->MaxQuota) quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1216 else quotaPct = 0.0;
1217 printf("%2.0f%% of quota used.\n", quotaPct);
1222 static ListMountCmd(as)
1223 register struct cmd_syndesc *as; {
1224 register afs_int32 code;
1225 struct ViceIoctl blob;
1227 register struct cmd_item *ti;
1228 char orig_name[1024]; /*Original name, may be modified*/
1229 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1230 char parent_dir[1024]; /*Parent directory of true name*/
1231 register char *last_component; /*Last component of true name*/
1233 struct stat statbuff; /*Buffer for status info*/
1234 #endif /* not WIN32 */
1236 int link_chars_read; /*Num chars read in readlink()*/
1237 #endif /* not WIN32 */
1238 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1241 for(ti=as->parms[0].items; ti; ti=ti->next) {
1245 strcpy(orig_name, ti->data);
1246 #else /* not WIN32 */
1247 sprintf(orig_name, "%s%s",
1248 (ti->data[0] == '/') ? "" : "./",
1250 #endif /* not WIN32 */
1253 if (lstat(orig_name, &statbuff) < 0) {
1254 /* if lstat fails, we should still try the pioctl, since it
1255 may work (for example, lstat will fail, but pioctl will
1256 work if the volume of offline (returning ENODEV). */
1257 statbuff.st_mode = S_IFDIR; /* lie like pros */
1261 * The lstat succeeded. If the given file is a symlink, substitute
1262 * the file name with the link name.
1264 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1267 * Read name of resolved file.
1269 link_chars_read = readlink(orig_name, true_name, 1024);
1270 if (link_chars_read <= 0) {
1271 fprintf(stderr,"%s: Can't read target name for '%s' symbolic link!\n",
1277 * Add a trailing null to what was read, bump the length.
1279 true_name[link_chars_read++] = 0;
1282 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1283 * have to create a full pathname using the original name and the
1284 * relative symlink name. Find the rightmost slash in the original
1285 * name (we know there is one) and splice in the symlink value.
1287 if (true_name[0] != '\\') {
1288 last_component = (char *) strrchr(orig_name, '\\');
1289 strcpy(++last_component, true_name);
1290 strcpy(true_name, orig_name);
1294 strcpy(true_name, orig_name);
1296 strcpy(true_name, orig_name);
1300 * Find rightmost slash, if any.
1302 last_component = (char *) strrchr(true_name, '\\');
1303 if (!last_component)
1304 last_component = (char *) strrchr(true_name, '/');
1305 if (last_component) {
1307 * Found it. Designate everything before it as the parent directory,
1308 * everything after it as the final component.
1310 strncpy(parent_dir, true_name, last_component - true_name + 1);
1311 parent_dir[last_component - true_name + 1] = 0;
1312 last_component++; /*Skip the slash*/
1316 * No slash appears in the given file name. Set parent_dir to the current
1317 * directory, and the last component as the given name.
1319 fs_ExtractDriveLetter(true_name, parent_dir);
1320 strcat(parent_dir, ".");
1321 last_component = true_name;
1322 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
1325 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1326 fprintf(stderr,"fs: you may not use '.' or '..' as the last component\n");
1327 fprintf(stderr,"fs: of a name in the 'fs lsmount' command.\n");
1332 blob.in = last_component;
1333 blob.in_size = strlen(last_component)+1;
1334 blob.out_size = MAXSIZE;
1336 memset(space, 0, MAXSIZE);
1338 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1341 printf("'%s' is a %smount point for volume '%s'\n",
1343 (thru_symlink ? "symbolic link, leading to a " : ""),
1348 if (errno == EINVAL)
1349 fprintf(stderr,"'%s' is not a mount point.\n",
1352 Die(errno, (ti->data ? ti->data : parent_dir));
1359 static MakeMountCmd(as)
1360 register struct cmd_syndesc *as; {
1361 register afs_int32 code;
1362 register char *cellName, *volName, *tmpName;
1364 char localCellName[1000];
1365 #else /* not WIN32 */
1366 struct afsconf_cell info;
1367 struct vldbentry vldbEntry;
1368 #endif /* not WIN32 */
1369 struct ViceIoctl blob;
1375 if (as->parms[5].items && !as->parms[2].items) {
1376 fprintf(stderr,"fs: must provide cell when creating cellular mount point.\n");
1381 if (as->parms[2].items) /* cell name specified */
1382 cellName = as->parms[2].items->data;
1384 cellName = (char *) 0;
1385 volName = as->parms[1].items->data;
1387 if (strlen(volName) >= 64) {
1388 fprintf(stderr,"fs: volume name too long (length must be < 64 characters)\n");
1392 /* Check for a cellname in the volume specification, and complain
1393 * if it doesn't match what was specified with -cell */
1394 if (tmpName = strchr(volName, ':')) {
1397 if (foldcmp(cellName,volName)) {
1398 fprintf(stderr,"fs: cellnames do not match.\n");
1403 volName = ++tmpName;
1406 if (!InAFS(Parent(as->parms[0].items->data))) {
1407 fprintf(stderr,"fs: mount points must be created within the AFS file system\n");
1413 blob.out_size = MAXSIZE;
1415 code = pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME, &blob, 1);
1419 strcpy(localCellName, (cellName? cellName : space));
1420 #else /* not win32 */
1421 code = GetCellName(cellName?cellName:space, &info);
1425 if (!(as->parms[4].items)) {
1426 /* not fast, check which cell the mountpoint is being created in */
1428 /* not fast, check name with VLDB */
1430 code = VLDBInit(1, &info);
1432 /* make the check. Don't complain if there are problems with init */
1433 code = ubik_Call(VL_GetEntryByNameO, uclient, 0, volName, &vldbEntry);
1434 if (code == VL_NOENT) {
1435 fprintf(stderr,"fs: warning, volume %s does not exist in cell %s.\n",
1436 volName, cellName ? cellName : space);
1440 #endif /* not WIN32 */
1442 if (as->parms[3].items) /* if -rw specified */
1447 /* cellular mount point, prepend cell prefix */
1449 strcat(space, localCellName);
1450 #else /* not WIN32 */
1451 strcat(space, info.name);
1452 #endif /* not WIN32 */
1455 strcat(space, volName); /* append volume name */
1456 strcat(space, "."); /* stupid convention; these end with a period */
1458 /* create symlink with a special pioctl for Windows NT, since it doesn't
1459 * have a symlink system call.
1462 blob.in_size = 1 + strlen(space);
1465 code = pioctl(as->parms[0].items->data, VIOC_AFS_CREATE_MT_PT, &blob, 0);
1466 #else /* not WIN32 */
1467 code = symlink(space, as->parms[0].items->data);
1468 #endif /* not WIN32 */
1470 Die(errno, as->parms[0].items->data);
1477 * Delete AFS mount points. Variables are used as follows:
1478 * tbuffer: Set to point to the null-terminated directory name of the mount point
1479 * (or ``.'' if none is provided)
1480 * tp: Set to point to the actual name of the mount point to nuke.
1482 static RemoveMountCmd(as)
1483 register struct cmd_syndesc *as; {
1484 register afs_int32 code=0;
1485 struct ViceIoctl blob;
1486 register struct cmd_item *ti;
1488 char lsbuffer[1024];
1491 for(ti=as->parms[0].items; ti; ti=ti->next) {
1493 tp = (char *) strrchr(ti->data, '\\');
1495 tp = (char *) strrchr(ti->data, '/');
1497 strncpy(tbuffer, ti->data, code=tp-ti->data+1); /* the dir name */
1499 tp++; /* skip the slash */
1502 fs_ExtractDriveLetter(ti->data, tbuffer);
1503 strcat(tbuffer, ".");
1505 fs_StripDriveLetter(tp, tp, 0);
1508 blob.in_size = strlen(tp)+1;
1509 blob.out = lsbuffer;
1510 blob.out_size = sizeof(lsbuffer);
1511 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1513 if (errno == EINVAL)
1514 fprintf(stderr,"fs: '%s' is not a mount point.\n", ti->data);
1516 Die(errno, ti->data);
1518 continue; /* don't bother trying */
1522 blob.in_size = strlen(tp)+1;
1523 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1525 Die(errno, ti->data);
1535 static CheckServersCmd(as)
1536 register struct cmd_syndesc *as; {
1537 register afs_int32 code;
1538 struct ViceIoctl blob;
1539 register afs_int32 j;
1542 struct afsconf_cell info;
1543 struct chservinfo checkserv;
1545 memset(&checkserv, 0, sizeof(struct chservinfo));
1546 blob.in_size=sizeof(struct chservinfo);
1547 blob.in=(caddr_t)&checkserv;
1549 blob.out_size = MAXSIZE;
1551 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1553 /* prepare flags for checkservers command */
1554 temp = 2; /* default to checking local cell only */
1555 if (as->parms[2].items) temp |= 1; /* set fast flag */
1556 if (as->parms[1].items) temp &= ~2; /* turn off local cell check */
1558 checkserv.magic = 0x12345678; /* XXX */
1559 checkserv.tflags=temp;
1561 /* now copy in optional cell name, if specified */
1562 if (as->parms[0].items) {
1563 code = GetCellName(as->parms[0].items->data, &info);
1567 strcpy(checkserv.tbuffer,info.name);
1568 checkserv.tsize=strlen(info.name)+1;
1572 strcpy(checkserv.tbuffer,"\0");
1576 if(as->parms[3].items)
1578 checkserv.tinterval=atol(as->parms[3].items->data);
1581 if(checkserv.tinterval<0) {
1582 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
1583 checkserv.tinterval=0;
1584 } else if(checkserv.tinterval> 600) {
1585 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1586 checkserv.tinterval=600; /* 10 min max interval */
1590 checkserv.tinterval = -1; /* don't change current interval */
1593 code = pioctl(0, VIOCCKSERV, &blob, 1);
1595 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1596 printf("Must be root to change -interval\n");
1602 memcpy(&temp, space, sizeof(afs_int32));
1603 if (checkserv.tinterval >= 0) {
1604 if (checkserv.tinterval > 0)
1605 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1606 checkserv.tinterval, temp);
1608 printf("The current down server probe interval is %d secs\n", temp);
1612 printf("All servers are running.\n");
1615 printf("These servers unavailable due to network or server problems: ");
1616 for(j=0; j < MAXHOSTS; j++) {
1617 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
1618 if (temp == 0) break;
1619 tp = hostutil_GetNameByINet(temp);
1629 register struct cmd_syndesc *as; {
1630 register afs_int32 code=0;
1631 struct ViceIoctl blob;
1632 struct gaginfo gagflags;
1633 struct cmd_item *show;
1635 memset(&gagflags, 0, sizeof(struct gaginfo));
1636 blob.in_size = sizeof(struct gaginfo);
1637 blob.in = (caddr_t ) &gagflags;
1638 blob.out_size = MAXSIZE;
1640 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1642 if (show = as->parms[0].items)
1643 if (!foldcmp (show->data, "user"))
1644 gagflags.showflags |= GAGUSER;
1645 else if (!foldcmp (show->data, "console"))
1646 gagflags.showflags |= GAGCONSOLE;
1647 else if (!foldcmp (show->data, "all"))
1648 gagflags.showflags |= GAGCONSOLE | GAGUSER;
1649 else if (!foldcmp (show->data, "none"))
1653 "unrecognized flag %s: must be in {user,console,all,none}\n",
1661 code = pioctl(0, VIOC_GAG, &blob, 1);
1669 static CheckVolumesCmd(as)
1670 register struct cmd_syndesc *as; {
1671 register afs_int32 code;
1672 struct ViceIoctl blob;
1676 code = pioctl(0, VIOCCKBACK, &blob, 1);
1681 else printf("All volumeID/name mappings checked.\n");
1686 static SetCacheSizeCmd(as)
1687 register struct cmd_syndesc *as; {
1688 register afs_int32 code;
1689 struct ViceIoctl blob;
1692 if (!as->parms[0].items && !as->parms[1].items) {
1693 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
1696 if (as->parms[0].items) {
1697 code = util_GetInt32(as->parms[0].items->data, &temp);
1699 fprintf(stderr,"fs: bad integer specified for cache size.\n");
1705 blob.in = (char *) &temp;
1706 blob.in_size = sizeof(afs_int32);
1708 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
1710 Die(errno, (char *) 0);
1712 printf("New cache size set.\n");
1716 #define MAXGCSIZE 16
1717 static GetCacheParmsCmd(as)
1718 register struct cmd_syndesc *as; {
1719 register afs_int32 code;
1720 struct ViceIoctl blob;
1721 afs_int32 parms[MAXGCSIZE];
1723 blob.in = (char *) 0;
1725 blob.out_size = sizeof(parms);
1726 blob.out = (char *) parms;
1727 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
1729 Die(errno, (char *) 0);
1731 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
1732 parms[1], parms[0]);
1733 if (parms[1] > parms[0])
1734 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
1739 static ListCellsCmd(as)
1740 register struct cmd_syndesc *as; {
1741 register afs_int32 code;
1742 afs_int32 i, j, *lp, magic, size;
1744 afs_int32 clear, maxa = OMAXHOSTS;
1745 struct ViceIoctl blob;
1747 for(i=0;i<1000;i++) {
1749 memcpy(tp, &i, sizeof(afs_int32));
1750 tp = (char *)(space + sizeof(afs_int32));
1751 lp = (afs_int32 *)tp;
1753 size = sizeof(afs_int32) + sizeof(afs_int32);
1754 blob.out_size = MAXSIZE;
1755 blob.in_size = sizeof(afs_int32);
1758 code = pioctl(0, VIOCGETCELL, &blob, 1);
1760 if (errno == EDOM) break; /* done with the list */
1767 memcpy(&magic, tp, sizeof(afs_int32));
1768 if (magic == 0x12345678) {
1770 tp += sizeof(afs_int32);
1772 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
1773 for(j=0; j < maxa; j++) {
1774 memcpy(&clear, tp + j*sizeof(afs_int32), sizeof(afs_int32));
1775 if (clear == 0) break;
1776 tcp = hostutil_GetNameByINet(clear);
1784 static NewCellCmd(as)
1785 register struct cmd_syndesc *as; {
1787 register afs_int32 code, linkedstate=0, size=0, *lp;
1788 struct ViceIoctl blob;
1789 register struct cmd_item *ti;
1790 register char *tp, *cellname=0;
1791 register struct hostent *thp;
1792 afs_int32 fsport = 0, vlport = 0;
1794 memset(space, 0, MAXHOSTS * sizeof(afs_int32));
1796 lp = (afs_int32 *)tp;
1798 tp += sizeof(afs_int32);
1799 for(ti=as->parms[1].items; ti; ti=ti->next) {
1800 thp = hostutil_GetHostByName(ti->data);
1802 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
1806 memcpy(tp, thp->h_addr, sizeof(afs_int32));
1807 tp += sizeof(afs_int32);
1810 if (as->parms[2].items) {
1812 * Link the cell, for the purposes of volume location, to the specified
1815 cellname = as->parms[2].items->data;
1818 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
1819 if (as->parms[3].items) {
1820 code = util_GetInt32(as->parms[3].items->data, &vlport);
1822 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
1826 if (as->parms[4].items) {
1827 code = util_GetInt32(as->parms[4].items->data, &fsport);
1829 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
1834 tp = (char *)(space + (MAXHOSTS+1) *sizeof(afs_int32));
1835 lp = (afs_int32 *)tp;
1839 strcpy(space + ((MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
1840 size = ((MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
1841 tp = (char *)(space + size);
1843 strcpy(tp, cellname);
1844 size += strlen(cellname) + 1;
1846 blob.in_size = size;
1849 code = pioctl(0, VIOCNEWCELL, &blob, 1);
1854 register afs_int32 code;
1855 struct ViceIoctl blob;
1858 blob.in = (char *) 0;
1859 blob.out_size = MAXSIZE;
1862 code = pioctl((char *) 0, VIOCNEWCELL, &blob, 1);
1865 Die(errno, (char *) 0);
1868 printf("Cell servers information refreshed\n");
1873 static WhichCellCmd(as)
1874 register struct cmd_syndesc *as; {
1875 register afs_int32 code;
1876 struct ViceIoctl blob;
1877 register struct cmd_item *ti;
1880 error = 0; /* no error occurred */
1881 SetDotDefault(&as->parms[0].items);
1882 for(ti=as->parms[0].items; ti; ti=ti->next) {
1885 blob.out_size = MAXSIZE;
1888 code = pioctl(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
1890 if (errno == ENOENT)
1891 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
1893 Die(errno, ti->data);
1898 printf("File %s lives in cell '%s'\n", ti->data, space);
1903 static WSCellCmd(as)
1904 register struct cmd_syndesc *as; {
1905 register afs_int32 code;
1906 struct ViceIoctl blob;
1909 blob.in = (char *) 0;
1910 blob.out_size = MAXSIZE;
1913 code = pioctl((char *) 0, VIOC_GET_WS_CELL, &blob, 1);
1916 Die(errno, (char *) 0);
1919 printf("This workstation belongs to cell '%s'\n", space);
1923 static PrimaryCellCmd(as)
1924 register struct cmd_syndesc *as; {
1926 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
1931 static MonitorCmd(as)
1932 register struct cmd_syndesc *as; {
1933 register afs_int32 code;
1934 struct ViceIoctl blob;
1935 register struct cmd_item *ti;
1937 register struct hostent *thp;
1941 ti = as->parms[0].items;
1945 if (!strcmp(ti->data, "off"))
1946 hostAddr = 0xffffffff;
1948 thp = hostutil_GetHostByName(ti->data);
1950 if (!strcmp(ti->data, "localhost")) {
1951 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
1952 hostAddr = htonl(0x7f000001);
1955 fprintf(stderr,"host %s not found in host table.\n", ti->data);
1959 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
1963 hostAddr = 0; /* means don't set host */
1964 setp = 0; /* aren't setting host */
1967 /* now do operation */
1968 blob.in_size = sizeof(afs_int32);
1969 blob.out_size = sizeof(afs_int32);
1970 blob.in = (char *) &hostAddr;
1971 blob.out = (char *) &hostAddr;
1972 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
1978 printf("%s: new monitor host set.\n", pn);
1981 /* now decode old address */
1982 if (hostAddr == 0xffffffff) {
1983 printf("Cache monitoring is currently disabled.\n");
1986 tp = hostutil_GetNameByINet(hostAddr);
1987 printf("Using host %s for monitor services.\n", tp);
1993 static SysNameCmd(as)
1994 register struct cmd_syndesc *as; {
1995 register afs_int32 code;
1996 struct ViceIoctl blob;
1997 register struct cmd_item *ti;
1998 char *input = space;
2001 ti = as->parms[0].items;
2005 blob.out_size = MAXSIZE;
2006 blob.in_size = sizeof(afs_int32);
2007 memcpy(input, &setp, sizeof(afs_int32));
2008 input += sizeof(afs_int32);
2010 strcpy(input, ti->data);
2011 blob.in_size += strlen(ti->data) + 1;
2012 input += strlen(ti->data);
2015 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2021 printf("%s: new sysname set.\n", pn);
2025 memcpy(&setp, input, sizeof(afs_int32));
2026 input += sizeof(afs_int32);
2028 fprintf(stderr,"No sysname name value was found\n");
2030 printf("Current sysname is '%s'\n", input);
2036 char *exported_types[] = {"null", "nfs", ""};
2037 static ExportAfsCmd(as)
2038 register struct cmd_syndesc *as; {
2039 register afs_int32 code;
2040 struct ViceIoctl blob;
2041 register struct cmd_item *ti;
2042 int export=0, type=0, mode = 0, exp = 0, gstat = 0, exportcall, pwsync=0, smounts=0;
2044 ti = as->parms[0].items;
2045 if (strcmp(ti->data, "nfs") == 0) type = 0x71; /* NFS */
2047 fprintf(stderr,"Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
2050 ti = as->parms[1].items;
2052 if (strcmp(ti->data, "on") == 0) export = 3;
2053 else if (strcmp(ti->data, "off") == 0) export = 2;
2055 printf("Illegal argument %s\n", ti->data);
2060 if (ti = as->parms[2].items) { /* -noconvert */
2061 if (strcmp(ti->data, "on") == 0) mode = 2;
2062 else if (strcmp(ti->data, "off") == 0) mode = 3;
2064 printf("Illegal argument %s\n", ti->data);
2068 if (ti = as->parms[3].items) { /* -uidcheck */
2069 if (strcmp(ti->data, "on") == 0) pwsync = 3;
2070 else if (strcmp(ti->data, "off") == 0) pwsync = 2;
2072 printf("Illegal argument %s\n", ti->data);
2076 if (ti = as->parms[4].items) { /* -submounts */
2077 if (strcmp(ti->data, "on") == 0) smounts = 3;
2078 else if (strcmp(ti->data, "off") == 0) smounts = 2;
2080 printf("Illegal argument %s\n", ti->data);
2084 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2087 blob.in = (char *) &exportcall;
2088 blob.in_size = sizeof(afs_int32);
2089 blob.out = (char *) &exportcall;
2090 blob.out_size = sizeof(afs_int32);
2091 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2093 if (errno == ENODEV) {
2094 fprintf(stderr,"Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
2101 if (exportcall & 1) {
2102 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
2103 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
2104 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
2105 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
2107 printf("'%s' translator is disabled\n", exported_types[type]);
2115 static GetCellCmd(as)
2116 register struct cmd_syndesc *as; {
2117 register afs_int32 code;
2118 struct ViceIoctl blob;
2119 struct afsconf_cell info;
2120 register struct cmd_item *ti;
2126 for(ti=as->parms[0].items; ti; ti=ti->next) {
2128 blob.out_size = sizeof(args);
2129 blob.out = (caddr_t) &args;
2130 code = GetCellName(ti->data, &info);
2134 blob.in_size = 1+strlen(info.name);
2135 blob.in = info.name;
2136 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2138 if (errno == ENOENT)
2139 fprintf(stderr,"fs: the cell named '%s' does not exist\n", info.name);
2141 Die(errno, info.name);
2144 printf("Cell %s status: ", info.name);
2146 if (args.stat & 1) printf("primary ");
2148 if (args.stat & 2) printf("no setuid allowed");
2149 else printf("setuid allowed");
2150 if (args.stat & 4) printf(", using old VLDB");
2156 static SetCellCmd(as)
2157 register struct cmd_syndesc *as; {
2158 register afs_int32 code;
2159 struct ViceIoctl blob;
2160 struct afsconf_cell info;
2161 register struct cmd_item *ti;
2168 /* figure stuff to set */
2172 if (! as->parms[1].items) args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
2174 /* set stat for all listed cells */
2175 for(ti=as->parms[0].items; ti; ti=ti->next) {
2177 code = GetCellName(ti->data, &info);
2181 strcpy(args.cname, info.name);
2182 blob.in_size = sizeof(args);
2183 blob.in = (caddr_t) &args;
2185 blob.out = (caddr_t) 0;
2186 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2196 static GetCellName(char *cellNamep, struct afsconf_cell *infop)
2198 strcpy(infop->name, cellNamep);
2202 static VLDBInit(int noAuthFlag, struct afsconf_cell *infop)
2207 #else /* not WIN32 */
2209 static GetCellName(cellName, info)
2211 struct afsconf_cell *info;
2213 struct afsconf_dir *tdir;
2216 tdir = afsconf_Open(AFSCONF_CLIENTNAME);
2218 fprintf(stderr,"Could not process files in configuration directory (%s).\n",AFSCONF_CLIENTNAME);
2222 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2224 fprintf(stderr,"fs: cell %s not in %s/CellServDB\n", cellName, AFSCONF_CLIENTNAME);
2232 static VLDBInit(noAuthFlag, info)
2234 struct afsconf_cell *info;
2236 struct ktc_principal sname;
2237 struct ktc_token ttoken;
2239 struct rx_securityClass *sc;
2240 struct rx_connection *serverconns[VLDB_MAXSERVERS];
2245 fprintf(stderr,"fs: could not initialize rx.\n");
2249 rx_SetRxDeadTime(50);
2250 if (!noAuthFlag) { /* we don't need tickets for null */
2251 strcpy(sname.cell, info->name);
2252 sname.instance[0] = 0;
2253 strcpy(sname.name, "afs");
2254 code = ktc_GetToken(&sname,&ttoken, sizeof(ttoken), (char *)0);
2256 fprintf(stderr,"fs: Could not get afs tokens, running unauthenticated.\n");
2261 if (ttoken.kvno >= 0 && ttoken.kvno <= 255) scIndex = 2; /* kerberos */
2263 fprintf (stderr, "fs: funny kvno (%d) in ticket, proceeding\n",
2269 else scIndex = 0; /* don't authenticate */
2272 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
2278 sc = (struct rx_securityClass *)
2279 rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
2280 ttoken.kvno, ttoken.ticketLen,
2284 if (info->numServers > VLDB_MAXSERVERS) {
2285 fprintf(stderr, "fs: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n",
2286 info->numServers, VLDB_MAXSERVERS);
2289 memset(serverconns, 0, sizeof(serverconns));
2290 for (i = 0;i<info->numServers;i++)
2291 serverconns[i] = rx_NewConnection(info->hostAddr[i].sin_addr.s_addr,
2292 info->hostAddr[i].sin_port, USER_SERVICE_ID,
2296 rxs_Release(sc); /* Decrement the initial refCount */
2297 code = ubik_ClientInit(serverconns, &uclient);
2300 fprintf(stderr,"fs: ubik client init failed.\n");
2305 #endif /* not WIN32 */
2307 static struct ViceIoctl gblob;
2308 static int debug = 0;
2310 * here follow some routines in suport of the setserverprefs and
2311 * getserverprefs commands. They are:
2312 * SetPrefCmd "top-level" routine
2313 * addServer adds a server to the list of servers to be poked into the
2314 * kernel. Will poke the list into the kernel if it threatens
2316 * pokeServers pokes the existing list of servers and ranks into the kernel
2317 * GetPrefCmd reads the Cache Manager's current list of server ranks
2320 static pokeServers()
2325 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2327 ssp = (cm_SSetPref_t *)space;
2328 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
2333 static addServer(name, rank)
2335 unsigned short rank;
2340 struct hostent *thostent;
2344 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
2346 #define MAXUSHORT ((unsigned short) ~0)
2351 thostent = hostutil_GetHostByName(name);
2353 fprintf (stderr, "%s: couldn't resolve name.\n", name);
2357 ssp = (cm_SSetPref_t *)(gblob.in);
2359 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
2360 code = pokeServers();
2361 ssp->num_servers = 0;
2364 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
2365 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
2366 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
2367 gblob.in_size += sizeof(cm_SPref_t);
2370 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
2376 static SetPrefCmd(as)
2377 register struct cmd_syndesc *as; {
2380 struct cmd_item *ti;
2385 ssp = (cm_SSetPref_t *)space;
2387 ssp->num_servers = 0;
2388 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
2391 gblob.out_size = MAXSIZE;
2396 fprintf (stderr,"Permission denied: requires root access.\n");
2403 ti = as->parms[2].items; /* -file */
2405 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
2406 if (!(infd = fopen(ti->data,"r" ))) {
2408 Die(errno,ti->data);
2411 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
2412 code = addServer (name, (unsigned short) rank);
2416 ti = as->parms[3].items; /* -stdin */
2418 while ( scanf("%79s%ld", name, &rank) != EOF) {
2419 code = addServer (name, (unsigned short) rank);
2423 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
2428 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
2430 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
2434 code = pokeServers();
2436 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
2438 ssp = (cm_SSetPref_t *)space;
2439 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
2441 ssp->flags = CM_SPREF_VLONLY;
2442 ssp->num_servers = 0;
2444 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
2449 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
2451 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
2456 if (as->parms[1].items) {
2458 printf("now poking vlservers\n");
2459 code = pokeServers();
2469 static GetPrefCmd(as)
2470 register struct cmd_syndesc *as; {
2472 struct cmd_item *ti;
2473 char *name, tbuffer[20];
2478 struct ViceIoctl blob;
2479 struct cm_SPrefRequest *in;
2480 struct cm_SPrefInfo *out;
2484 ti = as->parms[0].items; /* -file */
2486 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
2487 if (!(outfd = freopen(ti->data,"w",stdout))) {
2488 Die(errno,ti->data);
2493 ti = as->parms[1].items; /* -numeric */
2495 ti = as->parms[2].items; /* -vlservers */
2496 vlservers = (ti ? CM_SPREF_VLONLY : 0);
2497 /* ti = as->parms[3].items; -cell */
2499 in = (struct cm_SPrefRequest *)space;
2503 blob.in_size=sizeof(struct cm_SPrefRequest);
2504 blob.in = (char *)in;
2506 blob.out_size = MAXSIZE;
2508 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
2509 in->flags = vlservers;
2511 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
2513 perror("getserverprefs pioctl");
2517 out = (struct cm_SPrefInfo *) blob.out;
2519 for (i=0;i<out->num_servers;i++) {
2521 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
2524 addr = ntohl(out->servers[i].host.s_addr);
2525 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
2526 (addr>>8) & 0xff, addr & 0xff);
2529 printf ("%-50s %5u\n",name,out->servers[i].rank);
2532 in->offset = out->next_offset;
2534 } while (!code && out->next_offset > 0);
2539 static TraceCmd(struct cmd_syndesc *asp)
2542 struct ViceIoctl blob;
2546 if ((asp->parms[0].items && asp->parms[1].items)) {
2547 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
2551 /* determine if we're turning this tracing on or off */
2553 if (asp->parms[0].items)
2554 inValue = 3; /* enable */
2555 else if (asp->parms[1].items) inValue = 2; /* disable */
2556 if (asp->parms[2].items) inValue |= 4; /* do reset */
2557 if (asp->parms[3].items) inValue |= 8; /* dump */
2559 blob.in_size = sizeof(long);
2560 blob.in = (char *) &inValue;
2561 blob.out_size = sizeof(long);
2562 blob.out = (char *) &outValue;
2564 code = pioctl(NULL, VIOC_TRACECTL, &blob, 1);
2570 if (outValue) printf("AFS tracing enabled.\n");
2571 else printf("AFS tracing disabled.\n");
2576 static void sbusage()
2578 fprintf(stderr, "example usage: fs storebehind -files *.o -kb 99999 -default 0\n");
2579 fprintf(stderr, " fs sb 50000 *.[ao] -default 10\n");
2582 static StoreBehindCmd(as) /* fs sb -kbytes 9999 -files *.o -default 64 */
2583 struct cmd_syndesc *as; {
2585 struct ViceIoctl blob;
2586 struct cmd_item *ti;
2587 struct sbstruct tsb;
2590 if ((as->parms[0].items && as->parms[1].items) ||
2591 (!as->parms[0].items && !as->parms[1].items)) /* same as logical xor */
2598 ti=as->parms[2].items;
2599 if (ti && ti->data) {
2600 kb = atoi (ti->data);
2603 tsb.sb_default = kb;
2605 ti=as->parms[1].items;
2606 if (ti && ti->data) {
2607 kb = atoi (ti->data);
2610 tsb.sb_thisfile = kb;
2612 ti=as->parms[0].items;
2617 blob.in_size = sizeof(tsb);
2618 blob.out_size = sizeof(tsb);
2619 fprintf (stderr, "storbehind %s %d %d\n", (ti?ti->data:0),
2620 tsb.sb_thisfile, tsb.sb_default);
2621 code = pioctl((ti ? ti->data : 0) , VIOC_STOREBEHIND, &blob, 1);
2623 Die(errno, (ti ? ti->data : 0));
2626 if (blob.out_size == sizeof(tsb)) {
2627 fprintf (stderr, "storbehind %s is now %d (default %d)\n", (ti?ti->data:0),
2628 tsb.sb_thisfile, tsb.sb_default);
2630 ti = (ti ? ti->next : ti);
2636 static afs_int32 SetCryptCmd(as)
2637 struct cmd_syndesc *as;
2639 afs_int32 code = 0, flag;
2640 struct ViceIoctl blob;
2643 tp = as->parms[0].items->data;
2644 if (strcmp(tp, "on") == 0)
2646 else if (strcmp(tp, "off") == 0)
2649 fprintf (stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
2653 blob.in = (char *) &flag;
2654 blob.in_size = sizeof(flag);
2656 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
2658 Die(code, (char *) 0);
2662 static afs_int32 GetCryptCmd(as)
2663 struct cmd_syndesc *as;
2665 afs_int32 code = 0, flag;
2666 struct ViceIoctl blob;
2669 blob.in = (char *) 0;
2671 blob.out_size = sizeof(flag);
2674 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
2676 if (code) Die(code, (char *) 0);
2679 memcpy(&flag, tp, sizeof(afs_int32));
2680 printf("Security level is currently ");
2682 printf("crypt (data security).\n");
2692 register afs_int32 code;
2693 register struct cmd_syndesc *ts;
2695 #ifdef AFS_AIX32_ENV
2697 * The following signal action for AIX is necessary so that in case of a
2698 * crash (i.e. core is generated) we can include the user's data section
2699 * in the core dump. Unfortunately, by default, only a partial core is
2700 * generated which, in many cases, isn't too useful.
2702 struct sigaction nsa;
2704 sigemptyset(&nsa.sa_mask);
2705 nsa.sa_handler = SIG_DFL;
2706 nsa.sa_flags = SA_FULLDUMP;
2707 sigaction(SIGSEGV, &nsa, NULL);
2712 WSAStartup(0x0101, &WSAjunk);
2715 /* try to find volume location information */
2720 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0, "set server ranks");
2721 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
2722 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
2723 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
2724 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
2725 cmd_CreateAlias(ts, "sp");
2727 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0, "get server ranks");
2728 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
2729 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
2730 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
2731 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
2732 cmd_CreateAlias(ts, "gp");
2734 ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list");
2735 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
2736 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
2737 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
2738 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
2739 parm_setacl_id = ts->nParms;
2740 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
2741 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
2742 cmd_CreateAlias(ts, "sa");
2744 ts = cmd_CreateSyntax("listacl", ListACLCmd, 0, "list access control list");
2745 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2746 parm_listacl_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");
2749 cmd_CreateAlias(ts, "la");
2751 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0, "clean up access control list");
2752 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2754 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0, "copy access control list");
2755 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
2756 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
2757 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
2758 parm_copyacl_id = ts->nParms;
2759 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
2760 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
2762 cmd_CreateAlias(ts, "ca");
2764 ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache");
2765 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2767 ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status");
2768 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2769 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
2771 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
2773 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
2774 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
2775 cmd_CreateAlias(ts, "sv");
2777 ts = cmd_CreateSyntax("messages", GagCmd, 0, "control Cache Manager messages");
2778 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
2780 ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display volume status");
2781 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2782 cmd_CreateAlias(ts, "lv");
2783 cmd_CreateAlias(ts, "listvol");
2785 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota");
2786 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2787 cmd_CreateAlias(ts, "lq");
2789 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0, "show server disk space usage");
2790 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2791 cmd_CreateAlias(ts, "df");
2793 ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage");
2794 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2796 ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point");
2797 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
2799 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point");
2800 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
2801 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
2802 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
2803 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
2804 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
2810 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
2814 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point");
2815 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
2817 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0, "check local cell's servers");
2818 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
2819 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
2820 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
2821 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
2823 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd,0, "check volumeID/name mappings");
2824 cmd_CreateAlias(ts, "checkbackups");
2827 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0, "set cache size");
2828 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
2829 cmd_CreateAlias(ts, "cachesize");
2831 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
2833 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0, "get cache usage info");
2835 ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0, "list configured cells");
2837 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota");
2838 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
2839 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
2841 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
2843 cmd_CreateAlias(ts, "sq");
2845 ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell");
2847 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
2848 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
2849 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
2852 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2854 * Turn this on only if you wish to be able to talk to a server which is listening
2855 * on alternative ports. This is not intended for general use and may not be
2856 * supported in the cache manager. It is not a way to run two servers at the
2857 * same host, since the cache manager cannot properly distinguish those two hosts.
2859 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
2860 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
2863 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell");
2864 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2866 ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location");
2867 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2869 ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell");
2872 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
2875 ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, "set cache monitor host address");
2876 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
2877 cmd_CreateAlias(ts, "mariner");
2880 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status");
2881 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
2883 ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status");
2884 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
2885 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
2886 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
2888 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0, "flush all data in volume");
2889 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2891 ts = cmd_CreateSyntax("sysname", SysNameCmd, 0, "get/set sysname (i.e. @sys) value");
2892 cmd_AddParm(ts, "-newsys", CMD_SINGLE, CMD_OPTIONAL, "new sysname");
2894 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0, "enable/disable translators to AFS");
2895 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
2896 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
2897 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
2898 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
2899 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
2902 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0,
2903 "store to server after file close");
2904 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
2905 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
2906 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
2907 cmd_CreateAlias(ts, "sb");
2909 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0, "set cache manager encryption flag");
2910 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
2912 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0, "get cache manager encryption flag");
2914 ts = cmd_CreateSyntax("trace", TraceCmd, 0, "enable or disable CM tracing");
2915 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
2916 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
2917 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
2918 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
2919 cmd_CreateAlias(ts, "tr");
2921 ts = cmd_CreateSyntax("memdump", MemDumpCmd, 0, "dump memory allocs in debug builds");
2922 cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
2923 cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
2925 code = cmd_Dispatch(argc, argv);
2928 if (rxInitDone) rx_Finalize();
2929 #endif /* not WIN32 */
2934 void Die(code, filename)
2939 if (code == EINVAL) {
2941 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
2942 else fprintf(stderr,"%s: Invalid argument.\n", pn);
2944 else if (code == ENOENT) {
2945 if (filename) fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
2946 else fprintf(stderr,"%s: no such file returned\n", pn);
2948 else if (code == EROFS) fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
2949 else if (code == EACCES || code == EPERM) {
2950 if (filename) fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
2951 else fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
2953 else if (code == ENODEV) {
2954 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
2956 else if (code == ESRCH) {
2957 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
2959 else if (code == EPIPE) {
2960 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
2962 else if (code == EFBIG) {
2963 fprintf(stderr,"%s: Cache size too large.\n", pn);
2965 else if (code == ETIMEDOUT) {
2967 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
2969 fprintf(stderr,"%s: Connection timed out", pn);
2972 if (filename) fprintf(stderr,"%s:'%s'", pn, filename);
2973 else fprintf(stderr,"%s", pn);
2975 fprintf(stderr, ": code 0x%x\n", code);
2976 #else /* not WIN32 */
2977 fprintf(stderr,": %s\n", error_message(code));
2978 #endif /* not WIN32 */
2982 static MemDumpCmd(struct cmd_syndesc *asp)
2985 struct ViceIoctl blob;
2989 if ((asp->parms[0].items && asp->parms[1].items)) {
2990 fprintf(stderr, "fs trace: must use at most one of '-begin' or '-end'\n");
2994 /* determine if we're turning this tracing on or off */
2996 if (asp->parms[0].items)
2997 inValue = 1; /* begin */
2998 else if (asp->parms[1].items)
2999 inValue = 0; /* end */
3001 blob.in_size = sizeof(long);
3002 blob.in = (char *) &inValue;
3003 blob.out_size = sizeof(long);
3004 blob.out = (char *) &outValue;
3006 code = pioctl(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
3012 if (outValue) printf("AFS memdump begin.\n");
3013 else printf("AFS memdump end.\n");