2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #include <afs/afs_args.h>
18 #include <sys/ioctl.h>
19 #include <sys/socket.h>
23 #include <netinet/in.h>
27 #include <afs/venus.h>
28 #include <afs/com_err.h>
37 #include "afs/prs_fs.h"
38 #include <afs/afsint.h>
39 #include <afs/cellconfig.h>
42 #include <rx/rx_globals.h>
43 #include <afs/vldbint.h>
44 #include <afs/volser.h>
45 #include <afs/vlserver.h>
47 #include <afs/afsutil.h>
48 #include <afs/com_err.h>
51 #include <afs/ptclient.h>
56 #define MAXCELLHOSTS 8
59 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
60 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
62 static char space[MAXSIZE];
63 static char tspace[1024];
64 static struct ubik_client *uclient;
66 static int GetClientAddrsCmd(), SetClientAddrsCmd(), FlushMountCmd();
67 static int RxStatProcCmd(), RxStatPeerCmd(), GetFidCmd(), UuidCmd();
69 extern char *hostutil_GetNameByINet();
70 extern struct hostent *hostutil_GetHostByName();
73 static char pn[] = "fs";
74 static int rxInitDone = 0;
76 static void ZapList();
77 static int PruneList();
79 static int SetVolCmd(struct cmd_syndesc *as, void *arock);
85 * Character to use between name and rights in printed representation for
88 #define DFS_SEPARATOR ' '
90 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
93 int dfs; /* Originally true if a dfs acl; now also the type
94 * of the acl (1, 2, or 3, corresponding to object,
95 * initial dir, or initial object). */
96 sec_rgy_name_t cell; /* DFS cell name */
99 struct AclEntry *pluslist;
100 struct AclEntry *minuslist;
104 struct AclEntry *next;
110 afs_int32 callerAccess;
122 ZapList(acl->pluslist);
123 ZapList(acl->minuslist);
136 if (t >= 'A' && t <= 'Z')
138 if (u >= 'A' && u <= 'Z')
148 * Mods for the AFS/DFS protocol translator.
150 * DFS rights. It's ugly to put these definitions here, but they
151 * *cannot* change, because they're part of the wire protocol.
152 * In any event, the protocol translator will guarantee these
153 * assignments for AFS cache managers.
155 #define DFS_READ 0x01
156 #define DFS_WRITE 0x02
157 #define DFS_EXECUTE 0x04
158 #define DFS_CONTROL 0x08
159 #define DFS_INSERT 0x10
160 #define DFS_DELETE 0x20
162 /* the application definable ones (backwards from AFS) */
163 #define DFS_USR0 0x80000000 /* "A" bit */
164 #define DFS_USR1 0x40000000 /* "B" bit */
165 #define DFS_USR2 0x20000000 /* "C" bit */
166 #define DFS_USR3 0x10000000 /* "D" bit */
167 #define DFS_USR4 0x08000000 /* "E" bit */
168 #define DFS_USR5 0x04000000 /* "F" bit */
169 #define DFS_USR6 0x02000000 /* "G" bit */
170 #define DFS_USR7 0x01000000 /* "H" bit */
171 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
172 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
175 * Offset of -id switch in command structure for various commands.
176 * The -if switch is the next switch always.
178 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
181 * Determine whether either the -id or -if switches are present, and
182 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
184 /* int id; Offset of -id switch; -if is next switch */
186 getidf(struct cmd_syndesc *as, int id)
190 if (as->parms[id].items) {
193 if (as->parms[id + 1].items) {
198 "%s: you may specify either -id or -if, but not both switches\n",
206 PRights(afs_int32 arights, int dfs)
209 if (arights & PRSFS_READ)
211 if (arights & PRSFS_LOOKUP)
213 if (arights & PRSFS_INSERT)
215 if (arights & PRSFS_DELETE)
217 if (arights & PRSFS_WRITE)
219 if (arights & PRSFS_LOCK)
221 if (arights & PRSFS_ADMINISTER)
223 if (arights & PRSFS_USR0)
225 if (arights & PRSFS_USR1)
227 if (arights & PRSFS_USR2)
229 if (arights & PRSFS_USR3)
231 if (arights & PRSFS_USR4)
233 if (arights & PRSFS_USR5)
235 if (arights & PRSFS_USR6)
237 if (arights & PRSFS_USR7)
240 if (arights & DFS_READ)
244 if (arights & DFS_WRITE)
248 if (arights & DFS_EXECUTE)
252 if (arights & DFS_CONTROL)
256 if (arights & DFS_INSERT)
260 if (arights & DFS_DELETE)
264 if (arights & (DFS_USRALL))
266 if (arights & DFS_USR0)
268 if (arights & DFS_USR1)
270 if (arights & DFS_USR2)
272 if (arights & DFS_USR3)
274 if (arights & DFS_USR4)
276 if (arights & DFS_USR5)
278 if (arights & DFS_USR6)
280 if (arights & DFS_USR7)
286 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
290 struct ViceIoctl blob;
294 blob.out_size = MAXSIZE;
297 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
299 if ((errno == EINVAL) || (errno == ENOENT))
305 /* return a static pointer to a buffer */
310 strlcpy(tspace, apath, sizeof(tspace));
311 tp = strrchr(tspace, '/');
312 if (tp == (char *)tspace)
314 else if (tp == (char *)NULL) {
322 enum rtype { add, destroy, deny };
325 Convert(char *arights, int dfs, enum rtype *rtypep)
331 *rtypep = add; /* add rights, by default */
334 if (!strcmp(arights, "null")) {
338 if (!strcmp(arights, "read"))
339 return DFS_READ | DFS_EXECUTE;
340 if (!strcmp(arights, "write"))
341 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
343 if (!strcmp(arights, "all"))
344 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
345 DFS_WRITE | DFS_CONTROL;
347 if (!strcmp(arights, "read"))
348 return PRSFS_READ | PRSFS_LOOKUP;
349 if (!strcmp(arights, "write"))
350 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
351 PRSFS_WRITE | PRSFS_LOCK;
352 if (!strcmp(arights, "mail"))
353 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
354 if (!strcmp(arights, "all"))
355 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
356 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
358 if (!strcmp(arights, "none")) {
359 *rtypep = destroy; /* Remove entire entry */
362 len = strlen(arights);
364 for (i = 0; i < len; i++) {
398 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
406 mode |= PRSFS_LOOKUP;
408 mode |= PRSFS_INSERT;
410 mode |= PRSFS_DELETE;
416 mode |= PRSFS_ADMINISTER;
434 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
443 static struct AclEntry *
444 FindList(struct AclEntry *alist, char *aname)
447 if (!foldcmp(alist->name, aname))
454 /* if no parm specified in a particular slot, set parm to be "." instead */
456 SetDotDefault(struct cmd_item **aitemp)
460 return; /* already has value */
461 /* otherwise, allocate an item representing "." */
462 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
464 ti->next = (struct cmd_item *)0;
465 ti->data = (char *)malloc(2);
467 strcpy(ti->data, ".");
472 ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
474 struct AclEntry *tlist;
475 tlist = (plus ? al->pluslist : al->minuslist);
476 tlist = FindList(tlist, aname);
478 /* Found the item already in the list. */
479 tlist->rights = arights;
481 al->nplus -= PruneList(&al->pluslist, al->dfs);
483 al->nminus -= PruneList(&al->minuslist, al->dfs);
486 /* Otherwise we make a new item and plug in the new data. */
487 tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry));
489 strcpy(tlist->name, aname);
490 tlist->rights = arights;
492 tlist->next = al->pluslist;
493 al->pluslist = tlist;
495 if (arights == 0 || arights == -1)
496 al->nplus -= PruneList(&al->pluslist, al->dfs);
498 tlist->next = al->minuslist;
499 al->minuslist = tlist;
502 al->nminus -= PruneList(&al->minuslist, al->dfs);
507 ZapList(struct AclEntry *alist)
509 struct AclEntry *tp, *np;
510 for (tp = alist; tp; tp = np) {
517 PruneList(struct AclEntry **ae, int dfs)
519 struct AclEntry **lp;
520 struct AclEntry *te, *ne;
524 for (te = *ae; te; te = ne) {
525 if ((!dfs && te->rights == 0) || te->rights == -1) {
541 while (*astr != '\n')
548 * Create an empty acl, taking into account whether the acl pointed
549 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
550 * can recover from problems caused by bogus ACL's (in that case, always
551 * assume that the acl is AFS: for DFS, the user can always resort to
552 * acl_edit, but for AFS there may be no other way out).
560 tp = (struct Acl *)malloc(sizeof(struct Acl));
562 tp->nplus = tp->nminus = 0;
563 tp->pluslist = tp->minuslist = 0;
565 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
572 int nplus, nminus, i, trights;
574 struct AclEntry *first, *last, *tl;
577 ta = (struct Acl *)malloc(sizeof(struct Acl));
580 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
581 astr = SkipLine(astr);
582 sscanf(astr, "%d", &ta->nminus);
583 astr = SkipLine(astr);
590 for (i = 0; i < nplus; i++) {
591 sscanf(astr, "%100s %d", tname, &trights);
592 astr = SkipLine(astr);
593 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
597 strcpy(tl->name, tname);
598 tl->rights = trights;
604 ta->pluslist = first;
608 for (i = 0; i < nminus; i++) {
609 sscanf(astr, "%100s %d", tname, &trights);
610 astr = SkipLine(astr);
611 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
615 strcpy(tl->name, tname);
616 tl->rights = trights;
622 ta->minuslist = first;
628 PrintStatus(VolumeStatus * status, char *name, char *offmsg)
630 printf("Volume status for vid = %u named %s\n", status->Vid, name);
632 printf("Current offline message is %s\n", offmsg);
633 printf("Current disk quota is ");
634 if (status->MaxQuota != 0)
635 printf("%d\n", status->MaxQuota);
637 printf("unlimited\n");
638 printf("Current blocks used are %d\n", status->BlocksInUse);
639 printf("The partition has %d blocks available out of %d\n\n",
640 status->PartBlocksAvail, status->PartMaxBlocks);
645 QuickPrintStatus(VolumeStatus * status, char *name)
647 double QuotaUsed = 0.0;
648 double PartUsed = 0.0;
650 printf("%-25.25s", name);
652 if (status->MaxQuota != 0) {
653 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
655 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
657 printf(" no limit%10d", status->BlocksInUse);
659 if (QuotaUsed > 90.0) {
660 printf("%5.0f%%<<", QuotaUsed);
663 printf("%5.0f%% ", QuotaUsed);
666 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
668 if (PartUsed > 97.0) {
669 printf("%9.0f%%<<", PartUsed);
672 printf("%9.0f%% ", PartUsed);
674 printf(" <<WARNING\n");
681 QuickPrintSpace(VolumeStatus * status, char *name)
683 double PartUsed = 0.0;
685 printf("%-25.25s", name);
687 printf("%10d%10d%10d", status->PartMaxBlocks,
688 status->PartMaxBlocks - status->PartBlocksAvail,
689 status->PartBlocksAvail);
693 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
695 if (PartUsed > 90.0) {
696 printf(" %4.0f%%<<", PartUsed);
699 printf(" %4.0f%% ", PartUsed);
701 printf(" <<WARNING\n");
708 AclToString(struct Acl *acl)
710 static char mydata[MAXSIZE];
711 char tstring[MAXSIZE];
716 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
719 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
720 for (tp = acl->pluslist; tp; tp = tp->next) {
721 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
722 strcat(mydata, tstring);
724 for (tp = acl->minuslist; tp; tp = tp->next) {
725 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
726 strcat(mydata, tstring);
732 SetACLCmd(struct cmd_syndesc *as, void *arock)
735 struct ViceIoctl blob;
737 struct cmd_item *ti, *ui;
741 int idf = getidf(as, parm_setacl_id);
744 if (as->parms[2].items)
748 plusp = !(as->parms[3].items);
749 for (ti = as->parms[0].items; ti; ti = ti->next) {
750 blob.out_size = MAXSIZE;
752 blob.in = blob.out = space;
753 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
755 Die(errno, ti->data);
762 ta = ParseAcl(space);
763 if (!plusp && ta->dfs) {
765 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
767 "(you may specify \"null\" to revoke all rights, however)\n");
775 ta = EmptyAcl(space);
777 ta = ParseAcl(space);
778 CleanAcl(ta, ti->data);
779 for (ui = as->parms[1].items; ui; ui = ui->next->next) {
783 "%s: Missing second half of user/access pair.\n", pn);
787 rights = Convert(ui->next->data, ta->dfs, &rtype);
788 if (rtype == destroy && !ta->dfs) {
789 struct AclEntry *tlist;
791 tlist = (plusp ? ta->pluslist : ta->minuslist);
792 if (!FindList(tlist, ui->data))
795 if (rtype == deny && !ta->dfs)
797 if (rtype == destroy && ta->dfs)
799 ChangeList(ta, plusp, ui->data, rights);
801 blob.in = AclToString(ta);
803 blob.in_size = 1 + strlen(blob.in);
804 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
806 if (errno == EINVAL) {
808 static char *fsenv = 0;
810 fsenv = (char *)getenv("FS_EXPERT");
813 "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n",
817 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
818 "\nPossible reasons for this include:\n\n",
819 " -You may have specified an inappropriate combination of rights.\n",
820 " For example, some DFS-supported filesystems may not allow you to\n",
821 " drop the \"c\" right from \"user_obj\".\n\n",
822 " -A mask_obj may be required (it is likely required by the underlying\n",
823 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
824 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
825 " does not automatically create or update the mask_obj. Try setting\n",
826 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
827 " users or groups. You can do this with a single command, such as\n",
828 " \"fs sa mask_obj all user:somename read\"\n\n",
829 " -A specified user or group may not exist.\n\n",
830 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
831 " This is probably not allowed by the underlying file system.\n\n",
832 " -If you add a user or group to a DFS ACL, remember that it must be\n",
833 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
834 " may be local requirements on the format of the user or group name.\n",
835 " Check with your cell administrator.\n\n",
836 " -Or numerous other possibilities. It would be great if we could be more\n",
837 " precise about the actual problem, but for various reasons, this is\n",
838 " impractical via this interface. If you can't figure it out, you\n",
839 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
840 " whatever is provided). You may get better results. Good luck!\n\n",
841 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
845 "%s: Invalid argument, possible reasons include:\n",
847 fprintf(stderr, "\t-File not in AFS\n");
849 "\t-Too many users on access control list\n");
851 "\t-Tried to add non-existent user to access control list\n");
854 Die(errno, ti->data);
866 CopyACLCmd(struct cmd_syndesc *as, void *arock)
869 struct ViceIoctl blob;
870 struct Acl *fa, *ta = 0;
872 struct cmd_item *ti, *ui;
876 int idf = getidf(as, parm_copyacl_id);
879 if (as->parms[2].items)
883 blob.out_size = MAXSIZE;
885 blob.in = blob.out = space;
886 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
888 Die(errno, as->parms[0].items->data);
891 fa = ParseAcl(space);
892 CleanAcl(fa, as->parms[0].items->data);
893 for (ti = as->parms[1].items; ti; ti = ti->next) {
894 blob.out_size = MAXSIZE;
896 blob.in = blob.out = space;
897 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
899 Die(errno, ti->data);
907 ta = EmptyAcl(space);
909 ta = ParseAcl(space);
910 CleanAcl(ta, ti->data);
911 if (ta->dfs != fa->dfs) {
913 "%s: incompatible file system types: acl not copied to %s; aborted\n",
919 if (!clear && strcmp(ta->cell, fa->cell) != 0) {
921 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
926 strcpy(ta->cell, fa->cell);
928 for (tp = fa->pluslist; tp; tp = tp->next)
929 ChangeList(ta, 1, tp->name, tp->rights);
930 for (tp = fa->minuslist; tp; tp = tp->next)
931 ChangeList(ta, 0, tp->name, tp->rights);
932 blob.in = AclToString(ta);
934 blob.in_size = 1 + strlen(blob.in);
935 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
937 if (errno == EINVAL) {
939 "%s: Invalid argument, possible reasons include:\n",
941 fprintf(stderr, "\t-File not in AFS\n");
943 Die(errno, ti->data);
954 /* pioctl() call to get the cellname of a pathname */
956 GetCell(char *fname, char *cellname)
959 struct ViceIoctl blob;
962 blob.out_size = MAXCELLCHARS;
965 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
966 return code ? errno : 0;
969 /* Check if a username is valid: If it contains only digits (or a
970 * negative sign), then it might be bad. We then query the ptserver
974 BadName(char *aname, char *fname)
976 afs_int32 tc, code, id;
978 char cell[MAXCELLCHARS];
980 for (nm = aname; tc = *nm; nm++) {
981 /* all must be '-' or digit to be bad */
982 if (tc != '-' && (tc < '0' || tc > '9'))
986 /* Go to the PRDB and see if this all number username is valid */
987 code = GetCell(fname, cell);
991 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
992 code = pr_SNameToId(aname, &id);
995 /* 1=>Not-valid; 0=>Valid */
996 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1000 /* clean up an access control list of its bad entries; return 1 if we made
1001 any changes to the list, and 0 otherwise */
1003 CleanAcl(struct Acl *aa, char *fname)
1005 struct AclEntry *te, **le, *ne;
1008 /* Don't correct DFS ACL's for now */
1012 /* prune out bad entries */
1013 changes = 0; /* count deleted entries */
1015 for (te = aa->pluslist; te; te = ne) {
1017 if (BadName(te->name, fname)) {
1027 le = &aa->minuslist;
1028 for (te = aa->minuslist; te; te = ne) {
1030 if (BadName(te->name, fname)) {
1044 /* clean up an acl to not have bogus entries */
1046 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1050 struct ViceIoctl blob;
1052 struct cmd_item *ti;
1053 struct AclEntry *te;
1056 SetDotDefault(&as->parms[0].items);
1057 for (ti = as->parms[0].items; ti; ti = ti->next) {
1058 blob.out_size = MAXSIZE;
1061 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1063 Die(errno, ti->data);
1070 ta = ParseAcl(space);
1073 "%s: cleanacl is not supported for DFS access lists.\n",
1079 changes = CleanAcl(ta, ti->data);
1082 /* now set the acl */
1083 blob.in = AclToString(ta);
1084 blob.in_size = strlen(blob.in) + 1;
1086 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1088 if (errno == EINVAL) {
1090 "%s: Invalid argument, possible reasons include\n",
1092 fprintf(stderr, "%s: File not in vice or\n", pn);
1094 "%s: Too many users on access control list or\n",
1097 Die(errno, ti->data);
1103 /* now list the updated acl */
1104 printf("Access list for %s is now\n", ti->data);
1105 if (ta->nplus > 0) {
1107 printf("Normal rights:\n");
1108 for (te = ta->pluslist; te; te = te->next) {
1109 printf(" %s ", te->name);
1110 PRights(te->rights, ta->dfs);
1114 if (ta->nminus > 0) {
1115 printf("Negative rights:\n");
1116 for (te = ta->minuslist; te; te = te->next) {
1117 printf(" %s ", te->name);
1118 PRights(te->rights, ta->dfs);
1125 printf("Access list for %s is fine.\n", ti->data);
1133 ListACLCmd(struct cmd_syndesc *as, void *arock)
1137 struct ViceIoctl blob;
1138 struct AclEntry *te;
1139 struct cmd_item *ti;
1140 int idf = getidf(as, parm_listacl_id);
1143 SetDotDefault(&as->parms[0].items);
1144 for (ti = as->parms[0].items; ti; ti = ti->next) {
1145 blob.out_size = MAXSIZE;
1147 blob.in = blob.out = space;
1148 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1150 Die(errno, ti->data);
1154 ta = ParseAcl(space);
1157 printf("Access list for %s is\n", ti->data);
1160 printf("DFS access list for %s is\n", ti->data);
1163 printf("DFS initial directory access list of %s is\n", ti->data);
1166 printf("DFS initial file access list of %s is\n", ti->data);
1170 printf(" Default cell = %s\n", ta->cell);
1172 if (ta->nplus > 0) {
1174 printf("Normal rights:\n");
1175 for (te = ta->pluslist; te; te = te->next) {
1176 printf(" %s ", te->name);
1177 PRights(te->rights, ta->dfs);
1181 if (ta->nminus > 0) {
1182 printf("Negative rights:\n");
1183 for (te = ta->minuslist; te; te = te->next) {
1184 printf(" %s ", te->name);
1185 PRights(te->rights, ta->dfs);
1197 GetCallerAccess(struct cmd_syndesc *as, void *arock)
1199 struct cmd_item *ti;
1202 SetDotDefault(&as->parms[0].items);
1203 for (ti = as->parms[0].items; ti; ti = ti->next) {
1205 struct ViceIoctl blob;
1206 struct vcxstat2 stat;
1207 blob.out_size = sizeof(struct vcxstat2);
1209 blob.out = (void *)&stat;
1210 code = pioctl(ti->data, VIOC_GETVCXSTATUS2, &blob, 1);
1212 Die(errno, ti->data);
1216 printf("Callers access to %s is ", ti->data);
1217 PRights(stat.callerAccess, 0);
1224 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1227 struct ViceIoctl blob;
1228 struct cmd_item *ti;
1231 SetDotDefault(&as->parms[0].items);
1232 for (ti = as->parms[0].items; ti; ti = ti->next) {
1233 blob.in_size = blob.out_size = 0;
1234 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1236 fprintf(stderr, "Error flushing volume ");
1246 * The Windows version of UuidCmd displays the UUID.
1247 * When the UNIX version is updated to do the same
1248 * be sure to replace the CMD_REQUIRED flag with
1249 * CMD_OPTIONAL in the cmd_AddParam(-generate) call
1252 UuidCmd(struct cmd_syndesc *as, void *arock)
1255 struct ViceIoctl blob;
1260 if (as->parms[0].items) {
1262 fprintf (stderr, "Permission denied: requires root access.\n");
1266 /* generate new UUID */
1267 code = pioctl(0, VIOC_NEWUUID, &blob, 1);
1274 printf("New uuid generated.\n");
1276 /* This will never execute */
1277 printf("Please add the '-generate' option to generate a new UUID.\n");
1282 #if defined(AFS_CACHE_BYPASS)
1284 * Set cache-bypass threshold. Files larger than this size will not be cached.
1285 * With a threshold of 0, the cache is always bypassed. With a threshold of -1,
1286 * cache bypass is disabled.
1290 BypassThresholdCmd(struct cmd_syndesc *as, char *arock)
1294 struct ViceIoctl blob;
1295 afs_int32 threshold_i, threshold_o;
1298 /* if new threshold supplied, then set and confirm, else,
1299 * get current threshold and print
1302 if(as->parms[0].items) {
1305 tp = as->parms[0].items->data;
1308 for(ix = 0; ix < len; ++ix) {
1309 if(!isdigit(tp[0])) {
1315 fprintf(stderr, "fs bypassthreshold -size: %s must be an undecorated digit string.\n", tp);
1318 threshold_i = atoi(tp);
1319 if(ix > 9 && threshold_i < 2147483647)
1320 threshold_i = 2147483647;
1321 blob.in = (char *) &threshold_i;
1322 blob.in_size = sizeof(threshold_i);
1328 blob.out = (char *) &threshold_o;
1329 blob.out_size = sizeof(threshold_o);
1330 code = pioctl(0, VIOC_SETBYPASS_THRESH, &blob, 1);
1335 printf("Cache bypass threshold %d", threshold_o);
1336 if(threshold_o == -1)
1337 printf(" (disabled)");
1347 FlushCmd(struct cmd_syndesc *as, void *arock)
1350 struct ViceIoctl blob;
1351 struct cmd_item *ti;
1354 for (ti = as->parms[0].items; ti; ti = ti->next) {
1355 blob.in_size = blob.out_size = 0;
1356 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1358 if (errno == EMFILE) {
1359 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1362 fprintf(stderr, "%s: Error flushing file ", pn);
1372 /* all this command does is repackage its args and call SetVolCmd */
1374 SetQuotaCmd(struct cmd_syndesc *as, void *arock)
1376 struct cmd_syndesc ts;
1378 /* copy useful stuff from our command slot; we may later have to reorder */
1379 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1380 return SetVolCmd(&ts, arock);
1384 SetVolCmd(struct cmd_syndesc *as, void *arock)
1387 struct ViceIoctl blob;
1388 struct cmd_item *ti;
1389 struct VolumeStatus *status;
1390 char *offmsg, *input;
1393 SetDotDefault(&as->parms[0].items);
1394 for (ti = as->parms[0].items; ti; ti = ti->next) {
1396 blob.out_size = MAXSIZE;
1397 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1400 status = (VolumeStatus *) space;
1401 status->MinQuota = status->MaxQuota = -1;
1403 if (as->parms[1].items) {
1404 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1406 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1411 if (as->parms[2].items)
1412 offmsg = as->parms[2].items->data;
1413 input = (char *)status + sizeof(*status);
1414 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1416 if (strlen(offmsg) >= VMSGSIZE) {
1418 "%s: message must be shorter than %d characters\n",
1423 strcpy(input, offmsg);
1424 blob.in_size += strlen(offmsg);
1425 input += strlen(offmsg) + 1;
1428 *(input++) = '\0'; /* Pad for old style volume "motd" */
1429 code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1);
1431 Die(errno, ti->data);
1439 * Why is VenusFid declared in the kernel-only section of afs.h,
1440 * if it's the exported interface of the cache manager?
1448 ExamineCmd(struct cmd_syndesc *as, void *arock)
1451 struct ViceIoctl blob;
1452 struct cmd_item *ti;
1453 struct VolumeStatus *status;
1454 char *name, *offmsg;
1457 SetDotDefault(&as->parms[0].items);
1458 for (ti = as->parms[0].items; ti; ti = ti->next) {
1459 struct VenusFid vfid;
1462 blob.out_size = MAXSIZE;
1465 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1467 Die(errno, ti->data);
1471 status = (VolumeStatus *) space;
1472 name = (char *)status + sizeof(*status);
1473 offmsg = name + strlen(name) + 1;
1475 blob.out_size = sizeof(struct VenusFid);
1476 blob.out = (char *) &vfid;
1477 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1478 printf("File %s (%u.%u.%u) contained in volume %u\n",
1479 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1483 PrintStatus(status, name, offmsg);
1489 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1492 struct ViceIoctl blob;
1493 struct cmd_item *ti;
1494 struct VolumeStatus *status;
1498 printf("%-25s%-10s%-10s%-7s%-11s\n", "Volume Name", " Quota",
1499 " Used", " %Used", " Partition");
1500 SetDotDefault(&as->parms[0].items);
1501 for (ti = as->parms[0].items; ti; ti = ti->next) {
1503 blob.out_size = MAXSIZE;
1506 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1508 Die(errno, ti->data);
1512 status = (VolumeStatus *) space;
1513 name = (char *)status + sizeof(*status);
1514 QuickPrintStatus(status, name);
1520 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1523 struct ViceIoctl blob;
1524 struct cmd_item *ti;
1530 SetDotDefault(&as->parms[0].items);
1531 for (ti = as->parms[0].items; ti; ti = ti->next) {
1533 blob.out_size = MAXSIZE;
1536 memset(space, 0, sizeof(space));
1537 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1539 Die(errno, ti->data);
1543 hosts = (afs_int32 *) space;
1544 printf("File %s is on host%s ", ti->data,
1545 (hosts[0] && !hosts[1]) ? "" : "s");
1546 for (j = 0; j < MAXHOSTS; j++) {
1549 tp = hostutil_GetNameByINet(hosts[j]);
1559 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1562 struct ViceIoctl blob;
1563 struct cmd_item *ti;
1565 struct VolumeStatus *status;
1568 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1569 " used", " avail", " %used");
1570 SetDotDefault(&as->parms[0].items);
1571 for (ti = as->parms[0].items; ti; ti = ti->next) {
1573 blob.out_size = MAXSIZE;
1576 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1578 Die(errno, ti->data);
1582 status = (VolumeStatus *) space;
1583 name = (char *)status + sizeof(*status);
1584 QuickPrintSpace(status, name);
1590 QuotaCmd(struct cmd_syndesc *as, void *arock)
1593 struct ViceIoctl blob;
1594 struct cmd_item *ti;
1596 struct VolumeStatus *status;
1599 SetDotDefault(&as->parms[0].items);
1600 for (ti = as->parms[0].items; ti; ti = ti->next) {
1602 blob.out_size = MAXSIZE;
1605 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1607 Die(errno, ti->data);
1611 status = (VolumeStatus *) space;
1612 if (status->MaxQuota)
1614 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
1617 printf("%2.0f%% of quota used.\n", quotaPct);
1623 ListMountCmd(struct cmd_syndesc *as, void *arock)
1626 struct ViceIoctl blob;
1627 struct cmd_item *ti;
1628 char orig_name[1024]; /*Original name, may be modified */
1629 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
1630 char parent_dir[1024]; /*Parent directory of true name */
1631 char *last_component; /*Last component of true name */
1632 struct stat statbuff; /*Buffer for status info */
1633 int link_chars_read; /*Num chars read in readlink() */
1634 int thru_symlink; /*Did we get to a mount point via a symlink? */
1637 for (ti = as->parms[0].items; ti; ti = ti->next) {
1640 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
1643 if (lstat(orig_name, &statbuff) < 0) {
1644 /* if lstat fails, we should still try the pioctl, since it
1645 * may work (for example, lstat will fail, but pioctl will
1646 * work if the volume of offline (returning ENODEV). */
1647 statbuff.st_mode = S_IFDIR; /* lie like pros */
1651 * The lstat succeeded. If the given file is a symlink, substitute
1652 * the file name with the link name.
1654 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1657 * Read name of resolved file.
1659 link_chars_read = readlink(orig_name, true_name, 1024);
1660 if (link_chars_read <= 0) {
1662 "%s: Can't read target name for '%s' symbolic link!\n",
1669 * Add a trailing null to what was read, bump the length.
1671 true_name[link_chars_read++] = 0;
1674 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1675 * have to create a full pathname using the original name and the
1676 * relative symlink name. Find the rightmost slash in the original
1677 * name (we know there is one) and splice in the symlink value.
1679 if (true_name[0] != '/') {
1680 last_component = (char *)strrchr(orig_name, '/');
1681 strcpy(++last_component, true_name);
1682 strcpy(true_name, orig_name);
1685 strcpy(true_name, orig_name);
1688 * Find rightmost slash, if any.
1690 last_component = (char *)strrchr(true_name, '/');
1691 if (last_component == (char *)true_name) {
1692 strcpy(parent_dir, "/");
1695 else if (last_component != (char *)NULL) {
1697 * Found it. Designate everything before it as the parent directory,
1698 * everything after it as the final component.
1700 strncpy(parent_dir, true_name, last_component - true_name);
1701 parent_dir[last_component - true_name] = 0;
1702 last_component++; /*Skip the slash */
1705 * No slash appears in the given file name. Set parent_dir to the current
1706 * directory, and the last component as the given name.
1708 strcpy(parent_dir, ".");
1709 last_component = true_name;
1712 if (strcmp(last_component, ".") == 0
1713 || strcmp(last_component, "..") == 0) {
1715 "%s: you may not use '.' or '..' as the last component\n",
1717 fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n",
1723 blob.in = last_component;
1724 blob.in_size = strlen(last_component) + 1;
1725 blob.out_size = MAXSIZE;
1727 memset(space, 0, MAXSIZE);
1729 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1732 printf("'%s' is a %smount point for volume '%s'\n", ti->data,
1733 (thru_symlink ? "symbolic link, leading to a " : ""),
1736 if (errno == EINVAL) {
1737 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
1739 Die(errno, (ti->data ? ti->data : parent_dir));
1748 MakeMountCmd(struct cmd_syndesc *as, void *arock)
1751 char *cellName, *volName, *tmpName;
1752 struct afsconf_cell info;
1753 struct vldbentry vldbEntry;
1754 struct ViceIoctl blob;
1760 if (as->parms[5].items && !as->parms[2].items) {
1761 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1766 if (as->parms[2].items) /* cell name specified */
1767 cellName = as->parms[2].items->data;
1770 volName = as->parms[1].items->data;
1772 if (strlen(volName) >= 64) {
1774 "%s: volume name too long (length must be < 64 characters)\n",
1779 /* Check for a cellname in the volume specification, and complain
1780 * if it doesn't match what was specified with -cell */
1781 if (tmpName = strchr(volName, ':')) {
1784 if (strcasecmp(cellName, volName)) {
1785 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1790 volName = ++tmpName;
1793 if (!InAFS(Parent(as->parms[0].items->data))) {
1795 "%s: mount points must be created within the AFS file system\n",
1802 blob.out_size = MAXSIZE;
1805 pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME,
1809 code = GetCellName(cellName ? cellName : space, &info);
1813 if (!(as->parms[4].items)) {
1814 /* not fast, check which cell the mountpoint is being created in */
1815 /* not fast, check name with VLDB */
1816 code = VLDBInit(1, &info);
1818 /* make the check. Don't complain if there are problems with init */
1820 ubik_VL_GetEntryByNameO(uclient, 0, volName,
1822 if (code == VL_NOENT) {
1824 "%s: warning, volume %s does not exist in cell %s.\n",
1825 pn, volName, cellName ? cellName : space);
1830 if (as->parms[3].items) /* if -rw specified */
1835 /* cellular mount point, prepend cell prefix */
1836 strcat(space, info.name);
1839 strcat(space, volName); /* append volume name */
1840 strcat(space, "."); /* stupid convention; these end with a period */
1841 code = symlink(space, as->parms[0].items->data);
1843 Die(errno, as->parms[0].items->data);
1850 * Delete AFS mount points. Variables are used as follows:
1851 * tbuffer: Set to point to the null-terminated directory name of the mount point
1852 * (or ``.'' if none is provided)
1853 * tp: Set to point to the actual name of the mount point to nuke.
1856 RemoveMountCmd(struct cmd_syndesc *as, void *arock)
1859 struct ViceIoctl blob;
1860 struct cmd_item *ti;
1862 char lsbuffer[1024];
1866 for (ti = as->parms[0].items; ti; ti = ti->next) {
1868 tp = (char *)strrchr(ti->data, '/');
1870 strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */
1872 tp++; /* skip the slash */
1874 strcpy(tbuffer, ".");
1878 blob.in_size = strlen(tp) + 1;
1879 blob.out = lsbuffer;
1880 blob.out_size = sizeof(lsbuffer);
1881 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1883 if (errno == EINVAL) {
1884 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
1887 Die(errno, ti->data);
1890 continue; /* don't bother trying */
1894 blob.in_size = strlen(tp) + 1;
1895 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1897 Die(errno, ti->data);
1908 CheckServersCmd(struct cmd_syndesc *as, void *arock)
1911 struct ViceIoctl blob;
1917 struct afsconf_cell info;
1918 struct chservinfo checkserv;
1920 memset(&checkserv, 0, sizeof(struct chservinfo));
1921 blob.in_size = sizeof(struct chservinfo);
1922 blob.in = (caddr_t) & checkserv;
1924 blob.out_size = MAXSIZE;
1926 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1928 /* prepare flags for checkservers command */
1929 temp = 2; /* default to checking local cell only */
1930 if (as->parms[2].items)
1931 temp |= 1; /* set fast flag */
1932 if (as->parms[1].items)
1933 temp &= ~2; /* turn off local cell check */
1935 checkserv.magic = 0x12345678; /* XXX */
1936 checkserv.tflags = temp;
1938 /* now copy in optional cell name, if specified */
1939 if (as->parms[0].items) {
1940 code = GetCellName(as->parms[0].items->data, &info);
1944 strcpy(checkserv.tbuffer, info.name);
1945 checkserv.tsize = strlen(info.name) + 1;
1947 strcpy(checkserv.tbuffer, "\0");
1948 checkserv.tsize = 0;
1951 if (as->parms[3].items) {
1952 checkserv.tinterval = atol(as->parms[3].items->data);
1955 if (checkserv.tinterval < 0) {
1957 ("Warning: The negative -interval is ignored; treated as an inquiry\n");
1958 checkserv.tinterval = 0;
1959 } else if (checkserv.tinterval > 600) {
1961 ("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1962 checkserv.tinterval = 600; /* 10 min max interval */
1965 checkserv.tinterval = -1; /* don't change current interval */
1968 code = pioctl(0, VIOCCKSERV, &blob, 1);
1970 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1971 printf("Must be root to change -interval\n");
1977 memcpy(&temp, space, sizeof(afs_int32));
1978 if (checkserv.tinterval >= 0) {
1979 if (checkserv.tinterval > 0)
1981 ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1982 checkserv.tinterval, temp);
1984 printf("The current down server probe interval is %d secs\n",
1989 printf("All servers are running.\n");
1992 ("These servers unavailable due to network or server problems: ");
1994 memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32));
1997 tp = hostutil_GetNameByINet(temp);
2007 MessagesCmd(struct cmd_syndesc *as, void *arock)
2010 struct ViceIoctl blob;
2013 struct gaginfo gagflags;
2014 struct cmd_item *show;
2016 memset(&gagflags, 0, sizeof(struct gaginfo));
2017 blob.in_size = sizeof(struct gaginfo);
2018 blob.in = (caddr_t) & gagflags;
2019 blob.out_size = MAXSIZE;
2021 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2023 if (show = as->parms[0].items) {
2024 if (!strcasecmp(show->data, "user"))
2025 gagflags.showflags |= GAGUSER;
2026 else if (!strcasecmp(show->data, "console"))
2027 gagflags.showflags |= GAGCONSOLE;
2028 else if (!strcasecmp(show->data, "all"))
2029 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2030 else if (!strcasecmp(show->data, "none"))
2034 "unrecognized flag %s: must be in {user,console,all,none}\n",
2043 code = pioctl(0, VIOC_GAG, &blob, 1);
2053 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2056 struct ViceIoctl blob;
2060 code = pioctl(0, VIOCCKBACK, &blob, 1);
2066 printf("All volumeID/name mappings checked.\n");
2071 PreCacheCmd(struct cmd_syndesc *as, char *arock)
2074 struct ViceIoctl blob;
2077 if (!as->parms[0].items && !as->parms[1].items) {
2078 fprintf(stderr, "%s: syntax error in precache cmd.\n", pn);
2081 if (as->parms[0].items) {
2082 code = util_GetInt32(as->parms[0].items->data, &temp);
2084 fprintf(stderr, "%s: bad integer specified for precache size.\n",
2090 blob.in = (char *)&temp;
2091 blob.in_size = sizeof(afs_int32);
2093 code = pioctl(0, VIOCPRECACHE, &blob, 1);
2099 printf("New precache size set.\n");
2104 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2107 struct ViceIoctl blob;
2110 if (!as->parms[0].items && !as->parms[1].items) {
2111 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
2114 if (as->parms[0].items) {
2115 code = util_GetInt32(as->parms[0].items->data, &temp);
2117 fprintf(stderr, "%s: bad integer specified for cache size.\n",
2123 blob.in = (char *)&temp;
2124 blob.in_size = sizeof(afs_int32);
2126 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2128 if (errno == EROFS) {
2130 ("'fs setcache' not allowed on memory cache based cache managers.\n");
2137 printf("New cache size set.\n");
2141 #define MAXGCSIZE 16
2143 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2145 afs_int32 code, filesUsed;
2146 struct ViceIoctl blob;
2147 afs_int32 parms[MAXGCSIZE];
2148 double percentFiles, percentBlocks;
2149 afs_int32 flags = 0;
2151 if (as->parms[0].items){ /* -files */
2153 } else if (as->parms[1].items){ /* -excessive */
2159 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
2161 blob.in = (char *)&flags;
2162 blob.in_size = sizeof(afs_int32);
2163 } else { /* be backward compatible */
2167 blob.out_size = sizeof(parms);
2168 blob.out = (char *)parms;
2169 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2176 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2177 parms[1], parms[0]);
2178 if (parms[1] > parms[0])
2179 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2183 percentBlocks = ((double)parms[1]/parms[0]) * 100;
2184 printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n",
2185 percentBlocks, parms[1], parms[0]);
2190 filesUsed = parms[2] - parms[3];
2191 percentFiles = ((double)filesUsed/parms[2]) * 100;
2192 printf(" %5.0f%% of the cache files (%d of %d files)\n",
2193 percentFiles, filesUsed, parms[2]);
2195 printf(" afs_cacheFiles: %10d\n", parms[2]);
2196 printf(" IFFree: %10d\n", parms[3]);
2197 printf(" IFEverUsed: %10d\n", parms[4]);
2198 printf(" IFDataMod: %10d\n", parms[5]);
2199 printf(" IFDirtyPages: %10d\n", parms[6]);
2200 printf(" IFAnyPages: %10d\n", parms[7]);
2201 printf(" IFDiscarded: %10d\n", parms[8]);
2202 printf(" DCentries: %10d\n", parms[9]);
2203 printf(" 0k- 4K: %10d\n", parms[10]);
2204 printf(" 4k- 16k: %10d\n", parms[11]);
2205 printf(" 16k- 64k: %10d\n", parms[12]);
2206 printf(" 64k- 256k: %10d\n", parms[13]);
2207 printf(" 256k- 1M: %10d\n", parms[14]);
2208 printf(" >=1M: %10d\n", parms[15]);
2211 if (percentBlocks > 90)
2212 printf("[cache size usage over 90%, consider increasing cache size]\n");
2213 if (percentFiles > 90)
2214 printf("[cache file usage over 90%, consider increasing '-files' argument to afsd]\n");
2220 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2226 struct ViceIoctl blob;
2229 resolve = !(as->parms[0].items); /* -numeric */
2233 memcpy(tp, &i, sizeof(afs_int32));
2234 blob.out_size = MAXSIZE;
2235 blob.in_size = sizeof(afs_int32);
2238 code = pioctl(0, VIOCGETCELL, &blob, 1);
2241 break; /* done with the list */
2246 printf("Cell %s on hosts", tp + MAXCELLHOSTS * sizeof(afs_int32));
2247 for (j = 0; j < MAXCELLHOSTS; j++) {
2249 char *name, tbuffer[20];
2251 memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32));
2256 name = hostutil_GetNameByINet(addr);
2259 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2260 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2263 printf(" %s", name);
2271 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2274 char *tp, *aliasName, *realName;
2275 struct ViceIoctl blob;
2279 memcpy(tp, &i, sizeof(afs_int32));
2280 blob.out_size = MAXSIZE;
2281 blob.in_size = sizeof(afs_int32);
2284 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2287 break; /* done with the list */
2293 tp += strlen(aliasName) + 1;
2295 printf("Alias %s for cell %s\n", aliasName, realName);
2301 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2304 struct ViceIoctl blob;
2305 struct cmd_item *ti;
2307 struct hostent *thp;
2311 ti = as->parms[0].items;
2314 thp = hostutil_GetHostByName(ti->data);
2316 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2319 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2321 hostAddr = 0; /* means don't set host */
2322 setp = 0; /* aren't setting host */
2325 /* now do operation */
2326 blob.in_size = sizeof(afs_int32);
2327 blob.out_size = sizeof(afs_int32);
2328 blob.in = (char *) &hostAddr;
2329 blob.out = (char *) &hostAddr;
2331 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2340 NukeNFSCredsCmd(struct cmd_syndesc *as, void *arock)
2343 struct ViceIoctl blob;
2344 struct cmd_item *ti;
2346 struct hostent *thp;
2348 ti = as->parms[0].items;
2349 thp = hostutil_GetHostByName(ti->data);
2351 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2354 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2356 /* now do operation */
2357 blob.in_size = sizeof(afs_int32);
2358 blob.out_size = sizeof(afs_int32);
2359 blob.in = (char *) &hostAddr;
2360 blob.out = (char *) &hostAddr;
2362 code = pioctl(0, VIOC_NFS_NUKE_CREDS, &blob, 1);
2371 NewCellCmd(struct cmd_syndesc *as, void *arock)
2373 afs_int32 code, linkedstate = 0, size = 0, *lp;
2374 struct ViceIoctl blob;
2375 struct cmd_item *ti;
2376 char *tp, *cellname = 0;
2377 struct hostent *thp;
2378 afs_int32 fsport = 0, vlport = 0;
2379 afs_int32 magic, scount; /* Number of servers to pass in pioctl call */
2382 * With the NEWCELL pioctl call, 3.4 clients take an array of
2383 * MAXHOSTS (13) servers while 3.5 clients take an array of
2384 * MAXCELLHOSTS (8) servers. To determine which we are talking to,
2385 * do a GETCELL pioctl and pass it a magic number. If an array of
2386 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
2387 * If we get back EDOM, there are no cells in the kernel yet,
2388 * and we'll assume a 3.5 client.
2391 lp = (afs_int32 *) tp;
2392 *lp++ = 0; /* first cell entry */
2393 *lp = 0x12345678; /* magic */
2394 blob.out_size = MAXSIZE;
2395 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
2398 code = pioctl(0, VIOCGETCELL, &blob, 1);
2399 if (code < 0 && errno != EDOM) {
2403 if (code < 1 && errno == EDOM) {
2407 cellname = tp + MAXCELLHOSTS * sizeof(afs_int32);
2408 scount = ((cellname[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2411 /* Now setup and do the NEWCELL pioctl call */
2412 memset(space, 0, (scount + 1) * sizeof(afs_int32));
2414 lp = (afs_int32 *) tp;
2416 tp += sizeof(afs_int32);
2417 for (ti = as->parms[1].items; ti; ti = ti->next) {
2418 thp = hostutil_GetHostByName(ti->data);
2421 "%s: Host %s not found in host table, skipping it.\n", pn,
2424 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2425 tp += sizeof(afs_int32);
2428 if (as->parms[2].items) {
2430 * Link the cell, for the purposes of volume location, to the specified
2433 cellname = as->parms[2].items->data;
2436 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2437 if (as->parms[3].items) {
2438 code = util_GetInt32(as->parms[3].items->data, &vlport);
2441 "%s: bad integer specified for the fileserver port.\n",
2446 if (as->parms[4].items) {
2447 code = util_GetInt32(as->parms[4].items->data, &fsport);
2450 "%s: bad integer specified for the vldb server port.\n",
2456 tp = (char *)(space + (scount + 1) * sizeof(afs_int32));
2457 lp = (afs_int32 *) tp;
2461 strcpy(space + ((scount + 4) * sizeof(afs_int32)),
2462 as->parms[0].items->data);
2463 size = ((scount + 4) * sizeof(afs_int32))
2464 + strlen(as->parms[0].items->data)
2465 + 1 /* for null */ ;
2466 tp = (char *)(space + size);
2468 strcpy(tp, cellname);
2469 size += strlen(cellname) + 1;
2471 blob.in_size = size;
2474 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2483 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2486 struct ViceIoctl blob;
2488 char *aliasName, *realName;
2490 /* Now setup and do the NEWCELL pioctl call */
2491 aliasName = as->parms[0].items->data;
2492 realName = as->parms[1].items->data;
2494 strcpy(tp, aliasName);
2495 tp += strlen(aliasName) + 1;
2496 strcpy(tp, realName);
2497 tp += strlen(realName) + 1;
2499 blob.in_size = tp - space;
2503 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2505 if (errno == EEXIST) {
2507 "%s: cell name `%s' in use by an existing cell.\n", pn,
2518 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2521 struct cmd_item *ti;
2523 char cell[MAXCELLCHARS];
2525 SetDotDefault(&as->parms[0].items);
2526 for (ti = as->parms[0].items; ti; ti = ti->next) {
2527 code = GetCell(ti->data, cell);
2529 if (errno == ENOENT)
2530 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
2532 Die(errno, ti->data);
2537 printf("File %s lives in cell '%s'\n", ti->data, cell);
2543 WSCellCmd(struct cmd_syndesc *as, void *arock)
2546 struct ViceIoctl blob;
2550 blob.out_size = MAXSIZE;
2553 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2559 printf("This workstation belongs to cell '%s'\n", space);
2564 static PrimaryCellCmd(as)
2565 struct cmd_syndesc *as;
2567 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2573 MonitorCmd(struct cmd_syndesc *as, void *arock)
2576 struct ViceIoctl blob;
2577 struct cmd_item *ti;
2579 struct hostent *thp;
2583 ti = as->parms[0].items;
2587 if (!strcmp(ti->data, "off"))
2588 hostAddr = 0xffffffff;
2590 thp = hostutil_GetHostByName(ti->data);
2592 if (!strcmp(ti->data, "localhost")) {
2594 "localhost not in host table, assuming 127.0.0.1\n");
2595 hostAddr = htonl(0x7f000001);
2597 fprintf(stderr, "host %s not found in host table.\n",
2602 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2605 hostAddr = 0; /* means don't set host */
2606 setp = 0; /* aren't setting host */
2609 /* now do operation */
2610 blob.in_size = sizeof(afs_int32);
2611 blob.out_size = sizeof(afs_int32);
2612 blob.in = (char *)&hostAddr;
2613 blob.out = (char *)&hostAddr;
2614 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2620 printf("%s: new monitor host set.\n", pn);
2622 /* now decode old address */
2623 if (hostAddr == 0xffffffff) {
2624 printf("Cache monitoring is currently disabled.\n");
2626 tp = hostutil_GetNameByINet(hostAddr);
2627 printf("Using host %s for monitor services.\n", tp);
2634 SysNameCmd(struct cmd_syndesc *as, void *arock)
2637 struct ViceIoctl blob;
2638 struct cmd_item *ti;
2639 char *input = space;
2642 ti = as->parms[0].items;
2645 blob.out_size = MAXSIZE;
2646 blob.in_size = sizeof(afs_int32);
2647 input += sizeof(afs_int32);
2648 for (; ti; ti = ti->next) {
2650 blob.in_size += strlen(ti->data) + 1;
2651 if (blob.in_size > MAXSIZE) {
2652 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2653 setp > 1 ? "s" : "");
2656 strcpy(input, ti->data);
2657 input += strlen(ti->data);
2660 memcpy(space, &setp, sizeof(afs_int32));
2661 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2667 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2671 memcpy(&setp, input, sizeof(afs_int32));
2672 input += sizeof(afs_int32);
2674 fprintf(stderr, "No sysname name value was found\n");
2677 printf("Current sysname%s is", setp > 1 ? " list" : "");
2678 for (; setp > 0; --setp) {
2679 printf(" \'%s\'", input);
2680 input += strlen(input) + 1;
2686 static char *exported_types[] = { "null", "nfs", "" };
2688 ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2691 struct ViceIoctl blob;
2692 struct cmd_item *ti;
2693 int export = 0, type = 0, mode = 0, exp = 0, exportcall, pwsync =
2694 0, smounts = 0, clipags = 0, pagcb = 0;
2696 ti = as->parms[0].items;
2697 if (strcmp(ti->data, "nfs") == 0)
2698 type = 0x71; /* NFS */
2701 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n",
2705 ti = as->parms[1].items;
2707 if (strcmp(ti->data, "on") == 0)
2709 else if (strcmp(ti->data, "off") == 0)
2712 fprintf(stderr, "Illegal argument %s\n", ti->data);
2717 if (ti = as->parms[2].items) { /* -noconvert */
2718 if (strcmp(ti->data, "on") == 0)
2720 else if (strcmp(ti->data, "off") == 0)
2723 fprintf(stderr, "Illegal argument %s\n", ti->data);
2727 if (ti = as->parms[3].items) { /* -uidcheck */
2728 if (strcmp(ti->data, "on") == 0)
2730 else if (strcmp(ti->data, "off") == 0)
2733 fprintf(stderr, "Illegal argument %s\n", ti->data);
2737 if (ti = as->parms[4].items) { /* -submounts */
2738 if (strcmp(ti->data, "on") == 0)
2740 else if (strcmp(ti->data, "off") == 0)
2743 fprintf(stderr, "Illegal argument %s\n", ti->data);
2747 if (ti = as->parms[5].items) { /* -clipags */
2748 if (strcmp(ti->data, "on") == 0)
2750 else if (strcmp(ti->data, "off") == 0)
2753 fprintf(stderr, "Illegal argument %s\n", ti->data);
2757 if (ti = as->parms[6].items) { /* -pagcb */
2758 if (strcmp(ti->data, "on") == 0)
2760 else if (strcmp(ti->data, "off") == 0)
2763 fprintf(stderr, "Illegal argument %s\n", ti->data);
2768 (type << 24) | (pagcb << 10) | (clipags << 8) |
2769 (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2772 blob.in = (char *)&exportcall;
2773 blob.in_size = sizeof(afs_int32);
2774 blob.out = (char *)&exportcall;
2775 blob.out_size = sizeof(afs_int32);
2776 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2778 if (errno == ENODEV) {
2780 "Sorry, the %s-exporter type is currently not supported on this AFS client\n",
2781 exported_types[type]);
2788 if (exportcall & 1) {
2789 printf("'%s' translator is enabled with the following options:\n",
2790 exported_types[type]);
2791 printf("\tRunning in %s mode\n",
2792 (exportcall & 2 ? "strict unix" :
2793 "convert owner mode bits to world/other"));
2794 printf("\tRunning in %s mode\n",
2795 (exportcall & 4 ? "strict 'passwd sync'" :
2796 "no 'passwd sync'"));
2798 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
2799 "Only mounts to /afs allowed"));
2801 (exportcall & 16 ? "Client-assigned PAG's are used" :
2802 "Client-assigned PAG's are not used"));
2805 "Callbacks are made to get creds from new clients" :
2806 "Callbacks are not made to get creds from new clients"));
2808 printf("'%s' translator is disabled\n", exported_types[type]);
2815 GetCellCmd(struct cmd_syndesc *as, void *arock)
2818 struct ViceIoctl blob;
2819 struct afsconf_cell info;
2820 struct cmd_item *ti;
2827 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2828 for (ti = as->parms[0].items; ti; ti = ti->next) {
2830 blob.out_size = sizeof(args);
2831 blob.out = (caddr_t) & args;
2832 code = GetCellName(ti->data, &info);
2837 blob.in_size = 1 + strlen(info.name);
2838 blob.in = info.name;
2839 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2841 if (errno == ENOENT)
2842 fprintf(stderr, "%s: the cell named '%s' does not exist\n",
2845 Die(errno, info.name);
2849 printf("Cell %s status: ", info.name);
2855 printf("no setuid allowed");
2857 printf("setuid allowed");
2859 printf(", using old VLDB");
2866 SetCellCmd(struct cmd_syndesc *as, void *arock)
2869 struct ViceIoctl blob;
2870 struct afsconf_cell info;
2871 struct cmd_item *ti;
2879 /* Check arguments. */
2880 if (as->parms[1].items && as->parms[2].items) {
2881 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2885 /* figure stuff to set */
2889 if (!as->parms[1].items)
2890 args.stat |= 2; /* default to -nosuid */
2892 /* set stat for all listed cells */
2893 for (ti = as->parms[0].items; ti; ti = ti->next) {
2895 code = GetCellName(ti->data, &info);
2900 strcpy(args.cname, info.name);
2901 blob.in_size = sizeof(args);
2902 blob.in = (caddr_t) & args;
2904 blob.out = (caddr_t) 0;
2905 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2907 Die(errno, info.name); /* XXX added cell name to Die() call */
2915 GetCellName(char *cellName, struct afsconf_cell *info)
2917 struct afsconf_dir *tdir;
2920 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2923 "Could not process files in configuration directory (%s).\n",
2924 AFSDIR_CLIENT_ETC_DIRPATH);
2928 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2930 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2931 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
2940 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
2944 code = ugen_ClientInit(noAuthFlag, AFSDIR_CLIENT_ETC_DIRPATH,
2945 info->name, 0, &uclient,
2946 NULL, pn, rxkad_clear,
2947 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
2948 0, 0, USER_SERVICE_ID);
2953 static struct ViceIoctl gblob;
2954 static int debug = 0;
2956 * here follow some routines in suport of the setserverprefs and
2957 * getserverprefs commands. They are:
2958 * SetPrefCmd "top-level" routine
2959 * addServer adds a server to the list of servers to be poked into the
2960 * kernel. Will poke the list into the kernel if it threatens
2962 * pokeServers pokes the existing list of servers and ranks into the kernel
2963 * GetPrefCmd reads the Cache Manager's current list of server ranks
2967 * returns -1 if error message printed,
2969 * errno value if error and no error message printed
2976 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2977 if (code && (errno == EINVAL)) {
2978 struct setspref *ssp;
2979 ssp = (struct setspref *)gblob.in;
2980 if (!(ssp->flags & DBservers)) {
2981 gblob.in = (void *)&(ssp->servers[0]);
2982 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
2983 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
2984 return code ? errno : 0;
2987 "This cache manager does not support VL server preferences.\n");
2991 return code ? errno : 0;
2995 * returns -1 if error message printed,
2997 * errno value if error and no error message printed
3000 addServer(char *name, afs_int32 rank)
3003 struct setspref *ssp;
3005 struct hostent *thostent;
3011 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3013 #define MAXUSHORT ((unsigned short) ~0)
3017 thostent = hostutil_GetHostByName(name);
3019 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3023 ssp = (struct setspref *)(gblob.in);
3025 for (t = 0; thostent->h_addr_list[t]; t++) {
3026 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3027 code = pokeServers();
3030 ssp->num_servers = 0;
3033 sp = (struct spref *)(gblob.in + gblob.in_size);
3034 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3035 sizeof(afs_uint32));
3036 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3037 gblob.in_size += sizeof(struct spref);
3041 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3042 name, sp->rank, sp->server.s_addr);
3050 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3054 struct cmd_item *ti;
3057 struct setspref *ssp;
3058 int error = 0; /* -1 means error message printed,
3059 * >0 means errno value for unprinted message */
3061 ssp = (struct setspref *)space;
3063 ssp->num_servers = 0;
3064 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3067 gblob.out_size = MAXSIZE;
3071 fprintf(stderr, "Permission denied: requires root access.\n");
3075 ti = as->parms[2].items; /* -file */
3078 fprintf(stderr, "opening file %s\n", ti->data);
3079 if (!(infd = fopen(ti->data, "r"))) {
3083 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3084 code = addServer(name, (unsigned short)rank);
3091 ti = as->parms[3].items; /* -stdin */
3093 while (scanf("%79s%ld", name, &rank) != EOF) {
3094 code = addServer(name, (unsigned short)rank);
3100 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3105 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3109 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3113 code = pokeServers();
3117 printf("now working on vlservers, code=%d\n", code);
3119 ssp = (struct setspref *)space;
3120 ssp->flags = DBservers;
3121 ssp->num_servers = 0;
3122 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3125 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3130 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3134 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3139 if (as->parms[1].items) {
3141 printf("now poking vlservers\n");
3142 code = pokeServers();
3150 return error ? 1 : 0;
3156 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3159 struct cmd_item *ti;
3160 char *name, tbuffer[20];
3161 afs_int32 rank, addr;
3165 struct ViceIoctl blob;
3166 struct sprefrequest *in;
3167 struct sprefinfo *out;
3170 ti = as->parms[0].items; /* -file */
3173 fprintf(stderr, "opening file %s\n", ti->data);
3174 if (!(outfd = freopen(ti->data, "w", stdout))) {
3180 ti = as->parms[1].items; /* -numeric */
3182 ti = as->parms[2].items; /* -vlservers */
3183 vlservers |= (ti ? DBservers : 0);
3184 /* ti = as->parms[3].items; -cell */
3186 in = (struct sprefrequest *)space;
3190 blob.in_size = sizeof(struct sprefrequest);
3191 blob.in = (char *)in;
3193 blob.out_size = MAXSIZE;
3196 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3197 in->flags = vlservers;
3199 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3201 perror("getserverprefs pioctl");
3205 out = (struct sprefinfo *)blob.out;
3207 for (i = 0; i < out->num_servers; i++) {
3209 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3211 addr = ntohl(out->servers[i].server.s_addr);
3212 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3213 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3216 printf("%-50s %5u\n", name, out->servers[i].rank);
3219 in->offset = out->next_offset;
3220 } while (out->next_offset > 0);
3226 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
3229 struct ViceIoctl blob;
3230 struct cmd_item *ti;
3231 struct sbstruct tsb, tsb2;
3237 tsb.sb_thisfile = -1;
3238 ti = as->parms[0].items; /* -kbytes */
3240 if (!as->parms[1].items) {
3241 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3245 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3246 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3247 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3253 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3254 ti = as->parms[2].items; /* -allfiles */
3256 allfiles = strtol(ti->data, &t, 10) * 1024;
3257 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3258 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3264 /* -verbose or -file only or no options */
3265 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3266 || (!as->parms[0].items && !as->parms[1].items
3267 && !as->parms[2].items))
3270 blob.in = (char *)&tsb;
3271 blob.out = (char *)&tsb2;
3272 blob.in_size = blob.out_size = sizeof(struct sbstruct);
3273 memset(&tsb2, 0, sizeof(tsb2));
3275 /* once per -file */
3276 for (ti = as->parms[1].items; ti; ti = ti->next) {
3277 /* Do this solely to see if the file is there */
3278 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3280 Die(errno, ti->data);
3285 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
3287 Die(errno, ti->data);
3292 if (verbose && (blob.out_size == sizeof(tsb2))) {
3293 if (tsb2.sb_thisfile == -1) {
3294 fprintf(stdout, "Will store %s according to default.\n",
3298 "Will store up to %d kbytes of %s asynchronously.\n",
3299 (tsb2.sb_thisfile / 1024), ti->data);
3304 /* If no files - make at least one pioctl call, or
3305 * set the allfiles default if we need to.
3307 if (!as->parms[1].items || (allfiles != -1)) {
3308 tsb.sb_default = allfiles;
3309 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
3311 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3316 /* Having no arguments also reports the default store asynchrony */
3317 if (verbose && (blob.out_size == sizeof(tsb2))) {
3318 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3319 (tsb2.sb_default / 1024));
3327 SetCryptCmd(struct cmd_syndesc *as, void *arock)
3329 afs_int32 code = 0, flag;
3330 struct ViceIoctl blob;
3333 tp = as->parms[0].items->data;
3334 if (strcmp(tp, "on") == 0)
3336 else if (strcmp(tp, "off") == 0)
3339 fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3343 blob.in = (char *)&flag;
3344 blob.in_size = sizeof(flag);
3346 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3354 GetCryptCmd(struct cmd_syndesc *as, void *arock)
3356 afs_int32 code = 0, flag;
3357 struct ViceIoctl blob;
3362 blob.out_size = sizeof(flag);
3365 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3371 memcpy(&flag, tp, sizeof(afs_int32));
3372 printf("Security level is currently ");
3374 printf("crypt (data security).\n");
3381 #ifdef AFS_DISCON_ENV
3382 static char *modenames[] = {
3385 "readonly", /* Not currently supported */
3386 "fetchonly", /* Not currently supported */
3387 "partial", /* Not currently supported */
3391 static char *policynames[] = {
3394 "closer", /* Not currently supported. */
3395 "manual", /* Not currently supported. */
3400 DisconCmd(struct cmd_syndesc *as, void *arock)
3402 struct cmd_item *ti;
3405 int modelen, policylen;
3406 afs_int32 mode, policy, code;
3407 struct ViceIoctl blob;
3412 space[0] = space[1] = space[2] = 0;
3414 ti = as->parms[0].items;
3416 modename = ti->data;
3417 modelen = strlen(modename);
3418 for (mode = 0; modenames[mode] != NULL; mode++)
3419 if (!strncasecmp(modename, modenames[mode], modelen))
3421 if (modenames[mode] == NULL)
3422 printf("Unknown discon mode \"%s\"\n", modename);
3424 space[0] = mode + 1;
3427 ti = as->parms[1].items;
3429 policyname = ti->data;
3430 policylen = strlen(policyname);
3431 for (policy = 0; policynames[policy] != NULL; policy++)
3432 if (!strncasecmp(policyname, policynames[policy], policylen))
3434 if (policynames[policy] == NULL)
3435 printf("Unknown discon mode \"%s\"\n", policyname);
3437 space[1] = policy + 1;
3441 if (as->parms[2].items) {
3443 printf("force on\n");
3447 blob.in_size = 3 * sizeof(afs_int32);
3449 blob.out_size = sizeof(mode);
3451 code = pioctl(0, VIOC_DISCON, &blob, 1);
3455 memcpy(&mode, space, sizeof mode);
3456 if (mode < sizeof modenames / sizeof (char *))
3457 printf("Discon mode is now \"%s\"\n", modenames[mode]);
3459 printf("Unknown discon mode %d\n", mode);
3466 #include "AFS_component_version_number.c"
3469 main(int argc, char **argv)
3472 struct cmd_syndesc *ts;
3474 #ifdef AFS_AIX32_ENV
3476 * The following signal action for AIX is necessary so that in case of a
3477 * crash (i.e. core is generated) we can include the user's data section
3478 * in the core dump. Unfortunately, by default, only a partial core is
3479 * generated which, in many cases, isn't too useful.
3481 struct sigaction nsa;
3483 sigemptyset(&nsa.sa_mask);
3484 nsa.sa_handler = SIG_DFL;
3485 nsa.sa_flags = SA_FULLDUMP;
3486 sigaction(SIGSEGV, &nsa, NULL);
3489 /* try to find volume location information */
3490 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
3491 "get client network interface addresses");
3492 cmd_CreateAlias(ts, "gc");
3494 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
3495 "set client network interface addresses");
3496 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3497 "client network interfaces");
3498 cmd_CreateAlias(ts, "sc");
3500 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL,
3501 "set server ranks");
3502 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3503 "fileserver names and ranks");
3504 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3505 "VL server names and ranks");
3506 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3507 "input from named file");
3508 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3509 cmd_CreateAlias(ts, "sp");
3511 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL,
3512 "get server ranks");
3513 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3514 "output to named file");
3515 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3516 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3517 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3518 cmd_CreateAlias(ts, "gp");
3520 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
3521 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3522 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3523 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3524 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL,
3525 "apply to negative rights");
3526 parm_setacl_id = ts->nParms;
3527 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL,
3528 "initial directory acl (DFS only)");
3529 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL,
3530 "initial file acl (DFS only)");
3531 cmd_CreateAlias(ts, "sa");
3533 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL,
3534 "list access control list");
3535 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3536 parm_listacl_id = ts->nParms;
3537 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3538 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3539 cmd_CreateAlias(ts, "la");
3541 ts = cmd_CreateSyntax("getcalleraccess", GetCallerAccess, NULL,
3542 "list callers access");
3543 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3544 cmd_CreateAlias(ts, "gca");
3546 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL,
3547 "clean up access control list");
3548 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3550 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL,
3551 "copy access control list");
3552 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0,
3553 "source directory (or DFS file)");
3554 cmd_AddParm(ts, "-todir", CMD_LIST, 0,
3555 "destination directory (or DFS file)");
3556 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3557 "first clear dest access list");
3558 parm_copyacl_id = ts->nParms;
3559 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3560 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3562 cmd_CreateAlias(ts, "ca");
3564 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
3565 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3566 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
3567 "flush mount symlink from cache");
3568 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3570 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
3571 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3572 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL,
3573 "disk space quota in 1K units");
3575 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL,
3576 "disk space guaranteed");
3577 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3579 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL,
3581 cmd_CreateAlias(ts, "sv");
3583 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL,
3584 "control Cache Manager messages");
3585 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL,
3586 "[user|console|all|none]");
3588 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
3589 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3590 cmd_CreateAlias(ts, "lv");
3591 cmd_CreateAlias(ts, "listvol");
3593 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
3594 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3595 cmd_CreateAlias(ts, "lq");
3597 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL,
3598 "show server disk space usage");
3599 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3600 cmd_CreateAlias(ts, "df");
3602 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
3603 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3605 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
3606 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3608 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
3609 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3610 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3611 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3612 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3613 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3614 "don't check name with VLDB");
3616 #if defined(AFS_CACHE_BYPASS)
3617 ts = cmd_CreateSyntax("bypassthreshold", BypassThresholdCmd, 0,
3618 "get/set cache bypass file size threshold");
3619 cmd_AddParm(ts, "-size", CMD_SINGLE, CMD_OPTIONAL, "file size");
3626 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3630 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
3631 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3633 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL,
3634 "check local cell's servers");
3635 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3636 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3637 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3638 "just list, don't check");
3639 cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL,
3640 "seconds between probes");
3642 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL,
3643 "check volumeID/name mappings");
3644 cmd_CreateAlias(ts, "checkbackups");
3647 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL,
3649 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3650 "size in 1K byte blocks (0 => reset)");
3651 cmd_CreateAlias(ts, "cachesize");
3653 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL,
3654 "reset size back to boot value");
3656 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL,
3657 "get cache usage info");
3658 cmd_AddParm(ts, "-files", CMD_FLAG, CMD_OPTIONAL, "Show cach files used as well");
3659 cmd_AddParm(ts, "-excessive", CMD_FLAG, CMD_OPTIONAL, "excessively verbose cache stats");
3661 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL,
3662 "list configured cells");
3663 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3665 ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, NULL,
3666 "list configured cell aliases");
3668 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
3669 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3670 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3672 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3674 cmd_CreateAlias(ts, "sq");
3676 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
3677 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3678 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3679 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL,
3680 "linked cell name");
3682 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
3683 "configure new cell alias");
3684 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
3685 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
3687 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3689 * Turn this on only if you wish to be able to talk to a server which is listening
3690 * on alternative ports. This is not intended for general use and may not be
3691 * supported in the cache manager. It is not a way to run two servers at the
3692 * same host, since the cache manager cannot properly distinguish those two hosts.
3694 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL,
3695 "cell's fileserver port");
3696 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL,
3697 "cell's vldb server port");
3700 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
3701 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3703 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
3704 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3706 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
3709 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, NULL, "obsolete (listed primary cell)");
3712 /* set cache monitor host address */
3713 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, (char *)CMD_HIDDEN);
3714 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL,
3715 "host name or 'off'");
3716 cmd_CreateAlias(ts, "mariner");
3718 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
3719 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3721 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
3722 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3723 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3724 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL,
3725 "disallow setuid programs");
3727 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL,
3728 "flush all data in volume");
3729 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3731 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL,
3732 "get/set sysname (i.e. @sys) value");
3733 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3735 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL,
3736 "enable/disable translators to AFS");
3737 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3738 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL,
3739 "start/stop translator (on | off)");
3740 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL,
3741 "convert from afs to unix mode (on | off)");
3742 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL,
3743 "run on strict 'uid check' mode (on | off)");
3744 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
3745 "allow nfs mounts to subdirs of /afs/.. (on | off)");
3746 cmd_AddParm(ts, "-clipags", CMD_SINGLE, CMD_OPTIONAL,
3747 "enable use of client-assigned PAG's (on | off)");
3748 cmd_AddParm(ts, "-pagcb", CMD_SINGLE, CMD_OPTIONAL,
3749 "enable callbacks to get creds from new clients (on | off)");
3752 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
3753 "store to server after file close");
3754 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL,
3755 "asynchrony for specified names");
3756 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3757 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL,
3758 "new default (KB)");
3759 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3760 cmd_CreateAlias(ts, "sb");
3762 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL,
3763 "set cache manager encryption flag");
3764 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3766 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL,
3767 "get cache manager encryption flag");
3769 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
3770 "Manage per process RX statistics");
3771 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3772 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3773 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3775 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
3776 "Manage per peer RX statistics");
3777 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3778 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3779 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3781 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
3782 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
3784 /* try to find volume location information */
3785 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL,
3786 "get fid for file(s)");
3787 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3789 #ifdef AFS_DISCON_ENV
3790 ts = cmd_CreateSyntax("discon", DisconCmd, NULL,
3791 "disconnection mode");
3792 cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_REQUIRED, "offline | online");
3793 cmd_AddParm(ts, "-policy", CMD_SINGLE, CMD_OPTIONAL, "client | server");
3794 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Force reconnection, despite any synchronization issues.");
3797 ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, NULL, "nuke credentials for NFS client");
3798 cmd_AddParm(ts, "-addr", CMD_SINGLE, 0, "host name or address");
3800 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
3801 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_REQUIRED, "generate a new UUID");
3803 ts = cmd_CreateSyntax("precache", PreCacheCmd, 0,
3804 "set precache size");
3805 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3806 "size in 1K byte blocks (0 => disable)");
3808 code = cmd_Dispatch(argc, argv);
3816 Die(int errnum, char *filename)
3822 "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3825 fprintf(stderr, "%s: Invalid argument.\n", pn);
3829 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3831 fprintf(stderr, "%s: no such file returned\n", pn);
3835 "%s: You can not change a backup or readonly volume\n", pn);
3841 "%s: You don't have the required access rights on '%s'\n",
3845 "%s: You do not have the required rights to do this operation\n",
3850 fprintf(stderr, "%s:'%s'", pn, filename);
3852 fprintf(stderr, "%s", pn);
3853 fprintf(stderr, ": %s\n", afs_error_message(errnum));
3858 /* get clients interface addresses */
3860 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3863 struct cmd_item *ti;
3865 struct ViceIoctl blob;
3866 struct sprefrequest *in;
3867 struct sprefinfo *out;
3869 in = (struct sprefrequest *)space;
3873 blob.in_size = sizeof(struct sprefrequest);
3874 blob.in = (char *)in;
3876 blob.out_size = MAXSIZE;
3879 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3880 /* returns addr in network byte order */
3881 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3883 perror("getClientInterfaceAddr pioctl");
3889 out = (struct sprefinfo *)blob.out;
3890 for (i = 0; i < out->num_servers; i++) {
3893 addr = ntohl(out->servers[i].server.s_addr);
3894 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3895 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3896 printf("%-50s\n", tbuffer);
3898 in->offset = out->next_offset;
3900 } while (out->next_offset > 0);
3906 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3908 afs_int32 code, addr;
3909 struct cmd_item *ti;
3911 struct ViceIoctl blob;
3912 struct setspref *ssp;
3913 int sizeUsed = 0, i, flag;
3914 afs_int32 existingAddr[1024]; /* existing addresses on this host */
3918 ssp = (struct setspref *)space;
3919 ssp->num_servers = 0;
3922 blob.out_size = MAXSIZE;
3925 fprintf(stderr, "Permission denied: requires root access.\n");
3929 /* extract all existing interface addresses */
3930 existNu = rx_getAllAddr(existingAddr, 1024);
3934 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
3935 for (ti = as->parms[0].items; ti; ti = ti->next) {
3936 if (sizeUsed >= sizeof(space)) {
3937 fprintf(stderr, "No more space\n");
3940 addr = extractAddr(ti->data, 20); /* network order */
3941 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
3942 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
3947 /* see if it is an address that really exists */
3948 for (flag = 0, i = 0; i < existNu; i++)
3949 if (existingAddr[i] == addr) {
3953 if (!flag) { /* this is an nonexistent address */
3954 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
3958 /* copy all specified addr into ioctl buffer */
3959 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
3960 printf("Adding 0x%08x\n", addr);
3962 sizeUsed += sizeof(struct spref);
3964 if (ssp->num_servers < 1) {
3965 fprintf(stderr, "No addresses specified\n");
3968 blob.in_size = sizeUsed - sizeof(struct spref);
3970 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
3980 FlushMountCmd(struct cmd_syndesc *as, void *arock)
3983 struct ViceIoctl blob;
3984 struct cmd_item *ti;
3985 char orig_name[1024]; /*Original name, may be modified */
3986 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
3987 char parent_dir[1024]; /*Parent directory of true name */
3988 char *last_component; /*Last component of true name */
3989 struct stat statbuff; /*Buffer for status info */
3990 int link_chars_read; /*Num chars read in readlink() */
3991 int thru_symlink; /*Did we get to a mount point via a symlink? */
3994 for (ti = as->parms[0].items; ti; ti = ti->next) {
3997 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
4000 if (lstat(orig_name, &statbuff) < 0) {
4001 /* if lstat fails, we should still try the pioctl, since it
4002 * may work (for example, lstat will fail, but pioctl will
4003 * work if the volume of offline (returning ENODEV). */
4004 statbuff.st_mode = S_IFDIR; /* lie like pros */
4008 * The lstat succeeded. If the given file is a symlink, substitute
4009 * the file name with the link name.
4011 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
4014 * Read name of resolved file.
4016 link_chars_read = readlink(orig_name, true_name, 1024);
4017 if (link_chars_read <= 0) {
4019 "%s: Can't read target name for '%s' symbolic link!\n",
4026 * Add a trailing null to what was read, bump the length.
4028 true_name[link_chars_read++] = 0;
4031 * If the symlink is an absolute pathname, we're fine. Otherwise, we
4032 * have to create a full pathname using the original name and the
4033 * relative symlink name. Find the rightmost slash in the original
4034 * name (we know there is one) and splice in the symlink value.
4036 if (true_name[0] != '/') {
4037 last_component = (char *)strrchr(orig_name, '/');
4038 strcpy(++last_component, true_name);
4039 strcpy(true_name, orig_name);
4042 strcpy(true_name, orig_name);
4045 * Find rightmost slash, if any.
4047 last_component = (char *)strrchr(true_name, '/');
4048 if (last_component == (char *)true_name) {
4049 strcpy(parent_dir, "/");
4052 else if (last_component != (char *)NULL) {
4054 * Found it. Designate everything before it as the parent directory,
4055 * everything after it as the final component.
4057 strncpy(parent_dir, true_name, last_component - true_name);
4058 parent_dir[last_component - true_name] = 0;
4059 last_component++; /*Skip the slash */
4062 * No slash appears in the given file name. Set parent_dir to the current
4063 * directory, and the last component as the given name.
4065 strcpy(parent_dir, ".");
4066 last_component = true_name;
4069 if (strcmp(last_component, ".") == 0
4070 || strcmp(last_component, "..") == 0) {
4072 "%s: you may not use '.' or '..' as the last component\n",
4074 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
4080 blob.in = last_component;
4081 blob.in_size = strlen(last_component) + 1;
4083 memset(space, 0, MAXSIZE);
4085 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4088 if (errno == EINVAL) {
4089 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4091 Die(errno, (ti->data ? ti->data : parent_dir));
4100 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4103 afs_int32 flags = 0;
4104 struct ViceIoctl blob;
4105 struct cmd_item *ti;
4107 if (as->parms[0].items) { /* -enable */
4108 flags |= AFSCALL_RXSTATS_ENABLE;
4110 if (as->parms[1].items) { /* -disable */
4111 flags |= AFSCALL_RXSTATS_DISABLE;
4113 if (as->parms[2].items) { /* -clear */
4114 flags |= AFSCALL_RXSTATS_CLEAR;
4117 fprintf(stderr, "You must specify at least one argument\n");
4121 blob.in = (char *)&flags;
4122 blob.in_size = sizeof(afs_int32);
4125 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4135 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4138 afs_int32 flags = 0;
4139 struct ViceIoctl blob;
4140 struct cmd_item *ti;
4142 if (as->parms[0].items) { /* -enable */
4143 flags |= AFSCALL_RXSTATS_ENABLE;
4145 if (as->parms[1].items) { /* -disable */
4146 flags |= AFSCALL_RXSTATS_DISABLE;
4148 if (as->parms[2].items) { /* -clear */
4149 flags |= AFSCALL_RXSTATS_CLEAR;
4152 fprintf(stderr, "You must specify at least one argument\n");
4156 blob.in = (char *)&flags;
4157 blob.in_size = sizeof(afs_int32);
4160 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4170 GetFidCmd(struct cmd_syndesc *as, void *arock)
4172 struct ViceIoctl blob;
4173 struct cmd_item *ti;
4174 for (ti = as->parms[0].items; ti; ti = ti->next) {
4175 struct VenusFid vfid;
4177 blob.out_size = sizeof(struct VenusFid);
4178 blob.out = (char *) &vfid;
4181 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
4182 printf("File %s (%u.%u.%u) contained in volume %u\n",
4183 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,