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);
644 QuickPrintStatus(VolumeStatus * status, char *name)
646 double QuotaUsed = 0.0;
647 double PartUsed = 0.0;
649 printf("%-25.25s", name);
651 if (status->MaxQuota != 0) {
652 printf(" %10d %10d", status->MaxQuota, status->BlocksInUse);
654 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
656 printf(" no limit %10d", status->BlocksInUse);
658 if (QuotaUsed > 90.0) {
659 printf("%5.0f%%<<", QuotaUsed);
662 printf("%5.0f%% ", QuotaUsed);
665 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
667 if (PartUsed > 97.0) {
668 printf("%9.0f%%<<", PartUsed);
671 printf("%9.0f%% ", PartUsed);
673 printf(" <<WARNING\n");
680 QuickPrintSpace(VolumeStatus * status, char *name)
682 double PartUsed = 0.0;
684 printf("%-25.25s", name);
686 printf("%10d%10d%10d", status->PartMaxBlocks,
687 status->PartMaxBlocks - status->PartBlocksAvail,
688 status->PartBlocksAvail);
692 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
694 if (PartUsed > 90.0) {
695 printf(" %4.0f%%<<", PartUsed);
698 printf(" %4.0f%% ", PartUsed);
700 printf(" <<WARNING\n");
707 AclToString(struct Acl *acl)
709 static char mydata[AFS_PIOCTL_MAXSIZE];
710 char tstring[AFS_PIOCTL_MAXSIZE];
715 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
718 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
719 for (tp = acl->pluslist; tp; tp = tp->next) {
720 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
721 strcat(mydata, tstring);
723 for (tp = acl->minuslist; tp; tp = tp->next) {
724 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
725 strcat(mydata, tstring);
731 SetACLCmd(struct cmd_syndesc *as, void *arock)
734 struct ViceIoctl blob;
736 struct cmd_item *ti, *ui;
740 int idf = getidf(as, parm_setacl_id);
743 if (as->parms[2].items)
747 plusp = !(as->parms[3].items);
748 for (ti = as->parms[0].items; ti; ti = ti->next) {
749 blob.out_size = AFS_PIOCTL_MAXSIZE;
751 blob.in = blob.out = space;
752 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
754 Die(errno, ti->data);
761 ta = ParseAcl(space);
762 if (!plusp && ta->dfs) {
764 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
766 "(you may specify \"null\" to revoke all rights, however)\n");
774 ta = EmptyAcl(space);
776 ta = ParseAcl(space);
777 CleanAcl(ta, ti->data);
778 for (ui = as->parms[1].items; ui; ui = ui->next->next) {
782 "%s: Missing second half of user/access pair.\n", pn);
786 rights = Convert(ui->next->data, ta->dfs, &rtype);
787 if (rtype == destroy && !ta->dfs) {
788 struct AclEntry *tlist;
790 tlist = (plusp ? ta->pluslist : ta->minuslist);
791 if (!FindList(tlist, ui->data))
794 if (rtype == deny && !ta->dfs)
796 if (rtype == destroy && ta->dfs)
798 ChangeList(ta, plusp, ui->data, rights);
800 blob.in = AclToString(ta);
802 blob.in_size = 1 + strlen(blob.in);
803 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
805 if (errno == EINVAL) {
807 static char *fsenv = 0;
809 fsenv = (char *)getenv("FS_EXPERT");
812 "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n",
816 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
817 "\nPossible reasons for this include:\n\n",
818 " -You may have specified an inappropriate combination of rights.\n",
819 " For example, some DFS-supported filesystems may not allow you to\n",
820 " drop the \"c\" right from \"user_obj\".\n\n",
821 " -A mask_obj may be required (it is likely required by the underlying\n",
822 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
823 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
824 " does not automatically create or update the mask_obj. Try setting\n",
825 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
826 " users or groups. You can do this with a single command, such as\n",
827 " \"fs sa mask_obj all user:somename read\"\n\n",
828 " -A specified user or group may not exist.\n\n",
829 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
830 " This is probably not allowed by the underlying file system.\n\n",
831 " -If you add a user or group to a DFS ACL, remember that it must be\n",
832 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
833 " may be local requirements on the format of the user or group name.\n",
834 " Check with your cell administrator.\n\n",
835 " -Or numerous other possibilities. It would be great if we could be more\n",
836 " precise about the actual problem, but for various reasons, this is\n",
837 " impractical via this interface. If you can't figure it out, you\n",
838 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
839 " whatever is provided). You may get better results. Good luck!\n\n",
840 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
844 "%s: Invalid argument, possible reasons include:\n",
846 fprintf(stderr, "\t-File not in AFS\n");
848 "\t-Too many users on access control list\n");
850 "\t-Tried to add non-existent user to access control list\n");
853 Die(errno, ti->data);
865 CopyACLCmd(struct cmd_syndesc *as, void *arock)
868 struct ViceIoctl blob;
869 struct Acl *fa, *ta = 0;
873 int idf = getidf(as, parm_copyacl_id);
876 if (as->parms[2].items)
880 blob.out_size = AFS_PIOCTL_MAXSIZE;
882 blob.in = blob.out = space;
883 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
885 Die(errno, as->parms[0].items->data);
888 fa = ParseAcl(space);
889 CleanAcl(fa, as->parms[0].items->data);
890 for (ti = as->parms[1].items; ti; ti = ti->next) {
891 blob.out_size = AFS_PIOCTL_MAXSIZE;
893 blob.in = blob.out = space;
894 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
896 Die(errno, ti->data);
904 ta = EmptyAcl(space);
906 ta = ParseAcl(space);
907 CleanAcl(ta, ti->data);
908 if (ta->dfs != fa->dfs) {
910 "%s: incompatible file system types: acl not copied to %s; aborted\n",
916 if (!clear && strcmp(ta->cell, fa->cell) != 0) {
918 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
923 strcpy(ta->cell, fa->cell);
925 for (tp = fa->pluslist; tp; tp = tp->next)
926 ChangeList(ta, 1, tp->name, tp->rights);
927 for (tp = fa->minuslist; tp; tp = tp->next)
928 ChangeList(ta, 0, tp->name, tp->rights);
929 blob.in = AclToString(ta);
931 blob.in_size = 1 + strlen(blob.in);
932 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
934 if (errno == EINVAL) {
936 "%s: Invalid argument, possible reasons include:\n",
938 fprintf(stderr, "\t-File not in AFS\n");
940 Die(errno, ti->data);
951 /* pioctl() call to get the cellname of a pathname */
953 GetCell(char *fname, char *cellname)
956 struct ViceIoctl blob;
959 blob.out_size = MAXCELLCHARS;
962 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
963 return code ? errno : 0;
966 /* Check if a username is valid: If it contains only digits (or a
967 * negative sign), then it might be bad. We then query the ptserver
971 BadName(char *aname, char *fname)
973 afs_int32 tc, code, id;
975 char cell[MAXCELLCHARS];
977 for (nm = aname; (tc = *nm); nm++) {
978 /* all must be '-' or digit to be bad */
979 if (tc != '-' && (tc < '0' || tc > '9'))
983 /* Go to the PRDB and see if this all number username is valid */
984 code = GetCell(fname, cell);
988 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
989 code = pr_SNameToId(aname, &id);
992 /* 1=>Not-valid; 0=>Valid */
993 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
997 /* clean up an access control list of its bad entries; return 1 if we made
998 any changes to the list, and 0 otherwise */
1000 CleanAcl(struct Acl *aa, char *fname)
1002 struct AclEntry *te, **le, *ne;
1005 /* Don't correct DFS ACL's for now */
1009 /* prune out bad entries */
1010 changes = 0; /* count deleted entries */
1012 for (te = aa->pluslist; te; te = ne) {
1014 if (BadName(te->name, fname)) {
1024 le = &aa->minuslist;
1025 for (te = aa->minuslist; te; te = ne) {
1027 if (BadName(te->name, fname)) {
1041 /* clean up an acl to not have bogus entries */
1043 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1047 struct ViceIoctl blob;
1049 struct cmd_item *ti;
1050 struct AclEntry *te;
1053 SetDotDefault(&as->parms[0].items);
1054 for (ti = as->parms[0].items; ti; ti = ti->next) {
1055 blob.out_size = AFS_PIOCTL_MAXSIZE;
1058 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1060 Die(errno, ti->data);
1067 ta = ParseAcl(space);
1070 "%s: cleanacl is not supported for DFS access lists.\n",
1076 changes = CleanAcl(ta, ti->data);
1079 /* now set the acl */
1080 blob.in = AclToString(ta);
1081 blob.in_size = strlen(blob.in) + 1;
1083 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1085 if (errno == EINVAL) {
1087 "%s: Invalid argument, possible reasons include\n",
1089 fprintf(stderr, "%s: File not in vice or\n", pn);
1091 "%s: Too many users on access control list or\n",
1094 Die(errno, ti->data);
1100 /* now list the updated acl */
1101 printf("Access list for %s is now\n", ti->data);
1102 if (ta->nplus > 0) {
1104 printf("Normal rights:\n");
1105 for (te = ta->pluslist; te; te = te->next) {
1106 printf(" %s ", te->name);
1107 PRights(te->rights, ta->dfs);
1111 if (ta->nminus > 0) {
1112 printf("Negative rights:\n");
1113 for (te = ta->minuslist; te; te = te->next) {
1114 printf(" %s ", te->name);
1115 PRights(te->rights, ta->dfs);
1122 printf("Access list for %s is fine.\n", ti->data);
1130 ListACLCmd(struct cmd_syndesc *as, void *arock)
1134 struct ViceIoctl blob;
1135 struct AclEntry *te;
1136 struct cmd_item *ti;
1137 int idf = getidf(as, parm_listacl_id);
1140 SetDotDefault(&as->parms[0].items);
1141 for (ti = as->parms[0].items; ti; ti = ti->next) {
1142 blob.out_size = AFS_PIOCTL_MAXSIZE;
1144 blob.in = blob.out = space;
1145 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1147 Die(errno, ti->data);
1151 ta = ParseAcl(space);
1152 if (as->parms[3].items) { /* -cmd */
1153 printf("fs setacl -dir %s -acl ", ti->data);
1154 if (ta->nplus > 0) {
1155 for (te = ta->pluslist; te; te = te->next) {
1156 printf(" %s ", te->name);
1157 PRights(te->rights, ta->dfs);
1161 if (ta->nminus > 0) {
1162 printf("fs setacl -dir %s -acl ", ti->data);
1163 for (te = ta->minuslist; te; te = te->next) {
1164 printf(" %s ", te->name);
1165 PRights(te->rights, ta->dfs);
1167 printf(" -negative\n");
1172 printf("Access list for %s is\n", ti->data);
1175 printf("DFS access list for %s is\n", ti->data);
1178 printf("DFS initial directory access list of %s is\n", ti->data);
1181 printf("DFS initial file access list of %s is\n", ti->data);
1185 printf(" Default cell = %s\n", ta->cell);
1187 if (ta->nplus > 0) {
1189 printf("Normal rights:\n");
1190 for (te = ta->pluslist; te; te = te->next) {
1191 printf(" %s ", te->name);
1192 PRights(te->rights, ta->dfs);
1196 if (ta->nminus > 0) {
1197 printf("Negative rights:\n");
1198 for (te = ta->minuslist; te; te = te->next) {
1199 printf(" %s ", te->name);
1200 PRights(te->rights, ta->dfs);
1213 GetCallerAccess(struct cmd_syndesc *as, void *arock)
1215 struct cmd_item *ti;
1218 SetDotDefault(&as->parms[0].items);
1219 for (ti = as->parms[0].items; ti; ti = ti->next) {
1221 struct ViceIoctl blob;
1222 struct vcxstat2 stat;
1223 blob.out_size = sizeof(struct vcxstat2);
1225 blob.out = (void *)&stat;
1226 code = pioctl(ti->data, VIOC_GETVCXSTATUS2, &blob, 1);
1228 Die(errno, ti->data);
1232 printf("Callers access to %s is ", ti->data);
1233 PRights(stat.callerAccess, 0);
1240 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1243 struct ViceIoctl blob;
1244 struct cmd_item *ti;
1247 SetDotDefault(&as->parms[0].items);
1248 for (ti = as->parms[0].items; ti; ti = ti->next) {
1249 blob.in_size = blob.out_size = 0;
1250 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1252 fprintf(stderr, "Error flushing volume ");
1262 * The Windows version of UuidCmd displays the UUID.
1263 * When the UNIX version is updated to do the same
1264 * be sure to replace the CMD_REQUIRED flag with
1265 * CMD_OPTIONAL in the cmd_AddParam(-generate) call
1268 UuidCmd(struct cmd_syndesc *as, void *arock)
1271 struct ViceIoctl blob;
1276 if (as->parms[0].items) {
1278 fprintf (stderr, "Permission denied: requires root access.\n");
1282 /* generate new UUID */
1283 code = pioctl(0, VIOC_NEWUUID, &blob, 1);
1290 printf("New uuid generated.\n");
1292 /* This will never execute */
1293 printf("Please add the '-generate' option to generate a new UUID.\n");
1298 #if defined(AFS_CACHE_BYPASS)
1300 * Set cache-bypass threshold. Files larger than this size will not be cached.
1301 * With a threshold of 0, the cache is always bypassed. With a threshold of -1,
1302 * cache bypass is disabled.
1306 BypassThresholdCmd(struct cmd_syndesc *as, void *arock)
1309 struct ViceIoctl blob;
1310 afs_int32 threshold_i, threshold_o;
1313 /* if new threshold supplied, then set and confirm, else,
1314 * get current threshold and print
1317 if(as->parms[0].items) {
1320 tp = as->parms[0].items->data;
1323 for(ix = 0; ix < len; ++ix) {
1324 if(!isdigit(tp[0])) {
1330 fprintf(stderr, "fs bypassthreshold -size: %s must be an undecorated digit string.\n", tp);
1333 threshold_i = atoi(tp);
1334 if(ix > 9 && threshold_i < 2147483647)
1335 threshold_i = 2147483647;
1336 blob.in = (char *) &threshold_i;
1337 blob.in_size = sizeof(threshold_i);
1343 blob.out = (char *) &threshold_o;
1344 blob.out_size = sizeof(threshold_o);
1345 code = pioctl(0, VIOC_SETBYPASS_THRESH, &blob, 1);
1350 printf("Cache bypass threshold %d", threshold_o);
1351 if(threshold_o == -1)
1352 printf(" (disabled)");
1362 FlushCmd(struct cmd_syndesc *as, void *arock)
1365 struct ViceIoctl blob;
1366 struct cmd_item *ti;
1369 for (ti = as->parms[0].items; ti; ti = ti->next) {
1370 blob.in_size = blob.out_size = 0;
1371 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1373 if (errno == EMFILE) {
1374 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1377 fprintf(stderr, "%s: Error flushing file ", pn);
1387 /* all this command does is repackage its args and call SetVolCmd */
1389 SetQuotaCmd(struct cmd_syndesc *as, void *arock)
1391 struct cmd_syndesc ts;
1393 /* copy useful stuff from our command slot; we may later have to reorder */
1394 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1395 return SetVolCmd(&ts, arock);
1399 SetVolCmd(struct cmd_syndesc *as, void *arock)
1402 struct ViceIoctl blob;
1403 struct cmd_item *ti;
1404 struct VolumeStatus *status;
1405 char *offmsg, *input;
1408 SetDotDefault(&as->parms[0].items);
1409 for (ti = as->parms[0].items; ti; ti = ti->next) {
1411 blob.out_size = AFS_PIOCTL_MAXSIZE;
1412 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1415 status = (VolumeStatus *) space;
1416 status->MinQuota = status->MaxQuota = -1;
1418 if (as->parms[1].items) {
1419 code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota);
1421 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1426 if (as->parms[2].items)
1427 offmsg = as->parms[2].items->data;
1428 input = (char *)status + sizeof(*status);
1429 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1431 if (strlen(offmsg) >= VMSGSIZE) {
1433 "%s: message must be shorter than %d characters\n",
1438 strcpy(input, offmsg);
1439 blob.in_size += strlen(offmsg);
1440 input += strlen(offmsg) + 1;
1443 *(input++) = '\0'; /* Pad for old style volume "motd" */
1444 code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1);
1446 Die(errno, ti->data);
1454 * Why is VenusFid declared in the kernel-only section of afs.h,
1455 * if it's the exported interface of the cache manager?
1463 ExamineCmd(struct cmd_syndesc *as, void *arock)
1466 struct ViceIoctl blob;
1467 struct cmd_item *ti;
1468 struct VolumeStatus *status;
1469 char *name, *offmsg;
1472 SetDotDefault(&as->parms[0].items);
1473 for (ti = as->parms[0].items; ti; ti = ti->next) {
1474 struct VenusFid vfid;
1477 blob.out_size = AFS_PIOCTL_MAXSIZE;
1480 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1482 Die(errno, ti->data);
1486 status = (VolumeStatus *) space;
1487 name = (char *)status + sizeof(*status);
1488 offmsg = name + strlen(name) + 1;
1490 blob.out_size = sizeof(struct VenusFid);
1491 blob.out = (char *) &vfid;
1492 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1493 printf("File %s (%u.%u.%u) contained in volume %u\n",
1494 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1498 PrintStatus(status, name, offmsg);
1504 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1507 struct ViceIoctl blob;
1508 struct cmd_item *ti;
1509 struct VolumeStatus *status;
1513 printf("%-25s%-11s%-11s%-7s%-11s\n", "Volume Name", " Quota",
1514 " Used", " %Used", " Partition");
1515 SetDotDefault(&as->parms[0].items);
1516 for (ti = as->parms[0].items; ti; ti = ti->next) {
1518 blob.out_size = AFS_PIOCTL_MAXSIZE;
1521 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1523 Die(errno, ti->data);
1527 status = (VolumeStatus *) space;
1528 name = (char *)status + sizeof(*status);
1529 QuickPrintStatus(status, name);
1535 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1538 struct ViceIoctl blob;
1539 struct cmd_item *ti;
1545 SetDotDefault(&as->parms[0].items);
1546 for (ti = as->parms[0].items; ti; ti = ti->next) {
1548 blob.out_size = AFS_PIOCTL_MAXSIZE;
1551 memset(space, 0, sizeof(space));
1552 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1554 Die(errno, ti->data);
1558 hosts = (afs_int32 *) space;
1559 printf("File %s is on host%s ", ti->data,
1560 (hosts[0] && !hosts[1]) ? "" : "s");
1561 for (j = 0; j < AFS_MAXHOSTS; j++) {
1564 tp = hostutil_GetNameByINet(hosts[j]);
1574 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1577 struct ViceIoctl blob;
1578 struct cmd_item *ti;
1580 struct VolumeStatus *status;
1583 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1584 " used", " avail", " %used");
1585 SetDotDefault(&as->parms[0].items);
1586 for (ti = as->parms[0].items; ti; ti = ti->next) {
1588 blob.out_size = AFS_PIOCTL_MAXSIZE;
1591 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1593 Die(errno, ti->data);
1597 status = (VolumeStatus *) space;
1598 name = (char *)status + sizeof(*status);
1599 QuickPrintSpace(status, name);
1605 QuotaCmd(struct cmd_syndesc *as, void *arock)
1608 struct ViceIoctl blob;
1609 struct cmd_item *ti;
1611 struct VolumeStatus *status;
1614 SetDotDefault(&as->parms[0].items);
1615 for (ti = as->parms[0].items; ti; ti = ti->next) {
1617 blob.out_size = AFS_PIOCTL_MAXSIZE;
1620 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1622 Die(errno, ti->data);
1626 status = (VolumeStatus *) space;
1627 if (status->MaxQuota)
1629 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
1632 printf("%2.0f%% of quota used.\n", quotaPct);
1638 ListMountCmd(struct cmd_syndesc *as, void *arock)
1641 struct ViceIoctl blob;
1642 struct cmd_item *ti;
1643 char orig_name[1024]; /*Original name, may be modified */
1644 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
1645 char parent_dir[1024]; /*Parent directory of true name */
1646 char *last_component; /*Last component of true name */
1647 struct stat statbuff; /*Buffer for status info */
1648 int link_chars_read; /*Num chars read in readlink() */
1649 int thru_symlink; /*Did we get to a mount point via a symlink? */
1652 for (ti = as->parms[0].items; ti; ti = ti->next) {
1655 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
1658 if (lstat(orig_name, &statbuff) < 0) {
1659 /* if lstat fails, we should still try the pioctl, since it
1660 * may work (for example, lstat will fail, but pioctl will
1661 * work if the volume of offline (returning ENODEV). */
1662 statbuff.st_mode = S_IFDIR; /* lie like pros */
1666 * The lstat succeeded. If the given file is a symlink, substitute
1667 * the file name with the link name.
1669 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1672 * Read name of resolved file.
1674 link_chars_read = readlink(orig_name, true_name, 1024);
1675 if (link_chars_read <= 0) {
1677 "%s: Can't read target name for '%s' symbolic link!\n",
1684 * Add a trailing null to what was read, bump the length.
1686 true_name[link_chars_read++] = 0;
1689 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1690 * have to create a full pathname using the original name and the
1691 * relative symlink name. Find the rightmost slash in the original
1692 * name (we know there is one) and splice in the symlink value.
1694 if (true_name[0] != '/') {
1695 last_component = (char *)strrchr(orig_name, '/');
1696 strcpy(++last_component, true_name);
1697 strcpy(true_name, orig_name);
1700 strcpy(true_name, orig_name);
1703 * Find rightmost slash, if any.
1705 last_component = (char *)strrchr(true_name, '/');
1706 if (last_component == (char *)true_name) {
1707 strcpy(parent_dir, "/");
1710 else if (last_component != (char *)NULL) {
1712 * Found it. Designate everything before it as the parent directory,
1713 * everything after it as the final component.
1715 strncpy(parent_dir, true_name, last_component - true_name);
1716 parent_dir[last_component - true_name] = 0;
1717 last_component++; /*Skip the slash */
1720 * No slash appears in the given file name. Set parent_dir to the current
1721 * directory, and the last component as the given name.
1723 strcpy(parent_dir, ".");
1724 last_component = true_name;
1727 if (strcmp(last_component, ".") == 0
1728 || strcmp(last_component, "..") == 0) {
1730 "%s: you may not use '.' or '..' as the last component\n",
1732 fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n",
1738 blob.in = last_component;
1739 blob.in_size = strlen(last_component) + 1;
1740 blob.out_size = AFS_PIOCTL_MAXSIZE;
1742 memset(space, 0, AFS_PIOCTL_MAXSIZE);
1744 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1747 printf("'%s' is a %smount point for volume '%s'\n", ti->data,
1748 (thru_symlink ? "symbolic link, leading to a " : ""),
1751 if (errno == EINVAL) {
1752 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
1754 Die(errno, (ti->data ? ti->data : parent_dir));
1763 MakeMountCmd(struct cmd_syndesc *as, void *arock)
1766 char *cellName, *volName, *tmpName;
1767 struct afsconf_cell info;
1768 struct vldbentry vldbEntry;
1769 struct ViceIoctl blob;
1775 if (as->parms[5].items && !as->parms[2].items) {
1776 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1781 if (as->parms[2].items) /* cell name specified */
1782 cellName = as->parms[2].items->data;
1785 volName = as->parms[1].items->data;
1787 if (strlen(volName) >= 64) {
1789 "%s: volume name too long (length must be < 64 characters)\n",
1794 /* Check for a cellname in the volume specification, and complain
1795 * if it doesn't match what was specified with -cell */
1796 if ((tmpName = strchr(volName, ':'))) {
1799 if (strcasecmp(cellName, volName)) {
1800 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1805 volName = ++tmpName;
1808 if (!InAFS(Parent(as->parms[0].items->data))) {
1810 "%s: mount points must be created within the AFS file system\n",
1817 blob.out_size = AFS_PIOCTL_MAXSIZE;
1820 pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME,
1824 code = GetCellName(cellName ? cellName : space, &info);
1828 if (!(as->parms[4].items)) {
1829 /* not fast, check which cell the mountpoint is being created in */
1830 /* not fast, check name with VLDB */
1831 code = VLDBInit(1, &info);
1833 /* make the check. Don't complain if there are problems with init */
1835 ubik_VL_GetEntryByNameO(uclient, 0, volName,
1837 if (code == VL_NOENT) {
1839 "%s: warning, volume %s does not exist in cell %s.\n",
1840 pn, volName, cellName ? cellName : space);
1845 if (as->parms[3].items) /* if -rw specified */
1850 /* cellular mount point, prepend cell prefix */
1851 strcat(space, info.name);
1854 strcat(space, volName); /* append volume name */
1855 strcat(space, "."); /* stupid convention; these end with a period */
1856 code = symlink(space, as->parms[0].items->data);
1858 Die(errno, as->parms[0].items->data);
1865 * Delete AFS mount points. Variables are used as follows:
1866 * tbuffer: Set to point to the null-terminated directory name of the mount point
1867 * (or ``.'' if none is provided)
1868 * tp: Set to point to the actual name of the mount point to nuke.
1871 RemoveMountCmd(struct cmd_syndesc *as, void *arock)
1874 struct ViceIoctl blob;
1875 struct cmd_item *ti;
1877 char lsbuffer[1024];
1881 for (ti = as->parms[0].items; ti; ti = ti->next) {
1883 tp = (char *)strrchr(ti->data, '/');
1885 strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */
1887 tp++; /* skip the slash */
1889 strcpy(tbuffer, ".");
1893 blob.in_size = strlen(tp) + 1;
1894 blob.out = lsbuffer;
1895 blob.out_size = sizeof(lsbuffer);
1896 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 1);
1898 if (errno == EINVAL) {
1899 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
1902 Die(errno, ti->data);
1905 continue; /* don't bother trying */
1909 blob.in_size = strlen(tp) + 1;
1910 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 1);
1912 Die(errno, ti->data);
1923 CheckServersCmd(struct cmd_syndesc *as, void *arock)
1926 struct ViceIoctl blob;
1930 struct afsconf_cell info;
1931 struct chservinfo checkserv;
1933 memset(&checkserv, 0, sizeof(struct chservinfo));
1934 blob.in_size = sizeof(struct chservinfo);
1935 blob.in = (caddr_t) & checkserv;
1937 blob.out_size = AFS_PIOCTL_MAXSIZE;
1939 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1941 /* prepare flags for checkservers command */
1942 temp = 2; /* default to checking local cell only */
1943 if (as->parms[2].items)
1944 temp |= 1; /* set fast flag */
1945 if (as->parms[1].items)
1946 temp &= ~2; /* turn off local cell check */
1948 checkserv.magic = 0x12345678; /* XXX */
1949 checkserv.tflags = temp;
1951 /* now copy in optional cell name, if specified */
1952 if (as->parms[0].items) {
1953 code = GetCellName(as->parms[0].items->data, &info);
1957 strcpy(checkserv.tbuffer, info.name);
1958 checkserv.tsize = strlen(info.name) + 1;
1960 strcpy(checkserv.tbuffer, "\0");
1961 checkserv.tsize = 0;
1964 if (as->parms[3].items) {
1965 checkserv.tinterval = atol(as->parms[3].items->data);
1968 if (checkserv.tinterval < 0) {
1970 ("Warning: The negative -interval is ignored; treated as an inquiry\n");
1971 checkserv.tinterval = 0;
1972 } else if (checkserv.tinterval > 600) {
1974 ("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1975 checkserv.tinterval = 600; /* 10 min max interval */
1978 checkserv.tinterval = -1; /* don't change current interval */
1981 code = pioctl(0, VIOCCKSERV, &blob, 1);
1983 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1984 printf("Must be root to change -interval\n");
1990 memcpy(&temp, space, sizeof(afs_int32));
1991 if (checkserv.tinterval >= 0) {
1992 if (checkserv.tinterval > 0)
1994 ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1995 checkserv.tinterval, temp);
1997 printf("The current down server probe interval is %d secs\n",
2002 printf("All servers are running.\n");
2005 ("These servers unavailable due to network or server problems: ");
2007 memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32));
2010 tp = hostutil_GetNameByINet(temp);
2020 MessagesCmd(struct cmd_syndesc *as, void *arock)
2023 struct ViceIoctl blob;
2024 struct gaginfo gagflags;
2025 struct cmd_item *show;
2027 memset(&gagflags, 0, sizeof(struct gaginfo));
2028 blob.in_size = sizeof(struct gaginfo);
2029 blob.in = (caddr_t) & gagflags;
2030 blob.out_size = AFS_PIOCTL_MAXSIZE;
2032 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2034 if ((show = as->parms[0].items)) {
2035 if (!strcasecmp(show->data, "user"))
2036 gagflags.showflags |= GAGUSER;
2037 else if (!strcasecmp(show->data, "console"))
2038 gagflags.showflags |= GAGCONSOLE;
2039 else if (!strcasecmp(show->data, "all"))
2040 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2041 else if (!strcasecmp(show->data, "none"))
2045 "unrecognized flag %s: must be in {user,console,all,none}\n",
2054 code = pioctl(0, VIOC_GAG, &blob, 1);
2064 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2067 struct ViceIoctl blob;
2071 code = pioctl(0, VIOCCKBACK, &blob, 1);
2077 printf("All volumeID/name mappings checked.\n");
2082 PreCacheCmd(struct cmd_syndesc *as, void *arock)
2085 struct ViceIoctl blob;
2088 if (!as->parms[0].items && !as->parms[1].items) {
2089 fprintf(stderr, "%s: syntax error in precache cmd.\n", pn);
2092 if (as->parms[0].items) {
2093 code = util_GetInt32(as->parms[0].items->data, &temp);
2095 fprintf(stderr, "%s: bad integer specified for precache size.\n",
2101 blob.in = (char *)&temp;
2102 blob.in_size = sizeof(afs_int32);
2104 code = pioctl(0, VIOCPRECACHE, &blob, 1);
2110 printf("New precache size set.\n");
2115 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2118 struct ViceIoctl blob;
2121 if (!as->parms[0].items && !as->parms[1].items) {
2122 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
2125 if (as->parms[0].items) {
2126 code = util_GetHumanInt32(as->parms[0].items->data, &temp);
2128 fprintf(stderr, "%s: bad integer specified for cache size.\n",
2134 blob.in = (char *)&temp;
2135 blob.in_size = sizeof(afs_int32);
2137 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2139 if (errno == EROFS) {
2141 ("'fs setcache' not allowed on memory cache based cache managers.\n");
2148 printf("New cache size set.\n");
2152 #define MAXGCSIZE 16
2154 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2156 afs_int32 code, filesUsed;
2157 struct ViceIoctl blob;
2158 afs_int32 parms[MAXGCSIZE];
2159 double percentFiles, percentBlocks;
2160 afs_int32 flags = 0;
2162 if (as->parms[0].items){ /* -files */
2164 } else if (as->parms[1].items){ /* -excessive */
2170 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
2172 blob.in = (char *)&flags;
2173 blob.in_size = sizeof(afs_int32);
2174 } else { /* be backward compatible */
2178 blob.out_size = sizeof(parms);
2179 blob.out = (char *)parms;
2180 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2187 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2188 parms[1], parms[0]);
2189 if (parms[1] > parms[0])
2190 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2194 percentBlocks = ((double)parms[1]/parms[0]) * 100;
2195 printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n",
2196 percentBlocks, parms[1], parms[0]);
2201 filesUsed = parms[2] - parms[3];
2202 percentFiles = ((double)filesUsed/parms[2]) * 100;
2203 printf(" %5.0f%% of the cache files (%d of %d files)\n",
2204 percentFiles, filesUsed, parms[2]);
2206 printf(" afs_cacheFiles: %10d\n", parms[2]);
2207 printf(" IFFree: %10d\n", parms[3]);
2208 printf(" IFEverUsed: %10d\n", parms[4]);
2209 printf(" IFDataMod: %10d\n", parms[5]);
2210 printf(" IFDirtyPages: %10d\n", parms[6]);
2211 printf(" IFAnyPages: %10d\n", parms[7]);
2212 printf(" IFDiscarded: %10d\n", parms[8]);
2213 printf(" DCentries: %10d\n", parms[9]);
2214 printf(" 0k- 4K: %10d\n", parms[10]);
2215 printf(" 4k- 16k: %10d\n", parms[11]);
2216 printf(" 16k- 64k: %10d\n", parms[12]);
2217 printf(" 64k- 256k: %10d\n", parms[13]);
2218 printf(" 256k- 1M: %10d\n", parms[14]);
2219 printf(" >=1M: %10d\n", parms[15]);
2222 if (percentBlocks > 90)
2223 printf("[cache size usage over 90%%, consider increasing cache size]\n");
2224 if (percentFiles > 90)
2225 printf("[cache file usage over 90%%, consider increasing '-files' argument to afsd]\n");
2231 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2236 struct ViceIoctl blob;
2239 resolve = !(as->parms[0].items); /* -numeric */
2243 memcpy(tp, &i, sizeof(afs_int32));
2244 blob.out_size = AFS_PIOCTL_MAXSIZE;
2245 blob.in_size = sizeof(afs_int32);
2248 code = pioctl(0, VIOCGETCELL, &blob, 1);
2251 break; /* done with the list */
2256 printf("Cell %s on hosts", tp + AFS_MAXCELLHOSTS * sizeof(afs_int32));
2257 for (j = 0; j < AFS_MAXCELLHOSTS; j++) {
2259 char *name, tbuffer[20];
2261 memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32));
2266 name = hostutil_GetNameByINet(addr);
2269 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2270 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2273 printf(" %s", name);
2281 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2284 char *tp, *aliasName, *realName;
2285 struct ViceIoctl blob;
2289 memcpy(tp, &i, sizeof(afs_int32));
2290 blob.out_size = AFS_PIOCTL_MAXSIZE;
2291 blob.in_size = sizeof(afs_int32);
2294 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2297 break; /* done with the list */
2303 tp += strlen(aliasName) + 1;
2305 printf("Alias %s for cell %s\n", aliasName, realName);
2311 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2314 struct ViceIoctl blob;
2315 struct cmd_item *ti;
2317 struct hostent *thp;
2320 ti = as->parms[0].items;
2323 thp = hostutil_GetHostByName(ti->data);
2325 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2328 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2330 hostAddr = 0; /* means don't set host */
2331 setp = 0; /* aren't setting host */
2334 /* now do operation */
2335 blob.in_size = sizeof(afs_int32);
2336 blob.out_size = sizeof(afs_int32);
2337 blob.in = (char *) &hostAddr;
2338 blob.out = (char *) &hostAddr;
2340 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2349 NukeNFSCredsCmd(struct cmd_syndesc *as, void *arock)
2352 struct ViceIoctl blob;
2353 struct cmd_item *ti;
2355 struct hostent *thp;
2357 ti = as->parms[0].items;
2358 thp = hostutil_GetHostByName(ti->data);
2360 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2363 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2365 /* now do operation */
2366 blob.in_size = sizeof(afs_int32);
2367 blob.out_size = sizeof(afs_int32);
2368 blob.in = (char *) &hostAddr;
2369 blob.out = (char *) &hostAddr;
2371 code = pioctl(0, VIOC_NFS_NUKE_CREDS, &blob, 1);
2380 NewCellCmd(struct cmd_syndesc *as, void *arock)
2382 afs_int32 code, linkedstate = 0, size = 0, *lp;
2383 struct ViceIoctl blob;
2384 struct cmd_item *ti;
2385 char *tp, *cellname = 0;
2386 struct hostent *thp;
2387 afs_int32 fsport = 0, vlport = 0;
2388 afs_int32 scount; /* Number of servers to pass in pioctl call */
2391 * With the NEWCELL pioctl call, 3.4 clients take an array of
2392 * AFS_MAXHOSTS (13) servers while 3.5 clients take an array of
2393 * AFS_MAXCELLHOSTS (8) servers. To determine which we are talking to,
2394 * do a GETCELL pioctl and pass it a magic number. If an array of
2395 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
2396 * If we get back EDOM, there are no cells in the kernel yet,
2397 * and we'll assume a 3.5 client.
2400 lp = (afs_int32 *) tp;
2401 *lp++ = 0; /* first cell entry */
2402 *lp = 0x12345678; /* magic */
2403 blob.out_size = AFS_PIOCTL_MAXSIZE;
2404 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
2407 code = pioctl(0, VIOCGETCELL, &blob, 1);
2408 if (code < 0 && errno != EDOM) {
2412 if (code < 1 && errno == EDOM) {
2413 scount = AFS_MAXHOSTS;
2416 cellname = tp + AFS_MAXCELLHOSTS * sizeof(afs_int32);
2417 scount = ((cellname[0] != '\0') ? AFS_MAXCELLHOSTS : AFS_MAXHOSTS);
2420 /* Now setup and do the NEWCELL pioctl call */
2421 memset(space, 0, (scount + 1) * sizeof(afs_int32));
2423 lp = (afs_int32 *) tp;
2425 tp += sizeof(afs_int32);
2426 for (ti = as->parms[1].items; ti; ti = ti->next) {
2427 thp = hostutil_GetHostByName(ti->data);
2430 "%s: Host %s not found in host table, skipping it.\n", pn,
2433 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2434 tp += sizeof(afs_int32);
2437 if (as->parms[2].items) {
2439 * Link the cell, for the purposes of volume location, to the specified
2442 cellname = as->parms[2].items->data;
2445 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2446 if (as->parms[3].items) {
2447 code = util_GetInt32(as->parms[3].items->data, &vlport);
2450 "%s: bad integer specified for the fileserver port.\n",
2455 if (as->parms[4].items) {
2456 code = util_GetInt32(as->parms[4].items->data, &fsport);
2459 "%s: bad integer specified for the vldb server port.\n",
2465 tp = (char *)(space + (scount + 1) * sizeof(afs_int32));
2466 lp = (afs_int32 *) tp;
2470 strcpy(space + ((scount + 4) * sizeof(afs_int32)),
2471 as->parms[0].items->data);
2472 size = ((scount + 4) * sizeof(afs_int32))
2473 + strlen(as->parms[0].items->data)
2474 + 1 /* for null */ ;
2475 tp = (char *)(space + size);
2477 strcpy(tp, cellname);
2478 size += strlen(cellname) + 1;
2480 blob.in_size = size;
2483 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2492 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2495 struct ViceIoctl blob;
2497 char *aliasName, *realName;
2499 /* Now setup and do the NEWCELL pioctl call */
2500 aliasName = as->parms[0].items->data;
2501 realName = as->parms[1].items->data;
2503 strcpy(tp, aliasName);
2504 tp += strlen(aliasName) + 1;
2505 strcpy(tp, realName);
2506 tp += strlen(realName) + 1;
2508 blob.in_size = tp - space;
2512 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2514 if (errno == EEXIST) {
2516 "%s: cell name `%s' in use by an existing cell.\n", pn,
2527 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2530 struct cmd_item *ti;
2532 char cell[MAXCELLCHARS];
2534 SetDotDefault(&as->parms[0].items);
2535 for (ti = as->parms[0].items; ti; ti = ti->next) {
2536 code = GetCell(ti->data, cell);
2538 if (errno == ENOENT)
2539 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
2541 Die(errno, ti->data);
2546 printf("File %s lives in cell '%s'\n", ti->data, cell);
2552 WSCellCmd(struct cmd_syndesc *as, void *arock)
2555 struct ViceIoctl blob;
2559 blob.out_size = AFS_PIOCTL_MAXSIZE;
2562 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2568 printf("This workstation belongs to cell '%s'\n", space);
2573 static PrimaryCellCmd(as)
2574 struct cmd_syndesc *as;
2576 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2582 MonitorCmd(struct cmd_syndesc *as, void *arock)
2585 struct ViceIoctl blob;
2586 struct cmd_item *ti;
2588 struct hostent *thp;
2592 ti = as->parms[0].items;
2596 if (!strcmp(ti->data, "off"))
2597 hostAddr = 0xffffffff;
2599 thp = hostutil_GetHostByName(ti->data);
2601 if (!strcmp(ti->data, "localhost")) {
2603 "localhost not in host table, assuming 127.0.0.1\n");
2604 hostAddr = htonl(0x7f000001);
2606 fprintf(stderr, "host %s not found in host table.\n",
2611 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2614 hostAddr = 0; /* means don't set host */
2615 setp = 0; /* aren't setting host */
2618 /* now do operation */
2619 blob.in_size = sizeof(afs_int32);
2620 blob.out_size = sizeof(afs_int32);
2621 blob.in = (char *)&hostAddr;
2622 blob.out = (char *)&hostAddr;
2623 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2629 printf("%s: new monitor host set.\n", pn);
2631 /* now decode old address */
2632 if (hostAddr == 0xffffffff) {
2633 printf("Cache monitoring is currently disabled.\n");
2635 tp = hostutil_GetNameByINet(hostAddr);
2636 printf("Using host %s for monitor services.\n", tp);
2643 SysNameCmd(struct cmd_syndesc *as, void *arock)
2646 struct ViceIoctl blob;
2647 struct cmd_item *ti;
2648 char *input = space;
2651 ti = as->parms[0].items;
2654 blob.out_size = AFS_PIOCTL_MAXSIZE;
2655 blob.in_size = sizeof(afs_int32);
2656 input += sizeof(afs_int32);
2657 for (; ti; ti = ti->next) {
2659 blob.in_size += strlen(ti->data) + 1;
2660 if (blob.in_size > AFS_PIOCTL_MAXSIZE) {
2661 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2662 setp > 1 ? "s" : "");
2665 strcpy(input, ti->data);
2666 input += strlen(ti->data);
2669 memcpy(space, &setp, sizeof(afs_int32));
2670 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2676 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2680 memcpy(&setp, input, sizeof(afs_int32));
2681 input += sizeof(afs_int32);
2683 fprintf(stderr, "No sysname name value was found\n");
2686 printf("Current sysname%s is", setp > 1 ? " list" : "");
2687 for (; setp > 0; --setp) {
2688 printf(" \'%s\'", input);
2689 input += strlen(input) + 1;
2695 static char *exported_types[] = { "null", "nfs", "" };
2697 ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2700 struct ViceIoctl blob;
2701 struct cmd_item *ti;
2702 int export = 0, type = 0, mode = 0, exp = 0, exportcall, pwsync =
2703 0, smounts = 0, clipags = 0, pagcb = 0;
2705 ti = as->parms[0].items;
2706 if (strcmp(ti->data, "nfs") == 0)
2707 type = 0x71; /* NFS */
2710 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n",
2714 ti = as->parms[1].items;
2716 if (strcmp(ti->data, "on") == 0)
2718 else if (strcmp(ti->data, "off") == 0)
2721 fprintf(stderr, "Illegal argument %s\n", ti->data);
2726 if ((ti = as->parms[2].items)) { /* -noconvert */
2727 if (strcmp(ti->data, "on") == 0)
2729 else if (strcmp(ti->data, "off") == 0)
2732 fprintf(stderr, "Illegal argument %s\n", ti->data);
2736 if ((ti = as->parms[3].items)) { /* -uidcheck */
2737 if (strcmp(ti->data, "on") == 0)
2739 else if (strcmp(ti->data, "off") == 0)
2742 fprintf(stderr, "Illegal argument %s\n", ti->data);
2746 if ((ti = as->parms[4].items)) { /* -submounts */
2747 if (strcmp(ti->data, "on") == 0)
2749 else if (strcmp(ti->data, "off") == 0)
2752 fprintf(stderr, "Illegal argument %s\n", ti->data);
2756 if ((ti = as->parms[5].items)) { /* -clipags */
2757 if (strcmp(ti->data, "on") == 0)
2759 else if (strcmp(ti->data, "off") == 0)
2762 fprintf(stderr, "Illegal argument %s\n", ti->data);
2766 if ((ti = as->parms[6].items)) { /* -pagcb */
2767 if (strcmp(ti->data, "on") == 0)
2769 else if (strcmp(ti->data, "off") == 0)
2772 fprintf(stderr, "Illegal argument %s\n", ti->data);
2777 (type << 24) | (pagcb << 10) | (clipags << 8) |
2778 (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2781 blob.in = (char *)&exportcall;
2782 blob.in_size = sizeof(afs_int32);
2783 blob.out = (char *)&exportcall;
2784 blob.out_size = sizeof(afs_int32);
2785 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2787 if (errno == ENODEV) {
2789 "Sorry, the %s-exporter type is currently not supported on this AFS client\n",
2790 exported_types[type]);
2797 if (exportcall & 1) {
2798 printf("'%s' translator is enabled with the following options:\n",
2799 exported_types[type]);
2800 printf("\tRunning in %s mode\n",
2801 (exportcall & 2 ? "strict unix" :
2802 "convert owner mode bits to world/other"));
2803 printf("\tRunning in %s mode\n",
2804 (exportcall & 4 ? "strict 'passwd sync'" :
2805 "no 'passwd sync'"));
2807 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
2808 "Only mounts to /afs allowed"));
2810 (exportcall & 16 ? "Client-assigned PAG's are used" :
2811 "Client-assigned PAG's are not used"));
2814 "Callbacks are made to get creds from new clients" :
2815 "Callbacks are not made to get creds from new clients"));
2817 printf("'%s' translator is disabled\n", exported_types[type]);
2824 GetCellCmd(struct cmd_syndesc *as, void *arock)
2827 struct ViceIoctl blob;
2828 struct afsconf_cell info;
2829 struct cmd_item *ti;
2836 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2837 for (ti = as->parms[0].items; ti; ti = ti->next) {
2839 blob.out_size = sizeof(args);
2840 blob.out = (caddr_t) & args;
2841 code = GetCellName(ti->data, &info);
2846 blob.in_size = 1 + strlen(info.name);
2847 blob.in = info.name;
2848 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2850 if (errno == ENOENT)
2851 fprintf(stderr, "%s: the cell named '%s' does not exist\n",
2854 Die(errno, info.name);
2858 printf("Cell %s status: ", info.name);
2864 printf("no setuid allowed");
2866 printf("setuid allowed");
2868 printf(", using old VLDB");
2875 SetCellCmd(struct cmd_syndesc *as, void *arock)
2878 struct ViceIoctl blob;
2879 struct afsconf_cell info;
2880 struct cmd_item *ti;
2888 /* Check arguments. */
2889 if (as->parms[1].items && as->parms[2].items) {
2890 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2894 /* figure stuff to set */
2898 if (!as->parms[1].items)
2899 args.stat |= 2; /* default to -nosuid */
2901 /* set stat for all listed cells */
2902 for (ti = as->parms[0].items; ti; ti = ti->next) {
2904 code = GetCellName(ti->data, &info);
2909 strcpy(args.cname, info.name);
2910 blob.in_size = sizeof(args);
2911 blob.in = (caddr_t) & args;
2913 blob.out = (caddr_t) 0;
2914 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2916 Die(errno, info.name); /* XXX added cell name to Die() call */
2924 GetCellName(char *cellName, struct afsconf_cell *info)
2926 struct afsconf_dir *tdir;
2929 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2932 "Could not process files in configuration directory (%s).\n",
2933 AFSDIR_CLIENT_ETC_DIRPATH);
2937 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2939 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2940 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
2949 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
2953 code = ugen_ClientInit(noAuthFlag, (char *) AFSDIR_CLIENT_ETC_DIRPATH,
2954 info->name, 0, &uclient,
2955 NULL, pn, rxkad_clear,
2956 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
2957 0, 0, USER_SERVICE_ID);
2962 static struct ViceIoctl gblob;
2963 static int debug = 0;
2965 * here follow some routines in suport of the setserverprefs and
2966 * getserverprefs commands. They are:
2967 * SetPrefCmd "top-level" routine
2968 * addServer adds a server to the list of servers to be poked into the
2969 * kernel. Will poke the list into the kernel if it threatens
2971 * pokeServers pokes the existing list of servers and ranks into the kernel
2972 * GetPrefCmd reads the Cache Manager's current list of server ranks
2976 * returns -1 if error message printed,
2978 * errno value if error and no error message printed
2985 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2986 if (code && (errno == EINVAL)) {
2987 struct setspref *ssp;
2988 ssp = (struct setspref *)gblob.in;
2989 if (!(ssp->flags & DBservers)) {
2990 gblob.in = (void *)&(ssp->servers[0]);
2991 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
2992 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
2993 return code ? errno : 0;
2996 "This cache manager does not support VL server preferences.\n");
3000 return code ? errno : 0;
3004 * returns -1 if error message printed,
3006 * errno value if error and no error message printed
3009 addServer(char *name, afs_int32 rank)
3012 struct setspref *ssp;
3014 struct hostent *thostent;
3019 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3021 #define MAXUSHORT ((unsigned short) ~0)
3025 thostent = hostutil_GetHostByName(name);
3027 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3031 ssp = (struct setspref *)(gblob.in);
3033 for (t = 0; thostent->h_addr_list[t]; t++) {
3034 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3035 code = pokeServers();
3038 ssp->num_servers = 0;
3041 sp = (struct spref *)(gblob.in + gblob.in_size);
3042 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3043 sizeof(afs_uint32));
3044 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3045 gblob.in_size += sizeof(struct spref);
3049 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3050 name, sp->rank, (long unsigned int) sp->server.s_addr);
3058 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3062 struct cmd_item *ti;
3065 struct setspref *ssp;
3066 int error = 0; /* -1 means error message printed,
3067 * >0 means errno value for unprinted message */
3069 ssp = (struct setspref *)space;
3071 ssp->num_servers = 0;
3072 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3075 gblob.out_size = AFS_PIOCTL_MAXSIZE;
3079 fprintf(stderr, "Permission denied: requires root access.\n");
3083 ti = as->parms[2].items; /* -file */
3086 fprintf(stderr, "opening file %s\n", ti->data);
3087 if (!(infd = fopen(ti->data, "r"))) {
3091 while (fscanf(infd, "%79s%ld", name, (long int *)&rank) != EOF) {
3092 code = addServer(name, (unsigned short)rank);
3099 ti = as->parms[3].items; /* -stdin */
3101 while (scanf("%79s%ld", name, (long int *)&rank) != EOF) {
3102 code = addServer(name, (unsigned short)rank);
3108 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3113 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3117 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3121 code = pokeServers();
3125 printf("now working on vlservers, code=%d\n", code);
3127 ssp = (struct setspref *)space;
3128 ssp->flags = DBservers;
3129 ssp->num_servers = 0;
3130 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3133 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3138 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3142 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3147 if (as->parms[1].items) {
3149 printf("now poking vlservers\n");
3150 code = pokeServers();
3158 return error ? 1 : 0;
3164 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3167 struct cmd_item *ti;
3168 char *name, tbuffer[20];
3173 struct ViceIoctl blob;
3174 struct sprefrequest *in;
3175 struct sprefinfo *out;
3178 ti = as->parms[0].items; /* -file */
3181 fprintf(stderr, "opening file %s\n", ti->data);
3182 if (!(outfd = freopen(ti->data, "w", stdout))) {
3188 ti = as->parms[1].items; /* -numeric */
3190 ti = as->parms[2].items; /* -vlservers */
3191 vlservers |= (ti ? DBservers : 0);
3192 /* ti = as->parms[3].items; -cell */
3194 in = (struct sprefrequest *)space;
3198 blob.in_size = sizeof(struct sprefrequest);
3199 blob.in = (char *)in;
3201 blob.out_size = AFS_PIOCTL_MAXSIZE;
3204 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3205 in->flags = vlservers;
3207 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3209 perror("getserverprefs pioctl");
3213 out = (struct sprefinfo *)blob.out;
3215 for (i = 0; i < out->num_servers; i++) {
3217 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3219 addr = ntohl(out->servers[i].server.s_addr);
3220 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3221 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3224 printf("%-50s %5u\n", name, out->servers[i].rank);
3227 in->offset = out->next_offset;
3228 } while (out->next_offset > 0);
3234 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
3237 struct ViceIoctl blob;
3238 struct cmd_item *ti;
3239 struct sbstruct tsb, tsb2;
3245 tsb.sb_thisfile = -1;
3246 ti = as->parms[0].items; /* -kbytes */
3248 if (!as->parms[1].items) {
3249 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3253 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3254 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3255 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3261 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3262 ti = as->parms[2].items; /* -allfiles */
3264 allfiles = strtol(ti->data, &t, 10) * 1024;
3265 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3266 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3272 /* -verbose or -file only or no options */
3273 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3274 || (!as->parms[0].items && !as->parms[1].items
3275 && !as->parms[2].items))
3278 blob.in = (char *)&tsb;
3279 blob.in_size = sizeof(struct sbstruct);
3281 /* once per -file */
3282 for (ti = as->parms[1].items; ti; ti = ti->next) {
3283 /* Do this solely to see if the file is there */
3286 blob.out_size = AFS_PIOCTL_MAXSIZE;
3287 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3289 Die(errno, ti->data);
3294 memset(&tsb2, 0, sizeof(tsb2));
3295 blob.out = (char *)&tsb2;
3296 blob.out_size = sizeof(struct sbstruct);
3297 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
3299 Die(errno, ti->data);
3304 if (verbose && (blob.out_size == sizeof(tsb2))) {
3305 if (tsb2.sb_thisfile == -1) {
3306 fprintf(stdout, "Will store %s according to default.\n",
3310 "Will store up to %d kbytes of %s asynchronously.\n",
3311 (tsb2.sb_thisfile / 1024), ti->data);
3316 /* If no files - make at least one pioctl call, or
3317 * set the allfiles default if we need to.
3319 if (!as->parms[1].items || (allfiles != -1)) {
3320 tsb.sb_default = allfiles;
3321 memset(&tsb2, 0, sizeof(tsb2));
3322 blob.out = (char *)&tsb2;
3323 blob.out_size = sizeof(struct sbstruct);
3324 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
3326 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3331 /* Having no arguments also reports the default store asynchrony */
3332 if (verbose && (blob.out_size == sizeof(tsb2))) {
3333 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3334 (tsb2.sb_default / 1024));
3342 SetCryptCmd(struct cmd_syndesc *as, void *arock)
3344 afs_int32 code = 0, flag;
3345 struct ViceIoctl blob;
3348 tp = as->parms[0].items->data;
3349 if (strcmp(tp, "on") == 0)
3351 else if (strcmp(tp, "off") == 0)
3354 fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3358 blob.in = (char *)&flag;
3359 blob.in_size = sizeof(flag);
3361 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3369 GetCryptCmd(struct cmd_syndesc *as, void *arock)
3371 afs_int32 code = 0, flag;
3372 struct ViceIoctl blob;
3377 blob.out_size = sizeof(flag);
3380 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3386 memcpy(&flag, tp, sizeof(afs_int32));
3387 printf("Security level is currently ");
3389 printf("crypt (data security).\n");
3396 #ifdef AFS_DISCON_ENV
3397 static char *modenames[] = {
3400 "readonly", /* Not currently supported */
3401 "fetchonly", /* Not currently supported */
3402 "partial", /* Not currently supported */
3406 static char *policynames[] = {
3409 "closer", /* Not currently supported. */
3410 "manual", /* Not currently supported. */
3415 DisconCmd(struct cmd_syndesc *as, void *arock)
3417 struct cmd_item *ti;
3420 int modelen, policylen;
3421 afs_int32 mode, policy, code;
3422 struct ViceIoctl blob;
3427 space[0] = space[1] = space[2] = 0;
3429 ti = as->parms[0].items;
3431 modename = ti->data;
3432 modelen = strlen(modename);
3433 for (mode = 0; modenames[mode] != NULL; mode++)
3434 if (!strncasecmp(modename, modenames[mode], modelen))
3436 if (modenames[mode] == NULL)
3437 printf("Unknown discon mode \"%s\"\n", modename);
3439 space[0] = mode + 1;
3442 ti = as->parms[1].items;
3444 policyname = ti->data;
3445 policylen = strlen(policyname);
3446 for (policy = 0; policynames[policy] != NULL; policy++)
3447 if (!strncasecmp(policyname, policynames[policy], policylen))
3449 if (policynames[policy] == NULL)
3450 printf("Unknown discon mode \"%s\"\n", policyname);
3452 space[1] = policy + 1;
3456 if (as->parms[2].items) {
3458 printf("force on\n");
3462 blob.in_size = 3 * sizeof(afs_int32);
3464 blob.out_size = sizeof(mode);
3466 code = pioctl(0, VIOC_DISCON, &blob, 1);
3470 memcpy(&mode, space, sizeof mode);
3471 if (mode < sizeof modenames / sizeof (char *))
3472 printf("Discon mode is now \"%s\"\n", modenames[mode]);
3474 printf("Unknown discon mode %d\n", mode);
3481 #include "AFS_component_version_number.c"
3484 main(int argc, char **argv)
3487 struct cmd_syndesc *ts;
3489 #ifdef AFS_AIX32_ENV
3491 * The following signal action for AIX is necessary so that in case of a
3492 * crash (i.e. core is generated) we can include the user's data section
3493 * in the core dump. Unfortunately, by default, only a partial core is
3494 * generated which, in many cases, isn't too useful.
3496 struct sigaction nsa;
3498 sigemptyset(&nsa.sa_mask);
3499 nsa.sa_handler = SIG_DFL;
3500 nsa.sa_flags = SA_FULLDUMP;
3501 sigaction(SIGSEGV, &nsa, NULL);
3504 /* try to find volume location information */
3505 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
3506 "get client network interface addresses");
3507 cmd_CreateAlias(ts, "gc");
3509 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
3510 "set client network interface addresses");
3511 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3512 "client network interfaces");
3513 cmd_CreateAlias(ts, "sc");
3515 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL,
3516 "set server ranks");
3517 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3518 "fileserver names and ranks");
3519 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3520 "VL server names and ranks");
3521 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3522 "input from named file");
3523 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3524 cmd_CreateAlias(ts, "sp");
3526 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL,
3527 "get server ranks");
3528 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3529 "output to named file");
3530 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3531 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3532 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3533 cmd_CreateAlias(ts, "gp");
3535 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
3536 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3537 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3538 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3539 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL,
3540 "apply to negative rights");
3541 parm_setacl_id = ts->nParms;
3542 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL,
3543 "initial directory acl (DFS only)");
3544 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL,
3545 "initial file acl (DFS only)");
3546 cmd_CreateAlias(ts, "sa");
3548 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL,
3549 "list access control list");
3550 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3551 parm_listacl_id = ts->nParms;
3552 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3553 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3554 cmd_AddParm(ts, "-cmd", CMD_FLAG, CMD_OPTIONAL, "output as 'fs setacl' command");
3555 cmd_CreateAlias(ts, "la");
3557 ts = cmd_CreateSyntax("getcalleraccess", GetCallerAccess, NULL,
3558 "list callers access");
3559 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3560 cmd_CreateAlias(ts, "gca");
3562 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL,
3563 "clean up access control list");
3564 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3566 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL,
3567 "copy access control list");
3568 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0,
3569 "source directory (or DFS file)");
3570 cmd_AddParm(ts, "-todir", CMD_LIST, 0,
3571 "destination directory (or DFS file)");
3572 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3573 "first clear dest access list");
3574 parm_copyacl_id = ts->nParms;
3575 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3576 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3578 cmd_CreateAlias(ts, "ca");
3580 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
3581 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3582 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
3583 "flush mount symlink from cache");
3584 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3586 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
3587 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3588 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL,
3589 "disk space quota in 1K units");
3591 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL,
3592 "disk space guaranteed");
3593 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3595 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL,
3597 cmd_CreateAlias(ts, "sv");
3599 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL,
3600 "control Cache Manager messages");
3601 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL,
3602 "[user|console|all|none]");
3604 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
3605 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3606 cmd_CreateAlias(ts, "lv");
3607 cmd_CreateAlias(ts, "listvol");
3609 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
3610 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3611 cmd_CreateAlias(ts, "lq");
3613 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL,
3614 "show server disk space usage");
3615 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3616 cmd_CreateAlias(ts, "df");
3618 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
3619 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3621 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
3622 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3624 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
3625 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3626 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3627 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3628 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3629 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3630 "don't check name with VLDB");
3632 #if defined(AFS_CACHE_BYPASS)
3633 ts = cmd_CreateSyntax("bypassthreshold", BypassThresholdCmd, 0,
3634 "get/set cache bypass file size threshold");
3635 cmd_AddParm(ts, "-size", CMD_SINGLE, CMD_OPTIONAL, "file size");
3642 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3646 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
3647 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3649 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL,
3650 "check local cell's servers");
3651 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3652 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3653 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3654 "just list, don't check");
3655 cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL,
3656 "seconds between probes");
3658 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL,
3659 "check volumeID/name mappings");
3660 cmd_CreateAlias(ts, "checkbackups");
3663 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL,
3665 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3666 "size in 1K byte blocks (0 => reset)");
3667 cmd_CreateAlias(ts, "cachesize");
3669 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL,
3670 "reset size back to boot value");
3672 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL,
3673 "get cache usage info");
3674 cmd_AddParm(ts, "-files", CMD_FLAG, CMD_OPTIONAL, "Show cach files used as well");
3675 cmd_AddParm(ts, "-excessive", CMD_FLAG, CMD_OPTIONAL, "excessively verbose cache stats");
3677 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL,
3678 "list configured cells");
3679 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3681 ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, NULL,
3682 "list configured cell aliases");
3684 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
3685 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3686 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3688 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3690 cmd_CreateAlias(ts, "sq");
3692 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
3693 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3694 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3695 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL,
3696 "linked cell name");
3698 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
3699 "configure new cell alias");
3700 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
3701 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
3703 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3705 * Turn this on only if you wish to be able to talk to a server which is listening
3706 * on alternative ports. This is not intended for general use and may not be
3707 * supported in the cache manager. It is not a way to run two servers at the
3708 * same host, since the cache manager cannot properly distinguish those two hosts.
3710 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL,
3711 "cell's fileserver port");
3712 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL,
3713 "cell's vldb server port");
3716 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
3717 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3719 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
3720 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3722 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
3725 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, NULL, "obsolete (listed primary cell)");
3728 /* set cache monitor host address */
3729 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, (char *)CMD_HIDDEN);
3730 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL,
3731 "host name or 'off'");
3732 cmd_CreateAlias(ts, "mariner");
3734 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
3735 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3737 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
3738 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3739 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3740 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL,
3741 "disallow setuid programs");
3743 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL,
3744 "flush all data in volume");
3745 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3747 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL,
3748 "get/set sysname (i.e. @sys) value");
3749 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3751 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL,
3752 "enable/disable translators to AFS");
3753 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3754 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL,
3755 "start/stop translator (on | off)");
3756 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL,
3757 "convert from afs to unix mode (on | off)");
3758 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL,
3759 "run on strict 'uid check' mode (on | off)");
3760 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
3761 "allow nfs mounts to subdirs of /afs/.. (on | off)");
3762 cmd_AddParm(ts, "-clipags", CMD_SINGLE, CMD_OPTIONAL,
3763 "enable use of client-assigned PAG's (on | off)");
3764 cmd_AddParm(ts, "-pagcb", CMD_SINGLE, CMD_OPTIONAL,
3765 "enable callbacks to get creds from new clients (on | off)");
3768 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
3769 "store to server after file close");
3770 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL,
3771 "asynchrony for specified names");
3772 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3773 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL,
3774 "new default (KB)");
3775 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3776 cmd_CreateAlias(ts, "sb");
3778 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL,
3779 "set cache manager encryption flag");
3780 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3782 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL,
3783 "get cache manager encryption flag");
3785 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
3786 "Manage per process RX statistics");
3787 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3788 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3789 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3791 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
3792 "Manage per peer RX statistics");
3793 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3794 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3795 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3797 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
3798 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
3800 /* try to find volume location information */
3801 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL,
3802 "get fid for file(s)");
3803 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3805 #ifdef AFS_DISCON_ENV
3806 ts = cmd_CreateSyntax("discon", DisconCmd, NULL,
3807 "disconnection mode");
3808 cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_REQUIRED, "offline | online");
3809 cmd_AddParm(ts, "-policy", CMD_SINGLE, CMD_OPTIONAL, "client | server");
3810 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Force reconnection, despite any synchronization issues.");
3813 ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, NULL, "nuke credentials for NFS client");
3814 cmd_AddParm(ts, "-addr", CMD_SINGLE, 0, "host name or address");
3816 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
3817 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_REQUIRED, "generate a new UUID");
3819 ts = cmd_CreateSyntax("precache", PreCacheCmd, 0,
3820 "set precache size");
3821 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3822 "size in 1K byte blocks (0 => disable)");
3824 code = cmd_Dispatch(argc, argv);
3832 Die(int errnum, char *filename)
3838 "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3841 fprintf(stderr, "%s: Invalid argument.\n", pn);
3845 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3847 fprintf(stderr, "%s: no such file returned\n", pn);
3851 "%s: You can not change a backup or readonly volume\n", pn);
3857 "%s: You don't have the required access rights on '%s'\n",
3861 "%s: You do not have the required rights to do this operation\n",
3866 fprintf(stderr, "%s:'%s'", pn, filename);
3868 fprintf(stderr, "%s", pn);
3869 fprintf(stderr, ": %s\n", afs_error_message(errnum));
3874 /* get clients interface addresses */
3876 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3879 struct ViceIoctl blob;
3880 struct sprefrequest *in;
3881 struct sprefinfo *out;
3883 in = (struct sprefrequest *)space;
3887 blob.in_size = sizeof(struct sprefrequest);
3888 blob.in = (char *)in;
3890 blob.out_size = AFS_PIOCTL_MAXSIZE;
3893 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3894 /* returns addr in network byte order */
3895 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3897 perror("getClientInterfaceAddr pioctl");
3903 out = (struct sprefinfo *)blob.out;
3904 for (i = 0; i < out->num_servers; i++) {
3907 addr = ntohl(out->servers[i].server.s_addr);
3908 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3909 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3910 printf("%-50s\n", tbuffer);
3912 in->offset = out->next_offset;
3914 } while (out->next_offset > 0);
3920 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3922 afs_int32 code, addr;
3923 struct cmd_item *ti;
3924 struct ViceIoctl blob;
3925 struct setspref *ssp;
3926 int sizeUsed = 0, i, flag;
3927 afs_uint32 existingAddr[1024]; /* existing addresses on this host */
3931 ssp = (struct setspref *)space;
3932 ssp->num_servers = 0;
3935 blob.out_size = AFS_PIOCTL_MAXSIZE;
3938 fprintf(stderr, "Permission denied: requires root access.\n");
3942 /* extract all existing interface addresses */
3943 existNu = rx_getAllAddr(existingAddr, 1024);
3947 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
3948 for (ti = as->parms[0].items; ti; ti = ti->next) {
3949 if (sizeUsed >= sizeof(space)) {
3950 fprintf(stderr, "No more space\n");
3953 addr = extractAddr(ti->data, 20); /* network order */
3954 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
3955 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
3960 /* see if it is an address that really exists */
3961 for (flag = 0, i = 0; i < existNu; i++)
3962 if (existingAddr[i] == addr) {
3966 if (!flag) { /* this is an nonexistent address */
3967 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
3971 /* copy all specified addr into ioctl buffer */
3972 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
3973 printf("Adding 0x%08x\n", addr);
3975 sizeUsed += sizeof(struct spref);
3977 if (ssp->num_servers < 1) {
3978 fprintf(stderr, "No addresses specified\n");
3981 blob.in_size = sizeUsed - sizeof(struct spref);
3983 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
3993 FlushMountCmd(struct cmd_syndesc *as, void *arock)
3996 struct ViceIoctl blob;
3997 struct cmd_item *ti;
3998 char orig_name[1024]; /*Original name, may be modified */
3999 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
4000 char parent_dir[1024]; /*Parent directory of true name */
4001 char *last_component; /*Last component of true name */
4002 struct stat statbuff; /*Buffer for status info */
4003 int link_chars_read; /*Num chars read in readlink() */
4004 int thru_symlink; /*Did we get to a mount point via a symlink? */
4007 for (ti = as->parms[0].items; ti; ti = ti->next) {
4010 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
4013 if (lstat(orig_name, &statbuff) < 0) {
4014 /* if lstat fails, we should still try the pioctl, since it
4015 * may work (for example, lstat will fail, but pioctl will
4016 * work if the volume of offline (returning ENODEV). */
4017 statbuff.st_mode = S_IFDIR; /* lie like pros */
4021 * The lstat succeeded. If the given file is a symlink, substitute
4022 * the file name with the link name.
4024 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
4027 * Read name of resolved file.
4029 link_chars_read = readlink(orig_name, true_name, 1024);
4030 if (link_chars_read <= 0) {
4032 "%s: Can't read target name for '%s' symbolic link!\n",
4039 * Add a trailing null to what was read, bump the length.
4041 true_name[link_chars_read++] = 0;
4044 * If the symlink is an absolute pathname, we're fine. Otherwise, we
4045 * have to create a full pathname using the original name and the
4046 * relative symlink name. Find the rightmost slash in the original
4047 * name (we know there is one) and splice in the symlink value.
4049 if (true_name[0] != '/') {
4050 last_component = (char *)strrchr(orig_name, '/');
4051 strcpy(++last_component, true_name);
4052 strcpy(true_name, orig_name);
4055 strcpy(true_name, orig_name);
4058 * Find rightmost slash, if any.
4060 last_component = (char *)strrchr(true_name, '/');
4061 if (last_component == (char *)true_name) {
4062 strcpy(parent_dir, "/");
4065 else if (last_component != (char *)NULL) {
4067 * Found it. Designate everything before it as the parent directory,
4068 * everything after it as the final component.
4070 strncpy(parent_dir, true_name, last_component - true_name);
4071 parent_dir[last_component - true_name] = 0;
4072 last_component++; /*Skip the slash */
4075 * No slash appears in the given file name. Set parent_dir to the current
4076 * directory, and the last component as the given name.
4078 strcpy(parent_dir, ".");
4079 last_component = true_name;
4082 if (strcmp(last_component, ".") == 0
4083 || strcmp(last_component, "..") == 0) {
4085 "%s: you may not use '.' or '..' as the last component\n",
4087 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
4093 blob.in = last_component;
4094 blob.in_size = strlen(last_component) + 1;
4096 memset(space, 0, AFS_PIOCTL_MAXSIZE);
4098 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4101 if (errno == EINVAL) {
4102 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4104 Die(errno, (ti->data ? ti->data : parent_dir));
4113 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4116 afs_int32 flags = 0;
4117 struct ViceIoctl blob;
4119 if (as->parms[0].items) { /* -enable */
4120 flags |= AFSCALL_RXSTATS_ENABLE;
4122 if (as->parms[1].items) { /* -disable */
4123 flags |= AFSCALL_RXSTATS_DISABLE;
4125 if (as->parms[2].items) { /* -clear */
4126 flags |= AFSCALL_RXSTATS_CLEAR;
4129 fprintf(stderr, "You must specify at least one argument\n");
4133 blob.in = (char *)&flags;
4134 blob.in_size = sizeof(afs_int32);
4137 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4147 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4150 afs_int32 flags = 0;
4151 struct ViceIoctl blob;
4153 if (as->parms[0].items) { /* -enable */
4154 flags |= AFSCALL_RXSTATS_ENABLE;
4156 if (as->parms[1].items) { /* -disable */
4157 flags |= AFSCALL_RXSTATS_DISABLE;
4159 if (as->parms[2].items) { /* -clear */
4160 flags |= AFSCALL_RXSTATS_CLEAR;
4163 fprintf(stderr, "You must specify at least one argument\n");
4167 blob.in = (char *)&flags;
4168 blob.in_size = sizeof(afs_int32);
4171 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4181 GetFidCmd(struct cmd_syndesc *as, void *arock)
4183 struct ViceIoctl blob;
4184 struct cmd_item *ti;
4185 for (ti = as->parms[0].items; ti; ti = ti->next) {
4186 struct VenusFid vfid;
4188 blob.out_size = sizeof(struct VenusFid);
4189 blob.out = (char *) &vfid;
4192 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
4193 printf("File %s (%u.%u.%u) contained in volume %u\n",
4194 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,