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 /* added relative add resp. delete */
309 /* (so old add really means to set) */
310 enum rtype { add, destroy, deny, reladd, reldel };
313 Convert(char *arights, int dfs, enum rtype *rtypep)
317 char *tcp; /* to walk through the rights string */
319 *rtypep = add; /* add rights, by default */
321 /* analyze last character of string */
322 tcp = arights + strlen(arights);
323 if ( tcp-- > arights ) { /* assure non-empty string */
325 *rtypep = reladd; /* '+' indicates more rights */
326 else if ( *tcp == '-' )
327 *rtypep = reldel; /* '-' indicates less rights */
328 else if ( *tcp == '=' )
329 *rtypep = add; /* '=' also allows old behaviour */
331 tcp++; /* back to original null byte */
332 *tcp = '\0'; /* do not disturb old strcmp-s */
336 if (!strcmp(arights, "null")) {
340 if (!strcmp(arights, "read"))
341 return DFS_READ | DFS_EXECUTE;
342 if (!strcmp(arights, "write"))
343 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
345 if (!strcmp(arights, "all"))
346 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
347 DFS_WRITE | DFS_CONTROL;
349 if (!strcmp(arights, "read"))
350 return PRSFS_READ | PRSFS_LOOKUP;
351 if (!strcmp(arights, "write"))
352 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
353 PRSFS_WRITE | PRSFS_LOCK;
354 if (!strcmp(arights, "mail"))
355 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
356 if (!strcmp(arights, "all"))
357 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
358 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
360 if (!strcmp(arights, "none")) {
361 *rtypep = destroy; /* Remove entire entry */
366 while ((tc = *tcp++ )) {
399 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
407 mode |= PRSFS_LOOKUP;
409 mode |= PRSFS_INSERT;
411 mode |= PRSFS_DELETE;
417 mode |= PRSFS_ADMINISTER;
435 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
444 static struct AclEntry *
445 FindList(struct AclEntry *alist, char *aname)
448 if (!foldcmp(alist->name, aname))
455 /* if no parm specified in a particular slot, set parm to be "." instead */
457 SetDotDefault(struct cmd_item **aitemp)
461 return; /* already has value */
462 /* otherwise, allocate an item representing "." */
463 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
465 ti->next = (struct cmd_item *)0;
466 ti->data = (char *)malloc(2);
468 strcpy(ti->data, ".");
473 ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights,
476 struct AclEntry *tlist;
477 tlist = (plus ? al->pluslist : al->minuslist);
478 tlist = FindList(tlist, aname);
480 /* Found the item already in the list.
481 * modify rights in case of reladd and reladd only,
482 * use standard - add, ie. set - otherwise
484 if ( artypep == NULL )
485 tlist->rights = arights;
486 else if ( *artypep == reladd )
487 tlist->rights |= arights;
488 else if ( *artypep == reldel )
489 tlist->rights &= ~arights;
491 tlist->rights = arights;
494 al->nplus -= PruneList(&al->pluslist, al->dfs);
496 al->nminus -= PruneList(&al->minuslist, al->dfs);
499 if ( artypep != NULL && *artypep == reldel )
500 return; /* can't reduce non-existing rights */
502 /* Otherwise we make a new item and plug in the new data. */
503 tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry));
505 strcpy(tlist->name, aname);
506 tlist->rights = arights;
508 tlist->next = al->pluslist;
509 al->pluslist = tlist;
511 if (arights == 0 || arights == -1)
512 al->nplus -= PruneList(&al->pluslist, al->dfs);
514 tlist->next = al->minuslist;
515 al->minuslist = tlist;
518 al->nminus -= PruneList(&al->minuslist, al->dfs);
523 ZapList(struct AclEntry *alist)
525 struct AclEntry *tp, *np;
526 for (tp = alist; tp; tp = np) {
533 PruneList(struct AclEntry **ae, int dfs)
535 struct AclEntry **lp;
536 struct AclEntry *te, *ne;
540 for (te = *ae; te; te = ne) {
541 if ((!dfs && te->rights == 0) || te->rights == -1) {
557 while (*astr != '\n')
564 * Create an empty acl, taking into account whether the acl pointed
565 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
566 * can recover from problems caused by bogus ACL's (in that case, always
567 * assume that the acl is AFS: for DFS, the user can always resort to
568 * acl_edit, but for AFS there may be no other way out).
576 tp = (struct Acl *)malloc(sizeof(struct Acl));
578 tp->nplus = tp->nminus = 0;
579 tp->pluslist = tp->minuslist = 0;
581 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
588 int nplus, nminus, i, trights;
590 struct AclEntry *first, *last, *tl;
593 ta = (struct Acl *)malloc(sizeof(struct Acl));
596 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
597 astr = SkipLine(astr);
598 sscanf(astr, "%d", &ta->nminus);
599 astr = SkipLine(astr);
606 for (i = 0; i < nplus; i++) {
607 sscanf(astr, "%100s %d", tname, &trights);
608 astr = SkipLine(astr);
609 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
613 strcpy(tl->name, tname);
614 tl->rights = trights;
620 ta->pluslist = first;
624 for (i = 0; i < nminus; i++) {
625 sscanf(astr, "%100s %d", tname, &trights);
626 astr = SkipLine(astr);
627 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
631 strcpy(tl->name, tname);
632 tl->rights = trights;
638 ta->minuslist = first;
644 PrintStatus(VolumeStatus * status, char *name, char *offmsg)
646 printf("Volume status for vid = %u named %s\n", status->Vid, name);
648 printf("Current offline message is %s\n", offmsg);
649 printf("Current disk quota is ");
650 if (status->MaxQuota != 0)
651 printf("%d\n", status->MaxQuota);
653 printf("unlimited\n");
654 printf("Current blocks used are %d\n", status->BlocksInUse);
655 printf("The partition has %d blocks available out of %d\n\n",
656 status->PartBlocksAvail, status->PartMaxBlocks);
660 static const char power_letter[] = {
669 HumanPrintSpace(afs_int32 int_space)
672 int exponent_max = sizeof(power_letter) - 1;
673 float space = int_space;
675 while (space >= 1024 && exponent < exponent_max) {
679 printf("%9.1f%c", space, power_letter[exponent]);
683 QuickPrintStatus(VolumeStatus * status, char *name, int human)
685 double QuotaUsed = 0.0;
686 double PartUsed = 0.0;
688 printf("%-25.25s", name);
690 if (status->MaxQuota != 0) {
693 HumanPrintSpace(status->MaxQuota);
695 HumanPrintSpace(status->BlocksInUse);
698 printf(" %10d %10d", status->MaxQuota, status->BlocksInUse);
700 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
702 printf(" no limit ");
704 HumanPrintSpace(status->BlocksInUse);
706 printf("%10d", status->BlocksInUse);
708 if (QuotaUsed > 90.0) {
709 printf("%5.0f%%<<", QuotaUsed);
712 printf("%5.0f%% ", QuotaUsed);
715 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
717 if (PartUsed > 97.0) {
718 printf("%9.0f%%<<", PartUsed);
721 printf("%9.0f%% ", PartUsed);
723 printf(" <<WARNING\n");
730 QuickPrintSpace(VolumeStatus * status, char *name, int human)
732 double PartUsed = 0.0;
734 printf("%-25.25s", name);
737 HumanPrintSpace(status->PartMaxBlocks);
738 HumanPrintSpace(status->PartMaxBlocks - status->PartBlocksAvail);
739 HumanPrintSpace(status->PartBlocksAvail);
742 printf("%10d%10d%10d", status->PartMaxBlocks,
743 status->PartMaxBlocks - status->PartBlocksAvail,
744 status->PartBlocksAvail);
748 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
750 if (PartUsed > 90.0) {
751 printf(" %4.0f%%<<", PartUsed);
754 printf(" %4.0f%% ", PartUsed);
756 printf(" <<WARNING\n");
763 AclToString(struct Acl *acl)
765 static char mydata[AFS_PIOCTL_MAXSIZE];
766 char tstring[AFS_PIOCTL_MAXSIZE];
771 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
774 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
775 for (tp = acl->pluslist; tp; tp = tp->next) {
776 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
777 strcat(mydata, tstring);
779 for (tp = acl->minuslist; tp; tp = tp->next) {
780 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
781 strcat(mydata, tstring);
787 SetACLCmd(struct cmd_syndesc *as, void *arock)
790 struct ViceIoctl blob;
792 struct cmd_item *ti, *ui;
796 int idf = getidf(as, parm_setacl_id);
799 if (as->parms[2].items)
803 plusp = !(as->parms[3].items);
804 for (ti = as->parms[0].items; ti; ti = ti->next) {
805 blob.out_size = AFS_PIOCTL_MAXSIZE;
807 blob.in = blob.out = space;
808 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
810 Die(errno, ti->data);
817 ta = ParseAcl(space);
818 if (!plusp && ta->dfs) {
820 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
822 "(you may specify \"null\" to revoke all rights, however)\n");
830 ta = EmptyAcl(space);
832 ta = ParseAcl(space);
833 CleanAcl(ta, ti->data);
834 for (ui = as->parms[1].items; ui; ui = ui->next->next) {
838 "%s: Missing second half of user/access pair.\n", pn);
842 rights = Convert(ui->next->data, ta->dfs, &rtype);
843 if (rtype == destroy && !ta->dfs) {
844 struct AclEntry *tlist;
846 tlist = (plusp ? ta->pluslist : ta->minuslist);
847 if (!FindList(tlist, ui->data))
850 if (rtype == deny && !ta->dfs)
852 if (rtype == destroy && ta->dfs)
854 ChangeList(ta, plusp, ui->data, rights, &rtype);
856 blob.in = AclToString(ta);
858 blob.in_size = 1 + strlen(blob.in);
859 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
861 if (errno == EINVAL) {
863 static char *fsenv = 0;
865 fsenv = (char *)getenv("FS_EXPERT");
868 "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n",
872 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
873 "\nPossible reasons for this include:\n\n",
874 " -You may have specified an inappropriate combination of rights.\n",
875 " For example, some DFS-supported filesystems may not allow you to\n",
876 " drop the \"c\" right from \"user_obj\".\n\n",
877 " -A mask_obj may be required (it is likely required by the underlying\n",
878 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
879 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
880 " does not automatically create or update the mask_obj. Try setting\n",
881 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
882 " users or groups. You can do this with a single command, such as\n",
883 " \"fs sa mask_obj all user:somename read\"\n\n",
884 " -A specified user or group may not exist.\n\n",
885 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
886 " This is probably not allowed by the underlying file system.\n\n",
887 " -If you add a user or group to a DFS ACL, remember that it must be\n",
888 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
889 " may be local requirements on the format of the user or group name.\n",
890 " Check with your cell administrator.\n\n",
891 " -Or numerous other possibilities. It would be great if we could be more\n",
892 " precise about the actual problem, but for various reasons, this is\n",
893 " impractical via this interface. If you can't figure it out, you\n",
894 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
895 " whatever is provided). You may get better results. Good luck!\n\n",
896 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
900 "%s: Invalid argument, possible reasons include:\n",
902 fprintf(stderr, "\t-File not in AFS\n");
904 "\t-Too many users on access control list\n");
906 "\t-Tried to add non-existent user to access control list\n");
909 Die(errno, ti->data);
921 CopyACLCmd(struct cmd_syndesc *as, void *arock)
924 struct ViceIoctl blob;
925 struct Acl *fa, *ta = 0;
929 int idf = getidf(as, parm_copyacl_id);
932 if (as->parms[2].items)
936 blob.out_size = AFS_PIOCTL_MAXSIZE;
938 blob.in = blob.out = space;
939 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
941 Die(errno, as->parms[0].items->data);
944 fa = ParseAcl(space);
945 CleanAcl(fa, as->parms[0].items->data);
946 for (ti = as->parms[1].items; ti; ti = ti->next) {
947 blob.out_size = AFS_PIOCTL_MAXSIZE;
949 blob.in = blob.out = space;
950 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
952 Die(errno, ti->data);
960 ta = EmptyAcl(space);
962 ta = ParseAcl(space);
963 CleanAcl(ta, ti->data);
964 if (ta->dfs != fa->dfs) {
966 "%s: incompatible file system types: acl not copied to %s; aborted\n",
972 if (!clear && strcmp(ta->cell, fa->cell) != 0) {
974 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
979 strcpy(ta->cell, fa->cell);
981 /* NULL rtype for standard handling */
982 for (tp = fa->pluslist; tp; tp = tp->next)
983 ChangeList(ta, 1, tp->name, tp->rights, NULL);
984 for (tp = fa->minuslist; tp; tp = tp->next)
985 ChangeList(ta, 0, tp->name, tp->rights, NULL);
986 blob.in = AclToString(ta);
988 blob.in_size = 1 + strlen(blob.in);
989 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
991 if (errno == EINVAL) {
993 "%s: Invalid argument, possible reasons include:\n",
995 fprintf(stderr, "\t-File not in AFS\n");
997 Die(errno, ti->data);
1008 /* pioctl() call to get the cellname of a pathname */
1010 GetCell(char *fname, char *cellname)
1013 struct ViceIoctl blob;
1016 blob.out_size = MAXCELLCHARS;
1017 blob.out = cellname;
1019 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1020 return code ? errno : 0;
1023 /* Check if a username is valid: If it contains only digits (or a
1024 * negative sign), then it might be bad. We then query the ptserver
1028 BadName(char *aname, char *fname)
1030 afs_int32 tc, code, id;
1032 char cell[MAXCELLCHARS];
1034 for (nm = aname; (tc = *nm); nm++) {
1035 /* all must be '-' or digit to be bad */
1036 if (tc != '-' && (tc < '0' || tc > '9'))
1040 /* Go to the PRDB and see if this all number username is valid */
1041 code = GetCell(fname, cell);
1045 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
1046 code = pr_SNameToId(aname, &id);
1049 /* 1=>Not-valid; 0=>Valid */
1050 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1054 /* clean up an access control list of its bad entries; return 1 if we made
1055 any changes to the list, and 0 otherwise */
1057 CleanAcl(struct Acl *aa, char *fname)
1059 struct AclEntry *te, **le, *ne;
1062 /* Don't correct DFS ACL's for now */
1066 /* prune out bad entries */
1067 changes = 0; /* count deleted entries */
1069 for (te = aa->pluslist; te; te = ne) {
1071 if (BadName(te->name, fname)) {
1081 le = &aa->minuslist;
1082 for (te = aa->minuslist; te; te = ne) {
1084 if (BadName(te->name, fname)) {
1098 /* clean up an acl to not have bogus entries */
1100 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1104 struct ViceIoctl blob;
1106 struct cmd_item *ti;
1107 struct AclEntry *te;
1110 SetDotDefault(&as->parms[0].items);
1111 for (ti = as->parms[0].items; ti; ti = ti->next) {
1112 blob.out_size = AFS_PIOCTL_MAXSIZE;
1115 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1117 Die(errno, ti->data);
1124 ta = ParseAcl(space);
1127 "%s: cleanacl is not supported for DFS access lists.\n",
1133 changes = CleanAcl(ta, ti->data);
1136 /* now set the acl */
1137 blob.in = AclToString(ta);
1138 blob.in_size = strlen(blob.in) + 1;
1140 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1142 if (errno == EINVAL) {
1144 "%s: Invalid argument, possible reasons include\n",
1146 fprintf(stderr, "%s: File not in vice or\n", pn);
1148 "%s: Too many users on access control list or\n",
1151 Die(errno, ti->data);
1157 /* now list the updated acl */
1158 printf("Access list for %s is now\n", ti->data);
1159 if (ta->nplus > 0) {
1161 printf("Normal rights:\n");
1162 for (te = ta->pluslist; te; te = te->next) {
1163 printf(" %s ", te->name);
1164 PRights(te->rights, ta->dfs);
1168 if (ta->nminus > 0) {
1169 printf("Negative rights:\n");
1170 for (te = ta->minuslist; te; te = te->next) {
1171 printf(" %s ", te->name);
1172 PRights(te->rights, ta->dfs);
1179 printf("Access list for %s is fine.\n", ti->data);
1187 ListACLCmd(struct cmd_syndesc *as, void *arock)
1191 struct ViceIoctl blob;
1192 struct AclEntry *te;
1193 struct cmd_item *ti;
1194 int idf = getidf(as, parm_listacl_id);
1197 SetDotDefault(&as->parms[0].items);
1198 for (ti = as->parms[0].items; ti; ti = ti->next) {
1199 blob.out_size = AFS_PIOCTL_MAXSIZE;
1201 blob.in = blob.out = space;
1202 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1204 Die(errno, ti->data);
1208 ta = ParseAcl(space);
1209 if (as->parms[3].items) { /* -cmd */
1210 printf("fs setacl -dir %s -acl ", ti->data);
1211 if (ta->nplus > 0) {
1212 for (te = ta->pluslist; te; te = te->next) {
1213 printf(" %s ", te->name);
1214 PRights(te->rights, ta->dfs);
1218 if (ta->nminus > 0) {
1219 printf("fs setacl -dir %s -acl ", ti->data);
1220 for (te = ta->minuslist; te; te = te->next) {
1221 printf(" %s ", te->name);
1222 PRights(te->rights, ta->dfs);
1224 printf(" -negative\n");
1229 printf("Access list for %s is\n", ti->data);
1232 printf("DFS access list for %s is\n", ti->data);
1235 printf("DFS initial directory access list of %s is\n", ti->data);
1238 printf("DFS initial file access list of %s is\n", ti->data);
1242 printf(" Default cell = %s\n", ta->cell);
1244 if (ta->nplus > 0) {
1246 printf("Normal rights:\n");
1247 for (te = ta->pluslist; te; te = te->next) {
1248 printf(" %s ", te->name);
1249 PRights(te->rights, ta->dfs);
1253 if (ta->nminus > 0) {
1254 printf("Negative rights:\n");
1255 for (te = ta->minuslist; te; te = te->next) {
1256 printf(" %s ", te->name);
1257 PRights(te->rights, ta->dfs);
1270 GetCallerAccess(struct cmd_syndesc *as, void *arock)
1272 struct cmd_item *ti;
1275 SetDotDefault(&as->parms[0].items);
1276 for (ti = as->parms[0].items; ti; ti = ti->next) {
1278 struct ViceIoctl blob;
1279 struct vcxstat2 stat;
1280 blob.out_size = sizeof(struct vcxstat2);
1282 blob.out = (void *)&stat;
1283 code = pioctl(ti->data, VIOC_GETVCXSTATUS2, &blob, 1);
1285 Die(errno, ti->data);
1289 printf("Callers access to %s is ", ti->data);
1290 PRights(stat.callerAccess, 0);
1297 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1300 struct ViceIoctl blob;
1301 struct cmd_item *ti;
1304 SetDotDefault(&as->parms[0].items);
1305 for (ti = as->parms[0].items; ti; ti = ti->next) {
1306 blob.in_size = blob.out_size = 0;
1307 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1309 fprintf(stderr, "Error flushing volume ");
1319 * The Windows version of UuidCmd displays the UUID.
1320 * When the UNIX version is updated to do the same
1321 * be sure to replace the CMD_REQUIRED flag with
1322 * CMD_OPTIONAL in the cmd_AddParam(-generate) call
1325 UuidCmd(struct cmd_syndesc *as, void *arock)
1328 struct ViceIoctl blob;
1333 if (as->parms[0].items) {
1335 fprintf (stderr, "Permission denied: requires root access.\n");
1339 /* generate new UUID */
1340 code = pioctl(0, VIOC_NEWUUID, &blob, 1);
1347 printf("New uuid generated.\n");
1349 /* This will never execute */
1350 printf("Please add the '-generate' option to generate a new UUID.\n");
1355 #if defined(AFS_CACHE_BYPASS)
1357 * Set cache-bypass threshold. Files larger than this size will not be cached.
1358 * With a threshold of 0, the cache is always bypassed. With a threshold of -1,
1359 * cache bypass is disabled.
1363 BypassThresholdCmd(struct cmd_syndesc *as, void *arock)
1366 struct ViceIoctl blob;
1367 afs_int32 threshold_i, threshold_o;
1370 /* if new threshold supplied, then set and confirm, else,
1371 * get current threshold and print
1374 if(as->parms[0].items) {
1377 tp = as->parms[0].items->data;
1380 if (!strcmp(tp,"-1")) {
1384 for(ix = 0; ix < len; ++ix) {
1385 if(!isdigit(tp[0])) {
1391 fprintf(stderr, "fs bypassthreshold -size: %s must be an integer between -1 and 2^31\n", tp);
1394 threshold_i = atoi(tp);
1395 if(ix > 9 && threshold_i < 2147483647)
1396 threshold_i = 2147483647;
1398 blob.in = (char *) &threshold_i;
1399 blob.in_size = sizeof(threshold_i);
1405 blob.out = (char *) &threshold_o;
1406 blob.out_size = sizeof(threshold_o);
1407 code = pioctl(0, VIOC_SETBYPASS_THRESH, &blob, 1);
1412 printf("Cache bypass threshold %d", threshold_o);
1413 if(threshold_o == -1)
1414 printf(" (disabled)");
1424 FlushCmd(struct cmd_syndesc *as, void *arock)
1427 struct ViceIoctl blob;
1428 struct cmd_item *ti;
1431 for (ti = as->parms[0].items; ti; ti = ti->next) {
1432 blob.in_size = blob.out_size = 0;
1433 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1435 if (errno == EMFILE) {
1436 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1439 fprintf(stderr, "%s: Error flushing file ", pn);
1449 /* all this command does is repackage its args and call SetVolCmd */
1451 SetQuotaCmd(struct cmd_syndesc *as, void *arock)
1453 struct cmd_syndesc ts;
1455 /* copy useful stuff from our command slot; we may later have to reorder */
1456 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1457 return SetVolCmd(&ts, arock);
1461 SetVolCmd(struct cmd_syndesc *as, void *arock)
1464 struct ViceIoctl blob;
1465 struct cmd_item *ti;
1466 struct VolumeStatus *status;
1467 char *offmsg, *input;
1470 SetDotDefault(&as->parms[0].items);
1471 for (ti = as->parms[0].items; ti; ti = ti->next) {
1473 blob.out_size = AFS_PIOCTL_MAXSIZE;
1474 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1477 status = (VolumeStatus *) space;
1478 status->MinQuota = status->MaxQuota = -1;
1480 if (as->parms[1].items) {
1481 code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota);
1483 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1488 if (as->parms[2].items)
1489 offmsg = as->parms[2].items->data;
1490 input = (char *)status + sizeof(*status);
1491 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1493 if (strlen(offmsg) >= VMSGSIZE) {
1495 "%s: message must be shorter than %d characters\n",
1500 strcpy(input, offmsg);
1501 blob.in_size += strlen(offmsg);
1502 input += strlen(offmsg) + 1;
1505 *(input++) = '\0'; /* Pad for old style volume "motd" */
1506 code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1);
1508 Die(errno, ti->data);
1516 * Why is VenusFid declared in the kernel-only section of afs.h,
1517 * if it's the exported interface of the cache manager?
1525 ExamineCmd(struct cmd_syndesc *as, void *arock)
1528 struct ViceIoctl blob;
1529 struct cmd_item *ti;
1530 struct VolumeStatus *status;
1531 char *name, *offmsg;
1534 SetDotDefault(&as->parms[0].items);
1535 for (ti = as->parms[0].items; ti; ti = ti->next) {
1536 struct VenusFid vfid;
1539 blob.out_size = AFS_PIOCTL_MAXSIZE;
1542 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1544 Die(errno, ti->data);
1548 status = (VolumeStatus *) space;
1549 name = (char *)status + sizeof(*status);
1550 offmsg = name + strlen(name) + 1;
1552 blob.out_size = sizeof(struct VenusFid);
1553 blob.out = (char *) &vfid;
1554 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1555 printf("File %s (%u.%u.%u) contained in volume %u\n",
1556 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1560 PrintStatus(status, name, offmsg);
1566 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1569 struct ViceIoctl blob;
1570 struct cmd_item *ti;
1571 struct VolumeStatus *status;
1576 if (as->parms[1].items)
1579 printf("%-25s%-11s%-11s%-7s%-11s\n", "Volume Name", " Quota",
1580 " Used", " %Used", " Partition");
1581 SetDotDefault(&as->parms[0].items);
1582 for (ti = as->parms[0].items; ti; ti = ti->next) {
1584 blob.out_size = AFS_PIOCTL_MAXSIZE;
1587 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1589 Die(errno, ti->data);
1593 status = (VolumeStatus *) space;
1594 name = (char *)status + sizeof(*status);
1595 QuickPrintStatus(status, name, human);
1601 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1604 struct ViceIoctl blob;
1605 struct cmd_item *ti;
1611 SetDotDefault(&as->parms[0].items);
1612 for (ti = as->parms[0].items; ti; ti = ti->next) {
1614 blob.out_size = AFS_PIOCTL_MAXSIZE;
1617 memset(space, 0, sizeof(space));
1618 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1620 Die(errno, ti->data);
1624 hosts = (afs_int32 *) space;
1625 printf("File %s is on host%s ", ti->data,
1626 (hosts[0] && !hosts[1]) ? "" : "s");
1627 for (j = 0; j < AFS_MAXHOSTS; j++) {
1630 tp = hostutil_GetNameByINet(hosts[j]);
1640 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1643 struct ViceIoctl blob;
1644 struct cmd_item *ti;
1646 struct VolumeStatus *status;
1650 if (as->parms[1].items)
1653 printf("%-25s%10s%10s%10s%6s\n", "Volume Name",
1654 human ? "total" : "kbytes", "used", "avail", "%used");
1655 SetDotDefault(&as->parms[0].items);
1656 for (ti = as->parms[0].items; ti; ti = ti->next) {
1658 blob.out_size = AFS_PIOCTL_MAXSIZE;
1661 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1663 Die(errno, ti->data);
1667 status = (VolumeStatus *) space;
1668 name = (char *)status + sizeof(*status);
1669 QuickPrintSpace(status, name, human);
1675 QuotaCmd(struct cmd_syndesc *as, void *arock)
1678 struct ViceIoctl blob;
1679 struct cmd_item *ti;
1681 struct VolumeStatus *status;
1684 SetDotDefault(&as->parms[0].items);
1685 for (ti = as->parms[0].items; ti; ti = ti->next) {
1687 blob.out_size = AFS_PIOCTL_MAXSIZE;
1690 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1692 Die(errno, ti->data);
1696 status = (VolumeStatus *) space;
1697 if (status->MaxQuota)
1699 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
1702 printf("%2.0f%% of quota used.\n", quotaPct);
1708 GetLastComponent(const char *data, char **outdir, char **outbase,
1711 char orig_name[1024]; /*Original name, may be modified */
1712 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
1714 struct stat statbuff; /*Buffer for status info */
1715 int link_chars_read; /*Num chars read in readlink() */
1716 char *dirname = NULL;
1717 char *basename = NULL;
1722 snprintf(orig_name, sizeof(orig_name), "%s%s",
1723 (data[0] == '/') ? "" : "./", data);
1725 if (lstat(orig_name, &statbuff) < 0) {
1726 /* if lstat fails, we should still try the pioctl, since it
1727 * may work (for example, lstat will fail, but pioctl will
1728 * work if the volume of offline (returning ENODEV). */
1729 statbuff.st_mode = S_IFDIR; /* lie like pros */
1733 * The lstat succeeded. If the given file is a symlink, substitute
1734 * the file name with the link name.
1736 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1740 /* Read name of resolved file */
1741 link_chars_read = readlink(orig_name, true_name, 1024);
1742 if (link_chars_read <= 0) {
1744 "%s: Can't read target name for '%s' symbolic link!\n",
1749 /* Add a trailing null to what was read, bump the length. */
1750 true_name[link_chars_read++] = 0;
1753 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1754 * have to create a full pathname using the original name and the
1755 * relative symlink name. Find the rightmost slash in the original
1756 * name (we know there is one) and splice in the symlink value.
1758 if (true_name[0] != '/') {
1759 lastSlash = strrchr(orig_name, '/');
1760 strcpy(++lastSlash, true_name);
1761 strcpy(true_name, orig_name);
1764 strcpy(true_name, orig_name);
1767 /* Find rightmost slash, if any. */
1768 lastSlash = strrchr(true_name, '/');
1769 if (lastSlash == true_name) {
1770 dirname = strdup("/");
1771 basename = strdup(lastSlash+1);
1772 } else if (lastSlash != NULL) {
1774 * Found it. Designate everything before it as the parent directory,
1775 * everything after it as the final component.
1778 dirname = strdup(true_name);
1779 basename = strdup(lastSlash+1);
1782 * No slash appears in the given file name. Set parent_dir to the current
1783 * directory, and the last component as the given name.
1785 dirname = strdup(".");
1786 basename = strdup(true_name);
1789 if (strcmp(basename, ".") == 0
1790 || strcmp(basename, "..") == 0) {
1792 "%s: you may not use '.' or '..' as the last component\n", pn);
1793 fprintf(stderr, "%s: of a name in this fs command.\n", pn);
1798 *outbase = basename;
1812 ListMountCmd(struct cmd_syndesc *as, void *arock)
1815 struct ViceIoctl blob;
1816 struct cmd_item *ti;
1817 char *last_component;
1819 int thru_symlink = 0;
1822 for (ti = as->parms[0].items; ti; ti = ti->next) {
1823 if (GetLastComponent(ti->data, &parent_dir,
1824 &last_component, &thru_symlink) != 0) {
1829 blob.in = last_component;
1830 blob.in_size = strlen(last_component) + 1;
1831 blob.out_size = AFS_PIOCTL_MAXSIZE;
1833 memset(space, 0, AFS_PIOCTL_MAXSIZE);
1835 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1836 free(last_component);
1840 printf("'%s' is a %smount point for volume '%s'\n", ti->data,
1841 (thru_symlink ? "symbolic link, leading to a " : ""),
1844 if (errno == EINVAL) {
1845 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
1847 Die(errno, (ti->data ? ti->data : parent_dir));
1856 MakeMountCmd(struct cmd_syndesc *as, void *arock)
1859 char *cellName, *volName, *tmpName;
1860 struct afsconf_cell info;
1861 struct vldbentry vldbEntry;
1862 struct ViceIoctl blob;
1868 if (as->parms[5].items && !as->parms[2].items) {
1869 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1874 if (as->parms[2].items) /* cell name specified */
1875 cellName = as->parms[2].items->data;
1878 volName = as->parms[1].items->data;
1880 if (strlen(volName) >= 64) {
1882 "%s: volume name too long (length must be < 64 characters)\n",
1887 /* Check for a cellname in the volume specification, and complain
1888 * if it doesn't match what was specified with -cell */
1889 if ((tmpName = strchr(volName, ':'))) {
1892 if (strcasecmp(cellName, volName)) {
1893 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1898 volName = ++tmpName;
1901 if (!InAFS(Parent(as->parms[0].items->data))) {
1903 "%s: mount points must be created within the AFS file system\n",
1910 blob.out_size = AFS_PIOCTL_MAXSIZE;
1913 pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME,
1917 code = GetCellName(cellName ? cellName : space, &info);
1921 if (!(as->parms[4].items)) {
1922 /* not fast, check which cell the mountpoint is being created in */
1923 /* not fast, check name with VLDB */
1924 code = VLDBInit(1, &info);
1926 /* make the check. Don't complain if there are problems with init */
1928 ubik_VL_GetEntryByNameO(uclient, 0, volName,
1930 if (code == VL_NOENT) {
1932 "%s: warning, volume %s does not exist in cell %s.\n",
1933 pn, volName, cellName ? cellName : space);
1938 if (as->parms[3].items) /* if -rw specified */
1943 /* cellular mount point, prepend cell prefix */
1944 strcat(space, info.name);
1947 strcat(space, volName); /* append volume name */
1948 strcat(space, "."); /* stupid convention; these end with a period */
1949 code = symlink(space, as->parms[0].items->data);
1951 Die(errno, as->parms[0].items->data);
1958 * Delete AFS mount points. Variables are used as follows:
1959 * tbuffer: Set to point to the null-terminated directory name of the mount point
1960 * (or ``.'' if none is provided)
1961 * tp: Set to point to the actual name of the mount point to nuke.
1964 RemoveMountCmd(struct cmd_syndesc *as, void *arock)
1967 struct ViceIoctl blob;
1968 struct cmd_item *ti;
1970 char lsbuffer[1024];
1974 for (ti = as->parms[0].items; ti; ti = ti->next) {
1976 tp = (char *)strrchr(ti->data, '/');
1978 strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */
1980 tp++; /* skip the slash */
1982 strcpy(tbuffer, ".");
1986 blob.in_size = strlen(tp) + 1;
1987 blob.out = lsbuffer;
1988 blob.out_size = sizeof(lsbuffer);
1989 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 1);
1991 if (errno == EINVAL) {
1992 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
1995 Die(errno, ti->data);
1998 continue; /* don't bother trying */
2002 blob.in_size = strlen(tp) + 1;
2003 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 1);
2005 Die(errno, ti->data);
2016 CheckServersCmd(struct cmd_syndesc *as, void *arock)
2019 struct ViceIoctl blob;
2023 struct afsconf_cell info;
2024 struct chservinfo checkserv;
2026 memset(&checkserv, 0, sizeof(struct chservinfo));
2027 blob.in_size = sizeof(struct chservinfo);
2028 blob.in = (caddr_t) & checkserv;
2030 blob.out_size = AFS_PIOCTL_MAXSIZE;
2032 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2034 /* prepare flags for checkservers command */
2035 temp = 2; /* default to checking local cell only */
2036 if (as->parms[2].items)
2037 temp |= 1; /* set fast flag */
2038 if (as->parms[1].items)
2039 temp &= ~2; /* turn off local cell check */
2041 checkserv.magic = 0x12345678; /* XXX */
2042 checkserv.tflags = temp;
2044 /* now copy in optional cell name, if specified */
2045 if (as->parms[0].items) {
2046 code = GetCellName(as->parms[0].items->data, &info);
2050 strcpy(checkserv.tbuffer, info.name);
2051 checkserv.tsize = strlen(info.name) + 1;
2053 strcpy(checkserv.tbuffer, "\0");
2054 checkserv.tsize = 0;
2057 if (as->parms[3].items) {
2058 checkserv.tinterval = atol(as->parms[3].items->data);
2061 if (checkserv.tinterval < 0) {
2063 ("Warning: The negative -interval is ignored; treated as an inquiry\n");
2064 checkserv.tinterval = 0;
2065 } else if (checkserv.tinterval > 600) {
2067 ("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2068 checkserv.tinterval = 600; /* 10 min max interval */
2071 checkserv.tinterval = -1; /* don't change current interval */
2074 code = pioctl(0, VIOCCKSERV, &blob, 1);
2076 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2077 printf("Must be root to change -interval\n");
2083 memcpy(&temp, space, sizeof(afs_int32));
2084 if (checkserv.tinterval >= 0) {
2085 if (checkserv.tinterval > 0)
2087 ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2088 checkserv.tinterval, temp);
2090 printf("The current down server probe interval is %d secs\n",
2095 printf("All servers are running.\n");
2098 ("These servers unavailable due to network or server problems: ");
2100 memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32));
2103 tp = hostutil_GetNameByINet(temp);
2113 MessagesCmd(struct cmd_syndesc *as, void *arock)
2116 struct ViceIoctl blob;
2117 struct gaginfo gagflags;
2118 struct cmd_item *show;
2120 memset(&gagflags, 0, sizeof(struct gaginfo));
2121 blob.in_size = sizeof(struct gaginfo);
2122 blob.in = (caddr_t) & gagflags;
2123 blob.out_size = AFS_PIOCTL_MAXSIZE;
2125 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2127 if ((show = as->parms[0].items)) {
2128 if (!strcasecmp(show->data, "user"))
2129 gagflags.showflags |= GAGUSER;
2130 else if (!strcasecmp(show->data, "console"))
2131 gagflags.showflags |= GAGCONSOLE;
2132 else if (!strcasecmp(show->data, "all"))
2133 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2134 else if (!strcasecmp(show->data, "none"))
2138 "unrecognized flag %s: must be in {user,console,all,none}\n",
2147 code = pioctl(0, VIOC_GAG, &blob, 1);
2157 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2160 struct ViceIoctl blob;
2164 code = pioctl(0, VIOCCKBACK, &blob, 1);
2170 printf("All volumeID/name mappings checked.\n");
2175 PreCacheCmd(struct cmd_syndesc *as, void *arock)
2178 struct ViceIoctl blob;
2181 if (!as->parms[0].items && !as->parms[1].items) {
2182 fprintf(stderr, "%s: syntax error in precache cmd.\n", pn);
2185 if (as->parms[0].items) {
2186 code = util_GetInt32(as->parms[0].items->data, &temp);
2188 fprintf(stderr, "%s: bad integer specified for precache size.\n",
2194 blob.in = (char *)&temp;
2195 blob.in_size = sizeof(afs_int32);
2197 code = pioctl(0, VIOCPRECACHE, &blob, 1);
2203 printf("New precache size set.\n");
2208 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2211 struct ViceIoctl blob;
2214 if (!as->parms[0].items && !as->parms[1].items) {
2215 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
2218 if (as->parms[0].items) {
2219 code = util_GetHumanInt32(as->parms[0].items->data, &temp);
2221 fprintf(stderr, "%s: bad integer specified for cache size.\n",
2227 blob.in = (char *)&temp;
2228 blob.in_size = sizeof(afs_int32);
2230 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2232 if (errno == EROFS) {
2234 ("'fs setcache' not allowed on memory cache based cache managers.\n");
2241 printf("New cache size set.\n");
2245 #define MAXGCSIZE 16
2247 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2249 afs_int32 code, filesUsed;
2250 struct ViceIoctl blob;
2251 afs_int32 parms[MAXGCSIZE];
2252 double percentFiles, percentBlocks;
2253 afs_int32 flags = 0;
2255 if (as->parms[0].items){ /* -files */
2257 } else if (as->parms[1].items){ /* -excessive */
2263 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
2265 blob.in = (char *)&flags;
2266 blob.in_size = sizeof(afs_int32);
2267 } else { /* be backward compatible */
2271 blob.out_size = sizeof(parms);
2272 blob.out = (char *)parms;
2273 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2280 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2281 parms[1], parms[0]);
2282 if (parms[1] > parms[0])
2283 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2287 percentBlocks = ((double)parms[1]/parms[0]) * 100;
2288 printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n",
2289 percentBlocks, parms[1], parms[0]);
2294 filesUsed = parms[2] - parms[3];
2295 percentFiles = ((double)filesUsed/parms[2]) * 100;
2296 printf(" %5.0f%% of the cache files (%d of %d files)\n",
2297 percentFiles, filesUsed, parms[2]);
2299 printf(" afs_cacheFiles: %10d\n", parms[2]);
2300 printf(" IFFree: %10d\n", parms[3]);
2301 printf(" IFEverUsed: %10d\n", parms[4]);
2302 printf(" IFDataMod: %10d\n", parms[5]);
2303 printf(" IFDirtyPages: %10d\n", parms[6]);
2304 printf(" IFAnyPages: %10d\n", parms[7]);
2305 printf(" IFDiscarded: %10d\n", parms[8]);
2306 printf(" DCentries: %10d\n", parms[9]);
2307 printf(" 0k- 4K: %10d\n", parms[10]);
2308 printf(" 4k- 16k: %10d\n", parms[11]);
2309 printf(" 16k- 64k: %10d\n", parms[12]);
2310 printf(" 64k- 256k: %10d\n", parms[13]);
2311 printf(" 256k- 1M: %10d\n", parms[14]);
2312 printf(" >=1M: %10d\n", parms[15]);
2315 if (percentBlocks > 90)
2316 printf("[cache size usage over 90%%, consider increasing cache size]\n");
2317 if (percentFiles > 90)
2318 printf("[cache file usage over 90%%, consider increasing '-files' argument to afsd]\n");
2324 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2329 struct ViceIoctl blob;
2332 resolve = !(as->parms[0].items); /* -numeric */
2336 memcpy(tp, &i, sizeof(afs_int32));
2337 blob.out_size = AFS_PIOCTL_MAXSIZE;
2338 blob.in_size = sizeof(afs_int32);
2341 code = pioctl(0, VIOCGETCELL, &blob, 1);
2344 break; /* done with the list */
2349 printf("Cell %s on hosts", tp + AFS_MAXCELLHOSTS * sizeof(afs_int32));
2350 for (j = 0; j < AFS_MAXCELLHOSTS; j++) {
2352 char *name, tbuffer[20];
2354 memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32));
2359 name = hostutil_GetNameByINet(addr);
2362 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2363 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2366 printf(" %s", name);
2374 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2377 char *tp, *aliasName, *realName;
2378 struct ViceIoctl blob;
2382 memcpy(tp, &i, sizeof(afs_int32));
2383 blob.out_size = AFS_PIOCTL_MAXSIZE;
2384 blob.in_size = sizeof(afs_int32);
2387 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2390 break; /* done with the list */
2396 tp += strlen(aliasName) + 1;
2398 printf("Alias %s for cell %s\n", aliasName, realName);
2404 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2407 struct ViceIoctl blob;
2408 struct cmd_item *ti;
2410 struct hostent *thp;
2412 ti = as->parms[0].items;
2414 thp = hostutil_GetHostByName(ti->data);
2416 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2419 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2421 hostAddr = 0; /* means don't set host */
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_CBADDR, &blob, 1);
2439 NukeNFSCredsCmd(struct cmd_syndesc *as, void *arock)
2442 struct ViceIoctl blob;
2443 struct cmd_item *ti;
2445 struct hostent *thp;
2447 ti = as->parms[0].items;
2448 thp = hostutil_GetHostByName(ti->data);
2450 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2453 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2455 /* now do operation */
2456 blob.in_size = sizeof(afs_int32);
2457 blob.out_size = sizeof(afs_int32);
2458 blob.in = (char *) &hostAddr;
2459 blob.out = (char *) &hostAddr;
2461 code = pioctl(0, VIOC_NFS_NUKE_CREDS, &blob, 1);
2470 NewCellCmd(struct cmd_syndesc *as, void *arock)
2472 afs_int32 code, linkedstate = 0, size = 0, *lp;
2473 struct ViceIoctl blob;
2474 struct cmd_item *ti;
2475 char *tp, *cellname = 0;
2476 struct hostent *thp;
2477 afs_int32 fsport = 0, vlport = 0;
2478 afs_int32 scount; /* Number of servers to pass in pioctl call */
2481 * With the NEWCELL pioctl call, 3.4 clients take an array of
2482 * AFS_MAXHOSTS (13) servers while 3.5 clients take an array of
2483 * AFS_MAXCELLHOSTS (8) servers. To determine which we are talking to,
2484 * do a GETCELL pioctl and pass it a magic number. If an array of
2485 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
2486 * If we get back EDOM, there are no cells in the kernel yet,
2487 * and we'll assume a 3.5 client.
2490 lp = (afs_int32 *) tp;
2491 *lp++ = 0; /* first cell entry */
2492 *lp = 0x12345678; /* magic */
2493 blob.out_size = AFS_PIOCTL_MAXSIZE;
2494 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
2497 code = pioctl(0, VIOCGETCELL, &blob, 1);
2498 if (code < 0 && errno != EDOM) {
2502 if (code < 1 && errno == EDOM) {
2503 scount = AFS_MAXHOSTS;
2506 cellname = tp + AFS_MAXCELLHOSTS * sizeof(afs_int32);
2507 scount = ((cellname[0] != '\0') ? AFS_MAXCELLHOSTS : AFS_MAXHOSTS);
2510 /* Now setup and do the NEWCELL pioctl call */
2511 memset(space, 0, (scount + 1) * sizeof(afs_int32));
2513 lp = (afs_int32 *) tp;
2515 tp += sizeof(afs_int32);
2516 for (ti = as->parms[1].items; ti; ti = ti->next) {
2517 thp = hostutil_GetHostByName(ti->data);
2520 "%s: Host %s not found in host table, skipping it.\n", pn,
2523 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2524 tp += sizeof(afs_int32);
2527 if (as->parms[2].items) {
2529 * Link the cell, for the purposes of volume location, to the specified
2532 cellname = as->parms[2].items->data;
2535 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2536 if (as->parms[3].items) {
2537 code = util_GetInt32(as->parms[3].items->data, &vlport);
2540 "%s: bad integer specified for the fileserver port.\n",
2545 if (as->parms[4].items) {
2546 code = util_GetInt32(as->parms[4].items->data, &fsport);
2549 "%s: bad integer specified for the vldb server port.\n",
2555 tp = (char *)(space + (scount + 1) * sizeof(afs_int32));
2556 lp = (afs_int32 *) tp;
2560 strcpy(space + ((scount + 4) * sizeof(afs_int32)),
2561 as->parms[0].items->data);
2562 size = ((scount + 4) * sizeof(afs_int32))
2563 + strlen(as->parms[0].items->data)
2564 + 1 /* for null */ ;
2565 tp = (char *)(space + size);
2567 strcpy(tp, cellname);
2568 size += strlen(cellname) + 1;
2570 blob.in_size = size;
2573 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2582 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2585 struct ViceIoctl blob;
2587 char *aliasName, *realName;
2589 /* Now setup and do the NEWCELL pioctl call */
2590 aliasName = as->parms[0].items->data;
2591 realName = as->parms[1].items->data;
2593 strcpy(tp, aliasName);
2594 tp += strlen(aliasName) + 1;
2595 strcpy(tp, realName);
2596 tp += strlen(realName) + 1;
2598 blob.in_size = tp - space;
2602 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2604 if (errno == EEXIST) {
2606 "%s: cell name `%s' in use by an existing cell.\n", pn,
2617 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2620 struct cmd_item *ti;
2622 char cell[MAXCELLCHARS];
2624 SetDotDefault(&as->parms[0].items);
2625 for (ti = as->parms[0].items; ti; ti = ti->next) {
2626 code = GetCell(ti->data, cell);
2628 if (errno == ENOENT)
2629 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
2631 Die(errno, ti->data);
2636 printf("File %s lives in cell '%s'\n", ti->data, cell);
2642 WSCellCmd(struct cmd_syndesc *as, void *arock)
2645 struct ViceIoctl blob;
2649 blob.out_size = AFS_PIOCTL_MAXSIZE;
2652 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2658 printf("This workstation belongs to cell '%s'\n", space);
2663 static PrimaryCellCmd(as)
2664 struct cmd_syndesc *as;
2666 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2672 MonitorCmd(struct cmd_syndesc *as, void *arock)
2675 struct ViceIoctl blob;
2676 struct cmd_item *ti;
2678 struct hostent *thp;
2682 ti = as->parms[0].items;
2686 if (!strcmp(ti->data, "off"))
2687 hostAddr = 0xffffffff;
2689 thp = hostutil_GetHostByName(ti->data);
2691 if (!strcmp(ti->data, "localhost")) {
2693 "localhost not in host table, assuming 127.0.0.1\n");
2694 hostAddr = htonl(0x7f000001);
2696 fprintf(stderr, "host %s not found in host table.\n",
2701 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2704 hostAddr = 0; /* means don't set host */
2705 setp = 0; /* aren't setting host */
2708 /* now do operation */
2709 blob.in_size = sizeof(afs_int32);
2710 blob.out_size = sizeof(afs_int32);
2711 blob.in = (char *)&hostAddr;
2712 blob.out = (char *)&hostAddr;
2713 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2719 printf("%s: new monitor host set.\n", pn);
2721 /* now decode old address */
2722 if (hostAddr == 0xffffffff) {
2723 printf("Cache monitoring is currently disabled.\n");
2725 tp = hostutil_GetNameByINet(hostAddr);
2726 printf("Using host %s for monitor services.\n", tp);
2733 SysNameCmd(struct cmd_syndesc *as, void *arock)
2736 struct ViceIoctl blob;
2737 struct cmd_item *ti;
2738 char *input = space;
2741 ti = as->parms[0].items;
2744 blob.out_size = AFS_PIOCTL_MAXSIZE;
2745 blob.in_size = sizeof(afs_int32);
2746 input += sizeof(afs_int32);
2747 for (; ti; ti = ti->next) {
2749 blob.in_size += strlen(ti->data) + 1;
2750 if (blob.in_size > AFS_PIOCTL_MAXSIZE) {
2751 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2752 setp > 1 ? "s" : "");
2755 strcpy(input, ti->data);
2756 input += strlen(ti->data);
2759 memcpy(space, &setp, sizeof(afs_int32));
2760 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2766 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2770 memcpy(&setp, input, sizeof(afs_int32));
2771 input += sizeof(afs_int32);
2773 fprintf(stderr, "No sysname name value was found\n");
2776 printf("Current sysname%s is", setp > 1 ? " list" : "");
2777 for (; setp > 0; --setp) {
2778 printf(" \'%s\'", input);
2779 input += strlen(input) + 1;
2785 static char *exported_types[] = { "null", "nfs", "" };
2787 ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2790 struct ViceIoctl blob;
2791 struct cmd_item *ti;
2792 int export = 0, type = 0, mode = 0, exportcall, pwsync =
2793 0, smounts = 0, clipags = 0, pagcb = 0;
2795 ti = as->parms[0].items;
2796 if (strcmp(ti->data, "nfs") == 0)
2797 type = 0x71; /* NFS */
2800 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n",
2804 ti = as->parms[1].items;
2806 if (strcmp(ti->data, "on") == 0)
2808 else if (strcmp(ti->data, "off") == 0)
2811 fprintf(stderr, "Illegal argument %s\n", ti->data);
2815 if ((ti = as->parms[2].items)) { /* -noconvert */
2816 if (strcmp(ti->data, "on") == 0)
2818 else if (strcmp(ti->data, "off") == 0)
2821 fprintf(stderr, "Illegal argument %s\n", ti->data);
2825 if ((ti = as->parms[3].items)) { /* -uidcheck */
2826 if (strcmp(ti->data, "on") == 0)
2828 else if (strcmp(ti->data, "off") == 0)
2831 fprintf(stderr, "Illegal argument %s\n", ti->data);
2835 if ((ti = as->parms[4].items)) { /* -submounts */
2836 if (strcmp(ti->data, "on") == 0)
2838 else if (strcmp(ti->data, "off") == 0)
2841 fprintf(stderr, "Illegal argument %s\n", ti->data);
2845 if ((ti = as->parms[5].items)) { /* -clipags */
2846 if (strcmp(ti->data, "on") == 0)
2848 else if (strcmp(ti->data, "off") == 0)
2851 fprintf(stderr, "Illegal argument %s\n", ti->data);
2855 if ((ti = as->parms[6].items)) { /* -pagcb */
2856 if (strcmp(ti->data, "on") == 0)
2858 else if (strcmp(ti->data, "off") == 0)
2861 fprintf(stderr, "Illegal argument %s\n", ti->data);
2866 (type << 24) | (pagcb << 10) | (clipags << 8) |
2867 (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2870 blob.in = (char *)&exportcall;
2871 blob.in_size = sizeof(afs_int32);
2872 blob.out = (char *)&exportcall;
2873 blob.out_size = sizeof(afs_int32);
2874 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2876 if (errno == ENODEV) {
2878 "Sorry, the %s-exporter type is currently not supported on this AFS client\n",
2879 exported_types[type]);
2886 if (exportcall & 1) {
2887 printf("'%s' translator is enabled with the following options:\n",
2888 exported_types[type]);
2889 printf("\tRunning in %s mode\n",
2890 (exportcall & 2 ? "strict unix" :
2891 "convert owner mode bits to world/other"));
2892 printf("\tRunning in %s mode\n",
2893 (exportcall & 4 ? "strict 'passwd sync'" :
2894 "no 'passwd sync'"));
2896 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
2897 "Only mounts to /afs allowed"));
2899 (exportcall & 16 ? "Client-assigned PAG's are used" :
2900 "Client-assigned PAG's are not used"));
2903 "Callbacks are made to get creds from new clients" :
2904 "Callbacks are not made to get creds from new clients"));
2906 printf("'%s' translator is disabled\n", exported_types[type]);
2913 GetCellCmd(struct cmd_syndesc *as, void *arock)
2916 struct ViceIoctl blob;
2917 struct afsconf_cell info;
2918 struct cmd_item *ti;
2925 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2926 for (ti = as->parms[0].items; ti; ti = ti->next) {
2928 blob.out_size = sizeof(args);
2929 blob.out = (caddr_t) & args;
2930 code = GetCellName(ti->data, &info);
2935 blob.in_size = 1 + strlen(info.name);
2936 blob.in = info.name;
2937 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2939 if (errno == ENOENT)
2940 fprintf(stderr, "%s: the cell named '%s' does not exist\n",
2943 Die(errno, info.name);
2947 printf("Cell %s status: ", info.name);
2953 printf("no setuid allowed");
2955 printf("setuid allowed");
2957 printf(", using old VLDB");
2964 SetCellCmd(struct cmd_syndesc *as, void *arock)
2967 struct ViceIoctl blob;
2968 struct afsconf_cell info;
2969 struct cmd_item *ti;
2977 /* Check arguments. */
2978 if (as->parms[1].items && as->parms[2].items) {
2979 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2983 /* figure stuff to set */
2987 if (!as->parms[1].items)
2988 args.stat |= 2; /* default to -nosuid */
2990 /* set stat for all listed cells */
2991 for (ti = as->parms[0].items; ti; ti = ti->next) {
2993 code = GetCellName(ti->data, &info);
2998 strcpy(args.cname, info.name);
2999 blob.in_size = sizeof(args);
3000 blob.in = (caddr_t) & args;
3002 blob.out = (caddr_t) 0;
3003 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
3005 Die(errno, info.name); /* XXX added cell name to Die() call */
3013 GetCellName(char *cellName, struct afsconf_cell *info)
3015 struct afsconf_dir *tdir;
3018 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
3021 "Could not process files in configuration directory (%s).\n",
3022 AFSDIR_CLIENT_ETC_DIRPATH);
3026 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
3028 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
3029 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
3038 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3042 code = ugen_ClientInit(noAuthFlag, (char *) AFSDIR_CLIENT_ETC_DIRPATH,
3043 info->name, 0, &uclient,
3044 NULL, pn, rxkad_clear,
3045 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3046 0, 0, USER_SERVICE_ID);
3051 static struct ViceIoctl gblob;
3052 static int debug = 0;
3054 * here follow some routines in suport of the setserverprefs and
3055 * getserverprefs commands. They are:
3056 * SetPrefCmd "top-level" routine
3057 * addServer adds a server to the list of servers to be poked into the
3058 * kernel. Will poke the list into the kernel if it threatens
3060 * pokeServers pokes the existing list of servers and ranks into the kernel
3061 * GetPrefCmd reads the Cache Manager's current list of server ranks
3065 * returns -1 if error message printed,
3067 * errno value if error and no error message printed
3074 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
3075 if (code && (errno == EINVAL)) {
3076 struct setspref *ssp;
3077 ssp = (struct setspref *)gblob.in;
3078 if (!(ssp->flags & DBservers)) {
3079 gblob.in = (void *)&(ssp->servers[0]);
3080 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3081 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
3082 return code ? errno : 0;
3085 "This cache manager does not support VL server preferences.\n");
3089 return code ? errno : 0;
3093 * returns -1 if error message printed,
3095 * errno value if error and no error message printed
3098 addServer(char *name, afs_int32 rank)
3101 struct setspref *ssp;
3103 struct hostent *thostent;
3108 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3110 #define MAXUSHORT ((unsigned short) ~0)
3114 thostent = hostutil_GetHostByName(name);
3116 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3120 ssp = (struct setspref *)(gblob.in);
3122 for (t = 0; thostent->h_addr_list[t]; t++) {
3123 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3124 code = pokeServers();
3127 ssp->num_servers = 0;
3130 sp = (struct spref *)(gblob.in + gblob.in_size);
3131 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3132 sizeof(afs_uint32));
3133 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3134 gblob.in_size += sizeof(struct spref);
3138 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3139 name, sp->rank, (long unsigned int) sp->server.s_addr);
3147 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3151 struct cmd_item *ti;
3154 struct setspref *ssp;
3155 int error = 0; /* -1 means error message printed,
3156 * >0 means errno value for unprinted message */
3158 ssp = (struct setspref *)space;
3160 ssp->num_servers = 0;
3161 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3164 gblob.out_size = AFS_PIOCTL_MAXSIZE;
3168 fprintf(stderr, "Permission denied: requires root access.\n");
3172 ti = as->parms[2].items; /* -file */
3175 fprintf(stderr, "opening file %s\n", ti->data);
3176 if (!(infd = fopen(ti->data, "r"))) {
3180 while (fscanf(infd, "%79s%d", name, &rank) != EOF) {
3181 code = addServer(name, (unsigned short)rank);
3188 ti = as->parms[3].items; /* -stdin */
3190 while (scanf("%79s%d", name, &rank) != EOF) {
3191 code = addServer(name, (unsigned short)rank);
3197 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3202 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3206 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3210 code = pokeServers();
3214 printf("now working on vlservers, code=%d\n", code);
3216 ssp = (struct setspref *)space;
3217 ssp->flags = DBservers;
3218 ssp->num_servers = 0;
3219 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3222 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3227 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3231 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3236 if (as->parms[1].items) {
3238 printf("now poking vlservers\n");
3239 code = pokeServers();
3247 return error ? 1 : 0;
3253 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3256 struct cmd_item *ti;
3257 char *name, tbuffer[20];
3262 struct ViceIoctl blob;
3263 struct sprefrequest *in;
3264 struct sprefinfo *out;
3267 ti = as->parms[0].items; /* -file */
3270 fprintf(stderr, "opening file %s\n", ti->data);
3271 if (!(outfd = freopen(ti->data, "w", stdout))) {
3277 ti = as->parms[1].items; /* -numeric */
3279 ti = as->parms[2].items; /* -vlservers */
3280 vlservers |= (ti ? DBservers : 0);
3281 /* ti = as->parms[3].items; -cell */
3283 in = (struct sprefrequest *)space;
3287 blob.in_size = sizeof(struct sprefrequest);
3288 blob.in = (char *)in;
3290 blob.out_size = AFS_PIOCTL_MAXSIZE;
3293 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3294 in->flags = vlservers;
3297 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3299 if ((errno != E2BIG) || (2 * blob.out_size > 0x7FFF)) {
3300 perror("getserverprefs pioctl");
3304 if (blob.out == space)
3305 blob.out = malloc(blob.out_size);
3307 blob.out = realloc(blob.out, blob.out_size);
3309 } while (code != 0);
3311 out = (struct sprefinfo *)blob.out;
3313 for (i = 0; i < out->num_servers; i++) {
3315 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3317 addr = ntohl(out->servers[i].server.s_addr);
3318 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3319 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3322 printf("%-50s %5u\n", name, out->servers[i].rank);
3325 in->offset = out->next_offset;
3326 } while (out->next_offset > 0);
3328 if (blob.out != space)
3335 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
3338 struct ViceIoctl blob;
3339 struct cmd_item *ti;
3340 struct sbstruct tsb, tsb2;
3346 tsb.sb_thisfile = -1;
3347 ti = as->parms[0].items; /* -kbytes */
3349 if (!as->parms[1].items) {
3350 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3354 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3355 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3356 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3362 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3363 ti = as->parms[2].items; /* -allfiles */
3365 allfiles = strtol(ti->data, &t, 10) * 1024;
3366 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3367 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3373 /* -verbose or -file only or no options */
3374 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3375 || (!as->parms[0].items && !as->parms[1].items
3376 && !as->parms[2].items))
3379 blob.in = (char *)&tsb;
3380 blob.in_size = sizeof(struct sbstruct);
3382 /* once per -file */
3383 for (ti = as->parms[1].items; ti; ti = ti->next) {
3384 /* Do this solely to see if the file is there */
3387 blob.out_size = AFS_PIOCTL_MAXSIZE;
3388 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3390 Die(errno, ti->data);
3395 memset(&tsb2, 0, sizeof(tsb2));
3396 blob.out = (char *)&tsb2;
3397 blob.out_size = sizeof(struct sbstruct);
3398 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
3400 Die(errno, ti->data);
3405 if (verbose && (blob.out_size == sizeof(tsb2))) {
3406 if (tsb2.sb_thisfile == -1) {
3407 fprintf(stdout, "Will store %s according to default.\n",
3411 "Will store up to %d kbytes of %s asynchronously.\n",
3412 (tsb2.sb_thisfile / 1024), ti->data);
3417 /* If no files - make at least one pioctl call, or
3418 * set the allfiles default if we need to.
3420 if (!as->parms[1].items || (allfiles != -1)) {
3421 tsb.sb_default = allfiles;
3422 memset(&tsb2, 0, sizeof(tsb2));
3423 blob.out = (char *)&tsb2;
3424 blob.out_size = sizeof(struct sbstruct);
3425 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
3427 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3432 /* Having no arguments also reports the default store asynchrony */
3433 if (!error && verbose && (blob.out_size == sizeof(tsb2))) {
3434 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3435 (tsb2.sb_default / 1024));
3443 SetCryptCmd(struct cmd_syndesc *as, void *arock)
3445 afs_int32 code = 0, flag;
3446 struct ViceIoctl blob;
3449 tp = as->parms[0].items->data;
3450 if (strcmp(tp, "on") == 0)
3452 else if (strcmp(tp, "off") == 0)
3455 fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3459 blob.in = (char *)&flag;
3460 blob.in_size = sizeof(flag);
3462 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3470 GetCryptCmd(struct cmd_syndesc *as, void *arock)
3472 afs_int32 code = 0, flag;
3473 struct ViceIoctl blob;
3478 blob.out_size = sizeof(flag);
3481 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3487 memcpy(&flag, tp, sizeof(afs_int32));
3488 printf("Security level is currently ");
3490 printf("crypt (data security).\n");
3497 static char *modenames[] = {
3500 "readonly", /* Not currently supported */
3501 "fetchonly", /* Not currently supported */
3502 "partial", /* Not currently supported */
3506 static char *policynames[] = {
3509 "closer", /* Not currently supported. */
3510 "manual", /* Not currently supported. */
3515 DisconCmd(struct cmd_syndesc *as, void *arock)
3517 struct cmd_item *ti;
3520 int modelen, policylen;
3521 afs_int32 mode, policy, code, unixuid = 0;
3522 struct ViceIoctl blob;
3527 space[0] = space[1] = space[2] = space[3] = 0;
3529 ti = as->parms[0].items;
3531 modename = ti->data;
3532 modelen = strlen(modename);
3533 for (mode = 0; modenames[mode] != NULL; mode++)
3534 if (!strncasecmp(modename, modenames[mode], modelen))
3536 if (modenames[mode] == NULL)
3537 printf("Unknown discon mode \"%s\"\n", modename);
3539 space[0] = mode + 1;
3542 ti = as->parms[1].items;
3544 policyname = ti->data;
3545 policylen = strlen(policyname);
3546 for (policy = 0; policynames[policy] != NULL; policy++)
3547 if (!strncasecmp(policyname, policynames[policy], policylen))
3549 if (policynames[policy] == NULL)
3550 printf("Unknown discon mode \"%s\"\n", policyname);
3552 space[1] = policy + 1;
3556 if (as->parms[2].items) {
3558 printf("force on\n");
3561 ti = as->parms[3].items;
3563 code = util_GetInt32(ti->data, &unixuid);
3565 fprintf(stderr, "%s: bad integer specified for uid.\n", pn);
3573 blob.in_size = 4 * sizeof(afs_int32);
3575 blob.out_size = sizeof(mode);
3577 code = pioctl(0, VIOC_DISCON, &blob, 1);
3581 memcpy(&mode, space, sizeof mode);
3582 if (mode < sizeof modenames / sizeof (char *))
3583 printf("Discon mode is now \"%s\"\n", modenames[mode]);
3585 printf("Unknown discon mode %d\n", mode);
3591 #include "AFS_component_version_number.c"
3594 main(int argc, char **argv)
3597 struct cmd_syndesc *ts;
3599 #ifdef AFS_AIX32_ENV
3601 * The following signal action for AIX is necessary so that in case of a
3602 * crash (i.e. core is generated) we can include the user's data section
3603 * in the core dump. Unfortunately, by default, only a partial core is
3604 * generated which, in many cases, isn't too useful.
3606 struct sigaction nsa;
3608 sigemptyset(&nsa.sa_mask);
3609 nsa.sa_handler = SIG_DFL;
3610 nsa.sa_flags = SA_FULLDUMP;
3611 sigaction(SIGSEGV, &nsa, NULL);
3614 /* try to find volume location information */
3615 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
3616 "get client network interface addresses");
3617 cmd_CreateAlias(ts, "gc");
3619 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
3620 "set client network interface addresses");
3621 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3622 "client network interfaces");
3623 cmd_CreateAlias(ts, "sc");
3625 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL,
3626 "set server ranks");
3627 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3628 "fileserver names and ranks");
3629 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3630 "VL server names and ranks");
3631 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3632 "input from named file");
3633 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3634 cmd_CreateAlias(ts, "sp");
3636 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL,
3637 "get server ranks");
3638 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3639 "output to named file");
3640 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3641 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3642 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3643 cmd_CreateAlias(ts, "gp");
3645 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
3646 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3647 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3648 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3649 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL,
3650 "apply to negative rights");
3651 parm_setacl_id = ts->nParms;
3652 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL,
3653 "initial directory acl (DFS only)");
3654 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL,
3655 "initial file acl (DFS only)");
3656 cmd_CreateAlias(ts, "sa");
3658 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL,
3659 "list access control list");
3660 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3661 parm_listacl_id = ts->nParms;
3662 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3663 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3664 cmd_AddParm(ts, "-cmd", CMD_FLAG, CMD_OPTIONAL, "output as 'fs setacl' command");
3665 cmd_CreateAlias(ts, "la");
3667 ts = cmd_CreateSyntax("getcalleraccess", GetCallerAccess, NULL,
3668 "list callers access");
3669 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3670 cmd_CreateAlias(ts, "gca");
3672 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL,
3673 "clean up access control list");
3674 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3676 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL,
3677 "copy access control list");
3678 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0,
3679 "source directory (or DFS file)");
3680 cmd_AddParm(ts, "-todir", CMD_LIST, 0,
3681 "destination directory (or DFS file)");
3682 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3683 "first clear dest access list");
3684 parm_copyacl_id = ts->nParms;
3685 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3686 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3688 cmd_CreateAlias(ts, "ca");
3690 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
3691 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3692 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
3693 "flush mount symlink from cache");
3694 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3696 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
3697 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3698 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL,
3699 "disk space quota in 1K units");
3701 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL,
3702 "disk space guaranteed");
3703 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3705 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL,
3707 cmd_CreateAlias(ts, "sv");
3709 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL,
3710 "control Cache Manager messages");
3711 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL,
3712 "[user|console|all|none]");
3714 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
3715 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3716 cmd_CreateAlias(ts, "lv");
3717 cmd_CreateAlias(ts, "listvol");
3719 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
3720 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3721 cmd_AddParm(ts, "-human", CMD_FLAG, CMD_OPTIONAL, "human-readable listing");
3722 cmd_CreateAlias(ts, "lq");
3724 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL,
3725 "show server disk space usage");
3726 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3727 cmd_AddParm(ts, "-human", CMD_FLAG, CMD_OPTIONAL, "human-readable listing");
3728 cmd_CreateAlias(ts, "df");
3730 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
3731 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3733 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
3734 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3736 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
3737 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3738 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3739 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3740 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3741 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3742 "don't check name with VLDB");
3744 #if defined(AFS_CACHE_BYPASS)
3745 ts = cmd_CreateSyntax("bypassthreshold", BypassThresholdCmd, 0,
3746 "get/set cache bypass file size threshold");
3747 cmd_AddParm(ts, "-size", CMD_SINGLE, CMD_OPTIONAL, "file size");
3754 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3758 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
3759 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3761 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL,
3762 "check local cell's servers");
3763 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3764 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3765 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3766 "just list, don't check");
3767 cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL,
3768 "seconds between probes");
3770 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL,
3771 "check volumeID/name mappings");
3772 cmd_CreateAlias(ts, "checkbackups");
3775 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL,
3777 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3778 "size in 1K byte blocks (0 => reset)");
3779 cmd_CreateAlias(ts, "cachesize");
3781 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL,
3782 "reset size back to boot value");
3784 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL,
3785 "get cache usage info");
3786 cmd_AddParm(ts, "-files", CMD_FLAG, CMD_OPTIONAL, "Show cach files used as well");
3787 cmd_AddParm(ts, "-excessive", CMD_FLAG, CMD_OPTIONAL, "excessively verbose cache stats");
3789 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL,
3790 "list configured cells");
3791 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3793 ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, NULL,
3794 "list configured cell aliases");
3796 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
3797 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3798 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3800 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3802 cmd_CreateAlias(ts, "sq");
3804 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
3805 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3806 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3807 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL,
3808 "linked cell name");
3810 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
3811 "configure new cell alias");
3812 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
3813 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
3815 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3817 * Turn this on only if you wish to be able to talk to a server which is listening
3818 * on alternative ports. This is not intended for general use and may not be
3819 * supported in the cache manager. It is not a way to run two servers at the
3820 * same host, since the cache manager cannot properly distinguish those two hosts.
3822 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL,
3823 "cell's fileserver port");
3824 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL,
3825 "cell's vldb server port");
3828 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
3829 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3831 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
3832 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3834 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
3837 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, NULL, "obsolete (listed primary cell)");
3840 /* set cache monitor host address */
3841 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, (char *)CMD_HIDDEN);
3842 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL,
3843 "host name or 'off'");
3844 cmd_CreateAlias(ts, "mariner");
3846 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
3847 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3849 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
3850 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3851 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3852 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL,
3853 "disallow setuid programs");
3855 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL,
3856 "flush all data in volume");
3857 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3859 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL,
3860 "get/set sysname (i.e. @sys) value");
3861 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3863 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL,
3864 "enable/disable translators to AFS");
3865 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3866 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL,
3867 "start/stop translator (on | off)");
3868 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL,
3869 "convert from afs to unix mode (on | off)");
3870 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL,
3871 "run on strict 'uid check' mode (on | off)");
3872 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
3873 "allow nfs mounts to subdirs of /afs/.. (on | off)");
3874 cmd_AddParm(ts, "-clipags", CMD_SINGLE, CMD_OPTIONAL,
3875 "enable use of client-assigned PAG's (on | off)");
3876 cmd_AddParm(ts, "-pagcb", CMD_SINGLE, CMD_OPTIONAL,
3877 "enable callbacks to get creds from new clients (on | off)");
3880 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
3881 "store to server after file close");
3882 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL,
3883 "asynchrony for specified names");
3884 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3885 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL,
3886 "new default (KB)");
3887 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3888 cmd_CreateAlias(ts, "sb");
3890 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL,
3891 "set cache manager encryption flag");
3892 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3894 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL,
3895 "get cache manager encryption flag");
3897 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
3898 "Manage per process RX statistics");
3899 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3900 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3901 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3903 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
3904 "Manage per peer RX statistics");
3905 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3906 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3907 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3909 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
3910 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
3912 /* try to find volume location information */
3913 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL,
3914 "get fid for file(s)");
3915 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3917 ts = cmd_CreateSyntax("discon", DisconCmd, NULL,
3918 "disconnection mode");
3919 cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_REQUIRED, "offline | online");
3920 cmd_AddParm(ts, "-policy", CMD_SINGLE, CMD_OPTIONAL, "client | server");
3921 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Force reconnection, despite any synchronization issues.");
3922 cmd_AddParm(ts, "-uid", CMD_SINGLE, CMD_OPTIONAL, "Numeric UID of user whose tokens to use at reconnect.");
3924 ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, NULL, "nuke credentials for NFS client");
3925 cmd_AddParm(ts, "-addr", CMD_SINGLE, 0, "host name or address");
3927 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
3928 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_REQUIRED, "generate a new UUID");
3930 ts = cmd_CreateSyntax("precache", PreCacheCmd, 0,
3931 "set precache size");
3932 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3933 "size in 1K byte blocks (0 => disable)");
3935 code = cmd_Dispatch(argc, argv);
3943 Die(int errnum, char *filename)
3949 "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3952 fprintf(stderr, "%s: Invalid argument.\n", pn);
3956 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3958 fprintf(stderr, "%s: no such file returned\n", pn);
3962 "%s: You can not change a backup or readonly volume\n", pn);
3968 "%s: You don't have the required access rights on '%s'\n",
3972 "%s: You do not have the required rights to do this operation\n",
3977 fprintf(stderr, "%s:'%s'", pn, filename);
3979 fprintf(stderr, "%s", pn);
3980 fprintf(stderr, ": %s\n", afs_error_message(errnum));
3985 /* get clients interface addresses */
3987 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3990 struct ViceIoctl blob;
3991 struct sprefrequest *in;
3992 struct sprefinfo *out;
3994 in = (struct sprefrequest *)space;
3998 blob.in_size = sizeof(struct sprefrequest);
3999 blob.in = (char *)in;
4001 blob.out_size = AFS_PIOCTL_MAXSIZE;
4004 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
4005 /* returns addr in network byte order */
4006 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
4008 perror("getClientInterfaceAddr pioctl");
4014 out = (struct sprefinfo *)blob.out;
4015 for (i = 0; i < out->num_servers; i++) {
4018 addr = ntohl(out->servers[i].server.s_addr);
4019 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
4020 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
4021 printf("%-50s\n", tbuffer);
4023 in->offset = out->next_offset;
4025 } while (out->next_offset > 0);
4031 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4033 afs_int32 code, addr;
4034 struct cmd_item *ti;
4035 struct ViceIoctl blob;
4036 struct setspref *ssp;
4037 int sizeUsed = 0, i, flag;
4038 afs_uint32 existingAddr[1024]; /* existing addresses on this host */
4042 ssp = (struct setspref *)space;
4043 ssp->num_servers = 0;
4046 blob.out_size = AFS_PIOCTL_MAXSIZE;
4049 fprintf(stderr, "Permission denied: requires root access.\n");
4053 /* extract all existing interface addresses */
4054 existNu = rx_getAllAddr(existingAddr, 1024);
4058 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
4059 for (ti = as->parms[0].items; ti; ti = ti->next) {
4060 if (sizeUsed >= sizeof(space)) {
4061 fprintf(stderr, "No more space\n");
4064 addr = extractAddr(ti->data, 20); /* network order */
4065 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
4066 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
4071 /* see if it is an address that really exists */
4072 for (flag = 0, i = 0; i < existNu; i++)
4073 if (existingAddr[i] == addr) {
4077 if (!flag) { /* this is an nonexistent address */
4078 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
4082 /* copy all specified addr into ioctl buffer */
4083 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
4084 printf("Adding 0x%08x\n", addr);
4086 sizeUsed += sizeof(struct spref);
4088 if (ssp->num_servers < 1) {
4089 fprintf(stderr, "No addresses specified\n");
4092 blob.in_size = sizeUsed - sizeof(struct spref);
4094 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
4104 FlushMountCmd(struct cmd_syndesc *as, void *arock)
4107 struct ViceIoctl blob;
4108 struct cmd_item *ti;
4109 char *last_component;
4113 for (ti = as->parms[0].items; ti; ti = ti->next) {
4114 if (GetLastComponent(ti->data, &parent_dir,
4115 &last_component, NULL) != 0) {
4120 blob.in = last_component;
4121 blob.in_size = strlen(last_component) + 1;
4124 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4126 free(last_component);
4130 if (errno == EINVAL) {
4131 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4133 Die(errno, (ti->data ? ti->data : parent_dir));
4142 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4145 afs_int32 flags = 0;
4146 struct ViceIoctl blob;
4148 if (as->parms[0].items) { /* -enable */
4149 flags |= AFSCALL_RXSTATS_ENABLE;
4151 if (as->parms[1].items) { /* -disable */
4152 flags |= AFSCALL_RXSTATS_DISABLE;
4154 if (as->parms[2].items) { /* -clear */
4155 flags |= AFSCALL_RXSTATS_CLEAR;
4158 fprintf(stderr, "You must specify at least one argument\n");
4162 blob.in = (char *)&flags;
4163 blob.in_size = sizeof(afs_int32);
4166 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4176 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4179 afs_int32 flags = 0;
4180 struct ViceIoctl blob;
4182 if (as->parms[0].items) { /* -enable */
4183 flags |= AFSCALL_RXSTATS_ENABLE;
4185 if (as->parms[1].items) { /* -disable */
4186 flags |= AFSCALL_RXSTATS_DISABLE;
4188 if (as->parms[2].items) { /* -clear */
4189 flags |= AFSCALL_RXSTATS_CLEAR;
4192 fprintf(stderr, "You must specify at least one argument\n");
4196 blob.in = (char *)&flags;
4197 blob.in_size = sizeof(afs_int32);
4200 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4210 GetFidCmd(struct cmd_syndesc *as, void *arock)
4212 struct ViceIoctl blob;
4213 struct cmd_item *ti;
4217 char cell[MAXCELLCHARS];
4219 SetDotDefault(&as->parms[0].items);
4220 for (ti = as->parms[0].items; ti; ti = ti->next) {
4221 struct VenusFid vfid;
4223 blob.out_size = sizeof(struct VenusFid);
4224 blob.out = (char *) &vfid;
4227 code = pioctl(ti->data, VIOCGETFID, &blob, 1);
4229 Die(errno,ti->data);
4234 code = GetCell(ti->data, cell);
4236 if (errno == ENOENT)
4237 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
4239 Die(errno, ti->data);
4244 printf("File %s (%u.%u.%u) located in cell %s\n",
4245 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,