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>
50 #include <afs/ptclient.h>
55 #define MAXCELLHOSTS 8
58 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
59 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
61 static char space[MAXSIZE];
62 static char tspace[1024];
63 static struct ubik_client *uclient;
65 static int GetClientAddrsCmd(), SetClientAddrsCmd(), FlushMountCmd();
66 static int RxStatProcCmd(), RxStatPeerCmd(), GetFidCmd(), UuidCmd();
68 extern char *hostutil_GetNameByINet();
69 extern struct hostent *hostutil_GetHostByName();
72 extern struct cmd_syndesc *cmd_CreateSyntax();
73 static char pn[] = "fs";
74 static int rxInitDone = 0;
76 static void ZapList();
77 static int PruneList();
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)
285 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
289 struct ViceIoctl blob;
293 blob.out_size = MAXSIZE;
296 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
298 if ((errno == EINVAL) || (errno == ENOENT))
304 /* return a static pointer to a buffer */
309 strcpy(tspace, apath);
310 tp = strrchr(tspace, '/');
318 enum rtype { add, destroy, deny };
321 Convert(char *arights, int dfs, enum rtype *rtypep)
327 *rtypep = add; /* add rights, by default */
330 if (!strcmp(arights, "null")) {
334 if (!strcmp(arights, "read"))
335 return DFS_READ | DFS_EXECUTE;
336 if (!strcmp(arights, "write"))
337 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
339 if (!strcmp(arights, "all"))
340 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
341 DFS_WRITE | DFS_CONTROL;
343 if (!strcmp(arights, "read"))
344 return PRSFS_READ | PRSFS_LOOKUP;
345 if (!strcmp(arights, "write"))
346 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
347 PRSFS_WRITE | PRSFS_LOCK;
348 if (!strcmp(arights, "mail"))
349 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
350 if (!strcmp(arights, "all"))
351 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
352 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
354 if (!strcmp(arights, "none")) {
355 *rtypep = destroy; /* Remove entire entry */
358 len = strlen(arights);
360 for (i = 0; i < len; i++) {
394 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
402 mode |= PRSFS_LOOKUP;
404 mode |= PRSFS_INSERT;
406 mode |= PRSFS_DELETE;
412 mode |= PRSFS_ADMINISTER;
430 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
439 static struct AclEntry *
440 FindList(struct AclEntry *alist, char *aname)
443 if (!foldcmp(alist->name, aname))
450 /* if no parm specified in a particular slot, set parm to be "." instead */
452 SetDotDefault(struct cmd_item **aitemp)
456 return; /* already has value */
457 /* otherwise, allocate an item representing "." */
458 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
460 ti->next = (struct cmd_item *)0;
461 ti->data = (char *)malloc(2);
463 strcpy(ti->data, ".");
468 ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
470 struct AclEntry *tlist;
471 tlist = (plus ? al->pluslist : al->minuslist);
472 tlist = FindList(tlist, aname);
474 /* Found the item already in the list. */
475 tlist->rights = arights;
477 al->nplus -= PruneList(&al->pluslist, al->dfs);
479 al->nminus -= PruneList(&al->minuslist, al->dfs);
482 /* Otherwise we make a new item and plug in the new data. */
483 tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry));
485 strcpy(tlist->name, aname);
486 tlist->rights = arights;
488 tlist->next = al->pluslist;
489 al->pluslist = tlist;
491 if (arights == 0 || arights == -1)
492 al->nplus -= PruneList(&al->pluslist, al->dfs);
494 tlist->next = al->minuslist;
495 al->minuslist = tlist;
498 al->nminus -= PruneList(&al->minuslist, al->dfs);
503 ZapList(struct AclEntry *alist)
505 struct AclEntry *tp, *np;
506 for (tp = alist; tp; tp = np) {
513 PruneList(struct AclEntry **ae, int dfs)
515 struct AclEntry **lp;
516 struct AclEntry *te, *ne;
520 for (te = *ae; te; te = ne) {
521 if ((!dfs && te->rights == 0) || te->rights == -1) {
537 while (*astr != '\n')
544 * Create an empty acl, taking into account whether the acl pointed
545 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
546 * can recover from problems caused by bogus ACL's (in that case, always
547 * assume that the acl is AFS: for DFS, the user can always resort to
548 * acl_edit, but for AFS there may be no other way out).
556 tp = (struct Acl *)malloc(sizeof(struct Acl));
558 tp->nplus = tp->nminus = 0;
559 tp->pluslist = tp->minuslist = 0;
561 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
568 int nplus, nminus, i, trights;
570 struct AclEntry *first, *last, *tl;
573 ta = (struct Acl *)malloc(sizeof(struct Acl));
576 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
577 astr = SkipLine(astr);
578 sscanf(astr, "%d", &ta->nminus);
579 astr = SkipLine(astr);
586 for (i = 0; i < nplus; i++) {
587 sscanf(astr, "%100s %d", tname, &trights);
588 astr = SkipLine(astr);
589 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
593 strcpy(tl->name, tname);
594 tl->rights = trights;
600 ta->pluslist = first;
604 for (i = 0; i < nminus; i++) {
605 sscanf(astr, "%100s %d", tname, &trights);
606 astr = SkipLine(astr);
607 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
611 strcpy(tl->name, tname);
612 tl->rights = trights;
618 ta->minuslist = first;
624 PrintStatus(VolumeStatus * status, char *name, char *offmsg)
626 printf("Volume status for vid = %u named %s\n", status->Vid, name);
628 printf("Current offline message is %s\n", offmsg);
629 printf("Current disk quota is ");
630 if (status->MaxQuota != 0)
631 printf("%d\n", status->MaxQuota);
633 printf("unlimited\n");
634 printf("Current blocks used are %d\n", status->BlocksInUse);
635 printf("The partition has %d blocks available out of %d\n\n",
636 status->PartBlocksAvail, status->PartMaxBlocks);
641 QuickPrintStatus(VolumeStatus * status, char *name)
643 double QuotaUsed = 0.0;
644 double PartUsed = 0.0;
646 printf("%-25.25s", name);
648 if (status->MaxQuota != 0) {
649 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
651 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
653 printf(" no limit%10d", status->BlocksInUse);
655 if (QuotaUsed > 90.0) {
656 printf("%5.0f%%<<", QuotaUsed);
659 printf("%5.0f%% ", QuotaUsed);
662 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
664 if (PartUsed > 97.0) {
665 printf("%9.0f%%<<", PartUsed);
668 printf("%9.0f%% ", PartUsed);
670 printf(" <<WARNING\n");
677 QuickPrintSpace(VolumeStatus * status, char *name)
679 double PartUsed = 0.0;
681 printf("%-25.25s", name);
683 printf("%10d%10d%10d", status->PartMaxBlocks,
684 status->PartMaxBlocks - status->PartBlocksAvail,
685 status->PartBlocksAvail);
689 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
691 if (PartUsed > 90.0) {
692 printf(" %4.0f%%<<", PartUsed);
695 printf(" %4.0f%% ", PartUsed);
697 printf(" <<WARNING\n");
704 AclToString(struct Acl *acl)
706 static char mydata[MAXSIZE];
707 char tstring[MAXSIZE];
712 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
715 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
716 for (tp = acl->pluslist; tp; tp = tp->next) {
717 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
718 strcat(mydata, tstring);
720 for (tp = acl->minuslist; tp; tp = tp->next) {
721 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
722 strcat(mydata, tstring);
728 SetACLCmd(struct cmd_syndesc *as, char *arock)
731 struct ViceIoctl blob;
733 struct cmd_item *ti, *ui;
737 int idf = getidf(as, parm_setacl_id);
740 if (as->parms[2].items)
744 plusp = !(as->parms[3].items);
745 for (ti = as->parms[0].items; ti; ti = ti->next) {
746 blob.out_size = MAXSIZE;
748 blob.in = blob.out = space;
749 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
751 Die(errno, ti->data);
758 ta = ParseAcl(space);
759 if (!plusp && ta->dfs) {
761 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
763 "(you may specify \"null\" to revoke all rights, however)\n");
771 ta = EmptyAcl(space);
773 ta = ParseAcl(space);
774 CleanAcl(ta, ti->data);
775 for (ui = as->parms[1].items; ui; ui = ui->next->next) {
779 "%s: Missing second half of user/access pair.\n", pn);
783 rights = Convert(ui->next->data, ta->dfs, &rtype);
784 if (rtype == destroy && !ta->dfs) {
785 struct AclEntry *tlist;
787 tlist = (plusp ? ta->pluslist : ta->minuslist);
788 if (!FindList(tlist, ui->data))
791 if (rtype == deny && !ta->dfs)
793 if (rtype == destroy && ta->dfs)
795 ChangeList(ta, plusp, ui->data, rights);
797 blob.in = AclToString(ta);
799 blob.in_size = 1 + strlen(blob.in);
800 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
802 if (errno == EINVAL) {
804 static char *fsenv = 0;
806 fsenv = (char *)getenv("FS_EXPERT");
809 "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n",
813 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
814 "\nPossible reasons for this include:\n\n",
815 " -You may have specified an inappropriate combination of rights.\n",
816 " For example, some DFS-supported filesystems may not allow you to\n",
817 " drop the \"c\" right from \"user_obj\".\n\n",
818 " -A mask_obj may be required (it is likely required by the underlying\n",
819 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
820 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
821 " does not automatically create or update the mask_obj. Try setting\n",
822 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
823 " users or groups. You can do this with a single command, such as\n",
824 " \"fs sa mask_obj all user:somename read\"\n\n",
825 " -A specified user or group may not exist.\n\n",
826 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
827 " This is probably not allowed by the underlying file system.\n\n",
828 " -If you add a user or group to a DFS ACL, remember that it must be\n",
829 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
830 " may be local requirements on the format of the user or group name.\n",
831 " Check with your cell administrator.\n\n",
832 " -Or numerous other possibilities. It would be great if we could be more\n",
833 " precise about the actual problem, but for various reasons, this is\n",
834 " impractical via this interface. If you can't figure it out, you\n",
835 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
836 " whatever is provided). You may get better results. Good luck!\n\n",
837 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
841 "%s: Invalid argument, possible reasons include:\n",
843 fprintf(stderr, "\t-File not in AFS\n");
845 "\t-Too many users on access control list\n");
847 "\t-Tried to add non-existent user to access control list\n");
850 Die(errno, ti->data);
862 CopyACLCmd(struct cmd_syndesc *as, char *arock)
865 struct ViceIoctl blob;
866 struct Acl *fa, *ta = 0;
868 struct cmd_item *ti, *ui;
872 int idf = getidf(as, parm_copyacl_id);
875 if (as->parms[2].items)
879 blob.out_size = MAXSIZE;
881 blob.in = blob.out = space;
882 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
884 Die(errno, as->parms[0].items->data);
887 fa = ParseAcl(space);
888 CleanAcl(fa, as->parms[0].items->data);
889 for (ti = as->parms[1].items; ti; ti = ti->next) {
890 blob.out_size = MAXSIZE;
892 blob.in = blob.out = space;
893 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
895 Die(errno, ti->data);
903 ta = EmptyAcl(space);
905 ta = ParseAcl(space);
906 CleanAcl(ta, ti->data);
907 if (ta->dfs != fa->dfs) {
909 "%s: incompatible file system types: acl not copied to %s; aborted\n",
915 if (!clear && strcmp(ta->cell, fa->cell) != 0) {
917 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
922 strcpy(ta->cell, fa->cell);
924 for (tp = fa->pluslist; tp; tp = tp->next)
925 ChangeList(ta, 1, tp->name, tp->rights);
926 for (tp = fa->minuslist; tp; tp = tp->next)
927 ChangeList(ta, 0, tp->name, tp->rights);
928 blob.in = AclToString(ta);
930 blob.in_size = 1 + strlen(blob.in);
931 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
933 if (errno == EINVAL) {
935 "%s: Invalid argument, possible reasons include:\n",
937 fprintf(stderr, "\t-File not in AFS\n");
939 Die(errno, ti->data);
950 /* pioctl() call to get the cellname of a pathname */
952 GetCell(char *fname, char *cellname)
955 struct ViceIoctl blob;
958 blob.out_size = MAXCELLCHARS;
961 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
962 return code ? errno : 0;
965 /* Check if a username is valid: If it contains only digits (or a
966 * negative sign), then it might be bad. We then query the ptserver
970 BadName(char *aname, char *fname)
972 afs_int32 tc, code, id;
974 char cell[MAXCELLCHARS];
976 for (nm = aname; tc = *nm; nm++) {
977 /* all must be '-' or digit to be bad */
978 if (tc != '-' && (tc < '0' || tc > '9'))
982 /* Go to the PRDB and see if this all number username is valid */
983 code = GetCell(fname, cell);
987 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
988 code = pr_SNameToId(aname, &id);
991 /* 1=>Not-valid; 0=>Valid */
992 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
996 /* clean up an access control list of its bad entries; return 1 if we made
997 any changes to the list, and 0 otherwise */
999 CleanAcl(struct Acl *aa, char *fname)
1001 struct AclEntry *te, **le, *ne;
1004 /* Don't correct DFS ACL's for now */
1008 /* prune out bad entries */
1009 changes = 0; /* count deleted entries */
1011 for (te = aa->pluslist; te; te = ne) {
1013 if (BadName(te->name, fname)) {
1023 le = &aa->minuslist;
1024 for (te = aa->minuslist; te; te = ne) {
1026 if (BadName(te->name, fname)) {
1040 /* clean up an acl to not have bogus entries */
1042 CleanACLCmd(struct cmd_syndesc *as, char *arock)
1046 struct ViceIoctl blob;
1048 struct cmd_item *ti;
1049 struct AclEntry *te;
1052 SetDotDefault(&as->parms[0].items);
1053 for (ti = as->parms[0].items; ti; ti = ti->next) {
1054 blob.out_size = MAXSIZE;
1057 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1059 Die(errno, ti->data);
1066 ta = ParseAcl(space);
1069 "%s: cleanacl is not supported for DFS access lists.\n",
1075 changes = CleanAcl(ta, ti->data);
1078 /* now set the acl */
1079 blob.in = AclToString(ta);
1080 blob.in_size = strlen(blob.in) + 1;
1082 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1084 if (errno == EINVAL) {
1086 "%s: Invalid argument, possible reasons include\n",
1088 fprintf(stderr, "%s: File not in vice or\n", pn);
1090 "%s: Too many users on access control list or\n",
1093 Die(errno, ti->data);
1099 /* now list the updated acl */
1100 printf("Access list for %s is now\n", ti->data);
1101 if (ta->nplus > 0) {
1103 printf("Normal rights:\n");
1104 for (te = ta->pluslist; te; te = te->next) {
1105 printf(" %s ", te->name);
1106 PRights(te->rights, ta->dfs);
1110 if (ta->nminus > 0) {
1111 printf("Negative rights:\n");
1112 for (te = ta->minuslist; te; te = te->next) {
1113 printf(" %s ", te->name);
1114 PRights(te->rights, ta->dfs);
1121 printf("Access list for %s is fine.\n", ti->data);
1129 ListACLCmd(struct cmd_syndesc *as, char *arock)
1133 struct ViceIoctl blob;
1134 struct AclEntry *te;
1135 struct cmd_item *ti;
1136 int idf = getidf(as, parm_listacl_id);
1139 SetDotDefault(&as->parms[0].items);
1140 for (ti = as->parms[0].items; ti; ti = ti->next) {
1141 blob.out_size = MAXSIZE;
1143 blob.in = blob.out = space;
1144 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1146 Die(errno, ti->data);
1150 ta = ParseAcl(space);
1153 printf("Access list for %s is\n", ti->data);
1156 printf("DFS access list for %s is\n", ti->data);
1159 printf("DFS initial directory access list of %s is\n", ti->data);
1162 printf("DFS initial file access list of %s is\n", ti->data);
1166 printf(" Default cell = %s\n", ta->cell);
1168 if (ta->nplus > 0) {
1170 printf("Normal rights:\n");
1171 for (te = ta->pluslist; te; te = te->next) {
1172 printf(" %s ", te->name);
1173 PRights(te->rights, ta->dfs);
1177 if (ta->nminus > 0) {
1178 printf("Negative rights:\n");
1179 for (te = ta->minuslist; te; te = te->next) {
1180 printf(" %s ", te->name);
1181 PRights(te->rights, ta->dfs);
1193 GetCallerAccess(struct cmd_syndesc *as, char *arock)
1195 struct cmd_item *ti;
1198 SetDotDefault(&as->parms[0].items);
1199 for (ti = as->parms[0].items; ti; ti = ti->next) {
1201 struct ViceIoctl blob;
1202 struct vcxstat2 stat;
1203 blob.out_size = sizeof(struct vcxstat2);
1205 blob.out = (void *)&stat;
1206 code = pioctl(ti->data, VIOC_GETVCXSTATUS2, &blob, 1);
1208 Die(errno, ti->data);
1212 printf("Callers access to %s is ", ti->data);
1213 PRights(stat.callerAccess, 0);
1220 FlushVolumeCmd(struct cmd_syndesc *as, char *arock)
1223 struct ViceIoctl blob;
1224 struct cmd_item *ti;
1227 SetDotDefault(&as->parms[0].items);
1228 for (ti = as->parms[0].items; ti; ti = ti->next) {
1229 blob.in_size = blob.out_size = 0;
1230 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1232 fprintf(stderr, "Error flushing volume ");
1242 * The Windows version of UuidCmd displays the UUID.
1243 * When the UNIX version is updated to do the same
1244 * be sure to replace the CMD_REQUIRED flag with
1245 * CMD_OPTIONAL in the cmd_AddParam(-generate) call
1248 UuidCmd(struct cmd_syndesc *as, char *arock)
1251 struct ViceIoctl blob;
1256 if (as->parms[0].items) {
1258 fprintf (stderr, "Permission denied: requires root access.\n");
1262 /* generate new UUID */
1263 code = pioctl(0, VIOC_NEWUUID, &blob, 1);
1270 printf("New uuid generated.\n");
1272 /* This will never execute */
1273 printf("Please add the '-generate' option to generate a new UUID.\n");
1279 FlushCmd(struct cmd_syndesc *as, char *arock)
1282 struct ViceIoctl blob;
1283 struct cmd_item *ti;
1286 for (ti = as->parms[0].items; ti; ti = ti->next) {
1287 blob.in_size = blob.out_size = 0;
1288 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1290 if (errno == EMFILE) {
1291 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1294 fprintf(stderr, "%s: Error flushing file ", pn);
1304 /* all this command does is repackage its args and call SetVolCmd */
1306 SetQuotaCmd(struct cmd_syndesc *as, char *arock)
1308 struct cmd_syndesc ts;
1310 /* copy useful stuff from our command slot; we may later have to reorder */
1311 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1312 return SetVolCmd(&ts);
1316 SetVolCmd(struct cmd_syndesc *as, char *arock)
1319 struct ViceIoctl blob;
1320 struct cmd_item *ti;
1321 struct VolumeStatus *status;
1322 char *offmsg, *input;
1325 SetDotDefault(&as->parms[0].items);
1326 for (ti = as->parms[0].items; ti; ti = ti->next) {
1328 blob.out_size = MAXSIZE;
1329 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1332 status = (VolumeStatus *) space;
1333 status->MinQuota = status->MaxQuota = -1;
1335 if (as->parms[1].items) {
1336 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1338 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1343 if (as->parms[2].items)
1344 offmsg = as->parms[2].items->data;
1345 input = (char *)status + sizeof(*status);
1346 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1348 if (strlen(offmsg) >= VMSGSIZE) {
1350 "%s: message must be shorter than %d characters\n",
1355 strcpy(input, offmsg);
1356 blob.in_size += strlen(offmsg);
1357 input += strlen(offmsg) + 1;
1360 *(input++) = '\0'; /* Pad for old style volume "motd" */
1361 code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1);
1363 Die(errno, ti->data);
1371 * Why is VenusFid declared in the kernel-only section of afs.h,
1372 * if it's the exported interface of the cache manager?
1380 ExamineCmd(struct cmd_syndesc *as, char *arock)
1383 struct ViceIoctl blob;
1384 struct cmd_item *ti;
1385 struct VolumeStatus *status;
1386 char *name, *offmsg;
1389 SetDotDefault(&as->parms[0].items);
1390 for (ti = as->parms[0].items; ti; ti = ti->next) {
1391 struct VenusFid vfid;
1394 blob.out_size = MAXSIZE;
1397 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1399 Die(errno, ti->data);
1403 status = (VolumeStatus *) space;
1404 name = (char *)status + sizeof(*status);
1405 offmsg = name + strlen(name) + 1;
1407 blob.out_size = sizeof(struct VenusFid);
1408 blob.out = (char *) &vfid;
1409 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1410 printf("File %s (%u.%u.%u) contained in volume %u\n",
1411 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1415 PrintStatus(status, name, offmsg);
1421 ListQuotaCmd(struct cmd_syndesc *as, char *arock)
1424 struct ViceIoctl blob;
1425 struct cmd_item *ti;
1426 struct VolumeStatus *status;
1430 printf("%-25s%-10s%-10s%-7s%-11s\n", "Volume Name", " Quota",
1431 " Used", " %Used", " Partition");
1432 SetDotDefault(&as->parms[0].items);
1433 for (ti = as->parms[0].items; ti; ti = ti->next) {
1435 blob.out_size = MAXSIZE;
1438 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1440 Die(errno, ti->data);
1444 status = (VolumeStatus *) space;
1445 name = (char *)status + sizeof(*status);
1446 QuickPrintStatus(status, name);
1452 WhereIsCmd(struct cmd_syndesc *as, char *arock)
1455 struct ViceIoctl blob;
1456 struct cmd_item *ti;
1462 SetDotDefault(&as->parms[0].items);
1463 for (ti = as->parms[0].items; ti; ti = ti->next) {
1465 blob.out_size = MAXSIZE;
1468 memset(space, 0, sizeof(space));
1469 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1471 Die(errno, ti->data);
1475 hosts = (afs_int32 *) space;
1476 printf("File %s is on host%s ", ti->data,
1477 (hosts[0] && !hosts[1]) ? "" : "s");
1478 for (j = 0; j < MAXHOSTS; j++) {
1481 tp = hostutil_GetNameByINet(hosts[j]);
1491 DiskFreeCmd(struct cmd_syndesc *as, char *arock)
1494 struct ViceIoctl blob;
1495 struct cmd_item *ti;
1497 struct VolumeStatus *status;
1500 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1501 " used", " avail", " %used");
1502 SetDotDefault(&as->parms[0].items);
1503 for (ti = as->parms[0].items; ti; ti = ti->next) {
1505 blob.out_size = MAXSIZE;
1508 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1510 Die(errno, ti->data);
1514 status = (VolumeStatus *) space;
1515 name = (char *)status + sizeof(*status);
1516 QuickPrintSpace(status, name);
1522 QuotaCmd(struct cmd_syndesc *as, char *arock)
1525 struct ViceIoctl blob;
1526 struct cmd_item *ti;
1528 struct VolumeStatus *status;
1531 SetDotDefault(&as->parms[0].items);
1532 for (ti = as->parms[0].items; ti; ti = ti->next) {
1534 blob.out_size = MAXSIZE;
1537 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1539 Die(errno, ti->data);
1543 status = (VolumeStatus *) space;
1544 if (status->MaxQuota)
1546 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
1549 printf("%2.0f%% of quota used.\n", quotaPct);
1555 ListMountCmd(struct cmd_syndesc *as, char *arock)
1558 struct ViceIoctl blob;
1559 struct cmd_item *ti;
1560 char orig_name[1024]; /*Original name, may be modified */
1561 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
1562 char parent_dir[1024]; /*Parent directory of true name */
1563 char *last_component; /*Last component of true name */
1564 struct stat statbuff; /*Buffer for status info */
1565 int link_chars_read; /*Num chars read in readlink() */
1566 int thru_symlink; /*Did we get to a mount point via a symlink? */
1569 for (ti = as->parms[0].items; ti; ti = ti->next) {
1572 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
1575 if (lstat(orig_name, &statbuff) < 0) {
1576 /* if lstat fails, we should still try the pioctl, since it
1577 * may work (for example, lstat will fail, but pioctl will
1578 * work if the volume of offline (returning ENODEV). */
1579 statbuff.st_mode = S_IFDIR; /* lie like pros */
1583 * The lstat succeeded. If the given file is a symlink, substitute
1584 * the file name with the link name.
1586 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1589 * Read name of resolved file.
1591 link_chars_read = readlink(orig_name, true_name, 1024);
1592 if (link_chars_read <= 0) {
1594 "%s: Can't read target name for '%s' symbolic link!\n",
1601 * Add a trailing null to what was read, bump the length.
1603 true_name[link_chars_read++] = 0;
1606 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1607 * have to create a full pathname using the original name and the
1608 * relative symlink name. Find the rightmost slash in the original
1609 * name (we know there is one) and splice in the symlink value.
1611 if (true_name[0] != '/') {
1612 last_component = (char *)strrchr(orig_name, '/');
1613 strcpy(++last_component, true_name);
1614 strcpy(true_name, orig_name);
1617 strcpy(true_name, orig_name);
1620 * Find rightmost slash, if any.
1622 last_component = (char *)strrchr(true_name, '/');
1623 if (last_component) {
1625 * Found it. Designate everything before it as the parent directory,
1626 * everything after it as the final component.
1628 strncpy(parent_dir, true_name, last_component - true_name);
1629 parent_dir[last_component - true_name] = 0;
1630 last_component++; /*Skip the slash */
1633 * No slash appears in the given file name. Set parent_dir to the current
1634 * directory, and the last component as the given name.
1636 strcpy(parent_dir, ".");
1637 last_component = true_name;
1640 if (strcmp(last_component, ".") == 0
1641 || strcmp(last_component, "..") == 0) {
1643 "%s: you may not use '.' or '..' as the last component\n",
1645 fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n",
1651 blob.in = last_component;
1652 blob.in_size = strlen(last_component) + 1;
1653 blob.out_size = MAXSIZE;
1655 memset(space, 0, MAXSIZE);
1657 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1660 printf("'%s' is a %smount point for volume '%s'\n", ti->data,
1661 (thru_symlink ? "symbolic link, leading to a " : ""),
1664 if (errno == EINVAL) {
1665 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
1667 Die(errno, (ti->data ? ti->data : parent_dir));
1676 MakeMountCmd(struct cmd_syndesc *as, char *arock)
1679 char *cellName, *volName, *tmpName;
1680 struct afsconf_cell info;
1681 struct vldbentry vldbEntry;
1682 struct ViceIoctl blob;
1688 if (as->parms[5].items && !as->parms[2].items) {
1689 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1694 if (as->parms[2].items) /* cell name specified */
1695 cellName = as->parms[2].items->data;
1698 volName = as->parms[1].items->data;
1700 if (strlen(volName) >= 64) {
1702 "%s: volume name too long (length must be < 64 characters)\n",
1707 /* Check for a cellname in the volume specification, and complain
1708 * if it doesn't match what was specified with -cell */
1709 if (tmpName = strchr(volName, ':')) {
1712 if (strcasecmp(cellName, volName)) {
1713 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1718 volName = ++tmpName;
1721 if (!InAFS(Parent(as->parms[0].items->data))) {
1723 "%s: mount points must be created within the AFS file system\n",
1730 blob.out_size = MAXSIZE;
1733 pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME,
1737 code = GetCellName(cellName ? cellName : space, &info);
1741 if (!(as->parms[4].items)) {
1742 /* not fast, check which cell the mountpoint is being created in */
1743 /* not fast, check name with VLDB */
1744 code = VLDBInit(1, &info);
1746 /* make the check. Don't complain if there are problems with init */
1748 ubik_VL_GetEntryByNameO(uclient, 0, volName,
1750 if (code == VL_NOENT) {
1752 "%s: warning, volume %s does not exist in cell %s.\n",
1753 pn, volName, cellName ? cellName : space);
1758 if (as->parms[3].items) /* if -rw specified */
1763 /* cellular mount point, prepend cell prefix */
1764 strcat(space, info.name);
1767 strcat(space, volName); /* append volume name */
1768 strcat(space, "."); /* stupid convention; these end with a period */
1769 code = symlink(space, as->parms[0].items->data);
1771 Die(errno, as->parms[0].items->data);
1778 * Delete AFS mount points. Variables are used as follows:
1779 * tbuffer: Set to point to the null-terminated directory name of the mount point
1780 * (or ``.'' if none is provided)
1781 * tp: Set to point to the actual name of the mount point to nuke.
1784 RemoveMountCmd(struct cmd_syndesc *as, char *arock)
1787 struct ViceIoctl blob;
1788 struct cmd_item *ti;
1790 char lsbuffer[1024];
1794 for (ti = as->parms[0].items; ti; ti = ti->next) {
1796 tp = (char *)strrchr(ti->data, '/');
1798 strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */
1800 tp++; /* skip the slash */
1802 strcpy(tbuffer, ".");
1806 blob.in_size = strlen(tp) + 1;
1807 blob.out = lsbuffer;
1808 blob.out_size = sizeof(lsbuffer);
1809 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1811 if (errno == EINVAL) {
1812 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
1815 Die(errno, ti->data);
1818 continue; /* don't bother trying */
1822 blob.in_size = strlen(tp) + 1;
1823 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1825 Die(errno, ti->data);
1836 CheckServersCmd(struct cmd_syndesc *as, char *arock)
1839 struct ViceIoctl blob;
1845 struct afsconf_cell info;
1846 struct chservinfo checkserv;
1848 memset(&checkserv, 0, sizeof(struct chservinfo));
1849 blob.in_size = sizeof(struct chservinfo);
1850 blob.in = (caddr_t) & checkserv;
1852 blob.out_size = MAXSIZE;
1854 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1856 /* prepare flags for checkservers command */
1857 temp = 2; /* default to checking local cell only */
1858 if (as->parms[2].items)
1859 temp |= 1; /* set fast flag */
1860 if (as->parms[1].items)
1861 temp &= ~2; /* turn off local cell check */
1863 checkserv.magic = 0x12345678; /* XXX */
1864 checkserv.tflags = temp;
1866 /* now copy in optional cell name, if specified */
1867 if (as->parms[0].items) {
1868 code = GetCellName(as->parms[0].items->data, &info);
1872 strcpy(checkserv.tbuffer, info.name);
1873 checkserv.tsize = strlen(info.name) + 1;
1875 strcpy(checkserv.tbuffer, "\0");
1876 checkserv.tsize = 0;
1879 if (as->parms[3].items) {
1880 checkserv.tinterval = atol(as->parms[3].items->data);
1883 if (checkserv.tinterval < 0) {
1885 ("Warning: The negative -interval is ignored; treated as an inquiry\n");
1886 checkserv.tinterval = 0;
1887 } else if (checkserv.tinterval > 600) {
1889 ("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1890 checkserv.tinterval = 600; /* 10 min max interval */
1893 checkserv.tinterval = -1; /* don't change current interval */
1896 code = pioctl(0, VIOCCKSERV, &blob, 1);
1898 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1899 printf("Must be root to change -interval\n");
1905 memcpy(&temp, space, sizeof(afs_int32));
1906 if (checkserv.tinterval >= 0) {
1907 if (checkserv.tinterval > 0)
1909 ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1910 checkserv.tinterval, temp);
1912 printf("The current down server probe interval is %d secs\n",
1917 printf("All servers are running.\n");
1920 ("These servers unavailable due to network or server problems: ");
1922 memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32));
1925 tp = hostutil_GetNameByINet(temp);
1935 MessagesCmd(struct cmd_syndesc *as, char *arock)
1938 struct ViceIoctl blob;
1941 struct gaginfo gagflags;
1942 struct cmd_item *show;
1944 memset(&gagflags, 0, sizeof(struct gaginfo));
1945 blob.in_size = sizeof(struct gaginfo);
1946 blob.in = (caddr_t) & gagflags;
1947 blob.out_size = MAXSIZE;
1949 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1951 if (show = as->parms[0].items) {
1952 if (!strcasecmp(show->data, "user"))
1953 gagflags.showflags |= GAGUSER;
1954 else if (!strcasecmp(show->data, "console"))
1955 gagflags.showflags |= GAGCONSOLE;
1956 else if (!strcasecmp(show->data, "all"))
1957 gagflags.showflags |= GAGCONSOLE | GAGUSER;
1958 else if (!strcasecmp(show->data, "none"))
1962 "unrecognized flag %s: must be in {user,console,all,none}\n",
1971 code = pioctl(0, VIOC_GAG, &blob, 1);
1981 CheckVolumesCmd(struct cmd_syndesc *as, char *arock)
1984 struct ViceIoctl blob;
1988 code = pioctl(0, VIOCCKBACK, &blob, 1);
1994 printf("All volumeID/name mappings checked.\n");
1999 SetCacheSizeCmd(struct cmd_syndesc *as, char *arock)
2002 struct ViceIoctl blob;
2005 if (!as->parms[0].items && !as->parms[1].items) {
2006 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
2009 if (as->parms[0].items) {
2010 code = util_GetInt32(as->parms[0].items->data, &temp);
2012 fprintf(stderr, "%s: bad integer specified for cache size.\n",
2018 blob.in = (char *)&temp;
2019 blob.in_size = sizeof(afs_int32);
2021 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2023 if (errno == EROFS) {
2025 ("'fs setcache' not allowed on memory cache based cache managers.\n");
2032 printf("New cache size set.\n");
2036 #define MAXGCSIZE 16
2038 GetCacheParmsCmd(struct cmd_syndesc *as, char *arock)
2040 afs_int32 code, filesUsed;
2041 struct ViceIoctl blob;
2042 afs_int32 parms[MAXGCSIZE];
2043 double percentFiles, percentBlocks;
2044 afs_int32 flags = 0;
2046 if (as->parms[0].items){ /* -files */
2048 } else if (as->parms[1].items){ /* -excessive */
2054 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
2056 blob.in = (char *)&flags;
2057 blob.in_size = sizeof(afs_int32);
2058 } else { /* be backward compatible */
2062 blob.out_size = sizeof(parms);
2063 blob.out = (char *)parms;
2064 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2071 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2072 parms[1], parms[0]);
2073 if (parms[1] > parms[0])
2074 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2078 percentBlocks = ((double)parms[1]/parms[0]) * 100;
2079 printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n",
2080 percentBlocks, parms[1], parms[0]);
2082 filesUsed = parms[2] - parms[3];
2083 percentFiles = ((double)filesUsed/parms[2]) * 100;
2084 printf(" %5.0f%% of the cache files (%d of %d files)\n",
2085 percentFiles, filesUsed, parms[2]);
2087 printf(" afs_cacheFiles: %10d\n", parms[2]);
2088 printf(" IFFree: %10d\n", parms[3]);
2089 printf(" IFEverUsed: %10d\n", parms[4]);
2090 printf(" IFDataMod: %10d\n", parms[5]);
2091 printf(" IFDirtyPages: %10d\n", parms[6]);
2092 printf(" IFAnyPages: %10d\n", parms[7]);
2093 printf(" IFDiscarded: %10d\n", parms[8]);
2094 printf(" DCentries: %10d\n", parms[9]);
2095 printf(" 0k- 4K: %10d\n", parms[10]);
2096 printf(" 4k- 16k: %10d\n", parms[11]);
2097 printf(" 16k- 64k: %10d\n", parms[12]);
2098 printf(" 64k- 256k: %10d\n", parms[13]);
2099 printf(" 256k- 1M: %10d\n", parms[14]);
2100 printf(" >=1M: %10d\n", parms[15]);
2103 if (percentBlocks > 90)
2104 printf("[cache size usage over 90%, consider increasing cache size]\n");
2105 if (percentFiles > 90)
2106 printf("[cache file usage over 90%, consider increasing '-files' argument to afsd]\n");
2112 ListCellsCmd(struct cmd_syndesc *as, char *arock)
2118 struct ViceIoctl blob;
2121 resolve = !(as->parms[0].items); /* -numeric */
2125 memcpy(tp, &i, sizeof(afs_int32));
2126 blob.out_size = MAXSIZE;
2127 blob.in_size = sizeof(afs_int32);
2130 code = pioctl(0, VIOCGETCELL, &blob, 1);
2133 break; /* done with the list */
2138 printf("Cell %s on hosts", tp + MAXCELLHOSTS * sizeof(afs_int32));
2139 for (j = 0; j < MAXCELLHOSTS; j++) {
2141 char *name, tbuffer[20];
2143 memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32));
2148 name = hostutil_GetNameByINet(addr);
2151 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2152 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2155 printf(" %s", name);
2163 ListAliasesCmd(struct cmd_syndesc *as, char *arock)
2166 char *tp, *aliasName, *realName;
2167 struct ViceIoctl blob;
2171 memcpy(tp, &i, sizeof(afs_int32));
2172 blob.out_size = MAXSIZE;
2173 blob.in_size = sizeof(afs_int32);
2176 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2179 break; /* done with the list */
2185 tp += strlen(aliasName) + 1;
2187 printf("Alias %s for cell %s\n", aliasName, realName);
2193 CallBackRxConnCmd(struct cmd_syndesc *as, char *arock)
2196 struct ViceIoctl blob;
2197 struct cmd_item *ti;
2199 struct hostent *thp;
2203 ti = as->parms[0].items;
2206 thp = hostutil_GetHostByName(ti->data);
2208 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2211 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2213 hostAddr = 0; /* means don't set host */
2214 setp = 0; /* aren't setting host */
2217 /* now do operation */
2218 blob.in_size = sizeof(afs_int32);
2219 blob.out_size = sizeof(afs_int32);
2220 blob.in = (char *) &hostAddr;
2221 blob.out = (char *) &hostAddr;
2223 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2232 NukeNFSCredsCmd(struct cmd_syndesc *as, char *arock)
2235 struct ViceIoctl blob;
2236 struct cmd_item *ti;
2238 struct hostent *thp;
2240 ti = as->parms[0].items;
2241 thp = hostutil_GetHostByName(ti->data);
2243 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2246 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2248 /* now do operation */
2249 blob.in_size = sizeof(afs_int32);
2250 blob.out_size = sizeof(afs_int32);
2251 blob.in = (char *) &hostAddr;
2252 blob.out = (char *) &hostAddr;
2254 code = pioctl(0, VIOC_NFS_NUKE_CREDS, &blob, 1);
2263 NewCellCmd(struct cmd_syndesc *as, char *arock)
2265 afs_int32 code, linkedstate = 0, size = 0, *lp;
2266 struct ViceIoctl blob;
2267 struct cmd_item *ti;
2268 char *tp, *cellname = 0;
2269 struct hostent *thp;
2270 afs_int32 fsport = 0, vlport = 0;
2271 afs_int32 magic, scount; /* Number of servers to pass in pioctl call */
2274 * With the NEWCELL pioctl call, 3.4 clients take an array of
2275 * MAXHOSTS (13) servers while 3.5 clients take an array of
2276 * MAXCELLHOSTS (8) servers. To determine which we are talking to,
2277 * do a GETCELL pioctl and pass it a magic number. If an array of
2278 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
2279 * If we get back EDOM, there are no cells in the kernel yet,
2280 * and we'll assume a 3.5 client.
2283 lp = (afs_int32 *) tp;
2284 *lp++ = 0; /* first cell entry */
2285 *lp = 0x12345678; /* magic */
2286 blob.out_size = MAXSIZE;
2287 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
2290 code = pioctl(0, VIOCGETCELL, &blob, 1);
2291 if (code < 0 && errno != EDOM) {
2295 if (code < 1 && errno == EDOM) {
2299 cellname = tp + MAXCELLHOSTS * sizeof(afs_int32);
2300 scount = ((cellname[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2303 /* Now setup and do the NEWCELL pioctl call */
2304 memset(space, 0, (scount + 1) * sizeof(afs_int32));
2306 lp = (afs_int32 *) tp;
2308 tp += sizeof(afs_int32);
2309 for (ti = as->parms[1].items; ti; ti = ti->next) {
2310 thp = hostutil_GetHostByName(ti->data);
2313 "%s: Host %s not found in host table, skipping it.\n", pn,
2316 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2317 tp += sizeof(afs_int32);
2320 if (as->parms[2].items) {
2322 * Link the cell, for the purposes of volume location, to the specified
2325 cellname = as->parms[2].items->data;
2328 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2329 if (as->parms[3].items) {
2330 code = util_GetInt32(as->parms[3].items->data, &vlport);
2333 "%s: bad integer specified for the fileserver port.\n",
2338 if (as->parms[4].items) {
2339 code = util_GetInt32(as->parms[4].items->data, &fsport);
2342 "%s: bad integer specified for the vldb server port.\n",
2348 tp = (char *)(space + (scount + 1) * sizeof(afs_int32));
2349 lp = (afs_int32 *) tp;
2353 strcpy(space + ((scount + 4) * sizeof(afs_int32)),
2354 as->parms[0].items->data);
2355 size = ((scount + 4) * sizeof(afs_int32))
2356 + strlen(as->parms[0].items->data)
2357 + 1 /* for null */ ;
2358 tp = (char *)(space + size);
2360 strcpy(tp, cellname);
2361 size += strlen(cellname) + 1;
2363 blob.in_size = size;
2366 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2375 NewAliasCmd(struct cmd_syndesc *as, char *arock)
2378 struct ViceIoctl blob;
2380 char *aliasName, *realName;
2382 /* Now setup and do the NEWCELL pioctl call */
2383 aliasName = as->parms[0].items->data;
2384 realName = as->parms[1].items->data;
2386 strcpy(tp, aliasName);
2387 tp += strlen(aliasName) + 1;
2388 strcpy(tp, realName);
2389 tp += strlen(realName) + 1;
2391 blob.in_size = tp - space;
2395 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2397 if (errno == EEXIST) {
2399 "%s: cell name `%s' in use by an existing cell.\n", pn,
2410 WhichCellCmd(struct cmd_syndesc *as, char *arock)
2413 struct cmd_item *ti;
2415 char cell[MAXCELLCHARS];
2417 SetDotDefault(&as->parms[0].items);
2418 for (ti = as->parms[0].items; ti; ti = ti->next) {
2419 code = GetCell(ti->data, cell);
2421 if (errno == ENOENT)
2422 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
2424 Die(errno, ti->data);
2429 printf("File %s lives in cell '%s'\n", ti->data, cell);
2435 WSCellCmd(struct cmd_syndesc *as, char *arock)
2438 struct ViceIoctl blob;
2442 blob.out_size = MAXSIZE;
2445 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2451 printf("This workstation belongs to cell '%s'\n", space);
2456 static PrimaryCellCmd(as)
2457 struct cmd_syndesc *as;
2459 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2465 MonitorCmd(struct cmd_syndesc *as, char *arock)
2468 struct ViceIoctl blob;
2469 struct cmd_item *ti;
2471 struct hostent *thp;
2475 ti = as->parms[0].items;
2479 if (!strcmp(ti->data, "off"))
2480 hostAddr = 0xffffffff;
2482 thp = hostutil_GetHostByName(ti->data);
2484 if (!strcmp(ti->data, "localhost")) {
2486 "localhost not in host table, assuming 127.0.0.1\n");
2487 hostAddr = htonl(0x7f000001);
2489 fprintf(stderr, "host %s not found in host table.\n",
2494 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2497 hostAddr = 0; /* means don't set host */
2498 setp = 0; /* aren't setting host */
2501 /* now do operation */
2502 blob.in_size = sizeof(afs_int32);
2503 blob.out_size = sizeof(afs_int32);
2504 blob.in = (char *)&hostAddr;
2505 blob.out = (char *)&hostAddr;
2506 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2512 printf("%s: new monitor host set.\n", pn);
2514 /* now decode old address */
2515 if (hostAddr == 0xffffffff) {
2516 printf("Cache monitoring is currently disabled.\n");
2518 tp = hostutil_GetNameByINet(hostAddr);
2519 printf("Using host %s for monitor services.\n", tp);
2526 SysNameCmd(struct cmd_syndesc *as, char *arock)
2529 struct ViceIoctl blob;
2530 struct cmd_item *ti;
2531 char *input = space;
2534 ti = as->parms[0].items;
2537 blob.out_size = MAXSIZE;
2538 blob.in_size = sizeof(afs_int32);
2539 input += sizeof(afs_int32);
2540 for (; ti; ti = ti->next) {
2542 blob.in_size += strlen(ti->data) + 1;
2543 if (blob.in_size > MAXSIZE) {
2544 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2545 setp > 1 ? "s" : "");
2548 strcpy(input, ti->data);
2549 input += strlen(ti->data);
2552 memcpy(space, &setp, sizeof(afs_int32));
2553 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2559 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2563 memcpy(&setp, input, sizeof(afs_int32));
2564 input += sizeof(afs_int32);
2566 fprintf(stderr, "No sysname name value was found\n");
2569 printf("Current sysname%s is", setp > 1 ? " list" : "");
2570 for (; setp > 0; --setp) {
2571 printf(" \'%s\'", input);
2572 input += strlen(input) + 1;
2578 static char *exported_types[] = { "null", "nfs", "" };
2580 ExportAfsCmd(struct cmd_syndesc *as, char *arock)
2583 struct ViceIoctl blob;
2584 struct cmd_item *ti;
2585 int export = 0, type = 0, mode = 0, exp = 0, exportcall, pwsync =
2586 0, smounts = 0, clipags = 0, pagcb = 0;
2588 ti = as->parms[0].items;
2589 if (strcmp(ti->data, "nfs") == 0)
2590 type = 0x71; /* NFS */
2593 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n",
2597 ti = as->parms[1].items;
2599 if (strcmp(ti->data, "on") == 0)
2601 else if (strcmp(ti->data, "off") == 0)
2604 fprintf(stderr, "Illegal argument %s\n", ti->data);
2609 if (ti = as->parms[2].items) { /* -noconvert */
2610 if (strcmp(ti->data, "on") == 0)
2612 else if (strcmp(ti->data, "off") == 0)
2615 fprintf(stderr, "Illegal argument %s\n", ti->data);
2619 if (ti = as->parms[3].items) { /* -uidcheck */
2620 if (strcmp(ti->data, "on") == 0)
2622 else if (strcmp(ti->data, "off") == 0)
2625 fprintf(stderr, "Illegal argument %s\n", ti->data);
2629 if (ti = as->parms[4].items) { /* -submounts */
2630 if (strcmp(ti->data, "on") == 0)
2632 else if (strcmp(ti->data, "off") == 0)
2635 fprintf(stderr, "Illegal argument %s\n", ti->data);
2639 if (ti = as->parms[5].items) { /* -clipags */
2640 if (strcmp(ti->data, "on") == 0)
2642 else if (strcmp(ti->data, "off") == 0)
2645 fprintf(stderr, "Illegal argument %s\n", ti->data);
2649 if (ti = as->parms[6].items) { /* -pagcb */
2650 if (strcmp(ti->data, "on") == 0)
2652 else if (strcmp(ti->data, "off") == 0)
2655 fprintf(stderr, "Illegal argument %s\n", ti->data);
2660 (type << 24) | (pagcb << 10) | (clipags << 8) |
2661 (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2664 blob.in = (char *)&exportcall;
2665 blob.in_size = sizeof(afs_int32);
2666 blob.out = (char *)&exportcall;
2667 blob.out_size = sizeof(afs_int32);
2668 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2670 if (errno == ENODEV) {
2672 "Sorry, the %s-exporter type is currently not supported on this AFS client\n",
2673 exported_types[type]);
2680 if (exportcall & 1) {
2681 printf("'%s' translator is enabled with the following options:\n",
2682 exported_types[type]);
2683 printf("\tRunning in %s mode\n",
2684 (exportcall & 2 ? "strict unix" :
2685 "convert owner mode bits to world/other"));
2686 printf("\tRunning in %s mode\n",
2687 (exportcall & 4 ? "strict 'passwd sync'" :
2688 "no 'passwd sync'"));
2690 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
2691 "Only mounts to /afs allowed"));
2693 (exportcall & 16 ? "Client-assigned PAG's are used" :
2694 "Client-assigned PAG's are not used"));
2697 "Callbacks are made to get creds from new clients" :
2698 "Callbacks are not made to get creds from new clients"));
2700 printf("'%s' translator is disabled\n", exported_types[type]);
2707 GetCellCmd(struct cmd_syndesc *as, char *arock)
2710 struct ViceIoctl blob;
2711 struct afsconf_cell info;
2712 struct cmd_item *ti;
2719 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2720 for (ti = as->parms[0].items; ti; ti = ti->next) {
2722 blob.out_size = sizeof(args);
2723 blob.out = (caddr_t) & args;
2724 code = GetCellName(ti->data, &info);
2729 blob.in_size = 1 + strlen(info.name);
2730 blob.in = info.name;
2731 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2733 if (errno == ENOENT)
2734 fprintf(stderr, "%s: the cell named '%s' does not exist\n",
2737 Die(errno, info.name);
2741 printf("Cell %s status: ", info.name);
2747 printf("no setuid allowed");
2749 printf("setuid allowed");
2751 printf(", using old VLDB");
2758 SetCellCmd(struct cmd_syndesc *as, char *arock)
2761 struct ViceIoctl blob;
2762 struct afsconf_cell info;
2763 struct cmd_item *ti;
2771 /* Check arguments. */
2772 if (as->parms[1].items && as->parms[2].items) {
2773 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2777 /* figure stuff to set */
2781 if (!as->parms[1].items)
2782 args.stat |= 2; /* default to -nosuid */
2784 /* set stat for all listed cells */
2785 for (ti = as->parms[0].items; ti; ti = ti->next) {
2787 code = GetCellName(ti->data, &info);
2792 strcpy(args.cname, info.name);
2793 blob.in_size = sizeof(args);
2794 blob.in = (caddr_t) & args;
2796 blob.out = (caddr_t) 0;
2797 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2799 Die(errno, info.name); /* XXX added cell name to Die() call */
2807 GetCellName(char *cellName, struct afsconf_cell *info)
2809 struct afsconf_dir *tdir;
2812 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2815 "Could not process files in configuration directory (%s).\n",
2816 AFSDIR_CLIENT_ETC_DIRPATH);
2820 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2822 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2823 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
2832 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
2836 code = ugen_ClientInit(noAuthFlag, AFSDIR_CLIENT_ETC_DIRPATH,
2837 info->name, 0, &uclient,
2838 NULL, pn, rxkad_clear,
2839 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
2840 0, 0, USER_SERVICE_ID);
2845 static struct ViceIoctl gblob;
2846 static int debug = 0;
2848 * here follow some routines in suport of the setserverprefs and
2849 * getserverprefs commands. They are:
2850 * SetPrefCmd "top-level" routine
2851 * addServer adds a server to the list of servers to be poked into the
2852 * kernel. Will poke the list into the kernel if it threatens
2854 * pokeServers pokes the existing list of servers and ranks into the kernel
2855 * GetPrefCmd reads the Cache Manager's current list of server ranks
2859 * returns -1 if error message printed,
2861 * errno value if error and no error message printed
2868 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2869 if (code && (errno == EINVAL)) {
2870 struct setspref *ssp;
2871 ssp = (struct setspref *)gblob.in;
2872 if (!(ssp->flags & DBservers)) {
2873 gblob.in = (void *)&(ssp->servers[0]);
2874 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
2875 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
2876 return code ? errno : 0;
2879 "This cache manager does not support VL server preferences.\n");
2883 return code ? errno : 0;
2887 * returns -1 if error message printed,
2889 * errno value if error and no error message printed
2892 addServer(char *name, afs_int32 rank)
2895 struct setspref *ssp;
2897 struct hostent *thostent;
2903 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
2905 #define MAXUSHORT ((unsigned short) ~0)
2909 thostent = hostutil_GetHostByName(name);
2911 fprintf(stderr, "%s: couldn't resolve name.\n", name);
2915 ssp = (struct setspref *)(gblob.in);
2917 for (t = 0; thostent->h_addr_list[t]; t++) {
2918 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
2919 code = pokeServers();
2922 ssp->num_servers = 0;
2925 sp = (struct spref *)(gblob.in + gblob.in_size);
2926 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
2927 sizeof(afs_uint32));
2928 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
2929 gblob.in_size += sizeof(struct spref);
2933 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
2934 name, sp->rank, sp->server.s_addr);
2942 SetPrefCmd(struct cmd_syndesc *as, char *arock)
2946 struct cmd_item *ti;
2949 struct setspref *ssp;
2950 int error = 0; /* -1 means error message printed,
2951 * >0 means errno value for unprinted message */
2953 ssp = (struct setspref *)space;
2955 ssp->num_servers = 0;
2956 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
2959 gblob.out_size = MAXSIZE;
2963 fprintf(stderr, "Permission denied: requires root access.\n");
2967 ti = as->parms[2].items; /* -file */
2970 fprintf(stderr, "opening file %s\n", ti->data);
2971 if (!(infd = fopen(ti->data, "r"))) {
2975 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
2976 code = addServer(name, (unsigned short)rank);
2983 ti = as->parms[3].items; /* -stdin */
2985 while (scanf("%79s%ld", name, &rank) != EOF) {
2986 code = addServer(name, (unsigned short)rank);
2992 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
2997 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3001 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3005 code = pokeServers();
3009 printf("now working on vlservers, code=%d\n", code);
3011 ssp = (struct setspref *)space;
3012 ssp->flags = DBservers;
3013 ssp->num_servers = 0;
3014 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3017 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3022 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3026 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3031 if (as->parms[1].items) {
3033 printf("now poking vlservers\n");
3034 code = pokeServers();
3042 return error ? 1 : 0;
3048 GetPrefCmd(struct cmd_syndesc *as, char *arock)
3051 struct cmd_item *ti;
3052 char *name, tbuffer[20];
3053 afs_int32 rank, addr;
3057 struct ViceIoctl blob;
3058 struct sprefrequest *in;
3059 struct sprefinfo *out;
3062 ti = as->parms[0].items; /* -file */
3065 fprintf(stderr, "opening file %s\n", ti->data);
3066 if (!(outfd = freopen(ti->data, "w", stdout))) {
3072 ti = as->parms[1].items; /* -numeric */
3074 ti = as->parms[2].items; /* -vlservers */
3075 vlservers |= (ti ? DBservers : 0);
3076 /* ti = as->parms[3].items; -cell */
3078 in = (struct sprefrequest *)space;
3082 blob.in_size = sizeof(struct sprefrequest);
3083 blob.in = (char *)in;
3085 blob.out_size = MAXSIZE;
3088 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3089 in->flags = vlservers;
3091 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3093 perror("getserverprefs pioctl");
3097 out = (struct sprefinfo *)blob.out;
3099 for (i = 0; i < out->num_servers; i++) {
3101 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3103 addr = ntohl(out->servers[i].server.s_addr);
3104 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3105 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3108 printf("%-50s %5u\n", name, out->servers[i].rank);
3111 in->offset = out->next_offset;
3112 } while (out->next_offset > 0);
3118 StoreBehindCmd(struct cmd_syndesc *as, char *arock)
3121 struct ViceIoctl blob;
3122 struct cmd_item *ti;
3123 struct sbstruct tsb, tsb2;
3129 tsb.sb_thisfile = -1;
3130 ti = as->parms[0].items; /* -kbytes */
3132 if (!as->parms[1].items) {
3133 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3137 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3138 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3139 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3145 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3146 ti = as->parms[2].items; /* -allfiles */
3148 allfiles = strtol(ti->data, &t, 10) * 1024;
3149 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3150 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3156 /* -verbose or -file only or no options */
3157 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3158 || (!as->parms[0].items && !as->parms[1].items
3159 && !as->parms[2].items))
3162 blob.in = (char *)&tsb;
3163 blob.out = (char *)&tsb2;
3164 blob.in_size = blob.out_size = sizeof(struct sbstruct);
3165 memset(&tsb2, 0, sizeof(tsb2));
3167 /* once per -file */
3168 for (ti = as->parms[1].items; ti; ti = ti->next) {
3169 /* Do this solely to see if the file is there */
3170 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3172 Die(errno, ti->data);
3177 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
3179 Die(errno, ti->data);
3184 if (verbose && (blob.out_size == sizeof(tsb2))) {
3185 if (tsb2.sb_thisfile == -1) {
3186 fprintf(stdout, "Will store %s according to default.\n",
3190 "Will store up to %d kbytes of %s asynchronously.\n",
3191 (tsb2.sb_thisfile / 1024), ti->data);
3196 /* If no files - make at least one pioctl call, or
3197 * set the allfiles default if we need to.
3199 if (!as->parms[1].items || (allfiles != -1)) {
3200 tsb.sb_default = allfiles;
3201 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
3203 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3208 /* Having no arguments also reports the default store asynchrony */
3209 if (verbose && (blob.out_size == sizeof(tsb2))) {
3210 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3211 (tsb2.sb_default / 1024));
3219 SetCryptCmd(struct cmd_syndesc *as, char *arock)
3221 afs_int32 code = 0, flag;
3222 struct ViceIoctl blob;
3225 tp = as->parms[0].items->data;
3226 if (strcmp(tp, "on") == 0)
3228 else if (strcmp(tp, "off") == 0)
3231 fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3235 blob.in = (char *)&flag;
3236 blob.in_size = sizeof(flag);
3238 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3246 GetCryptCmd(struct cmd_syndesc *as, char *arock)
3248 afs_int32 code = 0, flag;
3249 struct ViceIoctl blob;
3254 blob.out_size = sizeof(flag);
3257 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3263 memcpy(&flag, tp, sizeof(afs_int32));
3264 printf("Security level is currently ");
3266 printf("crypt (data security).\n");
3273 #ifdef AFS_DISCON_ENV
3274 static char *modenames[] = {
3284 DisconCmd(struct cmd_syndesc *as, char *arock)
3286 struct cmd_item *ti;
3289 afs_int32 mode, code;
3290 struct ViceIoctl blob;
3295 ti = as->parms[0].items;
3297 modename = ti->data;
3298 modelen = strlen(modename);
3299 for (mode = 0; modenames[mode] != NULL; mode++)
3300 if (!strncasecmp(modename, modenames[mode], modelen))
3302 if (modenames[mode] == NULL)
3303 printf("Unknown discon mode \"%s\"\n", modename);
3305 memcpy(space, &mode, sizeof mode);
3307 blob.in_size = sizeof mode;
3311 blob.out_size = sizeof(mode);
3313 code = pioctl(0, VIOC_DISCON, &blob, 1);
3317 memcpy(&mode, space, sizeof mode);
3318 if (mode < sizeof modenames / sizeof (char *))
3319 printf("Discon mode is now \"%s\"\n", modenames[mode]);
3321 printf("Unknown discon mode %d\n", mode);
3328 #include "AFS_component_version_number.c"
3331 main(int argc, char **argv)
3334 struct cmd_syndesc *ts;
3336 #ifdef AFS_AIX32_ENV
3338 * The following signal action for AIX is necessary so that in case of a
3339 * crash (i.e. core is generated) we can include the user's data section
3340 * in the core dump. Unfortunately, by default, only a partial core is
3341 * generated which, in many cases, isn't too useful.
3343 struct sigaction nsa;
3345 sigemptyset(&nsa.sa_mask);
3346 nsa.sa_handler = SIG_DFL;
3347 nsa.sa_flags = SA_FULLDUMP;
3348 sigaction(SIGSEGV, &nsa, NULL);
3351 /* try to find volume location information */
3352 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, 0,
3353 "get client network interface addresses");
3354 cmd_CreateAlias(ts, "gc");
3356 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, 0,
3357 "set client network interface addresses");
3358 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3359 "client network interfaces");
3360 cmd_CreateAlias(ts, "sc");
3362 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0,
3363 "set server ranks");
3364 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3365 "fileserver names and ranks");
3366 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3367 "VL server names and ranks");
3368 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3369 "input from named file");
3370 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3371 cmd_CreateAlias(ts, "sp");
3373 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0,
3374 "get server ranks");
3375 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3376 "output to named file");
3377 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3378 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3379 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3380 cmd_CreateAlias(ts, "gp");
3382 ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list");
3383 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3384 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3385 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3386 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL,
3387 "apply to negative rights");
3388 parm_setacl_id = ts->nParms;
3389 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL,
3390 "initial directory acl (DFS only)");
3391 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL,
3392 "initial file acl (DFS only)");
3393 cmd_CreateAlias(ts, "sa");
3395 ts = cmd_CreateSyntax("listacl", ListACLCmd, 0,
3396 "list access control list");
3397 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3398 parm_listacl_id = ts->nParms;
3399 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3400 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3401 cmd_CreateAlias(ts, "la");
3403 ts = cmd_CreateSyntax("getcalleraccess", GetCallerAccess, 0,
3404 "list callers access");
3405 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3406 cmd_CreateAlias(ts, "gca");
3408 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0,
3409 "clean up access control list");
3410 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3412 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0,
3413 "copy access control list");
3414 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0,
3415 "source directory (or DFS file)");
3416 cmd_AddParm(ts, "-todir", CMD_LIST, 0,
3417 "destination directory (or DFS file)");
3418 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3419 "first clear dest access list");
3420 parm_copyacl_id = ts->nParms;
3421 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3422 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3424 cmd_CreateAlias(ts, "ca");
3426 ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache");
3427 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3428 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, 0,
3429 "flush mount symlink from cache");
3430 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3432 ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status");
3433 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3434 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL,
3435 "disk space quota in 1K units");
3437 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL,
3438 "disk space guaranteed");
3439 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3441 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL,
3443 cmd_CreateAlias(ts, "sv");
3445 ts = cmd_CreateSyntax("messages", MessagesCmd, 0,
3446 "control Cache Manager messages");
3447 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL,
3448 "[user|console|all|none]");
3450 ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display file/volume status");
3451 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3452 cmd_CreateAlias(ts, "lv");
3453 cmd_CreateAlias(ts, "listvol");
3455 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota");
3456 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3457 cmd_CreateAlias(ts, "lq");
3459 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0,
3460 "show server disk space usage");
3461 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3462 cmd_CreateAlias(ts, "df");
3464 ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage");
3465 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3467 ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point");
3468 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3470 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point");
3471 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3472 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3473 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3474 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3475 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3476 "don't check name with VLDB");
3482 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3486 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point");
3487 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3489 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0,
3490 "check local cell's servers");
3491 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3492 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3493 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3494 "just list, don't check");
3495 cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL,
3496 "seconds between probes");
3498 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, 0,
3499 "check volumeID/name mappings");
3500 cmd_CreateAlias(ts, "checkbackups");
3503 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0,
3505 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3506 "size in 1K byte blocks (0 => reset)");
3507 cmd_CreateAlias(ts, "cachesize");
3509 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL,
3510 "reset size back to boot value");
3512 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0,
3513 "get cache usage info");
3514 cmd_AddParm(ts, "-files", CMD_FLAG, CMD_OPTIONAL, "Show cach files used as well");
3515 cmd_AddParm(ts, "-excessive", CMD_FLAG, CMD_OPTIONAL, "excessively verbose cache stats");
3517 ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0,
3518 "list configured cells");
3519 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3521 ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, 0,
3522 "list configured cell aliases");
3524 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota");
3525 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3526 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3528 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3530 cmd_CreateAlias(ts, "sq");
3532 ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell");
3533 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3534 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3535 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL,
3536 "linked cell name");
3538 ts = cmd_CreateSyntax("newalias", NewAliasCmd, 0,
3539 "configure new cell alias");
3540 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
3541 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
3543 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3545 * Turn this on only if you wish to be able to talk to a server which is listening
3546 * on alternative ports. This is not intended for general use and may not be
3547 * supported in the cache manager. It is not a way to run two servers at the
3548 * same host, since the cache manager cannot properly distinguish those two hosts.
3550 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL,
3551 "cell's fileserver port");
3552 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL,
3553 "cell's vldb server port");
3556 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell");
3557 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3559 ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location");
3560 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3562 ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell");
3565 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
3568 /* set cache monitor host address */
3569 ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, (char *)CMD_HIDDEN);
3570 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL,
3571 "host name or 'off'");
3572 cmd_CreateAlias(ts, "mariner");
3574 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status");
3575 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3577 ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status");
3578 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3579 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3580 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL,
3581 "disallow setuid programs");
3583 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0,
3584 "flush all data in volume");
3585 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3587 ts = cmd_CreateSyntax("sysname", SysNameCmd, 0,
3588 "get/set sysname (i.e. @sys) value");
3589 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3591 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0,
3592 "enable/disable translators to AFS");
3593 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3594 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL,
3595 "start/stop translator (on | off)");
3596 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL,
3597 "convert from afs to unix mode (on | off)");
3598 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL,
3599 "run on strict 'uid check' mode (on | off)");
3600 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
3601 "allow nfs mounts to subdirs of /afs/.. (on | off)");
3602 cmd_AddParm(ts, "-clipags", CMD_SINGLE, CMD_OPTIONAL,
3603 "enable use of client-assigned PAG's (on | off)");
3604 cmd_AddParm(ts, "-pagcb", CMD_SINGLE, CMD_OPTIONAL,
3605 "enable callbacks to get creds from new clients (on | off)");
3608 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0,
3609 "store to server after file close");
3610 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL,
3611 "asynchrony for specified names");
3612 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3613 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL,
3614 "new default (KB)");
3615 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3616 cmd_CreateAlias(ts, "sb");
3618 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0,
3619 "set cache manager encryption flag");
3620 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3622 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0,
3623 "get cache manager encryption flag");
3625 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, 0,
3626 "Manage per process RX statistics");
3627 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3628 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3629 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3631 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, 0,
3632 "Manage per peer 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("setcbaddr", CallBackRxConnCmd, 0, "configure callback connection address");
3638 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
3640 /* try to find volume location information */
3641 ts = cmd_CreateSyntax("getfid", GetFidCmd, 0,
3642 "get fid for file(s)");
3643 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3645 #ifdef AFS_DISCON_ENV
3646 ts = cmd_CreateSyntax("discon", DisconCmd, 0,
3647 "disconnection mode");
3648 cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_OPTIONAL, "nat | full");
3651 ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, 0, "nuke credentials for NFS client");
3652 cmd_AddParm(ts, "-addr", CMD_SINGLE, 0, "host name or address");
3654 ts = cmd_CreateSyntax("uuid", UuidCmd, 0, "manage the UUID for the cache manager");
3655 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_REQUIRED, "generate a new UUID");
3657 code = cmd_Dispatch(argc, argv);
3665 Die(int errnum, char *filename)
3671 "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3674 fprintf(stderr, "%s: Invalid argument.\n", pn);
3678 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3680 fprintf(stderr, "%s: no such file returned\n", pn);
3684 "%s: You can not change a backup or readonly volume\n", pn);
3690 "%s: You don't have the required access rights on '%s'\n",
3694 "%s: You do not have the required rights to do this operation\n",
3699 fprintf(stderr, "%s:'%s'", pn, filename);
3701 fprintf(stderr, "%s", pn);
3702 fprintf(stderr, ": %s\n", afs_error_message(errnum));
3707 /* get clients interface addresses */
3709 GetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
3712 struct cmd_item *ti;
3714 struct ViceIoctl blob;
3715 struct sprefrequest *in;
3716 struct sprefinfo *out;
3718 in = (struct sprefrequest *)space;
3722 blob.in_size = sizeof(struct sprefrequest);
3723 blob.in = (char *)in;
3725 blob.out_size = MAXSIZE;
3728 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3729 /* returns addr in network byte order */
3730 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3732 perror("getClientInterfaceAddr pioctl");
3738 out = (struct sprefinfo *)blob.out;
3739 for (i = 0; i < out->num_servers; i++) {
3742 addr = ntohl(out->servers[i].server.s_addr);
3743 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3744 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3745 printf("%-50s\n", tbuffer);
3747 in->offset = out->next_offset;
3749 } while (out->next_offset > 0);
3755 SetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
3757 afs_int32 code, addr;
3758 struct cmd_item *ti;
3760 struct ViceIoctl blob;
3761 struct setspref *ssp;
3762 int sizeUsed = 0, i, flag;
3763 afs_int32 existingAddr[1024]; /* existing addresses on this host */
3767 ssp = (struct setspref *)space;
3768 ssp->num_servers = 0;
3771 blob.out_size = MAXSIZE;
3774 fprintf(stderr, "Permission denied: requires root access.\n");
3778 /* extract all existing interface addresses */
3779 existNu = rx_getAllAddr(existingAddr, 1024);
3783 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
3784 for (ti = as->parms[0].items; ti; ti = ti->next) {
3785 if (sizeUsed >= sizeof(space)) {
3786 fprintf(stderr, "No more space\n");
3789 addr = extractAddr(ti->data, 20); /* network order */
3790 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
3791 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
3796 /* see if it is an address that really exists */
3797 for (flag = 0, i = 0; i < existNu; i++)
3798 if (existingAddr[i] == addr) {
3802 if (!flag) { /* this is an nonexistent address */
3803 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
3807 /* copy all specified addr into ioctl buffer */
3808 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
3809 printf("Adding 0x%08x\n", addr);
3811 sizeUsed += sizeof(struct spref);
3813 if (ssp->num_servers < 1) {
3814 fprintf(stderr, "No addresses specified\n");
3817 blob.in_size = sizeUsed - sizeof(struct spref);
3819 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
3829 FlushMountCmd(struct cmd_syndesc *as, char *arock)
3832 struct ViceIoctl blob;
3833 struct cmd_item *ti;
3834 char orig_name[1024]; /*Original name, may be modified */
3835 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
3836 char parent_dir[1024]; /*Parent directory of true name */
3837 char *last_component; /*Last component of true name */
3838 struct stat statbuff; /*Buffer for status info */
3839 int link_chars_read; /*Num chars read in readlink() */
3840 int thru_symlink; /*Did we get to a mount point via a symlink? */
3843 for (ti = as->parms[0].items; ti; ti = ti->next) {
3846 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
3849 if (lstat(orig_name, &statbuff) < 0) {
3850 /* if lstat fails, we should still try the pioctl, since it
3851 * may work (for example, lstat will fail, but pioctl will
3852 * work if the volume of offline (returning ENODEV). */
3853 statbuff.st_mode = S_IFDIR; /* lie like pros */
3857 * The lstat succeeded. If the given file is a symlink, substitute
3858 * the file name with the link name.
3860 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
3863 * Read name of resolved file.
3865 link_chars_read = readlink(orig_name, true_name, 1024);
3866 if (link_chars_read <= 0) {
3868 "%s: Can't read target name for '%s' symbolic link!\n",
3875 * Add a trailing null to what was read, bump the length.
3877 true_name[link_chars_read++] = 0;
3880 * If the symlink is an absolute pathname, we're fine. Otherwise, we
3881 * have to create a full pathname using the original name and the
3882 * relative symlink name. Find the rightmost slash in the original
3883 * name (we know there is one) and splice in the symlink value.
3885 if (true_name[0] != '/') {
3886 last_component = (char *)strrchr(orig_name, '/');
3887 strcpy(++last_component, true_name);
3888 strcpy(true_name, orig_name);
3891 strcpy(true_name, orig_name);
3894 * Find rightmost slash, if any.
3896 last_component = (char *)strrchr(true_name, '/');
3897 if (last_component) {
3899 * Found it. Designate everything before it as the parent directory,
3900 * everything after it as the final component.
3902 strncpy(parent_dir, true_name, last_component - true_name);
3903 parent_dir[last_component - true_name] = 0;
3904 last_component++; /*Skip the slash */
3907 * No slash appears in the given file name. Set parent_dir to the current
3908 * directory, and the last component as the given name.
3910 strcpy(parent_dir, ".");
3911 last_component = true_name;
3914 if (strcmp(last_component, ".") == 0
3915 || strcmp(last_component, "..") == 0) {
3917 "%s: you may not use '.' or '..' as the last component\n",
3919 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
3925 blob.in = last_component;
3926 blob.in_size = strlen(last_component) + 1;
3928 memset(space, 0, MAXSIZE);
3930 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
3933 if (errno == EINVAL) {
3934 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
3936 Die(errno, (ti->data ? ti->data : parent_dir));
3945 RxStatProcCmd(struct cmd_syndesc *as, char *arock)
3948 afs_int32 flags = 0;
3949 struct ViceIoctl blob;
3950 struct cmd_item *ti;
3952 if (as->parms[0].items) { /* -enable */
3953 flags |= AFSCALL_RXSTATS_ENABLE;
3955 if (as->parms[1].items) { /* -disable */
3956 flags |= AFSCALL_RXSTATS_DISABLE;
3958 if (as->parms[2].items) { /* -clear */
3959 flags |= AFSCALL_RXSTATS_CLEAR;
3962 fprintf(stderr, "You must specify at least one argument\n");
3966 blob.in = (char *)&flags;
3967 blob.in_size = sizeof(afs_int32);
3970 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
3980 RxStatPeerCmd(struct cmd_syndesc *as, char *arock)
3983 afs_int32 flags = 0;
3984 struct ViceIoctl blob;
3985 struct cmd_item *ti;
3987 if (as->parms[0].items) { /* -enable */
3988 flags |= AFSCALL_RXSTATS_ENABLE;
3990 if (as->parms[1].items) { /* -disable */
3991 flags |= AFSCALL_RXSTATS_DISABLE;
3993 if (as->parms[2].items) { /* -clear */
3994 flags |= AFSCALL_RXSTATS_CLEAR;
3997 fprintf(stderr, "You must specify at least one argument\n");
4001 blob.in = (char *)&flags;
4002 blob.in_size = sizeof(afs_int32);
4005 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4015 GetFidCmd(struct cmd_syndesc *as, char *arock)
4017 struct ViceIoctl blob;
4018 struct cmd_item *ti;
4019 for (ti = as->parms[0].items; ti; ti = ti->next) {
4020 struct VenusFid vfid;
4022 blob.out_size = sizeof(struct VenusFid);
4023 blob.out = (char *) &vfid;
4026 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
4027 printf("File %s (%u.%u.%u) contained in volume %u\n",
4028 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,