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>
14 #include <afs/afs_consts.h>
15 #include <afs/afs_args.h>
17 #include <sys/ioctl.h>
18 #include <sys/socket.h>
23 #include <netinet/in.h>
27 #include <afs/venus.h>
28 #include <afs/com_err.h>
29 #include <afs/afs_consts.h>
38 #include "afs/prs_fs.h"
39 #include <afs/afsint.h>
40 #include <afs/cellconfig.h>
43 #include <rx/rx_globals.h>
44 #include <afs/vldbint.h>
45 #include <afs/volser.h>
46 #include <afs/vlserver.h>
48 #include <afs/afsutil.h>
49 #include <afs/com_err.h>
52 #include <afs/ptclient.h>
53 #include <afs/ptuser.h>
54 #include <afs/afsutil.h>
55 #include <afs/sys_prototypes.h>
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[AFS_PIOCTL_MAXSIZE];
62 static char tspace[1024];
63 static struct ubik_client *uclient;
65 static int GetClientAddrsCmd(struct cmd_syndesc *, void *);
66 static int SetClientAddrsCmd(struct cmd_syndesc *, void *);
67 static int FlushMountCmd(struct cmd_syndesc *, void *);
68 static int RxStatProcCmd(struct cmd_syndesc *, void *);
69 static int RxStatPeerCmd(struct cmd_syndesc *, void *);
70 static int GetFidCmd(struct cmd_syndesc *, void *);
71 static int UuidCmd(struct cmd_syndesc *, void *);
73 static char pn[] = "fs";
74 static int rxInitDone = 0;
78 static void ZapList(struct AclEntry *);
79 static int PruneList(struct AclEntry **, int);
80 static int CleanAcl(struct Acl *, char *);
81 static int SetVolCmd(struct cmd_syndesc *as, void *arock);
82 static int GetCellName(char *, struct afsconf_cell *);
83 static int VLDBInit(int, struct afsconf_cell *);
84 static void Die(int, char *);
87 * Character to use between name and rights in printed representation for
90 #define DFS_SEPARATOR ' '
92 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
95 int dfs; /* Originally true if a dfs acl; now also the type
96 * of the acl (1, 2, or 3, corresponding to object,
97 * initial dir, or initial object). */
98 sec_rgy_name_t cell; /* DFS cell name */
101 struct AclEntry *pluslist;
102 struct AclEntry *minuslist;
106 struct AclEntry *next;
112 afs_int32 callerAccess;
119 ZapAcl(struct Acl *acl)
123 ZapList(acl->pluslist);
124 ZapList(acl->minuslist);
129 foldcmp(char *a, char *b)
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)
285 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
289 struct ViceIoctl blob;
293 blob.out_size = AFS_PIOCTL_MAXSIZE;
296 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
298 if ((errno == EINVAL) || (errno == ENOENT))
304 /* return a static pointer to a buffer */
309 strlcpy(tspace, apath, sizeof(tspace));
310 tp = strrchr(tspace, '/');
311 if (tp == (char *)tspace)
313 else if (tp == (char *)NULL) {
321 enum rtype { add, destroy, deny };
324 Convert(char *arights, int dfs, enum rtype *rtypep)
330 *rtypep = add; /* add rights, by default */
333 if (!strcmp(arights, "null")) {
337 if (!strcmp(arights, "read"))
338 return DFS_READ | DFS_EXECUTE;
339 if (!strcmp(arights, "write"))
340 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
342 if (!strcmp(arights, "all"))
343 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
344 DFS_WRITE | DFS_CONTROL;
346 if (!strcmp(arights, "read"))
347 return PRSFS_READ | PRSFS_LOOKUP;
348 if (!strcmp(arights, "write"))
349 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
350 PRSFS_WRITE | PRSFS_LOCK;
351 if (!strcmp(arights, "mail"))
352 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
353 if (!strcmp(arights, "all"))
354 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
355 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
357 if (!strcmp(arights, "none")) {
358 *rtypep = destroy; /* Remove entire entry */
361 len = strlen(arights);
363 for (i = 0; i < len; i++) {
397 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
405 mode |= PRSFS_LOOKUP;
407 mode |= PRSFS_INSERT;
409 mode |= PRSFS_DELETE;
415 mode |= PRSFS_ADMINISTER;
433 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
442 static struct AclEntry *
443 FindList(struct AclEntry *alist, char *aname)
446 if (!foldcmp(alist->name, aname))
453 /* if no parm specified in a particular slot, set parm to be "." instead */
455 SetDotDefault(struct cmd_item **aitemp)
459 return; /* already has value */
460 /* otherwise, allocate an item representing "." */
461 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
463 ti->next = (struct cmd_item *)0;
464 ti->data = (char *)malloc(2);
466 strcpy(ti->data, ".");
471 ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
473 struct AclEntry *tlist;
474 tlist = (plus ? al->pluslist : al->minuslist);
475 tlist = FindList(tlist, aname);
477 /* Found the item already in the list. */
478 tlist->rights = arights;
480 al->nplus -= PruneList(&al->pluslist, al->dfs);
482 al->nminus -= PruneList(&al->minuslist, al->dfs);
485 /* Otherwise we make a new item and plug in the new data. */
486 tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry));
488 strcpy(tlist->name, aname);
489 tlist->rights = arights;
491 tlist->next = al->pluslist;
492 al->pluslist = tlist;
494 if (arights == 0 || arights == -1)
495 al->nplus -= PruneList(&al->pluslist, al->dfs);
497 tlist->next = al->minuslist;
498 al->minuslist = tlist;
501 al->nminus -= PruneList(&al->minuslist, al->dfs);
506 ZapList(struct AclEntry *alist)
508 struct AclEntry *tp, *np;
509 for (tp = alist; tp; tp = np) {
516 PruneList(struct AclEntry **ae, int dfs)
518 struct AclEntry **lp;
519 struct AclEntry *te, *ne;
523 for (te = *ae; te; te = ne) {
524 if ((!dfs && te->rights == 0) || te->rights == -1) {
540 while (*astr != '\n')
547 * Create an empty acl, taking into account whether the acl pointed
548 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
549 * can recover from problems caused by bogus ACL's (in that case, always
550 * assume that the acl is AFS: for DFS, the user can always resort to
551 * acl_edit, but for AFS there may be no other way out).
559 tp = (struct Acl *)malloc(sizeof(struct Acl));
561 tp->nplus = tp->nminus = 0;
562 tp->pluslist = tp->minuslist = 0;
564 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
571 int nplus, nminus, i, trights;
573 struct AclEntry *first, *last, *tl;
576 ta = (struct Acl *)malloc(sizeof(struct Acl));
579 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
580 astr = SkipLine(astr);
581 sscanf(astr, "%d", &ta->nminus);
582 astr = SkipLine(astr);
589 for (i = 0; i < nplus; i++) {
590 sscanf(astr, "%100s %d", tname, &trights);
591 astr = SkipLine(astr);
592 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
596 strcpy(tl->name, tname);
597 tl->rights = trights;
603 ta->pluslist = first;
607 for (i = 0; i < nminus; i++) {
608 sscanf(astr, "%100s %d", tname, &trights);
609 astr = SkipLine(astr);
610 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
614 strcpy(tl->name, tname);
615 tl->rights = trights;
621 ta->minuslist = first;
627 PrintStatus(VolumeStatus * status, char *name, char *offmsg)
629 printf("Volume status for vid = %u named %s\n", status->Vid, name);
631 printf("Current offline message is %s\n", offmsg);
632 printf("Current disk quota is ");
633 if (status->MaxQuota != 0)
634 printf("%d\n", status->MaxQuota);
636 printf("unlimited\n");
637 printf("Current blocks used are %d\n", status->BlocksInUse);
638 printf("The partition has %d blocks available out of %d\n\n",
639 status->PartBlocksAvail, status->PartMaxBlocks);
643 static const char power_letter[] = {
652 HumanPrintSpace(afs_int32 int_space)
655 int exponent_max = sizeof(power_letter) - 1;
656 float space = int_space;
658 while (space >= 1024 && exponent < exponent_max) {
662 printf("%9.1f%c", space, power_letter[exponent]);
666 QuickPrintStatus(VolumeStatus * status, char *name, int human)
668 double QuotaUsed = 0.0;
669 double PartUsed = 0.0;
671 printf("%-25.25s", name);
673 if (status->MaxQuota != 0) {
676 HumanPrintSpace(status->MaxQuota);
678 HumanPrintSpace(status->BlocksInUse);
681 printf(" %10d %10d", status->MaxQuota, status->BlocksInUse);
683 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
685 printf(" no limit ");
687 HumanPrintSpace(status->BlocksInUse);
689 printf("%10d", status->BlocksInUse);
691 if (QuotaUsed > 90.0) {
692 printf("%5.0f%%<<", QuotaUsed);
695 printf("%5.0f%% ", QuotaUsed);
698 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
700 if (PartUsed > 97.0) {
701 printf("%9.0f%%<<", PartUsed);
704 printf("%9.0f%% ", PartUsed);
706 printf(" <<WARNING\n");
713 QuickPrintSpace(VolumeStatus * status, char *name, int human)
715 double PartUsed = 0.0;
717 printf("%-25.25s", name);
720 HumanPrintSpace(status->PartMaxBlocks);
721 HumanPrintSpace(status->PartMaxBlocks - status->PartBlocksAvail);
722 HumanPrintSpace(status->PartBlocksAvail);
725 printf("%10d%10d%10d", status->PartMaxBlocks,
726 status->PartMaxBlocks - status->PartBlocksAvail,
727 status->PartBlocksAvail);
731 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
733 if (PartUsed > 90.0) {
734 printf(" %4.0f%%<<", PartUsed);
737 printf(" %4.0f%% ", PartUsed);
739 printf(" <<WARNING\n");
746 AclToString(struct Acl *acl)
748 static char mydata[AFS_PIOCTL_MAXSIZE];
749 char tstring[AFS_PIOCTL_MAXSIZE];
754 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
757 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
758 for (tp = acl->pluslist; tp; tp = tp->next) {
759 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
760 strcat(mydata, tstring);
762 for (tp = acl->minuslist; tp; tp = tp->next) {
763 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
764 strcat(mydata, tstring);
770 SetACLCmd(struct cmd_syndesc *as, void *arock)
773 struct ViceIoctl blob;
775 struct cmd_item *ti, *ui;
779 int idf = getidf(as, parm_setacl_id);
782 if (as->parms[2].items)
786 plusp = !(as->parms[3].items);
787 for (ti = as->parms[0].items; ti; ti = ti->next) {
788 blob.out_size = AFS_PIOCTL_MAXSIZE;
790 blob.in = blob.out = space;
791 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
793 Die(errno, ti->data);
800 ta = ParseAcl(space);
801 if (!plusp && ta->dfs) {
803 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
805 "(you may specify \"null\" to revoke all rights, however)\n");
813 ta = EmptyAcl(space);
815 ta = ParseAcl(space);
816 CleanAcl(ta, ti->data);
817 for (ui = as->parms[1].items; ui; ui = ui->next->next) {
821 "%s: Missing second half of user/access pair.\n", pn);
825 rights = Convert(ui->next->data, ta->dfs, &rtype);
826 if (rtype == destroy && !ta->dfs) {
827 struct AclEntry *tlist;
829 tlist = (plusp ? ta->pluslist : ta->minuslist);
830 if (!FindList(tlist, ui->data))
833 if (rtype == deny && !ta->dfs)
835 if (rtype == destroy && ta->dfs)
837 ChangeList(ta, plusp, ui->data, rights);
839 blob.in = AclToString(ta);
841 blob.in_size = 1 + strlen(blob.in);
842 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
844 if (errno == EINVAL) {
846 static char *fsenv = 0;
848 fsenv = (char *)getenv("FS_EXPERT");
851 "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n",
855 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
856 "\nPossible reasons for this include:\n\n",
857 " -You may have specified an inappropriate combination of rights.\n",
858 " For example, some DFS-supported filesystems may not allow you to\n",
859 " drop the \"c\" right from \"user_obj\".\n\n",
860 " -A mask_obj may be required (it is likely required by the underlying\n",
861 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
862 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
863 " does not automatically create or update the mask_obj. Try setting\n",
864 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
865 " users or groups. You can do this with a single command, such as\n",
866 " \"fs sa mask_obj all user:somename read\"\n\n",
867 " -A specified user or group may not exist.\n\n",
868 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
869 " This is probably not allowed by the underlying file system.\n\n",
870 " -If you add a user or group to a DFS ACL, remember that it must be\n",
871 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
872 " may be local requirements on the format of the user or group name.\n",
873 " Check with your cell administrator.\n\n",
874 " -Or numerous other possibilities. It would be great if we could be more\n",
875 " precise about the actual problem, but for various reasons, this is\n",
876 " impractical via this interface. If you can't figure it out, you\n",
877 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
878 " whatever is provided). You may get better results. Good luck!\n\n",
879 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
883 "%s: Invalid argument, possible reasons include:\n",
885 fprintf(stderr, "\t-File not in AFS\n");
887 "\t-Too many users on access control list\n");
889 "\t-Tried to add non-existent user to access control list\n");
892 Die(errno, ti->data);
904 CopyACLCmd(struct cmd_syndesc *as, void *arock)
907 struct ViceIoctl blob;
908 struct Acl *fa, *ta = 0;
912 int idf = getidf(as, parm_copyacl_id);
915 if (as->parms[2].items)
919 blob.out_size = AFS_PIOCTL_MAXSIZE;
921 blob.in = blob.out = space;
922 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
924 Die(errno, as->parms[0].items->data);
927 fa = ParseAcl(space);
928 CleanAcl(fa, as->parms[0].items->data);
929 for (ti = as->parms[1].items; ti; ti = ti->next) {
930 blob.out_size = AFS_PIOCTL_MAXSIZE;
932 blob.in = blob.out = space;
933 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
935 Die(errno, ti->data);
943 ta = EmptyAcl(space);
945 ta = ParseAcl(space);
946 CleanAcl(ta, ti->data);
947 if (ta->dfs != fa->dfs) {
949 "%s: incompatible file system types: acl not copied to %s; aborted\n",
955 if (!clear && strcmp(ta->cell, fa->cell) != 0) {
957 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
962 strcpy(ta->cell, fa->cell);
964 for (tp = fa->pluslist; tp; tp = tp->next)
965 ChangeList(ta, 1, tp->name, tp->rights);
966 for (tp = fa->minuslist; tp; tp = tp->next)
967 ChangeList(ta, 0, tp->name, tp->rights);
968 blob.in = AclToString(ta);
970 blob.in_size = 1 + strlen(blob.in);
971 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
973 if (errno == EINVAL) {
975 "%s: Invalid argument, possible reasons include:\n",
977 fprintf(stderr, "\t-File not in AFS\n");
979 Die(errno, ti->data);
990 /* pioctl() call to get the cellname of a pathname */
992 GetCell(char *fname, char *cellname)
995 struct ViceIoctl blob;
998 blob.out_size = MAXCELLCHARS;
1001 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1002 return code ? errno : 0;
1005 /* Check if a username is valid: If it contains only digits (or a
1006 * negative sign), then it might be bad. We then query the ptserver
1010 BadName(char *aname, char *fname)
1012 afs_int32 tc, code, id;
1014 char cell[MAXCELLCHARS];
1016 for (nm = aname; (tc = *nm); nm++) {
1017 /* all must be '-' or digit to be bad */
1018 if (tc != '-' && (tc < '0' || tc > '9'))
1022 /* Go to the PRDB and see if this all number username is valid */
1023 code = GetCell(fname, cell);
1027 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
1028 code = pr_SNameToId(aname, &id);
1031 /* 1=>Not-valid; 0=>Valid */
1032 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1036 /* clean up an access control list of its bad entries; return 1 if we made
1037 any changes to the list, and 0 otherwise */
1039 CleanAcl(struct Acl *aa, char *fname)
1041 struct AclEntry *te, **le, *ne;
1044 /* Don't correct DFS ACL's for now */
1048 /* prune out bad entries */
1049 changes = 0; /* count deleted entries */
1051 for (te = aa->pluslist; te; te = ne) {
1053 if (BadName(te->name, fname)) {
1063 le = &aa->minuslist;
1064 for (te = aa->minuslist; te; te = ne) {
1066 if (BadName(te->name, fname)) {
1080 /* clean up an acl to not have bogus entries */
1082 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1086 struct ViceIoctl blob;
1088 struct cmd_item *ti;
1089 struct AclEntry *te;
1092 SetDotDefault(&as->parms[0].items);
1093 for (ti = as->parms[0].items; ti; ti = ti->next) {
1094 blob.out_size = AFS_PIOCTL_MAXSIZE;
1097 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1099 Die(errno, ti->data);
1106 ta = ParseAcl(space);
1109 "%s: cleanacl is not supported for DFS access lists.\n",
1115 changes = CleanAcl(ta, ti->data);
1118 /* now set the acl */
1119 blob.in = AclToString(ta);
1120 blob.in_size = strlen(blob.in) + 1;
1122 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1124 if (errno == EINVAL) {
1126 "%s: Invalid argument, possible reasons include\n",
1128 fprintf(stderr, "%s: File not in vice or\n", pn);
1130 "%s: Too many users on access control list or\n",
1133 Die(errno, ti->data);
1139 /* now list the updated acl */
1140 printf("Access list for %s is now\n", ti->data);
1141 if (ta->nplus > 0) {
1143 printf("Normal rights:\n");
1144 for (te = ta->pluslist; te; te = te->next) {
1145 printf(" %s ", te->name);
1146 PRights(te->rights, ta->dfs);
1150 if (ta->nminus > 0) {
1151 printf("Negative rights:\n");
1152 for (te = ta->minuslist; te; te = te->next) {
1153 printf(" %s ", te->name);
1154 PRights(te->rights, ta->dfs);
1161 printf("Access list for %s is fine.\n", ti->data);
1169 ListACLCmd(struct cmd_syndesc *as, void *arock)
1173 struct ViceIoctl blob;
1174 struct AclEntry *te;
1175 struct cmd_item *ti;
1176 int idf = getidf(as, parm_listacl_id);
1179 SetDotDefault(&as->parms[0].items);
1180 for (ti = as->parms[0].items; ti; ti = ti->next) {
1181 blob.out_size = AFS_PIOCTL_MAXSIZE;
1183 blob.in = blob.out = space;
1184 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1186 Die(errno, ti->data);
1190 ta = ParseAcl(space);
1191 if (as->parms[3].items) { /* -cmd */
1192 printf("fs setacl -dir %s -acl ", ti->data);
1193 if (ta->nplus > 0) {
1194 for (te = ta->pluslist; te; te = te->next) {
1195 printf(" %s ", te->name);
1196 PRights(te->rights, ta->dfs);
1200 if (ta->nminus > 0) {
1201 printf("fs setacl -dir %s -acl ", ti->data);
1202 for (te = ta->minuslist; te; te = te->next) {
1203 printf(" %s ", te->name);
1204 PRights(te->rights, ta->dfs);
1206 printf(" -negative\n");
1211 printf("Access list for %s is\n", ti->data);
1214 printf("DFS access list for %s is\n", ti->data);
1217 printf("DFS initial directory access list of %s is\n", ti->data);
1220 printf("DFS initial file access list of %s is\n", ti->data);
1224 printf(" Default cell = %s\n", ta->cell);
1226 if (ta->nplus > 0) {
1228 printf("Normal rights:\n");
1229 for (te = ta->pluslist; te; te = te->next) {
1230 printf(" %s ", te->name);
1231 PRights(te->rights, ta->dfs);
1235 if (ta->nminus > 0) {
1236 printf("Negative rights:\n");
1237 for (te = ta->minuslist; te; te = te->next) {
1238 printf(" %s ", te->name);
1239 PRights(te->rights, ta->dfs);
1252 GetCallerAccess(struct cmd_syndesc *as, void *arock)
1254 struct cmd_item *ti;
1257 SetDotDefault(&as->parms[0].items);
1258 for (ti = as->parms[0].items; ti; ti = ti->next) {
1260 struct ViceIoctl blob;
1261 struct vcxstat2 stat;
1262 blob.out_size = sizeof(struct vcxstat2);
1264 blob.out = (void *)&stat;
1265 code = pioctl(ti->data, VIOC_GETVCXSTATUS2, &blob, 1);
1267 Die(errno, ti->data);
1271 printf("Callers access to %s is ", ti->data);
1272 PRights(stat.callerAccess, 0);
1279 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1282 struct ViceIoctl blob;
1283 struct cmd_item *ti;
1286 SetDotDefault(&as->parms[0].items);
1287 for (ti = as->parms[0].items; ti; ti = ti->next) {
1288 blob.in_size = blob.out_size = 0;
1289 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1291 fprintf(stderr, "Error flushing volume ");
1301 * The Windows version of UuidCmd displays the UUID.
1302 * When the UNIX version is updated to do the same
1303 * be sure to replace the CMD_REQUIRED flag with
1304 * CMD_OPTIONAL in the cmd_AddParam(-generate) call
1307 UuidCmd(struct cmd_syndesc *as, void *arock)
1310 struct ViceIoctl blob;
1315 if (as->parms[0].items) {
1317 fprintf (stderr, "Permission denied: requires root access.\n");
1321 /* generate new UUID */
1322 code = pioctl(0, VIOC_NEWUUID, &blob, 1);
1329 printf("New uuid generated.\n");
1331 /* This will never execute */
1332 printf("Please add the '-generate' option to generate a new UUID.\n");
1337 #if defined(AFS_CACHE_BYPASS)
1339 * Set cache-bypass threshold. Files larger than this size will not be cached.
1340 * With a threshold of 0, the cache is always bypassed. With a threshold of -1,
1341 * cache bypass is disabled.
1345 BypassThresholdCmd(struct cmd_syndesc *as, void *arock)
1348 struct ViceIoctl blob;
1349 afs_int32 threshold_i, threshold_o;
1352 /* if new threshold supplied, then set and confirm, else,
1353 * get current threshold and print
1356 if(as->parms[0].items) {
1359 tp = as->parms[0].items->data;
1362 for(ix = 0; ix < len; ++ix) {
1363 if(!isdigit(tp[0])) {
1369 fprintf(stderr, "fs bypassthreshold -size: %s must be an undecorated digit string.\n", tp);
1372 threshold_i = atoi(tp);
1373 if(ix > 9 && threshold_i < 2147483647)
1374 threshold_i = 2147483647;
1375 blob.in = (char *) &threshold_i;
1376 blob.in_size = sizeof(threshold_i);
1382 blob.out = (char *) &threshold_o;
1383 blob.out_size = sizeof(threshold_o);
1384 code = pioctl(0, VIOC_SETBYPASS_THRESH, &blob, 1);
1389 printf("Cache bypass threshold %d", threshold_o);
1390 if(threshold_o == -1)
1391 printf(" (disabled)");
1401 FlushCmd(struct cmd_syndesc *as, void *arock)
1404 struct ViceIoctl blob;
1405 struct cmd_item *ti;
1408 for (ti = as->parms[0].items; ti; ti = ti->next) {
1409 blob.in_size = blob.out_size = 0;
1410 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1412 if (errno == EMFILE) {
1413 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1416 fprintf(stderr, "%s: Error flushing file ", pn);
1426 /* all this command does is repackage its args and call SetVolCmd */
1428 SetQuotaCmd(struct cmd_syndesc *as, void *arock)
1430 struct cmd_syndesc ts;
1432 /* copy useful stuff from our command slot; we may later have to reorder */
1433 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1434 return SetVolCmd(&ts, arock);
1438 SetVolCmd(struct cmd_syndesc *as, void *arock)
1441 struct ViceIoctl blob;
1442 struct cmd_item *ti;
1443 struct VolumeStatus *status;
1444 char *offmsg, *input;
1447 SetDotDefault(&as->parms[0].items);
1448 for (ti = as->parms[0].items; ti; ti = ti->next) {
1450 blob.out_size = AFS_PIOCTL_MAXSIZE;
1451 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1454 status = (VolumeStatus *) space;
1455 status->MinQuota = status->MaxQuota = -1;
1457 if (as->parms[1].items) {
1458 code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota);
1460 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1465 if (as->parms[2].items)
1466 offmsg = as->parms[2].items->data;
1467 input = (char *)status + sizeof(*status);
1468 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1470 if (strlen(offmsg) >= VMSGSIZE) {
1472 "%s: message must be shorter than %d characters\n",
1477 strcpy(input, offmsg);
1478 blob.in_size += strlen(offmsg);
1479 input += strlen(offmsg) + 1;
1482 *(input++) = '\0'; /* Pad for old style volume "motd" */
1483 code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1);
1485 Die(errno, ti->data);
1493 * Why is VenusFid declared in the kernel-only section of afs.h,
1494 * if it's the exported interface of the cache manager?
1502 ExamineCmd(struct cmd_syndesc *as, void *arock)
1505 struct ViceIoctl blob;
1506 struct cmd_item *ti;
1507 struct VolumeStatus *status;
1508 char *name, *offmsg;
1511 SetDotDefault(&as->parms[0].items);
1512 for (ti = as->parms[0].items; ti; ti = ti->next) {
1513 struct VenusFid vfid;
1516 blob.out_size = AFS_PIOCTL_MAXSIZE;
1519 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1521 Die(errno, ti->data);
1525 status = (VolumeStatus *) space;
1526 name = (char *)status + sizeof(*status);
1527 offmsg = name + strlen(name) + 1;
1529 blob.out_size = sizeof(struct VenusFid);
1530 blob.out = (char *) &vfid;
1531 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1532 printf("File %s (%u.%u.%u) contained in volume %u\n",
1533 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1537 PrintStatus(status, name, offmsg);
1543 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1546 struct ViceIoctl blob;
1547 struct cmd_item *ti;
1548 struct VolumeStatus *status;
1553 if (as->parms[1].items)
1556 printf("%-25s%-11s%-11s%-7s%-11s\n", "Volume Name", " Quota",
1557 " Used", " %Used", " Partition");
1558 SetDotDefault(&as->parms[0].items);
1559 for (ti = as->parms[0].items; ti; ti = ti->next) {
1561 blob.out_size = AFS_PIOCTL_MAXSIZE;
1564 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1566 Die(errno, ti->data);
1570 status = (VolumeStatus *) space;
1571 name = (char *)status + sizeof(*status);
1572 QuickPrintStatus(status, name, human);
1578 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1581 struct ViceIoctl blob;
1582 struct cmd_item *ti;
1588 SetDotDefault(&as->parms[0].items);
1589 for (ti = as->parms[0].items; ti; ti = ti->next) {
1591 blob.out_size = AFS_PIOCTL_MAXSIZE;
1594 memset(space, 0, sizeof(space));
1595 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1597 Die(errno, ti->data);
1601 hosts = (afs_int32 *) space;
1602 printf("File %s is on host%s ", ti->data,
1603 (hosts[0] && !hosts[1]) ? "" : "s");
1604 for (j = 0; j < AFS_MAXHOSTS; j++) {
1607 tp = hostutil_GetNameByINet(hosts[j]);
1617 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1620 struct ViceIoctl blob;
1621 struct cmd_item *ti;
1623 struct VolumeStatus *status;
1627 if (as->parms[1].items)
1630 printf("%-25s%10s%10s%10s%6s\n", "Volume Name",
1631 human ? "total" : "kbytes", "used", "avail", "%used");
1632 SetDotDefault(&as->parms[0].items);
1633 for (ti = as->parms[0].items; ti; ti = ti->next) {
1635 blob.out_size = AFS_PIOCTL_MAXSIZE;
1638 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1640 Die(errno, ti->data);
1644 status = (VolumeStatus *) space;
1645 name = (char *)status + sizeof(*status);
1646 QuickPrintSpace(status, name, human);
1652 QuotaCmd(struct cmd_syndesc *as, void *arock)
1655 struct ViceIoctl blob;
1656 struct cmd_item *ti;
1658 struct VolumeStatus *status;
1661 SetDotDefault(&as->parms[0].items);
1662 for (ti = as->parms[0].items; ti; ti = ti->next) {
1664 blob.out_size = AFS_PIOCTL_MAXSIZE;
1667 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1669 Die(errno, ti->data);
1673 status = (VolumeStatus *) space;
1674 if (status->MaxQuota)
1676 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
1679 printf("%2.0f%% of quota used.\n", quotaPct);
1685 ListMountCmd(struct cmd_syndesc *as, void *arock)
1688 struct ViceIoctl blob;
1689 struct cmd_item *ti;
1690 char orig_name[1024]; /*Original name, may be modified */
1691 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
1692 char parent_dir[1024]; /*Parent directory of true name */
1693 char *last_component; /*Last component of true name */
1694 struct stat statbuff; /*Buffer for status info */
1695 int link_chars_read; /*Num chars read in readlink() */
1696 int thru_symlink; /*Did we get to a mount point via a symlink? */
1699 for (ti = as->parms[0].items; ti; ti = ti->next) {
1702 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
1705 if (lstat(orig_name, &statbuff) < 0) {
1706 /* if lstat fails, we should still try the pioctl, since it
1707 * may work (for example, lstat will fail, but pioctl will
1708 * work if the volume of offline (returning ENODEV). */
1709 statbuff.st_mode = S_IFDIR; /* lie like pros */
1713 * The lstat succeeded. If the given file is a symlink, substitute
1714 * the file name with the link name.
1716 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1719 * Read name of resolved file.
1721 link_chars_read = readlink(orig_name, true_name, 1024);
1722 if (link_chars_read <= 0) {
1724 "%s: Can't read target name for '%s' symbolic link!\n",
1731 * Add a trailing null to what was read, bump the length.
1733 true_name[link_chars_read++] = 0;
1736 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1737 * have to create a full pathname using the original name and the
1738 * relative symlink name. Find the rightmost slash in the original
1739 * name (we know there is one) and splice in the symlink value.
1741 if (true_name[0] != '/') {
1742 last_component = (char *)strrchr(orig_name, '/');
1743 strcpy(++last_component, true_name);
1744 strcpy(true_name, orig_name);
1747 strcpy(true_name, orig_name);
1750 * Find rightmost slash, if any.
1752 last_component = (char *)strrchr(true_name, '/');
1753 if (last_component == (char *)true_name) {
1754 strcpy(parent_dir, "/");
1757 else if (last_component != (char *)NULL) {
1759 * Found it. Designate everything before it as the parent directory,
1760 * everything after it as the final component.
1762 strncpy(parent_dir, true_name, last_component - true_name);
1763 parent_dir[last_component - true_name] = 0;
1764 last_component++; /*Skip the slash */
1767 * No slash appears in the given file name. Set parent_dir to the current
1768 * directory, and the last component as the given name.
1770 strcpy(parent_dir, ".");
1771 last_component = true_name;
1774 if (strcmp(last_component, ".") == 0
1775 || strcmp(last_component, "..") == 0) {
1777 "%s: you may not use '.' or '..' as the last component\n",
1779 fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n",
1785 blob.in = last_component;
1786 blob.in_size = strlen(last_component) + 1;
1787 blob.out_size = AFS_PIOCTL_MAXSIZE;
1789 memset(space, 0, AFS_PIOCTL_MAXSIZE);
1791 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1794 printf("'%s' is a %smount point for volume '%s'\n", ti->data,
1795 (thru_symlink ? "symbolic link, leading to a " : ""),
1798 if (errno == EINVAL) {
1799 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
1801 Die(errno, (ti->data ? ti->data : parent_dir));
1810 MakeMountCmd(struct cmd_syndesc *as, void *arock)
1813 char *cellName, *volName, *tmpName;
1814 struct afsconf_cell info;
1815 struct vldbentry vldbEntry;
1816 struct ViceIoctl blob;
1822 if (as->parms[5].items && !as->parms[2].items) {
1823 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1828 if (as->parms[2].items) /* cell name specified */
1829 cellName = as->parms[2].items->data;
1832 volName = as->parms[1].items->data;
1834 if (strlen(volName) >= 64) {
1836 "%s: volume name too long (length must be < 64 characters)\n",
1841 /* Check for a cellname in the volume specification, and complain
1842 * if it doesn't match what was specified with -cell */
1843 if ((tmpName = strchr(volName, ':'))) {
1846 if (strcasecmp(cellName, volName)) {
1847 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1852 volName = ++tmpName;
1855 if (!InAFS(Parent(as->parms[0].items->data))) {
1857 "%s: mount points must be created within the AFS file system\n",
1864 blob.out_size = AFS_PIOCTL_MAXSIZE;
1867 pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME,
1871 code = GetCellName(cellName ? cellName : space, &info);
1875 if (!(as->parms[4].items)) {
1876 /* not fast, check which cell the mountpoint is being created in */
1877 /* not fast, check name with VLDB */
1878 code = VLDBInit(1, &info);
1880 /* make the check. Don't complain if there are problems with init */
1882 ubik_VL_GetEntryByNameO(uclient, 0, volName,
1884 if (code == VL_NOENT) {
1886 "%s: warning, volume %s does not exist in cell %s.\n",
1887 pn, volName, cellName ? cellName : space);
1892 if (as->parms[3].items) /* if -rw specified */
1897 /* cellular mount point, prepend cell prefix */
1898 strcat(space, info.name);
1901 strcat(space, volName); /* append volume name */
1902 strcat(space, "."); /* stupid convention; these end with a period */
1903 code = symlink(space, as->parms[0].items->data);
1905 Die(errno, as->parms[0].items->data);
1912 * Delete AFS mount points. Variables are used as follows:
1913 * tbuffer: Set to point to the null-terminated directory name of the mount point
1914 * (or ``.'' if none is provided)
1915 * tp: Set to point to the actual name of the mount point to nuke.
1918 RemoveMountCmd(struct cmd_syndesc *as, void *arock)
1921 struct ViceIoctl blob;
1922 struct cmd_item *ti;
1924 char lsbuffer[1024];
1928 for (ti = as->parms[0].items; ti; ti = ti->next) {
1930 tp = (char *)strrchr(ti->data, '/');
1932 strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */
1934 tp++; /* skip the slash */
1936 strcpy(tbuffer, ".");
1940 blob.in_size = strlen(tp) + 1;
1941 blob.out = lsbuffer;
1942 blob.out_size = sizeof(lsbuffer);
1943 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 1);
1945 if (errno == EINVAL) {
1946 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
1949 Die(errno, ti->data);
1952 continue; /* don't bother trying */
1956 blob.in_size = strlen(tp) + 1;
1957 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 1);
1959 Die(errno, ti->data);
1970 CheckServersCmd(struct cmd_syndesc *as, void *arock)
1973 struct ViceIoctl blob;
1977 struct afsconf_cell info;
1978 struct chservinfo checkserv;
1980 memset(&checkserv, 0, sizeof(struct chservinfo));
1981 blob.in_size = sizeof(struct chservinfo);
1982 blob.in = (caddr_t) & checkserv;
1984 blob.out_size = AFS_PIOCTL_MAXSIZE;
1986 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1988 /* prepare flags for checkservers command */
1989 temp = 2; /* default to checking local cell only */
1990 if (as->parms[2].items)
1991 temp |= 1; /* set fast flag */
1992 if (as->parms[1].items)
1993 temp &= ~2; /* turn off local cell check */
1995 checkserv.magic = 0x12345678; /* XXX */
1996 checkserv.tflags = temp;
1998 /* now copy in optional cell name, if specified */
1999 if (as->parms[0].items) {
2000 code = GetCellName(as->parms[0].items->data, &info);
2004 strcpy(checkserv.tbuffer, info.name);
2005 checkserv.tsize = strlen(info.name) + 1;
2007 strcpy(checkserv.tbuffer, "\0");
2008 checkserv.tsize = 0;
2011 if (as->parms[3].items) {
2012 checkserv.tinterval = atol(as->parms[3].items->data);
2015 if (checkserv.tinterval < 0) {
2017 ("Warning: The negative -interval is ignored; treated as an inquiry\n");
2018 checkserv.tinterval = 0;
2019 } else if (checkserv.tinterval > 600) {
2021 ("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2022 checkserv.tinterval = 600; /* 10 min max interval */
2025 checkserv.tinterval = -1; /* don't change current interval */
2028 code = pioctl(0, VIOCCKSERV, &blob, 1);
2030 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2031 printf("Must be root to change -interval\n");
2037 memcpy(&temp, space, sizeof(afs_int32));
2038 if (checkserv.tinterval >= 0) {
2039 if (checkserv.tinterval > 0)
2041 ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2042 checkserv.tinterval, temp);
2044 printf("The current down server probe interval is %d secs\n",
2049 printf("All servers are running.\n");
2052 ("These servers unavailable due to network or server problems: ");
2054 memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32));
2057 tp = hostutil_GetNameByINet(temp);
2067 MessagesCmd(struct cmd_syndesc *as, void *arock)
2070 struct ViceIoctl blob;
2071 struct gaginfo gagflags;
2072 struct cmd_item *show;
2074 memset(&gagflags, 0, sizeof(struct gaginfo));
2075 blob.in_size = sizeof(struct gaginfo);
2076 blob.in = (caddr_t) & gagflags;
2077 blob.out_size = AFS_PIOCTL_MAXSIZE;
2079 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2081 if ((show = as->parms[0].items)) {
2082 if (!strcasecmp(show->data, "user"))
2083 gagflags.showflags |= GAGUSER;
2084 else if (!strcasecmp(show->data, "console"))
2085 gagflags.showflags |= GAGCONSOLE;
2086 else if (!strcasecmp(show->data, "all"))
2087 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2088 else if (!strcasecmp(show->data, "none"))
2092 "unrecognized flag %s: must be in {user,console,all,none}\n",
2101 code = pioctl(0, VIOC_GAG, &blob, 1);
2111 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2114 struct ViceIoctl blob;
2118 code = pioctl(0, VIOCCKBACK, &blob, 1);
2124 printf("All volumeID/name mappings checked.\n");
2129 PreCacheCmd(struct cmd_syndesc *as, void *arock)
2132 struct ViceIoctl blob;
2135 if (!as->parms[0].items && !as->parms[1].items) {
2136 fprintf(stderr, "%s: syntax error in precache cmd.\n", pn);
2139 if (as->parms[0].items) {
2140 code = util_GetInt32(as->parms[0].items->data, &temp);
2142 fprintf(stderr, "%s: bad integer specified for precache size.\n",
2148 blob.in = (char *)&temp;
2149 blob.in_size = sizeof(afs_int32);
2151 code = pioctl(0, VIOCPRECACHE, &blob, 1);
2157 printf("New precache size set.\n");
2162 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2165 struct ViceIoctl blob;
2168 if (!as->parms[0].items && !as->parms[1].items) {
2169 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
2172 if (as->parms[0].items) {
2173 code = util_GetHumanInt32(as->parms[0].items->data, &temp);
2175 fprintf(stderr, "%s: bad integer specified for cache size.\n",
2181 blob.in = (char *)&temp;
2182 blob.in_size = sizeof(afs_int32);
2184 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2186 if (errno == EROFS) {
2188 ("'fs setcache' not allowed on memory cache based cache managers.\n");
2195 printf("New cache size set.\n");
2199 #define MAXGCSIZE 16
2201 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2203 afs_int32 code, filesUsed;
2204 struct ViceIoctl blob;
2205 afs_int32 parms[MAXGCSIZE];
2206 double percentFiles, percentBlocks;
2207 afs_int32 flags = 0;
2209 if (as->parms[0].items){ /* -files */
2211 } else if (as->parms[1].items){ /* -excessive */
2217 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
2219 blob.in = (char *)&flags;
2220 blob.in_size = sizeof(afs_int32);
2221 } else { /* be backward compatible */
2225 blob.out_size = sizeof(parms);
2226 blob.out = (char *)parms;
2227 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2234 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2235 parms[1], parms[0]);
2236 if (parms[1] > parms[0])
2237 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2241 percentBlocks = ((double)parms[1]/parms[0]) * 100;
2242 printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n",
2243 percentBlocks, parms[1], parms[0]);
2248 filesUsed = parms[2] - parms[3];
2249 percentFiles = ((double)filesUsed/parms[2]) * 100;
2250 printf(" %5.0f%% of the cache files (%d of %d files)\n",
2251 percentFiles, filesUsed, parms[2]);
2253 printf(" afs_cacheFiles: %10d\n", parms[2]);
2254 printf(" IFFree: %10d\n", parms[3]);
2255 printf(" IFEverUsed: %10d\n", parms[4]);
2256 printf(" IFDataMod: %10d\n", parms[5]);
2257 printf(" IFDirtyPages: %10d\n", parms[6]);
2258 printf(" IFAnyPages: %10d\n", parms[7]);
2259 printf(" IFDiscarded: %10d\n", parms[8]);
2260 printf(" DCentries: %10d\n", parms[9]);
2261 printf(" 0k- 4K: %10d\n", parms[10]);
2262 printf(" 4k- 16k: %10d\n", parms[11]);
2263 printf(" 16k- 64k: %10d\n", parms[12]);
2264 printf(" 64k- 256k: %10d\n", parms[13]);
2265 printf(" 256k- 1M: %10d\n", parms[14]);
2266 printf(" >=1M: %10d\n", parms[15]);
2269 if (percentBlocks > 90)
2270 printf("[cache size usage over 90%%, consider increasing cache size]\n");
2271 if (percentFiles > 90)
2272 printf("[cache file usage over 90%%, consider increasing '-files' argument to afsd]\n");
2278 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2283 struct ViceIoctl blob;
2286 resolve = !(as->parms[0].items); /* -numeric */
2290 memcpy(tp, &i, sizeof(afs_int32));
2291 blob.out_size = AFS_PIOCTL_MAXSIZE;
2292 blob.in_size = sizeof(afs_int32);
2295 code = pioctl(0, VIOCGETCELL, &blob, 1);
2298 break; /* done with the list */
2303 printf("Cell %s on hosts", tp + AFS_MAXCELLHOSTS * sizeof(afs_int32));
2304 for (j = 0; j < AFS_MAXCELLHOSTS; j++) {
2306 char *name, tbuffer[20];
2308 memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32));
2313 name = hostutil_GetNameByINet(addr);
2316 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2317 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2320 printf(" %s", name);
2328 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2331 char *tp, *aliasName, *realName;
2332 struct ViceIoctl blob;
2336 memcpy(tp, &i, sizeof(afs_int32));
2337 blob.out_size = AFS_PIOCTL_MAXSIZE;
2338 blob.in_size = sizeof(afs_int32);
2341 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2344 break; /* done with the list */
2350 tp += strlen(aliasName) + 1;
2352 printf("Alias %s for cell %s\n", aliasName, realName);
2358 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2361 struct ViceIoctl blob;
2362 struct cmd_item *ti;
2364 struct hostent *thp;
2367 ti = as->parms[0].items;
2370 thp = hostutil_GetHostByName(ti->data);
2372 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2375 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2377 hostAddr = 0; /* means don't set host */
2378 setp = 0; /* aren't setting host */
2381 /* now do operation */
2382 blob.in_size = sizeof(afs_int32);
2383 blob.out_size = sizeof(afs_int32);
2384 blob.in = (char *) &hostAddr;
2385 blob.out = (char *) &hostAddr;
2387 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2396 NukeNFSCredsCmd(struct cmd_syndesc *as, void *arock)
2399 struct ViceIoctl blob;
2400 struct cmd_item *ti;
2402 struct hostent *thp;
2404 ti = as->parms[0].items;
2405 thp = hostutil_GetHostByName(ti->data);
2407 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2410 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2412 /* now do operation */
2413 blob.in_size = sizeof(afs_int32);
2414 blob.out_size = sizeof(afs_int32);
2415 blob.in = (char *) &hostAddr;
2416 blob.out = (char *) &hostAddr;
2418 code = pioctl(0, VIOC_NFS_NUKE_CREDS, &blob, 1);
2427 NewCellCmd(struct cmd_syndesc *as, void *arock)
2429 afs_int32 code, linkedstate = 0, size = 0, *lp;
2430 struct ViceIoctl blob;
2431 struct cmd_item *ti;
2432 char *tp, *cellname = 0;
2433 struct hostent *thp;
2434 afs_int32 fsport = 0, vlport = 0;
2435 afs_int32 scount; /* Number of servers to pass in pioctl call */
2438 * With the NEWCELL pioctl call, 3.4 clients take an array of
2439 * AFS_MAXHOSTS (13) servers while 3.5 clients take an array of
2440 * AFS_MAXCELLHOSTS (8) servers. To determine which we are talking to,
2441 * do a GETCELL pioctl and pass it a magic number. If an array of
2442 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
2443 * If we get back EDOM, there are no cells in the kernel yet,
2444 * and we'll assume a 3.5 client.
2447 lp = (afs_int32 *) tp;
2448 *lp++ = 0; /* first cell entry */
2449 *lp = 0x12345678; /* magic */
2450 blob.out_size = AFS_PIOCTL_MAXSIZE;
2451 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
2454 code = pioctl(0, VIOCGETCELL, &blob, 1);
2455 if (code < 0 && errno != EDOM) {
2459 if (code < 1 && errno == EDOM) {
2460 scount = AFS_MAXHOSTS;
2463 cellname = tp + AFS_MAXCELLHOSTS * sizeof(afs_int32);
2464 scount = ((cellname[0] != '\0') ? AFS_MAXCELLHOSTS : AFS_MAXHOSTS);
2467 /* Now setup and do the NEWCELL pioctl call */
2468 memset(space, 0, (scount + 1) * sizeof(afs_int32));
2470 lp = (afs_int32 *) tp;
2472 tp += sizeof(afs_int32);
2473 for (ti = as->parms[1].items; ti; ti = ti->next) {
2474 thp = hostutil_GetHostByName(ti->data);
2477 "%s: Host %s not found in host table, skipping it.\n", pn,
2480 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2481 tp += sizeof(afs_int32);
2484 if (as->parms[2].items) {
2486 * Link the cell, for the purposes of volume location, to the specified
2489 cellname = as->parms[2].items->data;
2492 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2493 if (as->parms[3].items) {
2494 code = util_GetInt32(as->parms[3].items->data, &vlport);
2497 "%s: bad integer specified for the fileserver port.\n",
2502 if (as->parms[4].items) {
2503 code = util_GetInt32(as->parms[4].items->data, &fsport);
2506 "%s: bad integer specified for the vldb server port.\n",
2512 tp = (char *)(space + (scount + 1) * sizeof(afs_int32));
2513 lp = (afs_int32 *) tp;
2517 strcpy(space + ((scount + 4) * sizeof(afs_int32)),
2518 as->parms[0].items->data);
2519 size = ((scount + 4) * sizeof(afs_int32))
2520 + strlen(as->parms[0].items->data)
2521 + 1 /* for null */ ;
2522 tp = (char *)(space + size);
2524 strcpy(tp, cellname);
2525 size += strlen(cellname) + 1;
2527 blob.in_size = size;
2530 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2539 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2542 struct ViceIoctl blob;
2544 char *aliasName, *realName;
2546 /* Now setup and do the NEWCELL pioctl call */
2547 aliasName = as->parms[0].items->data;
2548 realName = as->parms[1].items->data;
2550 strcpy(tp, aliasName);
2551 tp += strlen(aliasName) + 1;
2552 strcpy(tp, realName);
2553 tp += strlen(realName) + 1;
2555 blob.in_size = tp - space;
2559 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2561 if (errno == EEXIST) {
2563 "%s: cell name `%s' in use by an existing cell.\n", pn,
2574 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2577 struct cmd_item *ti;
2579 char cell[MAXCELLCHARS];
2581 SetDotDefault(&as->parms[0].items);
2582 for (ti = as->parms[0].items; ti; ti = ti->next) {
2583 code = GetCell(ti->data, cell);
2585 if (errno == ENOENT)
2586 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
2588 Die(errno, ti->data);
2593 printf("File %s lives in cell '%s'\n", ti->data, cell);
2599 WSCellCmd(struct cmd_syndesc *as, void *arock)
2602 struct ViceIoctl blob;
2606 blob.out_size = AFS_PIOCTL_MAXSIZE;
2609 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2615 printf("This workstation belongs to cell '%s'\n", space);
2620 static PrimaryCellCmd(as)
2621 struct cmd_syndesc *as;
2623 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2629 MonitorCmd(struct cmd_syndesc *as, void *arock)
2632 struct ViceIoctl blob;
2633 struct cmd_item *ti;
2635 struct hostent *thp;
2639 ti = as->parms[0].items;
2643 if (!strcmp(ti->data, "off"))
2644 hostAddr = 0xffffffff;
2646 thp = hostutil_GetHostByName(ti->data);
2648 if (!strcmp(ti->data, "localhost")) {
2650 "localhost not in host table, assuming 127.0.0.1\n");
2651 hostAddr = htonl(0x7f000001);
2653 fprintf(stderr, "host %s not found in host table.\n",
2658 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2661 hostAddr = 0; /* means don't set host */
2662 setp = 0; /* aren't setting host */
2665 /* now do operation */
2666 blob.in_size = sizeof(afs_int32);
2667 blob.out_size = sizeof(afs_int32);
2668 blob.in = (char *)&hostAddr;
2669 blob.out = (char *)&hostAddr;
2670 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2676 printf("%s: new monitor host set.\n", pn);
2678 /* now decode old address */
2679 if (hostAddr == 0xffffffff) {
2680 printf("Cache monitoring is currently disabled.\n");
2682 tp = hostutil_GetNameByINet(hostAddr);
2683 printf("Using host %s for monitor services.\n", tp);
2690 SysNameCmd(struct cmd_syndesc *as, void *arock)
2693 struct ViceIoctl blob;
2694 struct cmd_item *ti;
2695 char *input = space;
2698 ti = as->parms[0].items;
2701 blob.out_size = AFS_PIOCTL_MAXSIZE;
2702 blob.in_size = sizeof(afs_int32);
2703 input += sizeof(afs_int32);
2704 for (; ti; ti = ti->next) {
2706 blob.in_size += strlen(ti->data) + 1;
2707 if (blob.in_size > AFS_PIOCTL_MAXSIZE) {
2708 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2709 setp > 1 ? "s" : "");
2712 strcpy(input, ti->data);
2713 input += strlen(ti->data);
2716 memcpy(space, &setp, sizeof(afs_int32));
2717 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2723 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2727 memcpy(&setp, input, sizeof(afs_int32));
2728 input += sizeof(afs_int32);
2730 fprintf(stderr, "No sysname name value was found\n");
2733 printf("Current sysname%s is", setp > 1 ? " list" : "");
2734 for (; setp > 0; --setp) {
2735 printf(" \'%s\'", input);
2736 input += strlen(input) + 1;
2742 static char *exported_types[] = { "null", "nfs", "" };
2744 ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2747 struct ViceIoctl blob;
2748 struct cmd_item *ti;
2749 int export = 0, type = 0, mode = 0, exp = 0, exportcall, pwsync =
2750 0, smounts = 0, clipags = 0, pagcb = 0;
2752 ti = as->parms[0].items;
2753 if (strcmp(ti->data, "nfs") == 0)
2754 type = 0x71; /* NFS */
2757 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n",
2761 ti = as->parms[1].items;
2763 if (strcmp(ti->data, "on") == 0)
2765 else if (strcmp(ti->data, "off") == 0)
2768 fprintf(stderr, "Illegal argument %s\n", ti->data);
2773 if ((ti = as->parms[2].items)) { /* -noconvert */
2774 if (strcmp(ti->data, "on") == 0)
2776 else if (strcmp(ti->data, "off") == 0)
2779 fprintf(stderr, "Illegal argument %s\n", ti->data);
2783 if ((ti = as->parms[3].items)) { /* -uidcheck */
2784 if (strcmp(ti->data, "on") == 0)
2786 else if (strcmp(ti->data, "off") == 0)
2789 fprintf(stderr, "Illegal argument %s\n", ti->data);
2793 if ((ti = as->parms[4].items)) { /* -submounts */
2794 if (strcmp(ti->data, "on") == 0)
2796 else if (strcmp(ti->data, "off") == 0)
2799 fprintf(stderr, "Illegal argument %s\n", ti->data);
2803 if ((ti = as->parms[5].items)) { /* -clipags */
2804 if (strcmp(ti->data, "on") == 0)
2806 else if (strcmp(ti->data, "off") == 0)
2809 fprintf(stderr, "Illegal argument %s\n", ti->data);
2813 if ((ti = as->parms[6].items)) { /* -pagcb */
2814 if (strcmp(ti->data, "on") == 0)
2816 else if (strcmp(ti->data, "off") == 0)
2819 fprintf(stderr, "Illegal argument %s\n", ti->data);
2824 (type << 24) | (pagcb << 10) | (clipags << 8) |
2825 (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2828 blob.in = (char *)&exportcall;
2829 blob.in_size = sizeof(afs_int32);
2830 blob.out = (char *)&exportcall;
2831 blob.out_size = sizeof(afs_int32);
2832 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2834 if (errno == ENODEV) {
2836 "Sorry, the %s-exporter type is currently not supported on this AFS client\n",
2837 exported_types[type]);
2844 if (exportcall & 1) {
2845 printf("'%s' translator is enabled with the following options:\n",
2846 exported_types[type]);
2847 printf("\tRunning in %s mode\n",
2848 (exportcall & 2 ? "strict unix" :
2849 "convert owner mode bits to world/other"));
2850 printf("\tRunning in %s mode\n",
2851 (exportcall & 4 ? "strict 'passwd sync'" :
2852 "no 'passwd sync'"));
2854 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
2855 "Only mounts to /afs allowed"));
2857 (exportcall & 16 ? "Client-assigned PAG's are used" :
2858 "Client-assigned PAG's are not used"));
2861 "Callbacks are made to get creds from new clients" :
2862 "Callbacks are not made to get creds from new clients"));
2864 printf("'%s' translator is disabled\n", exported_types[type]);
2871 GetCellCmd(struct cmd_syndesc *as, void *arock)
2874 struct ViceIoctl blob;
2875 struct afsconf_cell info;
2876 struct cmd_item *ti;
2883 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2884 for (ti = as->parms[0].items; ti; ti = ti->next) {
2886 blob.out_size = sizeof(args);
2887 blob.out = (caddr_t) & args;
2888 code = GetCellName(ti->data, &info);
2893 blob.in_size = 1 + strlen(info.name);
2894 blob.in = info.name;
2895 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2897 if (errno == ENOENT)
2898 fprintf(stderr, "%s: the cell named '%s' does not exist\n",
2901 Die(errno, info.name);
2905 printf("Cell %s status: ", info.name);
2911 printf("no setuid allowed");
2913 printf("setuid allowed");
2915 printf(", using old VLDB");
2922 SetCellCmd(struct cmd_syndesc *as, void *arock)
2925 struct ViceIoctl blob;
2926 struct afsconf_cell info;
2927 struct cmd_item *ti;
2935 /* Check arguments. */
2936 if (as->parms[1].items && as->parms[2].items) {
2937 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2941 /* figure stuff to set */
2945 if (!as->parms[1].items)
2946 args.stat |= 2; /* default to -nosuid */
2948 /* set stat for all listed cells */
2949 for (ti = as->parms[0].items; ti; ti = ti->next) {
2951 code = GetCellName(ti->data, &info);
2956 strcpy(args.cname, info.name);
2957 blob.in_size = sizeof(args);
2958 blob.in = (caddr_t) & args;
2960 blob.out = (caddr_t) 0;
2961 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2963 Die(errno, info.name); /* XXX added cell name to Die() call */
2971 GetCellName(char *cellName, struct afsconf_cell *info)
2973 struct afsconf_dir *tdir;
2976 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2979 "Could not process files in configuration directory (%s).\n",
2980 AFSDIR_CLIENT_ETC_DIRPATH);
2984 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2986 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2987 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
2996 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3000 code = ugen_ClientInit(noAuthFlag, (char *) AFSDIR_CLIENT_ETC_DIRPATH,
3001 info->name, 0, &uclient,
3002 NULL, pn, rxkad_clear,
3003 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3004 0, 0, USER_SERVICE_ID);
3009 static struct ViceIoctl gblob;
3010 static int debug = 0;
3012 * here follow some routines in suport of the setserverprefs and
3013 * getserverprefs commands. They are:
3014 * SetPrefCmd "top-level" routine
3015 * addServer adds a server to the list of servers to be poked into the
3016 * kernel. Will poke the list into the kernel if it threatens
3018 * pokeServers pokes the existing list of servers and ranks into the kernel
3019 * GetPrefCmd reads the Cache Manager's current list of server ranks
3023 * returns -1 if error message printed,
3025 * errno value if error and no error message printed
3032 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
3033 if (code && (errno == EINVAL)) {
3034 struct setspref *ssp;
3035 ssp = (struct setspref *)gblob.in;
3036 if (!(ssp->flags & DBservers)) {
3037 gblob.in = (void *)&(ssp->servers[0]);
3038 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3039 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
3040 return code ? errno : 0;
3043 "This cache manager does not support VL server preferences.\n");
3047 return code ? errno : 0;
3051 * returns -1 if error message printed,
3053 * errno value if error and no error message printed
3056 addServer(char *name, afs_int32 rank)
3059 struct setspref *ssp;
3061 struct hostent *thostent;
3066 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3068 #define MAXUSHORT ((unsigned short) ~0)
3072 thostent = hostutil_GetHostByName(name);
3074 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3078 ssp = (struct setspref *)(gblob.in);
3080 for (t = 0; thostent->h_addr_list[t]; t++) {
3081 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3082 code = pokeServers();
3085 ssp->num_servers = 0;
3088 sp = (struct spref *)(gblob.in + gblob.in_size);
3089 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3090 sizeof(afs_uint32));
3091 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3092 gblob.in_size += sizeof(struct spref);
3096 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3097 name, sp->rank, (long unsigned int) sp->server.s_addr);
3105 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3109 struct cmd_item *ti;
3112 struct setspref *ssp;
3113 int error = 0; /* -1 means error message printed,
3114 * >0 means errno value for unprinted message */
3116 ssp = (struct setspref *)space;
3118 ssp->num_servers = 0;
3119 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3122 gblob.out_size = AFS_PIOCTL_MAXSIZE;
3126 fprintf(stderr, "Permission denied: requires root access.\n");
3130 ti = as->parms[2].items; /* -file */
3133 fprintf(stderr, "opening file %s\n", ti->data);
3134 if (!(infd = fopen(ti->data, "r"))) {
3138 while (fscanf(infd, "%79s%ld", name, (long int *)&rank) != EOF) {
3139 code = addServer(name, (unsigned short)rank);
3146 ti = as->parms[3].items; /* -stdin */
3148 while (scanf("%79s%ld", name, (long int *)&rank) != EOF) {
3149 code = addServer(name, (unsigned short)rank);
3155 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3160 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3164 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3168 code = pokeServers();
3172 printf("now working on vlservers, code=%d\n", code);
3174 ssp = (struct setspref *)space;
3175 ssp->flags = DBservers;
3176 ssp->num_servers = 0;
3177 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3180 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3185 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3189 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3194 if (as->parms[1].items) {
3196 printf("now poking vlservers\n");
3197 code = pokeServers();
3205 return error ? 1 : 0;
3211 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3214 struct cmd_item *ti;
3215 char *name, tbuffer[20];
3220 struct ViceIoctl blob;
3221 struct sprefrequest *in;
3222 struct sprefinfo *out;
3225 ti = as->parms[0].items; /* -file */
3228 fprintf(stderr, "opening file %s\n", ti->data);
3229 if (!(outfd = freopen(ti->data, "w", stdout))) {
3235 ti = as->parms[1].items; /* -numeric */
3237 ti = as->parms[2].items; /* -vlservers */
3238 vlservers |= (ti ? DBservers : 0);
3239 /* ti = as->parms[3].items; -cell */
3241 in = (struct sprefrequest *)space;
3245 blob.in_size = sizeof(struct sprefrequest);
3246 blob.in = (char *)in;
3248 blob.out_size = AFS_PIOCTL_MAXSIZE;
3251 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3252 in->flags = vlservers;
3255 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3257 if ((errno != E2BIG) || (2 * blob.out_size > 0x7FFF)) {
3258 perror("getserverprefs pioctl");
3262 if (blob.out == space)
3263 blob.out = malloc(blob.out_size);
3265 blob.out = realloc(blob.out, blob.out_size);
3267 } while (code != 0);
3269 out = (struct sprefinfo *)blob.out;
3271 for (i = 0; i < out->num_servers; i++) {
3273 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3275 addr = ntohl(out->servers[i].server.s_addr);
3276 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3277 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3280 printf("%-50s %5u\n", name, out->servers[i].rank);
3283 in->offset = out->next_offset;
3284 } while (out->next_offset > 0);
3286 if (blob.out != space)
3293 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
3296 struct ViceIoctl blob;
3297 struct cmd_item *ti;
3298 struct sbstruct tsb, tsb2;
3304 tsb.sb_thisfile = -1;
3305 ti = as->parms[0].items; /* -kbytes */
3307 if (!as->parms[1].items) {
3308 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3312 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3313 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3314 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3320 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3321 ti = as->parms[2].items; /* -allfiles */
3323 allfiles = strtol(ti->data, &t, 10) * 1024;
3324 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3325 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3331 /* -verbose or -file only or no options */
3332 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3333 || (!as->parms[0].items && !as->parms[1].items
3334 && !as->parms[2].items))
3337 blob.in = (char *)&tsb;
3338 blob.in_size = sizeof(struct sbstruct);
3340 /* once per -file */
3341 for (ti = as->parms[1].items; ti; ti = ti->next) {
3342 /* Do this solely to see if the file is there */
3345 blob.out_size = AFS_PIOCTL_MAXSIZE;
3346 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3348 Die(errno, ti->data);
3353 memset(&tsb2, 0, sizeof(tsb2));
3354 blob.out = (char *)&tsb2;
3355 blob.out_size = sizeof(struct sbstruct);
3356 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
3358 Die(errno, ti->data);
3363 if (verbose && (blob.out_size == sizeof(tsb2))) {
3364 if (tsb2.sb_thisfile == -1) {
3365 fprintf(stdout, "Will store %s according to default.\n",
3369 "Will store up to %d kbytes of %s asynchronously.\n",
3370 (tsb2.sb_thisfile / 1024), ti->data);
3375 /* If no files - make at least one pioctl call, or
3376 * set the allfiles default if we need to.
3378 if (!as->parms[1].items || (allfiles != -1)) {
3379 tsb.sb_default = allfiles;
3380 memset(&tsb2, 0, sizeof(tsb2));
3381 blob.out = (char *)&tsb2;
3382 blob.out_size = sizeof(struct sbstruct);
3383 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
3385 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3390 /* Having no arguments also reports the default store asynchrony */
3391 if (!error && verbose && (blob.out_size == sizeof(tsb2))) {
3392 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3393 (tsb2.sb_default / 1024));
3401 SetCryptCmd(struct cmd_syndesc *as, void *arock)
3403 afs_int32 code = 0, flag;
3404 struct ViceIoctl blob;
3407 tp = as->parms[0].items->data;
3408 if (strcmp(tp, "on") == 0)
3410 else if (strcmp(tp, "off") == 0)
3413 fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3417 blob.in = (char *)&flag;
3418 blob.in_size = sizeof(flag);
3420 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3428 GetCryptCmd(struct cmd_syndesc *as, void *arock)
3430 afs_int32 code = 0, flag;
3431 struct ViceIoctl blob;
3436 blob.out_size = sizeof(flag);
3439 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3445 memcpy(&flag, tp, sizeof(afs_int32));
3446 printf("Security level is currently ");
3448 printf("crypt (data security).\n");
3455 static char *modenames[] = {
3458 "readonly", /* Not currently supported */
3459 "fetchonly", /* Not currently supported */
3460 "partial", /* Not currently supported */
3464 static char *policynames[] = {
3467 "closer", /* Not currently supported. */
3468 "manual", /* Not currently supported. */
3473 DisconCmd(struct cmd_syndesc *as, void *arock)
3475 struct cmd_item *ti;
3478 int modelen, policylen;
3479 afs_int32 mode, policy, code, unixuid = 0;
3480 struct ViceIoctl blob;
3485 space[0] = space[1] = space[2] = space[3] = 0;
3487 ti = as->parms[0].items;
3489 modename = ti->data;
3490 modelen = strlen(modename);
3491 for (mode = 0; modenames[mode] != NULL; mode++)
3492 if (!strncasecmp(modename, modenames[mode], modelen))
3494 if (modenames[mode] == NULL)
3495 printf("Unknown discon mode \"%s\"\n", modename);
3497 space[0] = mode + 1;
3500 ti = as->parms[1].items;
3502 policyname = ti->data;
3503 policylen = strlen(policyname);
3504 for (policy = 0; policynames[policy] != NULL; policy++)
3505 if (!strncasecmp(policyname, policynames[policy], policylen))
3507 if (policynames[policy] == NULL)
3508 printf("Unknown discon mode \"%s\"\n", policyname);
3510 space[1] = policy + 1;
3514 if (as->parms[2].items) {
3516 printf("force on\n");
3519 ti = as->parms[3].items;
3521 code = util_GetInt32(ti->data, &unixuid);
3523 fprintf(stderr, "%s: bad integer specified for uid.\n", pn);
3531 blob.in_size = 4 * sizeof(afs_int32);
3533 blob.out_size = sizeof(mode);
3535 code = pioctl(0, VIOC_DISCON, &blob, 1);
3539 memcpy(&mode, space, sizeof mode);
3540 if (mode < sizeof modenames / sizeof (char *))
3541 printf("Discon mode is now \"%s\"\n", modenames[mode]);
3543 printf("Unknown discon mode %d\n", mode);
3549 #include "AFS_component_version_number.c"
3552 main(int argc, char **argv)
3555 struct cmd_syndesc *ts;
3557 #ifdef AFS_AIX32_ENV
3559 * The following signal action for AIX is necessary so that in case of a
3560 * crash (i.e. core is generated) we can include the user's data section
3561 * in the core dump. Unfortunately, by default, only a partial core is
3562 * generated which, in many cases, isn't too useful.
3564 struct sigaction nsa;
3566 sigemptyset(&nsa.sa_mask);
3567 nsa.sa_handler = SIG_DFL;
3568 nsa.sa_flags = SA_FULLDUMP;
3569 sigaction(SIGSEGV, &nsa, NULL);
3572 /* try to find volume location information */
3573 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
3574 "get client network interface addresses");
3575 cmd_CreateAlias(ts, "gc");
3577 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
3578 "set client network interface addresses");
3579 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3580 "client network interfaces");
3581 cmd_CreateAlias(ts, "sc");
3583 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL,
3584 "set server ranks");
3585 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3586 "fileserver names and ranks");
3587 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3588 "VL server names and ranks");
3589 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3590 "input from named file");
3591 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3592 cmd_CreateAlias(ts, "sp");
3594 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL,
3595 "get server ranks");
3596 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3597 "output to named file");
3598 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3599 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3600 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3601 cmd_CreateAlias(ts, "gp");
3603 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
3604 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3605 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3606 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3607 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL,
3608 "apply to negative rights");
3609 parm_setacl_id = ts->nParms;
3610 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL,
3611 "initial directory acl (DFS only)");
3612 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL,
3613 "initial file acl (DFS only)");
3614 cmd_CreateAlias(ts, "sa");
3616 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL,
3617 "list access control list");
3618 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3619 parm_listacl_id = ts->nParms;
3620 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3621 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3622 cmd_AddParm(ts, "-cmd", CMD_FLAG, CMD_OPTIONAL, "output as 'fs setacl' command");
3623 cmd_CreateAlias(ts, "la");
3625 ts = cmd_CreateSyntax("getcalleraccess", GetCallerAccess, NULL,
3626 "list callers access");
3627 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3628 cmd_CreateAlias(ts, "gca");
3630 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL,
3631 "clean up access control list");
3632 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3634 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL,
3635 "copy access control list");
3636 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0,
3637 "source directory (or DFS file)");
3638 cmd_AddParm(ts, "-todir", CMD_LIST, 0,
3639 "destination directory (or DFS file)");
3640 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3641 "first clear dest access list");
3642 parm_copyacl_id = ts->nParms;
3643 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3644 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3646 cmd_CreateAlias(ts, "ca");
3648 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
3649 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3650 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
3651 "flush mount symlink from cache");
3652 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3654 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
3655 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3656 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL,
3657 "disk space quota in 1K units");
3659 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL,
3660 "disk space guaranteed");
3661 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3663 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL,
3665 cmd_CreateAlias(ts, "sv");
3667 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL,
3668 "control Cache Manager messages");
3669 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL,
3670 "[user|console|all|none]");
3672 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
3673 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3674 cmd_CreateAlias(ts, "lv");
3675 cmd_CreateAlias(ts, "listvol");
3677 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
3678 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3679 cmd_AddParm(ts, "-human", CMD_FLAG, CMD_OPTIONAL, "human-readable listing");
3680 cmd_CreateAlias(ts, "lq");
3682 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL,
3683 "show server disk space usage");
3684 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3685 cmd_AddParm(ts, "-human", CMD_FLAG, CMD_OPTIONAL, "human-readable listing");
3686 cmd_CreateAlias(ts, "df");
3688 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
3689 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3691 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
3692 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3694 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
3695 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3696 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3697 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3698 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3699 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3700 "don't check name with VLDB");
3702 #if defined(AFS_CACHE_BYPASS)
3703 ts = cmd_CreateSyntax("bypassthreshold", BypassThresholdCmd, 0,
3704 "get/set cache bypass file size threshold");
3705 cmd_AddParm(ts, "-size", CMD_SINGLE, CMD_OPTIONAL, "file size");
3712 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3716 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
3717 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3719 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL,
3720 "check local cell's servers");
3721 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3722 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3723 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3724 "just list, don't check");
3725 cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL,
3726 "seconds between probes");
3728 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL,
3729 "check volumeID/name mappings");
3730 cmd_CreateAlias(ts, "checkbackups");
3733 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL,
3735 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3736 "size in 1K byte blocks (0 => reset)");
3737 cmd_CreateAlias(ts, "cachesize");
3739 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL,
3740 "reset size back to boot value");
3742 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL,
3743 "get cache usage info");
3744 cmd_AddParm(ts, "-files", CMD_FLAG, CMD_OPTIONAL, "Show cach files used as well");
3745 cmd_AddParm(ts, "-excessive", CMD_FLAG, CMD_OPTIONAL, "excessively verbose cache stats");
3747 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL,
3748 "list configured cells");
3749 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3751 ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, NULL,
3752 "list configured cell aliases");
3754 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
3755 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3756 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3758 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3760 cmd_CreateAlias(ts, "sq");
3762 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
3763 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3764 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3765 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL,
3766 "linked cell name");
3768 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
3769 "configure new cell alias");
3770 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
3771 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
3773 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3775 * Turn this on only if you wish to be able to talk to a server which is listening
3776 * on alternative ports. This is not intended for general use and may not be
3777 * supported in the cache manager. It is not a way to run two servers at the
3778 * same host, since the cache manager cannot properly distinguish those two hosts.
3780 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL,
3781 "cell's fileserver port");
3782 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL,
3783 "cell's vldb server port");
3786 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
3787 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3789 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
3790 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3792 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
3795 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, NULL, "obsolete (listed primary cell)");
3798 /* set cache monitor host address */
3799 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, (char *)CMD_HIDDEN);
3800 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL,
3801 "host name or 'off'");
3802 cmd_CreateAlias(ts, "mariner");
3804 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
3805 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3807 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
3808 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3809 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3810 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL,
3811 "disallow setuid programs");
3813 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL,
3814 "flush all data in volume");
3815 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3817 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL,
3818 "get/set sysname (i.e. @sys) value");
3819 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3821 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL,
3822 "enable/disable translators to AFS");
3823 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3824 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL,
3825 "start/stop translator (on | off)");
3826 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL,
3827 "convert from afs to unix mode (on | off)");
3828 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL,
3829 "run on strict 'uid check' mode (on | off)");
3830 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
3831 "allow nfs mounts to subdirs of /afs/.. (on | off)");
3832 cmd_AddParm(ts, "-clipags", CMD_SINGLE, CMD_OPTIONAL,
3833 "enable use of client-assigned PAG's (on | off)");
3834 cmd_AddParm(ts, "-pagcb", CMD_SINGLE, CMD_OPTIONAL,
3835 "enable callbacks to get creds from new clients (on | off)");
3838 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
3839 "store to server after file close");
3840 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL,
3841 "asynchrony for specified names");
3842 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3843 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL,
3844 "new default (KB)");
3845 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3846 cmd_CreateAlias(ts, "sb");
3848 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL,
3849 "set cache manager encryption flag");
3850 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3852 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL,
3853 "get cache manager encryption flag");
3855 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
3856 "Manage per process RX statistics");
3857 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3858 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3859 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3861 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
3862 "Manage per peer RX statistics");
3863 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3864 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3865 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3867 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
3868 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
3870 /* try to find volume location information */
3871 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL,
3872 "get fid for file(s)");
3873 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3875 ts = cmd_CreateSyntax("discon", DisconCmd, NULL,
3876 "disconnection mode");
3877 cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_REQUIRED, "offline | online");
3878 cmd_AddParm(ts, "-policy", CMD_SINGLE, CMD_OPTIONAL, "client | server");
3879 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Force reconnection, despite any synchronization issues.");
3880 cmd_AddParm(ts, "-uid", CMD_SINGLE, CMD_OPTIONAL, "Numeric UID of user whose tokens to use at reconnect.");
3882 ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, NULL, "nuke credentials for NFS client");
3883 cmd_AddParm(ts, "-addr", CMD_SINGLE, 0, "host name or address");
3885 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
3886 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_REQUIRED, "generate a new UUID");
3888 ts = cmd_CreateSyntax("precache", PreCacheCmd, 0,
3889 "set precache size");
3890 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3891 "size in 1K byte blocks (0 => disable)");
3893 code = cmd_Dispatch(argc, argv);
3901 Die(int errnum, char *filename)
3907 "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3910 fprintf(stderr, "%s: Invalid argument.\n", pn);
3914 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3916 fprintf(stderr, "%s: no such file returned\n", pn);
3920 "%s: You can not change a backup or readonly volume\n", pn);
3926 "%s: You don't have the required access rights on '%s'\n",
3930 "%s: You do not have the required rights to do this operation\n",
3935 fprintf(stderr, "%s:'%s'", pn, filename);
3937 fprintf(stderr, "%s", pn);
3938 fprintf(stderr, ": %s\n", afs_error_message(errnum));
3943 /* get clients interface addresses */
3945 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3948 struct ViceIoctl blob;
3949 struct sprefrequest *in;
3950 struct sprefinfo *out;
3952 in = (struct sprefrequest *)space;
3956 blob.in_size = sizeof(struct sprefrequest);
3957 blob.in = (char *)in;
3959 blob.out_size = AFS_PIOCTL_MAXSIZE;
3962 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3963 /* returns addr in network byte order */
3964 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3966 perror("getClientInterfaceAddr pioctl");
3972 out = (struct sprefinfo *)blob.out;
3973 for (i = 0; i < out->num_servers; i++) {
3976 addr = ntohl(out->servers[i].server.s_addr);
3977 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3978 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3979 printf("%-50s\n", tbuffer);
3981 in->offset = out->next_offset;
3983 } while (out->next_offset > 0);
3989 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3991 afs_int32 code, addr;
3992 struct cmd_item *ti;
3993 struct ViceIoctl blob;
3994 struct setspref *ssp;
3995 int sizeUsed = 0, i, flag;
3996 afs_uint32 existingAddr[1024]; /* existing addresses on this host */
4000 ssp = (struct setspref *)space;
4001 ssp->num_servers = 0;
4004 blob.out_size = AFS_PIOCTL_MAXSIZE;
4007 fprintf(stderr, "Permission denied: requires root access.\n");
4011 /* extract all existing interface addresses */
4012 existNu = rx_getAllAddr(existingAddr, 1024);
4016 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
4017 for (ti = as->parms[0].items; ti; ti = ti->next) {
4018 if (sizeUsed >= sizeof(space)) {
4019 fprintf(stderr, "No more space\n");
4022 addr = extractAddr(ti->data, 20); /* network order */
4023 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
4024 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
4029 /* see if it is an address that really exists */
4030 for (flag = 0, i = 0; i < existNu; i++)
4031 if (existingAddr[i] == addr) {
4035 if (!flag) { /* this is an nonexistent address */
4036 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
4040 /* copy all specified addr into ioctl buffer */
4041 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
4042 printf("Adding 0x%08x\n", addr);
4044 sizeUsed += sizeof(struct spref);
4046 if (ssp->num_servers < 1) {
4047 fprintf(stderr, "No addresses specified\n");
4050 blob.in_size = sizeUsed - sizeof(struct spref);
4052 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
4062 FlushMountCmd(struct cmd_syndesc *as, void *arock)
4065 struct ViceIoctl blob;
4066 struct cmd_item *ti;
4067 char orig_name[1024]; /*Original name, may be modified */
4068 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
4069 char parent_dir[1024]; /*Parent directory of true name */
4070 char *last_component; /*Last component of true name */
4071 struct stat statbuff; /*Buffer for status info */
4072 int link_chars_read; /*Num chars read in readlink() */
4073 int thru_symlink; /*Did we get to a mount point via a symlink? */
4076 for (ti = as->parms[0].items; ti; ti = ti->next) {
4079 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
4082 if (lstat(orig_name, &statbuff) < 0) {
4083 /* if lstat fails, we should still try the pioctl, since it
4084 * may work (for example, lstat will fail, but pioctl will
4085 * work if the volume of offline (returning ENODEV). */
4086 statbuff.st_mode = S_IFDIR; /* lie like pros */
4090 * The lstat succeeded. If the given file is a symlink, substitute
4091 * the file name with the link name.
4093 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
4096 * Read name of resolved file.
4098 link_chars_read = readlink(orig_name, true_name, 1024);
4099 if (link_chars_read <= 0) {
4101 "%s: Can't read target name for '%s' symbolic link!\n",
4108 * Add a trailing null to what was read, bump the length.
4110 true_name[link_chars_read++] = 0;
4113 * If the symlink is an absolute pathname, we're fine. Otherwise, we
4114 * have to create a full pathname using the original name and the
4115 * relative symlink name. Find the rightmost slash in the original
4116 * name (we know there is one) and splice in the symlink value.
4118 if (true_name[0] != '/') {
4119 last_component = (char *)strrchr(orig_name, '/');
4120 strcpy(++last_component, true_name);
4121 strcpy(true_name, orig_name);
4124 strcpy(true_name, orig_name);
4127 * Find rightmost slash, if any.
4129 last_component = (char *)strrchr(true_name, '/');
4130 if (last_component == (char *)true_name) {
4131 strcpy(parent_dir, "/");
4134 else if (last_component != (char *)NULL) {
4136 * Found it. Designate everything before it as the parent directory,
4137 * everything after it as the final component.
4139 strncpy(parent_dir, true_name, last_component - true_name);
4140 parent_dir[last_component - true_name] = 0;
4141 last_component++; /*Skip the slash */
4144 * No slash appears in the given file name. Set parent_dir to the current
4145 * directory, and the last component as the given name.
4147 strcpy(parent_dir, ".");
4148 last_component = true_name;
4151 if (strcmp(last_component, ".") == 0
4152 || strcmp(last_component, "..") == 0) {
4154 "%s: you may not use '.' or '..' as the last component\n",
4156 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
4162 blob.in = last_component;
4163 blob.in_size = strlen(last_component) + 1;
4165 memset(space, 0, AFS_PIOCTL_MAXSIZE);
4167 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4170 if (errno == EINVAL) {
4171 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4173 Die(errno, (ti->data ? ti->data : parent_dir));
4182 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4185 afs_int32 flags = 0;
4186 struct ViceIoctl blob;
4188 if (as->parms[0].items) { /* -enable */
4189 flags |= AFSCALL_RXSTATS_ENABLE;
4191 if (as->parms[1].items) { /* -disable */
4192 flags |= AFSCALL_RXSTATS_DISABLE;
4194 if (as->parms[2].items) { /* -clear */
4195 flags |= AFSCALL_RXSTATS_CLEAR;
4198 fprintf(stderr, "You must specify at least one argument\n");
4202 blob.in = (char *)&flags;
4203 blob.in_size = sizeof(afs_int32);
4206 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4216 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4219 afs_int32 flags = 0;
4220 struct ViceIoctl blob;
4222 if (as->parms[0].items) { /* -enable */
4223 flags |= AFSCALL_RXSTATS_ENABLE;
4225 if (as->parms[1].items) { /* -disable */
4226 flags |= AFSCALL_RXSTATS_DISABLE;
4228 if (as->parms[2].items) { /* -clear */
4229 flags |= AFSCALL_RXSTATS_CLEAR;
4232 fprintf(stderr, "You must specify at least one argument\n");
4236 blob.in = (char *)&flags;
4237 blob.in_size = sizeof(afs_int32);
4240 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4250 GetFidCmd(struct cmd_syndesc *as, void *arock)
4252 struct ViceIoctl blob;
4253 struct cmd_item *ti;
4254 for (ti = as->parms[0].items; ti; ti = ti->next) {
4255 struct VenusFid vfid;
4257 blob.out_size = sizeof(struct VenusFid);
4258 blob.out = (char *) &vfid;
4261 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
4262 printf("File %s (%u.%u.%u) contained in volume %u\n",
4263 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,