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>
18 #include <afs/afs_consts.h>
19 #include <afs/afs_args.h>
22 #include <afs/venus.h>
23 #include <afs/com_err.h>
24 #include <afs/afs_consts.h>
28 #include "afs/prs_fs.h"
29 #include <afs/afsint.h>
30 #include <afs/cellconfig.h>
33 #include <rx/rx_globals.h>
34 #include <afs/vldbint.h>
35 #include <afs/volser.h>
36 #include <afs/vlserver.h>
38 #include <afs/com_err.h>
39 #include <afs/ptclient.h>
40 #include <afs/ptuser.h>
41 #include <afs/afsutil.h>
42 #include <afs/sys_prototypes.h>
45 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
46 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
48 static char space[AFS_PIOCTL_MAXSIZE];
49 static char tspace[1024];
50 static struct ubik_client *uclient;
52 static int GetClientAddrsCmd(struct cmd_syndesc *, void *);
53 static int SetClientAddrsCmd(struct cmd_syndesc *, void *);
54 static int FlushMountCmd(struct cmd_syndesc *, void *);
55 static int RxStatProcCmd(struct cmd_syndesc *, void *);
56 static int RxStatPeerCmd(struct cmd_syndesc *, void *);
57 static int GetFidCmd(struct cmd_syndesc *, void *);
58 static int UuidCmd(struct cmd_syndesc *, void *);
60 static char pn[] = "fs";
61 static int rxInitDone = 0;
65 static void ZapList(struct AclEntry *);
66 static int PruneList(struct AclEntry **, int);
67 static int CleanAcl(struct Acl *, char *);
68 static int SetVolCmd(struct cmd_syndesc *as, void *arock);
69 static int GetCellName(char *, struct afsconf_cell *);
70 static int VLDBInit(int, struct afsconf_cell *);
71 static void Die(int, char *);
74 * Character to use between name and rights in printed representation for
77 #define DFS_SEPARATOR ' '
79 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
82 int dfs; /* Originally true if a dfs acl; now also the type
83 * of the acl (1, 2, or 3, corresponding to object,
84 * initial dir, or initial object). */
85 sec_rgy_name_t cell; /* DFS cell name */
88 struct AclEntry *pluslist;
89 struct AclEntry *minuslist;
93 struct AclEntry *next;
99 afs_int32 callerAccess;
106 ZapAcl(struct Acl *acl)
110 ZapList(acl->pluslist);
111 ZapList(acl->minuslist);
116 foldcmp(char *a, char *b)
122 if (t >= 'A' && t <= 'Z')
124 if (u >= 'A' && u <= 'Z')
134 * Mods for the AFS/DFS protocol translator.
136 * DFS rights. It's ugly to put these definitions here, but they
137 * *cannot* change, because they're part of the wire protocol.
138 * In any event, the protocol translator will guarantee these
139 * assignments for AFS cache managers.
141 #define DFS_READ 0x01
142 #define DFS_WRITE 0x02
143 #define DFS_EXECUTE 0x04
144 #define DFS_CONTROL 0x08
145 #define DFS_INSERT 0x10
146 #define DFS_DELETE 0x20
148 /* the application definable ones (backwards from AFS) */
149 #define DFS_USR0 0x80000000 /* "A" bit */
150 #define DFS_USR1 0x40000000 /* "B" bit */
151 #define DFS_USR2 0x20000000 /* "C" bit */
152 #define DFS_USR3 0x10000000 /* "D" bit */
153 #define DFS_USR4 0x08000000 /* "E" bit */
154 #define DFS_USR5 0x04000000 /* "F" bit */
155 #define DFS_USR6 0x02000000 /* "G" bit */
156 #define DFS_USR7 0x01000000 /* "H" bit */
157 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
158 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
161 * Offset of -id switch in command structure for various commands.
162 * The -if switch is the next switch always.
164 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
167 * Determine whether either the -id or -if switches are present, and
168 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
170 /* int id; Offset of -id switch; -if is next switch */
172 getidf(struct cmd_syndesc *as, int id)
176 if (as->parms[id].items) {
179 if (as->parms[id + 1].items) {
184 "%s: you may specify either -id or -if, but not both switches\n",
192 PRights(afs_int32 arights, int dfs)
195 if (arights & PRSFS_READ)
197 if (arights & PRSFS_LOOKUP)
199 if (arights & PRSFS_INSERT)
201 if (arights & PRSFS_DELETE)
203 if (arights & PRSFS_WRITE)
205 if (arights & PRSFS_LOCK)
207 if (arights & PRSFS_ADMINISTER)
209 if (arights & PRSFS_USR0)
211 if (arights & PRSFS_USR1)
213 if (arights & PRSFS_USR2)
215 if (arights & PRSFS_USR3)
217 if (arights & PRSFS_USR4)
219 if (arights & PRSFS_USR5)
221 if (arights & PRSFS_USR6)
223 if (arights & PRSFS_USR7)
226 if (arights & DFS_READ)
230 if (arights & DFS_WRITE)
234 if (arights & DFS_EXECUTE)
238 if (arights & DFS_CONTROL)
242 if (arights & DFS_INSERT)
246 if (arights & DFS_DELETE)
250 if (arights & (DFS_USRALL))
252 if (arights & DFS_USR0)
254 if (arights & DFS_USR1)
256 if (arights & DFS_USR2)
258 if (arights & DFS_USR3)
260 if (arights & DFS_USR4)
262 if (arights & DFS_USR5)
264 if (arights & DFS_USR6)
266 if (arights & DFS_USR7)
272 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
276 struct ViceIoctl blob;
280 blob.out_size = AFS_PIOCTL_MAXSIZE;
283 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
285 if ((errno == EINVAL) || (errno == ENOENT))
291 /* return a static pointer to a buffer */
296 strlcpy(tspace, apath, sizeof(tspace));
297 tp = strrchr(tspace, '/');
298 if (tp == (char *)tspace)
300 else if (tp == (char *)NULL) {
308 enum rtype { add, destroy, deny };
311 Convert(char *arights, int dfs, enum rtype *rtypep)
317 *rtypep = add; /* add rights, by default */
320 if (!strcmp(arights, "null")) {
324 if (!strcmp(arights, "read"))
325 return DFS_READ | DFS_EXECUTE;
326 if (!strcmp(arights, "write"))
327 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
329 if (!strcmp(arights, "all"))
330 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
331 DFS_WRITE | DFS_CONTROL;
333 if (!strcmp(arights, "read"))
334 return PRSFS_READ | PRSFS_LOOKUP;
335 if (!strcmp(arights, "write"))
336 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
337 PRSFS_WRITE | PRSFS_LOCK;
338 if (!strcmp(arights, "mail"))
339 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
340 if (!strcmp(arights, "all"))
341 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
342 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
344 if (!strcmp(arights, "none")) {
345 *rtypep = destroy; /* Remove entire entry */
348 len = strlen(arights);
350 for (i = 0; i < len; i++) {
384 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
392 mode |= PRSFS_LOOKUP;
394 mode |= PRSFS_INSERT;
396 mode |= PRSFS_DELETE;
402 mode |= PRSFS_ADMINISTER;
420 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
429 static struct AclEntry *
430 FindList(struct AclEntry *alist, char *aname)
433 if (!foldcmp(alist->name, aname))
440 /* if no parm specified in a particular slot, set parm to be "." instead */
442 SetDotDefault(struct cmd_item **aitemp)
446 return; /* already has value */
447 /* otherwise, allocate an item representing "." */
448 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
450 ti->next = (struct cmd_item *)0;
451 ti->data = (char *)malloc(2);
453 strcpy(ti->data, ".");
458 ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
460 struct AclEntry *tlist;
461 tlist = (plus ? al->pluslist : al->minuslist);
462 tlist = FindList(tlist, aname);
464 /* Found the item already in the list. */
465 tlist->rights = arights;
467 al->nplus -= PruneList(&al->pluslist, al->dfs);
469 al->nminus -= PruneList(&al->minuslist, al->dfs);
472 /* Otherwise we make a new item and plug in the new data. */
473 tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry));
475 strcpy(tlist->name, aname);
476 tlist->rights = arights;
478 tlist->next = al->pluslist;
479 al->pluslist = tlist;
481 if (arights == 0 || arights == -1)
482 al->nplus -= PruneList(&al->pluslist, al->dfs);
484 tlist->next = al->minuslist;
485 al->minuslist = tlist;
488 al->nminus -= PruneList(&al->minuslist, al->dfs);
493 ZapList(struct AclEntry *alist)
495 struct AclEntry *tp, *np;
496 for (tp = alist; tp; tp = np) {
503 PruneList(struct AclEntry **ae, int dfs)
505 struct AclEntry **lp;
506 struct AclEntry *te, *ne;
510 for (te = *ae; te; te = ne) {
511 if ((!dfs && te->rights == 0) || te->rights == -1) {
527 while (*astr != '\n')
534 * Create an empty acl, taking into account whether the acl pointed
535 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
536 * can recover from problems caused by bogus ACL's (in that case, always
537 * assume that the acl is AFS: for DFS, the user can always resort to
538 * acl_edit, but for AFS there may be no other way out).
546 tp = (struct Acl *)malloc(sizeof(struct Acl));
548 tp->nplus = tp->nminus = 0;
549 tp->pluslist = tp->minuslist = 0;
551 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
558 int nplus, nminus, i, trights;
560 struct AclEntry *first, *last, *tl;
563 ta = (struct Acl *)malloc(sizeof(struct Acl));
566 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
567 astr = SkipLine(astr);
568 sscanf(astr, "%d", &ta->nminus);
569 astr = SkipLine(astr);
576 for (i = 0; i < nplus; i++) {
577 sscanf(astr, "%100s %d", tname, &trights);
578 astr = SkipLine(astr);
579 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
583 strcpy(tl->name, tname);
584 tl->rights = trights;
590 ta->pluslist = first;
594 for (i = 0; i < nminus; i++) {
595 sscanf(astr, "%100s %d", tname, &trights);
596 astr = SkipLine(astr);
597 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
601 strcpy(tl->name, tname);
602 tl->rights = trights;
608 ta->minuslist = first;
614 PrintStatus(VolumeStatus * status, char *name, char *offmsg)
616 printf("Volume status for vid = %u named %s\n", status->Vid, name);
618 printf("Current offline message is %s\n", offmsg);
619 printf("Current disk quota is ");
620 if (status->MaxQuota != 0)
621 printf("%d\n", status->MaxQuota);
623 printf("unlimited\n");
624 printf("Current blocks used are %d\n", status->BlocksInUse);
625 printf("The partition has %d blocks available out of %d\n\n",
626 status->PartBlocksAvail, status->PartMaxBlocks);
630 static const char power_letter[] = {
639 HumanPrintSpace(afs_int32 int_space)
642 int exponent_max = sizeof(power_letter) - 1;
643 float space = int_space;
645 while (space >= 1024 && exponent < exponent_max) {
649 printf("%9.1f%c", space, power_letter[exponent]);
653 QuickPrintStatus(VolumeStatus * status, char *name, int human)
655 double QuotaUsed = 0.0;
656 double PartUsed = 0.0;
658 printf("%-25.25s", name);
660 if (status->MaxQuota != 0) {
663 HumanPrintSpace(status->MaxQuota);
665 HumanPrintSpace(status->BlocksInUse);
668 printf(" %10d %10d", status->MaxQuota, status->BlocksInUse);
670 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
672 printf(" no limit ");
674 HumanPrintSpace(status->BlocksInUse);
676 printf("%10d", status->BlocksInUse);
678 if (QuotaUsed > 90.0) {
679 printf("%5.0f%%<<", QuotaUsed);
682 printf("%5.0f%% ", QuotaUsed);
685 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
687 if (PartUsed > 97.0) {
688 printf("%9.0f%%<<", PartUsed);
691 printf("%9.0f%% ", PartUsed);
693 printf(" <<WARNING\n");
700 QuickPrintSpace(VolumeStatus * status, char *name, int human)
702 double PartUsed = 0.0;
704 printf("%-25.25s", name);
707 HumanPrintSpace(status->PartMaxBlocks);
708 HumanPrintSpace(status->PartMaxBlocks - status->PartBlocksAvail);
709 HumanPrintSpace(status->PartBlocksAvail);
712 printf("%10d%10d%10d", status->PartMaxBlocks,
713 status->PartMaxBlocks - status->PartBlocksAvail,
714 status->PartBlocksAvail);
718 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
720 if (PartUsed > 90.0) {
721 printf(" %4.0f%%<<", PartUsed);
724 printf(" %4.0f%% ", PartUsed);
726 printf(" <<WARNING\n");
733 AclToString(struct Acl *acl)
735 static char mydata[AFS_PIOCTL_MAXSIZE];
736 char tstring[AFS_PIOCTL_MAXSIZE];
741 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
744 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
745 for (tp = acl->pluslist; tp; tp = tp->next) {
746 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
747 strcat(mydata, tstring);
749 for (tp = acl->minuslist; tp; tp = tp->next) {
750 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
751 strcat(mydata, tstring);
757 SetACLCmd(struct cmd_syndesc *as, void *arock)
760 struct ViceIoctl blob;
762 struct cmd_item *ti, *ui;
766 int idf = getidf(as, parm_setacl_id);
769 if (as->parms[2].items)
773 plusp = !(as->parms[3].items);
774 for (ti = as->parms[0].items; ti; ti = ti->next) {
775 blob.out_size = AFS_PIOCTL_MAXSIZE;
777 blob.in = blob.out = space;
778 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
780 Die(errno, ti->data);
787 ta = ParseAcl(space);
788 if (!plusp && ta->dfs) {
790 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
792 "(you may specify \"null\" to revoke all rights, however)\n");
800 ta = EmptyAcl(space);
802 ta = ParseAcl(space);
803 CleanAcl(ta, ti->data);
804 for (ui = as->parms[1].items; ui; ui = ui->next->next) {
808 "%s: Missing second half of user/access pair.\n", pn);
812 rights = Convert(ui->next->data, ta->dfs, &rtype);
813 if (rtype == destroy && !ta->dfs) {
814 struct AclEntry *tlist;
816 tlist = (plusp ? ta->pluslist : ta->minuslist);
817 if (!FindList(tlist, ui->data))
820 if (rtype == deny && !ta->dfs)
822 if (rtype == destroy && ta->dfs)
824 ChangeList(ta, plusp, ui->data, rights);
826 blob.in = AclToString(ta);
828 blob.in_size = 1 + strlen(blob.in);
829 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
831 if (errno == EINVAL) {
833 static char *fsenv = 0;
835 fsenv = (char *)getenv("FS_EXPERT");
838 "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n",
842 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
843 "\nPossible reasons for this include:\n\n",
844 " -You may have specified an inappropriate combination of rights.\n",
845 " For example, some DFS-supported filesystems may not allow you to\n",
846 " drop the \"c\" right from \"user_obj\".\n\n",
847 " -A mask_obj may be required (it is likely required by the underlying\n",
848 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
849 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
850 " does not automatically create or update the mask_obj. Try setting\n",
851 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
852 " users or groups. You can do this with a single command, such as\n",
853 " \"fs sa mask_obj all user:somename read\"\n\n",
854 " -A specified user or group may not exist.\n\n",
855 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
856 " This is probably not allowed by the underlying file system.\n\n",
857 " -If you add a user or group to a DFS ACL, remember that it must be\n",
858 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
859 " may be local requirements on the format of the user or group name.\n",
860 " Check with your cell administrator.\n\n",
861 " -Or numerous other possibilities. It would be great if we could be more\n",
862 " precise about the actual problem, but for various reasons, this is\n",
863 " impractical via this interface. If you can't figure it out, you\n",
864 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
865 " whatever is provided). You may get better results. Good luck!\n\n",
866 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
870 "%s: Invalid argument, possible reasons include:\n",
872 fprintf(stderr, "\t-File not in AFS\n");
874 "\t-Too many users on access control list\n");
876 "\t-Tried to add non-existent user to access control list\n");
879 Die(errno, ti->data);
891 CopyACLCmd(struct cmd_syndesc *as, void *arock)
894 struct ViceIoctl blob;
895 struct Acl *fa, *ta = 0;
899 int idf = getidf(as, parm_copyacl_id);
902 if (as->parms[2].items)
906 blob.out_size = AFS_PIOCTL_MAXSIZE;
908 blob.in = blob.out = space;
909 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
911 Die(errno, as->parms[0].items->data);
914 fa = ParseAcl(space);
915 CleanAcl(fa, as->parms[0].items->data);
916 for (ti = as->parms[1].items; ti; ti = ti->next) {
917 blob.out_size = AFS_PIOCTL_MAXSIZE;
919 blob.in = blob.out = space;
920 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
922 Die(errno, ti->data);
930 ta = EmptyAcl(space);
932 ta = ParseAcl(space);
933 CleanAcl(ta, ti->data);
934 if (ta->dfs != fa->dfs) {
936 "%s: incompatible file system types: acl not copied to %s; aborted\n",
942 if (!clear && strcmp(ta->cell, fa->cell) != 0) {
944 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
949 strcpy(ta->cell, fa->cell);
951 for (tp = fa->pluslist; tp; tp = tp->next)
952 ChangeList(ta, 1, tp->name, tp->rights);
953 for (tp = fa->minuslist; tp; tp = tp->next)
954 ChangeList(ta, 0, tp->name, tp->rights);
955 blob.in = AclToString(ta);
957 blob.in_size = 1 + strlen(blob.in);
958 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
960 if (errno == EINVAL) {
962 "%s: Invalid argument, possible reasons include:\n",
964 fprintf(stderr, "\t-File not in AFS\n");
966 Die(errno, ti->data);
977 /* pioctl() call to get the cellname of a pathname */
979 GetCell(char *fname, char *cellname)
982 struct ViceIoctl blob;
985 blob.out_size = MAXCELLCHARS;
988 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
989 return code ? errno : 0;
992 /* Check if a username is valid: If it contains only digits (or a
993 * negative sign), then it might be bad. We then query the ptserver
997 BadName(char *aname, char *fname)
999 afs_int32 tc, code, id;
1001 char cell[MAXCELLCHARS];
1003 for (nm = aname; (tc = *nm); nm++) {
1004 /* all must be '-' or digit to be bad */
1005 if (tc != '-' && (tc < '0' || tc > '9'))
1009 /* Go to the PRDB and see if this all number username is valid */
1010 code = GetCell(fname, cell);
1014 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
1015 code = pr_SNameToId(aname, &id);
1018 /* 1=>Not-valid; 0=>Valid */
1019 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1023 /* clean up an access control list of its bad entries; return 1 if we made
1024 any changes to the list, and 0 otherwise */
1026 CleanAcl(struct Acl *aa, char *fname)
1028 struct AclEntry *te, **le, *ne;
1031 /* Don't correct DFS ACL's for now */
1035 /* prune out bad entries */
1036 changes = 0; /* count deleted entries */
1038 for (te = aa->pluslist; te; te = ne) {
1040 if (BadName(te->name, fname)) {
1050 le = &aa->minuslist;
1051 for (te = aa->minuslist; te; te = ne) {
1053 if (BadName(te->name, fname)) {
1067 /* clean up an acl to not have bogus entries */
1069 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1073 struct ViceIoctl blob;
1075 struct cmd_item *ti;
1076 struct AclEntry *te;
1079 SetDotDefault(&as->parms[0].items);
1080 for (ti = as->parms[0].items; ti; ti = ti->next) {
1081 blob.out_size = AFS_PIOCTL_MAXSIZE;
1084 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1086 Die(errno, ti->data);
1093 ta = ParseAcl(space);
1096 "%s: cleanacl is not supported for DFS access lists.\n",
1102 changes = CleanAcl(ta, ti->data);
1105 /* now set the acl */
1106 blob.in = AclToString(ta);
1107 blob.in_size = strlen(blob.in) + 1;
1109 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1111 if (errno == EINVAL) {
1113 "%s: Invalid argument, possible reasons include\n",
1115 fprintf(stderr, "%s: File not in vice or\n", pn);
1117 "%s: Too many users on access control list or\n",
1120 Die(errno, ti->data);
1126 /* now list the updated acl */
1127 printf("Access list for %s is now\n", ti->data);
1128 if (ta->nplus > 0) {
1130 printf("Normal rights:\n");
1131 for (te = ta->pluslist; te; te = te->next) {
1132 printf(" %s ", te->name);
1133 PRights(te->rights, ta->dfs);
1137 if (ta->nminus > 0) {
1138 printf("Negative rights:\n");
1139 for (te = ta->minuslist; te; te = te->next) {
1140 printf(" %s ", te->name);
1141 PRights(te->rights, ta->dfs);
1148 printf("Access list for %s is fine.\n", ti->data);
1156 ListACLCmd(struct cmd_syndesc *as, void *arock)
1160 struct ViceIoctl blob;
1161 struct AclEntry *te;
1162 struct cmd_item *ti;
1163 int idf = getidf(as, parm_listacl_id);
1166 SetDotDefault(&as->parms[0].items);
1167 for (ti = as->parms[0].items; ti; ti = ti->next) {
1168 blob.out_size = AFS_PIOCTL_MAXSIZE;
1170 blob.in = blob.out = space;
1171 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1173 Die(errno, ti->data);
1177 ta = ParseAcl(space);
1178 if (as->parms[3].items) { /* -cmd */
1179 printf("fs setacl -dir %s -acl ", ti->data);
1180 if (ta->nplus > 0) {
1181 for (te = ta->pluslist; te; te = te->next) {
1182 printf(" %s ", te->name);
1183 PRights(te->rights, ta->dfs);
1187 if (ta->nminus > 0) {
1188 printf("fs setacl -dir %s -acl ", ti->data);
1189 for (te = ta->minuslist; te; te = te->next) {
1190 printf(" %s ", te->name);
1191 PRights(te->rights, ta->dfs);
1193 printf(" -negative\n");
1198 printf("Access list for %s is\n", ti->data);
1201 printf("DFS access list for %s is\n", ti->data);
1204 printf("DFS initial directory access list of %s is\n", ti->data);
1207 printf("DFS initial file access list of %s is\n", ti->data);
1211 printf(" Default cell = %s\n", ta->cell);
1213 if (ta->nplus > 0) {
1215 printf("Normal rights:\n");
1216 for (te = ta->pluslist; te; te = te->next) {
1217 printf(" %s ", te->name);
1218 PRights(te->rights, ta->dfs);
1222 if (ta->nminus > 0) {
1223 printf("Negative rights:\n");
1224 for (te = ta->minuslist; te; te = te->next) {
1225 printf(" %s ", te->name);
1226 PRights(te->rights, ta->dfs);
1239 GetCallerAccess(struct cmd_syndesc *as, void *arock)
1241 struct cmd_item *ti;
1244 SetDotDefault(&as->parms[0].items);
1245 for (ti = as->parms[0].items; ti; ti = ti->next) {
1247 struct ViceIoctl blob;
1248 struct vcxstat2 stat;
1249 blob.out_size = sizeof(struct vcxstat2);
1251 blob.out = (void *)&stat;
1252 code = pioctl(ti->data, VIOC_GETVCXSTATUS2, &blob, 1);
1254 Die(errno, ti->data);
1258 printf("Callers access to %s is ", ti->data);
1259 PRights(stat.callerAccess, 0);
1266 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1269 struct ViceIoctl blob;
1270 struct cmd_item *ti;
1273 SetDotDefault(&as->parms[0].items);
1274 for (ti = as->parms[0].items; ti; ti = ti->next) {
1275 blob.in_size = blob.out_size = 0;
1276 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1278 fprintf(stderr, "Error flushing volume ");
1288 * The Windows version of UuidCmd displays the UUID.
1289 * When the UNIX version is updated to do the same
1290 * be sure to replace the CMD_REQUIRED flag with
1291 * CMD_OPTIONAL in the cmd_AddParam(-generate) call
1294 UuidCmd(struct cmd_syndesc *as, void *arock)
1297 struct ViceIoctl blob;
1302 if (as->parms[0].items) {
1304 fprintf (stderr, "Permission denied: requires root access.\n");
1308 /* generate new UUID */
1309 code = pioctl(0, VIOC_NEWUUID, &blob, 1);
1316 printf("New uuid generated.\n");
1318 /* This will never execute */
1319 printf("Please add the '-generate' option to generate a new UUID.\n");
1324 #if defined(AFS_CACHE_BYPASS)
1326 * Set cache-bypass threshold. Files larger than this size will not be cached.
1327 * With a threshold of 0, the cache is always bypassed. With a threshold of -1,
1328 * cache bypass is disabled.
1332 BypassThresholdCmd(struct cmd_syndesc *as, void *arock)
1335 struct ViceIoctl blob;
1336 afs_int32 threshold_i, threshold_o;
1339 /* if new threshold supplied, then set and confirm, else,
1340 * get current threshold and print
1343 if(as->parms[0].items) {
1346 tp = as->parms[0].items->data;
1349 if (!strcmp(tp,"-1")) {
1353 for(ix = 0; ix < len; ++ix) {
1354 if(!isdigit(tp[0])) {
1360 fprintf(stderr, "fs bypassthreshold -size: %s must be an integer between -1 and 2^31\n", tp);
1363 threshold_i = atoi(tp);
1364 if(ix > 9 && threshold_i < 2147483647)
1365 threshold_i = 2147483647;
1367 blob.in = (char *) &threshold_i;
1368 blob.in_size = sizeof(threshold_i);
1374 blob.out = (char *) &threshold_o;
1375 blob.out_size = sizeof(threshold_o);
1376 code = pioctl(0, VIOC_SETBYPASS_THRESH, &blob, 1);
1381 printf("Cache bypass threshold %d", threshold_o);
1382 if(threshold_o == -1)
1383 printf(" (disabled)");
1393 FlushCmd(struct cmd_syndesc *as, void *arock)
1396 struct ViceIoctl blob;
1397 struct cmd_item *ti;
1400 for (ti = as->parms[0].items; ti; ti = ti->next) {
1401 blob.in_size = blob.out_size = 0;
1402 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1404 if (errno == EMFILE) {
1405 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1408 fprintf(stderr, "%s: Error flushing file ", pn);
1418 /* all this command does is repackage its args and call SetVolCmd */
1420 SetQuotaCmd(struct cmd_syndesc *as, void *arock)
1422 struct cmd_syndesc ts;
1424 /* copy useful stuff from our command slot; we may later have to reorder */
1425 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1426 return SetVolCmd(&ts, arock);
1430 SetVolCmd(struct cmd_syndesc *as, void *arock)
1433 struct ViceIoctl blob;
1434 struct cmd_item *ti;
1435 struct VolumeStatus *status;
1436 char *offmsg, *input;
1439 SetDotDefault(&as->parms[0].items);
1440 for (ti = as->parms[0].items; ti; ti = ti->next) {
1442 blob.out_size = AFS_PIOCTL_MAXSIZE;
1443 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1446 status = (VolumeStatus *) space;
1447 status->MinQuota = status->MaxQuota = -1;
1449 if (as->parms[1].items) {
1450 code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota);
1452 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1457 if (as->parms[2].items)
1458 offmsg = as->parms[2].items->data;
1459 input = (char *)status + sizeof(*status);
1460 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1462 if (strlen(offmsg) >= VMSGSIZE) {
1464 "%s: message must be shorter than %d characters\n",
1469 strcpy(input, offmsg);
1470 blob.in_size += strlen(offmsg);
1471 input += strlen(offmsg) + 1;
1474 *(input++) = '\0'; /* Pad for old style volume "motd" */
1475 code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1);
1477 Die(errno, ti->data);
1485 * Why is VenusFid declared in the kernel-only section of afs.h,
1486 * if it's the exported interface of the cache manager?
1494 ExamineCmd(struct cmd_syndesc *as, void *arock)
1497 struct ViceIoctl blob;
1498 struct cmd_item *ti;
1499 struct VolumeStatus *status;
1500 char *name, *offmsg;
1503 SetDotDefault(&as->parms[0].items);
1504 for (ti = as->parms[0].items; ti; ti = ti->next) {
1505 struct VenusFid vfid;
1508 blob.out_size = AFS_PIOCTL_MAXSIZE;
1511 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1513 Die(errno, ti->data);
1517 status = (VolumeStatus *) space;
1518 name = (char *)status + sizeof(*status);
1519 offmsg = name + strlen(name) + 1;
1521 blob.out_size = sizeof(struct VenusFid);
1522 blob.out = (char *) &vfid;
1523 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1524 printf("File %s (%u.%u.%u) contained in volume %u\n",
1525 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1529 PrintStatus(status, name, offmsg);
1535 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1538 struct ViceIoctl blob;
1539 struct cmd_item *ti;
1540 struct VolumeStatus *status;
1545 if (as->parms[1].items)
1548 printf("%-25s%-11s%-11s%-7s%-11s\n", "Volume Name", " Quota",
1549 " Used", " %Used", " Partition");
1550 SetDotDefault(&as->parms[0].items);
1551 for (ti = as->parms[0].items; ti; ti = ti->next) {
1553 blob.out_size = AFS_PIOCTL_MAXSIZE;
1556 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1558 Die(errno, ti->data);
1562 status = (VolumeStatus *) space;
1563 name = (char *)status + sizeof(*status);
1564 QuickPrintStatus(status, name, human);
1570 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1573 struct ViceIoctl blob;
1574 struct cmd_item *ti;
1580 SetDotDefault(&as->parms[0].items);
1581 for (ti = as->parms[0].items; ti; ti = ti->next) {
1583 blob.out_size = AFS_PIOCTL_MAXSIZE;
1586 memset(space, 0, sizeof(space));
1587 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1589 Die(errno, ti->data);
1593 hosts = (afs_int32 *) space;
1594 printf("File %s is on host%s ", ti->data,
1595 (hosts[0] && !hosts[1]) ? "" : "s");
1596 for (j = 0; j < AFS_MAXHOSTS; j++) {
1599 tp = hostutil_GetNameByINet(hosts[j]);
1609 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1612 struct ViceIoctl blob;
1613 struct cmd_item *ti;
1615 struct VolumeStatus *status;
1619 if (as->parms[1].items)
1622 printf("%-25s%10s%10s%10s%6s\n", "Volume Name",
1623 human ? "total" : "kbytes", "used", "avail", "%used");
1624 SetDotDefault(&as->parms[0].items);
1625 for (ti = as->parms[0].items; ti; ti = ti->next) {
1627 blob.out_size = AFS_PIOCTL_MAXSIZE;
1630 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1632 Die(errno, ti->data);
1636 status = (VolumeStatus *) space;
1637 name = (char *)status + sizeof(*status);
1638 QuickPrintSpace(status, name, human);
1644 QuotaCmd(struct cmd_syndesc *as, void *arock)
1647 struct ViceIoctl blob;
1648 struct cmd_item *ti;
1650 struct VolumeStatus *status;
1653 SetDotDefault(&as->parms[0].items);
1654 for (ti = as->parms[0].items; ti; ti = ti->next) {
1656 blob.out_size = AFS_PIOCTL_MAXSIZE;
1659 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1661 Die(errno, ti->data);
1665 status = (VolumeStatus *) space;
1666 if (status->MaxQuota)
1668 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
1671 printf("%2.0f%% of quota used.\n", quotaPct);
1677 GetLastComponent(const char *data, char **outdir, char **outbase,
1680 char orig_name[1024]; /*Original name, may be modified */
1681 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
1683 struct stat statbuff; /*Buffer for status info */
1684 int link_chars_read; /*Num chars read in readlink() */
1685 char *dirname = NULL;
1686 char *basename = NULL;
1691 snprintf(orig_name, sizeof(orig_name), "%s%s",
1692 (data[0] == '/') ? "" : "./", data);
1694 if (lstat(orig_name, &statbuff) < 0) {
1695 /* if lstat fails, we should still try the pioctl, since it
1696 * may work (for example, lstat will fail, but pioctl will
1697 * work if the volume of offline (returning ENODEV). */
1698 statbuff.st_mode = S_IFDIR; /* lie like pros */
1702 * The lstat succeeded. If the given file is a symlink, substitute
1703 * the file name with the link name.
1705 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1709 /* Read name of resolved file */
1710 link_chars_read = readlink(orig_name, true_name, 1024);
1711 if (link_chars_read <= 0) {
1713 "%s: Can't read target name for '%s' symbolic link!\n",
1718 /* Add a trailing null to what was read, bump the length. */
1719 true_name[link_chars_read++] = 0;
1722 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1723 * have to create a full pathname using the original name and the
1724 * relative symlink name. Find the rightmost slash in the original
1725 * name (we know there is one) and splice in the symlink value.
1727 if (true_name[0] != '/') {
1728 lastSlash = strrchr(orig_name, '/');
1729 strcpy(++lastSlash, true_name);
1730 strcpy(true_name, orig_name);
1733 strcpy(true_name, orig_name);
1736 /* Find rightmost slash, if any. */
1737 lastSlash = strrchr(true_name, '/');
1738 if (lastSlash == true_name) {
1739 dirname = strdup("/");
1740 basename = strdup(lastSlash+1);
1741 } else if (lastSlash != NULL) {
1743 * Found it. Designate everything before it as the parent directory,
1744 * everything after it as the final component.
1747 dirname = strdup(true_name);
1748 basename = strdup(lastSlash+1);
1751 * No slash appears in the given file name. Set parent_dir to the current
1752 * directory, and the last component as the given name.
1754 dirname = strdup(".");
1755 basename = strdup(true_name);
1758 if (strcmp(basename, ".") == 0
1759 || strcmp(basename, "..") == 0) {
1761 "%s: you may not use '.' or '..' as the last component\n", pn);
1762 fprintf(stderr, "%s: of a name in this fs command.\n", pn);
1767 *outbase = basename;
1781 ListMountCmd(struct cmd_syndesc *as, void *arock)
1784 struct ViceIoctl blob;
1785 struct cmd_item *ti;
1786 char *last_component;
1788 int thru_symlink = 0;
1791 for (ti = as->parms[0].items; ti; ti = ti->next) {
1792 if (GetLastComponent(ti->data, &parent_dir,
1793 &last_component, &thru_symlink) != 0) {
1798 blob.in = last_component;
1799 blob.in_size = strlen(last_component) + 1;
1800 blob.out_size = AFS_PIOCTL_MAXSIZE;
1802 memset(space, 0, AFS_PIOCTL_MAXSIZE);
1804 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1805 free(last_component);
1809 printf("'%s' is a %smount point for volume '%s'\n", ti->data,
1810 (thru_symlink ? "symbolic link, leading to a " : ""),
1813 if (errno == EINVAL) {
1814 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
1816 Die(errno, (ti->data ? ti->data : parent_dir));
1825 MakeMountCmd(struct cmd_syndesc *as, void *arock)
1828 char *cellName, *volName, *tmpName;
1829 struct afsconf_cell info;
1830 struct vldbentry vldbEntry;
1831 struct ViceIoctl blob;
1837 if (as->parms[5].items && !as->parms[2].items) {
1838 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1843 if (as->parms[2].items) /* cell name specified */
1844 cellName = as->parms[2].items->data;
1847 volName = as->parms[1].items->data;
1849 if (strlen(volName) >= 64) {
1851 "%s: volume name too long (length must be < 64 characters)\n",
1856 /* Check for a cellname in the volume specification, and complain
1857 * if it doesn't match what was specified with -cell */
1858 if ((tmpName = strchr(volName, ':'))) {
1861 if (strcasecmp(cellName, volName)) {
1862 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1867 volName = ++tmpName;
1870 if (!InAFS(Parent(as->parms[0].items->data))) {
1872 "%s: mount points must be created within the AFS file system\n",
1879 blob.out_size = AFS_PIOCTL_MAXSIZE;
1882 pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME,
1886 code = GetCellName(cellName ? cellName : space, &info);
1890 if (!(as->parms[4].items)) {
1891 /* not fast, check which cell the mountpoint is being created in */
1892 /* not fast, check name with VLDB */
1893 code = VLDBInit(1, &info);
1895 /* make the check. Don't complain if there are problems with init */
1897 ubik_VL_GetEntryByNameO(uclient, 0, volName,
1899 if (code == VL_NOENT) {
1901 "%s: warning, volume %s does not exist in cell %s.\n",
1902 pn, volName, cellName ? cellName : space);
1907 if (as->parms[3].items) /* if -rw specified */
1912 /* cellular mount point, prepend cell prefix */
1913 strcat(space, info.name);
1916 strcat(space, volName); /* append volume name */
1917 strcat(space, "."); /* stupid convention; these end with a period */
1918 code = symlink(space, as->parms[0].items->data);
1920 Die(errno, as->parms[0].items->data);
1927 * Delete AFS mount points. Variables are used as follows:
1928 * tbuffer: Set to point to the null-terminated directory name of the mount point
1929 * (or ``.'' if none is provided)
1930 * tp: Set to point to the actual name of the mount point to nuke.
1933 RemoveMountCmd(struct cmd_syndesc *as, void *arock)
1936 struct ViceIoctl blob;
1937 struct cmd_item *ti;
1939 char lsbuffer[1024];
1943 for (ti = as->parms[0].items; ti; ti = ti->next) {
1945 tp = (char *)strrchr(ti->data, '/');
1947 strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */
1949 tp++; /* skip the slash */
1951 strcpy(tbuffer, ".");
1955 blob.in_size = strlen(tp) + 1;
1956 blob.out = lsbuffer;
1957 blob.out_size = sizeof(lsbuffer);
1958 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 1);
1960 if (errno == EINVAL) {
1961 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
1964 Die(errno, ti->data);
1967 continue; /* don't bother trying */
1971 blob.in_size = strlen(tp) + 1;
1972 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 1);
1974 Die(errno, ti->data);
1985 CheckServersCmd(struct cmd_syndesc *as, void *arock)
1988 struct ViceIoctl blob;
1992 struct afsconf_cell info;
1993 struct chservinfo checkserv;
1995 memset(&checkserv, 0, sizeof(struct chservinfo));
1996 blob.in_size = sizeof(struct chservinfo);
1997 blob.in = (caddr_t) & checkserv;
1999 blob.out_size = AFS_PIOCTL_MAXSIZE;
2001 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2003 /* prepare flags for checkservers command */
2004 temp = 2; /* default to checking local cell only */
2005 if (as->parms[2].items)
2006 temp |= 1; /* set fast flag */
2007 if (as->parms[1].items)
2008 temp &= ~2; /* turn off local cell check */
2010 checkserv.magic = 0x12345678; /* XXX */
2011 checkserv.tflags = temp;
2013 /* now copy in optional cell name, if specified */
2014 if (as->parms[0].items) {
2015 code = GetCellName(as->parms[0].items->data, &info);
2019 strcpy(checkserv.tbuffer, info.name);
2020 checkserv.tsize = strlen(info.name) + 1;
2022 strcpy(checkserv.tbuffer, "\0");
2023 checkserv.tsize = 0;
2026 if (as->parms[3].items) {
2027 checkserv.tinterval = atol(as->parms[3].items->data);
2030 if (checkserv.tinterval < 0) {
2032 ("Warning: The negative -interval is ignored; treated as an inquiry\n");
2033 checkserv.tinterval = 0;
2034 } else if (checkserv.tinterval > 600) {
2036 ("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2037 checkserv.tinterval = 600; /* 10 min max interval */
2040 checkserv.tinterval = -1; /* don't change current interval */
2043 code = pioctl(0, VIOCCKSERV, &blob, 1);
2045 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2046 printf("Must be root to change -interval\n");
2052 memcpy(&temp, space, sizeof(afs_int32));
2053 if (checkserv.tinterval >= 0) {
2054 if (checkserv.tinterval > 0)
2056 ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2057 checkserv.tinterval, temp);
2059 printf("The current down server probe interval is %d secs\n",
2064 printf("All servers are running.\n");
2067 ("These servers unavailable due to network or server problems: ");
2069 memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32));
2072 tp = hostutil_GetNameByINet(temp);
2082 MessagesCmd(struct cmd_syndesc *as, void *arock)
2085 struct ViceIoctl blob;
2086 struct gaginfo gagflags;
2087 struct cmd_item *show;
2089 memset(&gagflags, 0, sizeof(struct gaginfo));
2090 blob.in_size = sizeof(struct gaginfo);
2091 blob.in = (caddr_t) & gagflags;
2092 blob.out_size = AFS_PIOCTL_MAXSIZE;
2094 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2096 if ((show = as->parms[0].items)) {
2097 if (!strcasecmp(show->data, "user"))
2098 gagflags.showflags |= GAGUSER;
2099 else if (!strcasecmp(show->data, "console"))
2100 gagflags.showflags |= GAGCONSOLE;
2101 else if (!strcasecmp(show->data, "all"))
2102 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2103 else if (!strcasecmp(show->data, "none"))
2107 "unrecognized flag %s: must be in {user,console,all,none}\n",
2116 code = pioctl(0, VIOC_GAG, &blob, 1);
2126 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2129 struct ViceIoctl blob;
2133 code = pioctl(0, VIOCCKBACK, &blob, 1);
2139 printf("All volumeID/name mappings checked.\n");
2144 PreCacheCmd(struct cmd_syndesc *as, void *arock)
2147 struct ViceIoctl blob;
2150 if (!as->parms[0].items && !as->parms[1].items) {
2151 fprintf(stderr, "%s: syntax error in precache cmd.\n", pn);
2154 if (as->parms[0].items) {
2155 code = util_GetInt32(as->parms[0].items->data, &temp);
2157 fprintf(stderr, "%s: bad integer specified for precache size.\n",
2163 blob.in = (char *)&temp;
2164 blob.in_size = sizeof(afs_int32);
2166 code = pioctl(0, VIOCPRECACHE, &blob, 1);
2172 printf("New precache size set.\n");
2177 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2180 struct ViceIoctl blob;
2183 if (!as->parms[0].items && !as->parms[1].items) {
2184 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
2187 if (as->parms[0].items) {
2188 code = util_GetHumanInt32(as->parms[0].items->data, &temp);
2190 fprintf(stderr, "%s: bad integer specified for cache size.\n",
2196 blob.in = (char *)&temp;
2197 blob.in_size = sizeof(afs_int32);
2199 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2201 if (errno == EROFS) {
2203 ("'fs setcache' not allowed on memory cache based cache managers.\n");
2210 printf("New cache size set.\n");
2214 #define MAXGCSIZE 16
2216 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2218 afs_int32 code, filesUsed;
2219 struct ViceIoctl blob;
2220 afs_int32 parms[MAXGCSIZE];
2221 double percentFiles, percentBlocks;
2222 afs_int32 flags = 0;
2224 if (as->parms[0].items){ /* -files */
2226 } else if (as->parms[1].items){ /* -excessive */
2232 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
2234 blob.in = (char *)&flags;
2235 blob.in_size = sizeof(afs_int32);
2236 } else { /* be backward compatible */
2240 blob.out_size = sizeof(parms);
2241 blob.out = (char *)parms;
2242 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2249 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2250 parms[1], parms[0]);
2251 if (parms[1] > parms[0])
2252 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2256 percentBlocks = ((double)parms[1]/parms[0]) * 100;
2257 printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n",
2258 percentBlocks, parms[1], parms[0]);
2263 filesUsed = parms[2] - parms[3];
2264 percentFiles = ((double)filesUsed/parms[2]) * 100;
2265 printf(" %5.0f%% of the cache files (%d of %d files)\n",
2266 percentFiles, filesUsed, parms[2]);
2268 printf(" afs_cacheFiles: %10d\n", parms[2]);
2269 printf(" IFFree: %10d\n", parms[3]);
2270 printf(" IFEverUsed: %10d\n", parms[4]);
2271 printf(" IFDataMod: %10d\n", parms[5]);
2272 printf(" IFDirtyPages: %10d\n", parms[6]);
2273 printf(" IFAnyPages: %10d\n", parms[7]);
2274 printf(" IFDiscarded: %10d\n", parms[8]);
2275 printf(" DCentries: %10d\n", parms[9]);
2276 printf(" 0k- 4K: %10d\n", parms[10]);
2277 printf(" 4k- 16k: %10d\n", parms[11]);
2278 printf(" 16k- 64k: %10d\n", parms[12]);
2279 printf(" 64k- 256k: %10d\n", parms[13]);
2280 printf(" 256k- 1M: %10d\n", parms[14]);
2281 printf(" >=1M: %10d\n", parms[15]);
2284 if (percentBlocks > 90)
2285 printf("[cache size usage over 90%%, consider increasing cache size]\n");
2286 if (percentFiles > 90)
2287 printf("[cache file usage over 90%%, consider increasing '-files' argument to afsd]\n");
2293 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2298 struct ViceIoctl blob;
2301 resolve = !(as->parms[0].items); /* -numeric */
2305 memcpy(tp, &i, sizeof(afs_int32));
2306 blob.out_size = AFS_PIOCTL_MAXSIZE;
2307 blob.in_size = sizeof(afs_int32);
2310 code = pioctl(0, VIOCGETCELL, &blob, 1);
2313 break; /* done with the list */
2318 printf("Cell %s on hosts", tp + AFS_MAXCELLHOSTS * sizeof(afs_int32));
2319 for (j = 0; j < AFS_MAXCELLHOSTS; j++) {
2321 char *name, tbuffer[20];
2323 memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32));
2328 name = hostutil_GetNameByINet(addr);
2331 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2332 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2335 printf(" %s", name);
2343 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2346 char *tp, *aliasName, *realName;
2347 struct ViceIoctl blob;
2351 memcpy(tp, &i, sizeof(afs_int32));
2352 blob.out_size = AFS_PIOCTL_MAXSIZE;
2353 blob.in_size = sizeof(afs_int32);
2356 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2359 break; /* done with the list */
2365 tp += strlen(aliasName) + 1;
2367 printf("Alias %s for cell %s\n", aliasName, realName);
2373 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2376 struct ViceIoctl blob;
2377 struct cmd_item *ti;
2379 struct hostent *thp;
2381 ti = as->parms[0].items;
2383 thp = hostutil_GetHostByName(ti->data);
2385 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2388 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2390 hostAddr = 0; /* means don't set host */
2393 /* now do operation */
2394 blob.in_size = sizeof(afs_int32);
2395 blob.out_size = sizeof(afs_int32);
2396 blob.in = (char *) &hostAddr;
2397 blob.out = (char *) &hostAddr;
2399 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2408 NukeNFSCredsCmd(struct cmd_syndesc *as, void *arock)
2411 struct ViceIoctl blob;
2412 struct cmd_item *ti;
2414 struct hostent *thp;
2416 ti = as->parms[0].items;
2417 thp = hostutil_GetHostByName(ti->data);
2419 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2422 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2424 /* now do operation */
2425 blob.in_size = sizeof(afs_int32);
2426 blob.out_size = sizeof(afs_int32);
2427 blob.in = (char *) &hostAddr;
2428 blob.out = (char *) &hostAddr;
2430 code = pioctl(0, VIOC_NFS_NUKE_CREDS, &blob, 1);
2439 NewCellCmd(struct cmd_syndesc *as, void *arock)
2441 afs_int32 code, linkedstate = 0, size = 0, *lp;
2442 struct ViceIoctl blob;
2443 struct cmd_item *ti;
2444 char *tp, *cellname = 0;
2445 struct hostent *thp;
2446 afs_int32 fsport = 0, vlport = 0;
2447 afs_int32 scount; /* Number of servers to pass in pioctl call */
2450 * With the NEWCELL pioctl call, 3.4 clients take an array of
2451 * AFS_MAXHOSTS (13) servers while 3.5 clients take an array of
2452 * AFS_MAXCELLHOSTS (8) servers. To determine which we are talking to,
2453 * do a GETCELL pioctl and pass it a magic number. If an array of
2454 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
2455 * If we get back EDOM, there are no cells in the kernel yet,
2456 * and we'll assume a 3.5 client.
2459 lp = (afs_int32 *) tp;
2460 *lp++ = 0; /* first cell entry */
2461 *lp = 0x12345678; /* magic */
2462 blob.out_size = AFS_PIOCTL_MAXSIZE;
2463 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
2466 code = pioctl(0, VIOCGETCELL, &blob, 1);
2467 if (code < 0 && errno != EDOM) {
2471 if (code < 1 && errno == EDOM) {
2472 scount = AFS_MAXHOSTS;
2475 cellname = tp + AFS_MAXCELLHOSTS * sizeof(afs_int32);
2476 scount = ((cellname[0] != '\0') ? AFS_MAXCELLHOSTS : AFS_MAXHOSTS);
2479 /* Now setup and do the NEWCELL pioctl call */
2480 memset(space, 0, (scount + 1) * sizeof(afs_int32));
2482 lp = (afs_int32 *) tp;
2484 tp += sizeof(afs_int32);
2485 for (ti = as->parms[1].items; ti; ti = ti->next) {
2486 thp = hostutil_GetHostByName(ti->data);
2489 "%s: Host %s not found in host table, skipping it.\n", pn,
2492 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2493 tp += sizeof(afs_int32);
2496 if (as->parms[2].items) {
2498 * Link the cell, for the purposes of volume location, to the specified
2501 cellname = as->parms[2].items->data;
2504 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2505 if (as->parms[3].items) {
2506 code = util_GetInt32(as->parms[3].items->data, &vlport);
2509 "%s: bad integer specified for the fileserver port.\n",
2514 if (as->parms[4].items) {
2515 code = util_GetInt32(as->parms[4].items->data, &fsport);
2518 "%s: bad integer specified for the vldb server port.\n",
2524 tp = (char *)(space + (scount + 1) * sizeof(afs_int32));
2525 lp = (afs_int32 *) tp;
2529 strcpy(space + ((scount + 4) * sizeof(afs_int32)),
2530 as->parms[0].items->data);
2531 size = ((scount + 4) * sizeof(afs_int32))
2532 + strlen(as->parms[0].items->data)
2533 + 1 /* for null */ ;
2534 tp = (char *)(space + size);
2536 strcpy(tp, cellname);
2537 size += strlen(cellname) + 1;
2539 blob.in_size = size;
2542 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2551 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2554 struct ViceIoctl blob;
2556 char *aliasName, *realName;
2558 /* Now setup and do the NEWCELL pioctl call */
2559 aliasName = as->parms[0].items->data;
2560 realName = as->parms[1].items->data;
2562 strcpy(tp, aliasName);
2563 tp += strlen(aliasName) + 1;
2564 strcpy(tp, realName);
2565 tp += strlen(realName) + 1;
2567 blob.in_size = tp - space;
2571 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2573 if (errno == EEXIST) {
2575 "%s: cell name `%s' in use by an existing cell.\n", pn,
2586 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2589 struct cmd_item *ti;
2591 char cell[MAXCELLCHARS];
2593 SetDotDefault(&as->parms[0].items);
2594 for (ti = as->parms[0].items; ti; ti = ti->next) {
2595 code = GetCell(ti->data, cell);
2597 if (errno == ENOENT)
2598 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
2600 Die(errno, ti->data);
2605 printf("File %s lives in cell '%s'\n", ti->data, cell);
2611 WSCellCmd(struct cmd_syndesc *as, void *arock)
2614 struct ViceIoctl blob;
2618 blob.out_size = AFS_PIOCTL_MAXSIZE;
2621 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2627 printf("This workstation belongs to cell '%s'\n", space);
2632 static PrimaryCellCmd(as)
2633 struct cmd_syndesc *as;
2635 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2641 MonitorCmd(struct cmd_syndesc *as, void *arock)
2644 struct ViceIoctl blob;
2645 struct cmd_item *ti;
2647 struct hostent *thp;
2651 ti = as->parms[0].items;
2655 if (!strcmp(ti->data, "off"))
2656 hostAddr = 0xffffffff;
2658 thp = hostutil_GetHostByName(ti->data);
2660 if (!strcmp(ti->data, "localhost")) {
2662 "localhost not in host table, assuming 127.0.0.1\n");
2663 hostAddr = htonl(0x7f000001);
2665 fprintf(stderr, "host %s not found in host table.\n",
2670 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2673 hostAddr = 0; /* means don't set host */
2674 setp = 0; /* aren't setting host */
2677 /* now do operation */
2678 blob.in_size = sizeof(afs_int32);
2679 blob.out_size = sizeof(afs_int32);
2680 blob.in = (char *)&hostAddr;
2681 blob.out = (char *)&hostAddr;
2682 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2688 printf("%s: new monitor host set.\n", pn);
2690 /* now decode old address */
2691 if (hostAddr == 0xffffffff) {
2692 printf("Cache monitoring is currently disabled.\n");
2694 tp = hostutil_GetNameByINet(hostAddr);
2695 printf("Using host %s for monitor services.\n", tp);
2702 SysNameCmd(struct cmd_syndesc *as, void *arock)
2705 struct ViceIoctl blob;
2706 struct cmd_item *ti;
2707 char *input = space;
2710 ti = as->parms[0].items;
2713 blob.out_size = AFS_PIOCTL_MAXSIZE;
2714 blob.in_size = sizeof(afs_int32);
2715 input += sizeof(afs_int32);
2716 for (; ti; ti = ti->next) {
2718 blob.in_size += strlen(ti->data) + 1;
2719 if (blob.in_size > AFS_PIOCTL_MAXSIZE) {
2720 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2721 setp > 1 ? "s" : "");
2724 strcpy(input, ti->data);
2725 input += strlen(ti->data);
2728 memcpy(space, &setp, sizeof(afs_int32));
2729 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2735 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2739 memcpy(&setp, input, sizeof(afs_int32));
2740 input += sizeof(afs_int32);
2742 fprintf(stderr, "No sysname name value was found\n");
2745 printf("Current sysname%s is", setp > 1 ? " list" : "");
2746 for (; setp > 0; --setp) {
2747 printf(" \'%s\'", input);
2748 input += strlen(input) + 1;
2754 static char *exported_types[] = { "null", "nfs", "" };
2756 ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2759 struct ViceIoctl blob;
2760 struct cmd_item *ti;
2761 int export = 0, type = 0, mode = 0, exportcall, pwsync =
2762 0, smounts = 0, clipags = 0, pagcb = 0;
2764 ti = as->parms[0].items;
2765 if (strcmp(ti->data, "nfs") == 0)
2766 type = 0x71; /* NFS */
2769 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n",
2773 ti = as->parms[1].items;
2775 if (strcmp(ti->data, "on") == 0)
2777 else if (strcmp(ti->data, "off") == 0)
2780 fprintf(stderr, "Illegal argument %s\n", ti->data);
2784 if ((ti = as->parms[2].items)) { /* -noconvert */
2785 if (strcmp(ti->data, "on") == 0)
2787 else if (strcmp(ti->data, "off") == 0)
2790 fprintf(stderr, "Illegal argument %s\n", ti->data);
2794 if ((ti = as->parms[3].items)) { /* -uidcheck */
2795 if (strcmp(ti->data, "on") == 0)
2797 else if (strcmp(ti->data, "off") == 0)
2800 fprintf(stderr, "Illegal argument %s\n", ti->data);
2804 if ((ti = as->parms[4].items)) { /* -submounts */
2805 if (strcmp(ti->data, "on") == 0)
2807 else if (strcmp(ti->data, "off") == 0)
2810 fprintf(stderr, "Illegal argument %s\n", ti->data);
2814 if ((ti = as->parms[5].items)) { /* -clipags */
2815 if (strcmp(ti->data, "on") == 0)
2817 else if (strcmp(ti->data, "off") == 0)
2820 fprintf(stderr, "Illegal argument %s\n", ti->data);
2824 if ((ti = as->parms[6].items)) { /* -pagcb */
2825 if (strcmp(ti->data, "on") == 0)
2827 else if (strcmp(ti->data, "off") == 0)
2830 fprintf(stderr, "Illegal argument %s\n", ti->data);
2835 (type << 24) | (pagcb << 10) | (clipags << 8) |
2836 (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2839 blob.in = (char *)&exportcall;
2840 blob.in_size = sizeof(afs_int32);
2841 blob.out = (char *)&exportcall;
2842 blob.out_size = sizeof(afs_int32);
2843 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2845 if (errno == ENODEV) {
2847 "Sorry, the %s-exporter type is currently not supported on this AFS client\n",
2848 exported_types[type]);
2855 if (exportcall & 1) {
2856 printf("'%s' translator is enabled with the following options:\n",
2857 exported_types[type]);
2858 printf("\tRunning in %s mode\n",
2859 (exportcall & 2 ? "strict unix" :
2860 "convert owner mode bits to world/other"));
2861 printf("\tRunning in %s mode\n",
2862 (exportcall & 4 ? "strict 'passwd sync'" :
2863 "no 'passwd sync'"));
2865 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
2866 "Only mounts to /afs allowed"));
2868 (exportcall & 16 ? "Client-assigned PAG's are used" :
2869 "Client-assigned PAG's are not used"));
2872 "Callbacks are made to get creds from new clients" :
2873 "Callbacks are not made to get creds from new clients"));
2875 printf("'%s' translator is disabled\n", exported_types[type]);
2882 GetCellCmd(struct cmd_syndesc *as, void *arock)
2885 struct ViceIoctl blob;
2886 struct afsconf_cell info;
2887 struct cmd_item *ti;
2894 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2895 for (ti = as->parms[0].items; ti; ti = ti->next) {
2897 blob.out_size = sizeof(args);
2898 blob.out = (caddr_t) & args;
2899 code = GetCellName(ti->data, &info);
2904 blob.in_size = 1 + strlen(info.name);
2905 blob.in = info.name;
2906 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2908 if (errno == ENOENT)
2909 fprintf(stderr, "%s: the cell named '%s' does not exist\n",
2912 Die(errno, info.name);
2916 printf("Cell %s status: ", info.name);
2922 printf("no setuid allowed");
2924 printf("setuid allowed");
2926 printf(", using old VLDB");
2933 SetCellCmd(struct cmd_syndesc *as, void *arock)
2936 struct ViceIoctl blob;
2937 struct afsconf_cell info;
2938 struct cmd_item *ti;
2946 /* Check arguments. */
2947 if (as->parms[1].items && as->parms[2].items) {
2948 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2952 /* figure stuff to set */
2956 if (!as->parms[1].items)
2957 args.stat |= 2; /* default to -nosuid */
2959 /* set stat for all listed cells */
2960 for (ti = as->parms[0].items; ti; ti = ti->next) {
2962 code = GetCellName(ti->data, &info);
2967 strcpy(args.cname, info.name);
2968 blob.in_size = sizeof(args);
2969 blob.in = (caddr_t) & args;
2971 blob.out = (caddr_t) 0;
2972 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2974 Die(errno, info.name); /* XXX added cell name to Die() call */
2982 GetCellName(char *cellName, struct afsconf_cell *info)
2984 struct afsconf_dir *tdir;
2987 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2990 "Could not process files in configuration directory (%s).\n",
2991 AFSDIR_CLIENT_ETC_DIRPATH);
2995 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2997 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2998 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
3007 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3011 code = ugen_ClientInit(noAuthFlag, (char *) AFSDIR_CLIENT_ETC_DIRPATH,
3012 info->name, 0, &uclient,
3013 NULL, pn, rxkad_clear,
3014 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3015 0, 0, USER_SERVICE_ID);
3020 static struct ViceIoctl gblob;
3021 static int debug = 0;
3023 * here follow some routines in suport of the setserverprefs and
3024 * getserverprefs commands. They are:
3025 * SetPrefCmd "top-level" routine
3026 * addServer adds a server to the list of servers to be poked into the
3027 * kernel. Will poke the list into the kernel if it threatens
3029 * pokeServers pokes the existing list of servers and ranks into the kernel
3030 * GetPrefCmd reads the Cache Manager's current list of server ranks
3034 * returns -1 if error message printed,
3036 * errno value if error and no error message printed
3043 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
3044 if (code && (errno == EINVAL)) {
3045 struct setspref *ssp;
3046 ssp = (struct setspref *)gblob.in;
3047 if (!(ssp->flags & DBservers)) {
3048 gblob.in = (void *)&(ssp->servers[0]);
3049 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3050 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
3051 return code ? errno : 0;
3054 "This cache manager does not support VL server preferences.\n");
3058 return code ? errno : 0;
3062 * returns -1 if error message printed,
3064 * errno value if error and no error message printed
3067 addServer(char *name, afs_int32 rank)
3070 struct setspref *ssp;
3072 struct hostent *thostent;
3077 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3079 #define MAXUSHORT ((unsigned short) ~0)
3083 thostent = hostutil_GetHostByName(name);
3085 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3089 ssp = (struct setspref *)(gblob.in);
3091 for (t = 0; thostent->h_addr_list[t]; t++) {
3092 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3093 code = pokeServers();
3096 ssp->num_servers = 0;
3099 sp = (struct spref *)(gblob.in + gblob.in_size);
3100 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3101 sizeof(afs_uint32));
3102 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3103 gblob.in_size += sizeof(struct spref);
3107 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3108 name, sp->rank, (long unsigned int) sp->server.s_addr);
3116 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3120 struct cmd_item *ti;
3123 struct setspref *ssp;
3124 int error = 0; /* -1 means error message printed,
3125 * >0 means errno value for unprinted message */
3127 ssp = (struct setspref *)space;
3129 ssp->num_servers = 0;
3130 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3133 gblob.out_size = AFS_PIOCTL_MAXSIZE;
3137 fprintf(stderr, "Permission denied: requires root access.\n");
3141 ti = as->parms[2].items; /* -file */
3144 fprintf(stderr, "opening file %s\n", ti->data);
3145 if (!(infd = fopen(ti->data, "r"))) {
3149 while (fscanf(infd, "%79s%ld", name, (long int *)&rank) != EOF) {
3150 code = addServer(name, (unsigned short)rank);
3157 ti = as->parms[3].items; /* -stdin */
3159 while (scanf("%79s%ld", name, (long int *)&rank) != EOF) {
3160 code = addServer(name, (unsigned short)rank);
3166 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3171 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3175 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3179 code = pokeServers();
3183 printf("now working on vlservers, code=%d\n", code);
3185 ssp = (struct setspref *)space;
3186 ssp->flags = DBservers;
3187 ssp->num_servers = 0;
3188 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3191 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3196 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3200 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3205 if (as->parms[1].items) {
3207 printf("now poking vlservers\n");
3208 code = pokeServers();
3216 return error ? 1 : 0;
3222 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3225 struct cmd_item *ti;
3226 char *name, tbuffer[20];
3231 struct ViceIoctl blob;
3232 struct sprefrequest *in;
3233 struct sprefinfo *out;
3236 ti = as->parms[0].items; /* -file */
3239 fprintf(stderr, "opening file %s\n", ti->data);
3240 if (!(outfd = freopen(ti->data, "w", stdout))) {
3246 ti = as->parms[1].items; /* -numeric */
3248 ti = as->parms[2].items; /* -vlservers */
3249 vlservers |= (ti ? DBservers : 0);
3250 /* ti = as->parms[3].items; -cell */
3252 in = (struct sprefrequest *)space;
3256 blob.in_size = sizeof(struct sprefrequest);
3257 blob.in = (char *)in;
3259 blob.out_size = AFS_PIOCTL_MAXSIZE;
3262 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3263 in->flags = vlservers;
3266 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3268 if ((errno != E2BIG) || (2 * blob.out_size > 0x7FFF)) {
3269 perror("getserverprefs pioctl");
3273 if (blob.out == space)
3274 blob.out = malloc(blob.out_size);
3276 blob.out = realloc(blob.out, blob.out_size);
3278 } while (code != 0);
3280 out = (struct sprefinfo *)blob.out;
3282 for (i = 0; i < out->num_servers; i++) {
3284 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3286 addr = ntohl(out->servers[i].server.s_addr);
3287 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3288 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3291 printf("%-50s %5u\n", name, out->servers[i].rank);
3294 in->offset = out->next_offset;
3295 } while (out->next_offset > 0);
3297 if (blob.out != space)
3304 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
3307 struct ViceIoctl blob;
3308 struct cmd_item *ti;
3309 struct sbstruct tsb, tsb2;
3315 tsb.sb_thisfile = -1;
3316 ti = as->parms[0].items; /* -kbytes */
3318 if (!as->parms[1].items) {
3319 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3323 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3324 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3325 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3331 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3332 ti = as->parms[2].items; /* -allfiles */
3334 allfiles = strtol(ti->data, &t, 10) * 1024;
3335 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3336 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3342 /* -verbose or -file only or no options */
3343 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3344 || (!as->parms[0].items && !as->parms[1].items
3345 && !as->parms[2].items))
3348 blob.in = (char *)&tsb;
3349 blob.in_size = sizeof(struct sbstruct);
3351 /* once per -file */
3352 for (ti = as->parms[1].items; ti; ti = ti->next) {
3353 /* Do this solely to see if the file is there */
3356 blob.out_size = AFS_PIOCTL_MAXSIZE;
3357 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3359 Die(errno, ti->data);
3364 memset(&tsb2, 0, sizeof(tsb2));
3365 blob.out = (char *)&tsb2;
3366 blob.out_size = sizeof(struct sbstruct);
3367 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
3369 Die(errno, ti->data);
3374 if (verbose && (blob.out_size == sizeof(tsb2))) {
3375 if (tsb2.sb_thisfile == -1) {
3376 fprintf(stdout, "Will store %s according to default.\n",
3380 "Will store up to %d kbytes of %s asynchronously.\n",
3381 (tsb2.sb_thisfile / 1024), ti->data);
3386 /* If no files - make at least one pioctl call, or
3387 * set the allfiles default if we need to.
3389 if (!as->parms[1].items || (allfiles != -1)) {
3390 tsb.sb_default = allfiles;
3391 memset(&tsb2, 0, sizeof(tsb2));
3392 blob.out = (char *)&tsb2;
3393 blob.out_size = sizeof(struct sbstruct);
3394 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
3396 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3401 /* Having no arguments also reports the default store asynchrony */
3402 if (!error && verbose && (blob.out_size == sizeof(tsb2))) {
3403 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3404 (tsb2.sb_default / 1024));
3412 SetCryptCmd(struct cmd_syndesc *as, void *arock)
3414 afs_int32 code = 0, flag;
3415 struct ViceIoctl blob;
3418 tp = as->parms[0].items->data;
3419 if (strcmp(tp, "on") == 0)
3421 else if (strcmp(tp, "off") == 0)
3424 fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3428 blob.in = (char *)&flag;
3429 blob.in_size = sizeof(flag);
3431 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3439 GetCryptCmd(struct cmd_syndesc *as, void *arock)
3441 afs_int32 code = 0, flag;
3442 struct ViceIoctl blob;
3447 blob.out_size = sizeof(flag);
3450 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3456 memcpy(&flag, tp, sizeof(afs_int32));
3457 printf("Security level is currently ");
3459 printf("crypt (data security).\n");
3466 static char *modenames[] = {
3469 "readonly", /* Not currently supported */
3470 "fetchonly", /* Not currently supported */
3471 "partial", /* Not currently supported */
3475 static char *policynames[] = {
3478 "closer", /* Not currently supported. */
3479 "manual", /* Not currently supported. */
3484 DisconCmd(struct cmd_syndesc *as, void *arock)
3486 struct cmd_item *ti;
3489 int modelen, policylen;
3490 afs_int32 mode, policy, code, unixuid = 0;
3491 struct ViceIoctl blob;
3496 space[0] = space[1] = space[2] = space[3] = 0;
3498 ti = as->parms[0].items;
3500 modename = ti->data;
3501 modelen = strlen(modename);
3502 for (mode = 0; modenames[mode] != NULL; mode++)
3503 if (!strncasecmp(modename, modenames[mode], modelen))
3505 if (modenames[mode] == NULL)
3506 printf("Unknown discon mode \"%s\"\n", modename);
3508 space[0] = mode + 1;
3511 ti = as->parms[1].items;
3513 policyname = ti->data;
3514 policylen = strlen(policyname);
3515 for (policy = 0; policynames[policy] != NULL; policy++)
3516 if (!strncasecmp(policyname, policynames[policy], policylen))
3518 if (policynames[policy] == NULL)
3519 printf("Unknown discon mode \"%s\"\n", policyname);
3521 space[1] = policy + 1;
3525 if (as->parms[2].items) {
3527 printf("force on\n");
3530 ti = as->parms[3].items;
3532 code = util_GetInt32(ti->data, &unixuid);
3534 fprintf(stderr, "%s: bad integer specified for uid.\n", pn);
3542 blob.in_size = 4 * sizeof(afs_int32);
3544 blob.out_size = sizeof(mode);
3546 code = pioctl(0, VIOC_DISCON, &blob, 1);
3550 memcpy(&mode, space, sizeof mode);
3551 if (mode < sizeof modenames / sizeof (char *))
3552 printf("Discon mode is now \"%s\"\n", modenames[mode]);
3554 printf("Unknown discon mode %d\n", mode);
3560 #include "AFS_component_version_number.c"
3563 main(int argc, char **argv)
3566 struct cmd_syndesc *ts;
3568 #ifdef AFS_AIX32_ENV
3570 * The following signal action for AIX is necessary so that in case of a
3571 * crash (i.e. core is generated) we can include the user's data section
3572 * in the core dump. Unfortunately, by default, only a partial core is
3573 * generated which, in many cases, isn't too useful.
3575 struct sigaction nsa;
3577 sigemptyset(&nsa.sa_mask);
3578 nsa.sa_handler = SIG_DFL;
3579 nsa.sa_flags = SA_FULLDUMP;
3580 sigaction(SIGSEGV, &nsa, NULL);
3583 /* try to find volume location information */
3584 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
3585 "get client network interface addresses");
3586 cmd_CreateAlias(ts, "gc");
3588 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
3589 "set client network interface addresses");
3590 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3591 "client network interfaces");
3592 cmd_CreateAlias(ts, "sc");
3594 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL,
3595 "set server ranks");
3596 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3597 "fileserver names and ranks");
3598 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3599 "VL server names and ranks");
3600 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3601 "input from named file");
3602 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3603 cmd_CreateAlias(ts, "sp");
3605 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL,
3606 "get server ranks");
3607 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3608 "output to named file");
3609 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3610 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3611 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3612 cmd_CreateAlias(ts, "gp");
3614 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
3615 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3616 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3617 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3618 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL,
3619 "apply to negative rights");
3620 parm_setacl_id = ts->nParms;
3621 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL,
3622 "initial directory acl (DFS only)");
3623 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL,
3624 "initial file acl (DFS only)");
3625 cmd_CreateAlias(ts, "sa");
3627 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL,
3628 "list access control list");
3629 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3630 parm_listacl_id = ts->nParms;
3631 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3632 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3633 cmd_AddParm(ts, "-cmd", CMD_FLAG, CMD_OPTIONAL, "output as 'fs setacl' command");
3634 cmd_CreateAlias(ts, "la");
3636 ts = cmd_CreateSyntax("getcalleraccess", GetCallerAccess, NULL,
3637 "list callers access");
3638 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3639 cmd_CreateAlias(ts, "gca");
3641 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL,
3642 "clean up access control list");
3643 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3645 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL,
3646 "copy access control list");
3647 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0,
3648 "source directory (or DFS file)");
3649 cmd_AddParm(ts, "-todir", CMD_LIST, 0,
3650 "destination directory (or DFS file)");
3651 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3652 "first clear dest access list");
3653 parm_copyacl_id = ts->nParms;
3654 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3655 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3657 cmd_CreateAlias(ts, "ca");
3659 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
3660 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3661 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
3662 "flush mount symlink from cache");
3663 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3665 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
3666 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3667 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL,
3668 "disk space quota in 1K units");
3670 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL,
3671 "disk space guaranteed");
3672 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3674 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL,
3676 cmd_CreateAlias(ts, "sv");
3678 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL,
3679 "control Cache Manager messages");
3680 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL,
3681 "[user|console|all|none]");
3683 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
3684 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3685 cmd_CreateAlias(ts, "lv");
3686 cmd_CreateAlias(ts, "listvol");
3688 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
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, "lq");
3693 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL,
3694 "show server disk space usage");
3695 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3696 cmd_AddParm(ts, "-human", CMD_FLAG, CMD_OPTIONAL, "human-readable listing");
3697 cmd_CreateAlias(ts, "df");
3699 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
3700 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3702 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
3703 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3705 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
3706 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3707 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3708 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3709 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3710 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3711 "don't check name with VLDB");
3713 #if defined(AFS_CACHE_BYPASS)
3714 ts = cmd_CreateSyntax("bypassthreshold", BypassThresholdCmd, 0,
3715 "get/set cache bypass file size threshold");
3716 cmd_AddParm(ts, "-size", CMD_SINGLE, CMD_OPTIONAL, "file size");
3723 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3727 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
3728 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3730 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL,
3731 "check local cell's servers");
3732 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3733 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3734 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3735 "just list, don't check");
3736 cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL,
3737 "seconds between probes");
3739 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL,
3740 "check volumeID/name mappings");
3741 cmd_CreateAlias(ts, "checkbackups");
3744 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL,
3746 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3747 "size in 1K byte blocks (0 => reset)");
3748 cmd_CreateAlias(ts, "cachesize");
3750 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL,
3751 "reset size back to boot value");
3753 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL,
3754 "get cache usage info");
3755 cmd_AddParm(ts, "-files", CMD_FLAG, CMD_OPTIONAL, "Show cach files used as well");
3756 cmd_AddParm(ts, "-excessive", CMD_FLAG, CMD_OPTIONAL, "excessively verbose cache stats");
3758 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL,
3759 "list configured cells");
3760 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3762 ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, NULL,
3763 "list configured cell aliases");
3765 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
3766 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3767 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3769 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3771 cmd_CreateAlias(ts, "sq");
3773 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
3774 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3775 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3776 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL,
3777 "linked cell name");
3779 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
3780 "configure new cell alias");
3781 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
3782 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
3784 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3786 * Turn this on only if you wish to be able to talk to a server which is listening
3787 * on alternative ports. This is not intended for general use and may not be
3788 * supported in the cache manager. It is not a way to run two servers at the
3789 * same host, since the cache manager cannot properly distinguish those two hosts.
3791 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL,
3792 "cell's fileserver port");
3793 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL,
3794 "cell's vldb server port");
3797 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
3798 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3800 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
3801 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3803 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
3806 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, NULL, "obsolete (listed primary cell)");
3809 /* set cache monitor host address */
3810 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, (char *)CMD_HIDDEN);
3811 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL,
3812 "host name or 'off'");
3813 cmd_CreateAlias(ts, "mariner");
3815 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
3816 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3818 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
3819 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3820 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3821 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL,
3822 "disallow setuid programs");
3824 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL,
3825 "flush all data in volume");
3826 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3828 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL,
3829 "get/set sysname (i.e. @sys) value");
3830 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3832 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL,
3833 "enable/disable translators to AFS");
3834 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3835 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL,
3836 "start/stop translator (on | off)");
3837 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL,
3838 "convert from afs to unix mode (on | off)");
3839 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL,
3840 "run on strict 'uid check' mode (on | off)");
3841 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
3842 "allow nfs mounts to subdirs of /afs/.. (on | off)");
3843 cmd_AddParm(ts, "-clipags", CMD_SINGLE, CMD_OPTIONAL,
3844 "enable use of client-assigned PAG's (on | off)");
3845 cmd_AddParm(ts, "-pagcb", CMD_SINGLE, CMD_OPTIONAL,
3846 "enable callbacks to get creds from new clients (on | off)");
3849 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
3850 "store to server after file close");
3851 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL,
3852 "asynchrony for specified names");
3853 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3854 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL,
3855 "new default (KB)");
3856 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3857 cmd_CreateAlias(ts, "sb");
3859 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL,
3860 "set cache manager encryption flag");
3861 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3863 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL,
3864 "get cache manager encryption flag");
3866 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
3867 "Manage per process 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("rxstatpeer", RxStatPeerCmd, NULL,
3873 "Manage per peer RX statistics");
3874 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3875 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3876 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3878 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
3879 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
3881 /* try to find volume location information */
3882 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL,
3883 "get fid for file(s)");
3884 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3886 ts = cmd_CreateSyntax("discon", DisconCmd, NULL,
3887 "disconnection mode");
3888 cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_REQUIRED, "offline | online");
3889 cmd_AddParm(ts, "-policy", CMD_SINGLE, CMD_OPTIONAL, "client | server");
3890 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Force reconnection, despite any synchronization issues.");
3891 cmd_AddParm(ts, "-uid", CMD_SINGLE, CMD_OPTIONAL, "Numeric UID of user whose tokens to use at reconnect.");
3893 ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, NULL, "nuke credentials for NFS client");
3894 cmd_AddParm(ts, "-addr", CMD_SINGLE, 0, "host name or address");
3896 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
3897 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_REQUIRED, "generate a new UUID");
3899 ts = cmd_CreateSyntax("precache", PreCacheCmd, 0,
3900 "set precache size");
3901 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3902 "size in 1K byte blocks (0 => disable)");
3904 code = cmd_Dispatch(argc, argv);
3912 Die(int errnum, char *filename)
3918 "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3921 fprintf(stderr, "%s: Invalid argument.\n", pn);
3925 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3927 fprintf(stderr, "%s: no such file returned\n", pn);
3931 "%s: You can not change a backup or readonly volume\n", pn);
3937 "%s: You don't have the required access rights on '%s'\n",
3941 "%s: You do not have the required rights to do this operation\n",
3946 fprintf(stderr, "%s:'%s'", pn, filename);
3948 fprintf(stderr, "%s", pn);
3949 fprintf(stderr, ": %s\n", afs_error_message(errnum));
3954 /* get clients interface addresses */
3956 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3959 struct ViceIoctl blob;
3960 struct sprefrequest *in;
3961 struct sprefinfo *out;
3963 in = (struct sprefrequest *)space;
3967 blob.in_size = sizeof(struct sprefrequest);
3968 blob.in = (char *)in;
3970 blob.out_size = AFS_PIOCTL_MAXSIZE;
3973 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3974 /* returns addr in network byte order */
3975 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3977 perror("getClientInterfaceAddr pioctl");
3983 out = (struct sprefinfo *)blob.out;
3984 for (i = 0; i < out->num_servers; i++) {
3987 addr = ntohl(out->servers[i].server.s_addr);
3988 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3989 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3990 printf("%-50s\n", tbuffer);
3992 in->offset = out->next_offset;
3994 } while (out->next_offset > 0);
4000 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4002 afs_int32 code, addr;
4003 struct cmd_item *ti;
4004 struct ViceIoctl blob;
4005 struct setspref *ssp;
4006 int sizeUsed = 0, i, flag;
4007 afs_uint32 existingAddr[1024]; /* existing addresses on this host */
4011 ssp = (struct setspref *)space;
4012 ssp->num_servers = 0;
4015 blob.out_size = AFS_PIOCTL_MAXSIZE;
4018 fprintf(stderr, "Permission denied: requires root access.\n");
4022 /* extract all existing interface addresses */
4023 existNu = rx_getAllAddr(existingAddr, 1024);
4027 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
4028 for (ti = as->parms[0].items; ti; ti = ti->next) {
4029 if (sizeUsed >= sizeof(space)) {
4030 fprintf(stderr, "No more space\n");
4033 addr = extractAddr(ti->data, 20); /* network order */
4034 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
4035 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
4040 /* see if it is an address that really exists */
4041 for (flag = 0, i = 0; i < existNu; i++)
4042 if (existingAddr[i] == addr) {
4046 if (!flag) { /* this is an nonexistent address */
4047 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
4051 /* copy all specified addr into ioctl buffer */
4052 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
4053 printf("Adding 0x%08x\n", addr);
4055 sizeUsed += sizeof(struct spref);
4057 if (ssp->num_servers < 1) {
4058 fprintf(stderr, "No addresses specified\n");
4061 blob.in_size = sizeUsed - sizeof(struct spref);
4063 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
4073 FlushMountCmd(struct cmd_syndesc *as, void *arock)
4076 struct ViceIoctl blob;
4077 struct cmd_item *ti;
4078 char *last_component;
4082 for (ti = as->parms[0].items; ti; ti = ti->next) {
4083 if (GetLastComponent(ti->data, &parent_dir,
4084 &last_component, NULL) != 0) {
4089 blob.in = last_component;
4090 blob.in_size = strlen(last_component) + 1;
4093 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4095 free(last_component);
4099 if (errno == EINVAL) {
4100 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4102 Die(errno, (ti->data ? ti->data : parent_dir));
4111 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4114 afs_int32 flags = 0;
4115 struct ViceIoctl blob;
4117 if (as->parms[0].items) { /* -enable */
4118 flags |= AFSCALL_RXSTATS_ENABLE;
4120 if (as->parms[1].items) { /* -disable */
4121 flags |= AFSCALL_RXSTATS_DISABLE;
4123 if (as->parms[2].items) { /* -clear */
4124 flags |= AFSCALL_RXSTATS_CLEAR;
4127 fprintf(stderr, "You must specify at least one argument\n");
4131 blob.in = (char *)&flags;
4132 blob.in_size = sizeof(afs_int32);
4135 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4145 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4148 afs_int32 flags = 0;
4149 struct ViceIoctl blob;
4151 if (as->parms[0].items) { /* -enable */
4152 flags |= AFSCALL_RXSTATS_ENABLE;
4154 if (as->parms[1].items) { /* -disable */
4155 flags |= AFSCALL_RXSTATS_DISABLE;
4157 if (as->parms[2].items) { /* -clear */
4158 flags |= AFSCALL_RXSTATS_CLEAR;
4161 fprintf(stderr, "You must specify at least one argument\n");
4165 blob.in = (char *)&flags;
4166 blob.in_size = sizeof(afs_int32);
4169 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4179 GetFidCmd(struct cmd_syndesc *as, void *arock)
4181 struct ViceIoctl blob;
4182 struct cmd_item *ti;
4186 char cell[MAXCELLCHARS];
4188 SetDotDefault(&as->parms[0].items);
4189 for (ti = as->parms[0].items; ti; ti = ti->next) {
4190 struct VenusFid vfid;
4192 blob.out_size = sizeof(struct VenusFid);
4193 blob.out = (char *) &vfid;
4196 code = pioctl(ti->data, VIOCGETFID, &blob, 1);
4198 Die(errno,ti->data);
4203 code = GetCell(ti->data, cell);
4205 if (errno == ENOENT)
4206 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
4208 Die(errno, ti->data);
4213 printf("File %s (%u.%u.%u) located in cell %s\n",
4214 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,