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 static char pn[] = "fs";
73 static int rxInitDone = 0;
75 static void ZapList();
76 static int PruneList();
78 static int SetVolCmd(struct cmd_syndesc *as, void *arock);
84 * Character to use between name and rights in printed representation for
87 #define DFS_SEPARATOR ' '
89 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
92 int dfs; /* Originally true if a dfs acl; now also the type
93 * of the acl (1, 2, or 3, corresponding to object,
94 * initial dir, or initial object). */
95 sec_rgy_name_t cell; /* DFS cell name */
98 struct AclEntry *pluslist;
99 struct AclEntry *minuslist;
103 struct AclEntry *next;
109 afs_int32 callerAccess;
121 ZapList(acl->pluslist);
122 ZapList(acl->minuslist);
135 if (t >= 'A' && t <= 'Z')
137 if (u >= 'A' && u <= 'Z')
147 * Mods for the AFS/DFS protocol translator.
149 * DFS rights. It's ugly to put these definitions here, but they
150 * *cannot* change, because they're part of the wire protocol.
151 * In any event, the protocol translator will guarantee these
152 * assignments for AFS cache managers.
154 #define DFS_READ 0x01
155 #define DFS_WRITE 0x02
156 #define DFS_EXECUTE 0x04
157 #define DFS_CONTROL 0x08
158 #define DFS_INSERT 0x10
159 #define DFS_DELETE 0x20
161 /* the application definable ones (backwards from AFS) */
162 #define DFS_USR0 0x80000000 /* "A" bit */
163 #define DFS_USR1 0x40000000 /* "B" bit */
164 #define DFS_USR2 0x20000000 /* "C" bit */
165 #define DFS_USR3 0x10000000 /* "D" bit */
166 #define DFS_USR4 0x08000000 /* "E" bit */
167 #define DFS_USR5 0x04000000 /* "F" bit */
168 #define DFS_USR6 0x02000000 /* "G" bit */
169 #define DFS_USR7 0x01000000 /* "H" bit */
170 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
171 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
174 * Offset of -id switch in command structure for various commands.
175 * The -if switch is the next switch always.
177 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
180 * Determine whether either the -id or -if switches are present, and
181 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
183 /* int id; Offset of -id switch; -if is next switch */
185 getidf(struct cmd_syndesc *as, int id)
189 if (as->parms[id].items) {
192 if (as->parms[id + 1].items) {
197 "%s: you may specify either -id or -if, but not both switches\n",
205 PRights(afs_int32 arights, int dfs)
208 if (arights & PRSFS_READ)
210 if (arights & PRSFS_LOOKUP)
212 if (arights & PRSFS_INSERT)
214 if (arights & PRSFS_DELETE)
216 if (arights & PRSFS_WRITE)
218 if (arights & PRSFS_LOCK)
220 if (arights & PRSFS_ADMINISTER)
222 if (arights & PRSFS_USR0)
224 if (arights & PRSFS_USR1)
226 if (arights & PRSFS_USR2)
228 if (arights & PRSFS_USR3)
230 if (arights & PRSFS_USR4)
232 if (arights & PRSFS_USR5)
234 if (arights & PRSFS_USR6)
236 if (arights & PRSFS_USR7)
239 if (arights & DFS_READ)
243 if (arights & DFS_WRITE)
247 if (arights & DFS_EXECUTE)
251 if (arights & DFS_CONTROL)
255 if (arights & DFS_INSERT)
259 if (arights & DFS_DELETE)
263 if (arights & (DFS_USRALL))
265 if (arights & DFS_USR0)
267 if (arights & DFS_USR1)
269 if (arights & DFS_USR2)
271 if (arights & DFS_USR3)
273 if (arights & DFS_USR4)
275 if (arights & DFS_USR5)
277 if (arights & DFS_USR6)
279 if (arights & DFS_USR7)
284 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
288 struct ViceIoctl blob;
292 blob.out_size = MAXSIZE;
295 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
297 if ((errno == EINVAL) || (errno == ENOENT))
303 /* return a static pointer to a buffer */
308 strcpy(tspace, apath);
309 tp = strrchr(tspace, '/');
317 enum rtype { add, destroy, deny };
320 Convert(char *arights, int dfs, enum rtype *rtypep)
326 *rtypep = add; /* add rights, by default */
329 if (!strcmp(arights, "null")) {
333 if (!strcmp(arights, "read"))
334 return DFS_READ | DFS_EXECUTE;
335 if (!strcmp(arights, "write"))
336 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
338 if (!strcmp(arights, "all"))
339 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
340 DFS_WRITE | DFS_CONTROL;
342 if (!strcmp(arights, "read"))
343 return PRSFS_READ | PRSFS_LOOKUP;
344 if (!strcmp(arights, "write"))
345 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
346 PRSFS_WRITE | PRSFS_LOCK;
347 if (!strcmp(arights, "mail"))
348 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
349 if (!strcmp(arights, "all"))
350 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
351 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
353 if (!strcmp(arights, "none")) {
354 *rtypep = destroy; /* Remove entire entry */
357 len = strlen(arights);
359 for (i = 0; i < len; i++) {
393 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
401 mode |= PRSFS_LOOKUP;
403 mode |= PRSFS_INSERT;
405 mode |= PRSFS_DELETE;
411 mode |= PRSFS_ADMINISTER;
429 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
438 static struct AclEntry *
439 FindList(struct AclEntry *alist, char *aname)
442 if (!foldcmp(alist->name, aname))
449 /* if no parm specified in a particular slot, set parm to be "." instead */
451 SetDotDefault(struct cmd_item **aitemp)
455 return; /* already has value */
456 /* otherwise, allocate an item representing "." */
457 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
459 ti->next = (struct cmd_item *)0;
460 ti->data = (char *)malloc(2);
462 strcpy(ti->data, ".");
467 ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
469 struct AclEntry *tlist;
470 tlist = (plus ? al->pluslist : al->minuslist);
471 tlist = FindList(tlist, aname);
473 /* Found the item already in the list. */
474 tlist->rights = arights;
476 al->nplus -= PruneList(&al->pluslist, al->dfs);
478 al->nminus -= PruneList(&al->minuslist, al->dfs);
481 /* Otherwise we make a new item and plug in the new data. */
482 tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry));
484 strcpy(tlist->name, aname);
485 tlist->rights = arights;
487 tlist->next = al->pluslist;
488 al->pluslist = tlist;
490 if (arights == 0 || arights == -1)
491 al->nplus -= PruneList(&al->pluslist, al->dfs);
493 tlist->next = al->minuslist;
494 al->minuslist = tlist;
497 al->nminus -= PruneList(&al->minuslist, al->dfs);
502 ZapList(struct AclEntry *alist)
504 struct AclEntry *tp, *np;
505 for (tp = alist; tp; tp = np) {
512 PruneList(struct AclEntry **ae, int dfs)
514 struct AclEntry **lp;
515 struct AclEntry *te, *ne;
519 for (te = *ae; te; te = ne) {
520 if ((!dfs && te->rights == 0) || te->rights == -1) {
536 while (*astr != '\n')
543 * Create an empty acl, taking into account whether the acl pointed
544 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
545 * can recover from problems caused by bogus ACL's (in that case, always
546 * assume that the acl is AFS: for DFS, the user can always resort to
547 * acl_edit, but for AFS there may be no other way out).
555 tp = (struct Acl *)malloc(sizeof(struct Acl));
557 tp->nplus = tp->nminus = 0;
558 tp->pluslist = tp->minuslist = 0;
560 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
567 int nplus, nminus, i, trights;
569 struct AclEntry *first, *last, *tl;
572 ta = (struct Acl *)malloc(sizeof(struct Acl));
575 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
576 astr = SkipLine(astr);
577 sscanf(astr, "%d", &ta->nminus);
578 astr = SkipLine(astr);
585 for (i = 0; i < nplus; i++) {
586 sscanf(astr, "%100s %d", tname, &trights);
587 astr = SkipLine(astr);
588 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
592 strcpy(tl->name, tname);
593 tl->rights = trights;
599 ta->pluslist = first;
603 for (i = 0; i < nminus; i++) {
604 sscanf(astr, "%100s %d", tname, &trights);
605 astr = SkipLine(astr);
606 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
610 strcpy(tl->name, tname);
611 tl->rights = trights;
617 ta->minuslist = first;
623 PrintStatus(VolumeStatus * status, char *name, char *offmsg)
625 printf("Volume status for vid = %u named %s\n", status->Vid, name);
627 printf("Current offline message is %s\n", offmsg);
628 printf("Current disk quota is ");
629 if (status->MaxQuota != 0)
630 printf("%d\n", status->MaxQuota);
632 printf("unlimited\n");
633 printf("Current blocks used are %d\n", status->BlocksInUse);
634 printf("The partition has %d blocks available out of %d\n\n",
635 status->PartBlocksAvail, status->PartMaxBlocks);
640 QuickPrintStatus(VolumeStatus * status, char *name)
642 double QuotaUsed = 0.0;
643 double PartUsed = 0.0;
645 printf("%-25.25s", name);
647 if (status->MaxQuota != 0) {
648 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
650 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
652 printf(" no limit%10d", status->BlocksInUse);
654 if (QuotaUsed > 90.0) {
655 printf("%5.0f%%<<", QuotaUsed);
658 printf("%5.0f%% ", QuotaUsed);
661 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
663 if (PartUsed > 97.0) {
664 printf("%9.0f%%<<", PartUsed);
667 printf("%9.0f%% ", PartUsed);
669 printf(" <<WARNING\n");
676 QuickPrintSpace(VolumeStatus * status, char *name)
678 double PartUsed = 0.0;
680 printf("%-25.25s", name);
682 printf("%10d%10d%10d", status->PartMaxBlocks,
683 status->PartMaxBlocks - status->PartBlocksAvail,
684 status->PartBlocksAvail);
688 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
690 if (PartUsed > 90.0) {
691 printf(" %4.0f%%<<", PartUsed);
694 printf(" %4.0f%% ", PartUsed);
696 printf(" <<WARNING\n");
703 AclToString(struct Acl *acl)
705 static char mydata[MAXSIZE];
706 char tstring[MAXSIZE];
711 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
714 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
715 for (tp = acl->pluslist; tp; tp = tp->next) {
716 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
717 strcat(mydata, tstring);
719 for (tp = acl->minuslist; tp; tp = tp->next) {
720 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
721 strcat(mydata, tstring);
727 SetACLCmd(struct cmd_syndesc *as, void *arock)
730 struct ViceIoctl blob;
732 struct cmd_item *ti, *ui;
736 int idf = getidf(as, parm_setacl_id);
739 if (as->parms[2].items)
743 plusp = !(as->parms[3].items);
744 for (ti = as->parms[0].items; ti; ti = ti->next) {
745 blob.out_size = MAXSIZE;
747 blob.in = blob.out = space;
748 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
750 Die(errno, ti->data);
757 ta = ParseAcl(space);
758 if (!plusp && ta->dfs) {
760 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
762 "(you may specify \"null\" to revoke all rights, however)\n");
770 ta = EmptyAcl(space);
772 ta = ParseAcl(space);
773 CleanAcl(ta, ti->data);
774 for (ui = as->parms[1].items; ui; ui = ui->next->next) {
778 "%s: Missing second half of user/access pair.\n", pn);
782 rights = Convert(ui->next->data, ta->dfs, &rtype);
783 if (rtype == destroy && !ta->dfs) {
784 struct AclEntry *tlist;
786 tlist = (plusp ? ta->pluslist : ta->minuslist);
787 if (!FindList(tlist, ui->data))
790 if (rtype == deny && !ta->dfs)
792 if (rtype == destroy && ta->dfs)
794 ChangeList(ta, plusp, ui->data, rights);
796 blob.in = AclToString(ta);
798 blob.in_size = 1 + strlen(blob.in);
799 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
801 if (errno == EINVAL) {
803 static char *fsenv = 0;
805 fsenv = (char *)getenv("FS_EXPERT");
808 "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n",
812 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
813 "\nPossible reasons for this include:\n\n",
814 " -You may have specified an inappropriate combination of rights.\n",
815 " For example, some DFS-supported filesystems may not allow you to\n",
816 " drop the \"c\" right from \"user_obj\".\n\n",
817 " -A mask_obj may be required (it is likely required by the underlying\n",
818 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
819 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
820 " does not automatically create or update the mask_obj. Try setting\n",
821 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
822 " users or groups. You can do this with a single command, such as\n",
823 " \"fs sa mask_obj all user:somename read\"\n\n",
824 " -A specified user or group may not exist.\n\n",
825 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
826 " This is probably not allowed by the underlying file system.\n\n",
827 " -If you add a user or group to a DFS ACL, remember that it must be\n",
828 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
829 " may be local requirements on the format of the user or group name.\n",
830 " Check with your cell administrator.\n\n",
831 " -Or numerous other possibilities. It would be great if we could be more\n",
832 " precise about the actual problem, but for various reasons, this is\n",
833 " impractical via this interface. If you can't figure it out, you\n",
834 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
835 " whatever is provided). You may get better results. Good luck!\n\n",
836 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
840 "%s: Invalid argument, possible reasons include:\n",
842 fprintf(stderr, "\t-File not in AFS\n");
844 "\t-Too many users on access control list\n");
846 "\t-Tried to add non-existent user to access control list\n");
849 Die(errno, ti->data);
861 CopyACLCmd(struct cmd_syndesc *as, void *arock)
864 struct ViceIoctl blob;
865 struct Acl *fa, *ta = 0;
867 struct cmd_item *ti, *ui;
871 int idf = getidf(as, parm_copyacl_id);
874 if (as->parms[2].items)
878 blob.out_size = MAXSIZE;
880 blob.in = blob.out = space;
881 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
883 Die(errno, as->parms[0].items->data);
886 fa = ParseAcl(space);
887 CleanAcl(fa, as->parms[0].items->data);
888 for (ti = as->parms[1].items; ti; ti = ti->next) {
889 blob.out_size = MAXSIZE;
891 blob.in = blob.out = space;
892 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
894 Die(errno, ti->data);
902 ta = EmptyAcl(space);
904 ta = ParseAcl(space);
905 CleanAcl(ta, ti->data);
906 if (ta->dfs != fa->dfs) {
908 "%s: incompatible file system types: acl not copied to %s; aborted\n",
914 if (!clear && strcmp(ta->cell, fa->cell) != 0) {
916 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
921 strcpy(ta->cell, fa->cell);
923 for (tp = fa->pluslist; tp; tp = tp->next)
924 ChangeList(ta, 1, tp->name, tp->rights);
925 for (tp = fa->minuslist; tp; tp = tp->next)
926 ChangeList(ta, 0, tp->name, tp->rights);
927 blob.in = AclToString(ta);
929 blob.in_size = 1 + strlen(blob.in);
930 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
932 if (errno == EINVAL) {
934 "%s: Invalid argument, possible reasons include:\n",
936 fprintf(stderr, "\t-File not in AFS\n");
938 Die(errno, ti->data);
949 /* pioctl() call to get the cellname of a pathname */
951 GetCell(char *fname, char *cellname)
954 struct ViceIoctl blob;
957 blob.out_size = MAXCELLCHARS;
960 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
961 return code ? errno : 0;
964 /* Check if a username is valid: If it contains only digits (or a
965 * negative sign), then it might be bad. We then query the ptserver
969 BadName(char *aname, char *fname)
971 afs_int32 tc, code, id;
973 char cell[MAXCELLCHARS];
975 for (nm = aname; tc = *nm; nm++) {
976 /* all must be '-' or digit to be bad */
977 if (tc != '-' && (tc < '0' || tc > '9'))
981 /* Go to the PRDB and see if this all number username is valid */
982 code = GetCell(fname, cell);
986 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
987 code = pr_SNameToId(aname, &id);
990 /* 1=>Not-valid; 0=>Valid */
991 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
995 /* clean up an access control list of its bad entries; return 1 if we made
996 any changes to the list, and 0 otherwise */
998 CleanAcl(struct Acl *aa, char *fname)
1000 struct AclEntry *te, **le, *ne;
1003 /* Don't correct DFS ACL's for now */
1007 /* prune out bad entries */
1008 changes = 0; /* count deleted entries */
1010 for (te = aa->pluslist; te; te = ne) {
1012 if (BadName(te->name, fname)) {
1022 le = &aa->minuslist;
1023 for (te = aa->minuslist; te; te = ne) {
1025 if (BadName(te->name, fname)) {
1039 /* clean up an acl to not have bogus entries */
1041 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1045 struct ViceIoctl blob;
1047 struct cmd_item *ti;
1048 struct AclEntry *te;
1051 SetDotDefault(&as->parms[0].items);
1052 for (ti = as->parms[0].items; ti; ti = ti->next) {
1053 blob.out_size = MAXSIZE;
1056 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1058 Die(errno, ti->data);
1065 ta = ParseAcl(space);
1068 "%s: cleanacl is not supported for DFS access lists.\n",
1074 changes = CleanAcl(ta, ti->data);
1077 /* now set the acl */
1078 blob.in = AclToString(ta);
1079 blob.in_size = strlen(blob.in) + 1;
1081 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1083 if (errno == EINVAL) {
1085 "%s: Invalid argument, possible reasons include\n",
1087 fprintf(stderr, "%s: File not in vice or\n", pn);
1089 "%s: Too many users on access control list or\n",
1092 Die(errno, ti->data);
1098 /* now list the updated acl */
1099 printf("Access list for %s is now\n", ti->data);
1100 if (ta->nplus > 0) {
1102 printf("Normal rights:\n");
1103 for (te = ta->pluslist; te; te = te->next) {
1104 printf(" %s ", te->name);
1105 PRights(te->rights, ta->dfs);
1109 if (ta->nminus > 0) {
1110 printf("Negative rights:\n");
1111 for (te = ta->minuslist; te; te = te->next) {
1112 printf(" %s ", te->name);
1113 PRights(te->rights, ta->dfs);
1120 printf("Access list for %s is fine.\n", ti->data);
1128 ListACLCmd(struct cmd_syndesc *as, void *arock)
1132 struct ViceIoctl blob;
1133 struct AclEntry *te;
1134 struct cmd_item *ti;
1135 int idf = getidf(as, parm_listacl_id);
1138 SetDotDefault(&as->parms[0].items);
1139 for (ti = as->parms[0].items; ti; ti = ti->next) {
1140 blob.out_size = MAXSIZE;
1142 blob.in = blob.out = space;
1143 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1145 Die(errno, ti->data);
1149 ta = ParseAcl(space);
1152 printf("Access list for %s is\n", ti->data);
1155 printf("DFS access list for %s is\n", ti->data);
1158 printf("DFS initial directory access list of %s is\n", ti->data);
1161 printf("DFS initial file access list of %s is\n", ti->data);
1165 printf(" Default cell = %s\n", ta->cell);
1167 if (ta->nplus > 0) {
1169 printf("Normal rights:\n");
1170 for (te = ta->pluslist; te; te = te->next) {
1171 printf(" %s ", te->name);
1172 PRights(te->rights, ta->dfs);
1176 if (ta->nminus > 0) {
1177 printf("Negative rights:\n");
1178 for (te = ta->minuslist; te; te = te->next) {
1179 printf(" %s ", te->name);
1180 PRights(te->rights, ta->dfs);
1192 GetCallerAccess(struct cmd_syndesc *as, void *arock)
1194 struct cmd_item *ti;
1197 SetDotDefault(&as->parms[0].items);
1198 for (ti = as->parms[0].items; ti; ti = ti->next) {
1200 struct ViceIoctl blob;
1201 struct vcxstat2 stat;
1202 blob.out_size = sizeof(struct vcxstat2);
1204 blob.out = (void *)&stat;
1205 code = pioctl(ti->data, VIOC_GETVCXSTATUS2, &blob, 1);
1207 Die(errno, ti->data);
1211 printf("Callers access to %s is ", ti->data);
1212 PRights(stat.callerAccess, 0);
1219 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1222 struct ViceIoctl blob;
1223 struct cmd_item *ti;
1226 SetDotDefault(&as->parms[0].items);
1227 for (ti = as->parms[0].items; ti; ti = ti->next) {
1228 blob.in_size = blob.out_size = 0;
1229 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1231 fprintf(stderr, "Error flushing volume ");
1241 * The Windows version of UuidCmd displays the UUID.
1242 * When the UNIX version is updated to do the same
1243 * be sure to replace the CMD_REQUIRED flag with
1244 * CMD_OPTIONAL in the cmd_AddParam(-generate) call
1247 UuidCmd(struct cmd_syndesc *as, void *arock)
1250 struct ViceIoctl blob;
1255 if (as->parms[0].items) {
1257 fprintf (stderr, "Permission denied: requires root access.\n");
1261 /* generate new UUID */
1262 code = pioctl(0, VIOC_NEWUUID, &blob, 1);
1269 printf("New uuid generated.\n");
1271 /* This will never execute */
1272 printf("Please add the '-generate' option to generate a new UUID.\n");
1278 FlushCmd(struct cmd_syndesc *as, void *arock)
1281 struct ViceIoctl blob;
1282 struct cmd_item *ti;
1285 for (ti = as->parms[0].items; ti; ti = ti->next) {
1286 blob.in_size = blob.out_size = 0;
1287 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1289 if (errno == EMFILE) {
1290 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1293 fprintf(stderr, "%s: Error flushing file ", pn);
1303 /* all this command does is repackage its args and call SetVolCmd */
1305 SetQuotaCmd(struct cmd_syndesc *as, void *arock)
1307 struct cmd_syndesc ts;
1309 /* copy useful stuff from our command slot; we may later have to reorder */
1310 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1311 return SetVolCmd(&ts, arock);
1315 SetVolCmd(struct cmd_syndesc *as, void *arock)
1318 struct ViceIoctl blob;
1319 struct cmd_item *ti;
1320 struct VolumeStatus *status;
1321 char *offmsg, *input;
1324 SetDotDefault(&as->parms[0].items);
1325 for (ti = as->parms[0].items; ti; ti = ti->next) {
1327 blob.out_size = MAXSIZE;
1328 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1331 status = (VolumeStatus *) space;
1332 status->MinQuota = status->MaxQuota = -1;
1334 if (as->parms[1].items) {
1335 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1337 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1342 if (as->parms[2].items)
1343 offmsg = as->parms[2].items->data;
1344 input = (char *)status + sizeof(*status);
1345 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1347 if (strlen(offmsg) >= VMSGSIZE) {
1349 "%s: message must be shorter than %d characters\n",
1354 strcpy(input, offmsg);
1355 blob.in_size += strlen(offmsg);
1356 input += strlen(offmsg) + 1;
1359 *(input++) = '\0'; /* Pad for old style volume "motd" */
1360 code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1);
1362 Die(errno, ti->data);
1370 * Why is VenusFid declared in the kernel-only section of afs.h,
1371 * if it's the exported interface of the cache manager?
1379 ExamineCmd(struct cmd_syndesc *as, void *arock)
1382 struct ViceIoctl blob;
1383 struct cmd_item *ti;
1384 struct VolumeStatus *status;
1385 char *name, *offmsg;
1388 SetDotDefault(&as->parms[0].items);
1389 for (ti = as->parms[0].items; ti; ti = ti->next) {
1390 struct VenusFid vfid;
1393 blob.out_size = MAXSIZE;
1396 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1398 Die(errno, ti->data);
1402 status = (VolumeStatus *) space;
1403 name = (char *)status + sizeof(*status);
1404 offmsg = name + strlen(name) + 1;
1406 blob.out_size = sizeof(struct VenusFid);
1407 blob.out = (char *) &vfid;
1408 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1409 printf("File %s (%u.%u.%u) contained in volume %u\n",
1410 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1414 PrintStatus(status, name, offmsg);
1420 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1423 struct ViceIoctl blob;
1424 struct cmd_item *ti;
1425 struct VolumeStatus *status;
1429 printf("%-25s%-10s%-10s%-7s%-11s\n", "Volume Name", " Quota",
1430 " Used", " %Used", " Partition");
1431 SetDotDefault(&as->parms[0].items);
1432 for (ti = as->parms[0].items; ti; ti = ti->next) {
1434 blob.out_size = MAXSIZE;
1437 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1439 Die(errno, ti->data);
1443 status = (VolumeStatus *) space;
1444 name = (char *)status + sizeof(*status);
1445 QuickPrintStatus(status, name);
1451 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1454 struct ViceIoctl blob;
1455 struct cmd_item *ti;
1461 SetDotDefault(&as->parms[0].items);
1462 for (ti = as->parms[0].items; ti; ti = ti->next) {
1464 blob.out_size = MAXSIZE;
1467 memset(space, 0, sizeof(space));
1468 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1470 Die(errno, ti->data);
1474 hosts = (afs_int32 *) space;
1475 printf("File %s is on host%s ", ti->data,
1476 (hosts[0] && !hosts[1]) ? "" : "s");
1477 for (j = 0; j < MAXHOSTS; j++) {
1480 tp = hostutil_GetNameByINet(hosts[j]);
1490 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1493 struct ViceIoctl blob;
1494 struct cmd_item *ti;
1496 struct VolumeStatus *status;
1499 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1500 " used", " avail", " %used");
1501 SetDotDefault(&as->parms[0].items);
1502 for (ti = as->parms[0].items; ti; ti = ti->next) {
1504 blob.out_size = MAXSIZE;
1507 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1509 Die(errno, ti->data);
1513 status = (VolumeStatus *) space;
1514 name = (char *)status + sizeof(*status);
1515 QuickPrintSpace(status, name);
1521 QuotaCmd(struct cmd_syndesc *as, void *arock)
1524 struct ViceIoctl blob;
1525 struct cmd_item *ti;
1527 struct VolumeStatus *status;
1530 SetDotDefault(&as->parms[0].items);
1531 for (ti = as->parms[0].items; ti; ti = ti->next) {
1533 blob.out_size = MAXSIZE;
1536 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1538 Die(errno, ti->data);
1542 status = (VolumeStatus *) space;
1543 if (status->MaxQuota)
1545 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
1548 printf("%2.0f%% of quota used.\n", quotaPct);
1554 ListMountCmd(struct cmd_syndesc *as, void *arock)
1557 struct ViceIoctl blob;
1558 struct cmd_item *ti;
1559 char orig_name[1024]; /*Original name, may be modified */
1560 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
1561 char parent_dir[1024]; /*Parent directory of true name */
1562 char *last_component; /*Last component of true name */
1563 struct stat statbuff; /*Buffer for status info */
1564 int link_chars_read; /*Num chars read in readlink() */
1565 int thru_symlink; /*Did we get to a mount point via a symlink? */
1568 for (ti = as->parms[0].items; ti; ti = ti->next) {
1571 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
1574 if (lstat(orig_name, &statbuff) < 0) {
1575 /* if lstat fails, we should still try the pioctl, since it
1576 * may work (for example, lstat will fail, but pioctl will
1577 * work if the volume of offline (returning ENODEV). */
1578 statbuff.st_mode = S_IFDIR; /* lie like pros */
1582 * The lstat succeeded. If the given file is a symlink, substitute
1583 * the file name with the link name.
1585 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1588 * Read name of resolved file.
1590 link_chars_read = readlink(orig_name, true_name, 1024);
1591 if (link_chars_read <= 0) {
1593 "%s: Can't read target name for '%s' symbolic link!\n",
1600 * Add a trailing null to what was read, bump the length.
1602 true_name[link_chars_read++] = 0;
1605 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1606 * have to create a full pathname using the original name and the
1607 * relative symlink name. Find the rightmost slash in the original
1608 * name (we know there is one) and splice in the symlink value.
1610 if (true_name[0] != '/') {
1611 last_component = (char *)strrchr(orig_name, '/');
1612 strcpy(++last_component, true_name);
1613 strcpy(true_name, orig_name);
1616 strcpy(true_name, orig_name);
1619 * Find rightmost slash, if any.
1621 last_component = (char *)strrchr(true_name, '/');
1622 if (last_component) {
1624 * Found it. Designate everything before it as the parent directory,
1625 * everything after it as the final component.
1627 strncpy(parent_dir, true_name, last_component - true_name);
1628 parent_dir[last_component - true_name] = 0;
1629 last_component++; /*Skip the slash */
1632 * No slash appears in the given file name. Set parent_dir to the current
1633 * directory, and the last component as the given name.
1635 strcpy(parent_dir, ".");
1636 last_component = true_name;
1639 if (strcmp(last_component, ".") == 0
1640 || strcmp(last_component, "..") == 0) {
1642 "%s: you may not use '.' or '..' as the last component\n",
1644 fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n",
1650 blob.in = last_component;
1651 blob.in_size = strlen(last_component) + 1;
1652 blob.out_size = MAXSIZE;
1654 memset(space, 0, MAXSIZE);
1656 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1659 printf("'%s' is a %smount point for volume '%s'\n", ti->data,
1660 (thru_symlink ? "symbolic link, leading to a " : ""),
1663 if (errno == EINVAL) {
1664 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
1666 Die(errno, (ti->data ? ti->data : parent_dir));
1675 MakeMountCmd(struct cmd_syndesc *as, void *arock)
1678 char *cellName, *volName, *tmpName;
1679 struct afsconf_cell info;
1680 struct vldbentry vldbEntry;
1681 struct ViceIoctl blob;
1687 if (as->parms[5].items && !as->parms[2].items) {
1688 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1693 if (as->parms[2].items) /* cell name specified */
1694 cellName = as->parms[2].items->data;
1697 volName = as->parms[1].items->data;
1699 if (strlen(volName) >= 64) {
1701 "%s: volume name too long (length must be < 64 characters)\n",
1706 /* Check for a cellname in the volume specification, and complain
1707 * if it doesn't match what was specified with -cell */
1708 if (tmpName = strchr(volName, ':')) {
1711 if (strcasecmp(cellName, volName)) {
1712 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1717 volName = ++tmpName;
1720 if (!InAFS(Parent(as->parms[0].items->data))) {
1722 "%s: mount points must be created within the AFS file system\n",
1729 blob.out_size = MAXSIZE;
1732 pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME,
1736 code = GetCellName(cellName ? cellName : space, &info);
1740 if (!(as->parms[4].items)) {
1741 /* not fast, check which cell the mountpoint is being created in */
1742 /* not fast, check name with VLDB */
1743 code = VLDBInit(1, &info);
1745 /* make the check. Don't complain if there are problems with init */
1747 ubik_VL_GetEntryByNameO(uclient, 0, volName,
1749 if (code == VL_NOENT) {
1751 "%s: warning, volume %s does not exist in cell %s.\n",
1752 pn, volName, cellName ? cellName : space);
1757 if (as->parms[3].items) /* if -rw specified */
1762 /* cellular mount point, prepend cell prefix */
1763 strcat(space, info.name);
1766 strcat(space, volName); /* append volume name */
1767 strcat(space, "."); /* stupid convention; these end with a period */
1768 code = symlink(space, as->parms[0].items->data);
1770 Die(errno, as->parms[0].items->data);
1777 * Delete AFS mount points. Variables are used as follows:
1778 * tbuffer: Set to point to the null-terminated directory name of the mount point
1779 * (or ``.'' if none is provided)
1780 * tp: Set to point to the actual name of the mount point to nuke.
1783 RemoveMountCmd(struct cmd_syndesc *as, void *arock)
1786 struct ViceIoctl blob;
1787 struct cmd_item *ti;
1789 char lsbuffer[1024];
1793 for (ti = as->parms[0].items; ti; ti = ti->next) {
1795 tp = (char *)strrchr(ti->data, '/');
1797 strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */
1799 tp++; /* skip the slash */
1801 strcpy(tbuffer, ".");
1805 blob.in_size = strlen(tp) + 1;
1806 blob.out = lsbuffer;
1807 blob.out_size = sizeof(lsbuffer);
1808 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1810 if (errno == EINVAL) {
1811 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
1814 Die(errno, ti->data);
1817 continue; /* don't bother trying */
1821 blob.in_size = strlen(tp) + 1;
1822 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1824 Die(errno, ti->data);
1835 CheckServersCmd(struct cmd_syndesc *as, void *arock)
1838 struct ViceIoctl blob;
1844 struct afsconf_cell info;
1845 struct chservinfo checkserv;
1847 memset(&checkserv, 0, sizeof(struct chservinfo));
1848 blob.in_size = sizeof(struct chservinfo);
1849 blob.in = (caddr_t) & checkserv;
1851 blob.out_size = MAXSIZE;
1853 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1855 /* prepare flags for checkservers command */
1856 temp = 2; /* default to checking local cell only */
1857 if (as->parms[2].items)
1858 temp |= 1; /* set fast flag */
1859 if (as->parms[1].items)
1860 temp &= ~2; /* turn off local cell check */
1862 checkserv.magic = 0x12345678; /* XXX */
1863 checkserv.tflags = temp;
1865 /* now copy in optional cell name, if specified */
1866 if (as->parms[0].items) {
1867 code = GetCellName(as->parms[0].items->data, &info);
1871 strcpy(checkserv.tbuffer, info.name);
1872 checkserv.tsize = strlen(info.name) + 1;
1874 strcpy(checkserv.tbuffer, "\0");
1875 checkserv.tsize = 0;
1878 if (as->parms[3].items) {
1879 checkserv.tinterval = atol(as->parms[3].items->data);
1882 if (checkserv.tinterval < 0) {
1884 ("Warning: The negative -interval is ignored; treated as an inquiry\n");
1885 checkserv.tinterval = 0;
1886 } else if (checkserv.tinterval > 600) {
1888 ("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1889 checkserv.tinterval = 600; /* 10 min max interval */
1892 checkserv.tinterval = -1; /* don't change current interval */
1895 code = pioctl(0, VIOCCKSERV, &blob, 1);
1897 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1898 printf("Must be root to change -interval\n");
1904 memcpy(&temp, space, sizeof(afs_int32));
1905 if (checkserv.tinterval >= 0) {
1906 if (checkserv.tinterval > 0)
1908 ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1909 checkserv.tinterval, temp);
1911 printf("The current down server probe interval is %d secs\n",
1916 printf("All servers are running.\n");
1919 ("These servers unavailable due to network or server problems: ");
1921 memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32));
1924 tp = hostutil_GetNameByINet(temp);
1934 MessagesCmd(struct cmd_syndesc *as, void *arock)
1937 struct ViceIoctl blob;
1940 struct gaginfo gagflags;
1941 struct cmd_item *show;
1943 memset(&gagflags, 0, sizeof(struct gaginfo));
1944 blob.in_size = sizeof(struct gaginfo);
1945 blob.in = (caddr_t) & gagflags;
1946 blob.out_size = MAXSIZE;
1948 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1950 if (show = as->parms[0].items) {
1951 if (!strcasecmp(show->data, "user"))
1952 gagflags.showflags |= GAGUSER;
1953 else if (!strcasecmp(show->data, "console"))
1954 gagflags.showflags |= GAGCONSOLE;
1955 else if (!strcasecmp(show->data, "all"))
1956 gagflags.showflags |= GAGCONSOLE | GAGUSER;
1957 else if (!strcasecmp(show->data, "none"))
1961 "unrecognized flag %s: must be in {user,console,all,none}\n",
1970 code = pioctl(0, VIOC_GAG, &blob, 1);
1980 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
1983 struct ViceIoctl blob;
1987 code = pioctl(0, VIOCCKBACK, &blob, 1);
1993 printf("All volumeID/name mappings checked.\n");
1998 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2001 struct ViceIoctl blob;
2004 if (!as->parms[0].items && !as->parms[1].items) {
2005 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
2008 if (as->parms[0].items) {
2009 code = util_GetInt32(as->parms[0].items->data, &temp);
2011 fprintf(stderr, "%s: bad integer specified for cache size.\n",
2017 blob.in = (char *)&temp;
2018 blob.in_size = sizeof(afs_int32);
2020 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2022 if (errno == EROFS) {
2024 ("'fs setcache' not allowed on memory cache based cache managers.\n");
2031 printf("New cache size set.\n");
2035 #define MAXGCSIZE 16
2037 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2039 afs_int32 code, filesUsed;
2040 struct ViceIoctl blob;
2041 afs_int32 parms[MAXGCSIZE];
2042 double percentFiles, percentBlocks;
2043 afs_int32 flags = 0;
2045 if (as->parms[0].items){ /* -files */
2047 } else if (as->parms[1].items){ /* -excessive */
2053 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
2055 blob.in = (char *)&flags;
2056 blob.in_size = sizeof(afs_int32);
2057 } else { /* be backward compatible */
2061 blob.out_size = sizeof(parms);
2062 blob.out = (char *)parms;
2063 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2070 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2071 parms[1], parms[0]);
2072 if (parms[1] > parms[0])
2073 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2077 percentBlocks = ((double)parms[1]/parms[0]) * 100;
2078 printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n",
2079 percentBlocks, parms[1], parms[0]);
2084 filesUsed = parms[2] - parms[3];
2085 percentFiles = ((double)filesUsed/parms[2]) * 100;
2086 printf(" %5.0f%% of the cache files (%d of %d files)\n",
2087 percentFiles, filesUsed, parms[2]);
2089 printf(" afs_cacheFiles: %10d\n", parms[2]);
2090 printf(" IFFree: %10d\n", parms[3]);
2091 printf(" IFEverUsed: %10d\n", parms[4]);
2092 printf(" IFDataMod: %10d\n", parms[5]);
2093 printf(" IFDirtyPages: %10d\n", parms[6]);
2094 printf(" IFAnyPages: %10d\n", parms[7]);
2095 printf(" IFDiscarded: %10d\n", parms[8]);
2096 printf(" DCentries: %10d\n", parms[9]);
2097 printf(" 0k- 4K: %10d\n", parms[10]);
2098 printf(" 4k- 16k: %10d\n", parms[11]);
2099 printf(" 16k- 64k: %10d\n", parms[12]);
2100 printf(" 64k- 256k: %10d\n", parms[13]);
2101 printf(" 256k- 1M: %10d\n", parms[14]);
2102 printf(" >=1M: %10d\n", parms[15]);
2105 if (percentBlocks > 90)
2106 printf("[cache size usage over 90%, consider increasing cache size]\n");
2107 if (percentFiles > 90)
2108 printf("[cache file usage over 90%, consider increasing '-files' argument to afsd]\n");
2114 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2120 struct ViceIoctl blob;
2123 resolve = !(as->parms[0].items); /* -numeric */
2127 memcpy(tp, &i, sizeof(afs_int32));
2128 blob.out_size = MAXSIZE;
2129 blob.in_size = sizeof(afs_int32);
2132 code = pioctl(0, VIOCGETCELL, &blob, 1);
2135 break; /* done with the list */
2140 printf("Cell %s on hosts", tp + MAXCELLHOSTS * sizeof(afs_int32));
2141 for (j = 0; j < MAXCELLHOSTS; j++) {
2143 char *name, tbuffer[20];
2145 memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32));
2150 name = hostutil_GetNameByINet(addr);
2153 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2154 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2157 printf(" %s", name);
2165 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2168 char *tp, *aliasName, *realName;
2169 struct ViceIoctl blob;
2173 memcpy(tp, &i, sizeof(afs_int32));
2174 blob.out_size = MAXSIZE;
2175 blob.in_size = sizeof(afs_int32);
2178 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2181 break; /* done with the list */
2187 tp += strlen(aliasName) + 1;
2189 printf("Alias %s for cell %s\n", aliasName, realName);
2195 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2198 struct ViceIoctl blob;
2199 struct cmd_item *ti;
2201 struct hostent *thp;
2205 ti = as->parms[0].items;
2208 thp = hostutil_GetHostByName(ti->data);
2210 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2213 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2215 hostAddr = 0; /* means don't set host */
2216 setp = 0; /* aren't setting host */
2219 /* now do operation */
2220 blob.in_size = sizeof(afs_int32);
2221 blob.out_size = sizeof(afs_int32);
2222 blob.in = (char *) &hostAddr;
2223 blob.out = (char *) &hostAddr;
2225 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2234 NukeNFSCredsCmd(struct cmd_syndesc *as, void *arock)
2237 struct ViceIoctl blob;
2238 struct cmd_item *ti;
2240 struct hostent *thp;
2242 ti = as->parms[0].items;
2243 thp = hostutil_GetHostByName(ti->data);
2245 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2248 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2250 /* now do operation */
2251 blob.in_size = sizeof(afs_int32);
2252 blob.out_size = sizeof(afs_int32);
2253 blob.in = (char *) &hostAddr;
2254 blob.out = (char *) &hostAddr;
2256 code = pioctl(0, VIOC_NFS_NUKE_CREDS, &blob, 1);
2265 NewCellCmd(struct cmd_syndesc *as, void *arock)
2267 afs_int32 code, linkedstate = 0, size = 0, *lp;
2268 struct ViceIoctl blob;
2269 struct cmd_item *ti;
2270 char *tp, *cellname = 0;
2271 struct hostent *thp;
2272 afs_int32 fsport = 0, vlport = 0;
2273 afs_int32 magic, scount; /* Number of servers to pass in pioctl call */
2276 * With the NEWCELL pioctl call, 3.4 clients take an array of
2277 * MAXHOSTS (13) servers while 3.5 clients take an array of
2278 * MAXCELLHOSTS (8) servers. To determine which we are talking to,
2279 * do a GETCELL pioctl and pass it a magic number. If an array of
2280 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
2281 * If we get back EDOM, there are no cells in the kernel yet,
2282 * and we'll assume a 3.5 client.
2285 lp = (afs_int32 *) tp;
2286 *lp++ = 0; /* first cell entry */
2287 *lp = 0x12345678; /* magic */
2288 blob.out_size = MAXSIZE;
2289 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
2292 code = pioctl(0, VIOCGETCELL, &blob, 1);
2293 if (code < 0 && errno != EDOM) {
2297 if (code < 1 && errno == EDOM) {
2301 cellname = tp + MAXCELLHOSTS * sizeof(afs_int32);
2302 scount = ((cellname[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2305 /* Now setup and do the NEWCELL pioctl call */
2306 memset(space, 0, (scount + 1) * sizeof(afs_int32));
2308 lp = (afs_int32 *) tp;
2310 tp += sizeof(afs_int32);
2311 for (ti = as->parms[1].items; ti; ti = ti->next) {
2312 thp = hostutil_GetHostByName(ti->data);
2315 "%s: Host %s not found in host table, skipping it.\n", pn,
2318 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2319 tp += sizeof(afs_int32);
2322 if (as->parms[2].items) {
2324 * Link the cell, for the purposes of volume location, to the specified
2327 cellname = as->parms[2].items->data;
2330 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2331 if (as->parms[3].items) {
2332 code = util_GetInt32(as->parms[3].items->data, &vlport);
2335 "%s: bad integer specified for the fileserver port.\n",
2340 if (as->parms[4].items) {
2341 code = util_GetInt32(as->parms[4].items->data, &fsport);
2344 "%s: bad integer specified for the vldb server port.\n",
2350 tp = (char *)(space + (scount + 1) * sizeof(afs_int32));
2351 lp = (afs_int32 *) tp;
2355 strcpy(space + ((scount + 4) * sizeof(afs_int32)),
2356 as->parms[0].items->data);
2357 size = ((scount + 4) * sizeof(afs_int32))
2358 + strlen(as->parms[0].items->data)
2359 + 1 /* for null */ ;
2360 tp = (char *)(space + size);
2362 strcpy(tp, cellname);
2363 size += strlen(cellname) + 1;
2365 blob.in_size = size;
2368 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2377 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2380 struct ViceIoctl blob;
2382 char *aliasName, *realName;
2384 /* Now setup and do the NEWCELL pioctl call */
2385 aliasName = as->parms[0].items->data;
2386 realName = as->parms[1].items->data;
2388 strcpy(tp, aliasName);
2389 tp += strlen(aliasName) + 1;
2390 strcpy(tp, realName);
2391 tp += strlen(realName) + 1;
2393 blob.in_size = tp - space;
2397 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2399 if (errno == EEXIST) {
2401 "%s: cell name `%s' in use by an existing cell.\n", pn,
2412 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2415 struct cmd_item *ti;
2417 char cell[MAXCELLCHARS];
2419 SetDotDefault(&as->parms[0].items);
2420 for (ti = as->parms[0].items; ti; ti = ti->next) {
2421 code = GetCell(ti->data, cell);
2423 if (errno == ENOENT)
2424 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
2426 Die(errno, ti->data);
2431 printf("File %s lives in cell '%s'\n", ti->data, cell);
2437 WSCellCmd(struct cmd_syndesc *as, void *arock)
2440 struct ViceIoctl blob;
2444 blob.out_size = MAXSIZE;
2447 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2453 printf("This workstation belongs to cell '%s'\n", space);
2458 static PrimaryCellCmd(as)
2459 struct cmd_syndesc *as;
2461 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2467 MonitorCmd(struct cmd_syndesc *as, void *arock)
2470 struct ViceIoctl blob;
2471 struct cmd_item *ti;
2473 struct hostent *thp;
2477 ti = as->parms[0].items;
2481 if (!strcmp(ti->data, "off"))
2482 hostAddr = 0xffffffff;
2484 thp = hostutil_GetHostByName(ti->data);
2486 if (!strcmp(ti->data, "localhost")) {
2488 "localhost not in host table, assuming 127.0.0.1\n");
2489 hostAddr = htonl(0x7f000001);
2491 fprintf(stderr, "host %s not found in host table.\n",
2496 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2499 hostAddr = 0; /* means don't set host */
2500 setp = 0; /* aren't setting host */
2503 /* now do operation */
2504 blob.in_size = sizeof(afs_int32);
2505 blob.out_size = sizeof(afs_int32);
2506 blob.in = (char *)&hostAddr;
2507 blob.out = (char *)&hostAddr;
2508 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2514 printf("%s: new monitor host set.\n", pn);
2516 /* now decode old address */
2517 if (hostAddr == 0xffffffff) {
2518 printf("Cache monitoring is currently disabled.\n");
2520 tp = hostutil_GetNameByINet(hostAddr);
2521 printf("Using host %s for monitor services.\n", tp);
2528 SysNameCmd(struct cmd_syndesc *as, void *arock)
2531 struct ViceIoctl blob;
2532 struct cmd_item *ti;
2533 char *input = space;
2536 ti = as->parms[0].items;
2539 blob.out_size = MAXSIZE;
2540 blob.in_size = sizeof(afs_int32);
2541 input += sizeof(afs_int32);
2542 for (; ti; ti = ti->next) {
2544 blob.in_size += strlen(ti->data) + 1;
2545 if (blob.in_size > MAXSIZE) {
2546 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2547 setp > 1 ? "s" : "");
2550 strcpy(input, ti->data);
2551 input += strlen(ti->data);
2554 memcpy(space, &setp, sizeof(afs_int32));
2555 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2561 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2565 memcpy(&setp, input, sizeof(afs_int32));
2566 input += sizeof(afs_int32);
2568 fprintf(stderr, "No sysname name value was found\n");
2571 printf("Current sysname%s is", setp > 1 ? " list" : "");
2572 for (; setp > 0; --setp) {
2573 printf(" \'%s\'", input);
2574 input += strlen(input) + 1;
2580 static char *exported_types[] = { "null", "nfs", "" };
2582 ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2585 struct ViceIoctl blob;
2586 struct cmd_item *ti;
2587 int export = 0, type = 0, mode = 0, exp = 0, exportcall, pwsync =
2588 0, smounts = 0, clipags = 0, pagcb = 0;
2590 ti = as->parms[0].items;
2591 if (strcmp(ti->data, "nfs") == 0)
2592 type = 0x71; /* NFS */
2595 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n",
2599 ti = as->parms[1].items;
2601 if (strcmp(ti->data, "on") == 0)
2603 else if (strcmp(ti->data, "off") == 0)
2606 fprintf(stderr, "Illegal argument %s\n", ti->data);
2611 if (ti = as->parms[2].items) { /* -noconvert */
2612 if (strcmp(ti->data, "on") == 0)
2614 else if (strcmp(ti->data, "off") == 0)
2617 fprintf(stderr, "Illegal argument %s\n", ti->data);
2621 if (ti = as->parms[3].items) { /* -uidcheck */
2622 if (strcmp(ti->data, "on") == 0)
2624 else if (strcmp(ti->data, "off") == 0)
2627 fprintf(stderr, "Illegal argument %s\n", ti->data);
2631 if (ti = as->parms[4].items) { /* -submounts */
2632 if (strcmp(ti->data, "on") == 0)
2634 else if (strcmp(ti->data, "off") == 0)
2637 fprintf(stderr, "Illegal argument %s\n", ti->data);
2641 if (ti = as->parms[5].items) { /* -clipags */
2642 if (strcmp(ti->data, "on") == 0)
2644 else if (strcmp(ti->data, "off") == 0)
2647 fprintf(stderr, "Illegal argument %s\n", ti->data);
2651 if (ti = as->parms[6].items) { /* -pagcb */
2652 if (strcmp(ti->data, "on") == 0)
2654 else if (strcmp(ti->data, "off") == 0)
2657 fprintf(stderr, "Illegal argument %s\n", ti->data);
2662 (type << 24) | (pagcb << 10) | (clipags << 8) |
2663 (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2666 blob.in = (char *)&exportcall;
2667 blob.in_size = sizeof(afs_int32);
2668 blob.out = (char *)&exportcall;
2669 blob.out_size = sizeof(afs_int32);
2670 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2672 if (errno == ENODEV) {
2674 "Sorry, the %s-exporter type is currently not supported on this AFS client\n",
2675 exported_types[type]);
2682 if (exportcall & 1) {
2683 printf("'%s' translator is enabled with the following options:\n",
2684 exported_types[type]);
2685 printf("\tRunning in %s mode\n",
2686 (exportcall & 2 ? "strict unix" :
2687 "convert owner mode bits to world/other"));
2688 printf("\tRunning in %s mode\n",
2689 (exportcall & 4 ? "strict 'passwd sync'" :
2690 "no 'passwd sync'"));
2692 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
2693 "Only mounts to /afs allowed"));
2695 (exportcall & 16 ? "Client-assigned PAG's are used" :
2696 "Client-assigned PAG's are not used"));
2699 "Callbacks are made to get creds from new clients" :
2700 "Callbacks are not made to get creds from new clients"));
2702 printf("'%s' translator is disabled\n", exported_types[type]);
2709 GetCellCmd(struct cmd_syndesc *as, void *arock)
2712 struct ViceIoctl blob;
2713 struct afsconf_cell info;
2714 struct cmd_item *ti;
2721 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2722 for (ti = as->parms[0].items; ti; ti = ti->next) {
2724 blob.out_size = sizeof(args);
2725 blob.out = (caddr_t) & args;
2726 code = GetCellName(ti->data, &info);
2731 blob.in_size = 1 + strlen(info.name);
2732 blob.in = info.name;
2733 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2735 if (errno == ENOENT)
2736 fprintf(stderr, "%s: the cell named '%s' does not exist\n",
2739 Die(errno, info.name);
2743 printf("Cell %s status: ", info.name);
2749 printf("no setuid allowed");
2751 printf("setuid allowed");
2753 printf(", using old VLDB");
2760 SetCellCmd(struct cmd_syndesc *as, void *arock)
2763 struct ViceIoctl blob;
2764 struct afsconf_cell info;
2765 struct cmd_item *ti;
2773 /* Check arguments. */
2774 if (as->parms[1].items && as->parms[2].items) {
2775 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2779 /* figure stuff to set */
2783 if (!as->parms[1].items)
2784 args.stat |= 2; /* default to -nosuid */
2786 /* set stat for all listed cells */
2787 for (ti = as->parms[0].items; ti; ti = ti->next) {
2789 code = GetCellName(ti->data, &info);
2794 strcpy(args.cname, info.name);
2795 blob.in_size = sizeof(args);
2796 blob.in = (caddr_t) & args;
2798 blob.out = (caddr_t) 0;
2799 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2801 Die(errno, info.name); /* XXX added cell name to Die() call */
2809 GetCellName(char *cellName, struct afsconf_cell *info)
2811 struct afsconf_dir *tdir;
2814 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2817 "Could not process files in configuration directory (%s).\n",
2818 AFSDIR_CLIENT_ETC_DIRPATH);
2822 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2824 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2825 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
2834 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
2838 code = ugen_ClientInit(noAuthFlag, AFSDIR_CLIENT_ETC_DIRPATH,
2839 info->name, 0, &uclient,
2840 NULL, pn, rxkad_clear,
2841 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
2842 0, 0, USER_SERVICE_ID);
2847 static struct ViceIoctl gblob;
2848 static int debug = 0;
2850 * here follow some routines in suport of the setserverprefs and
2851 * getserverprefs commands. They are:
2852 * SetPrefCmd "top-level" routine
2853 * addServer adds a server to the list of servers to be poked into the
2854 * kernel. Will poke the list into the kernel if it threatens
2856 * pokeServers pokes the existing list of servers and ranks into the kernel
2857 * GetPrefCmd reads the Cache Manager's current list of server ranks
2861 * returns -1 if error message printed,
2863 * errno value if error and no error message printed
2870 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2871 if (code && (errno == EINVAL)) {
2872 struct setspref *ssp;
2873 ssp = (struct setspref *)gblob.in;
2874 if (!(ssp->flags & DBservers)) {
2875 gblob.in = (void *)&(ssp->servers[0]);
2876 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
2877 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
2878 return code ? errno : 0;
2881 "This cache manager does not support VL server preferences.\n");
2885 return code ? errno : 0;
2889 * returns -1 if error message printed,
2891 * errno value if error and no error message printed
2894 addServer(char *name, afs_int32 rank)
2897 struct setspref *ssp;
2899 struct hostent *thostent;
2905 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
2907 #define MAXUSHORT ((unsigned short) ~0)
2911 thostent = hostutil_GetHostByName(name);
2913 fprintf(stderr, "%s: couldn't resolve name.\n", name);
2917 ssp = (struct setspref *)(gblob.in);
2919 for (t = 0; thostent->h_addr_list[t]; t++) {
2920 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
2921 code = pokeServers();
2924 ssp->num_servers = 0;
2927 sp = (struct spref *)(gblob.in + gblob.in_size);
2928 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
2929 sizeof(afs_uint32));
2930 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
2931 gblob.in_size += sizeof(struct spref);
2935 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
2936 name, sp->rank, sp->server.s_addr);
2944 SetPrefCmd(struct cmd_syndesc *as, void *arock)
2948 struct cmd_item *ti;
2951 struct setspref *ssp;
2952 int error = 0; /* -1 means error message printed,
2953 * >0 means errno value for unprinted message */
2955 ssp = (struct setspref *)space;
2957 ssp->num_servers = 0;
2958 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
2961 gblob.out_size = MAXSIZE;
2965 fprintf(stderr, "Permission denied: requires root access.\n");
2969 ti = as->parms[2].items; /* -file */
2972 fprintf(stderr, "opening file %s\n", ti->data);
2973 if (!(infd = fopen(ti->data, "r"))) {
2977 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
2978 code = addServer(name, (unsigned short)rank);
2985 ti = as->parms[3].items; /* -stdin */
2987 while (scanf("%79s%ld", name, &rank) != EOF) {
2988 code = addServer(name, (unsigned short)rank);
2994 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
2999 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3003 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3007 code = pokeServers();
3011 printf("now working on vlservers, code=%d\n", code);
3013 ssp = (struct setspref *)space;
3014 ssp->flags = DBservers;
3015 ssp->num_servers = 0;
3016 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3019 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3024 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3028 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3033 if (as->parms[1].items) {
3035 printf("now poking vlservers\n");
3036 code = pokeServers();
3044 return error ? 1 : 0;
3050 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3053 struct cmd_item *ti;
3054 char *name, tbuffer[20];
3055 afs_int32 rank, addr;
3059 struct ViceIoctl blob;
3060 struct sprefrequest *in;
3061 struct sprefinfo *out;
3064 ti = as->parms[0].items; /* -file */
3067 fprintf(stderr, "opening file %s\n", ti->data);
3068 if (!(outfd = freopen(ti->data, "w", stdout))) {
3074 ti = as->parms[1].items; /* -numeric */
3076 ti = as->parms[2].items; /* -vlservers */
3077 vlservers |= (ti ? DBservers : 0);
3078 /* ti = as->parms[3].items; -cell */
3080 in = (struct sprefrequest *)space;
3084 blob.in_size = sizeof(struct sprefrequest);
3085 blob.in = (char *)in;
3087 blob.out_size = MAXSIZE;
3090 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3091 in->flags = vlservers;
3093 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3095 perror("getserverprefs pioctl");
3099 out = (struct sprefinfo *)blob.out;
3101 for (i = 0; i < out->num_servers; i++) {
3103 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3105 addr = ntohl(out->servers[i].server.s_addr);
3106 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3107 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3110 printf("%-50s %5u\n", name, out->servers[i].rank);
3113 in->offset = out->next_offset;
3114 } while (out->next_offset > 0);
3120 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
3123 struct ViceIoctl blob;
3124 struct cmd_item *ti;
3125 struct sbstruct tsb, tsb2;
3131 tsb.sb_thisfile = -1;
3132 ti = as->parms[0].items; /* -kbytes */
3134 if (!as->parms[1].items) {
3135 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3139 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3140 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3141 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3147 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3148 ti = as->parms[2].items; /* -allfiles */
3150 allfiles = strtol(ti->data, &t, 10) * 1024;
3151 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3152 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3158 /* -verbose or -file only or no options */
3159 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3160 || (!as->parms[0].items && !as->parms[1].items
3161 && !as->parms[2].items))
3164 blob.in = (char *)&tsb;
3165 blob.out = (char *)&tsb2;
3166 blob.in_size = blob.out_size = sizeof(struct sbstruct);
3167 memset(&tsb2, 0, sizeof(tsb2));
3169 /* once per -file */
3170 for (ti = as->parms[1].items; ti; ti = ti->next) {
3171 /* Do this solely to see if the file is there */
3172 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3174 Die(errno, ti->data);
3179 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
3181 Die(errno, ti->data);
3186 if (verbose && (blob.out_size == sizeof(tsb2))) {
3187 if (tsb2.sb_thisfile == -1) {
3188 fprintf(stdout, "Will store %s according to default.\n",
3192 "Will store up to %d kbytes of %s asynchronously.\n",
3193 (tsb2.sb_thisfile / 1024), ti->data);
3198 /* If no files - make at least one pioctl call, or
3199 * set the allfiles default if we need to.
3201 if (!as->parms[1].items || (allfiles != -1)) {
3202 tsb.sb_default = allfiles;
3203 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
3205 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3210 /* Having no arguments also reports the default store asynchrony */
3211 if (verbose && (blob.out_size == sizeof(tsb2))) {
3212 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3213 (tsb2.sb_default / 1024));
3221 SetCryptCmd(struct cmd_syndesc *as, void *arock)
3223 afs_int32 code = 0, flag;
3224 struct ViceIoctl blob;
3227 tp = as->parms[0].items->data;
3228 if (strcmp(tp, "on") == 0)
3230 else if (strcmp(tp, "off") == 0)
3233 fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3237 blob.in = (char *)&flag;
3238 blob.in_size = sizeof(flag);
3240 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3248 GetCryptCmd(struct cmd_syndesc *as, void *arock)
3250 afs_int32 code = 0, flag;
3251 struct ViceIoctl blob;
3256 blob.out_size = sizeof(flag);
3259 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3265 memcpy(&flag, tp, sizeof(afs_int32));
3266 printf("Security level is currently ");
3268 printf("crypt (data security).\n");
3275 #ifdef AFS_DISCON_ENV
3276 static char *modenames[] = {
3286 DisconCmd(struct cmd_syndesc *as, void *arock)
3288 struct cmd_item *ti;
3291 afs_int32 mode, code;
3292 struct ViceIoctl blob;
3297 ti = as->parms[0].items;
3299 modename = ti->data;
3300 modelen = strlen(modename);
3301 for (mode = 0; modenames[mode] != NULL; mode++)
3302 if (!strncasecmp(modename, modenames[mode], modelen))
3304 if (modenames[mode] == NULL)
3305 printf("Unknown discon mode \"%s\"\n", modename);
3307 memcpy(space, &mode, sizeof mode);
3309 blob.in_size = sizeof mode;
3313 blob.out_size = sizeof(mode);
3315 code = pioctl(0, VIOC_DISCON, &blob, 1);
3319 memcpy(&mode, space, sizeof mode);
3320 if (mode < sizeof modenames / sizeof (char *))
3321 printf("Discon mode is now \"%s\"\n", modenames[mode]);
3323 printf("Unknown discon mode %d\n", mode);
3330 #include "AFS_component_version_number.c"
3333 main(int argc, char **argv)
3336 struct cmd_syndesc *ts;
3338 #ifdef AFS_AIX32_ENV
3340 * The following signal action for AIX is necessary so that in case of a
3341 * crash (i.e. core is generated) we can include the user's data section
3342 * in the core dump. Unfortunately, by default, only a partial core is
3343 * generated which, in many cases, isn't too useful.
3345 struct sigaction nsa;
3347 sigemptyset(&nsa.sa_mask);
3348 nsa.sa_handler = SIG_DFL;
3349 nsa.sa_flags = SA_FULLDUMP;
3350 sigaction(SIGSEGV, &nsa, NULL);
3353 /* try to find volume location information */
3354 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
3355 "get client network interface addresses");
3356 cmd_CreateAlias(ts, "gc");
3358 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
3359 "set client network interface addresses");
3360 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3361 "client network interfaces");
3362 cmd_CreateAlias(ts, "sc");
3364 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL,
3365 "set server ranks");
3366 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3367 "fileserver names and ranks");
3368 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3369 "VL server names and ranks");
3370 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3371 "input from named file");
3372 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3373 cmd_CreateAlias(ts, "sp");
3375 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL,
3376 "get server ranks");
3377 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3378 "output to named file");
3379 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3380 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3381 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3382 cmd_CreateAlias(ts, "gp");
3384 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
3385 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3386 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3387 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3388 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL,
3389 "apply to negative rights");
3390 parm_setacl_id = ts->nParms;
3391 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL,
3392 "initial directory acl (DFS only)");
3393 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL,
3394 "initial file acl (DFS only)");
3395 cmd_CreateAlias(ts, "sa");
3397 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL,
3398 "list access control list");
3399 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3400 parm_listacl_id = ts->nParms;
3401 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3402 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3403 cmd_CreateAlias(ts, "la");
3405 ts = cmd_CreateSyntax("getcalleraccess", GetCallerAccess, NULL,
3406 "list callers access");
3407 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3408 cmd_CreateAlias(ts, "gca");
3410 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL,
3411 "clean up access control list");
3412 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3414 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL,
3415 "copy access control list");
3416 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0,
3417 "source directory (or DFS file)");
3418 cmd_AddParm(ts, "-todir", CMD_LIST, 0,
3419 "destination directory (or DFS file)");
3420 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3421 "first clear dest access list");
3422 parm_copyacl_id = ts->nParms;
3423 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3424 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3426 cmd_CreateAlias(ts, "ca");
3428 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
3429 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3430 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
3431 "flush mount symlink from cache");
3432 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3434 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
3435 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3436 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL,
3437 "disk space quota in 1K units");
3439 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL,
3440 "disk space guaranteed");
3441 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3443 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL,
3445 cmd_CreateAlias(ts, "sv");
3447 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL,
3448 "control Cache Manager messages");
3449 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL,
3450 "[user|console|all|none]");
3452 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
3453 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3454 cmd_CreateAlias(ts, "lv");
3455 cmd_CreateAlias(ts, "listvol");
3457 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
3458 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3459 cmd_CreateAlias(ts, "lq");
3461 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL,
3462 "show server disk space usage");
3463 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3464 cmd_CreateAlias(ts, "df");
3466 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
3467 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3469 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
3470 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3472 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
3473 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3474 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3475 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3476 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3477 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3478 "don't check name with VLDB");
3484 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3488 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
3489 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3491 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL,
3492 "check local cell's servers");
3493 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3494 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3495 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3496 "just list, don't check");
3497 cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL,
3498 "seconds between probes");
3500 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL,
3501 "check volumeID/name mappings");
3502 cmd_CreateAlias(ts, "checkbackups");
3505 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL,
3507 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3508 "size in 1K byte blocks (0 => reset)");
3509 cmd_CreateAlias(ts, "cachesize");
3511 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL,
3512 "reset size back to boot value");
3514 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL,
3515 "get cache usage info");
3516 cmd_AddParm(ts, "-files", CMD_FLAG, CMD_OPTIONAL, "Show cach files used as well");
3517 cmd_AddParm(ts, "-excessive", CMD_FLAG, CMD_OPTIONAL, "excessively verbose cache stats");
3519 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL,
3520 "list configured cells");
3521 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3523 ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, NULL,
3524 "list configured cell aliases");
3526 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
3527 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3528 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3530 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3532 cmd_CreateAlias(ts, "sq");
3534 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
3535 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3536 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3537 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL,
3538 "linked cell name");
3540 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
3541 "configure new cell alias");
3542 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
3543 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
3545 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3547 * Turn this on only if you wish to be able to talk to a server which is listening
3548 * on alternative ports. This is not intended for general use and may not be
3549 * supported in the cache manager. It is not a way to run two servers at the
3550 * same host, since the cache manager cannot properly distinguish those two hosts.
3552 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL,
3553 "cell's fileserver port");
3554 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL,
3555 "cell's vldb server port");
3558 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
3559 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3561 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
3562 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3564 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
3567 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, NULL, "obsolete (listed primary cell)");
3570 /* set cache monitor host address */
3571 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, (char *)CMD_HIDDEN);
3572 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL,
3573 "host name or 'off'");
3574 cmd_CreateAlias(ts, "mariner");
3576 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
3577 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3579 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
3580 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3581 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3582 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL,
3583 "disallow setuid programs");
3585 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL,
3586 "flush all data in volume");
3587 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3589 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL,
3590 "get/set sysname (i.e. @sys) value");
3591 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3593 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL,
3594 "enable/disable translators to AFS");
3595 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3596 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL,
3597 "start/stop translator (on | off)");
3598 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL,
3599 "convert from afs to unix mode (on | off)");
3600 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL,
3601 "run on strict 'uid check' mode (on | off)");
3602 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
3603 "allow nfs mounts to subdirs of /afs/.. (on | off)");
3604 cmd_AddParm(ts, "-clipags", CMD_SINGLE, CMD_OPTIONAL,
3605 "enable use of client-assigned PAG's (on | off)");
3606 cmd_AddParm(ts, "-pagcb", CMD_SINGLE, CMD_OPTIONAL,
3607 "enable callbacks to get creds from new clients (on | off)");
3610 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
3611 "store to server after file close");
3612 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL,
3613 "asynchrony for specified names");
3614 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3615 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL,
3616 "new default (KB)");
3617 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3618 cmd_CreateAlias(ts, "sb");
3620 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL,
3621 "set cache manager encryption flag");
3622 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3624 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL,
3625 "get cache manager encryption flag");
3627 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
3628 "Manage per process RX statistics");
3629 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3630 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3631 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3633 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
3634 "Manage per peer RX statistics");
3635 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3636 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3637 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3639 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
3640 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
3642 /* try to find volume location information */
3643 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL,
3644 "get fid for file(s)");
3645 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3647 #ifdef AFS_DISCON_ENV
3648 ts = cmd_CreateSyntax("discon", DisconCmd, NULL,
3649 "disconnection mode");
3650 cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_OPTIONAL, "nat | full");
3653 ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, NULL, "nuke credentials for NFS client");
3654 cmd_AddParm(ts, "-addr", CMD_SINGLE, 0, "host name or address");
3656 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
3657 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_REQUIRED, "generate a new UUID");
3659 code = cmd_Dispatch(argc, argv);
3667 Die(int errnum, char *filename)
3673 "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3676 fprintf(stderr, "%s: Invalid argument.\n", pn);
3680 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3682 fprintf(stderr, "%s: no such file returned\n", pn);
3686 "%s: You can not change a backup or readonly volume\n", pn);
3692 "%s: You don't have the required access rights on '%s'\n",
3696 "%s: You do not have the required rights to do this operation\n",
3701 fprintf(stderr, "%s:'%s'", pn, filename);
3703 fprintf(stderr, "%s", pn);
3704 fprintf(stderr, ": %s\n", afs_error_message(errnum));
3709 /* get clients interface addresses */
3711 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3714 struct cmd_item *ti;
3716 struct ViceIoctl blob;
3717 struct sprefrequest *in;
3718 struct sprefinfo *out;
3720 in = (struct sprefrequest *)space;
3724 blob.in_size = sizeof(struct sprefrequest);
3725 blob.in = (char *)in;
3727 blob.out_size = MAXSIZE;
3730 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3731 /* returns addr in network byte order */
3732 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3734 perror("getClientInterfaceAddr pioctl");
3740 out = (struct sprefinfo *)blob.out;
3741 for (i = 0; i < out->num_servers; i++) {
3744 addr = ntohl(out->servers[i].server.s_addr);
3745 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3746 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3747 printf("%-50s\n", tbuffer);
3749 in->offset = out->next_offset;
3751 } while (out->next_offset > 0);
3757 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3759 afs_int32 code, addr;
3760 struct cmd_item *ti;
3762 struct ViceIoctl blob;
3763 struct setspref *ssp;
3764 int sizeUsed = 0, i, flag;
3765 afs_int32 existingAddr[1024]; /* existing addresses on this host */
3769 ssp = (struct setspref *)space;
3770 ssp->num_servers = 0;
3773 blob.out_size = MAXSIZE;
3776 fprintf(stderr, "Permission denied: requires root access.\n");
3780 /* extract all existing interface addresses */
3781 existNu = rx_getAllAddr(existingAddr, 1024);
3785 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
3786 for (ti = as->parms[0].items; ti; ti = ti->next) {
3787 if (sizeUsed >= sizeof(space)) {
3788 fprintf(stderr, "No more space\n");
3791 addr = extractAddr(ti->data, 20); /* network order */
3792 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
3793 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
3798 /* see if it is an address that really exists */
3799 for (flag = 0, i = 0; i < existNu; i++)
3800 if (existingAddr[i] == addr) {
3804 if (!flag) { /* this is an nonexistent address */
3805 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
3809 /* copy all specified addr into ioctl buffer */
3810 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
3811 printf("Adding 0x%08x\n", addr);
3813 sizeUsed += sizeof(struct spref);
3815 if (ssp->num_servers < 1) {
3816 fprintf(stderr, "No addresses specified\n");
3819 blob.in_size = sizeUsed - sizeof(struct spref);
3821 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
3831 FlushMountCmd(struct cmd_syndesc *as, void *arock)
3834 struct ViceIoctl blob;
3835 struct cmd_item *ti;
3836 char orig_name[1024]; /*Original name, may be modified */
3837 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
3838 char parent_dir[1024]; /*Parent directory of true name */
3839 char *last_component; /*Last component of true name */
3840 struct stat statbuff; /*Buffer for status info */
3841 int link_chars_read; /*Num chars read in readlink() */
3842 int thru_symlink; /*Did we get to a mount point via a symlink? */
3845 for (ti = as->parms[0].items; ti; ti = ti->next) {
3848 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
3851 if (lstat(orig_name, &statbuff) < 0) {
3852 /* if lstat fails, we should still try the pioctl, since it
3853 * may work (for example, lstat will fail, but pioctl will
3854 * work if the volume of offline (returning ENODEV). */
3855 statbuff.st_mode = S_IFDIR; /* lie like pros */
3859 * The lstat succeeded. If the given file is a symlink, substitute
3860 * the file name with the link name.
3862 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
3865 * Read name of resolved file.
3867 link_chars_read = readlink(orig_name, true_name, 1024);
3868 if (link_chars_read <= 0) {
3870 "%s: Can't read target name for '%s' symbolic link!\n",
3877 * Add a trailing null to what was read, bump the length.
3879 true_name[link_chars_read++] = 0;
3882 * If the symlink is an absolute pathname, we're fine. Otherwise, we
3883 * have to create a full pathname using the original name and the
3884 * relative symlink name. Find the rightmost slash in the original
3885 * name (we know there is one) and splice in the symlink value.
3887 if (true_name[0] != '/') {
3888 last_component = (char *)strrchr(orig_name, '/');
3889 strcpy(++last_component, true_name);
3890 strcpy(true_name, orig_name);
3893 strcpy(true_name, orig_name);
3896 * Find rightmost slash, if any.
3898 last_component = (char *)strrchr(true_name, '/');
3899 if (last_component) {
3901 * Found it. Designate everything before it as the parent directory,
3902 * everything after it as the final component.
3904 strncpy(parent_dir, true_name, last_component - true_name);
3905 parent_dir[last_component - true_name] = 0;
3906 last_component++; /*Skip the slash */
3909 * No slash appears in the given file name. Set parent_dir to the current
3910 * directory, and the last component as the given name.
3912 strcpy(parent_dir, ".");
3913 last_component = true_name;
3916 if (strcmp(last_component, ".") == 0
3917 || strcmp(last_component, "..") == 0) {
3919 "%s: you may not use '.' or '..' as the last component\n",
3921 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
3927 blob.in = last_component;
3928 blob.in_size = strlen(last_component) + 1;
3930 memset(space, 0, MAXSIZE);
3932 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
3935 if (errno == EINVAL) {
3936 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
3938 Die(errno, (ti->data ? ti->data : parent_dir));
3947 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
3950 afs_int32 flags = 0;
3951 struct ViceIoctl blob;
3952 struct cmd_item *ti;
3954 if (as->parms[0].items) { /* -enable */
3955 flags |= AFSCALL_RXSTATS_ENABLE;
3957 if (as->parms[1].items) { /* -disable */
3958 flags |= AFSCALL_RXSTATS_DISABLE;
3960 if (as->parms[2].items) { /* -clear */
3961 flags |= AFSCALL_RXSTATS_CLEAR;
3964 fprintf(stderr, "You must specify at least one argument\n");
3968 blob.in = (char *)&flags;
3969 blob.in_size = sizeof(afs_int32);
3972 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
3982 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
3985 afs_int32 flags = 0;
3986 struct ViceIoctl blob;
3987 struct cmd_item *ti;
3989 if (as->parms[0].items) { /* -enable */
3990 flags |= AFSCALL_RXSTATS_ENABLE;
3992 if (as->parms[1].items) { /* -disable */
3993 flags |= AFSCALL_RXSTATS_DISABLE;
3995 if (as->parms[2].items) { /* -clear */
3996 flags |= AFSCALL_RXSTATS_CLEAR;
3999 fprintf(stderr, "You must specify at least one argument\n");
4003 blob.in = (char *)&flags;
4004 blob.in_size = sizeof(afs_int32);
4007 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4017 GetFidCmd(struct cmd_syndesc *as, void *arock)
4019 struct ViceIoctl blob;
4020 struct cmd_item *ti;
4021 for (ti = as->parms[0].items; ti; ti = ti->next) {
4022 struct VenusFid vfid;
4024 blob.out_size = sizeof(struct VenusFid);
4025 blob.out = (char *) &vfid;
4028 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
4029 printf("File %s (%u.%u.%u) contained in volume %u\n",
4030 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,