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>
43 #include "afs/prs_fs.h"
44 #include <afs/afsint.h>
45 #include <afs/cellconfig.h>
48 #include <rx/rx_globals.h>
49 #include <afs/vldbint.h>
50 #include <afs/volser.h>
51 #include <afs/vlserver.h>
53 #include <afs/afsutil.h>
56 #include <afs/ptclient.h>
61 #define MAXCELLHOSTS 8
64 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
65 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
67 static char space[MAXSIZE];
68 static char tspace[1024];
69 static struct ubik_client *uclient;
71 static int GetClientAddrsCmd(), SetClientAddrsCmd(), FlushMountCmd();
72 static int RxStatProcCmd(), RxStatPeerCmd(), GetFidCmd(), UuidCmd();
74 extern char *hostutil_GetNameByINet();
75 extern struct hostent *hostutil_GetHostByName();
78 extern struct cmd_syndesc *cmd_CreateSyntax();
79 static char pn[] = "fs";
80 static int rxInitDone = 0;
82 static void ZapList();
83 static int PruneList();
91 * Character to use between name and rights in printed representation for
94 #define DFS_SEPARATOR ' '
96 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
99 int dfs; /* Originally true if a dfs acl; now also the type
100 * of the acl (1, 2, or 3, corresponding to object,
101 * initial dir, or initial object). */
102 sec_rgy_name_t cell; /* DFS cell name */
105 struct AclEntry *pluslist;
106 struct AclEntry *minuslist;
110 struct AclEntry *next;
116 afs_int32 callerAccess;
128 ZapList(acl->pluslist);
129 ZapList(acl->minuslist);
142 if (t >= 'A' && t <= 'Z')
144 if (u >= 'A' && u <= 'Z')
154 * Mods for the AFS/DFS protocol translator.
156 * DFS rights. It's ugly to put these definitions here, but they
157 * *cannot* change, because they're part of the wire protocol.
158 * In any event, the protocol translator will guarantee these
159 * assignments for AFS cache managers.
161 #define DFS_READ 0x01
162 #define DFS_WRITE 0x02
163 #define DFS_EXECUTE 0x04
164 #define DFS_CONTROL 0x08
165 #define DFS_INSERT 0x10
166 #define DFS_DELETE 0x20
168 /* the application definable ones (backwards from AFS) */
169 #define DFS_USR0 0x80000000 /* "A" bit */
170 #define DFS_USR1 0x40000000 /* "B" bit */
171 #define DFS_USR2 0x20000000 /* "C" bit */
172 #define DFS_USR3 0x10000000 /* "D" bit */
173 #define DFS_USR4 0x08000000 /* "E" bit */
174 #define DFS_USR5 0x04000000 /* "F" bit */
175 #define DFS_USR6 0x02000000 /* "G" bit */
176 #define DFS_USR7 0x01000000 /* "H" bit */
177 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
178 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
181 * Offset of -id switch in command structure for various commands.
182 * The -if switch is the next switch always.
184 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
187 * Determine whether either the -id or -if switches are present, and
188 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
190 /* int id; Offset of -id switch; -if is next switch */
192 getidf(struct cmd_syndesc *as, int id)
196 if (as->parms[id].items) {
199 if (as->parms[id + 1].items) {
204 "%s: you may specify either -id or -if, but not both switches\n",
212 PRights(afs_int32 arights, int dfs)
215 if (arights & PRSFS_READ)
217 if (arights & PRSFS_LOOKUP)
219 if (arights & PRSFS_INSERT)
221 if (arights & PRSFS_DELETE)
223 if (arights & PRSFS_WRITE)
225 if (arights & PRSFS_LOCK)
227 if (arights & PRSFS_ADMINISTER)
229 if (arights & PRSFS_USR0)
231 if (arights & PRSFS_USR1)
233 if (arights & PRSFS_USR2)
235 if (arights & PRSFS_USR3)
237 if (arights & PRSFS_USR4)
239 if (arights & PRSFS_USR5)
241 if (arights & PRSFS_USR6)
243 if (arights & PRSFS_USR7)
246 if (arights & DFS_READ)
250 if (arights & DFS_WRITE)
254 if (arights & DFS_EXECUTE)
258 if (arights & DFS_CONTROL)
262 if (arights & DFS_INSERT)
266 if (arights & DFS_DELETE)
270 if (arights & (DFS_USRALL))
272 if (arights & DFS_USR0)
274 if (arights & DFS_USR1)
276 if (arights & DFS_USR2)
278 if (arights & DFS_USR3)
280 if (arights & DFS_USR4)
282 if (arights & DFS_USR5)
284 if (arights & DFS_USR6)
286 if (arights & DFS_USR7)
291 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
295 struct ViceIoctl blob;
299 blob.out_size = MAXSIZE;
302 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
304 if ((errno == EINVAL) || (errno == ENOENT))
310 /* return a static pointer to a buffer */
315 strcpy(tspace, apath);
316 tp = strrchr(tspace, '/');
324 enum rtype { add, destroy, deny };
327 Convert(char *arights, int dfs, enum rtype *rtypep)
333 *rtypep = add; /* add rights, by default */
336 if (!strcmp(arights, "null")) {
340 if (!strcmp(arights, "read"))
341 return DFS_READ | DFS_EXECUTE;
342 if (!strcmp(arights, "write"))
343 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
345 if (!strcmp(arights, "all"))
346 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
347 DFS_WRITE | DFS_CONTROL;
349 if (!strcmp(arights, "read"))
350 return PRSFS_READ | PRSFS_LOOKUP;
351 if (!strcmp(arights, "write"))
352 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
353 PRSFS_WRITE | PRSFS_LOCK;
354 if (!strcmp(arights, "mail"))
355 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
356 if (!strcmp(arights, "all"))
357 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
358 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
360 if (!strcmp(arights, "none")) {
361 *rtypep = destroy; /* Remove entire entry */
364 len = strlen(arights);
366 for (i = 0; i < len; i++) {
400 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
408 mode |= PRSFS_LOOKUP;
410 mode |= PRSFS_INSERT;
412 mode |= PRSFS_DELETE;
418 mode |= PRSFS_ADMINISTER;
436 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
445 static struct AclEntry *
446 FindList(struct AclEntry *alist, char *aname)
449 if (!foldcmp(alist->name, aname))
456 /* if no parm specified in a particular slot, set parm to be "." instead */
458 SetDotDefault(struct cmd_item **aitemp)
462 return; /* already has value */
463 /* otherwise, allocate an item representing "." */
464 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
466 ti->next = (struct cmd_item *)0;
467 ti->data = (char *)malloc(2);
469 strcpy(ti->data, ".");
474 ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
476 struct AclEntry *tlist;
477 tlist = (plus ? al->pluslist : al->minuslist);
478 tlist = FindList(tlist, aname);
480 /* Found the item already in the list. */
481 tlist->rights = arights;
483 al->nplus -= PruneList(&al->pluslist, al->dfs);
485 al->nminus -= PruneList(&al->minuslist, al->dfs);
488 /* Otherwise we make a new item and plug in the new data. */
489 tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry));
491 strcpy(tlist->name, aname);
492 tlist->rights = arights;
494 tlist->next = al->pluslist;
495 al->pluslist = tlist;
497 if (arights == 0 || arights == -1)
498 al->nplus -= PruneList(&al->pluslist, al->dfs);
500 tlist->next = al->minuslist;
501 al->minuslist = tlist;
504 al->nminus -= PruneList(&al->minuslist, al->dfs);
509 ZapList(struct AclEntry *alist)
511 struct AclEntry *tp, *np;
512 for (tp = alist; tp; tp = np) {
519 PruneList(struct AclEntry **ae, int dfs)
521 struct AclEntry **lp;
522 struct AclEntry *te, *ne;
526 for (te = *ae; te; te = ne) {
527 if ((!dfs && te->rights == 0) || te->rights == -1) {
543 while (*astr != '\n')
550 * Create an empty acl, taking into account whether the acl pointed
551 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
552 * can recover from problems caused by bogus ACL's (in that case, always
553 * assume that the acl is AFS: for DFS, the user can always resort to
554 * acl_edit, but for AFS there may be no other way out).
562 tp = (struct Acl *)malloc(sizeof(struct Acl));
564 tp->nplus = tp->nminus = 0;
565 tp->pluslist = tp->minuslist = 0;
567 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
574 int nplus, nminus, i, trights;
576 struct AclEntry *first, *last, *tl;
579 ta = (struct Acl *)malloc(sizeof(struct Acl));
582 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
583 astr = SkipLine(astr);
584 sscanf(astr, "%d", &ta->nminus);
585 astr = SkipLine(astr);
592 for (i = 0; i < nplus; i++) {
593 sscanf(astr, "%100s %d", tname, &trights);
594 astr = SkipLine(astr);
595 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
599 strcpy(tl->name, tname);
600 tl->rights = trights;
606 ta->pluslist = first;
610 for (i = 0; i < nminus; i++) {
611 sscanf(astr, "%100s %d", tname, &trights);
612 astr = SkipLine(astr);
613 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
617 strcpy(tl->name, tname);
618 tl->rights = trights;
624 ta->minuslist = first;
630 PrintStatus(VolumeStatus * status, char *name, char *offmsg)
632 printf("Volume status for vid = %u named %s\n", status->Vid, name);
634 printf("Current offline message is %s\n", offmsg);
635 printf("Current disk quota is ");
636 if (status->MaxQuota != 0)
637 printf("%d\n", status->MaxQuota);
639 printf("unlimited\n");
640 printf("Current blocks used are %d\n", status->BlocksInUse);
641 printf("The partition has %d blocks available out of %d\n\n",
642 status->PartBlocksAvail, status->PartMaxBlocks);
647 QuickPrintStatus(VolumeStatus * status, char *name)
649 double QuotaUsed = 0.0;
650 double PartUsed = 0.0;
652 printf("%-25.25s", name);
654 if (status->MaxQuota != 0) {
655 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
657 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
659 printf(" no limit%10d", status->BlocksInUse);
661 if (QuotaUsed > 90.0) {
662 printf("%5.0f%%<<", QuotaUsed);
665 printf("%5.0f%% ", QuotaUsed);
668 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
670 if (PartUsed > 97.0) {
671 printf("%9.0f%%<<", PartUsed);
674 printf("%9.0f%% ", PartUsed);
676 printf(" <<WARNING\n");
683 QuickPrintSpace(VolumeStatus * status, char *name)
685 double PartUsed = 0.0;
687 printf("%-25.25s", name);
689 printf("%10d%10d%10d", status->PartMaxBlocks,
690 status->PartMaxBlocks - status->PartBlocksAvail,
691 status->PartBlocksAvail);
695 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
697 if (PartUsed > 90.0) {
698 printf(" %4.0f%%<<", PartUsed);
701 printf(" %4.0f%% ", PartUsed);
703 printf(" <<WARNING\n");
710 AclToString(struct Acl *acl)
712 static char mydata[MAXSIZE];
713 char tstring[MAXSIZE];
718 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
721 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
722 for (tp = acl->pluslist; tp; tp = tp->next) {
723 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
724 strcat(mydata, tstring);
726 for (tp = acl->minuslist; tp; tp = tp->next) {
727 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
728 strcat(mydata, tstring);
734 SetACLCmd(struct cmd_syndesc *as, char *arock)
737 struct ViceIoctl blob;
739 struct cmd_item *ti, *ui;
743 int idf = getidf(as, parm_setacl_id);
746 if (as->parms[2].items)
750 plusp = !(as->parms[3].items);
751 for (ti = as->parms[0].items; ti; ti = ti->next) {
752 blob.out_size = MAXSIZE;
754 blob.in = blob.out = space;
755 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
757 Die(errno, ti->data);
764 ta = ParseAcl(space);
765 if (!plusp && ta->dfs) {
767 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
769 "(you may specify \"null\" to revoke all rights, however)\n");
777 ta = EmptyAcl(space);
779 ta = ParseAcl(space);
780 CleanAcl(ta, ti->data);
781 for (ui = as->parms[1].items; ui; ui = ui->next->next) {
785 "%s: Missing second half of user/access pair.\n", pn);
789 rights = Convert(ui->next->data, ta->dfs, &rtype);
790 if (rtype == destroy && !ta->dfs) {
791 struct AclEntry *tlist;
793 tlist = (plusp ? ta->pluslist : ta->minuslist);
794 if (!FindList(tlist, ui->data))
797 if (rtype == deny && !ta->dfs)
799 if (rtype == destroy && ta->dfs)
801 ChangeList(ta, plusp, ui->data, rights);
803 blob.in = AclToString(ta);
805 blob.in_size = 1 + strlen(blob.in);
806 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
808 if (errno == EINVAL) {
810 static char *fsenv = 0;
812 fsenv = (char *)getenv("FS_EXPERT");
815 "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n",
819 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
820 "\nPossible reasons for this include:\n\n",
821 " -You may have specified an inappropriate combination of rights.\n",
822 " For example, some DFS-supported filesystems may not allow you to\n",
823 " drop the \"c\" right from \"user_obj\".\n\n",
824 " -A mask_obj may be required (it is likely required by the underlying\n",
825 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
826 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
827 " does not automatically create or update the mask_obj. Try setting\n",
828 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
829 " users or groups. You can do this with a single command, such as\n",
830 " \"fs sa mask_obj all user:somename read\"\n\n",
831 " -A specified user or group may not exist.\n\n",
832 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
833 " This is probably not allowed by the underlying file system.\n\n",
834 " -If you add a user or group to a DFS ACL, remember that it must be\n",
835 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
836 " may be local requirements on the format of the user or group name.\n",
837 " Check with your cell administrator.\n\n",
838 " -Or numerous other possibilities. It would be great if we could be more\n",
839 " precise about the actual problem, but for various reasons, this is\n",
840 " impractical via this interface. If you can't figure it out, you\n",
841 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
842 " whatever is provided). You may get better results. Good luck!\n\n",
843 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
847 "%s: Invalid argument, possible reasons include:\n",
849 fprintf(stderr, "\t-File not in AFS\n");
851 "\t-Too many users on access control list\n");
853 "\t-Tried to add non-existent user to access control list\n");
856 Die(errno, ti->data);
868 CopyACLCmd(struct cmd_syndesc *as, char *arock)
871 struct ViceIoctl blob;
872 struct Acl *fa, *ta = 0;
874 struct cmd_item *ti, *ui;
878 int idf = getidf(as, parm_copyacl_id);
881 if (as->parms[2].items)
885 blob.out_size = MAXSIZE;
887 blob.in = blob.out = space;
888 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
890 Die(errno, as->parms[0].items->data);
893 fa = ParseAcl(space);
894 CleanAcl(fa, as->parms[0].items->data);
895 for (ti = as->parms[1].items; ti; ti = ti->next) {
896 blob.out_size = MAXSIZE;
898 blob.in = blob.out = space;
899 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
901 Die(errno, ti->data);
909 ta = EmptyAcl(space);
911 ta = ParseAcl(space);
912 CleanAcl(ta, ti->data);
913 if (ta->dfs != fa->dfs) {
915 "%s: incompatible file system types: acl not copied to %s; aborted\n",
921 if (!clear && strcmp(ta->cell, fa->cell) != 0) {
923 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
928 strcpy(ta->cell, fa->cell);
930 for (tp = fa->pluslist; tp; tp = tp->next)
931 ChangeList(ta, 1, tp->name, tp->rights);
932 for (tp = fa->minuslist; tp; tp = tp->next)
933 ChangeList(ta, 0, tp->name, tp->rights);
934 blob.in = AclToString(ta);
936 blob.in_size = 1 + strlen(blob.in);
937 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
939 if (errno == EINVAL) {
941 "%s: Invalid argument, possible reasons include:\n",
943 fprintf(stderr, "\t-File not in AFS\n");
945 Die(errno, ti->data);
956 /* pioctl() call to get the cellname of a pathname */
958 GetCell(char *fname, char *cellname)
961 struct ViceIoctl blob;
964 blob.out_size = MAXCELLCHARS;
967 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
968 return code ? errno : 0;
971 /* Check if a username is valid: If it contains only digits (or a
972 * negative sign), then it might be bad. We then query the ptserver
976 BadName(char *aname, char *fname)
978 afs_int32 tc, code, id;
980 char cell[MAXCELLCHARS];
982 for (nm = aname; tc = *nm; nm++) {
983 /* all must be '-' or digit to be bad */
984 if (tc != '-' && (tc < '0' || tc > '9'))
988 /* Go to the PRDB and see if this all number username is valid */
989 code = GetCell(fname, cell);
993 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
994 code = pr_SNameToId(aname, &id);
997 /* 1=>Not-valid; 0=>Valid */
998 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1002 /* clean up an access control list of its bad entries; return 1 if we made
1003 any changes to the list, and 0 otherwise */
1005 CleanAcl(struct Acl *aa, char *fname)
1007 struct AclEntry *te, **le, *ne;
1010 /* Don't correct DFS ACL's for now */
1014 /* prune out bad entries */
1015 changes = 0; /* count deleted entries */
1017 for (te = aa->pluslist; te; te = ne) {
1019 if (BadName(te->name, fname)) {
1029 le = &aa->minuslist;
1030 for (te = aa->minuslist; te; te = ne) {
1032 if (BadName(te->name, fname)) {
1046 /* clean up an acl to not have bogus entries */
1048 CleanACLCmd(struct cmd_syndesc *as, char *arock)
1052 struct ViceIoctl blob;
1054 struct cmd_item *ti;
1055 struct AclEntry *te;
1058 SetDotDefault(&as->parms[0].items);
1059 for (ti = as->parms[0].items; ti; ti = ti->next) {
1060 blob.out_size = MAXSIZE;
1063 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1065 Die(errno, ti->data);
1072 ta = ParseAcl(space);
1075 "%s: cleanacl is not supported for DFS access lists.\n",
1081 changes = CleanAcl(ta, ti->data);
1084 /* now set the acl */
1085 blob.in = AclToString(ta);
1086 blob.in_size = strlen(blob.in) + 1;
1088 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1090 if (errno == EINVAL) {
1092 "%s: Invalid argument, possible reasons include\n",
1094 fprintf(stderr, "%s: File not in vice or\n", pn);
1096 "%s: Too many users on access control list or\n",
1099 Die(errno, ti->data);
1105 /* now list the updated acl */
1106 printf("Access list for %s is now\n", ti->data);
1107 if (ta->nplus > 0) {
1109 printf("Normal rights:\n");
1110 for (te = ta->pluslist; te; te = te->next) {
1111 printf(" %s ", te->name);
1112 PRights(te->rights, ta->dfs);
1116 if (ta->nminus > 0) {
1117 printf("Negative rights:\n");
1118 for (te = ta->minuslist; te; te = te->next) {
1119 printf(" %s ", te->name);
1120 PRights(te->rights, ta->dfs);
1127 printf("Access list for %s is fine.\n", ti->data);
1135 ListACLCmd(struct cmd_syndesc *as, char *arock)
1139 struct ViceIoctl blob;
1140 struct AclEntry *te;
1141 struct cmd_item *ti;
1142 int idf = getidf(as, parm_listacl_id);
1145 SetDotDefault(&as->parms[0].items);
1146 for (ti = as->parms[0].items; ti; ti = ti->next) {
1147 blob.out_size = MAXSIZE;
1149 blob.in = blob.out = space;
1150 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1152 Die(errno, ti->data);
1156 ta = ParseAcl(space);
1159 printf("Access list for %s is\n", ti->data);
1162 printf("DFS access list for %s is\n", ti->data);
1165 printf("DFS initial directory access list of %s is\n", ti->data);
1168 printf("DFS initial file access list of %s is\n", ti->data);
1172 printf(" Default cell = %s\n", ta->cell);
1174 if (ta->nplus > 0) {
1176 printf("Normal rights:\n");
1177 for (te = ta->pluslist; te; te = te->next) {
1178 printf(" %s ", te->name);
1179 PRights(te->rights, ta->dfs);
1183 if (ta->nminus > 0) {
1184 printf("Negative rights:\n");
1185 for (te = ta->minuslist; te; te = te->next) {
1186 printf(" %s ", te->name);
1187 PRights(te->rights, ta->dfs);
1199 GetCallerAccess(struct cmd_syndesc *as, char *arock)
1201 struct cmd_item *ti;
1204 SetDotDefault(&as->parms[0].items);
1205 for (ti = as->parms[0].items; ti; ti = ti->next) {
1207 struct ViceIoctl blob;
1208 struct vcxstat2 stat;
1209 blob.out_size = sizeof(struct vcxstat2);
1211 blob.out = (void *)&stat;
1212 code = pioctl(ti->data, VIOC_GETVCXSTATUS2, &blob, 1);
1214 Die(errno, ti->data);
1218 printf("Callers access to %s is ", ti->data);
1219 PRights(stat.callerAccess, 0);
1226 FlushVolumeCmd(struct cmd_syndesc *as, char *arock)
1229 struct ViceIoctl blob;
1230 struct cmd_item *ti;
1233 SetDotDefault(&as->parms[0].items);
1234 for (ti = as->parms[0].items; ti; ti = ti->next) {
1235 blob.in_size = blob.out_size = 0;
1236 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1238 fprintf(stderr, "Error flushing volume ");
1248 * The Windows version of UuidCmd displays the UUID.
1249 * When the UNIX version is updated to do the same
1250 * be sure to replace the CMD_REQUIRED flag with
1251 * CMD_OPTIONAL in the cmd_AddParam(-generate) call
1254 UuidCmd(struct cmd_syndesc *as, char *arock)
1257 struct ViceIoctl blob;
1262 if (as->parms[0].items) {
1264 fprintf (stderr, "Permission denied: requires root access.\n");
1268 /* generate new UUID */
1269 code = pioctl(0, VIOC_NEWUUID, &blob, 1);
1276 printf("New uuid generated.\n");
1278 /* This will never execute */
1279 printf("Please add the '-generate' option to generate a new UUID.\n");
1285 FlushCmd(struct cmd_syndesc *as, char *arock)
1288 struct ViceIoctl blob;
1289 struct cmd_item *ti;
1292 for (ti = as->parms[0].items; ti; ti = ti->next) {
1293 blob.in_size = blob.out_size = 0;
1294 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1296 if (errno == EMFILE) {
1297 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1300 fprintf(stderr, "%s: Error flushing file ", pn);
1310 /* all this command does is repackage its args and call SetVolCmd */
1312 SetQuotaCmd(struct cmd_syndesc *as, char *arock)
1314 struct cmd_syndesc ts;
1316 /* copy useful stuff from our command slot; we may later have to reorder */
1317 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1318 return SetVolCmd(&ts);
1322 SetVolCmd(struct cmd_syndesc *as, char *arock)
1325 struct ViceIoctl blob;
1326 struct cmd_item *ti;
1327 struct VolumeStatus *status;
1328 char *offmsg, *input;
1331 SetDotDefault(&as->parms[0].items);
1332 for (ti = as->parms[0].items; ti; ti = ti->next) {
1334 blob.out_size = MAXSIZE;
1335 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1338 status = (VolumeStatus *) space;
1339 status->MinQuota = status->MaxQuota = -1;
1341 if (as->parms[1].items) {
1342 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1344 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1349 if (as->parms[2].items)
1350 offmsg = as->parms[2].items->data;
1351 input = (char *)status + sizeof(*status);
1352 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1354 if (strlen(offmsg) >= VMSGSIZE) {
1356 "%s: message must be shorter than %d characters\n",
1361 strcpy(input, offmsg);
1362 blob.in_size += strlen(offmsg);
1363 input += strlen(offmsg) + 1;
1366 *(input++) = '\0'; /* Pad for old style volume "motd" */
1367 code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1);
1369 Die(errno, ti->data);
1377 * Why is VenusFid declared in the kernel-only section of afs.h,
1378 * if it's the exported interface of the cache manager?
1386 ExamineCmd(struct cmd_syndesc *as, char *arock)
1389 struct ViceIoctl blob;
1390 struct cmd_item *ti;
1391 struct VolumeStatus *status;
1392 char *name, *offmsg;
1395 SetDotDefault(&as->parms[0].items);
1396 for (ti = as->parms[0].items; ti; ti = ti->next) {
1397 struct VenusFid vfid;
1400 blob.out_size = MAXSIZE;
1403 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1405 Die(errno, ti->data);
1409 status = (VolumeStatus *) space;
1410 name = (char *)status + sizeof(*status);
1411 offmsg = name + strlen(name) + 1;
1413 blob.out_size = sizeof(struct VenusFid);
1414 blob.out = (char *) &vfid;
1415 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1416 printf("File %s (%u.%u.%u) contained in volume %u\n",
1417 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1421 PrintStatus(status, name, offmsg);
1427 ListQuotaCmd(struct cmd_syndesc *as, char *arock)
1430 struct ViceIoctl blob;
1431 struct cmd_item *ti;
1432 struct VolumeStatus *status;
1436 printf("%-25s%-10s%-10s%-7s%-11s\n", "Volume Name", " Quota",
1437 " Used", " %Used", " Partition");
1438 SetDotDefault(&as->parms[0].items);
1439 for (ti = as->parms[0].items; ti; ti = ti->next) {
1441 blob.out_size = MAXSIZE;
1444 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1446 Die(errno, ti->data);
1450 status = (VolumeStatus *) space;
1451 name = (char *)status + sizeof(*status);
1452 QuickPrintStatus(status, name);
1458 WhereIsCmd(struct cmd_syndesc *as, char *arock)
1461 struct ViceIoctl blob;
1462 struct cmd_item *ti;
1468 SetDotDefault(&as->parms[0].items);
1469 for (ti = as->parms[0].items; ti; ti = ti->next) {
1471 blob.out_size = MAXSIZE;
1474 memset(space, 0, sizeof(space));
1475 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1477 Die(errno, ti->data);
1481 hosts = (afs_int32 *) space;
1482 printf("File %s is on host%s ", ti->data,
1483 (hosts[0] && !hosts[1]) ? "" : "s");
1484 for (j = 0; j < MAXHOSTS; j++) {
1487 tp = hostutil_GetNameByINet(hosts[j]);
1497 DiskFreeCmd(struct cmd_syndesc *as, char *arock)
1500 struct ViceIoctl blob;
1501 struct cmd_item *ti;
1503 struct VolumeStatus *status;
1506 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1507 " used", " avail", " %used");
1508 SetDotDefault(&as->parms[0].items);
1509 for (ti = as->parms[0].items; ti; ti = ti->next) {
1511 blob.out_size = MAXSIZE;
1514 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1516 Die(errno, ti->data);
1520 status = (VolumeStatus *) space;
1521 name = (char *)status + sizeof(*status);
1522 QuickPrintSpace(status, name);
1528 QuotaCmd(struct cmd_syndesc *as, char *arock)
1531 struct ViceIoctl blob;
1532 struct cmd_item *ti;
1534 struct VolumeStatus *status;
1537 SetDotDefault(&as->parms[0].items);
1538 for (ti = as->parms[0].items; ti; ti = ti->next) {
1540 blob.out_size = MAXSIZE;
1543 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1545 Die(errno, ti->data);
1549 status = (VolumeStatus *) space;
1550 if (status->MaxQuota)
1552 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
1555 printf("%2.0f%% of quota used.\n", quotaPct);
1561 ListMountCmd(struct cmd_syndesc *as, char *arock)
1564 struct ViceIoctl blob;
1565 struct cmd_item *ti;
1566 char orig_name[1024]; /*Original name, may be modified */
1567 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
1568 char parent_dir[1024]; /*Parent directory of true name */
1569 char *last_component; /*Last component of true name */
1570 struct stat statbuff; /*Buffer for status info */
1571 int link_chars_read; /*Num chars read in readlink() */
1572 int thru_symlink; /*Did we get to a mount point via a symlink? */
1575 for (ti = as->parms[0].items; ti; ti = ti->next) {
1578 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
1581 if (lstat(orig_name, &statbuff) < 0) {
1582 /* if lstat fails, we should still try the pioctl, since it
1583 * may work (for example, lstat will fail, but pioctl will
1584 * work if the volume of offline (returning ENODEV). */
1585 statbuff.st_mode = S_IFDIR; /* lie like pros */
1589 * The lstat succeeded. If the given file is a symlink, substitute
1590 * the file name with the link name.
1592 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1595 * Read name of resolved file.
1597 link_chars_read = readlink(orig_name, true_name, 1024);
1598 if (link_chars_read <= 0) {
1600 "%s: Can't read target name for '%s' symbolic link!\n",
1607 * Add a trailing null to what was read, bump the length.
1609 true_name[link_chars_read++] = 0;
1612 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1613 * have to create a full pathname using the original name and the
1614 * relative symlink name. Find the rightmost slash in the original
1615 * name (we know there is one) and splice in the symlink value.
1617 if (true_name[0] != '/') {
1618 last_component = (char *)strrchr(orig_name, '/');
1619 strcpy(++last_component, true_name);
1620 strcpy(true_name, orig_name);
1623 strcpy(true_name, orig_name);
1626 * Find rightmost slash, if any.
1628 last_component = (char *)strrchr(true_name, '/');
1629 if (last_component) {
1631 * Found it. Designate everything before it as the parent directory,
1632 * everything after it as the final component.
1634 strncpy(parent_dir, true_name, last_component - true_name);
1635 parent_dir[last_component - true_name] = 0;
1636 last_component++; /*Skip the slash */
1639 * No slash appears in the given file name. Set parent_dir to the current
1640 * directory, and the last component as the given name.
1642 strcpy(parent_dir, ".");
1643 last_component = true_name;
1646 if (strcmp(last_component, ".") == 0
1647 || strcmp(last_component, "..") == 0) {
1649 "%s: you may not use '.' or '..' as the last component\n",
1651 fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n",
1657 blob.in = last_component;
1658 blob.in_size = strlen(last_component) + 1;
1659 blob.out_size = MAXSIZE;
1661 memset(space, 0, MAXSIZE);
1663 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1666 printf("'%s' is a %smount point for volume '%s'\n", ti->data,
1667 (thru_symlink ? "symbolic link, leading to a " : ""),
1670 if (errno == EINVAL) {
1671 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
1673 Die(errno, (ti->data ? ti->data : parent_dir));
1682 MakeMountCmd(struct cmd_syndesc *as, char *arock)
1685 char *cellName, *volName, *tmpName;
1686 struct afsconf_cell info;
1687 struct vldbentry vldbEntry;
1688 struct ViceIoctl blob;
1694 if (as->parms[5].items && !as->parms[2].items) {
1695 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1700 if (as->parms[2].items) /* cell name specified */
1701 cellName = as->parms[2].items->data;
1704 volName = as->parms[1].items->data;
1706 if (strlen(volName) >= 64) {
1708 "%s: volume name too long (length must be < 64 characters)\n",
1713 /* Check for a cellname in the volume specification, and complain
1714 * if it doesn't match what was specified with -cell */
1715 if (tmpName = strchr(volName, ':')) {
1718 if (strcasecmp(cellName, volName)) {
1719 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1724 volName = ++tmpName;
1727 if (!InAFS(Parent(as->parms[0].items->data))) {
1729 "%s: mount points must be created within the AFS file system\n",
1736 blob.out_size = MAXSIZE;
1739 pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME,
1743 code = GetCellName(cellName ? cellName : space, &info);
1747 if (!(as->parms[4].items)) {
1748 /* not fast, check which cell the mountpoint is being created in */
1749 /* not fast, check name with VLDB */
1750 code = VLDBInit(1, &info);
1752 /* make the check. Don't complain if there are problems with init */
1754 ubik_VL_GetEntryByNameO(uclient, 0, volName,
1756 if (code == VL_NOENT) {
1758 "%s: warning, volume %s does not exist in cell %s.\n",
1759 pn, volName, cellName ? cellName : space);
1764 if (as->parms[3].items) /* if -rw specified */
1769 /* cellular mount point, prepend cell prefix */
1770 strcat(space, info.name);
1773 strcat(space, volName); /* append volume name */
1774 strcat(space, "."); /* stupid convention; these end with a period */
1775 code = symlink(space, as->parms[0].items->data);
1777 Die(errno, as->parms[0].items->data);
1784 * Delete AFS mount points. Variables are used as follows:
1785 * tbuffer: Set to point to the null-terminated directory name of the mount point
1786 * (or ``.'' if none is provided)
1787 * tp: Set to point to the actual name of the mount point to nuke.
1790 RemoveMountCmd(struct cmd_syndesc *as, char *arock)
1793 struct ViceIoctl blob;
1794 struct cmd_item *ti;
1796 char lsbuffer[1024];
1800 for (ti = as->parms[0].items; ti; ti = ti->next) {
1802 tp = (char *)strrchr(ti->data, '/');
1804 strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */
1806 tp++; /* skip the slash */
1808 strcpy(tbuffer, ".");
1812 blob.in_size = strlen(tp) + 1;
1813 blob.out = lsbuffer;
1814 blob.out_size = sizeof(lsbuffer);
1815 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1817 if (errno == EINVAL) {
1818 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
1821 Die(errno, ti->data);
1824 continue; /* don't bother trying */
1828 blob.in_size = strlen(tp) + 1;
1829 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1831 Die(errno, ti->data);
1842 CheckServersCmd(struct cmd_syndesc *as, char *arock)
1845 struct ViceIoctl blob;
1851 struct afsconf_cell info;
1852 struct chservinfo checkserv;
1854 memset(&checkserv, 0, sizeof(struct chservinfo));
1855 blob.in_size = sizeof(struct chservinfo);
1856 blob.in = (caddr_t) & checkserv;
1858 blob.out_size = MAXSIZE;
1860 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1862 /* prepare flags for checkservers command */
1863 temp = 2; /* default to checking local cell only */
1864 if (as->parms[2].items)
1865 temp |= 1; /* set fast flag */
1866 if (as->parms[1].items)
1867 temp &= ~2; /* turn off local cell check */
1869 checkserv.magic = 0x12345678; /* XXX */
1870 checkserv.tflags = temp;
1872 /* now copy in optional cell name, if specified */
1873 if (as->parms[0].items) {
1874 code = GetCellName(as->parms[0].items->data, &info);
1878 strcpy(checkserv.tbuffer, info.name);
1879 checkserv.tsize = strlen(info.name) + 1;
1881 strcpy(checkserv.tbuffer, "\0");
1882 checkserv.tsize = 0;
1885 if (as->parms[3].items) {
1886 checkserv.tinterval = atol(as->parms[3].items->data);
1889 if (checkserv.tinterval < 0) {
1891 ("Warning: The negative -interval is ignored; treated as an inquiry\n");
1892 checkserv.tinterval = 0;
1893 } else if (checkserv.tinterval > 600) {
1895 ("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1896 checkserv.tinterval = 600; /* 10 min max interval */
1899 checkserv.tinterval = -1; /* don't change current interval */
1902 code = pioctl(0, VIOCCKSERV, &blob, 1);
1904 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1905 printf("Must be root to change -interval\n");
1911 memcpy(&temp, space, sizeof(afs_int32));
1912 if (checkserv.tinterval >= 0) {
1913 if (checkserv.tinterval > 0)
1915 ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1916 checkserv.tinterval, temp);
1918 printf("The current down server probe interval is %d secs\n",
1923 printf("All servers are running.\n");
1926 ("These servers unavailable due to network or server problems: ");
1928 memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32));
1931 tp = hostutil_GetNameByINet(temp);
1941 MessagesCmd(struct cmd_syndesc *as, char *arock)
1944 struct ViceIoctl blob;
1947 struct gaginfo gagflags;
1948 struct cmd_item *show;
1950 memset(&gagflags, 0, sizeof(struct gaginfo));
1951 blob.in_size = sizeof(struct gaginfo);
1952 blob.in = (caddr_t) & gagflags;
1953 blob.out_size = MAXSIZE;
1955 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1957 if (show = as->parms[0].items) {
1958 if (!strcasecmp(show->data, "user"))
1959 gagflags.showflags |= GAGUSER;
1960 else if (!strcasecmp(show->data, "console"))
1961 gagflags.showflags |= GAGCONSOLE;
1962 else if (!strcasecmp(show->data, "all"))
1963 gagflags.showflags |= GAGCONSOLE | GAGUSER;
1964 else if (!strcasecmp(show->data, "none"))
1968 "unrecognized flag %s: must be in {user,console,all,none}\n",
1977 code = pioctl(0, VIOC_GAG, &blob, 1);
1987 CheckVolumesCmd(struct cmd_syndesc *as, char *arock)
1990 struct ViceIoctl blob;
1994 code = pioctl(0, VIOCCKBACK, &blob, 1);
2000 printf("All volumeID/name mappings checked.\n");
2005 SetCacheSizeCmd(struct cmd_syndesc *as, char *arock)
2008 struct ViceIoctl blob;
2011 if (!as->parms[0].items && !as->parms[1].items) {
2012 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
2015 if (as->parms[0].items) {
2016 code = util_GetInt32(as->parms[0].items->data, &temp);
2018 fprintf(stderr, "%s: bad integer specified for cache size.\n",
2024 blob.in = (char *)&temp;
2025 blob.in_size = sizeof(afs_int32);
2027 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2029 if (errno == EROFS) {
2031 ("'fs setcache' not allowed on memory cache based cache managers.\n");
2038 printf("New cache size set.\n");
2042 #define MAXGCSIZE 16
2044 GetCacheParmsCmd(struct cmd_syndesc *as, char *arock)
2046 afs_int32 code, filesUsed;
2047 struct ViceIoctl blob;
2048 afs_int32 parms[MAXGCSIZE];
2049 double percentFiles, percentBlocks;
2050 afs_int32 flags = 0;
2052 if (as->parms[0].items){ /* -files */
2054 } else if (as->parms[1].items){ /* -excessive */
2060 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
2062 blob.in = (char *)&flags;
2063 blob.in_size = sizeof(afs_int32);
2064 } else { /* be backward compatible */
2068 blob.out_size = sizeof(parms);
2069 blob.out = (char *)parms;
2070 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2077 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2078 parms[1], parms[0]);
2079 if (parms[1] > parms[0])
2080 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2084 percentBlocks = ((double)parms[1]/parms[0]) * 100;
2085 printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n",
2086 percentBlocks, parms[1], parms[0]);
2088 filesUsed = parms[2] - parms[3];
2089 percentFiles = ((double)filesUsed/parms[2]) * 100;
2090 printf(" %5.0f%% of the cache files (%d of %d files)\n",
2091 percentFiles, filesUsed, parms[2]);
2093 printf(" afs_cacheFiles: %10d\n", parms[2]);
2094 printf(" IFFree: %10d\n", parms[3]);
2095 printf(" IFEverUsed: %10d\n", parms[4]);
2096 printf(" IFDataMod: %10d\n", parms[5]);
2097 printf(" IFDirtyPages: %10d\n", parms[6]);
2098 printf(" IFAnyPages: %10d\n", parms[7]);
2099 printf(" IFDiscarded: %10d\n", parms[8]);
2100 printf(" DCentries: %10d\n", parms[9]);
2101 printf(" 0k- 4K: %10d\n", parms[10]);
2102 printf(" 4k- 16k: %10d\n", parms[11]);
2103 printf(" 16k- 64k: %10d\n", parms[12]);
2104 printf(" 64k- 256k: %10d\n", parms[13]);
2105 printf(" 256k- 1M: %10d\n", parms[14]);
2106 printf(" >=1M: %10d\n", parms[15]);
2109 if (percentBlocks > 90)
2110 printf("[cache size usage over 90%, consider increasing cache size]\n");
2111 if (percentFiles > 90)
2112 printf("[cache file usage over 90%, consider increasing '-files' argument to afsd]\n");
2118 ListCellsCmd(struct cmd_syndesc *as, char *arock)
2124 struct ViceIoctl blob;
2127 resolve = !(as->parms[0].items); /* -numeric */
2131 memcpy(tp, &i, sizeof(afs_int32));
2132 blob.out_size = MAXSIZE;
2133 blob.in_size = sizeof(afs_int32);
2136 code = pioctl(0, VIOCGETCELL, &blob, 1);
2139 break; /* done with the list */
2144 printf("Cell %s on hosts", tp + MAXCELLHOSTS * sizeof(afs_int32));
2145 for (j = 0; j < MAXCELLHOSTS; j++) {
2147 char *name, tbuffer[20];
2149 memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32));
2154 name = hostutil_GetNameByINet(addr);
2157 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2158 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2161 printf(" %s", name);
2169 ListAliasesCmd(struct cmd_syndesc *as, char *arock)
2172 char *tp, *aliasName, *realName;
2173 struct ViceIoctl blob;
2177 memcpy(tp, &i, sizeof(afs_int32));
2178 blob.out_size = MAXSIZE;
2179 blob.in_size = sizeof(afs_int32);
2182 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2185 break; /* done with the list */
2191 tp += strlen(aliasName) + 1;
2193 printf("Alias %s for cell %s\n", aliasName, realName);
2199 CallBackRxConnCmd(struct cmd_syndesc *as, char *arock)
2202 struct ViceIoctl blob;
2203 struct cmd_item *ti;
2205 struct hostent *thp;
2209 ti = as->parms[0].items;
2212 thp = hostutil_GetHostByName(ti->data);
2214 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2217 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2219 hostAddr = 0; /* means don't set host */
2220 setp = 0; /* aren't setting host */
2223 /* now do operation */
2224 blob.in_size = sizeof(afs_int32);
2225 blob.out_size = sizeof(afs_int32);
2226 blob.in = (char *) &hostAddr;
2227 blob.out = (char *) &hostAddr;
2229 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2238 NukeNFSCredsCmd(struct cmd_syndesc *as, char *arock)
2241 struct ViceIoctl blob;
2242 struct cmd_item *ti;
2244 struct hostent *thp;
2246 ti = as->parms[0].items;
2247 thp = hostutil_GetHostByName(ti->data);
2249 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2252 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2254 /* now do operation */
2255 blob.in_size = sizeof(afs_int32);
2256 blob.out_size = sizeof(afs_int32);
2257 blob.in = (char *) &hostAddr;
2258 blob.out = (char *) &hostAddr;
2260 code = pioctl(0, VIOC_NFS_NUKE_CREDS, &blob, 1);
2269 NewCellCmd(struct cmd_syndesc *as, char *arock)
2271 afs_int32 code, linkedstate = 0, size = 0, *lp;
2272 struct ViceIoctl blob;
2273 struct cmd_item *ti;
2274 char *tp, *cellname = 0;
2275 struct hostent *thp;
2276 afs_int32 fsport = 0, vlport = 0;
2277 afs_int32 magic, scount; /* Number of servers to pass in pioctl call */
2280 * With the NEWCELL pioctl call, 3.4 clients take an array of
2281 * MAXHOSTS (13) servers while 3.5 clients take an array of
2282 * MAXCELLHOSTS (8) servers. To determine which we are talking to,
2283 * do a GETCELL pioctl and pass it a magic number. If an array of
2284 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
2285 * If we get back EDOM, there are no cells in the kernel yet,
2286 * and we'll assume a 3.5 client.
2289 lp = (afs_int32 *) tp;
2290 *lp++ = 0; /* first cell entry */
2291 *lp = 0x12345678; /* magic */
2292 blob.out_size = MAXSIZE;
2293 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
2296 code = pioctl(0, VIOCGETCELL, &blob, 1);
2297 if (code < 0 && errno != EDOM) {
2301 if (code < 1 && errno == EDOM) {
2305 cellname = tp + MAXCELLHOSTS * sizeof(afs_int32);
2306 scount = ((cellname[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2309 /* Now setup and do the NEWCELL pioctl call */
2310 memset(space, 0, (scount + 1) * sizeof(afs_int32));
2312 lp = (afs_int32 *) tp;
2314 tp += sizeof(afs_int32);
2315 for (ti = as->parms[1].items; ti; ti = ti->next) {
2316 thp = hostutil_GetHostByName(ti->data);
2319 "%s: Host %s not found in host table, skipping it.\n", pn,
2322 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2323 tp += sizeof(afs_int32);
2326 if (as->parms[2].items) {
2328 * Link the cell, for the purposes of volume location, to the specified
2331 cellname = as->parms[2].items->data;
2334 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2335 if (as->parms[3].items) {
2336 code = util_GetInt32(as->parms[3].items->data, &vlport);
2339 "%s: bad integer specified for the fileserver port.\n",
2344 if (as->parms[4].items) {
2345 code = util_GetInt32(as->parms[4].items->data, &fsport);
2348 "%s: bad integer specified for the vldb server port.\n",
2354 tp = (char *)(space + (scount + 1) * sizeof(afs_int32));
2355 lp = (afs_int32 *) tp;
2359 strcpy(space + ((scount + 4) * sizeof(afs_int32)),
2360 as->parms[0].items->data);
2361 size = ((scount + 4) * sizeof(afs_int32))
2362 + strlen(as->parms[0].items->data)
2363 + 1 /* for null */ ;
2364 tp = (char *)(space + size);
2366 strcpy(tp, cellname);
2367 size += strlen(cellname) + 1;
2369 blob.in_size = size;
2372 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2381 NewAliasCmd(struct cmd_syndesc *as, char *arock)
2384 struct ViceIoctl blob;
2386 char *aliasName, *realName;
2388 /* Now setup and do the NEWCELL pioctl call */
2389 aliasName = as->parms[0].items->data;
2390 realName = as->parms[1].items->data;
2392 strcpy(tp, aliasName);
2393 tp += strlen(aliasName) + 1;
2394 strcpy(tp, realName);
2395 tp += strlen(realName) + 1;
2397 blob.in_size = tp - space;
2401 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2403 if (errno == EEXIST) {
2405 "%s: cell name `%s' in use by an existing cell.\n", pn,
2416 WhichCellCmd(struct cmd_syndesc *as, char *arock)
2419 struct cmd_item *ti;
2421 char cell[MAXCELLCHARS];
2423 SetDotDefault(&as->parms[0].items);
2424 for (ti = as->parms[0].items; ti; ti = ti->next) {
2425 code = GetCell(ti->data, cell);
2427 if (errno == ENOENT)
2428 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
2430 Die(errno, ti->data);
2435 printf("File %s lives in cell '%s'\n", ti->data, cell);
2441 WSCellCmd(struct cmd_syndesc *as, char *arock)
2444 struct ViceIoctl blob;
2448 blob.out_size = MAXSIZE;
2451 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2457 printf("This workstation belongs to cell '%s'\n", space);
2462 static PrimaryCellCmd(as)
2463 struct cmd_syndesc *as;
2465 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2471 MonitorCmd(struct cmd_syndesc *as, char *arock)
2474 struct ViceIoctl blob;
2475 struct cmd_item *ti;
2477 struct hostent *thp;
2481 ti = as->parms[0].items;
2485 if (!strcmp(ti->data, "off"))
2486 hostAddr = 0xffffffff;
2488 thp = hostutil_GetHostByName(ti->data);
2490 if (!strcmp(ti->data, "localhost")) {
2492 "localhost not in host table, assuming 127.0.0.1\n");
2493 hostAddr = htonl(0x7f000001);
2495 fprintf(stderr, "host %s not found in host table.\n",
2500 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2503 hostAddr = 0; /* means don't set host */
2504 setp = 0; /* aren't setting host */
2507 /* now do operation */
2508 blob.in_size = sizeof(afs_int32);
2509 blob.out_size = sizeof(afs_int32);
2510 blob.in = (char *)&hostAddr;
2511 blob.out = (char *)&hostAddr;
2512 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2518 printf("%s: new monitor host set.\n", pn);
2520 /* now decode old address */
2521 if (hostAddr == 0xffffffff) {
2522 printf("Cache monitoring is currently disabled.\n");
2524 tp = hostutil_GetNameByINet(hostAddr);
2525 printf("Using host %s for monitor services.\n", tp);
2532 SysNameCmd(struct cmd_syndesc *as, char *arock)
2535 struct ViceIoctl blob;
2536 struct cmd_item *ti;
2537 char *input = space;
2540 ti = as->parms[0].items;
2543 blob.out_size = MAXSIZE;
2544 blob.in_size = sizeof(afs_int32);
2545 input += sizeof(afs_int32);
2546 for (; ti; ti = ti->next) {
2548 blob.in_size += strlen(ti->data) + 1;
2549 if (blob.in_size > MAXSIZE) {
2550 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2551 setp > 1 ? "s" : "");
2554 strcpy(input, ti->data);
2555 input += strlen(ti->data);
2558 memcpy(space, &setp, sizeof(afs_int32));
2559 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2565 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2569 memcpy(&setp, input, sizeof(afs_int32));
2570 input += sizeof(afs_int32);
2572 fprintf(stderr, "No sysname name value was found\n");
2575 printf("Current sysname%s is", setp > 1 ? " list" : "");
2576 for (; setp > 0; --setp) {
2577 printf(" \'%s\'", input);
2578 input += strlen(input) + 1;
2584 static char *exported_types[] = { "null", "nfs", "" };
2586 ExportAfsCmd(struct cmd_syndesc *as, char *arock)
2589 struct ViceIoctl blob;
2590 struct cmd_item *ti;
2591 int export = 0, type = 0, mode = 0, exp = 0, exportcall, pwsync =
2592 0, smounts = 0, clipags = 0, pagcb = 0;
2594 ti = as->parms[0].items;
2595 if (strcmp(ti->data, "nfs") == 0)
2596 type = 0x71; /* NFS */
2599 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n",
2603 ti = as->parms[1].items;
2605 if (strcmp(ti->data, "on") == 0)
2607 else if (strcmp(ti->data, "off") == 0)
2610 fprintf(stderr, "Illegal argument %s\n", ti->data);
2615 if (ti = as->parms[2].items) { /* -noconvert */
2616 if (strcmp(ti->data, "on") == 0)
2618 else if (strcmp(ti->data, "off") == 0)
2621 fprintf(stderr, "Illegal argument %s\n", ti->data);
2625 if (ti = as->parms[3].items) { /* -uidcheck */
2626 if (strcmp(ti->data, "on") == 0)
2628 else if (strcmp(ti->data, "off") == 0)
2631 fprintf(stderr, "Illegal argument %s\n", ti->data);
2635 if (ti = as->parms[4].items) { /* -submounts */
2636 if (strcmp(ti->data, "on") == 0)
2638 else if (strcmp(ti->data, "off") == 0)
2641 fprintf(stderr, "Illegal argument %s\n", ti->data);
2645 if (ti = as->parms[5].items) { /* -clipags */
2646 if (strcmp(ti->data, "on") == 0)
2648 else if (strcmp(ti->data, "off") == 0)
2651 fprintf(stderr, "Illegal argument %s\n", ti->data);
2655 if (ti = as->parms[6].items) { /* -pagcb */
2656 if (strcmp(ti->data, "on") == 0)
2658 else if (strcmp(ti->data, "off") == 0)
2661 fprintf(stderr, "Illegal argument %s\n", ti->data);
2666 (type << 24) | (pagcb << 10) | (clipags << 8) |
2667 (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2670 blob.in = (char *)&exportcall;
2671 blob.in_size = sizeof(afs_int32);
2672 blob.out = (char *)&exportcall;
2673 blob.out_size = sizeof(afs_int32);
2674 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2676 if (errno == ENODEV) {
2678 "Sorry, the %s-exporter type is currently not supported on this AFS client\n",
2679 exported_types[type]);
2686 if (exportcall & 1) {
2687 printf("'%s' translator is enabled with the following options:\n",
2688 exported_types[type]);
2689 printf("\tRunning in %s mode\n",
2690 (exportcall & 2 ? "strict unix" :
2691 "convert owner mode bits to world/other"));
2692 printf("\tRunning in %s mode\n",
2693 (exportcall & 4 ? "strict 'passwd sync'" :
2694 "no 'passwd sync'"));
2696 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
2697 "Only mounts to /afs allowed"));
2699 (exportcall & 16 ? "Client-assigned PAG's are used" :
2700 "Client-assigned PAG's are not used"));
2703 "Callbacks are made to get creds from new clients" :
2704 "Callbacks are not made to get creds from new clients"));
2706 printf("'%s' translator is disabled\n", exported_types[type]);
2713 GetCellCmd(struct cmd_syndesc *as, char *arock)
2716 struct ViceIoctl blob;
2717 struct afsconf_cell info;
2718 struct cmd_item *ti;
2725 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2726 for (ti = as->parms[0].items; ti; ti = ti->next) {
2728 blob.out_size = sizeof(args);
2729 blob.out = (caddr_t) & args;
2730 code = GetCellName(ti->data, &info);
2735 blob.in_size = 1 + strlen(info.name);
2736 blob.in = info.name;
2737 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2739 if (errno == ENOENT)
2740 fprintf(stderr, "%s: the cell named '%s' does not exist\n",
2743 Die(errno, info.name);
2747 printf("Cell %s status: ", info.name);
2753 printf("no setuid allowed");
2755 printf("setuid allowed");
2757 printf(", using old VLDB");
2764 SetCellCmd(struct cmd_syndesc *as, char *arock)
2767 struct ViceIoctl blob;
2768 struct afsconf_cell info;
2769 struct cmd_item *ti;
2777 /* Check arguments. */
2778 if (as->parms[1].items && as->parms[2].items) {
2779 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2783 /* figure stuff to set */
2787 if (!as->parms[1].items)
2788 args.stat |= 2; /* default to -nosuid */
2790 /* set stat for all listed cells */
2791 for (ti = as->parms[0].items; ti; ti = ti->next) {
2793 code = GetCellName(ti->data, &info);
2798 strcpy(args.cname, info.name);
2799 blob.in_size = sizeof(args);
2800 blob.in = (caddr_t) & args;
2802 blob.out = (caddr_t) 0;
2803 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2805 Die(errno, info.name); /* XXX added cell name to Die() call */
2813 GetCellName(char *cellName, struct afsconf_cell *info)
2815 struct afsconf_dir *tdir;
2818 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2821 "Could not process files in configuration directory (%s).\n",
2822 AFSDIR_CLIENT_ETC_DIRPATH);
2826 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2828 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2829 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
2838 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
2842 code = ugen_ClientInit(noAuthFlag, AFSDIR_CLIENT_ETC_DIRPATH,
2843 info->name, 0, &uclient,
2844 NULL, pn, rxkad_clear,
2845 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
2846 0, 0, USER_SERVICE_ID);
2851 static struct ViceIoctl gblob;
2852 static int debug = 0;
2854 * here follow some routines in suport of the setserverprefs and
2855 * getserverprefs commands. They are:
2856 * SetPrefCmd "top-level" routine
2857 * addServer adds a server to the list of servers to be poked into the
2858 * kernel. Will poke the list into the kernel if it threatens
2860 * pokeServers pokes the existing list of servers and ranks into the kernel
2861 * GetPrefCmd reads the Cache Manager's current list of server ranks
2865 * returns -1 if error message printed,
2867 * errno value if error and no error message printed
2874 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2875 if (code && (errno == EINVAL)) {
2876 struct setspref *ssp;
2877 ssp = (struct setspref *)gblob.in;
2878 if (!(ssp->flags & DBservers)) {
2879 gblob.in = (void *)&(ssp->servers[0]);
2880 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
2881 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
2882 return code ? errno : 0;
2885 "This cache manager does not support VL server preferences.\n");
2889 return code ? errno : 0;
2893 * returns -1 if error message printed,
2895 * errno value if error and no error message printed
2898 addServer(char *name, afs_int32 rank)
2901 struct setspref *ssp;
2903 struct hostent *thostent;
2909 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
2911 #define MAXUSHORT ((unsigned short) ~0)
2915 thostent = hostutil_GetHostByName(name);
2917 fprintf(stderr, "%s: couldn't resolve name.\n", name);
2921 ssp = (struct setspref *)(gblob.in);
2923 for (t = 0; thostent->h_addr_list[t]; t++) {
2924 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
2925 code = pokeServers();
2928 ssp->num_servers = 0;
2931 sp = (struct spref *)(gblob.in + gblob.in_size);
2932 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
2933 sizeof(afs_uint32));
2934 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
2935 gblob.in_size += sizeof(struct spref);
2939 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
2940 name, sp->rank, sp->server.s_addr);
2948 SetPrefCmd(struct cmd_syndesc *as, char *arock)
2952 struct cmd_item *ti;
2955 struct setspref *ssp;
2956 int error = 0; /* -1 means error message printed,
2957 * >0 means errno value for unprinted message */
2959 ssp = (struct setspref *)space;
2961 ssp->num_servers = 0;
2962 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
2965 gblob.out_size = MAXSIZE;
2969 fprintf(stderr, "Permission denied: requires root access.\n");
2973 ti = as->parms[2].items; /* -file */
2976 fprintf(stderr, "opening file %s\n", ti->data);
2977 if (!(infd = fopen(ti->data, "r"))) {
2981 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
2982 code = addServer(name, (unsigned short)rank);
2989 ti = as->parms[3].items; /* -stdin */
2991 while (scanf("%79s%ld", name, &rank) != EOF) {
2992 code = addServer(name, (unsigned short)rank);
2998 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3003 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3007 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3011 code = pokeServers();
3015 printf("now working on vlservers, code=%d\n", code);
3017 ssp = (struct setspref *)space;
3018 ssp->flags = DBservers;
3019 ssp->num_servers = 0;
3020 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3023 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3028 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3032 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3037 if (as->parms[1].items) {
3039 printf("now poking vlservers\n");
3040 code = pokeServers();
3048 return error ? 1 : 0;
3054 GetPrefCmd(struct cmd_syndesc *as, char *arock)
3057 struct cmd_item *ti;
3058 char *name, tbuffer[20];
3059 afs_int32 rank, addr;
3063 struct ViceIoctl blob;
3064 struct sprefrequest *in;
3065 struct sprefinfo *out;
3068 ti = as->parms[0].items; /* -file */
3071 fprintf(stderr, "opening file %s\n", ti->data);
3072 if (!(outfd = freopen(ti->data, "w", stdout))) {
3078 ti = as->parms[1].items; /* -numeric */
3080 ti = as->parms[2].items; /* -vlservers */
3081 vlservers |= (ti ? DBservers : 0);
3082 /* ti = as->parms[3].items; -cell */
3084 in = (struct sprefrequest *)space;
3088 blob.in_size = sizeof(struct sprefrequest);
3089 blob.in = (char *)in;
3091 blob.out_size = MAXSIZE;
3094 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3095 in->flags = vlservers;
3097 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3099 perror("getserverprefs pioctl");
3103 out = (struct sprefinfo *)blob.out;
3105 for (i = 0; i < out->num_servers; i++) {
3107 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3109 addr = ntohl(out->servers[i].server.s_addr);
3110 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3111 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3114 printf("%-50s %5u\n", name, out->servers[i].rank);
3117 in->offset = out->next_offset;
3118 } while (out->next_offset > 0);
3124 StoreBehindCmd(struct cmd_syndesc *as, char *arock)
3127 struct ViceIoctl blob;
3128 struct cmd_item *ti;
3129 struct sbstruct tsb, tsb2;
3135 tsb.sb_thisfile = -1;
3136 ti = as->parms[0].items; /* -kbytes */
3138 if (!as->parms[1].items) {
3139 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3143 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3144 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3145 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3151 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3152 ti = as->parms[2].items; /* -allfiles */
3154 allfiles = strtol(ti->data, &t, 10) * 1024;
3155 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3156 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3162 /* -verbose or -file only or no options */
3163 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3164 || (!as->parms[0].items && !as->parms[1].items
3165 && !as->parms[2].items))
3168 blob.in = (char *)&tsb;
3169 blob.out = (char *)&tsb2;
3170 blob.in_size = blob.out_size = sizeof(struct sbstruct);
3171 memset(&tsb2, 0, sizeof(tsb2));
3173 /* once per -file */
3174 for (ti = as->parms[1].items; ti; ti = ti->next) {
3175 /* Do this solely to see if the file is there */
3176 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3178 Die(errno, ti->data);
3183 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
3185 Die(errno, ti->data);
3190 if (verbose && (blob.out_size == sizeof(tsb2))) {
3191 if (tsb2.sb_thisfile == -1) {
3192 fprintf(stdout, "Will store %s according to default.\n",
3196 "Will store up to %d kbytes of %s asynchronously.\n",
3197 (tsb2.sb_thisfile / 1024), ti->data);
3202 /* If no files - make at least one pioctl call, or
3203 * set the allfiles default if we need to.
3205 if (!as->parms[1].items || (allfiles != -1)) {
3206 tsb.sb_default = allfiles;
3207 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
3209 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3214 /* Having no arguments also reports the default store asynchrony */
3215 if (verbose && (blob.out_size == sizeof(tsb2))) {
3216 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3217 (tsb2.sb_default / 1024));
3225 SetCryptCmd(struct cmd_syndesc *as, char *arock)
3227 afs_int32 code = 0, flag;
3228 struct ViceIoctl blob;
3231 tp = as->parms[0].items->data;
3232 if (strcmp(tp, "on") == 0)
3234 else if (strcmp(tp, "off") == 0)
3237 fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3241 blob.in = (char *)&flag;
3242 blob.in_size = sizeof(flag);
3244 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3252 GetCryptCmd(struct cmd_syndesc *as, char *arock)
3254 afs_int32 code = 0, flag;
3255 struct ViceIoctl blob;
3260 blob.out_size = sizeof(flag);
3263 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3269 memcpy(&flag, tp, sizeof(afs_int32));
3270 printf("Security level is currently ");
3272 printf("crypt (data security).\n");
3279 #ifdef AFS_DISCON_ENV
3280 static char *modenames[] = {
3290 DisconCmd(struct cmd_syndesc *as, char *arock)
3292 struct cmd_item *ti;
3295 afs_int32 mode, code;
3296 struct ViceIoctl blob;
3301 ti = as->parms[0].items;
3303 modename = ti->data;
3304 modelen = strlen(modename);
3305 for (mode = 0; modenames[mode] != NULL; mode++)
3306 if (!strncasecmp(modename, modenames[mode], modelen))
3308 if (modenames[mode] == NULL)
3309 printf("Unknown discon mode \"%s\"\n", modename);
3311 memcpy(space, &mode, sizeof mode);
3313 blob.in_size = sizeof mode;
3317 blob.out_size = sizeof(mode);
3319 code = pioctl(0, VIOC_DISCON, &blob, 1);
3323 memcpy(&mode, space, sizeof mode);
3324 if (mode < sizeof modenames / sizeof (char *))
3325 printf("Discon mode is now \"%s\"\n", modenames[mode]);
3327 printf("Unknown discon mode %d\n", mode);
3334 #include "AFS_component_version_number.c"
3337 main(int argc, char **argv)
3340 struct cmd_syndesc *ts;
3342 #ifdef AFS_AIX32_ENV
3344 * The following signal action for AIX is necessary so that in case of a
3345 * crash (i.e. core is generated) we can include the user's data section
3346 * in the core dump. Unfortunately, by default, only a partial core is
3347 * generated which, in many cases, isn't too useful.
3349 struct sigaction nsa;
3351 sigemptyset(&nsa.sa_mask);
3352 nsa.sa_handler = SIG_DFL;
3353 nsa.sa_flags = SA_FULLDUMP;
3354 sigaction(SIGSEGV, &nsa, NULL);
3357 /* try to find volume location information */
3358 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, 0,
3359 "get client network interface addresses");
3360 cmd_CreateAlias(ts, "gc");
3362 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, 0,
3363 "set client network interface addresses");
3364 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3365 "client network interfaces");
3366 cmd_CreateAlias(ts, "sc");
3368 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0,
3369 "set server ranks");
3370 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3371 "fileserver names and ranks");
3372 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3373 "VL server names and ranks");
3374 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3375 "input from named file");
3376 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3377 cmd_CreateAlias(ts, "sp");
3379 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0,
3380 "get server ranks");
3381 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3382 "output to named file");
3383 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3384 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3385 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3386 cmd_CreateAlias(ts, "gp");
3388 ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list");
3389 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3390 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3391 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3392 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL,
3393 "apply to negative rights");
3394 parm_setacl_id = ts->nParms;
3395 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL,
3396 "initial directory acl (DFS only)");
3397 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL,
3398 "initial file acl (DFS only)");
3399 cmd_CreateAlias(ts, "sa");
3401 ts = cmd_CreateSyntax("listacl", ListACLCmd, 0,
3402 "list access control list");
3403 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3404 parm_listacl_id = ts->nParms;
3405 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3406 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3407 cmd_CreateAlias(ts, "la");
3409 ts = cmd_CreateSyntax("getcalleraccess", GetCallerAccess, 0,
3410 "list callers access");
3411 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3412 cmd_CreateAlias(ts, "gca");
3414 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0,
3415 "clean up access control list");
3416 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3418 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0,
3419 "copy access control list");
3420 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0,
3421 "source directory (or DFS file)");
3422 cmd_AddParm(ts, "-todir", CMD_LIST, 0,
3423 "destination directory (or DFS file)");
3424 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3425 "first clear dest access list");
3426 parm_copyacl_id = ts->nParms;
3427 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3428 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3430 cmd_CreateAlias(ts, "ca");
3432 ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache");
3433 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3434 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, 0,
3435 "flush mount symlink from cache");
3436 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3438 ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status");
3439 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3440 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL,
3441 "disk space quota in 1K units");
3443 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL,
3444 "disk space guaranteed");
3445 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3447 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL,
3449 cmd_CreateAlias(ts, "sv");
3451 ts = cmd_CreateSyntax("messages", MessagesCmd, 0,
3452 "control Cache Manager messages");
3453 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL,
3454 "[user|console|all|none]");
3456 ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display file/volume status");
3457 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3458 cmd_CreateAlias(ts, "lv");
3459 cmd_CreateAlias(ts, "listvol");
3461 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota");
3462 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3463 cmd_CreateAlias(ts, "lq");
3465 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0,
3466 "show server disk space usage");
3467 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3468 cmd_CreateAlias(ts, "df");
3470 ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage");
3471 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3473 ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point");
3474 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3476 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point");
3477 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3478 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3479 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3480 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3481 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3482 "don't check name with VLDB");
3488 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3492 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point");
3493 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3495 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0,
3496 "check local cell's servers");
3497 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3498 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3499 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3500 "just list, don't check");
3501 cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL,
3502 "seconds between probes");
3504 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, 0,
3505 "check volumeID/name mappings");
3506 cmd_CreateAlias(ts, "checkbackups");
3509 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0,
3511 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3512 "size in 1K byte blocks (0 => reset)");
3513 cmd_CreateAlias(ts, "cachesize");
3515 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL,
3516 "reset size back to boot value");
3518 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0,
3519 "get cache usage info");
3520 cmd_AddParm(ts, "-files", CMD_FLAG, CMD_OPTIONAL, "Show cach files used as well");
3521 cmd_AddParm(ts, "-excessive", CMD_FLAG, CMD_OPTIONAL, "excessively verbose cache stats");
3523 ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0,
3524 "list configured cells");
3525 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3527 ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, 0,
3528 "list configured cell aliases");
3530 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota");
3531 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3532 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3534 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3536 cmd_CreateAlias(ts, "sq");
3538 ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell");
3539 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3540 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3541 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL,
3542 "linked cell name");
3544 ts = cmd_CreateSyntax("newalias", NewAliasCmd, 0,
3545 "configure new cell alias");
3546 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
3547 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
3549 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3551 * Turn this on only if you wish to be able to talk to a server which is listening
3552 * on alternative ports. This is not intended for general use and may not be
3553 * supported in the cache manager. It is not a way to run two servers at the
3554 * same host, since the cache manager cannot properly distinguish those two hosts.
3556 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL,
3557 "cell's fileserver port");
3558 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL,
3559 "cell's vldb server port");
3562 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell");
3563 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3565 ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location");
3566 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3568 ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell");
3571 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
3574 /* set cache monitor host address */
3575 ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, (char *)CMD_HIDDEN);
3576 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL,
3577 "host name or 'off'");
3578 cmd_CreateAlias(ts, "mariner");
3580 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status");
3581 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3583 ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status");
3584 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3585 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3586 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL,
3587 "disallow setuid programs");
3589 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0,
3590 "flush all data in volume");
3591 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3593 ts = cmd_CreateSyntax("sysname", SysNameCmd, 0,
3594 "get/set sysname (i.e. @sys) value");
3595 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3597 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0,
3598 "enable/disable translators to AFS");
3599 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3600 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL,
3601 "start/stop translator (on | off)");
3602 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL,
3603 "convert from afs to unix mode (on | off)");
3604 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL,
3605 "run on strict 'uid check' mode (on | off)");
3606 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
3607 "allow nfs mounts to subdirs of /afs/.. (on | off)");
3608 cmd_AddParm(ts, "-clipags", CMD_SINGLE, CMD_OPTIONAL,
3609 "enable use of client-assigned PAG's (on | off)");
3610 cmd_AddParm(ts, "-pagcb", CMD_SINGLE, CMD_OPTIONAL,
3611 "enable callbacks to get creds from new clients (on | off)");
3614 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0,
3615 "store to server after file close");
3616 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL,
3617 "asynchrony for specified names");
3618 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3619 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL,
3620 "new default (KB)");
3621 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3622 cmd_CreateAlias(ts, "sb");
3624 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0,
3625 "set cache manager encryption flag");
3626 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3628 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0,
3629 "get cache manager encryption flag");
3631 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, 0,
3632 "Manage per process RX statistics");
3633 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3634 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3635 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3637 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, 0,
3638 "Manage per peer RX statistics");
3639 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3640 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3641 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3643 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, 0, "configure callback connection address");
3644 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
3646 /* try to find volume location information */
3647 ts = cmd_CreateSyntax("getfid", GetFidCmd, 0,
3648 "get fid for file(s)");
3649 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3651 #ifdef AFS_DISCON_ENV
3652 ts = cmd_CreateSyntax("discon", DisconCmd, 0,
3653 "disconnection mode");
3654 cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_OPTIONAL, "nat | full");
3657 ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, 0, "nuke credentials for NFS client");
3658 cmd_AddParm(ts, "-addr", CMD_SINGLE, 0, "host name or address");
3660 ts = cmd_CreateSyntax("uuid", UuidCmd, 0, "manage the UUID for the cache manager");
3661 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_REQUIRED, "generate a new UUID");
3663 code = cmd_Dispatch(argc, argv);
3671 Die(int errnum, char *filename)
3677 "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3680 fprintf(stderr, "%s: Invalid argument.\n", pn);
3684 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3686 fprintf(stderr, "%s: no such file returned\n", pn);
3690 "%s: You can not change a backup or readonly volume\n", pn);
3696 "%s: You don't have the required access rights on '%s'\n",
3700 "%s: You do not have the required rights to do this operation\n",
3705 fprintf(stderr, "%s:'%s'", pn, filename);
3707 fprintf(stderr, "%s", pn);
3708 fprintf(stderr, ": %s\n", afs_error_message(errnum));
3713 /* get clients interface addresses */
3715 GetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
3718 struct cmd_item *ti;
3720 struct ViceIoctl blob;
3721 struct sprefrequest *in;
3722 struct sprefinfo *out;
3724 in = (struct sprefrequest *)space;
3728 blob.in_size = sizeof(struct sprefrequest);
3729 blob.in = (char *)in;
3731 blob.out_size = MAXSIZE;
3734 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3735 /* returns addr in network byte order */
3736 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3738 perror("getClientInterfaceAddr pioctl");
3744 out = (struct sprefinfo *)blob.out;
3745 for (i = 0; i < out->num_servers; i++) {
3748 addr = ntohl(out->servers[i].server.s_addr);
3749 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3750 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3751 printf("%-50s\n", tbuffer);
3753 in->offset = out->next_offset;
3755 } while (out->next_offset > 0);
3761 SetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
3763 afs_int32 code, addr;
3764 struct cmd_item *ti;
3766 struct ViceIoctl blob;
3767 struct setspref *ssp;
3768 int sizeUsed = 0, i, flag;
3769 afs_int32 existingAddr[1024]; /* existing addresses on this host */
3773 ssp = (struct setspref *)space;
3774 ssp->num_servers = 0;
3777 blob.out_size = MAXSIZE;
3780 fprintf(stderr, "Permission denied: requires root access.\n");
3784 /* extract all existing interface addresses */
3785 existNu = rx_getAllAddr(existingAddr, 1024);
3789 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
3790 for (ti = as->parms[0].items; ti; ti = ti->next) {
3791 if (sizeUsed >= sizeof(space)) {
3792 fprintf(stderr, "No more space\n");
3795 addr = extractAddr(ti->data, 20); /* network order */
3796 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
3797 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
3802 /* see if it is an address that really exists */
3803 for (flag = 0, i = 0; i < existNu; i++)
3804 if (existingAddr[i] == addr) {
3808 if (!flag) { /* this is an nonexistent address */
3809 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
3813 /* copy all specified addr into ioctl buffer */
3814 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
3815 printf("Adding 0x%08x\n", addr);
3817 sizeUsed += sizeof(struct spref);
3819 if (ssp->num_servers < 1) {
3820 fprintf(stderr, "No addresses specified\n");
3823 blob.in_size = sizeUsed - sizeof(struct spref);
3825 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
3835 FlushMountCmd(struct cmd_syndesc *as, char *arock)
3838 struct ViceIoctl blob;
3839 struct cmd_item *ti;
3840 char orig_name[1024]; /*Original name, may be modified */
3841 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
3842 char parent_dir[1024]; /*Parent directory of true name */
3843 char *last_component; /*Last component of true name */
3844 struct stat statbuff; /*Buffer for status info */
3845 int link_chars_read; /*Num chars read in readlink() */
3846 int thru_symlink; /*Did we get to a mount point via a symlink? */
3849 for (ti = as->parms[0].items; ti; ti = ti->next) {
3852 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
3855 if (lstat(orig_name, &statbuff) < 0) {
3856 /* if lstat fails, we should still try the pioctl, since it
3857 * may work (for example, lstat will fail, but pioctl will
3858 * work if the volume of offline (returning ENODEV). */
3859 statbuff.st_mode = S_IFDIR; /* lie like pros */
3863 * The lstat succeeded. If the given file is a symlink, substitute
3864 * the file name with the link name.
3866 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
3869 * Read name of resolved file.
3871 link_chars_read = readlink(orig_name, true_name, 1024);
3872 if (link_chars_read <= 0) {
3874 "%s: Can't read target name for '%s' symbolic link!\n",
3881 * Add a trailing null to what was read, bump the length.
3883 true_name[link_chars_read++] = 0;
3886 * If the symlink is an absolute pathname, we're fine. Otherwise, we
3887 * have to create a full pathname using the original name and the
3888 * relative symlink name. Find the rightmost slash in the original
3889 * name (we know there is one) and splice in the symlink value.
3891 if (true_name[0] != '/') {
3892 last_component = (char *)strrchr(orig_name, '/');
3893 strcpy(++last_component, true_name);
3894 strcpy(true_name, orig_name);
3897 strcpy(true_name, orig_name);
3900 * Find rightmost slash, if any.
3902 last_component = (char *)strrchr(true_name, '/');
3903 if (last_component) {
3905 * Found it. Designate everything before it as the parent directory,
3906 * everything after it as the final component.
3908 strncpy(parent_dir, true_name, last_component - true_name);
3909 parent_dir[last_component - true_name] = 0;
3910 last_component++; /*Skip the slash */
3913 * No slash appears in the given file name. Set parent_dir to the current
3914 * directory, and the last component as the given name.
3916 strcpy(parent_dir, ".");
3917 last_component = true_name;
3920 if (strcmp(last_component, ".") == 0
3921 || strcmp(last_component, "..") == 0) {
3923 "%s: you may not use '.' or '..' as the last component\n",
3925 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
3931 blob.in = last_component;
3932 blob.in_size = strlen(last_component) + 1;
3934 memset(space, 0, MAXSIZE);
3936 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
3939 if (errno == EINVAL) {
3940 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
3942 Die(errno, (ti->data ? ti->data : parent_dir));
3951 RxStatProcCmd(struct cmd_syndesc *as, char *arock)
3954 afs_int32 flags = 0;
3955 struct ViceIoctl blob;
3956 struct cmd_item *ti;
3958 if (as->parms[0].items) { /* -enable */
3959 flags |= AFSCALL_RXSTATS_ENABLE;
3961 if (as->parms[1].items) { /* -disable */
3962 flags |= AFSCALL_RXSTATS_DISABLE;
3964 if (as->parms[2].items) { /* -clear */
3965 flags |= AFSCALL_RXSTATS_CLEAR;
3968 fprintf(stderr, "You must specify at least one argument\n");
3972 blob.in = (char *)&flags;
3973 blob.in_size = sizeof(afs_int32);
3976 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
3986 RxStatPeerCmd(struct cmd_syndesc *as, char *arock)
3989 afs_int32 flags = 0;
3990 struct ViceIoctl blob;
3991 struct cmd_item *ti;
3993 if (as->parms[0].items) { /* -enable */
3994 flags |= AFSCALL_RXSTATS_ENABLE;
3996 if (as->parms[1].items) { /* -disable */
3997 flags |= AFSCALL_RXSTATS_DISABLE;
3999 if (as->parms[2].items) { /* -clear */
4000 flags |= AFSCALL_RXSTATS_CLEAR;
4003 fprintf(stderr, "You must specify at least one argument\n");
4007 blob.in = (char *)&flags;
4008 blob.in_size = sizeof(afs_int32);
4011 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4021 GetFidCmd(struct cmd_syndesc *as, char *arock)
4023 struct ViceIoctl blob;
4024 struct cmd_item *ti;
4025 for (ti = as->parms[0].items; ti; ti = ti->next) {
4026 struct VenusFid vfid;
4028 blob.out_size = sizeof(struct VenusFid);
4029 blob.out = (char *) &vfid;
4032 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
4033 printf("File %s (%u.%u.%u) contained in volume %u\n",
4034 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,