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 if (!strcmp(tp,"-1")) {
1366 for(ix = 0; ix < len; ++ix) {
1367 if(!isdigit(tp[0])) {
1373 fprintf(stderr, "fs bypassthreshold -size: %s must be an integer between -1 and 2^31\n", tp);
1376 threshold_i = atoi(tp);
1377 if(ix > 9 && threshold_i < 2147483647)
1378 threshold_i = 2147483647;
1380 blob.in = (char *) &threshold_i;
1381 blob.in_size = sizeof(threshold_i);
1387 blob.out = (char *) &threshold_o;
1388 blob.out_size = sizeof(threshold_o);
1389 code = pioctl(0, VIOC_SETBYPASS_THRESH, &blob, 1);
1394 printf("Cache bypass threshold %d", threshold_o);
1395 if(threshold_o == -1)
1396 printf(" (disabled)");
1406 FlushCmd(struct cmd_syndesc *as, void *arock)
1409 struct ViceIoctl blob;
1410 struct cmd_item *ti;
1413 for (ti = as->parms[0].items; ti; ti = ti->next) {
1414 blob.in_size = blob.out_size = 0;
1415 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1417 if (errno == EMFILE) {
1418 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1421 fprintf(stderr, "%s: Error flushing file ", pn);
1431 /* all this command does is repackage its args and call SetVolCmd */
1433 SetQuotaCmd(struct cmd_syndesc *as, void *arock)
1435 struct cmd_syndesc ts;
1437 /* copy useful stuff from our command slot; we may later have to reorder */
1438 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1439 return SetVolCmd(&ts, arock);
1443 SetVolCmd(struct cmd_syndesc *as, void *arock)
1446 struct ViceIoctl blob;
1447 struct cmd_item *ti;
1448 struct VolumeStatus *status;
1449 char *offmsg, *input;
1452 SetDotDefault(&as->parms[0].items);
1453 for (ti = as->parms[0].items; ti; ti = ti->next) {
1455 blob.out_size = AFS_PIOCTL_MAXSIZE;
1456 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1459 status = (VolumeStatus *) space;
1460 status->MinQuota = status->MaxQuota = -1;
1462 if (as->parms[1].items) {
1463 code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota);
1465 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1470 if (as->parms[2].items)
1471 offmsg = as->parms[2].items->data;
1472 input = (char *)status + sizeof(*status);
1473 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1475 if (strlen(offmsg) >= VMSGSIZE) {
1477 "%s: message must be shorter than %d characters\n",
1482 strcpy(input, offmsg);
1483 blob.in_size += strlen(offmsg);
1484 input += strlen(offmsg) + 1;
1487 *(input++) = '\0'; /* Pad for old style volume "motd" */
1488 code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1);
1490 Die(errno, ti->data);
1498 * Why is VenusFid declared in the kernel-only section of afs.h,
1499 * if it's the exported interface of the cache manager?
1507 ExamineCmd(struct cmd_syndesc *as, void *arock)
1510 struct ViceIoctl blob;
1511 struct cmd_item *ti;
1512 struct VolumeStatus *status;
1513 char *name, *offmsg;
1516 SetDotDefault(&as->parms[0].items);
1517 for (ti = as->parms[0].items; ti; ti = ti->next) {
1518 struct VenusFid vfid;
1521 blob.out_size = AFS_PIOCTL_MAXSIZE;
1524 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1526 Die(errno, ti->data);
1530 status = (VolumeStatus *) space;
1531 name = (char *)status + sizeof(*status);
1532 offmsg = name + strlen(name) + 1;
1534 blob.out_size = sizeof(struct VenusFid);
1535 blob.out = (char *) &vfid;
1536 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1537 printf("File %s (%u.%u.%u) contained in volume %u\n",
1538 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1542 PrintStatus(status, name, offmsg);
1548 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1551 struct ViceIoctl blob;
1552 struct cmd_item *ti;
1553 struct VolumeStatus *status;
1558 if (as->parms[1].items)
1561 printf("%-25s%-11s%-11s%-7s%-11s\n", "Volume Name", " Quota",
1562 " Used", " %Used", " Partition");
1563 SetDotDefault(&as->parms[0].items);
1564 for (ti = as->parms[0].items; ti; ti = ti->next) {
1566 blob.out_size = AFS_PIOCTL_MAXSIZE;
1569 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1571 Die(errno, ti->data);
1575 status = (VolumeStatus *) space;
1576 name = (char *)status + sizeof(*status);
1577 QuickPrintStatus(status, name, human);
1583 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1586 struct ViceIoctl blob;
1587 struct cmd_item *ti;
1593 SetDotDefault(&as->parms[0].items);
1594 for (ti = as->parms[0].items; ti; ti = ti->next) {
1596 blob.out_size = AFS_PIOCTL_MAXSIZE;
1599 memset(space, 0, sizeof(space));
1600 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1602 Die(errno, ti->data);
1606 hosts = (afs_int32 *) space;
1607 printf("File %s is on host%s ", ti->data,
1608 (hosts[0] && !hosts[1]) ? "" : "s");
1609 for (j = 0; j < AFS_MAXHOSTS; j++) {
1612 tp = hostutil_GetNameByINet(hosts[j]);
1622 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1625 struct ViceIoctl blob;
1626 struct cmd_item *ti;
1628 struct VolumeStatus *status;
1632 if (as->parms[1].items)
1635 printf("%-25s%10s%10s%10s%6s\n", "Volume Name",
1636 human ? "total" : "kbytes", "used", "avail", "%used");
1637 SetDotDefault(&as->parms[0].items);
1638 for (ti = as->parms[0].items; ti; ti = ti->next) {
1640 blob.out_size = AFS_PIOCTL_MAXSIZE;
1643 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1645 Die(errno, ti->data);
1649 status = (VolumeStatus *) space;
1650 name = (char *)status + sizeof(*status);
1651 QuickPrintSpace(status, name, human);
1657 QuotaCmd(struct cmd_syndesc *as, void *arock)
1660 struct ViceIoctl blob;
1661 struct cmd_item *ti;
1663 struct VolumeStatus *status;
1666 SetDotDefault(&as->parms[0].items);
1667 for (ti = as->parms[0].items; ti; ti = ti->next) {
1669 blob.out_size = AFS_PIOCTL_MAXSIZE;
1672 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1674 Die(errno, ti->data);
1678 status = (VolumeStatus *) space;
1679 if (status->MaxQuota)
1681 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
1684 printf("%2.0f%% of quota used.\n", quotaPct);
1690 ListMountCmd(struct cmd_syndesc *as, void *arock)
1693 struct ViceIoctl blob;
1694 struct cmd_item *ti;
1695 char orig_name[1024]; /*Original name, may be modified */
1696 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
1697 char parent_dir[1024]; /*Parent directory of true name */
1698 char *last_component; /*Last component of true name */
1699 struct stat statbuff; /*Buffer for status info */
1700 int link_chars_read; /*Num chars read in readlink() */
1701 int thru_symlink; /*Did we get to a mount point via a symlink? */
1704 for (ti = as->parms[0].items; ti; ti = ti->next) {
1707 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
1710 if (lstat(orig_name, &statbuff) < 0) {
1711 /* if lstat fails, we should still try the pioctl, since it
1712 * may work (for example, lstat will fail, but pioctl will
1713 * work if the volume of offline (returning ENODEV). */
1714 statbuff.st_mode = S_IFDIR; /* lie like pros */
1718 * The lstat succeeded. If the given file is a symlink, substitute
1719 * the file name with the link name.
1721 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1724 * Read name of resolved file.
1726 link_chars_read = readlink(orig_name, true_name, 1024);
1727 if (link_chars_read <= 0) {
1729 "%s: Can't read target name for '%s' symbolic link!\n",
1736 * Add a trailing null to what was read, bump the length.
1738 true_name[link_chars_read++] = 0;
1741 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1742 * have to create a full pathname using the original name and the
1743 * relative symlink name. Find the rightmost slash in the original
1744 * name (we know there is one) and splice in the symlink value.
1746 if (true_name[0] != '/') {
1747 last_component = (char *)strrchr(orig_name, '/');
1748 strcpy(++last_component, true_name);
1749 strcpy(true_name, orig_name);
1752 strcpy(true_name, orig_name);
1755 * Find rightmost slash, if any.
1757 last_component = (char *)strrchr(true_name, '/');
1758 if (last_component == (char *)true_name) {
1759 strcpy(parent_dir, "/");
1762 else if (last_component != (char *)NULL) {
1764 * Found it. Designate everything before it as the parent directory,
1765 * everything after it as the final component.
1767 strncpy(parent_dir, true_name, last_component - true_name);
1768 parent_dir[last_component - true_name] = 0;
1769 last_component++; /*Skip the slash */
1772 * No slash appears in the given file name. Set parent_dir to the current
1773 * directory, and the last component as the given name.
1775 strcpy(parent_dir, ".");
1776 last_component = true_name;
1779 if (strcmp(last_component, ".") == 0
1780 || strcmp(last_component, "..") == 0) {
1782 "%s: you may not use '.' or '..' as the last component\n",
1784 fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n",
1790 blob.in = last_component;
1791 blob.in_size = strlen(last_component) + 1;
1792 blob.out_size = AFS_PIOCTL_MAXSIZE;
1794 memset(space, 0, AFS_PIOCTL_MAXSIZE);
1796 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1799 printf("'%s' is a %smount point for volume '%s'\n", ti->data,
1800 (thru_symlink ? "symbolic link, leading to a " : ""),
1803 if (errno == EINVAL) {
1804 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
1806 Die(errno, (ti->data ? ti->data : parent_dir));
1815 MakeMountCmd(struct cmd_syndesc *as, void *arock)
1818 char *cellName, *volName, *tmpName;
1819 struct afsconf_cell info;
1820 struct vldbentry vldbEntry;
1821 struct ViceIoctl blob;
1827 if (as->parms[5].items && !as->parms[2].items) {
1828 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1833 if (as->parms[2].items) /* cell name specified */
1834 cellName = as->parms[2].items->data;
1837 volName = as->parms[1].items->data;
1839 if (strlen(volName) >= 64) {
1841 "%s: volume name too long (length must be < 64 characters)\n",
1846 /* Check for a cellname in the volume specification, and complain
1847 * if it doesn't match what was specified with -cell */
1848 if ((tmpName = strchr(volName, ':'))) {
1851 if (strcasecmp(cellName, volName)) {
1852 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1857 volName = ++tmpName;
1860 if (!InAFS(Parent(as->parms[0].items->data))) {
1862 "%s: mount points must be created within the AFS file system\n",
1869 blob.out_size = AFS_PIOCTL_MAXSIZE;
1872 pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME,
1876 code = GetCellName(cellName ? cellName : space, &info);
1880 if (!(as->parms[4].items)) {
1881 /* not fast, check which cell the mountpoint is being created in */
1882 /* not fast, check name with VLDB */
1883 code = VLDBInit(1, &info);
1885 /* make the check. Don't complain if there are problems with init */
1887 ubik_VL_GetEntryByNameO(uclient, 0, volName,
1889 if (code == VL_NOENT) {
1891 "%s: warning, volume %s does not exist in cell %s.\n",
1892 pn, volName, cellName ? cellName : space);
1897 if (as->parms[3].items) /* if -rw specified */
1902 /* cellular mount point, prepend cell prefix */
1903 strcat(space, info.name);
1906 strcat(space, volName); /* append volume name */
1907 strcat(space, "."); /* stupid convention; these end with a period */
1908 code = symlink(space, as->parms[0].items->data);
1910 Die(errno, as->parms[0].items->data);
1917 * Delete AFS mount points. Variables are used as follows:
1918 * tbuffer: Set to point to the null-terminated directory name of the mount point
1919 * (or ``.'' if none is provided)
1920 * tp: Set to point to the actual name of the mount point to nuke.
1923 RemoveMountCmd(struct cmd_syndesc *as, void *arock)
1926 struct ViceIoctl blob;
1927 struct cmd_item *ti;
1929 char lsbuffer[1024];
1933 for (ti = as->parms[0].items; ti; ti = ti->next) {
1935 tp = (char *)strrchr(ti->data, '/');
1937 strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */
1939 tp++; /* skip the slash */
1941 strcpy(tbuffer, ".");
1945 blob.in_size = strlen(tp) + 1;
1946 blob.out = lsbuffer;
1947 blob.out_size = sizeof(lsbuffer);
1948 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 1);
1950 if (errno == EINVAL) {
1951 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
1954 Die(errno, ti->data);
1957 continue; /* don't bother trying */
1961 blob.in_size = strlen(tp) + 1;
1962 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 1);
1964 Die(errno, ti->data);
1975 CheckServersCmd(struct cmd_syndesc *as, void *arock)
1978 struct ViceIoctl blob;
1982 struct afsconf_cell info;
1983 struct chservinfo checkserv;
1985 memset(&checkserv, 0, sizeof(struct chservinfo));
1986 blob.in_size = sizeof(struct chservinfo);
1987 blob.in = (caddr_t) & checkserv;
1989 blob.out_size = AFS_PIOCTL_MAXSIZE;
1991 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1993 /* prepare flags for checkservers command */
1994 temp = 2; /* default to checking local cell only */
1995 if (as->parms[2].items)
1996 temp |= 1; /* set fast flag */
1997 if (as->parms[1].items)
1998 temp &= ~2; /* turn off local cell check */
2000 checkserv.magic = 0x12345678; /* XXX */
2001 checkserv.tflags = temp;
2003 /* now copy in optional cell name, if specified */
2004 if (as->parms[0].items) {
2005 code = GetCellName(as->parms[0].items->data, &info);
2009 strcpy(checkserv.tbuffer, info.name);
2010 checkserv.tsize = strlen(info.name) + 1;
2012 strcpy(checkserv.tbuffer, "\0");
2013 checkserv.tsize = 0;
2016 if (as->parms[3].items) {
2017 checkserv.tinterval = atol(as->parms[3].items->data);
2020 if (checkserv.tinterval < 0) {
2022 ("Warning: The negative -interval is ignored; treated as an inquiry\n");
2023 checkserv.tinterval = 0;
2024 } else if (checkserv.tinterval > 600) {
2026 ("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2027 checkserv.tinterval = 600; /* 10 min max interval */
2030 checkserv.tinterval = -1; /* don't change current interval */
2033 code = pioctl(0, VIOCCKSERV, &blob, 1);
2035 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2036 printf("Must be root to change -interval\n");
2042 memcpy(&temp, space, sizeof(afs_int32));
2043 if (checkserv.tinterval >= 0) {
2044 if (checkserv.tinterval > 0)
2046 ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2047 checkserv.tinterval, temp);
2049 printf("The current down server probe interval is %d secs\n",
2054 printf("All servers are running.\n");
2057 ("These servers unavailable due to network or server problems: ");
2059 memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32));
2062 tp = hostutil_GetNameByINet(temp);
2072 MessagesCmd(struct cmd_syndesc *as, void *arock)
2075 struct ViceIoctl blob;
2076 struct gaginfo gagflags;
2077 struct cmd_item *show;
2079 memset(&gagflags, 0, sizeof(struct gaginfo));
2080 blob.in_size = sizeof(struct gaginfo);
2081 blob.in = (caddr_t) & gagflags;
2082 blob.out_size = AFS_PIOCTL_MAXSIZE;
2084 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2086 if ((show = as->parms[0].items)) {
2087 if (!strcasecmp(show->data, "user"))
2088 gagflags.showflags |= GAGUSER;
2089 else if (!strcasecmp(show->data, "console"))
2090 gagflags.showflags |= GAGCONSOLE;
2091 else if (!strcasecmp(show->data, "all"))
2092 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2093 else if (!strcasecmp(show->data, "none"))
2097 "unrecognized flag %s: must be in {user,console,all,none}\n",
2106 code = pioctl(0, VIOC_GAG, &blob, 1);
2116 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2119 struct ViceIoctl blob;
2123 code = pioctl(0, VIOCCKBACK, &blob, 1);
2129 printf("All volumeID/name mappings checked.\n");
2134 PreCacheCmd(struct cmd_syndesc *as, void *arock)
2137 struct ViceIoctl blob;
2140 if (!as->parms[0].items && !as->parms[1].items) {
2141 fprintf(stderr, "%s: syntax error in precache cmd.\n", pn);
2144 if (as->parms[0].items) {
2145 code = util_GetInt32(as->parms[0].items->data, &temp);
2147 fprintf(stderr, "%s: bad integer specified for precache size.\n",
2153 blob.in = (char *)&temp;
2154 blob.in_size = sizeof(afs_int32);
2156 code = pioctl(0, VIOCPRECACHE, &blob, 1);
2162 printf("New precache size set.\n");
2167 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2170 struct ViceIoctl blob;
2173 if (!as->parms[0].items && !as->parms[1].items) {
2174 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
2177 if (as->parms[0].items) {
2178 code = util_GetHumanInt32(as->parms[0].items->data, &temp);
2180 fprintf(stderr, "%s: bad integer specified for cache size.\n",
2186 blob.in = (char *)&temp;
2187 blob.in_size = sizeof(afs_int32);
2189 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2191 if (errno == EROFS) {
2193 ("'fs setcache' not allowed on memory cache based cache managers.\n");
2200 printf("New cache size set.\n");
2204 #define MAXGCSIZE 16
2206 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2208 afs_int32 code, filesUsed;
2209 struct ViceIoctl blob;
2210 afs_int32 parms[MAXGCSIZE];
2211 double percentFiles, percentBlocks;
2212 afs_int32 flags = 0;
2214 if (as->parms[0].items){ /* -files */
2216 } else if (as->parms[1].items){ /* -excessive */
2222 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
2224 blob.in = (char *)&flags;
2225 blob.in_size = sizeof(afs_int32);
2226 } else { /* be backward compatible */
2230 blob.out_size = sizeof(parms);
2231 blob.out = (char *)parms;
2232 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2239 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2240 parms[1], parms[0]);
2241 if (parms[1] > parms[0])
2242 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2246 percentBlocks = ((double)parms[1]/parms[0]) * 100;
2247 printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n",
2248 percentBlocks, parms[1], parms[0]);
2253 filesUsed = parms[2] - parms[3];
2254 percentFiles = ((double)filesUsed/parms[2]) * 100;
2255 printf(" %5.0f%% of the cache files (%d of %d files)\n",
2256 percentFiles, filesUsed, parms[2]);
2258 printf(" afs_cacheFiles: %10d\n", parms[2]);
2259 printf(" IFFree: %10d\n", parms[3]);
2260 printf(" IFEverUsed: %10d\n", parms[4]);
2261 printf(" IFDataMod: %10d\n", parms[5]);
2262 printf(" IFDirtyPages: %10d\n", parms[6]);
2263 printf(" IFAnyPages: %10d\n", parms[7]);
2264 printf(" IFDiscarded: %10d\n", parms[8]);
2265 printf(" DCentries: %10d\n", parms[9]);
2266 printf(" 0k- 4K: %10d\n", parms[10]);
2267 printf(" 4k- 16k: %10d\n", parms[11]);
2268 printf(" 16k- 64k: %10d\n", parms[12]);
2269 printf(" 64k- 256k: %10d\n", parms[13]);
2270 printf(" 256k- 1M: %10d\n", parms[14]);
2271 printf(" >=1M: %10d\n", parms[15]);
2274 if (percentBlocks > 90)
2275 printf("[cache size usage over 90%%, consider increasing cache size]\n");
2276 if (percentFiles > 90)
2277 printf("[cache file usage over 90%%, consider increasing '-files' argument to afsd]\n");
2283 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2288 struct ViceIoctl blob;
2291 resolve = !(as->parms[0].items); /* -numeric */
2295 memcpy(tp, &i, sizeof(afs_int32));
2296 blob.out_size = AFS_PIOCTL_MAXSIZE;
2297 blob.in_size = sizeof(afs_int32);
2300 code = pioctl(0, VIOCGETCELL, &blob, 1);
2303 break; /* done with the list */
2308 printf("Cell %s on hosts", tp + AFS_MAXCELLHOSTS * sizeof(afs_int32));
2309 for (j = 0; j < AFS_MAXCELLHOSTS; j++) {
2311 char *name, tbuffer[20];
2313 memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32));
2318 name = hostutil_GetNameByINet(addr);
2321 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2322 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2325 printf(" %s", name);
2333 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2336 char *tp, *aliasName, *realName;
2337 struct ViceIoctl blob;
2341 memcpy(tp, &i, sizeof(afs_int32));
2342 blob.out_size = AFS_PIOCTL_MAXSIZE;
2343 blob.in_size = sizeof(afs_int32);
2346 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2349 break; /* done with the list */
2355 tp += strlen(aliasName) + 1;
2357 printf("Alias %s for cell %s\n", aliasName, realName);
2363 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2366 struct ViceIoctl blob;
2367 struct cmd_item *ti;
2369 struct hostent *thp;
2372 ti = as->parms[0].items;
2375 thp = hostutil_GetHostByName(ti->data);
2377 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2380 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2382 hostAddr = 0; /* means don't set host */
2383 setp = 0; /* aren't setting host */
2386 /* now do operation */
2387 blob.in_size = sizeof(afs_int32);
2388 blob.out_size = sizeof(afs_int32);
2389 blob.in = (char *) &hostAddr;
2390 blob.out = (char *) &hostAddr;
2392 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2401 NukeNFSCredsCmd(struct cmd_syndesc *as, void *arock)
2404 struct ViceIoctl blob;
2405 struct cmd_item *ti;
2407 struct hostent *thp;
2409 ti = as->parms[0].items;
2410 thp = hostutil_GetHostByName(ti->data);
2412 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2415 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2417 /* now do operation */
2418 blob.in_size = sizeof(afs_int32);
2419 blob.out_size = sizeof(afs_int32);
2420 blob.in = (char *) &hostAddr;
2421 blob.out = (char *) &hostAddr;
2423 code = pioctl(0, VIOC_NFS_NUKE_CREDS, &blob, 1);
2432 NewCellCmd(struct cmd_syndesc *as, void *arock)
2434 afs_int32 code, linkedstate = 0, size = 0, *lp;
2435 struct ViceIoctl blob;
2436 struct cmd_item *ti;
2437 char *tp, *cellname = 0;
2438 struct hostent *thp;
2439 afs_int32 fsport = 0, vlport = 0;
2440 afs_int32 scount; /* Number of servers to pass in pioctl call */
2443 * With the NEWCELL pioctl call, 3.4 clients take an array of
2444 * AFS_MAXHOSTS (13) servers while 3.5 clients take an array of
2445 * AFS_MAXCELLHOSTS (8) servers. To determine which we are talking to,
2446 * do a GETCELL pioctl and pass it a magic number. If an array of
2447 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
2448 * If we get back EDOM, there are no cells in the kernel yet,
2449 * and we'll assume a 3.5 client.
2452 lp = (afs_int32 *) tp;
2453 *lp++ = 0; /* first cell entry */
2454 *lp = 0x12345678; /* magic */
2455 blob.out_size = AFS_PIOCTL_MAXSIZE;
2456 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
2459 code = pioctl(0, VIOCGETCELL, &blob, 1);
2460 if (code < 0 && errno != EDOM) {
2464 if (code < 1 && errno == EDOM) {
2465 scount = AFS_MAXHOSTS;
2468 cellname = tp + AFS_MAXCELLHOSTS * sizeof(afs_int32);
2469 scount = ((cellname[0] != '\0') ? AFS_MAXCELLHOSTS : AFS_MAXHOSTS);
2472 /* Now setup and do the NEWCELL pioctl call */
2473 memset(space, 0, (scount + 1) * sizeof(afs_int32));
2475 lp = (afs_int32 *) tp;
2477 tp += sizeof(afs_int32);
2478 for (ti = as->parms[1].items; ti; ti = ti->next) {
2479 thp = hostutil_GetHostByName(ti->data);
2482 "%s: Host %s not found in host table, skipping it.\n", pn,
2485 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2486 tp += sizeof(afs_int32);
2489 if (as->parms[2].items) {
2491 * Link the cell, for the purposes of volume location, to the specified
2494 cellname = as->parms[2].items->data;
2497 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2498 if (as->parms[3].items) {
2499 code = util_GetInt32(as->parms[3].items->data, &vlport);
2502 "%s: bad integer specified for the fileserver port.\n",
2507 if (as->parms[4].items) {
2508 code = util_GetInt32(as->parms[4].items->data, &fsport);
2511 "%s: bad integer specified for the vldb server port.\n",
2517 tp = (char *)(space + (scount + 1) * sizeof(afs_int32));
2518 lp = (afs_int32 *) tp;
2522 strcpy(space + ((scount + 4) * sizeof(afs_int32)),
2523 as->parms[0].items->data);
2524 size = ((scount + 4) * sizeof(afs_int32))
2525 + strlen(as->parms[0].items->data)
2526 + 1 /* for null */ ;
2527 tp = (char *)(space + size);
2529 strcpy(tp, cellname);
2530 size += strlen(cellname) + 1;
2532 blob.in_size = size;
2535 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2544 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2547 struct ViceIoctl blob;
2549 char *aliasName, *realName;
2551 /* Now setup and do the NEWCELL pioctl call */
2552 aliasName = as->parms[0].items->data;
2553 realName = as->parms[1].items->data;
2555 strcpy(tp, aliasName);
2556 tp += strlen(aliasName) + 1;
2557 strcpy(tp, realName);
2558 tp += strlen(realName) + 1;
2560 blob.in_size = tp - space;
2564 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2566 if (errno == EEXIST) {
2568 "%s: cell name `%s' in use by an existing cell.\n", pn,
2579 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2582 struct cmd_item *ti;
2584 char cell[MAXCELLCHARS];
2586 SetDotDefault(&as->parms[0].items);
2587 for (ti = as->parms[0].items; ti; ti = ti->next) {
2588 code = GetCell(ti->data, cell);
2590 if (errno == ENOENT)
2591 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
2593 Die(errno, ti->data);
2598 printf("File %s lives in cell '%s'\n", ti->data, cell);
2604 WSCellCmd(struct cmd_syndesc *as, void *arock)
2607 struct ViceIoctl blob;
2611 blob.out_size = AFS_PIOCTL_MAXSIZE;
2614 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2620 printf("This workstation belongs to cell '%s'\n", space);
2625 static PrimaryCellCmd(as)
2626 struct cmd_syndesc *as;
2628 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2634 MonitorCmd(struct cmd_syndesc *as, void *arock)
2637 struct ViceIoctl blob;
2638 struct cmd_item *ti;
2640 struct hostent *thp;
2644 ti = as->parms[0].items;
2648 if (!strcmp(ti->data, "off"))
2649 hostAddr = 0xffffffff;
2651 thp = hostutil_GetHostByName(ti->data);
2653 if (!strcmp(ti->data, "localhost")) {
2655 "localhost not in host table, assuming 127.0.0.1\n");
2656 hostAddr = htonl(0x7f000001);
2658 fprintf(stderr, "host %s not found in host table.\n",
2663 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2666 hostAddr = 0; /* means don't set host */
2667 setp = 0; /* aren't setting host */
2670 /* now do operation */
2671 blob.in_size = sizeof(afs_int32);
2672 blob.out_size = sizeof(afs_int32);
2673 blob.in = (char *)&hostAddr;
2674 blob.out = (char *)&hostAddr;
2675 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2681 printf("%s: new monitor host set.\n", pn);
2683 /* now decode old address */
2684 if (hostAddr == 0xffffffff) {
2685 printf("Cache monitoring is currently disabled.\n");
2687 tp = hostutil_GetNameByINet(hostAddr);
2688 printf("Using host %s for monitor services.\n", tp);
2695 SysNameCmd(struct cmd_syndesc *as, void *arock)
2698 struct ViceIoctl blob;
2699 struct cmd_item *ti;
2700 char *input = space;
2703 ti = as->parms[0].items;
2706 blob.out_size = AFS_PIOCTL_MAXSIZE;
2707 blob.in_size = sizeof(afs_int32);
2708 input += sizeof(afs_int32);
2709 for (; ti; ti = ti->next) {
2711 blob.in_size += strlen(ti->data) + 1;
2712 if (blob.in_size > AFS_PIOCTL_MAXSIZE) {
2713 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2714 setp > 1 ? "s" : "");
2717 strcpy(input, ti->data);
2718 input += strlen(ti->data);
2721 memcpy(space, &setp, sizeof(afs_int32));
2722 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2728 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2732 memcpy(&setp, input, sizeof(afs_int32));
2733 input += sizeof(afs_int32);
2735 fprintf(stderr, "No sysname name value was found\n");
2738 printf("Current sysname%s is", setp > 1 ? " list" : "");
2739 for (; setp > 0; --setp) {
2740 printf(" \'%s\'", input);
2741 input += strlen(input) + 1;
2747 static char *exported_types[] = { "null", "nfs", "" };
2749 ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2752 struct ViceIoctl blob;
2753 struct cmd_item *ti;
2754 int export = 0, type = 0, mode = 0, exp = 0, exportcall, pwsync =
2755 0, smounts = 0, clipags = 0, pagcb = 0;
2757 ti = as->parms[0].items;
2758 if (strcmp(ti->data, "nfs") == 0)
2759 type = 0x71; /* NFS */
2762 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n",
2766 ti = as->parms[1].items;
2768 if (strcmp(ti->data, "on") == 0)
2770 else if (strcmp(ti->data, "off") == 0)
2773 fprintf(stderr, "Illegal argument %s\n", ti->data);
2778 if ((ti = as->parms[2].items)) { /* -noconvert */
2779 if (strcmp(ti->data, "on") == 0)
2781 else if (strcmp(ti->data, "off") == 0)
2784 fprintf(stderr, "Illegal argument %s\n", ti->data);
2788 if ((ti = as->parms[3].items)) { /* -uidcheck */
2789 if (strcmp(ti->data, "on") == 0)
2791 else if (strcmp(ti->data, "off") == 0)
2794 fprintf(stderr, "Illegal argument %s\n", ti->data);
2798 if ((ti = as->parms[4].items)) { /* -submounts */
2799 if (strcmp(ti->data, "on") == 0)
2801 else if (strcmp(ti->data, "off") == 0)
2804 fprintf(stderr, "Illegal argument %s\n", ti->data);
2808 if ((ti = as->parms[5].items)) { /* -clipags */
2809 if (strcmp(ti->data, "on") == 0)
2811 else if (strcmp(ti->data, "off") == 0)
2814 fprintf(stderr, "Illegal argument %s\n", ti->data);
2818 if ((ti = as->parms[6].items)) { /* -pagcb */
2819 if (strcmp(ti->data, "on") == 0)
2821 else if (strcmp(ti->data, "off") == 0)
2824 fprintf(stderr, "Illegal argument %s\n", ti->data);
2829 (type << 24) | (pagcb << 10) | (clipags << 8) |
2830 (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2833 blob.in = (char *)&exportcall;
2834 blob.in_size = sizeof(afs_int32);
2835 blob.out = (char *)&exportcall;
2836 blob.out_size = sizeof(afs_int32);
2837 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2839 if (errno == ENODEV) {
2841 "Sorry, the %s-exporter type is currently not supported on this AFS client\n",
2842 exported_types[type]);
2849 if (exportcall & 1) {
2850 printf("'%s' translator is enabled with the following options:\n",
2851 exported_types[type]);
2852 printf("\tRunning in %s mode\n",
2853 (exportcall & 2 ? "strict unix" :
2854 "convert owner mode bits to world/other"));
2855 printf("\tRunning in %s mode\n",
2856 (exportcall & 4 ? "strict 'passwd sync'" :
2857 "no 'passwd sync'"));
2859 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
2860 "Only mounts to /afs allowed"));
2862 (exportcall & 16 ? "Client-assigned PAG's are used" :
2863 "Client-assigned PAG's are not used"));
2866 "Callbacks are made to get creds from new clients" :
2867 "Callbacks are not made to get creds from new clients"));
2869 printf("'%s' translator is disabled\n", exported_types[type]);
2876 GetCellCmd(struct cmd_syndesc *as, void *arock)
2879 struct ViceIoctl blob;
2880 struct afsconf_cell info;
2881 struct cmd_item *ti;
2888 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2889 for (ti = as->parms[0].items; ti; ti = ti->next) {
2891 blob.out_size = sizeof(args);
2892 blob.out = (caddr_t) & args;
2893 code = GetCellName(ti->data, &info);
2898 blob.in_size = 1 + strlen(info.name);
2899 blob.in = info.name;
2900 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2902 if (errno == ENOENT)
2903 fprintf(stderr, "%s: the cell named '%s' does not exist\n",
2906 Die(errno, info.name);
2910 printf("Cell %s status: ", info.name);
2916 printf("no setuid allowed");
2918 printf("setuid allowed");
2920 printf(", using old VLDB");
2927 SetCellCmd(struct cmd_syndesc *as, void *arock)
2930 struct ViceIoctl blob;
2931 struct afsconf_cell info;
2932 struct cmd_item *ti;
2940 /* Check arguments. */
2941 if (as->parms[1].items && as->parms[2].items) {
2942 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2946 /* figure stuff to set */
2950 if (!as->parms[1].items)
2951 args.stat |= 2; /* default to -nosuid */
2953 /* set stat for all listed cells */
2954 for (ti = as->parms[0].items; ti; ti = ti->next) {
2956 code = GetCellName(ti->data, &info);
2961 strcpy(args.cname, info.name);
2962 blob.in_size = sizeof(args);
2963 blob.in = (caddr_t) & args;
2965 blob.out = (caddr_t) 0;
2966 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2968 Die(errno, info.name); /* XXX added cell name to Die() call */
2976 GetCellName(char *cellName, struct afsconf_cell *info)
2978 struct afsconf_dir *tdir;
2981 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2984 "Could not process files in configuration directory (%s).\n",
2985 AFSDIR_CLIENT_ETC_DIRPATH);
2989 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2991 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2992 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
3001 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3005 code = ugen_ClientInit(noAuthFlag, (char *) AFSDIR_CLIENT_ETC_DIRPATH,
3006 info->name, 0, &uclient,
3007 NULL, pn, rxkad_clear,
3008 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3009 0, 0, USER_SERVICE_ID);
3014 static struct ViceIoctl gblob;
3015 static int debug = 0;
3017 * here follow some routines in suport of the setserverprefs and
3018 * getserverprefs commands. They are:
3019 * SetPrefCmd "top-level" routine
3020 * addServer adds a server to the list of servers to be poked into the
3021 * kernel. Will poke the list into the kernel if it threatens
3023 * pokeServers pokes the existing list of servers and ranks into the kernel
3024 * GetPrefCmd reads the Cache Manager's current list of server ranks
3028 * returns -1 if error message printed,
3030 * errno value if error and no error message printed
3037 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
3038 if (code && (errno == EINVAL)) {
3039 struct setspref *ssp;
3040 ssp = (struct setspref *)gblob.in;
3041 if (!(ssp->flags & DBservers)) {
3042 gblob.in = (void *)&(ssp->servers[0]);
3043 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3044 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
3045 return code ? errno : 0;
3048 "This cache manager does not support VL server preferences.\n");
3052 return code ? errno : 0;
3056 * returns -1 if error message printed,
3058 * errno value if error and no error message printed
3061 addServer(char *name, afs_int32 rank)
3064 struct setspref *ssp;
3066 struct hostent *thostent;
3071 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3073 #define MAXUSHORT ((unsigned short) ~0)
3077 thostent = hostutil_GetHostByName(name);
3079 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3083 ssp = (struct setspref *)(gblob.in);
3085 for (t = 0; thostent->h_addr_list[t]; t++) {
3086 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3087 code = pokeServers();
3090 ssp->num_servers = 0;
3093 sp = (struct spref *)(gblob.in + gblob.in_size);
3094 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3095 sizeof(afs_uint32));
3096 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3097 gblob.in_size += sizeof(struct spref);
3101 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3102 name, sp->rank, (long unsigned int) sp->server.s_addr);
3110 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3114 struct cmd_item *ti;
3117 struct setspref *ssp;
3118 int error = 0; /* -1 means error message printed,
3119 * >0 means errno value for unprinted message */
3121 ssp = (struct setspref *)space;
3123 ssp->num_servers = 0;
3124 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3127 gblob.out_size = AFS_PIOCTL_MAXSIZE;
3131 fprintf(stderr, "Permission denied: requires root access.\n");
3135 ti = as->parms[2].items; /* -file */
3138 fprintf(stderr, "opening file %s\n", ti->data);
3139 if (!(infd = fopen(ti->data, "r"))) {
3143 while (fscanf(infd, "%79s%ld", name, (long int *)&rank) != EOF) {
3144 code = addServer(name, (unsigned short)rank);
3151 ti = as->parms[3].items; /* -stdin */
3153 while (scanf("%79s%ld", name, (long int *)&rank) != EOF) {
3154 code = addServer(name, (unsigned short)rank);
3160 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3165 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3169 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3173 code = pokeServers();
3177 printf("now working on vlservers, code=%d\n", code);
3179 ssp = (struct setspref *)space;
3180 ssp->flags = DBservers;
3181 ssp->num_servers = 0;
3182 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3185 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3190 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3194 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3199 if (as->parms[1].items) {
3201 printf("now poking vlservers\n");
3202 code = pokeServers();
3210 return error ? 1 : 0;
3216 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3219 struct cmd_item *ti;
3220 char *name, tbuffer[20];
3225 struct ViceIoctl blob;
3226 struct sprefrequest *in;
3227 struct sprefinfo *out;
3230 ti = as->parms[0].items; /* -file */
3233 fprintf(stderr, "opening file %s\n", ti->data);
3234 if (!(outfd = freopen(ti->data, "w", stdout))) {
3240 ti = as->parms[1].items; /* -numeric */
3242 ti = as->parms[2].items; /* -vlservers */
3243 vlservers |= (ti ? DBservers : 0);
3244 /* ti = as->parms[3].items; -cell */
3246 in = (struct sprefrequest *)space;
3250 blob.in_size = sizeof(struct sprefrequest);
3251 blob.in = (char *)in;
3253 blob.out_size = AFS_PIOCTL_MAXSIZE;
3256 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3257 in->flags = vlservers;
3260 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3262 if ((errno != E2BIG) || (2 * blob.out_size > 0x7FFF)) {
3263 perror("getserverprefs pioctl");
3267 if (blob.out == space)
3268 blob.out = malloc(blob.out_size);
3270 blob.out = realloc(blob.out, blob.out_size);
3272 } while (code != 0);
3274 out = (struct sprefinfo *)blob.out;
3276 for (i = 0; i < out->num_servers; i++) {
3278 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3280 addr = ntohl(out->servers[i].server.s_addr);
3281 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3282 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3285 printf("%-50s %5u\n", name, out->servers[i].rank);
3288 in->offset = out->next_offset;
3289 } while (out->next_offset > 0);
3291 if (blob.out != space)
3298 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
3301 struct ViceIoctl blob;
3302 struct cmd_item *ti;
3303 struct sbstruct tsb, tsb2;
3309 tsb.sb_thisfile = -1;
3310 ti = as->parms[0].items; /* -kbytes */
3312 if (!as->parms[1].items) {
3313 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3317 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3318 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3319 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3325 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3326 ti = as->parms[2].items; /* -allfiles */
3328 allfiles = strtol(ti->data, &t, 10) * 1024;
3329 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3330 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3336 /* -verbose or -file only or no options */
3337 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3338 || (!as->parms[0].items && !as->parms[1].items
3339 && !as->parms[2].items))
3342 blob.in = (char *)&tsb;
3343 blob.in_size = sizeof(struct sbstruct);
3345 /* once per -file */
3346 for (ti = as->parms[1].items; ti; ti = ti->next) {
3347 /* Do this solely to see if the file is there */
3350 blob.out_size = AFS_PIOCTL_MAXSIZE;
3351 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3353 Die(errno, ti->data);
3358 memset(&tsb2, 0, sizeof(tsb2));
3359 blob.out = (char *)&tsb2;
3360 blob.out_size = sizeof(struct sbstruct);
3361 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
3363 Die(errno, ti->data);
3368 if (verbose && (blob.out_size == sizeof(tsb2))) {
3369 if (tsb2.sb_thisfile == -1) {
3370 fprintf(stdout, "Will store %s according to default.\n",
3374 "Will store up to %d kbytes of %s asynchronously.\n",
3375 (tsb2.sb_thisfile / 1024), ti->data);
3380 /* If no files - make at least one pioctl call, or
3381 * set the allfiles default if we need to.
3383 if (!as->parms[1].items || (allfiles != -1)) {
3384 tsb.sb_default = allfiles;
3385 memset(&tsb2, 0, sizeof(tsb2));
3386 blob.out = (char *)&tsb2;
3387 blob.out_size = sizeof(struct sbstruct);
3388 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
3390 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3395 /* Having no arguments also reports the default store asynchrony */
3396 if (!error && verbose && (blob.out_size == sizeof(tsb2))) {
3397 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3398 (tsb2.sb_default / 1024));
3406 SetCryptCmd(struct cmd_syndesc *as, void *arock)
3408 afs_int32 code = 0, flag;
3409 struct ViceIoctl blob;
3412 tp = as->parms[0].items->data;
3413 if (strcmp(tp, "on") == 0)
3415 else if (strcmp(tp, "off") == 0)
3418 fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3422 blob.in = (char *)&flag;
3423 blob.in_size = sizeof(flag);
3425 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3433 GetCryptCmd(struct cmd_syndesc *as, void *arock)
3435 afs_int32 code = 0, flag;
3436 struct ViceIoctl blob;
3441 blob.out_size = sizeof(flag);
3444 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3450 memcpy(&flag, tp, sizeof(afs_int32));
3451 printf("Security level is currently ");
3453 printf("crypt (data security).\n");
3460 static char *modenames[] = {
3463 "readonly", /* Not currently supported */
3464 "fetchonly", /* Not currently supported */
3465 "partial", /* Not currently supported */
3469 static char *policynames[] = {
3472 "closer", /* Not currently supported. */
3473 "manual", /* Not currently supported. */
3478 DisconCmd(struct cmd_syndesc *as, void *arock)
3480 struct cmd_item *ti;
3483 int modelen, policylen;
3484 afs_int32 mode, policy, code, unixuid = 0;
3485 struct ViceIoctl blob;
3490 space[0] = space[1] = space[2] = space[3] = 0;
3492 ti = as->parms[0].items;
3494 modename = ti->data;
3495 modelen = strlen(modename);
3496 for (mode = 0; modenames[mode] != NULL; mode++)
3497 if (!strncasecmp(modename, modenames[mode], modelen))
3499 if (modenames[mode] == NULL)
3500 printf("Unknown discon mode \"%s\"\n", modename);
3502 space[0] = mode + 1;
3505 ti = as->parms[1].items;
3507 policyname = ti->data;
3508 policylen = strlen(policyname);
3509 for (policy = 0; policynames[policy] != NULL; policy++)
3510 if (!strncasecmp(policyname, policynames[policy], policylen))
3512 if (policynames[policy] == NULL)
3513 printf("Unknown discon mode \"%s\"\n", policyname);
3515 space[1] = policy + 1;
3519 if (as->parms[2].items) {
3521 printf("force on\n");
3524 ti = as->parms[3].items;
3526 code = util_GetInt32(ti->data, &unixuid);
3528 fprintf(stderr, "%s: bad integer specified for uid.\n", pn);
3536 blob.in_size = 4 * sizeof(afs_int32);
3538 blob.out_size = sizeof(mode);
3540 code = pioctl(0, VIOC_DISCON, &blob, 1);
3544 memcpy(&mode, space, sizeof mode);
3545 if (mode < sizeof modenames / sizeof (char *))
3546 printf("Discon mode is now \"%s\"\n", modenames[mode]);
3548 printf("Unknown discon mode %d\n", mode);
3554 #include "AFS_component_version_number.c"
3557 main(int argc, char **argv)
3560 struct cmd_syndesc *ts;
3562 #ifdef AFS_AIX32_ENV
3564 * The following signal action for AIX is necessary so that in case of a
3565 * crash (i.e. core is generated) we can include the user's data section
3566 * in the core dump. Unfortunately, by default, only a partial core is
3567 * generated which, in many cases, isn't too useful.
3569 struct sigaction nsa;
3571 sigemptyset(&nsa.sa_mask);
3572 nsa.sa_handler = SIG_DFL;
3573 nsa.sa_flags = SA_FULLDUMP;
3574 sigaction(SIGSEGV, &nsa, NULL);
3577 /* try to find volume location information */
3578 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
3579 "get client network interface addresses");
3580 cmd_CreateAlias(ts, "gc");
3582 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
3583 "set client network interface addresses");
3584 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3585 "client network interfaces");
3586 cmd_CreateAlias(ts, "sc");
3588 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL,
3589 "set server ranks");
3590 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3591 "fileserver names and ranks");
3592 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3593 "VL server names and ranks");
3594 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3595 "input from named file");
3596 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3597 cmd_CreateAlias(ts, "sp");
3599 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL,
3600 "get server ranks");
3601 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3602 "output to named file");
3603 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3604 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3605 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3606 cmd_CreateAlias(ts, "gp");
3608 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
3609 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3610 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3611 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3612 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL,
3613 "apply to negative rights");
3614 parm_setacl_id = ts->nParms;
3615 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL,
3616 "initial directory acl (DFS only)");
3617 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL,
3618 "initial file acl (DFS only)");
3619 cmd_CreateAlias(ts, "sa");
3621 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL,
3622 "list access control list");
3623 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3624 parm_listacl_id = ts->nParms;
3625 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3626 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3627 cmd_AddParm(ts, "-cmd", CMD_FLAG, CMD_OPTIONAL, "output as 'fs setacl' command");
3628 cmd_CreateAlias(ts, "la");
3630 ts = cmd_CreateSyntax("getcalleraccess", GetCallerAccess, NULL,
3631 "list callers access");
3632 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3633 cmd_CreateAlias(ts, "gca");
3635 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL,
3636 "clean up access control list");
3637 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3639 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL,
3640 "copy access control list");
3641 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0,
3642 "source directory (or DFS file)");
3643 cmd_AddParm(ts, "-todir", CMD_LIST, 0,
3644 "destination directory (or DFS file)");
3645 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3646 "first clear dest access list");
3647 parm_copyacl_id = ts->nParms;
3648 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3649 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3651 cmd_CreateAlias(ts, "ca");
3653 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
3654 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3655 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
3656 "flush mount symlink from cache");
3657 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3659 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
3660 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3661 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL,
3662 "disk space quota in 1K units");
3664 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL,
3665 "disk space guaranteed");
3666 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3668 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL,
3670 cmd_CreateAlias(ts, "sv");
3672 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL,
3673 "control Cache Manager messages");
3674 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL,
3675 "[user|console|all|none]");
3677 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
3678 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3679 cmd_CreateAlias(ts, "lv");
3680 cmd_CreateAlias(ts, "listvol");
3682 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
3683 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3684 cmd_AddParm(ts, "-human", CMD_FLAG, CMD_OPTIONAL, "human-readable listing");
3685 cmd_CreateAlias(ts, "lq");
3687 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL,
3688 "show server disk space usage");
3689 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3690 cmd_AddParm(ts, "-human", CMD_FLAG, CMD_OPTIONAL, "human-readable listing");
3691 cmd_CreateAlias(ts, "df");
3693 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
3694 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3696 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
3697 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3699 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
3700 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3701 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3702 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3703 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3704 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3705 "don't check name with VLDB");
3707 #if defined(AFS_CACHE_BYPASS)
3708 ts = cmd_CreateSyntax("bypassthreshold", BypassThresholdCmd, 0,
3709 "get/set cache bypass file size threshold");
3710 cmd_AddParm(ts, "-size", CMD_SINGLE, CMD_OPTIONAL, "file size");
3717 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3721 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
3722 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3724 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL,
3725 "check local cell's servers");
3726 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3727 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3728 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3729 "just list, don't check");
3730 cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL,
3731 "seconds between probes");
3733 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL,
3734 "check volumeID/name mappings");
3735 cmd_CreateAlias(ts, "checkbackups");
3738 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL,
3740 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3741 "size in 1K byte blocks (0 => reset)");
3742 cmd_CreateAlias(ts, "cachesize");
3744 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL,
3745 "reset size back to boot value");
3747 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL,
3748 "get cache usage info");
3749 cmd_AddParm(ts, "-files", CMD_FLAG, CMD_OPTIONAL, "Show cach files used as well");
3750 cmd_AddParm(ts, "-excessive", CMD_FLAG, CMD_OPTIONAL, "excessively verbose cache stats");
3752 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL,
3753 "list configured cells");
3754 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3756 ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, NULL,
3757 "list configured cell aliases");
3759 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
3760 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3761 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3763 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3765 cmd_CreateAlias(ts, "sq");
3767 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
3768 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3769 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3770 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL,
3771 "linked cell name");
3773 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
3774 "configure new cell alias");
3775 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
3776 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
3778 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3780 * Turn this on only if you wish to be able to talk to a server which is listening
3781 * on alternative ports. This is not intended for general use and may not be
3782 * supported in the cache manager. It is not a way to run two servers at the
3783 * same host, since the cache manager cannot properly distinguish those two hosts.
3785 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL,
3786 "cell's fileserver port");
3787 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL,
3788 "cell's vldb server port");
3791 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
3792 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3794 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
3795 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3797 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
3800 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, NULL, "obsolete (listed primary cell)");
3803 /* set cache monitor host address */
3804 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, (char *)CMD_HIDDEN);
3805 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL,
3806 "host name or 'off'");
3807 cmd_CreateAlias(ts, "mariner");
3809 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
3810 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3812 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
3813 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3814 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3815 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL,
3816 "disallow setuid programs");
3818 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL,
3819 "flush all data in volume");
3820 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3822 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL,
3823 "get/set sysname (i.e. @sys) value");
3824 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3826 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL,
3827 "enable/disable translators to AFS");
3828 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3829 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL,
3830 "start/stop translator (on | off)");
3831 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL,
3832 "convert from afs to unix mode (on | off)");
3833 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL,
3834 "run on strict 'uid check' mode (on | off)");
3835 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
3836 "allow nfs mounts to subdirs of /afs/.. (on | off)");
3837 cmd_AddParm(ts, "-clipags", CMD_SINGLE, CMD_OPTIONAL,
3838 "enable use of client-assigned PAG's (on | off)");
3839 cmd_AddParm(ts, "-pagcb", CMD_SINGLE, CMD_OPTIONAL,
3840 "enable callbacks to get creds from new clients (on | off)");
3843 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
3844 "store to server after file close");
3845 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL,
3846 "asynchrony for specified names");
3847 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3848 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL,
3849 "new default (KB)");
3850 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3851 cmd_CreateAlias(ts, "sb");
3853 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL,
3854 "set cache manager encryption flag");
3855 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3857 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL,
3858 "get cache manager encryption flag");
3860 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
3861 "Manage per process RX statistics");
3862 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3863 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3864 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3866 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
3867 "Manage per peer RX statistics");
3868 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3869 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3870 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3872 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
3873 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
3875 /* try to find volume location information */
3876 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL,
3877 "get fid for file(s)");
3878 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3880 ts = cmd_CreateSyntax("discon", DisconCmd, NULL,
3881 "disconnection mode");
3882 cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_REQUIRED, "offline | online");
3883 cmd_AddParm(ts, "-policy", CMD_SINGLE, CMD_OPTIONAL, "client | server");
3884 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Force reconnection, despite any synchronization issues.");
3885 cmd_AddParm(ts, "-uid", CMD_SINGLE, CMD_OPTIONAL, "Numeric UID of user whose tokens to use at reconnect.");
3887 ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, NULL, "nuke credentials for NFS client");
3888 cmd_AddParm(ts, "-addr", CMD_SINGLE, 0, "host name or address");
3890 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
3891 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_REQUIRED, "generate a new UUID");
3893 ts = cmd_CreateSyntax("precache", PreCacheCmd, 0,
3894 "set precache size");
3895 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3896 "size in 1K byte blocks (0 => disable)");
3898 code = cmd_Dispatch(argc, argv);
3906 Die(int errnum, char *filename)
3912 "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3915 fprintf(stderr, "%s: Invalid argument.\n", pn);
3919 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3921 fprintf(stderr, "%s: no such file returned\n", pn);
3925 "%s: You can not change a backup or readonly volume\n", pn);
3931 "%s: You don't have the required access rights on '%s'\n",
3935 "%s: You do not have the required rights to do this operation\n",
3940 fprintf(stderr, "%s:'%s'", pn, filename);
3942 fprintf(stderr, "%s", pn);
3943 fprintf(stderr, ": %s\n", afs_error_message(errnum));
3948 /* get clients interface addresses */
3950 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3953 struct ViceIoctl blob;
3954 struct sprefrequest *in;
3955 struct sprefinfo *out;
3957 in = (struct sprefrequest *)space;
3961 blob.in_size = sizeof(struct sprefrequest);
3962 blob.in = (char *)in;
3964 blob.out_size = AFS_PIOCTL_MAXSIZE;
3967 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3968 /* returns addr in network byte order */
3969 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3971 perror("getClientInterfaceAddr pioctl");
3977 out = (struct sprefinfo *)blob.out;
3978 for (i = 0; i < out->num_servers; i++) {
3981 addr = ntohl(out->servers[i].server.s_addr);
3982 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3983 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3984 printf("%-50s\n", tbuffer);
3986 in->offset = out->next_offset;
3988 } while (out->next_offset > 0);
3994 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3996 afs_int32 code, addr;
3997 struct cmd_item *ti;
3998 struct ViceIoctl blob;
3999 struct setspref *ssp;
4000 int sizeUsed = 0, i, flag;
4001 afs_uint32 existingAddr[1024]; /* existing addresses on this host */
4005 ssp = (struct setspref *)space;
4006 ssp->num_servers = 0;
4009 blob.out_size = AFS_PIOCTL_MAXSIZE;
4012 fprintf(stderr, "Permission denied: requires root access.\n");
4016 /* extract all existing interface addresses */
4017 existNu = rx_getAllAddr(existingAddr, 1024);
4021 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
4022 for (ti = as->parms[0].items; ti; ti = ti->next) {
4023 if (sizeUsed >= sizeof(space)) {
4024 fprintf(stderr, "No more space\n");
4027 addr = extractAddr(ti->data, 20); /* network order */
4028 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
4029 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
4034 /* see if it is an address that really exists */
4035 for (flag = 0, i = 0; i < existNu; i++)
4036 if (existingAddr[i] == addr) {
4040 if (!flag) { /* this is an nonexistent address */
4041 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
4045 /* copy all specified addr into ioctl buffer */
4046 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
4047 printf("Adding 0x%08x\n", addr);
4049 sizeUsed += sizeof(struct spref);
4051 if (ssp->num_servers < 1) {
4052 fprintf(stderr, "No addresses specified\n");
4055 blob.in_size = sizeUsed - sizeof(struct spref);
4057 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
4067 FlushMountCmd(struct cmd_syndesc *as, void *arock)
4070 struct ViceIoctl blob;
4071 struct cmd_item *ti;
4072 char orig_name[1024]; /*Original name, may be modified */
4073 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
4074 char parent_dir[1024]; /*Parent directory of true name */
4075 char *last_component; /*Last component of true name */
4076 struct stat statbuff; /*Buffer for status info */
4077 int link_chars_read; /*Num chars read in readlink() */
4078 int thru_symlink; /*Did we get to a mount point via a symlink? */
4081 for (ti = as->parms[0].items; ti; ti = ti->next) {
4084 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
4087 if (lstat(orig_name, &statbuff) < 0) {
4088 /* if lstat fails, we should still try the pioctl, since it
4089 * may work (for example, lstat will fail, but pioctl will
4090 * work if the volume of offline (returning ENODEV). */
4091 statbuff.st_mode = S_IFDIR; /* lie like pros */
4095 * The lstat succeeded. If the given file is a symlink, substitute
4096 * the file name with the link name.
4098 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
4101 * Read name of resolved file.
4103 link_chars_read = readlink(orig_name, true_name, 1024);
4104 if (link_chars_read <= 0) {
4106 "%s: Can't read target name for '%s' symbolic link!\n",
4113 * Add a trailing null to what was read, bump the length.
4115 true_name[link_chars_read++] = 0;
4118 * If the symlink is an absolute pathname, we're fine. Otherwise, we
4119 * have to create a full pathname using the original name and the
4120 * relative symlink name. Find the rightmost slash in the original
4121 * name (we know there is one) and splice in the symlink value.
4123 if (true_name[0] != '/') {
4124 last_component = (char *)strrchr(orig_name, '/');
4125 strcpy(++last_component, true_name);
4126 strcpy(true_name, orig_name);
4129 strcpy(true_name, orig_name);
4132 * Find rightmost slash, if any.
4134 last_component = (char *)strrchr(true_name, '/');
4135 if (last_component == (char *)true_name) {
4136 strcpy(parent_dir, "/");
4139 else if (last_component != (char *)NULL) {
4141 * Found it. Designate everything before it as the parent directory,
4142 * everything after it as the final component.
4144 strncpy(parent_dir, true_name, last_component - true_name);
4145 parent_dir[last_component - true_name] = 0;
4146 last_component++; /*Skip the slash */
4149 * No slash appears in the given file name. Set parent_dir to the current
4150 * directory, and the last component as the given name.
4152 strcpy(parent_dir, ".");
4153 last_component = true_name;
4156 if (strcmp(last_component, ".") == 0
4157 || strcmp(last_component, "..") == 0) {
4159 "%s: you may not use '.' or '..' as the last component\n",
4161 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
4167 blob.in = last_component;
4168 blob.in_size = strlen(last_component) + 1;
4170 memset(space, 0, AFS_PIOCTL_MAXSIZE);
4172 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4175 if (errno == EINVAL) {
4176 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4178 Die(errno, (ti->data ? ti->data : parent_dir));
4187 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4190 afs_int32 flags = 0;
4191 struct ViceIoctl blob;
4193 if (as->parms[0].items) { /* -enable */
4194 flags |= AFSCALL_RXSTATS_ENABLE;
4196 if (as->parms[1].items) { /* -disable */
4197 flags |= AFSCALL_RXSTATS_DISABLE;
4199 if (as->parms[2].items) { /* -clear */
4200 flags |= AFSCALL_RXSTATS_CLEAR;
4203 fprintf(stderr, "You must specify at least one argument\n");
4207 blob.in = (char *)&flags;
4208 blob.in_size = sizeof(afs_int32);
4211 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4221 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4224 afs_int32 flags = 0;
4225 struct ViceIoctl blob;
4227 if (as->parms[0].items) { /* -enable */
4228 flags |= AFSCALL_RXSTATS_ENABLE;
4230 if (as->parms[1].items) { /* -disable */
4231 flags |= AFSCALL_RXSTATS_DISABLE;
4233 if (as->parms[2].items) { /* -clear */
4234 flags |= AFSCALL_RXSTATS_CLEAR;
4237 fprintf(stderr, "You must specify at least one argument\n");
4241 blob.in = (char *)&flags;
4242 blob.in_size = sizeof(afs_int32);
4245 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4255 GetFidCmd(struct cmd_syndesc *as, void *arock)
4257 struct ViceIoctl blob;
4258 struct cmd_item *ti;
4262 char cell[MAXCELLCHARS];
4264 SetDotDefault(&as->parms[0].items);
4265 for (ti = as->parms[0].items; ti; ti = ti->next) {
4266 struct VenusFid vfid;
4268 blob.out_size = sizeof(struct VenusFid);
4269 blob.out = (char *) &vfid;
4272 code = pioctl(ti->data, VIOCGETFID, &blob, 1);
4274 Die(errno,ti->data);
4279 code = GetCell(ti->data, cell);
4281 if (errno == ENOENT)
4282 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
4284 Die(errno, ti->data);
4289 printf("File %s (%u.%u.%u) located in cell %s\n",
4290 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,