2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #include <afs/afs_args.h>
18 #include <sys/ioctl.h>
19 #include <sys/socket.h>
23 #include <netinet/in.h>
27 #include <afs/venus.h>
28 #include <afs/com_err.h>
37 #include "afs/prs_fs.h"
38 #include <afs/afsint.h>
39 #include <afs/cellconfig.h>
42 #include <rx/rx_globals.h>
43 #include <afs/vldbint.h>
44 #include <afs/volser.h>
45 #include <afs/vlserver.h>
47 #include <afs/afsutil.h>
48 #include <afs/com_err.h>
51 #include <afs/ptclient.h>
56 #define MAXCELLHOSTS 8
59 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
60 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
62 static char space[MAXSIZE];
63 static char tspace[1024];
64 static struct ubik_client *uclient;
66 static int GetClientAddrsCmd(), SetClientAddrsCmd(), FlushMountCmd();
67 static int RxStatProcCmd(), RxStatPeerCmd(), GetFidCmd(), UuidCmd();
69 extern char *hostutil_GetNameByINet();
70 extern struct hostent *hostutil_GetHostByName();
73 static char pn[] = "fs";
74 static int rxInitDone = 0;
76 static void ZapList();
77 static int PruneList();
79 static int SetVolCmd(struct cmd_syndesc *as, void *arock);
85 * Character to use between name and rights in printed representation for
88 #define DFS_SEPARATOR ' '
90 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
93 int dfs; /* Originally true if a dfs acl; now also the type
94 * of the acl (1, 2, or 3, corresponding to object,
95 * initial dir, or initial object). */
96 sec_rgy_name_t cell; /* DFS cell name */
99 struct AclEntry *pluslist;
100 struct AclEntry *minuslist;
104 struct AclEntry *next;
110 afs_int32 callerAccess;
122 ZapList(acl->pluslist);
123 ZapList(acl->minuslist);
136 if (t >= 'A' && t <= 'Z')
138 if (u >= 'A' && u <= 'Z')
148 * Mods for the AFS/DFS protocol translator.
150 * DFS rights. It's ugly to put these definitions here, but they
151 * *cannot* change, because they're part of the wire protocol.
152 * In any event, the protocol translator will guarantee these
153 * assignments for AFS cache managers.
155 #define DFS_READ 0x01
156 #define DFS_WRITE 0x02
157 #define DFS_EXECUTE 0x04
158 #define DFS_CONTROL 0x08
159 #define DFS_INSERT 0x10
160 #define DFS_DELETE 0x20
162 /* the application definable ones (backwards from AFS) */
163 #define DFS_USR0 0x80000000 /* "A" bit */
164 #define DFS_USR1 0x40000000 /* "B" bit */
165 #define DFS_USR2 0x20000000 /* "C" bit */
166 #define DFS_USR3 0x10000000 /* "D" bit */
167 #define DFS_USR4 0x08000000 /* "E" bit */
168 #define DFS_USR5 0x04000000 /* "F" bit */
169 #define DFS_USR6 0x02000000 /* "G" bit */
170 #define DFS_USR7 0x01000000 /* "H" bit */
171 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
172 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
175 * Offset of -id switch in command structure for various commands.
176 * The -if switch is the next switch always.
178 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
181 * Determine whether either the -id or -if switches are present, and
182 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
184 /* int id; Offset of -id switch; -if is next switch */
186 getidf(struct cmd_syndesc *as, int id)
190 if (as->parms[id].items) {
193 if (as->parms[id + 1].items) {
198 "%s: you may specify either -id or -if, but not both switches\n",
206 PRights(afs_int32 arights, int dfs)
209 if (arights & PRSFS_READ)
211 if (arights & PRSFS_LOOKUP)
213 if (arights & PRSFS_INSERT)
215 if (arights & PRSFS_DELETE)
217 if (arights & PRSFS_WRITE)
219 if (arights & PRSFS_LOCK)
221 if (arights & PRSFS_ADMINISTER)
223 if (arights & PRSFS_USR0)
225 if (arights & PRSFS_USR1)
227 if (arights & PRSFS_USR2)
229 if (arights & PRSFS_USR3)
231 if (arights & PRSFS_USR4)
233 if (arights & PRSFS_USR5)
235 if (arights & PRSFS_USR6)
237 if (arights & PRSFS_USR7)
240 if (arights & DFS_READ)
244 if (arights & DFS_WRITE)
248 if (arights & DFS_EXECUTE)
252 if (arights & DFS_CONTROL)
256 if (arights & DFS_INSERT)
260 if (arights & DFS_DELETE)
264 if (arights & (DFS_USRALL))
266 if (arights & DFS_USR0)
268 if (arights & DFS_USR1)
270 if (arights & DFS_USR2)
272 if (arights & DFS_USR3)
274 if (arights & DFS_USR4)
276 if (arights & DFS_USR5)
278 if (arights & DFS_USR6)
280 if (arights & DFS_USR7)
286 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
290 struct ViceIoctl blob;
294 blob.out_size = MAXSIZE;
297 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
299 if ((errno == EINVAL) || (errno == ENOENT))
305 /* return a static pointer to a buffer */
310 strcpy(tspace, apath);
311 tp = strrchr(tspace, '/');
319 enum rtype { add, destroy, deny };
322 Convert(char *arights, int dfs, enum rtype *rtypep)
328 *rtypep = add; /* add rights, by default */
331 if (!strcmp(arights, "null")) {
335 if (!strcmp(arights, "read"))
336 return DFS_READ | DFS_EXECUTE;
337 if (!strcmp(arights, "write"))
338 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
340 if (!strcmp(arights, "all"))
341 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
342 DFS_WRITE | DFS_CONTROL;
344 if (!strcmp(arights, "read"))
345 return PRSFS_READ | PRSFS_LOOKUP;
346 if (!strcmp(arights, "write"))
347 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
348 PRSFS_WRITE | PRSFS_LOCK;
349 if (!strcmp(arights, "mail"))
350 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
351 if (!strcmp(arights, "all"))
352 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
353 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
355 if (!strcmp(arights, "none")) {
356 *rtypep = destroy; /* Remove entire entry */
359 len = strlen(arights);
361 for (i = 0; i < len; i++) {
395 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
403 mode |= PRSFS_LOOKUP;
405 mode |= PRSFS_INSERT;
407 mode |= PRSFS_DELETE;
413 mode |= PRSFS_ADMINISTER;
431 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
440 static struct AclEntry *
441 FindList(struct AclEntry *alist, char *aname)
444 if (!foldcmp(alist->name, aname))
451 /* if no parm specified in a particular slot, set parm to be "." instead */
453 SetDotDefault(struct cmd_item **aitemp)
457 return; /* already has value */
458 /* otherwise, allocate an item representing "." */
459 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
461 ti->next = (struct cmd_item *)0;
462 ti->data = (char *)malloc(2);
464 strcpy(ti->data, ".");
469 ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
471 struct AclEntry *tlist;
472 tlist = (plus ? al->pluslist : al->minuslist);
473 tlist = FindList(tlist, aname);
475 /* Found the item already in the list. */
476 tlist->rights = arights;
478 al->nplus -= PruneList(&al->pluslist, al->dfs);
480 al->nminus -= PruneList(&al->minuslist, al->dfs);
483 /* Otherwise we make a new item and plug in the new data. */
484 tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry));
486 strcpy(tlist->name, aname);
487 tlist->rights = arights;
489 tlist->next = al->pluslist;
490 al->pluslist = tlist;
492 if (arights == 0 || arights == -1)
493 al->nplus -= PruneList(&al->pluslist, al->dfs);
495 tlist->next = al->minuslist;
496 al->minuslist = tlist;
499 al->nminus -= PruneList(&al->minuslist, al->dfs);
504 ZapList(struct AclEntry *alist)
506 struct AclEntry *tp, *np;
507 for (tp = alist; tp; tp = np) {
514 PruneList(struct AclEntry **ae, int dfs)
516 struct AclEntry **lp;
517 struct AclEntry *te, *ne;
521 for (te = *ae; te; te = ne) {
522 if ((!dfs && te->rights == 0) || te->rights == -1) {
538 while (*astr != '\n')
545 * Create an empty acl, taking into account whether the acl pointed
546 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
547 * can recover from problems caused by bogus ACL's (in that case, always
548 * assume that the acl is AFS: for DFS, the user can always resort to
549 * acl_edit, but for AFS there may be no other way out).
557 tp = (struct Acl *)malloc(sizeof(struct Acl));
559 tp->nplus = tp->nminus = 0;
560 tp->pluslist = tp->minuslist = 0;
562 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
569 int nplus, nminus, i, trights;
571 struct AclEntry *first, *last, *tl;
574 ta = (struct Acl *)malloc(sizeof(struct Acl));
577 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
578 astr = SkipLine(astr);
579 sscanf(astr, "%d", &ta->nminus);
580 astr = SkipLine(astr);
587 for (i = 0; i < nplus; i++) {
588 sscanf(astr, "%100s %d", tname, &trights);
589 astr = SkipLine(astr);
590 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
594 strcpy(tl->name, tname);
595 tl->rights = trights;
601 ta->pluslist = first;
605 for (i = 0; i < nminus; i++) {
606 sscanf(astr, "%100s %d", tname, &trights);
607 astr = SkipLine(astr);
608 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
612 strcpy(tl->name, tname);
613 tl->rights = trights;
619 ta->minuslist = first;
625 PrintStatus(VolumeStatus * status, char *name, char *offmsg)
627 printf("Volume status for vid = %u named %s\n", status->Vid, name);
629 printf("Current offline message is %s\n", offmsg);
630 printf("Current disk quota is ");
631 if (status->MaxQuota != 0)
632 printf("%d\n", status->MaxQuota);
634 printf("unlimited\n");
635 printf("Current blocks used are %d\n", status->BlocksInUse);
636 printf("The partition has %d blocks available out of %d\n\n",
637 status->PartBlocksAvail, status->PartMaxBlocks);
642 QuickPrintStatus(VolumeStatus * status, char *name)
644 double QuotaUsed = 0.0;
645 double PartUsed = 0.0;
647 printf("%-25.25s", name);
649 if (status->MaxQuota != 0) {
650 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
652 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
654 printf(" no limit%10d", status->BlocksInUse);
656 if (QuotaUsed > 90.0) {
657 printf("%5.0f%%<<", QuotaUsed);
660 printf("%5.0f%% ", QuotaUsed);
663 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
665 if (PartUsed > 97.0) {
666 printf("%9.0f%%<<", PartUsed);
669 printf("%9.0f%% ", PartUsed);
671 printf(" <<WARNING\n");
678 QuickPrintSpace(VolumeStatus * status, char *name)
680 double PartUsed = 0.0;
682 printf("%-25.25s", name);
684 printf("%10d%10d%10d", status->PartMaxBlocks,
685 status->PartMaxBlocks - status->PartBlocksAvail,
686 status->PartBlocksAvail);
690 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
692 if (PartUsed > 90.0) {
693 printf(" %4.0f%%<<", PartUsed);
696 printf(" %4.0f%% ", PartUsed);
698 printf(" <<WARNING\n");
705 AclToString(struct Acl *acl)
707 static char mydata[MAXSIZE];
708 char tstring[MAXSIZE];
713 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
716 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
717 for (tp = acl->pluslist; tp; tp = tp->next) {
718 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
719 strcat(mydata, tstring);
721 for (tp = acl->minuslist; tp; tp = tp->next) {
722 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
723 strcat(mydata, tstring);
729 SetACLCmd(struct cmd_syndesc *as, void *arock)
732 struct ViceIoctl blob;
734 struct cmd_item *ti, *ui;
738 int idf = getidf(as, parm_setacl_id);
741 if (as->parms[2].items)
745 plusp = !(as->parms[3].items);
746 for (ti = as->parms[0].items; ti; ti = ti->next) {
747 blob.out_size = MAXSIZE;
749 blob.in = blob.out = space;
750 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
752 Die(errno, ti->data);
759 ta = ParseAcl(space);
760 if (!plusp && ta->dfs) {
762 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
764 "(you may specify \"null\" to revoke all rights, however)\n");
772 ta = EmptyAcl(space);
774 ta = ParseAcl(space);
775 CleanAcl(ta, ti->data);
776 for (ui = as->parms[1].items; ui; ui = ui->next->next) {
780 "%s: Missing second half of user/access pair.\n", pn);
784 rights = Convert(ui->next->data, ta->dfs, &rtype);
785 if (rtype == destroy && !ta->dfs) {
786 struct AclEntry *tlist;
788 tlist = (plusp ? ta->pluslist : ta->minuslist);
789 if (!FindList(tlist, ui->data))
792 if (rtype == deny && !ta->dfs)
794 if (rtype == destroy && ta->dfs)
796 ChangeList(ta, plusp, ui->data, rights);
798 blob.in = AclToString(ta);
800 blob.in_size = 1 + strlen(blob.in);
801 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
803 if (errno == EINVAL) {
805 static char *fsenv = 0;
807 fsenv = (char *)getenv("FS_EXPERT");
810 "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n",
814 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
815 "\nPossible reasons for this include:\n\n",
816 " -You may have specified an inappropriate combination of rights.\n",
817 " For example, some DFS-supported filesystems may not allow you to\n",
818 " drop the \"c\" right from \"user_obj\".\n\n",
819 " -A mask_obj may be required (it is likely required by the underlying\n",
820 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
821 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
822 " does not automatically create or update the mask_obj. Try setting\n",
823 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
824 " users or groups. You can do this with a single command, such as\n",
825 " \"fs sa mask_obj all user:somename read\"\n\n",
826 " -A specified user or group may not exist.\n\n",
827 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
828 " This is probably not allowed by the underlying file system.\n\n",
829 " -If you add a user or group to a DFS ACL, remember that it must be\n",
830 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
831 " may be local requirements on the format of the user or group name.\n",
832 " Check with your cell administrator.\n\n",
833 " -Or numerous other possibilities. It would be great if we could be more\n",
834 " precise about the actual problem, but for various reasons, this is\n",
835 " impractical via this interface. If you can't figure it out, you\n",
836 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
837 " whatever is provided). You may get better results. Good luck!\n\n",
838 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
842 "%s: Invalid argument, possible reasons include:\n",
844 fprintf(stderr, "\t-File not in AFS\n");
846 "\t-Too many users on access control list\n");
848 "\t-Tried to add non-existent user to access control list\n");
851 Die(errno, ti->data);
863 CopyACLCmd(struct cmd_syndesc *as, void *arock)
866 struct ViceIoctl blob;
867 struct Acl *fa, *ta = 0;
869 struct cmd_item *ti, *ui;
873 int idf = getidf(as, parm_copyacl_id);
876 if (as->parms[2].items)
880 blob.out_size = MAXSIZE;
882 blob.in = blob.out = space;
883 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
885 Die(errno, as->parms[0].items->data);
888 fa = ParseAcl(space);
889 CleanAcl(fa, as->parms[0].items->data);
890 for (ti = as->parms[1].items; ti; ti = ti->next) {
891 blob.out_size = MAXSIZE;
893 blob.in = blob.out = space;
894 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
896 Die(errno, ti->data);
904 ta = EmptyAcl(space);
906 ta = ParseAcl(space);
907 CleanAcl(ta, ti->data);
908 if (ta->dfs != fa->dfs) {
910 "%s: incompatible file system types: acl not copied to %s; aborted\n",
916 if (!clear && strcmp(ta->cell, fa->cell) != 0) {
918 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
923 strcpy(ta->cell, fa->cell);
925 for (tp = fa->pluslist; tp; tp = tp->next)
926 ChangeList(ta, 1, tp->name, tp->rights);
927 for (tp = fa->minuslist; tp; tp = tp->next)
928 ChangeList(ta, 0, tp->name, tp->rights);
929 blob.in = AclToString(ta);
931 blob.in_size = 1 + strlen(blob.in);
932 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
934 if (errno == EINVAL) {
936 "%s: Invalid argument, possible reasons include:\n",
938 fprintf(stderr, "\t-File not in AFS\n");
940 Die(errno, ti->data);
951 /* pioctl() call to get the cellname of a pathname */
953 GetCell(char *fname, char *cellname)
956 struct ViceIoctl blob;
959 blob.out_size = MAXCELLCHARS;
962 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
963 return code ? errno : 0;
966 /* Check if a username is valid: If it contains only digits (or a
967 * negative sign), then it might be bad. We then query the ptserver
971 BadName(char *aname, char *fname)
973 afs_int32 tc, code, id;
975 char cell[MAXCELLCHARS];
977 for (nm = aname; tc = *nm; nm++) {
978 /* all must be '-' or digit to be bad */
979 if (tc != '-' && (tc < '0' || tc > '9'))
983 /* Go to the PRDB and see if this all number username is valid */
984 code = GetCell(fname, cell);
988 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
989 code = pr_SNameToId(aname, &id);
992 /* 1=>Not-valid; 0=>Valid */
993 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
997 /* clean up an access control list of its bad entries; return 1 if we made
998 any changes to the list, and 0 otherwise */
1000 CleanAcl(struct Acl *aa, char *fname)
1002 struct AclEntry *te, **le, *ne;
1005 /* Don't correct DFS ACL's for now */
1009 /* prune out bad entries */
1010 changes = 0; /* count deleted entries */
1012 for (te = aa->pluslist; te; te = ne) {
1014 if (BadName(te->name, fname)) {
1024 le = &aa->minuslist;
1025 for (te = aa->minuslist; te; te = ne) {
1027 if (BadName(te->name, fname)) {
1041 /* clean up an acl to not have bogus entries */
1043 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1047 struct ViceIoctl blob;
1049 struct cmd_item *ti;
1050 struct AclEntry *te;
1053 SetDotDefault(&as->parms[0].items);
1054 for (ti = as->parms[0].items; ti; ti = ti->next) {
1055 blob.out_size = MAXSIZE;
1058 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1060 Die(errno, ti->data);
1067 ta = ParseAcl(space);
1070 "%s: cleanacl is not supported for DFS access lists.\n",
1076 changes = CleanAcl(ta, ti->data);
1079 /* now set the acl */
1080 blob.in = AclToString(ta);
1081 blob.in_size = strlen(blob.in) + 1;
1083 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1085 if (errno == EINVAL) {
1087 "%s: Invalid argument, possible reasons include\n",
1089 fprintf(stderr, "%s: File not in vice or\n", pn);
1091 "%s: Too many users on access control list or\n",
1094 Die(errno, ti->data);
1100 /* now list the updated acl */
1101 printf("Access list for %s is now\n", ti->data);
1102 if (ta->nplus > 0) {
1104 printf("Normal rights:\n");
1105 for (te = ta->pluslist; te; te = te->next) {
1106 printf(" %s ", te->name);
1107 PRights(te->rights, ta->dfs);
1111 if (ta->nminus > 0) {
1112 printf("Negative rights:\n");
1113 for (te = ta->minuslist; te; te = te->next) {
1114 printf(" %s ", te->name);
1115 PRights(te->rights, ta->dfs);
1122 printf("Access list for %s is fine.\n", ti->data);
1130 ListACLCmd(struct cmd_syndesc *as, void *arock)
1134 struct ViceIoctl blob;
1135 struct AclEntry *te;
1136 struct cmd_item *ti;
1137 int idf = getidf(as, parm_listacl_id);
1140 SetDotDefault(&as->parms[0].items);
1141 for (ti = as->parms[0].items; ti; ti = ti->next) {
1142 blob.out_size = MAXSIZE;
1144 blob.in = blob.out = space;
1145 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1147 Die(errno, ti->data);
1151 ta = ParseAcl(space);
1154 printf("Access list for %s is\n", ti->data);
1157 printf("DFS access list for %s is\n", ti->data);
1160 printf("DFS initial directory access list of %s is\n", ti->data);
1163 printf("DFS initial file access list of %s is\n", ti->data);
1167 printf(" Default cell = %s\n", ta->cell);
1169 if (ta->nplus > 0) {
1171 printf("Normal rights:\n");
1172 for (te = ta->pluslist; te; te = te->next) {
1173 printf(" %s ", te->name);
1174 PRights(te->rights, ta->dfs);
1178 if (ta->nminus > 0) {
1179 printf("Negative rights:\n");
1180 for (te = ta->minuslist; te; te = te->next) {
1181 printf(" %s ", te->name);
1182 PRights(te->rights, ta->dfs);
1194 GetCallerAccess(struct cmd_syndesc *as, void *arock)
1196 struct cmd_item *ti;
1199 SetDotDefault(&as->parms[0].items);
1200 for (ti = as->parms[0].items; ti; ti = ti->next) {
1202 struct ViceIoctl blob;
1203 struct vcxstat2 stat;
1204 blob.out_size = sizeof(struct vcxstat2);
1206 blob.out = (void *)&stat;
1207 code = pioctl(ti->data, VIOC_GETVCXSTATUS2, &blob, 1);
1209 Die(errno, ti->data);
1213 printf("Callers access to %s is ", ti->data);
1214 PRights(stat.callerAccess, 0);
1221 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1224 struct ViceIoctl blob;
1225 struct cmd_item *ti;
1228 SetDotDefault(&as->parms[0].items);
1229 for (ti = as->parms[0].items; ti; ti = ti->next) {
1230 blob.in_size = blob.out_size = 0;
1231 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1233 fprintf(stderr, "Error flushing volume ");
1243 * The Windows version of UuidCmd displays the UUID.
1244 * When the UNIX version is updated to do the same
1245 * be sure to replace the CMD_REQUIRED flag with
1246 * CMD_OPTIONAL in the cmd_AddParam(-generate) call
1249 UuidCmd(struct cmd_syndesc *as, void *arock)
1252 struct ViceIoctl blob;
1257 if (as->parms[0].items) {
1259 fprintf (stderr, "Permission denied: requires root access.\n");
1263 /* generate new UUID */
1264 code = pioctl(0, VIOC_NEWUUID, &blob, 1);
1271 printf("New uuid generated.\n");
1273 /* This will never execute */
1274 printf("Please add the '-generate' option to generate a new UUID.\n");
1279 #if defined(AFS_CACHE_BYPASS)
1281 * Set cache-bypass threshold. Files larger than this size will not be cached.
1282 * With a threshold of 0, the cache is always bypassed. With a threshold of -1,
1283 * cache bypass is disabled.
1287 BypassThresholdCmd(struct cmd_syndesc *as, char *arock)
1291 struct ViceIoctl blob;
1292 afs_int32 threshold_i, threshold_o;
1295 /* if new threshold supplied, then set and confirm, else,
1296 * get current threshold and print
1299 if(as->parms[0].items) {
1302 tp = as->parms[0].items->data;
1305 for(ix = 0; ix < len; ++ix) {
1306 if(!isdigit(tp[0])) {
1312 fprintf(stderr, "fs bypassthreshold -size: %s must be an undecorated digit string.\n", tp);
1315 threshold_i = atoi(tp);
1316 if(ix > 9 && threshold_i < 2147483647)
1317 threshold_i = 2147483647;
1318 blob.in = (char *) &threshold_i;
1319 blob.in_size = sizeof(threshold_i);
1325 blob.out = (char *) &threshold_o;
1326 blob.out_size = sizeof(threshold_o);
1327 code = pioctl(0, VIOC_SETBYPASS_THRESH, &blob, 1);
1332 printf("Cache bypass threshold %d", threshold_o);
1333 if(threshold_o == -1)
1334 printf(" (disabled)");
1344 FlushCmd(struct cmd_syndesc *as, void *arock)
1347 struct ViceIoctl blob;
1348 struct cmd_item *ti;
1351 for (ti = as->parms[0].items; ti; ti = ti->next) {
1352 blob.in_size = blob.out_size = 0;
1353 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1355 if (errno == EMFILE) {
1356 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1359 fprintf(stderr, "%s: Error flushing file ", pn);
1369 /* all this command does is repackage its args and call SetVolCmd */
1371 SetQuotaCmd(struct cmd_syndesc *as, void *arock)
1373 struct cmd_syndesc ts;
1375 /* copy useful stuff from our command slot; we may later have to reorder */
1376 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1377 return SetVolCmd(&ts, arock);
1381 SetVolCmd(struct cmd_syndesc *as, void *arock)
1384 struct ViceIoctl blob;
1385 struct cmd_item *ti;
1386 struct VolumeStatus *status;
1387 char *offmsg, *input;
1390 SetDotDefault(&as->parms[0].items);
1391 for (ti = as->parms[0].items; ti; ti = ti->next) {
1393 blob.out_size = MAXSIZE;
1394 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1397 status = (VolumeStatus *) space;
1398 status->MinQuota = status->MaxQuota = -1;
1400 if (as->parms[1].items) {
1401 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1403 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1408 if (as->parms[2].items)
1409 offmsg = as->parms[2].items->data;
1410 input = (char *)status + sizeof(*status);
1411 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1413 if (strlen(offmsg) >= VMSGSIZE) {
1415 "%s: message must be shorter than %d characters\n",
1420 strcpy(input, offmsg);
1421 blob.in_size += strlen(offmsg);
1422 input += strlen(offmsg) + 1;
1425 *(input++) = '\0'; /* Pad for old style volume "motd" */
1426 code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1);
1428 Die(errno, ti->data);
1436 * Why is VenusFid declared in the kernel-only section of afs.h,
1437 * if it's the exported interface of the cache manager?
1445 ExamineCmd(struct cmd_syndesc *as, void *arock)
1448 struct ViceIoctl blob;
1449 struct cmd_item *ti;
1450 struct VolumeStatus *status;
1451 char *name, *offmsg;
1454 SetDotDefault(&as->parms[0].items);
1455 for (ti = as->parms[0].items; ti; ti = ti->next) {
1456 struct VenusFid vfid;
1459 blob.out_size = MAXSIZE;
1462 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1464 Die(errno, ti->data);
1468 status = (VolumeStatus *) space;
1469 name = (char *)status + sizeof(*status);
1470 offmsg = name + strlen(name) + 1;
1472 blob.out_size = sizeof(struct VenusFid);
1473 blob.out = (char *) &vfid;
1474 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1475 printf("File %s (%u.%u.%u) contained in volume %u\n",
1476 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1480 PrintStatus(status, name, offmsg);
1486 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1489 struct ViceIoctl blob;
1490 struct cmd_item *ti;
1491 struct VolumeStatus *status;
1495 printf("%-25s%-10s%-10s%-7s%-11s\n", "Volume Name", " Quota",
1496 " Used", " %Used", " Partition");
1497 SetDotDefault(&as->parms[0].items);
1498 for (ti = as->parms[0].items; ti; ti = ti->next) {
1500 blob.out_size = MAXSIZE;
1503 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1505 Die(errno, ti->data);
1509 status = (VolumeStatus *) space;
1510 name = (char *)status + sizeof(*status);
1511 QuickPrintStatus(status, name);
1517 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1520 struct ViceIoctl blob;
1521 struct cmd_item *ti;
1527 SetDotDefault(&as->parms[0].items);
1528 for (ti = as->parms[0].items; ti; ti = ti->next) {
1530 blob.out_size = MAXSIZE;
1533 memset(space, 0, sizeof(space));
1534 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1536 Die(errno, ti->data);
1540 hosts = (afs_int32 *) space;
1541 printf("File %s is on host%s ", ti->data,
1542 (hosts[0] && !hosts[1]) ? "" : "s");
1543 for (j = 0; j < MAXHOSTS; j++) {
1546 tp = hostutil_GetNameByINet(hosts[j]);
1556 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1559 struct ViceIoctl blob;
1560 struct cmd_item *ti;
1562 struct VolumeStatus *status;
1565 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1566 " used", " avail", " %used");
1567 SetDotDefault(&as->parms[0].items);
1568 for (ti = as->parms[0].items; ti; ti = ti->next) {
1570 blob.out_size = MAXSIZE;
1573 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1575 Die(errno, ti->data);
1579 status = (VolumeStatus *) space;
1580 name = (char *)status + sizeof(*status);
1581 QuickPrintSpace(status, name);
1587 QuotaCmd(struct cmd_syndesc *as, void *arock)
1590 struct ViceIoctl blob;
1591 struct cmd_item *ti;
1593 struct VolumeStatus *status;
1596 SetDotDefault(&as->parms[0].items);
1597 for (ti = as->parms[0].items; ti; ti = ti->next) {
1599 blob.out_size = MAXSIZE;
1602 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1604 Die(errno, ti->data);
1608 status = (VolumeStatus *) space;
1609 if (status->MaxQuota)
1611 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
1614 printf("%2.0f%% of quota used.\n", quotaPct);
1620 ListMountCmd(struct cmd_syndesc *as, void *arock)
1623 struct ViceIoctl blob;
1624 struct cmd_item *ti;
1625 char orig_name[1024]; /*Original name, may be modified */
1626 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
1627 char parent_dir[1024]; /*Parent directory of true name */
1628 char *last_component; /*Last component of true name */
1629 struct stat statbuff; /*Buffer for status info */
1630 int link_chars_read; /*Num chars read in readlink() */
1631 int thru_symlink; /*Did we get to a mount point via a symlink? */
1634 for (ti = as->parms[0].items; ti; ti = ti->next) {
1637 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
1640 if (lstat(orig_name, &statbuff) < 0) {
1641 /* if lstat fails, we should still try the pioctl, since it
1642 * may work (for example, lstat will fail, but pioctl will
1643 * work if the volume of offline (returning ENODEV). */
1644 statbuff.st_mode = S_IFDIR; /* lie like pros */
1648 * The lstat succeeded. If the given file is a symlink, substitute
1649 * the file name with the link name.
1651 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1654 * Read name of resolved file.
1656 link_chars_read = readlink(orig_name, true_name, 1024);
1657 if (link_chars_read <= 0) {
1659 "%s: Can't read target name for '%s' symbolic link!\n",
1666 * Add a trailing null to what was read, bump the length.
1668 true_name[link_chars_read++] = 0;
1671 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1672 * have to create a full pathname using the original name and the
1673 * relative symlink name. Find the rightmost slash in the original
1674 * name (we know there is one) and splice in the symlink value.
1676 if (true_name[0] != '/') {
1677 last_component = (char *)strrchr(orig_name, '/');
1678 strcpy(++last_component, true_name);
1679 strcpy(true_name, orig_name);
1682 strcpy(true_name, orig_name);
1685 * Find rightmost slash, if any.
1687 last_component = (char *)strrchr(true_name, '/');
1688 if (last_component) {
1690 * Found it. Designate everything before it as the parent directory,
1691 * everything after it as the final component.
1693 strncpy(parent_dir, true_name, last_component - true_name);
1694 parent_dir[last_component - true_name] = 0;
1695 last_component++; /*Skip the slash */
1698 * No slash appears in the given file name. Set parent_dir to the current
1699 * directory, and the last component as the given name.
1701 strcpy(parent_dir, ".");
1702 last_component = true_name;
1705 if (strcmp(last_component, ".") == 0
1706 || strcmp(last_component, "..") == 0) {
1708 "%s: you may not use '.' or '..' as the last component\n",
1710 fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n",
1716 blob.in = last_component;
1717 blob.in_size = strlen(last_component) + 1;
1718 blob.out_size = MAXSIZE;
1720 memset(space, 0, MAXSIZE);
1722 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1725 printf("'%s' is a %smount point for volume '%s'\n", ti->data,
1726 (thru_symlink ? "symbolic link, leading to a " : ""),
1729 if (errno == EINVAL) {
1730 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
1732 Die(errno, (ti->data ? ti->data : parent_dir));
1741 MakeMountCmd(struct cmd_syndesc *as, void *arock)
1744 char *cellName, *volName, *tmpName;
1745 struct afsconf_cell info;
1746 struct vldbentry vldbEntry;
1747 struct ViceIoctl blob;
1753 if (as->parms[5].items && !as->parms[2].items) {
1754 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1759 if (as->parms[2].items) /* cell name specified */
1760 cellName = as->parms[2].items->data;
1763 volName = as->parms[1].items->data;
1765 if (strlen(volName) >= 64) {
1767 "%s: volume name too long (length must be < 64 characters)\n",
1772 /* Check for a cellname in the volume specification, and complain
1773 * if it doesn't match what was specified with -cell */
1774 if (tmpName = strchr(volName, ':')) {
1777 if (strcasecmp(cellName, volName)) {
1778 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1783 volName = ++tmpName;
1786 if (!InAFS(Parent(as->parms[0].items->data))) {
1788 "%s: mount points must be created within the AFS file system\n",
1795 blob.out_size = MAXSIZE;
1798 pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME,
1802 code = GetCellName(cellName ? cellName : space, &info);
1806 if (!(as->parms[4].items)) {
1807 /* not fast, check which cell the mountpoint is being created in */
1808 /* not fast, check name with VLDB */
1809 code = VLDBInit(1, &info);
1811 /* make the check. Don't complain if there are problems with init */
1813 ubik_VL_GetEntryByNameO(uclient, 0, volName,
1815 if (code == VL_NOENT) {
1817 "%s: warning, volume %s does not exist in cell %s.\n",
1818 pn, volName, cellName ? cellName : space);
1823 if (as->parms[3].items) /* if -rw specified */
1828 /* cellular mount point, prepend cell prefix */
1829 strcat(space, info.name);
1832 strcat(space, volName); /* append volume name */
1833 strcat(space, "."); /* stupid convention; these end with a period */
1834 code = symlink(space, as->parms[0].items->data);
1836 Die(errno, as->parms[0].items->data);
1843 * Delete AFS mount points. Variables are used as follows:
1844 * tbuffer: Set to point to the null-terminated directory name of the mount point
1845 * (or ``.'' if none is provided)
1846 * tp: Set to point to the actual name of the mount point to nuke.
1849 RemoveMountCmd(struct cmd_syndesc *as, void *arock)
1852 struct ViceIoctl blob;
1853 struct cmd_item *ti;
1855 char lsbuffer[1024];
1859 for (ti = as->parms[0].items; ti; ti = ti->next) {
1861 tp = (char *)strrchr(ti->data, '/');
1863 strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */
1865 tp++; /* skip the slash */
1867 strcpy(tbuffer, ".");
1871 blob.in_size = strlen(tp) + 1;
1872 blob.out = lsbuffer;
1873 blob.out_size = sizeof(lsbuffer);
1874 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1876 if (errno == EINVAL) {
1877 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
1880 Die(errno, ti->data);
1883 continue; /* don't bother trying */
1887 blob.in_size = strlen(tp) + 1;
1888 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1890 Die(errno, ti->data);
1901 CheckServersCmd(struct cmd_syndesc *as, void *arock)
1904 struct ViceIoctl blob;
1910 struct afsconf_cell info;
1911 struct chservinfo checkserv;
1913 memset(&checkserv, 0, sizeof(struct chservinfo));
1914 blob.in_size = sizeof(struct chservinfo);
1915 blob.in = (caddr_t) & checkserv;
1917 blob.out_size = MAXSIZE;
1919 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1921 /* prepare flags for checkservers command */
1922 temp = 2; /* default to checking local cell only */
1923 if (as->parms[2].items)
1924 temp |= 1; /* set fast flag */
1925 if (as->parms[1].items)
1926 temp &= ~2; /* turn off local cell check */
1928 checkserv.magic = 0x12345678; /* XXX */
1929 checkserv.tflags = temp;
1931 /* now copy in optional cell name, if specified */
1932 if (as->parms[0].items) {
1933 code = GetCellName(as->parms[0].items->data, &info);
1937 strcpy(checkserv.tbuffer, info.name);
1938 checkserv.tsize = strlen(info.name) + 1;
1940 strcpy(checkserv.tbuffer, "\0");
1941 checkserv.tsize = 0;
1944 if (as->parms[3].items) {
1945 checkserv.tinterval = atol(as->parms[3].items->data);
1948 if (checkserv.tinterval < 0) {
1950 ("Warning: The negative -interval is ignored; treated as an inquiry\n");
1951 checkserv.tinterval = 0;
1952 } else if (checkserv.tinterval > 600) {
1954 ("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1955 checkserv.tinterval = 600; /* 10 min max interval */
1958 checkserv.tinterval = -1; /* don't change current interval */
1961 code = pioctl(0, VIOCCKSERV, &blob, 1);
1963 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1964 printf("Must be root to change -interval\n");
1970 memcpy(&temp, space, sizeof(afs_int32));
1971 if (checkserv.tinterval >= 0) {
1972 if (checkserv.tinterval > 0)
1974 ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1975 checkserv.tinterval, temp);
1977 printf("The current down server probe interval is %d secs\n",
1982 printf("All servers are running.\n");
1985 ("These servers unavailable due to network or server problems: ");
1987 memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32));
1990 tp = hostutil_GetNameByINet(temp);
2000 MessagesCmd(struct cmd_syndesc *as, void *arock)
2003 struct ViceIoctl blob;
2006 struct gaginfo gagflags;
2007 struct cmd_item *show;
2009 memset(&gagflags, 0, sizeof(struct gaginfo));
2010 blob.in_size = sizeof(struct gaginfo);
2011 blob.in = (caddr_t) & gagflags;
2012 blob.out_size = MAXSIZE;
2014 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2016 if (show = as->parms[0].items) {
2017 if (!strcasecmp(show->data, "user"))
2018 gagflags.showflags |= GAGUSER;
2019 else if (!strcasecmp(show->data, "console"))
2020 gagflags.showflags |= GAGCONSOLE;
2021 else if (!strcasecmp(show->data, "all"))
2022 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2023 else if (!strcasecmp(show->data, "none"))
2027 "unrecognized flag %s: must be in {user,console,all,none}\n",
2036 code = pioctl(0, VIOC_GAG, &blob, 1);
2046 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2049 struct ViceIoctl blob;
2053 code = pioctl(0, VIOCCKBACK, &blob, 1);
2059 printf("All volumeID/name mappings checked.\n");
2064 PreCacheCmd(struct cmd_syndesc *as, char *arock)
2067 struct ViceIoctl blob;
2070 if (!as->parms[0].items && !as->parms[1].items) {
2071 fprintf(stderr, "%s: syntax error in precache cmd.\n", pn);
2074 if (as->parms[0].items) {
2075 code = util_GetInt32(as->parms[0].items->data, &temp);
2077 fprintf(stderr, "%s: bad integer specified for precache size.\n",
2083 blob.in = (char *)&temp;
2084 blob.in_size = sizeof(afs_int32);
2086 code = pioctl(0, VIOCPRECACHE, &blob, 1);
2092 printf("New precache size set.\n");
2097 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2100 struct ViceIoctl blob;
2103 if (!as->parms[0].items && !as->parms[1].items) {
2104 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
2107 if (as->parms[0].items) {
2108 code = util_GetInt32(as->parms[0].items->data, &temp);
2110 fprintf(stderr, "%s: bad integer specified for cache size.\n",
2116 blob.in = (char *)&temp;
2117 blob.in_size = sizeof(afs_int32);
2119 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2121 if (errno == EROFS) {
2123 ("'fs setcache' not allowed on memory cache based cache managers.\n");
2130 printf("New cache size set.\n");
2134 #define MAXGCSIZE 16
2136 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2138 afs_int32 code, filesUsed;
2139 struct ViceIoctl blob;
2140 afs_int32 parms[MAXGCSIZE];
2141 double percentFiles, percentBlocks;
2142 afs_int32 flags = 0;
2144 if (as->parms[0].items){ /* -files */
2146 } else if (as->parms[1].items){ /* -excessive */
2152 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
2154 blob.in = (char *)&flags;
2155 blob.in_size = sizeof(afs_int32);
2156 } else { /* be backward compatible */
2160 blob.out_size = sizeof(parms);
2161 blob.out = (char *)parms;
2162 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2169 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2170 parms[1], parms[0]);
2171 if (parms[1] > parms[0])
2172 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2176 percentBlocks = ((double)parms[1]/parms[0]) * 100;
2177 printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n",
2178 percentBlocks, parms[1], parms[0]);
2183 filesUsed = parms[2] - parms[3];
2184 percentFiles = ((double)filesUsed/parms[2]) * 100;
2185 printf(" %5.0f%% of the cache files (%d of %d files)\n",
2186 percentFiles, filesUsed, parms[2]);
2188 printf(" afs_cacheFiles: %10d\n", parms[2]);
2189 printf(" IFFree: %10d\n", parms[3]);
2190 printf(" IFEverUsed: %10d\n", parms[4]);
2191 printf(" IFDataMod: %10d\n", parms[5]);
2192 printf(" IFDirtyPages: %10d\n", parms[6]);
2193 printf(" IFAnyPages: %10d\n", parms[7]);
2194 printf(" IFDiscarded: %10d\n", parms[8]);
2195 printf(" DCentries: %10d\n", parms[9]);
2196 printf(" 0k- 4K: %10d\n", parms[10]);
2197 printf(" 4k- 16k: %10d\n", parms[11]);
2198 printf(" 16k- 64k: %10d\n", parms[12]);
2199 printf(" 64k- 256k: %10d\n", parms[13]);
2200 printf(" 256k- 1M: %10d\n", parms[14]);
2201 printf(" >=1M: %10d\n", parms[15]);
2204 if (percentBlocks > 90)
2205 printf("[cache size usage over 90%, consider increasing cache size]\n");
2206 if (percentFiles > 90)
2207 printf("[cache file usage over 90%, consider increasing '-files' argument to afsd]\n");
2213 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2219 struct ViceIoctl blob;
2222 resolve = !(as->parms[0].items); /* -numeric */
2226 memcpy(tp, &i, sizeof(afs_int32));
2227 blob.out_size = MAXSIZE;
2228 blob.in_size = sizeof(afs_int32);
2231 code = pioctl(0, VIOCGETCELL, &blob, 1);
2234 break; /* done with the list */
2239 printf("Cell %s on hosts", tp + MAXCELLHOSTS * sizeof(afs_int32));
2240 for (j = 0; j < MAXCELLHOSTS; j++) {
2242 char *name, tbuffer[20];
2244 memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32));
2249 name = hostutil_GetNameByINet(addr);
2252 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2253 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2256 printf(" %s", name);
2264 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2267 char *tp, *aliasName, *realName;
2268 struct ViceIoctl blob;
2272 memcpy(tp, &i, sizeof(afs_int32));
2273 blob.out_size = MAXSIZE;
2274 blob.in_size = sizeof(afs_int32);
2277 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2280 break; /* done with the list */
2286 tp += strlen(aliasName) + 1;
2288 printf("Alias %s for cell %s\n", aliasName, realName);
2294 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2297 struct ViceIoctl blob;
2298 struct cmd_item *ti;
2300 struct hostent *thp;
2304 ti = as->parms[0].items;
2307 thp = hostutil_GetHostByName(ti->data);
2309 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2312 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2314 hostAddr = 0; /* means don't set host */
2315 setp = 0; /* aren't setting host */
2318 /* now do operation */
2319 blob.in_size = sizeof(afs_int32);
2320 blob.out_size = sizeof(afs_int32);
2321 blob.in = (char *) &hostAddr;
2322 blob.out = (char *) &hostAddr;
2324 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2333 NukeNFSCredsCmd(struct cmd_syndesc *as, void *arock)
2336 struct ViceIoctl blob;
2337 struct cmd_item *ti;
2339 struct hostent *thp;
2341 ti = as->parms[0].items;
2342 thp = hostutil_GetHostByName(ti->data);
2344 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2347 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2349 /* now do operation */
2350 blob.in_size = sizeof(afs_int32);
2351 blob.out_size = sizeof(afs_int32);
2352 blob.in = (char *) &hostAddr;
2353 blob.out = (char *) &hostAddr;
2355 code = pioctl(0, VIOC_NFS_NUKE_CREDS, &blob, 1);
2364 NewCellCmd(struct cmd_syndesc *as, void *arock)
2366 afs_int32 code, linkedstate = 0, size = 0, *lp;
2367 struct ViceIoctl blob;
2368 struct cmd_item *ti;
2369 char *tp, *cellname = 0;
2370 struct hostent *thp;
2371 afs_int32 fsport = 0, vlport = 0;
2372 afs_int32 magic, scount; /* Number of servers to pass in pioctl call */
2375 * With the NEWCELL pioctl call, 3.4 clients take an array of
2376 * MAXHOSTS (13) servers while 3.5 clients take an array of
2377 * MAXCELLHOSTS (8) servers. To determine which we are talking to,
2378 * do a GETCELL pioctl and pass it a magic number. If an array of
2379 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
2380 * If we get back EDOM, there are no cells in the kernel yet,
2381 * and we'll assume a 3.5 client.
2384 lp = (afs_int32 *) tp;
2385 *lp++ = 0; /* first cell entry */
2386 *lp = 0x12345678; /* magic */
2387 blob.out_size = MAXSIZE;
2388 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
2391 code = pioctl(0, VIOCGETCELL, &blob, 1);
2392 if (code < 0 && errno != EDOM) {
2396 if (code < 1 && errno == EDOM) {
2400 cellname = tp + MAXCELLHOSTS * sizeof(afs_int32);
2401 scount = ((cellname[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2404 /* Now setup and do the NEWCELL pioctl call */
2405 memset(space, 0, (scount + 1) * sizeof(afs_int32));
2407 lp = (afs_int32 *) tp;
2409 tp += sizeof(afs_int32);
2410 for (ti = as->parms[1].items; ti; ti = ti->next) {
2411 thp = hostutil_GetHostByName(ti->data);
2414 "%s: Host %s not found in host table, skipping it.\n", pn,
2417 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2418 tp += sizeof(afs_int32);
2421 if (as->parms[2].items) {
2423 * Link the cell, for the purposes of volume location, to the specified
2426 cellname = as->parms[2].items->data;
2429 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2430 if (as->parms[3].items) {
2431 code = util_GetInt32(as->parms[3].items->data, &vlport);
2434 "%s: bad integer specified for the fileserver port.\n",
2439 if (as->parms[4].items) {
2440 code = util_GetInt32(as->parms[4].items->data, &fsport);
2443 "%s: bad integer specified for the vldb server port.\n",
2449 tp = (char *)(space + (scount + 1) * sizeof(afs_int32));
2450 lp = (afs_int32 *) tp;
2454 strcpy(space + ((scount + 4) * sizeof(afs_int32)),
2455 as->parms[0].items->data);
2456 size = ((scount + 4) * sizeof(afs_int32))
2457 + strlen(as->parms[0].items->data)
2458 + 1 /* for null */ ;
2459 tp = (char *)(space + size);
2461 strcpy(tp, cellname);
2462 size += strlen(cellname) + 1;
2464 blob.in_size = size;
2467 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2476 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2479 struct ViceIoctl blob;
2481 char *aliasName, *realName;
2483 /* Now setup and do the NEWCELL pioctl call */
2484 aliasName = as->parms[0].items->data;
2485 realName = as->parms[1].items->data;
2487 strcpy(tp, aliasName);
2488 tp += strlen(aliasName) + 1;
2489 strcpy(tp, realName);
2490 tp += strlen(realName) + 1;
2492 blob.in_size = tp - space;
2496 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2498 if (errno == EEXIST) {
2500 "%s: cell name `%s' in use by an existing cell.\n", pn,
2511 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2514 struct cmd_item *ti;
2516 char cell[MAXCELLCHARS];
2518 SetDotDefault(&as->parms[0].items);
2519 for (ti = as->parms[0].items; ti; ti = ti->next) {
2520 code = GetCell(ti->data, cell);
2522 if (errno == ENOENT)
2523 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
2525 Die(errno, ti->data);
2530 printf("File %s lives in cell '%s'\n", ti->data, cell);
2536 WSCellCmd(struct cmd_syndesc *as, void *arock)
2539 struct ViceIoctl blob;
2543 blob.out_size = MAXSIZE;
2546 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2552 printf("This workstation belongs to cell '%s'\n", space);
2557 static PrimaryCellCmd(as)
2558 struct cmd_syndesc *as;
2560 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2566 MonitorCmd(struct cmd_syndesc *as, void *arock)
2569 struct ViceIoctl blob;
2570 struct cmd_item *ti;
2572 struct hostent *thp;
2576 ti = as->parms[0].items;
2580 if (!strcmp(ti->data, "off"))
2581 hostAddr = 0xffffffff;
2583 thp = hostutil_GetHostByName(ti->data);
2585 if (!strcmp(ti->data, "localhost")) {
2587 "localhost not in host table, assuming 127.0.0.1\n");
2588 hostAddr = htonl(0x7f000001);
2590 fprintf(stderr, "host %s not found in host table.\n",
2595 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2598 hostAddr = 0; /* means don't set host */
2599 setp = 0; /* aren't setting host */
2602 /* now do operation */
2603 blob.in_size = sizeof(afs_int32);
2604 blob.out_size = sizeof(afs_int32);
2605 blob.in = (char *)&hostAddr;
2606 blob.out = (char *)&hostAddr;
2607 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2613 printf("%s: new monitor host set.\n", pn);
2615 /* now decode old address */
2616 if (hostAddr == 0xffffffff) {
2617 printf("Cache monitoring is currently disabled.\n");
2619 tp = hostutil_GetNameByINet(hostAddr);
2620 printf("Using host %s for monitor services.\n", tp);
2627 SysNameCmd(struct cmd_syndesc *as, void *arock)
2630 struct ViceIoctl blob;
2631 struct cmd_item *ti;
2632 char *input = space;
2635 ti = as->parms[0].items;
2638 blob.out_size = MAXSIZE;
2639 blob.in_size = sizeof(afs_int32);
2640 input += sizeof(afs_int32);
2641 for (; ti; ti = ti->next) {
2643 blob.in_size += strlen(ti->data) + 1;
2644 if (blob.in_size > MAXSIZE) {
2645 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2646 setp > 1 ? "s" : "");
2649 strcpy(input, ti->data);
2650 input += strlen(ti->data);
2653 memcpy(space, &setp, sizeof(afs_int32));
2654 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2660 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2664 memcpy(&setp, input, sizeof(afs_int32));
2665 input += sizeof(afs_int32);
2667 fprintf(stderr, "No sysname name value was found\n");
2670 printf("Current sysname%s is", setp > 1 ? " list" : "");
2671 for (; setp > 0; --setp) {
2672 printf(" \'%s\'", input);
2673 input += strlen(input) + 1;
2679 static char *exported_types[] = { "null", "nfs", "" };
2681 ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2684 struct ViceIoctl blob;
2685 struct cmd_item *ti;
2686 int export = 0, type = 0, mode = 0, exp = 0, exportcall, pwsync =
2687 0, smounts = 0, clipags = 0, pagcb = 0;
2689 ti = as->parms[0].items;
2690 if (strcmp(ti->data, "nfs") == 0)
2691 type = 0x71; /* NFS */
2694 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n",
2698 ti = as->parms[1].items;
2700 if (strcmp(ti->data, "on") == 0)
2702 else if (strcmp(ti->data, "off") == 0)
2705 fprintf(stderr, "Illegal argument %s\n", ti->data);
2710 if (ti = as->parms[2].items) { /* -noconvert */
2711 if (strcmp(ti->data, "on") == 0)
2713 else if (strcmp(ti->data, "off") == 0)
2716 fprintf(stderr, "Illegal argument %s\n", ti->data);
2720 if (ti = as->parms[3].items) { /* -uidcheck */
2721 if (strcmp(ti->data, "on") == 0)
2723 else if (strcmp(ti->data, "off") == 0)
2726 fprintf(stderr, "Illegal argument %s\n", ti->data);
2730 if (ti = as->parms[4].items) { /* -submounts */
2731 if (strcmp(ti->data, "on") == 0)
2733 else if (strcmp(ti->data, "off") == 0)
2736 fprintf(stderr, "Illegal argument %s\n", ti->data);
2740 if (ti = as->parms[5].items) { /* -clipags */
2741 if (strcmp(ti->data, "on") == 0)
2743 else if (strcmp(ti->data, "off") == 0)
2746 fprintf(stderr, "Illegal argument %s\n", ti->data);
2750 if (ti = as->parms[6].items) { /* -pagcb */
2751 if (strcmp(ti->data, "on") == 0)
2753 else if (strcmp(ti->data, "off") == 0)
2756 fprintf(stderr, "Illegal argument %s\n", ti->data);
2761 (type << 24) | (pagcb << 10) | (clipags << 8) |
2762 (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2765 blob.in = (char *)&exportcall;
2766 blob.in_size = sizeof(afs_int32);
2767 blob.out = (char *)&exportcall;
2768 blob.out_size = sizeof(afs_int32);
2769 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2771 if (errno == ENODEV) {
2773 "Sorry, the %s-exporter type is currently not supported on this AFS client\n",
2774 exported_types[type]);
2781 if (exportcall & 1) {
2782 printf("'%s' translator is enabled with the following options:\n",
2783 exported_types[type]);
2784 printf("\tRunning in %s mode\n",
2785 (exportcall & 2 ? "strict unix" :
2786 "convert owner mode bits to world/other"));
2787 printf("\tRunning in %s mode\n",
2788 (exportcall & 4 ? "strict 'passwd sync'" :
2789 "no 'passwd sync'"));
2791 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
2792 "Only mounts to /afs allowed"));
2794 (exportcall & 16 ? "Client-assigned PAG's are used" :
2795 "Client-assigned PAG's are not used"));
2798 "Callbacks are made to get creds from new clients" :
2799 "Callbacks are not made to get creds from new clients"));
2801 printf("'%s' translator is disabled\n", exported_types[type]);
2808 GetCellCmd(struct cmd_syndesc *as, void *arock)
2811 struct ViceIoctl blob;
2812 struct afsconf_cell info;
2813 struct cmd_item *ti;
2820 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2821 for (ti = as->parms[0].items; ti; ti = ti->next) {
2823 blob.out_size = sizeof(args);
2824 blob.out = (caddr_t) & args;
2825 code = GetCellName(ti->data, &info);
2830 blob.in_size = 1 + strlen(info.name);
2831 blob.in = info.name;
2832 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2834 if (errno == ENOENT)
2835 fprintf(stderr, "%s: the cell named '%s' does not exist\n",
2838 Die(errno, info.name);
2842 printf("Cell %s status: ", info.name);
2848 printf("no setuid allowed");
2850 printf("setuid allowed");
2852 printf(", using old VLDB");
2859 SetCellCmd(struct cmd_syndesc *as, void *arock)
2862 struct ViceIoctl blob;
2863 struct afsconf_cell info;
2864 struct cmd_item *ti;
2872 /* Check arguments. */
2873 if (as->parms[1].items && as->parms[2].items) {
2874 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2878 /* figure stuff to set */
2882 if (!as->parms[1].items)
2883 args.stat |= 2; /* default to -nosuid */
2885 /* set stat for all listed cells */
2886 for (ti = as->parms[0].items; ti; ti = ti->next) {
2888 code = GetCellName(ti->data, &info);
2893 strcpy(args.cname, info.name);
2894 blob.in_size = sizeof(args);
2895 blob.in = (caddr_t) & args;
2897 blob.out = (caddr_t) 0;
2898 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2900 Die(errno, info.name); /* XXX added cell name to Die() call */
2908 GetCellName(char *cellName, struct afsconf_cell *info)
2910 struct afsconf_dir *tdir;
2913 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2916 "Could not process files in configuration directory (%s).\n",
2917 AFSDIR_CLIENT_ETC_DIRPATH);
2921 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2923 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2924 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
2933 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
2937 code = ugen_ClientInit(noAuthFlag, AFSDIR_CLIENT_ETC_DIRPATH,
2938 info->name, 0, &uclient,
2939 NULL, pn, rxkad_clear,
2940 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
2941 0, 0, USER_SERVICE_ID);
2946 static struct ViceIoctl gblob;
2947 static int debug = 0;
2949 * here follow some routines in suport of the setserverprefs and
2950 * getserverprefs commands. They are:
2951 * SetPrefCmd "top-level" routine
2952 * addServer adds a server to the list of servers to be poked into the
2953 * kernel. Will poke the list into the kernel if it threatens
2955 * pokeServers pokes the existing list of servers and ranks into the kernel
2956 * GetPrefCmd reads the Cache Manager's current list of server ranks
2960 * returns -1 if error message printed,
2962 * errno value if error and no error message printed
2969 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2970 if (code && (errno == EINVAL)) {
2971 struct setspref *ssp;
2972 ssp = (struct setspref *)gblob.in;
2973 if (!(ssp->flags & DBservers)) {
2974 gblob.in = (void *)&(ssp->servers[0]);
2975 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
2976 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
2977 return code ? errno : 0;
2980 "This cache manager does not support VL server preferences.\n");
2984 return code ? errno : 0;
2988 * returns -1 if error message printed,
2990 * errno value if error and no error message printed
2993 addServer(char *name, afs_int32 rank)
2996 struct setspref *ssp;
2998 struct hostent *thostent;
3004 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3006 #define MAXUSHORT ((unsigned short) ~0)
3010 thostent = hostutil_GetHostByName(name);
3012 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3016 ssp = (struct setspref *)(gblob.in);
3018 for (t = 0; thostent->h_addr_list[t]; t++) {
3019 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3020 code = pokeServers();
3023 ssp->num_servers = 0;
3026 sp = (struct spref *)(gblob.in + gblob.in_size);
3027 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3028 sizeof(afs_uint32));
3029 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3030 gblob.in_size += sizeof(struct spref);
3034 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3035 name, sp->rank, sp->server.s_addr);
3043 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3047 struct cmd_item *ti;
3050 struct setspref *ssp;
3051 int error = 0; /* -1 means error message printed,
3052 * >0 means errno value for unprinted message */
3054 ssp = (struct setspref *)space;
3056 ssp->num_servers = 0;
3057 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3060 gblob.out_size = MAXSIZE;
3064 fprintf(stderr, "Permission denied: requires root access.\n");
3068 ti = as->parms[2].items; /* -file */
3071 fprintf(stderr, "opening file %s\n", ti->data);
3072 if (!(infd = fopen(ti->data, "r"))) {
3076 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3077 code = addServer(name, (unsigned short)rank);
3084 ti = as->parms[3].items; /* -stdin */
3086 while (scanf("%79s%ld", name, &rank) != EOF) {
3087 code = addServer(name, (unsigned short)rank);
3093 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3098 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3102 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3106 code = pokeServers();
3110 printf("now working on vlservers, code=%d\n", code);
3112 ssp = (struct setspref *)space;
3113 ssp->flags = DBservers;
3114 ssp->num_servers = 0;
3115 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3118 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3123 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3127 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3132 if (as->parms[1].items) {
3134 printf("now poking vlservers\n");
3135 code = pokeServers();
3143 return error ? 1 : 0;
3149 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3152 struct cmd_item *ti;
3153 char *name, tbuffer[20];
3154 afs_int32 rank, addr;
3158 struct ViceIoctl blob;
3159 struct sprefrequest *in;
3160 struct sprefinfo *out;
3163 ti = as->parms[0].items; /* -file */
3166 fprintf(stderr, "opening file %s\n", ti->data);
3167 if (!(outfd = freopen(ti->data, "w", stdout))) {
3173 ti = as->parms[1].items; /* -numeric */
3175 ti = as->parms[2].items; /* -vlservers */
3176 vlservers |= (ti ? DBservers : 0);
3177 /* ti = as->parms[3].items; -cell */
3179 in = (struct sprefrequest *)space;
3183 blob.in_size = sizeof(struct sprefrequest);
3184 blob.in = (char *)in;
3186 blob.out_size = MAXSIZE;
3189 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3190 in->flags = vlservers;
3192 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3194 perror("getserverprefs pioctl");
3198 out = (struct sprefinfo *)blob.out;
3200 for (i = 0; i < out->num_servers; i++) {
3202 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3204 addr = ntohl(out->servers[i].server.s_addr);
3205 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3206 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3209 printf("%-50s %5u\n", name, out->servers[i].rank);
3212 in->offset = out->next_offset;
3213 } while (out->next_offset > 0);
3219 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
3222 struct ViceIoctl blob;
3223 struct cmd_item *ti;
3224 struct sbstruct tsb, tsb2;
3230 tsb.sb_thisfile = -1;
3231 ti = as->parms[0].items; /* -kbytes */
3233 if (!as->parms[1].items) {
3234 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3238 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3239 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3240 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3246 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3247 ti = as->parms[2].items; /* -allfiles */
3249 allfiles = strtol(ti->data, &t, 10) * 1024;
3250 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3251 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3257 /* -verbose or -file only or no options */
3258 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3259 || (!as->parms[0].items && !as->parms[1].items
3260 && !as->parms[2].items))
3263 blob.in = (char *)&tsb;
3264 blob.out = (char *)&tsb2;
3265 blob.in_size = blob.out_size = sizeof(struct sbstruct);
3266 memset(&tsb2, 0, sizeof(tsb2));
3268 /* once per -file */
3269 for (ti = as->parms[1].items; ti; ti = ti->next) {
3270 /* Do this solely to see if the file is there */
3271 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3273 Die(errno, ti->data);
3278 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
3280 Die(errno, ti->data);
3285 if (verbose && (blob.out_size == sizeof(tsb2))) {
3286 if (tsb2.sb_thisfile == -1) {
3287 fprintf(stdout, "Will store %s according to default.\n",
3291 "Will store up to %d kbytes of %s asynchronously.\n",
3292 (tsb2.sb_thisfile / 1024), ti->data);
3297 /* If no files - make at least one pioctl call, or
3298 * set the allfiles default if we need to.
3300 if (!as->parms[1].items || (allfiles != -1)) {
3301 tsb.sb_default = allfiles;
3302 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
3304 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3309 /* Having no arguments also reports the default store asynchrony */
3310 if (verbose && (blob.out_size == sizeof(tsb2))) {
3311 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3312 (tsb2.sb_default / 1024));
3320 SetCryptCmd(struct cmd_syndesc *as, void *arock)
3322 afs_int32 code = 0, flag;
3323 struct ViceIoctl blob;
3326 tp = as->parms[0].items->data;
3327 if (strcmp(tp, "on") == 0)
3329 else if (strcmp(tp, "off") == 0)
3332 fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3336 blob.in = (char *)&flag;
3337 blob.in_size = sizeof(flag);
3339 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3347 GetCryptCmd(struct cmd_syndesc *as, void *arock)
3349 afs_int32 code = 0, flag;
3350 struct ViceIoctl blob;
3355 blob.out_size = sizeof(flag);
3358 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3364 memcpy(&flag, tp, sizeof(afs_int32));
3365 printf("Security level is currently ");
3367 printf("crypt (data security).\n");
3374 #ifdef AFS_DISCON_ENV
3375 static char *modenames[] = {
3378 "readonly", /* Not currently supported */
3379 "fetchonly", /* Not currently supported */
3380 "partial", /* Not currently supported */
3384 static char *policynames[] = {
3387 "closer", /* Not currently supported. */
3388 "manual", /* Not currently supported. */
3393 DisconCmd(struct cmd_syndesc *as, void *arock)
3395 struct cmd_item *ti;
3398 int modelen, policylen;
3399 afs_int32 mode, policy, code;
3400 struct ViceIoctl blob;
3405 space[0] = space[1] = space[2] = 0;
3407 ti = as->parms[0].items;
3409 modename = ti->data;
3410 modelen = strlen(modename);
3411 for (mode = 0; modenames[mode] != NULL; mode++)
3412 if (!strncasecmp(modename, modenames[mode], modelen))
3414 if (modenames[mode] == NULL)
3415 printf("Unknown discon mode \"%s\"\n", modename);
3417 space[0] = mode + 1;
3420 ti = as->parms[1].items;
3422 policyname = ti->data;
3423 policylen = strlen(policyname);
3424 for (policy = 0; policynames[policy] != NULL; policy++)
3425 if (!strncasecmp(policyname, policynames[policy], policylen))
3427 if (policynames[policy] == NULL)
3428 printf("Unknown discon mode \"%s\"\n", policyname);
3430 space[1] = policy + 1;
3434 if (as->parms[2].items) {
3436 printf("force on\n");
3440 blob.in_size = 3 * sizeof(afs_int32);
3442 blob.out_size = sizeof(mode);
3444 code = pioctl(0, VIOC_DISCON, &blob, 1);
3448 memcpy(&mode, space, sizeof mode);
3449 if (mode < sizeof modenames / sizeof (char *))
3450 printf("Discon mode is now \"%s\"\n", modenames[mode]);
3452 printf("Unknown discon mode %d\n", mode);
3459 #include "AFS_component_version_number.c"
3462 main(int argc, char **argv)
3465 struct cmd_syndesc *ts;
3467 #ifdef AFS_AIX32_ENV
3469 * The following signal action for AIX is necessary so that in case of a
3470 * crash (i.e. core is generated) we can include the user's data section
3471 * in the core dump. Unfortunately, by default, only a partial core is
3472 * generated which, in many cases, isn't too useful.
3474 struct sigaction nsa;
3476 sigemptyset(&nsa.sa_mask);
3477 nsa.sa_handler = SIG_DFL;
3478 nsa.sa_flags = SA_FULLDUMP;
3479 sigaction(SIGSEGV, &nsa, NULL);
3482 /* try to find volume location information */
3483 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
3484 "get client network interface addresses");
3485 cmd_CreateAlias(ts, "gc");
3487 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
3488 "set client network interface addresses");
3489 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3490 "client network interfaces");
3491 cmd_CreateAlias(ts, "sc");
3493 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL,
3494 "set server ranks");
3495 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3496 "fileserver names and ranks");
3497 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3498 "VL server names and ranks");
3499 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3500 "input from named file");
3501 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3502 cmd_CreateAlias(ts, "sp");
3504 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL,
3505 "get server ranks");
3506 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3507 "output to named file");
3508 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3509 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3510 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3511 cmd_CreateAlias(ts, "gp");
3513 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
3514 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3515 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3516 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3517 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL,
3518 "apply to negative rights");
3519 parm_setacl_id = ts->nParms;
3520 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL,
3521 "initial directory acl (DFS only)");
3522 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL,
3523 "initial file acl (DFS only)");
3524 cmd_CreateAlias(ts, "sa");
3526 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL,
3527 "list access control list");
3528 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3529 parm_listacl_id = ts->nParms;
3530 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3531 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3532 cmd_CreateAlias(ts, "la");
3534 ts = cmd_CreateSyntax("getcalleraccess", GetCallerAccess, NULL,
3535 "list callers access");
3536 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3537 cmd_CreateAlias(ts, "gca");
3539 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL,
3540 "clean up access control list");
3541 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3543 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL,
3544 "copy access control list");
3545 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0,
3546 "source directory (or DFS file)");
3547 cmd_AddParm(ts, "-todir", CMD_LIST, 0,
3548 "destination directory (or DFS file)");
3549 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3550 "first clear dest access list");
3551 parm_copyacl_id = ts->nParms;
3552 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3553 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3555 cmd_CreateAlias(ts, "ca");
3557 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
3558 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3559 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
3560 "flush mount symlink from cache");
3561 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3563 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
3564 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3565 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL,
3566 "disk space quota in 1K units");
3568 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL,
3569 "disk space guaranteed");
3570 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3572 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL,
3574 cmd_CreateAlias(ts, "sv");
3576 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL,
3577 "control Cache Manager messages");
3578 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL,
3579 "[user|console|all|none]");
3581 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
3582 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3583 cmd_CreateAlias(ts, "lv");
3584 cmd_CreateAlias(ts, "listvol");
3586 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
3587 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3588 cmd_CreateAlias(ts, "lq");
3590 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL,
3591 "show server disk space usage");
3592 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3593 cmd_CreateAlias(ts, "df");
3595 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
3596 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3598 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
3599 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3601 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
3602 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3603 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3604 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3605 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3606 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3607 "don't check name with VLDB");
3609 #if defined(AFS_CACHE_BYPASS)
3610 ts = cmd_CreateSyntax("bypassthreshold", BypassThresholdCmd, 0,
3611 "get/set cache bypass file size threshold");
3612 cmd_AddParm(ts, "-size", CMD_SINGLE, CMD_OPTIONAL, "file size");
3619 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3623 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
3624 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3626 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL,
3627 "check local cell's servers");
3628 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3629 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3630 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3631 "just list, don't check");
3632 cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL,
3633 "seconds between probes");
3635 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL,
3636 "check volumeID/name mappings");
3637 cmd_CreateAlias(ts, "checkbackups");
3640 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL,
3642 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3643 "size in 1K byte blocks (0 => reset)");
3644 cmd_CreateAlias(ts, "cachesize");
3646 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL,
3647 "reset size back to boot value");
3649 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL,
3650 "get cache usage info");
3651 cmd_AddParm(ts, "-files", CMD_FLAG, CMD_OPTIONAL, "Show cach files used as well");
3652 cmd_AddParm(ts, "-excessive", CMD_FLAG, CMD_OPTIONAL, "excessively verbose cache stats");
3654 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL,
3655 "list configured cells");
3656 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3658 ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, NULL,
3659 "list configured cell aliases");
3661 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
3662 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3663 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3665 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3667 cmd_CreateAlias(ts, "sq");
3669 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
3670 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3671 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3672 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL,
3673 "linked cell name");
3675 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
3676 "configure new cell alias");
3677 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
3678 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
3680 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3682 * Turn this on only if you wish to be able to talk to a server which is listening
3683 * on alternative ports. This is not intended for general use and may not be
3684 * supported in the cache manager. It is not a way to run two servers at the
3685 * same host, since the cache manager cannot properly distinguish those two hosts.
3687 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL,
3688 "cell's fileserver port");
3689 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL,
3690 "cell's vldb server port");
3693 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
3694 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3696 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
3697 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3699 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
3702 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, NULL, "obsolete (listed primary cell)");
3705 /* set cache monitor host address */
3706 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, (char *)CMD_HIDDEN);
3707 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL,
3708 "host name or 'off'");
3709 cmd_CreateAlias(ts, "mariner");
3711 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
3712 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3714 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
3715 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3716 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3717 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL,
3718 "disallow setuid programs");
3720 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL,
3721 "flush all data in volume");
3722 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3724 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL,
3725 "get/set sysname (i.e. @sys) value");
3726 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3728 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL,
3729 "enable/disable translators to AFS");
3730 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3731 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL,
3732 "start/stop translator (on | off)");
3733 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL,
3734 "convert from afs to unix mode (on | off)");
3735 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL,
3736 "run on strict 'uid check' mode (on | off)");
3737 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
3738 "allow nfs mounts to subdirs of /afs/.. (on | off)");
3739 cmd_AddParm(ts, "-clipags", CMD_SINGLE, CMD_OPTIONAL,
3740 "enable use of client-assigned PAG's (on | off)");
3741 cmd_AddParm(ts, "-pagcb", CMD_SINGLE, CMD_OPTIONAL,
3742 "enable callbacks to get creds from new clients (on | off)");
3745 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
3746 "store to server after file close");
3747 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL,
3748 "asynchrony for specified names");
3749 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3750 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL,
3751 "new default (KB)");
3752 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3753 cmd_CreateAlias(ts, "sb");
3755 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL,
3756 "set cache manager encryption flag");
3757 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3759 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL,
3760 "get cache manager encryption flag");
3762 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
3763 "Manage per process RX statistics");
3764 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3765 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3766 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3768 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
3769 "Manage per peer RX statistics");
3770 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3771 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3772 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3774 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
3775 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
3777 /* try to find volume location information */
3778 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL,
3779 "get fid for file(s)");
3780 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3782 #ifdef AFS_DISCON_ENV
3783 ts = cmd_CreateSyntax("discon", DisconCmd, NULL,
3784 "disconnection mode");
3785 cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_REQUIRED, "offline | online");
3786 cmd_AddParm(ts, "-policy", CMD_SINGLE, CMD_OPTIONAL, "client | server");
3787 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Force reconnection, despite any synchronization issues.");
3790 ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, NULL, "nuke credentials for NFS client");
3791 cmd_AddParm(ts, "-addr", CMD_SINGLE, 0, "host name or address");
3793 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
3794 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_REQUIRED, "generate a new UUID");
3796 ts = cmd_CreateSyntax("precache", PreCacheCmd, 0,
3797 "set precache size");
3798 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3799 "size in 1K byte blocks (0 => disable)");
3801 code = cmd_Dispatch(argc, argv);
3809 Die(int errnum, char *filename)
3815 "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3818 fprintf(stderr, "%s: Invalid argument.\n", pn);
3822 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3824 fprintf(stderr, "%s: no such file returned\n", pn);
3828 "%s: You can not change a backup or readonly volume\n", pn);
3834 "%s: You don't have the required access rights on '%s'\n",
3838 "%s: You do not have the required rights to do this operation\n",
3843 fprintf(stderr, "%s:'%s'", pn, filename);
3845 fprintf(stderr, "%s", pn);
3846 fprintf(stderr, ": %s\n", afs_error_message(errnum));
3851 /* get clients interface addresses */
3853 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3856 struct cmd_item *ti;
3858 struct ViceIoctl blob;
3859 struct sprefrequest *in;
3860 struct sprefinfo *out;
3862 in = (struct sprefrequest *)space;
3866 blob.in_size = sizeof(struct sprefrequest);
3867 blob.in = (char *)in;
3869 blob.out_size = MAXSIZE;
3872 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3873 /* returns addr in network byte order */
3874 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3876 perror("getClientInterfaceAddr pioctl");
3882 out = (struct sprefinfo *)blob.out;
3883 for (i = 0; i < out->num_servers; i++) {
3886 addr = ntohl(out->servers[i].server.s_addr);
3887 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3888 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3889 printf("%-50s\n", tbuffer);
3891 in->offset = out->next_offset;
3893 } while (out->next_offset > 0);
3899 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3901 afs_int32 code, addr;
3902 struct cmd_item *ti;
3904 struct ViceIoctl blob;
3905 struct setspref *ssp;
3906 int sizeUsed = 0, i, flag;
3907 afs_int32 existingAddr[1024]; /* existing addresses on this host */
3911 ssp = (struct setspref *)space;
3912 ssp->num_servers = 0;
3915 blob.out_size = MAXSIZE;
3918 fprintf(stderr, "Permission denied: requires root access.\n");
3922 /* extract all existing interface addresses */
3923 existNu = rx_getAllAddr(existingAddr, 1024);
3927 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
3928 for (ti = as->parms[0].items; ti; ti = ti->next) {
3929 if (sizeUsed >= sizeof(space)) {
3930 fprintf(stderr, "No more space\n");
3933 addr = extractAddr(ti->data, 20); /* network order */
3934 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
3935 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
3940 /* see if it is an address that really exists */
3941 for (flag = 0, i = 0; i < existNu; i++)
3942 if (existingAddr[i] == addr) {
3946 if (!flag) { /* this is an nonexistent address */
3947 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
3951 /* copy all specified addr into ioctl buffer */
3952 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
3953 printf("Adding 0x%08x\n", addr);
3955 sizeUsed += sizeof(struct spref);
3957 if (ssp->num_servers < 1) {
3958 fprintf(stderr, "No addresses specified\n");
3961 blob.in_size = sizeUsed - sizeof(struct spref);
3963 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
3973 FlushMountCmd(struct cmd_syndesc *as, void *arock)
3976 struct ViceIoctl blob;
3977 struct cmd_item *ti;
3978 char orig_name[1024]; /*Original name, may be modified */
3979 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
3980 char parent_dir[1024]; /*Parent directory of true name */
3981 char *last_component; /*Last component of true name */
3982 struct stat statbuff; /*Buffer for status info */
3983 int link_chars_read; /*Num chars read in readlink() */
3984 int thru_symlink; /*Did we get to a mount point via a symlink? */
3987 for (ti = as->parms[0].items; ti; ti = ti->next) {
3990 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
3993 if (lstat(orig_name, &statbuff) < 0) {
3994 /* if lstat fails, we should still try the pioctl, since it
3995 * may work (for example, lstat will fail, but pioctl will
3996 * work if the volume of offline (returning ENODEV). */
3997 statbuff.st_mode = S_IFDIR; /* lie like pros */
4001 * The lstat succeeded. If the given file is a symlink, substitute
4002 * the file name with the link name.
4004 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
4007 * Read name of resolved file.
4009 link_chars_read = readlink(orig_name, true_name, 1024);
4010 if (link_chars_read <= 0) {
4012 "%s: Can't read target name for '%s' symbolic link!\n",
4019 * Add a trailing null to what was read, bump the length.
4021 true_name[link_chars_read++] = 0;
4024 * If the symlink is an absolute pathname, we're fine. Otherwise, we
4025 * have to create a full pathname using the original name and the
4026 * relative symlink name. Find the rightmost slash in the original
4027 * name (we know there is one) and splice in the symlink value.
4029 if (true_name[0] != '/') {
4030 last_component = (char *)strrchr(orig_name, '/');
4031 strcpy(++last_component, true_name);
4032 strcpy(true_name, orig_name);
4035 strcpy(true_name, orig_name);
4038 * Find rightmost slash, if any.
4040 last_component = (char *)strrchr(true_name, '/');
4041 if (last_component) {
4043 * Found it. Designate everything before it as the parent directory,
4044 * everything after it as the final component.
4046 strncpy(parent_dir, true_name, last_component - true_name);
4047 parent_dir[last_component - true_name] = 0;
4048 last_component++; /*Skip the slash */
4051 * No slash appears in the given file name. Set parent_dir to the current
4052 * directory, and the last component as the given name.
4054 strcpy(parent_dir, ".");
4055 last_component = true_name;
4058 if (strcmp(last_component, ".") == 0
4059 || strcmp(last_component, "..") == 0) {
4061 "%s: you may not use '.' or '..' as the last component\n",
4063 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
4069 blob.in = last_component;
4070 blob.in_size = strlen(last_component) + 1;
4072 memset(space, 0, MAXSIZE);
4074 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4077 if (errno == EINVAL) {
4078 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4080 Die(errno, (ti->data ? ti->data : parent_dir));
4089 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4092 afs_int32 flags = 0;
4093 struct ViceIoctl blob;
4094 struct cmd_item *ti;
4096 if (as->parms[0].items) { /* -enable */
4097 flags |= AFSCALL_RXSTATS_ENABLE;
4099 if (as->parms[1].items) { /* -disable */
4100 flags |= AFSCALL_RXSTATS_DISABLE;
4102 if (as->parms[2].items) { /* -clear */
4103 flags |= AFSCALL_RXSTATS_CLEAR;
4106 fprintf(stderr, "You must specify at least one argument\n");
4110 blob.in = (char *)&flags;
4111 blob.in_size = sizeof(afs_int32);
4114 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4124 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4127 afs_int32 flags = 0;
4128 struct ViceIoctl blob;
4129 struct cmd_item *ti;
4131 if (as->parms[0].items) { /* -enable */
4132 flags |= AFSCALL_RXSTATS_ENABLE;
4134 if (as->parms[1].items) { /* -disable */
4135 flags |= AFSCALL_RXSTATS_DISABLE;
4137 if (as->parms[2].items) { /* -clear */
4138 flags |= AFSCALL_RXSTATS_CLEAR;
4141 fprintf(stderr, "You must specify at least one argument\n");
4145 blob.in = (char *)&flags;
4146 blob.in_size = sizeof(afs_int32);
4149 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4159 GetFidCmd(struct cmd_syndesc *as, void *arock)
4161 struct ViceIoctl blob;
4162 struct cmd_item *ti;
4163 for (ti = as->parms[0].items; ti; ti = ti->next) {
4164 struct VenusFid vfid;
4166 blob.out_size = sizeof(struct VenusFid);
4167 blob.out = (char *) &vfid;
4170 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
4171 printf("File %s (%u.%u.%u) contained in volume %u\n",
4172 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,