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>
15 #include <afs/afs_consts.h>
16 #include <afs/afs_args.h>
18 #include <sys/ioctl.h>
19 #include <sys/socket.h>
24 #include <netinet/in.h>
28 #include <afs/venus.h>
29 #include <afs/com_err.h>
30 #include <afs/afs_consts.h>
39 #include "afs/prs_fs.h"
40 #include <afs/afsint.h>
41 #include <afs/cellconfig.h>
44 #include <rx/rx_globals.h>
45 #include <afs/vldbint.h>
46 #include <afs/volser.h>
47 #include <afs/vlserver.h>
49 #include <afs/afsutil.h>
50 #include <afs/com_err.h>
53 #include <afs/ptclient.h>
54 #include <afs/ptuser.h>
55 #include <afs/afsutil.h>
56 #include <afs/sys_prototypes.h>
59 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
60 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
62 static char space[AFS_PIOCTL_MAXSIZE];
63 static char tspace[1024];
64 static struct ubik_client *uclient;
66 static int GetClientAddrsCmd(struct cmd_syndesc *, void *);
67 static int SetClientAddrsCmd(struct cmd_syndesc *, void *);
68 static int FlushMountCmd(struct cmd_syndesc *, void *);
69 static int RxStatProcCmd(struct cmd_syndesc *, void *);
70 static int RxStatPeerCmd(struct cmd_syndesc *, void *);
71 static int GetFidCmd(struct cmd_syndesc *, void *);
72 static int UuidCmd(struct cmd_syndesc *, void *);
74 static char pn[] = "fs";
75 static int rxInitDone = 0;
79 static void ZapList(struct AclEntry *);
80 static int PruneList(struct AclEntry **, int);
81 static int CleanAcl(struct Acl *, char *);
82 static int SetVolCmd(struct cmd_syndesc *as, void *arock);
83 static int GetCellName(char *, struct afsconf_cell *);
84 static int VLDBInit(int, struct afsconf_cell *);
85 static void Die(int, char *);
88 * Character to use between name and rights in printed representation for
91 #define DFS_SEPARATOR ' '
93 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
96 int dfs; /* Originally true if a dfs acl; now also the type
97 * of the acl (1, 2, or 3, corresponding to object,
98 * initial dir, or initial object). */
99 sec_rgy_name_t cell; /* DFS cell name */
102 struct AclEntry *pluslist;
103 struct AclEntry *minuslist;
107 struct AclEntry *next;
113 afs_int32 callerAccess;
120 ZapAcl(struct Acl *acl)
124 ZapList(acl->pluslist);
125 ZapList(acl->minuslist);
130 foldcmp(char *a, char *b)
136 if (t >= 'A' && t <= 'Z')
138 if (u >= 'A' && u <= 'Z')
148 * Mods for the AFS/DFS protocol translator.
150 * DFS rights. It's ugly to put these definitions here, but they
151 * *cannot* change, because they're part of the wire protocol.
152 * In any event, the protocol translator will guarantee these
153 * assignments for AFS cache managers.
155 #define DFS_READ 0x01
156 #define DFS_WRITE 0x02
157 #define DFS_EXECUTE 0x04
158 #define DFS_CONTROL 0x08
159 #define DFS_INSERT 0x10
160 #define DFS_DELETE 0x20
162 /* the application definable ones (backwards from AFS) */
163 #define DFS_USR0 0x80000000 /* "A" bit */
164 #define DFS_USR1 0x40000000 /* "B" bit */
165 #define DFS_USR2 0x20000000 /* "C" bit */
166 #define DFS_USR3 0x10000000 /* "D" bit */
167 #define DFS_USR4 0x08000000 /* "E" bit */
168 #define DFS_USR5 0x04000000 /* "F" bit */
169 #define DFS_USR6 0x02000000 /* "G" bit */
170 #define DFS_USR7 0x01000000 /* "H" bit */
171 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
172 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
175 * Offset of -id switch in command structure for various commands.
176 * The -if switch is the next switch always.
178 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
181 * Determine whether either the -id or -if switches are present, and
182 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
184 /* int id; Offset of -id switch; -if is next switch */
186 getidf(struct cmd_syndesc *as, int id)
190 if (as->parms[id].items) {
193 if (as->parms[id + 1].items) {
198 "%s: you may specify either -id or -if, but not both switches\n",
206 PRights(afs_int32 arights, int dfs)
209 if (arights & PRSFS_READ)
211 if (arights & PRSFS_LOOKUP)
213 if (arights & PRSFS_INSERT)
215 if (arights & PRSFS_DELETE)
217 if (arights & PRSFS_WRITE)
219 if (arights & PRSFS_LOCK)
221 if (arights & PRSFS_ADMINISTER)
223 if (arights & PRSFS_USR0)
225 if (arights & PRSFS_USR1)
227 if (arights & PRSFS_USR2)
229 if (arights & PRSFS_USR3)
231 if (arights & PRSFS_USR4)
233 if (arights & PRSFS_USR5)
235 if (arights & PRSFS_USR6)
237 if (arights & PRSFS_USR7)
240 if (arights & DFS_READ)
244 if (arights & DFS_WRITE)
248 if (arights & DFS_EXECUTE)
252 if (arights & DFS_CONTROL)
256 if (arights & DFS_INSERT)
260 if (arights & DFS_DELETE)
264 if (arights & (DFS_USRALL))
266 if (arights & DFS_USR0)
268 if (arights & DFS_USR1)
270 if (arights & DFS_USR2)
272 if (arights & DFS_USR3)
274 if (arights & DFS_USR4)
276 if (arights & DFS_USR5)
278 if (arights & DFS_USR6)
280 if (arights & DFS_USR7)
286 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
290 struct ViceIoctl blob;
294 blob.out_size = AFS_PIOCTL_MAXSIZE;
297 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
299 if ((errno == EINVAL) || (errno == ENOENT))
305 /* return a static pointer to a buffer */
310 strlcpy(tspace, apath, sizeof(tspace));
311 tp = strrchr(tspace, '/');
312 if (tp == (char *)tspace)
314 else if (tp == (char *)NULL) {
322 enum rtype { add, destroy, deny };
325 Convert(char *arights, int dfs, enum rtype *rtypep)
331 *rtypep = add; /* add rights, by default */
334 if (!strcmp(arights, "null")) {
338 if (!strcmp(arights, "read"))
339 return DFS_READ | DFS_EXECUTE;
340 if (!strcmp(arights, "write"))
341 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
343 if (!strcmp(arights, "all"))
344 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
345 DFS_WRITE | DFS_CONTROL;
347 if (!strcmp(arights, "read"))
348 return PRSFS_READ | PRSFS_LOOKUP;
349 if (!strcmp(arights, "write"))
350 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
351 PRSFS_WRITE | PRSFS_LOCK;
352 if (!strcmp(arights, "mail"))
353 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
354 if (!strcmp(arights, "all"))
355 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
356 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
358 if (!strcmp(arights, "none")) {
359 *rtypep = destroy; /* Remove entire entry */
362 len = strlen(arights);
364 for (i = 0; i < len; i++) {
398 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
406 mode |= PRSFS_LOOKUP;
408 mode |= PRSFS_INSERT;
410 mode |= PRSFS_DELETE;
416 mode |= PRSFS_ADMINISTER;
434 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
443 static struct AclEntry *
444 FindList(struct AclEntry *alist, char *aname)
447 if (!foldcmp(alist->name, aname))
454 /* if no parm specified in a particular slot, set parm to be "." instead */
456 SetDotDefault(struct cmd_item **aitemp)
460 return; /* already has value */
461 /* otherwise, allocate an item representing "." */
462 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
464 ti->next = (struct cmd_item *)0;
465 ti->data = (char *)malloc(2);
467 strcpy(ti->data, ".");
472 ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
474 struct AclEntry *tlist;
475 tlist = (plus ? al->pluslist : al->minuslist);
476 tlist = FindList(tlist, aname);
478 /* Found the item already in the list. */
479 tlist->rights = arights;
481 al->nplus -= PruneList(&al->pluslist, al->dfs);
483 al->nminus -= PruneList(&al->minuslist, al->dfs);
486 /* Otherwise we make a new item and plug in the new data. */
487 tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry));
489 strcpy(tlist->name, aname);
490 tlist->rights = arights;
492 tlist->next = al->pluslist;
493 al->pluslist = tlist;
495 if (arights == 0 || arights == -1)
496 al->nplus -= PruneList(&al->pluslist, al->dfs);
498 tlist->next = al->minuslist;
499 al->minuslist = tlist;
502 al->nminus -= PruneList(&al->minuslist, al->dfs);
507 ZapList(struct AclEntry *alist)
509 struct AclEntry *tp, *np;
510 for (tp = alist; tp; tp = np) {
517 PruneList(struct AclEntry **ae, int dfs)
519 struct AclEntry **lp;
520 struct AclEntry *te, *ne;
524 for (te = *ae; te; te = ne) {
525 if ((!dfs && te->rights == 0) || te->rights == -1) {
541 while (*astr != '\n')
548 * Create an empty acl, taking into account whether the acl pointed
549 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
550 * can recover from problems caused by bogus ACL's (in that case, always
551 * assume that the acl is AFS: for DFS, the user can always resort to
552 * acl_edit, but for AFS there may be no other way out).
560 tp = (struct Acl *)malloc(sizeof(struct Acl));
562 tp->nplus = tp->nminus = 0;
563 tp->pluslist = tp->minuslist = 0;
565 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
572 int nplus, nminus, i, trights;
574 struct AclEntry *first, *last, *tl;
577 ta = (struct Acl *)malloc(sizeof(struct Acl));
580 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
581 astr = SkipLine(astr);
582 sscanf(astr, "%d", &ta->nminus);
583 astr = SkipLine(astr);
590 for (i = 0; i < nplus; i++) {
591 sscanf(astr, "%100s %d", tname, &trights);
592 astr = SkipLine(astr);
593 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
597 strcpy(tl->name, tname);
598 tl->rights = trights;
604 ta->pluslist = first;
608 for (i = 0; i < nminus; i++) {
609 sscanf(astr, "%100s %d", tname, &trights);
610 astr = SkipLine(astr);
611 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
615 strcpy(tl->name, tname);
616 tl->rights = trights;
622 ta->minuslist = first;
628 PrintStatus(VolumeStatus * status, char *name, char *offmsg)
630 printf("Volume status for vid = %u named %s\n", status->Vid, name);
632 printf("Current offline message is %s\n", offmsg);
633 printf("Current disk quota is ");
634 if (status->MaxQuota != 0)
635 printf("%d\n", status->MaxQuota);
637 printf("unlimited\n");
638 printf("Current blocks used are %d\n", status->BlocksInUse);
639 printf("The partition has %d blocks available out of %d\n\n",
640 status->PartBlocksAvail, status->PartMaxBlocks);
644 static const char power_letter[] = {
653 HumanPrintSpace(afs_int32 int_space)
656 int exponent_max = sizeof(power_letter) - 1;
657 float space = int_space;
659 while (space >= 1024 && exponent < exponent_max) {
663 printf("%9.1f%c", space, power_letter[exponent]);
667 QuickPrintStatus(VolumeStatus * status, char *name, int human)
669 double QuotaUsed = 0.0;
670 double PartUsed = 0.0;
672 printf("%-25.25s", name);
674 if (status->MaxQuota != 0) {
677 HumanPrintSpace(status->MaxQuota);
679 HumanPrintSpace(status->BlocksInUse);
682 printf(" %10d %10d", status->MaxQuota, status->BlocksInUse);
684 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
686 printf(" no limit ");
688 HumanPrintSpace(status->BlocksInUse);
690 printf("%10d", status->BlocksInUse);
692 if (QuotaUsed > 90.0) {
693 printf("%5.0f%%<<", QuotaUsed);
696 printf("%5.0f%% ", QuotaUsed);
699 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
701 if (PartUsed > 97.0) {
702 printf("%9.0f%%<<", PartUsed);
705 printf("%9.0f%% ", PartUsed);
707 printf(" <<WARNING\n");
714 QuickPrintSpace(VolumeStatus * status, char *name, int human)
716 double PartUsed = 0.0;
718 printf("%-25.25s", name);
721 HumanPrintSpace(status->PartMaxBlocks);
722 HumanPrintSpace(status->PartMaxBlocks - status->PartBlocksAvail);
723 HumanPrintSpace(status->PartBlocksAvail);
726 printf("%10d%10d%10d", status->PartMaxBlocks,
727 status->PartMaxBlocks - status->PartBlocksAvail,
728 status->PartBlocksAvail);
732 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
734 if (PartUsed > 90.0) {
735 printf(" %4.0f%%<<", PartUsed);
738 printf(" %4.0f%% ", PartUsed);
740 printf(" <<WARNING\n");
747 AclToString(struct Acl *acl)
749 static char mydata[AFS_PIOCTL_MAXSIZE];
750 char tstring[AFS_PIOCTL_MAXSIZE];
755 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
758 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
759 for (tp = acl->pluslist; tp; tp = tp->next) {
760 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
761 strcat(mydata, tstring);
763 for (tp = acl->minuslist; tp; tp = tp->next) {
764 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
765 strcat(mydata, tstring);
771 SetACLCmd(struct cmd_syndesc *as, void *arock)
774 struct ViceIoctl blob;
776 struct cmd_item *ti, *ui;
780 int idf = getidf(as, parm_setacl_id);
783 if (as->parms[2].items)
787 plusp = !(as->parms[3].items);
788 for (ti = as->parms[0].items; ti; ti = ti->next) {
789 blob.out_size = AFS_PIOCTL_MAXSIZE;
791 blob.in = blob.out = space;
792 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
794 Die(errno, ti->data);
801 ta = ParseAcl(space);
802 if (!plusp && ta->dfs) {
804 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
806 "(you may specify \"null\" to revoke all rights, however)\n");
814 ta = EmptyAcl(space);
816 ta = ParseAcl(space);
817 CleanAcl(ta, ti->data);
818 for (ui = as->parms[1].items; ui; ui = ui->next->next) {
822 "%s: Missing second half of user/access pair.\n", pn);
826 rights = Convert(ui->next->data, ta->dfs, &rtype);
827 if (rtype == destroy && !ta->dfs) {
828 struct AclEntry *tlist;
830 tlist = (plusp ? ta->pluslist : ta->minuslist);
831 if (!FindList(tlist, ui->data))
834 if (rtype == deny && !ta->dfs)
836 if (rtype == destroy && ta->dfs)
838 ChangeList(ta, plusp, ui->data, rights);
840 blob.in = AclToString(ta);
842 blob.in_size = 1 + strlen(blob.in);
843 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
845 if (errno == EINVAL) {
847 static char *fsenv = 0;
849 fsenv = (char *)getenv("FS_EXPERT");
852 "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n",
856 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
857 "\nPossible reasons for this include:\n\n",
858 " -You may have specified an inappropriate combination of rights.\n",
859 " For example, some DFS-supported filesystems may not allow you to\n",
860 " drop the \"c\" right from \"user_obj\".\n\n",
861 " -A mask_obj may be required (it is likely required by the underlying\n",
862 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
863 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
864 " does not automatically create or update the mask_obj. Try setting\n",
865 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
866 " users or groups. You can do this with a single command, such as\n",
867 " \"fs sa mask_obj all user:somename read\"\n\n",
868 " -A specified user or group may not exist.\n\n",
869 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
870 " This is probably not allowed by the underlying file system.\n\n",
871 " -If you add a user or group to a DFS ACL, remember that it must be\n",
872 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
873 " may be local requirements on the format of the user or group name.\n",
874 " Check with your cell administrator.\n\n",
875 " -Or numerous other possibilities. It would be great if we could be more\n",
876 " precise about the actual problem, but for various reasons, this is\n",
877 " impractical via this interface. If you can't figure it out, you\n",
878 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
879 " whatever is provided). You may get better results. Good luck!\n\n",
880 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
884 "%s: Invalid argument, possible reasons include:\n",
886 fprintf(stderr, "\t-File not in AFS\n");
888 "\t-Too many users on access control list\n");
890 "\t-Tried to add non-existent user to access control list\n");
893 Die(errno, ti->data);
905 CopyACLCmd(struct cmd_syndesc *as, void *arock)
908 struct ViceIoctl blob;
909 struct Acl *fa, *ta = 0;
913 int idf = getidf(as, parm_copyacl_id);
916 if (as->parms[2].items)
920 blob.out_size = AFS_PIOCTL_MAXSIZE;
922 blob.in = blob.out = space;
923 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
925 Die(errno, as->parms[0].items->data);
928 fa = ParseAcl(space);
929 CleanAcl(fa, as->parms[0].items->data);
930 for (ti = as->parms[1].items; ti; ti = ti->next) {
931 blob.out_size = AFS_PIOCTL_MAXSIZE;
933 blob.in = blob.out = space;
934 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
936 Die(errno, ti->data);
944 ta = EmptyAcl(space);
946 ta = ParseAcl(space);
947 CleanAcl(ta, ti->data);
948 if (ta->dfs != fa->dfs) {
950 "%s: incompatible file system types: acl not copied to %s; aborted\n",
956 if (!clear && strcmp(ta->cell, fa->cell) != 0) {
958 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
963 strcpy(ta->cell, fa->cell);
965 for (tp = fa->pluslist; tp; tp = tp->next)
966 ChangeList(ta, 1, tp->name, tp->rights);
967 for (tp = fa->minuslist; tp; tp = tp->next)
968 ChangeList(ta, 0, tp->name, tp->rights);
969 blob.in = AclToString(ta);
971 blob.in_size = 1 + strlen(blob.in);
972 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
974 if (errno == EINVAL) {
976 "%s: Invalid argument, possible reasons include:\n",
978 fprintf(stderr, "\t-File not in AFS\n");
980 Die(errno, ti->data);
991 /* pioctl() call to get the cellname of a pathname */
993 GetCell(char *fname, char *cellname)
996 struct ViceIoctl blob;
999 blob.out_size = MAXCELLCHARS;
1000 blob.out = cellname;
1002 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1003 return code ? errno : 0;
1006 /* Check if a username is valid: If it contains only digits (or a
1007 * negative sign), then it might be bad. We then query the ptserver
1011 BadName(char *aname, char *fname)
1013 afs_int32 tc, code, id;
1015 char cell[MAXCELLCHARS];
1017 for (nm = aname; (tc = *nm); nm++) {
1018 /* all must be '-' or digit to be bad */
1019 if (tc != '-' && (tc < '0' || tc > '9'))
1023 /* Go to the PRDB and see if this all number username is valid */
1024 code = GetCell(fname, cell);
1028 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
1029 code = pr_SNameToId(aname, &id);
1032 /* 1=>Not-valid; 0=>Valid */
1033 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1037 /* clean up an access control list of its bad entries; return 1 if we made
1038 any changes to the list, and 0 otherwise */
1040 CleanAcl(struct Acl *aa, char *fname)
1042 struct AclEntry *te, **le, *ne;
1045 /* Don't correct DFS ACL's for now */
1049 /* prune out bad entries */
1050 changes = 0; /* count deleted entries */
1052 for (te = aa->pluslist; te; te = ne) {
1054 if (BadName(te->name, fname)) {
1064 le = &aa->minuslist;
1065 for (te = aa->minuslist; te; te = ne) {
1067 if (BadName(te->name, fname)) {
1081 /* clean up an acl to not have bogus entries */
1083 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1087 struct ViceIoctl blob;
1089 struct cmd_item *ti;
1090 struct AclEntry *te;
1093 SetDotDefault(&as->parms[0].items);
1094 for (ti = as->parms[0].items; ti; ti = ti->next) {
1095 blob.out_size = AFS_PIOCTL_MAXSIZE;
1098 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1100 Die(errno, ti->data);
1107 ta = ParseAcl(space);
1110 "%s: cleanacl is not supported for DFS access lists.\n",
1116 changes = CleanAcl(ta, ti->data);
1119 /* now set the acl */
1120 blob.in = AclToString(ta);
1121 blob.in_size = strlen(blob.in) + 1;
1123 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1125 if (errno == EINVAL) {
1127 "%s: Invalid argument, possible reasons include\n",
1129 fprintf(stderr, "%s: File not in vice or\n", pn);
1131 "%s: Too many users on access control list or\n",
1134 Die(errno, ti->data);
1140 /* now list the updated acl */
1141 printf("Access list for %s is now\n", ti->data);
1142 if (ta->nplus > 0) {
1144 printf("Normal rights:\n");
1145 for (te = ta->pluslist; te; te = te->next) {
1146 printf(" %s ", te->name);
1147 PRights(te->rights, ta->dfs);
1151 if (ta->nminus > 0) {
1152 printf("Negative rights:\n");
1153 for (te = ta->minuslist; te; te = te->next) {
1154 printf(" %s ", te->name);
1155 PRights(te->rights, ta->dfs);
1162 printf("Access list for %s is fine.\n", ti->data);
1170 ListACLCmd(struct cmd_syndesc *as, void *arock)
1174 struct ViceIoctl blob;
1175 struct AclEntry *te;
1176 struct cmd_item *ti;
1177 int idf = getidf(as, parm_listacl_id);
1180 SetDotDefault(&as->parms[0].items);
1181 for (ti = as->parms[0].items; ti; ti = ti->next) {
1182 blob.out_size = AFS_PIOCTL_MAXSIZE;
1184 blob.in = blob.out = space;
1185 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1187 Die(errno, ti->data);
1191 ta = ParseAcl(space);
1192 if (as->parms[3].items) { /* -cmd */
1193 printf("fs setacl -dir %s -acl ", ti->data);
1194 if (ta->nplus > 0) {
1195 for (te = ta->pluslist; te; te = te->next) {
1196 printf(" %s ", te->name);
1197 PRights(te->rights, ta->dfs);
1201 if (ta->nminus > 0) {
1202 printf("fs setacl -dir %s -acl ", ti->data);
1203 for (te = ta->minuslist; te; te = te->next) {
1204 printf(" %s ", te->name);
1205 PRights(te->rights, ta->dfs);
1207 printf(" -negative\n");
1212 printf("Access list for %s is\n", ti->data);
1215 printf("DFS access list for %s is\n", ti->data);
1218 printf("DFS initial directory access list of %s is\n", ti->data);
1221 printf("DFS initial file access list of %s is\n", ti->data);
1225 printf(" Default cell = %s\n", ta->cell);
1227 if (ta->nplus > 0) {
1229 printf("Normal rights:\n");
1230 for (te = ta->pluslist; te; te = te->next) {
1231 printf(" %s ", te->name);
1232 PRights(te->rights, ta->dfs);
1236 if (ta->nminus > 0) {
1237 printf("Negative rights:\n");
1238 for (te = ta->minuslist; te; te = te->next) {
1239 printf(" %s ", te->name);
1240 PRights(te->rights, ta->dfs);
1253 GetCallerAccess(struct cmd_syndesc *as, void *arock)
1255 struct cmd_item *ti;
1258 SetDotDefault(&as->parms[0].items);
1259 for (ti = as->parms[0].items; ti; ti = ti->next) {
1261 struct ViceIoctl blob;
1262 struct vcxstat2 stat;
1263 blob.out_size = sizeof(struct vcxstat2);
1265 blob.out = (void *)&stat;
1266 code = pioctl(ti->data, VIOC_GETVCXSTATUS2, &blob, 1);
1268 Die(errno, ti->data);
1272 printf("Callers access to %s is ", ti->data);
1273 PRights(stat.callerAccess, 0);
1280 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1283 struct ViceIoctl blob;
1284 struct cmd_item *ti;
1287 SetDotDefault(&as->parms[0].items);
1288 for (ti = as->parms[0].items; ti; ti = ti->next) {
1289 blob.in_size = blob.out_size = 0;
1290 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1292 fprintf(stderr, "Error flushing volume ");
1302 * The Windows version of UuidCmd displays the UUID.
1303 * When the UNIX version is updated to do the same
1304 * be sure to replace the CMD_REQUIRED flag with
1305 * CMD_OPTIONAL in the cmd_AddParam(-generate) call
1308 UuidCmd(struct cmd_syndesc *as, void *arock)
1311 struct ViceIoctl blob;
1316 if (as->parms[0].items) {
1318 fprintf (stderr, "Permission denied: requires root access.\n");
1322 /* generate new UUID */
1323 code = pioctl(0, VIOC_NEWUUID, &blob, 1);
1330 printf("New uuid generated.\n");
1332 /* This will never execute */
1333 printf("Please add the '-generate' option to generate a new UUID.\n");
1338 #if defined(AFS_CACHE_BYPASS)
1340 * Set cache-bypass threshold. Files larger than this size will not be cached.
1341 * With a threshold of 0, the cache is always bypassed. With a threshold of -1,
1342 * cache bypass is disabled.
1346 BypassThresholdCmd(struct cmd_syndesc *as, void *arock)
1349 struct ViceIoctl blob;
1350 afs_int32 threshold_i, threshold_o;
1353 /* if new threshold supplied, then set and confirm, else,
1354 * get current threshold and print
1357 if(as->parms[0].items) {
1360 tp = as->parms[0].items->data;
1363 if (!strcmp(tp,"-1")) {
1367 for(ix = 0; ix < len; ++ix) {
1368 if(!isdigit(tp[0])) {
1374 fprintf(stderr, "fs bypassthreshold -size: %s must be an integer between -1 and 2^31\n", tp);
1377 threshold_i = atoi(tp);
1378 if(ix > 9 && threshold_i < 2147483647)
1379 threshold_i = 2147483647;
1381 blob.in = (char *) &threshold_i;
1382 blob.in_size = sizeof(threshold_i);
1388 blob.out = (char *) &threshold_o;
1389 blob.out_size = sizeof(threshold_o);
1390 code = pioctl(0, VIOC_SETBYPASS_THRESH, &blob, 1);
1395 printf("Cache bypass threshold %d", threshold_o);
1396 if(threshold_o == -1)
1397 printf(" (disabled)");
1407 FlushCmd(struct cmd_syndesc *as, void *arock)
1410 struct ViceIoctl blob;
1411 struct cmd_item *ti;
1414 for (ti = as->parms[0].items; ti; ti = ti->next) {
1415 blob.in_size = blob.out_size = 0;
1416 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1418 if (errno == EMFILE) {
1419 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1422 fprintf(stderr, "%s: Error flushing file ", pn);
1432 /* all this command does is repackage its args and call SetVolCmd */
1434 SetQuotaCmd(struct cmd_syndesc *as, void *arock)
1436 struct cmd_syndesc ts;
1438 /* copy useful stuff from our command slot; we may later have to reorder */
1439 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1440 return SetVolCmd(&ts, arock);
1444 SetVolCmd(struct cmd_syndesc *as, void *arock)
1447 struct ViceIoctl blob;
1448 struct cmd_item *ti;
1449 struct VolumeStatus *status;
1450 char *offmsg, *input;
1453 SetDotDefault(&as->parms[0].items);
1454 for (ti = as->parms[0].items; ti; ti = ti->next) {
1456 blob.out_size = AFS_PIOCTL_MAXSIZE;
1457 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1460 status = (VolumeStatus *) space;
1461 status->MinQuota = status->MaxQuota = -1;
1463 if (as->parms[1].items) {
1464 code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota);
1466 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1471 if (as->parms[2].items)
1472 offmsg = as->parms[2].items->data;
1473 input = (char *)status + sizeof(*status);
1474 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1476 if (strlen(offmsg) >= VMSGSIZE) {
1478 "%s: message must be shorter than %d characters\n",
1483 strcpy(input, offmsg);
1484 blob.in_size += strlen(offmsg);
1485 input += strlen(offmsg) + 1;
1488 *(input++) = '\0'; /* Pad for old style volume "motd" */
1489 code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1);
1491 Die(errno, ti->data);
1499 * Why is VenusFid declared in the kernel-only section of afs.h,
1500 * if it's the exported interface of the cache manager?
1508 ExamineCmd(struct cmd_syndesc *as, void *arock)
1511 struct ViceIoctl blob;
1512 struct cmd_item *ti;
1513 struct VolumeStatus *status;
1514 char *name, *offmsg;
1517 SetDotDefault(&as->parms[0].items);
1518 for (ti = as->parms[0].items; ti; ti = ti->next) {
1519 struct VenusFid vfid;
1522 blob.out_size = AFS_PIOCTL_MAXSIZE;
1525 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1527 Die(errno, ti->data);
1531 status = (VolumeStatus *) space;
1532 name = (char *)status + sizeof(*status);
1533 offmsg = name + strlen(name) + 1;
1535 blob.out_size = sizeof(struct VenusFid);
1536 blob.out = (char *) &vfid;
1537 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1538 printf("File %s (%u.%u.%u) contained in volume %u\n",
1539 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1543 PrintStatus(status, name, offmsg);
1549 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1552 struct ViceIoctl blob;
1553 struct cmd_item *ti;
1554 struct VolumeStatus *status;
1559 if (as->parms[1].items)
1562 printf("%-25s%-11s%-11s%-7s%-11s\n", "Volume Name", " Quota",
1563 " Used", " %Used", " Partition");
1564 SetDotDefault(&as->parms[0].items);
1565 for (ti = as->parms[0].items; ti; ti = ti->next) {
1567 blob.out_size = AFS_PIOCTL_MAXSIZE;
1570 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1572 Die(errno, ti->data);
1576 status = (VolumeStatus *) space;
1577 name = (char *)status + sizeof(*status);
1578 QuickPrintStatus(status, name, human);
1584 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1587 struct ViceIoctl blob;
1588 struct cmd_item *ti;
1594 SetDotDefault(&as->parms[0].items);
1595 for (ti = as->parms[0].items; ti; ti = ti->next) {
1597 blob.out_size = AFS_PIOCTL_MAXSIZE;
1600 memset(space, 0, sizeof(space));
1601 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1603 Die(errno, ti->data);
1607 hosts = (afs_int32 *) space;
1608 printf("File %s is on host%s ", ti->data,
1609 (hosts[0] && !hosts[1]) ? "" : "s");
1610 for (j = 0; j < AFS_MAXHOSTS; j++) {
1613 tp = hostutil_GetNameByINet(hosts[j]);
1623 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1626 struct ViceIoctl blob;
1627 struct cmd_item *ti;
1629 struct VolumeStatus *status;
1633 if (as->parms[1].items)
1636 printf("%-25s%10s%10s%10s%6s\n", "Volume Name",
1637 human ? "total" : "kbytes", "used", "avail", "%used");
1638 SetDotDefault(&as->parms[0].items);
1639 for (ti = as->parms[0].items; ti; ti = ti->next) {
1641 blob.out_size = AFS_PIOCTL_MAXSIZE;
1644 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1646 Die(errno, ti->data);
1650 status = (VolumeStatus *) space;
1651 name = (char *)status + sizeof(*status);
1652 QuickPrintSpace(status, name, human);
1658 QuotaCmd(struct cmd_syndesc *as, void *arock)
1661 struct ViceIoctl blob;
1662 struct cmd_item *ti;
1664 struct VolumeStatus *status;
1667 SetDotDefault(&as->parms[0].items);
1668 for (ti = as->parms[0].items; ti; ti = ti->next) {
1670 blob.out_size = AFS_PIOCTL_MAXSIZE;
1673 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1675 Die(errno, ti->data);
1679 status = (VolumeStatus *) space;
1680 if (status->MaxQuota)
1682 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
1685 printf("%2.0f%% of quota used.\n", quotaPct);
1691 ListMountCmd(struct cmd_syndesc *as, void *arock)
1694 struct ViceIoctl blob;
1695 struct cmd_item *ti;
1696 char orig_name[1024]; /*Original name, may be modified */
1697 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
1698 char parent_dir[1024]; /*Parent directory of true name */
1699 char *last_component; /*Last component of true name */
1700 struct stat statbuff; /*Buffer for status info */
1701 int link_chars_read; /*Num chars read in readlink() */
1702 int thru_symlink; /*Did we get to a mount point via a symlink? */
1705 for (ti = as->parms[0].items; ti; ti = ti->next) {
1708 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
1711 if (lstat(orig_name, &statbuff) < 0) {
1712 /* if lstat fails, we should still try the pioctl, since it
1713 * may work (for example, lstat will fail, but pioctl will
1714 * work if the volume of offline (returning ENODEV). */
1715 statbuff.st_mode = S_IFDIR; /* lie like pros */
1719 * The lstat succeeded. If the given file is a symlink, substitute
1720 * the file name with the link name.
1722 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1725 * Read name of resolved file.
1727 link_chars_read = readlink(orig_name, true_name, 1024);
1728 if (link_chars_read <= 0) {
1730 "%s: Can't read target name for '%s' symbolic link!\n",
1737 * Add a trailing null to what was read, bump the length.
1739 true_name[link_chars_read++] = 0;
1742 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1743 * have to create a full pathname using the original name and the
1744 * relative symlink name. Find the rightmost slash in the original
1745 * name (we know there is one) and splice in the symlink value.
1747 if (true_name[0] != '/') {
1748 last_component = (char *)strrchr(orig_name, '/');
1749 strcpy(++last_component, true_name);
1750 strcpy(true_name, orig_name);
1753 strcpy(true_name, orig_name);
1756 * Find rightmost slash, if any.
1758 last_component = (char *)strrchr(true_name, '/');
1759 if (last_component == (char *)true_name) {
1760 strcpy(parent_dir, "/");
1763 else if (last_component != (char *)NULL) {
1765 * Found it. Designate everything before it as the parent directory,
1766 * everything after it as the final component.
1768 strncpy(parent_dir, true_name, last_component - true_name);
1769 parent_dir[last_component - true_name] = 0;
1770 last_component++; /*Skip the slash */
1773 * No slash appears in the given file name. Set parent_dir to the current
1774 * directory, and the last component as the given name.
1776 strcpy(parent_dir, ".");
1777 last_component = true_name;
1780 if (strcmp(last_component, ".") == 0
1781 || strcmp(last_component, "..") == 0) {
1783 "%s: you may not use '.' or '..' as the last component\n",
1785 fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n",
1791 blob.in = last_component;
1792 blob.in_size = strlen(last_component) + 1;
1793 blob.out_size = AFS_PIOCTL_MAXSIZE;
1795 memset(space, 0, AFS_PIOCTL_MAXSIZE);
1797 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1800 printf("'%s' is a %smount point for volume '%s'\n", ti->data,
1801 (thru_symlink ? "symbolic link, leading to a " : ""),
1804 if (errno == EINVAL) {
1805 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
1807 Die(errno, (ti->data ? ti->data : parent_dir));
1816 MakeMountCmd(struct cmd_syndesc *as, void *arock)
1819 char *cellName, *volName, *tmpName;
1820 struct afsconf_cell info;
1821 struct vldbentry vldbEntry;
1822 struct ViceIoctl blob;
1828 if (as->parms[5].items && !as->parms[2].items) {
1829 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1834 if (as->parms[2].items) /* cell name specified */
1835 cellName = as->parms[2].items->data;
1838 volName = as->parms[1].items->data;
1840 if (strlen(volName) >= 64) {
1842 "%s: volume name too long (length must be < 64 characters)\n",
1847 /* Check for a cellname in the volume specification, and complain
1848 * if it doesn't match what was specified with -cell */
1849 if ((tmpName = strchr(volName, ':'))) {
1852 if (strcasecmp(cellName, volName)) {
1853 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1858 volName = ++tmpName;
1861 if (!InAFS(Parent(as->parms[0].items->data))) {
1863 "%s: mount points must be created within the AFS file system\n",
1870 blob.out_size = AFS_PIOCTL_MAXSIZE;
1873 pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME,
1877 code = GetCellName(cellName ? cellName : space, &info);
1881 if (!(as->parms[4].items)) {
1882 /* not fast, check which cell the mountpoint is being created in */
1883 /* not fast, check name with VLDB */
1884 code = VLDBInit(1, &info);
1886 /* make the check. Don't complain if there are problems with init */
1888 ubik_VL_GetEntryByNameO(uclient, 0, volName,
1890 if (code == VL_NOENT) {
1892 "%s: warning, volume %s does not exist in cell %s.\n",
1893 pn, volName, cellName ? cellName : space);
1898 if (as->parms[3].items) /* if -rw specified */
1903 /* cellular mount point, prepend cell prefix */
1904 strcat(space, info.name);
1907 strcat(space, volName); /* append volume name */
1908 strcat(space, "."); /* stupid convention; these end with a period */
1909 code = symlink(space, as->parms[0].items->data);
1911 Die(errno, as->parms[0].items->data);
1918 * Delete AFS mount points. Variables are used as follows:
1919 * tbuffer: Set to point to the null-terminated directory name of the mount point
1920 * (or ``.'' if none is provided)
1921 * tp: Set to point to the actual name of the mount point to nuke.
1924 RemoveMountCmd(struct cmd_syndesc *as, void *arock)
1927 struct ViceIoctl blob;
1928 struct cmd_item *ti;
1930 char lsbuffer[1024];
1934 for (ti = as->parms[0].items; ti; ti = ti->next) {
1936 tp = (char *)strrchr(ti->data, '/');
1938 strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */
1940 tp++; /* skip the slash */
1942 strcpy(tbuffer, ".");
1946 blob.in_size = strlen(tp) + 1;
1947 blob.out = lsbuffer;
1948 blob.out_size = sizeof(lsbuffer);
1949 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 1);
1951 if (errno == EINVAL) {
1952 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
1955 Die(errno, ti->data);
1958 continue; /* don't bother trying */
1962 blob.in_size = strlen(tp) + 1;
1963 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 1);
1965 Die(errno, ti->data);
1976 CheckServersCmd(struct cmd_syndesc *as, void *arock)
1979 struct ViceIoctl blob;
1983 struct afsconf_cell info;
1984 struct chservinfo checkserv;
1986 memset(&checkserv, 0, sizeof(struct chservinfo));
1987 blob.in_size = sizeof(struct chservinfo);
1988 blob.in = (caddr_t) & checkserv;
1990 blob.out_size = AFS_PIOCTL_MAXSIZE;
1992 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1994 /* prepare flags for checkservers command */
1995 temp = 2; /* default to checking local cell only */
1996 if (as->parms[2].items)
1997 temp |= 1; /* set fast flag */
1998 if (as->parms[1].items)
1999 temp &= ~2; /* turn off local cell check */
2001 checkserv.magic = 0x12345678; /* XXX */
2002 checkserv.tflags = temp;
2004 /* now copy in optional cell name, if specified */
2005 if (as->parms[0].items) {
2006 code = GetCellName(as->parms[0].items->data, &info);
2010 strcpy(checkserv.tbuffer, info.name);
2011 checkserv.tsize = strlen(info.name) + 1;
2013 strcpy(checkserv.tbuffer, "\0");
2014 checkserv.tsize = 0;
2017 if (as->parms[3].items) {
2018 checkserv.tinterval = atol(as->parms[3].items->data);
2021 if (checkserv.tinterval < 0) {
2023 ("Warning: The negative -interval is ignored; treated as an inquiry\n");
2024 checkserv.tinterval = 0;
2025 } else if (checkserv.tinterval > 600) {
2027 ("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2028 checkserv.tinterval = 600; /* 10 min max interval */
2031 checkserv.tinterval = -1; /* don't change current interval */
2034 code = pioctl(0, VIOCCKSERV, &blob, 1);
2036 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2037 printf("Must be root to change -interval\n");
2043 memcpy(&temp, space, sizeof(afs_int32));
2044 if (checkserv.tinterval >= 0) {
2045 if (checkserv.tinterval > 0)
2047 ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2048 checkserv.tinterval, temp);
2050 printf("The current down server probe interval is %d secs\n",
2055 printf("All servers are running.\n");
2058 ("These servers unavailable due to network or server problems: ");
2060 memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32));
2063 tp = hostutil_GetNameByINet(temp);
2073 MessagesCmd(struct cmd_syndesc *as, void *arock)
2076 struct ViceIoctl blob;
2077 struct gaginfo gagflags;
2078 struct cmd_item *show;
2080 memset(&gagflags, 0, sizeof(struct gaginfo));
2081 blob.in_size = sizeof(struct gaginfo);
2082 blob.in = (caddr_t) & gagflags;
2083 blob.out_size = AFS_PIOCTL_MAXSIZE;
2085 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2087 if ((show = as->parms[0].items)) {
2088 if (!strcasecmp(show->data, "user"))
2089 gagflags.showflags |= GAGUSER;
2090 else if (!strcasecmp(show->data, "console"))
2091 gagflags.showflags |= GAGCONSOLE;
2092 else if (!strcasecmp(show->data, "all"))
2093 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2094 else if (!strcasecmp(show->data, "none"))
2098 "unrecognized flag %s: must be in {user,console,all,none}\n",
2107 code = pioctl(0, VIOC_GAG, &blob, 1);
2117 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2120 struct ViceIoctl blob;
2124 code = pioctl(0, VIOCCKBACK, &blob, 1);
2130 printf("All volumeID/name mappings checked.\n");
2135 PreCacheCmd(struct cmd_syndesc *as, void *arock)
2138 struct ViceIoctl blob;
2141 if (!as->parms[0].items && !as->parms[1].items) {
2142 fprintf(stderr, "%s: syntax error in precache cmd.\n", pn);
2145 if (as->parms[0].items) {
2146 code = util_GetInt32(as->parms[0].items->data, &temp);
2148 fprintf(stderr, "%s: bad integer specified for precache size.\n",
2154 blob.in = (char *)&temp;
2155 blob.in_size = sizeof(afs_int32);
2157 code = pioctl(0, VIOCPRECACHE, &blob, 1);
2163 printf("New precache size set.\n");
2168 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2171 struct ViceIoctl blob;
2174 if (!as->parms[0].items && !as->parms[1].items) {
2175 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
2178 if (as->parms[0].items) {
2179 code = util_GetHumanInt32(as->parms[0].items->data, &temp);
2181 fprintf(stderr, "%s: bad integer specified for cache size.\n",
2187 blob.in = (char *)&temp;
2188 blob.in_size = sizeof(afs_int32);
2190 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2192 if (errno == EROFS) {
2194 ("'fs setcache' not allowed on memory cache based cache managers.\n");
2201 printf("New cache size set.\n");
2205 #define MAXGCSIZE 16
2207 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2209 afs_int32 code, filesUsed;
2210 struct ViceIoctl blob;
2211 afs_int32 parms[MAXGCSIZE];
2212 double percentFiles, percentBlocks;
2213 afs_int32 flags = 0;
2215 if (as->parms[0].items){ /* -files */
2217 } else if (as->parms[1].items){ /* -excessive */
2223 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
2225 blob.in = (char *)&flags;
2226 blob.in_size = sizeof(afs_int32);
2227 } else { /* be backward compatible */
2231 blob.out_size = sizeof(parms);
2232 blob.out = (char *)parms;
2233 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2240 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2241 parms[1], parms[0]);
2242 if (parms[1] > parms[0])
2243 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2247 percentBlocks = ((double)parms[1]/parms[0]) * 100;
2248 printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n",
2249 percentBlocks, parms[1], parms[0]);
2254 filesUsed = parms[2] - parms[3];
2255 percentFiles = ((double)filesUsed/parms[2]) * 100;
2256 printf(" %5.0f%% of the cache files (%d of %d files)\n",
2257 percentFiles, filesUsed, parms[2]);
2259 printf(" afs_cacheFiles: %10d\n", parms[2]);
2260 printf(" IFFree: %10d\n", parms[3]);
2261 printf(" IFEverUsed: %10d\n", parms[4]);
2262 printf(" IFDataMod: %10d\n", parms[5]);
2263 printf(" IFDirtyPages: %10d\n", parms[6]);
2264 printf(" IFAnyPages: %10d\n", parms[7]);
2265 printf(" IFDiscarded: %10d\n", parms[8]);
2266 printf(" DCentries: %10d\n", parms[9]);
2267 printf(" 0k- 4K: %10d\n", parms[10]);
2268 printf(" 4k- 16k: %10d\n", parms[11]);
2269 printf(" 16k- 64k: %10d\n", parms[12]);
2270 printf(" 64k- 256k: %10d\n", parms[13]);
2271 printf(" 256k- 1M: %10d\n", parms[14]);
2272 printf(" >=1M: %10d\n", parms[15]);
2275 if (percentBlocks > 90)
2276 printf("[cache size usage over 90%%, consider increasing cache size]\n");
2277 if (percentFiles > 90)
2278 printf("[cache file usage over 90%%, consider increasing '-files' argument to afsd]\n");
2284 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2289 struct ViceIoctl blob;
2292 resolve = !(as->parms[0].items); /* -numeric */
2296 memcpy(tp, &i, sizeof(afs_int32));
2297 blob.out_size = AFS_PIOCTL_MAXSIZE;
2298 blob.in_size = sizeof(afs_int32);
2301 code = pioctl(0, VIOCGETCELL, &blob, 1);
2304 break; /* done with the list */
2309 printf("Cell %s on hosts", tp + AFS_MAXCELLHOSTS * sizeof(afs_int32));
2310 for (j = 0; j < AFS_MAXCELLHOSTS; j++) {
2312 char *name, tbuffer[20];
2314 memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32));
2319 name = hostutil_GetNameByINet(addr);
2322 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2323 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2326 printf(" %s", name);
2334 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2337 char *tp, *aliasName, *realName;
2338 struct ViceIoctl blob;
2342 memcpy(tp, &i, sizeof(afs_int32));
2343 blob.out_size = AFS_PIOCTL_MAXSIZE;
2344 blob.in_size = sizeof(afs_int32);
2347 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2350 break; /* done with the list */
2356 tp += strlen(aliasName) + 1;
2358 printf("Alias %s for cell %s\n", aliasName, realName);
2364 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2367 struct ViceIoctl blob;
2368 struct cmd_item *ti;
2370 struct hostent *thp;
2373 ti = as->parms[0].items;
2376 thp = hostutil_GetHostByName(ti->data);
2378 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2381 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2383 hostAddr = 0; /* means don't set host */
2384 setp = 0; /* aren't setting host */
2387 /* now do operation */
2388 blob.in_size = sizeof(afs_int32);
2389 blob.out_size = sizeof(afs_int32);
2390 blob.in = (char *) &hostAddr;
2391 blob.out = (char *) &hostAddr;
2393 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2402 NukeNFSCredsCmd(struct cmd_syndesc *as, void *arock)
2405 struct ViceIoctl blob;
2406 struct cmd_item *ti;
2408 struct hostent *thp;
2410 ti = as->parms[0].items;
2411 thp = hostutil_GetHostByName(ti->data);
2413 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2416 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2418 /* now do operation */
2419 blob.in_size = sizeof(afs_int32);
2420 blob.out_size = sizeof(afs_int32);
2421 blob.in = (char *) &hostAddr;
2422 blob.out = (char *) &hostAddr;
2424 code = pioctl(0, VIOC_NFS_NUKE_CREDS, &blob, 1);
2433 NewCellCmd(struct cmd_syndesc *as, void *arock)
2435 afs_int32 code, linkedstate = 0, size = 0, *lp;
2436 struct ViceIoctl blob;
2437 struct cmd_item *ti;
2438 char *tp, *cellname = 0;
2439 struct hostent *thp;
2440 afs_int32 fsport = 0, vlport = 0;
2441 afs_int32 scount; /* Number of servers to pass in pioctl call */
2444 * With the NEWCELL pioctl call, 3.4 clients take an array of
2445 * AFS_MAXHOSTS (13) servers while 3.5 clients take an array of
2446 * AFS_MAXCELLHOSTS (8) servers. To determine which we are talking to,
2447 * do a GETCELL pioctl and pass it a magic number. If an array of
2448 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
2449 * If we get back EDOM, there are no cells in the kernel yet,
2450 * and we'll assume a 3.5 client.
2453 lp = (afs_int32 *) tp;
2454 *lp++ = 0; /* first cell entry */
2455 *lp = 0x12345678; /* magic */
2456 blob.out_size = AFS_PIOCTL_MAXSIZE;
2457 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
2460 code = pioctl(0, VIOCGETCELL, &blob, 1);
2461 if (code < 0 && errno != EDOM) {
2465 if (code < 1 && errno == EDOM) {
2466 scount = AFS_MAXHOSTS;
2469 cellname = tp + AFS_MAXCELLHOSTS * sizeof(afs_int32);
2470 scount = ((cellname[0] != '\0') ? AFS_MAXCELLHOSTS : AFS_MAXHOSTS);
2473 /* Now setup and do the NEWCELL pioctl call */
2474 memset(space, 0, (scount + 1) * sizeof(afs_int32));
2476 lp = (afs_int32 *) tp;
2478 tp += sizeof(afs_int32);
2479 for (ti = as->parms[1].items; ti; ti = ti->next) {
2480 thp = hostutil_GetHostByName(ti->data);
2483 "%s: Host %s not found in host table, skipping it.\n", pn,
2486 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2487 tp += sizeof(afs_int32);
2490 if (as->parms[2].items) {
2492 * Link the cell, for the purposes of volume location, to the specified
2495 cellname = as->parms[2].items->data;
2498 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2499 if (as->parms[3].items) {
2500 code = util_GetInt32(as->parms[3].items->data, &vlport);
2503 "%s: bad integer specified for the fileserver port.\n",
2508 if (as->parms[4].items) {
2509 code = util_GetInt32(as->parms[4].items->data, &fsport);
2512 "%s: bad integer specified for the vldb server port.\n",
2518 tp = (char *)(space + (scount + 1) * sizeof(afs_int32));
2519 lp = (afs_int32 *) tp;
2523 strcpy(space + ((scount + 4) * sizeof(afs_int32)),
2524 as->parms[0].items->data);
2525 size = ((scount + 4) * sizeof(afs_int32))
2526 + strlen(as->parms[0].items->data)
2527 + 1 /* for null */ ;
2528 tp = (char *)(space + size);
2530 strcpy(tp, cellname);
2531 size += strlen(cellname) + 1;
2533 blob.in_size = size;
2536 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2545 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2548 struct ViceIoctl blob;
2550 char *aliasName, *realName;
2552 /* Now setup and do the NEWCELL pioctl call */
2553 aliasName = as->parms[0].items->data;
2554 realName = as->parms[1].items->data;
2556 strcpy(tp, aliasName);
2557 tp += strlen(aliasName) + 1;
2558 strcpy(tp, realName);
2559 tp += strlen(realName) + 1;
2561 blob.in_size = tp - space;
2565 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2567 if (errno == EEXIST) {
2569 "%s: cell name `%s' in use by an existing cell.\n", pn,
2580 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2583 struct cmd_item *ti;
2585 char cell[MAXCELLCHARS];
2587 SetDotDefault(&as->parms[0].items);
2588 for (ti = as->parms[0].items; ti; ti = ti->next) {
2589 code = GetCell(ti->data, cell);
2591 if (errno == ENOENT)
2592 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
2594 Die(errno, ti->data);
2599 printf("File %s lives in cell '%s'\n", ti->data, cell);
2605 WSCellCmd(struct cmd_syndesc *as, void *arock)
2608 struct ViceIoctl blob;
2612 blob.out_size = AFS_PIOCTL_MAXSIZE;
2615 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2621 printf("This workstation belongs to cell '%s'\n", space);
2626 static PrimaryCellCmd(as)
2627 struct cmd_syndesc *as;
2629 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2635 MonitorCmd(struct cmd_syndesc *as, void *arock)
2638 struct ViceIoctl blob;
2639 struct cmd_item *ti;
2641 struct hostent *thp;
2645 ti = as->parms[0].items;
2649 if (!strcmp(ti->data, "off"))
2650 hostAddr = 0xffffffff;
2652 thp = hostutil_GetHostByName(ti->data);
2654 if (!strcmp(ti->data, "localhost")) {
2656 "localhost not in host table, assuming 127.0.0.1\n");
2657 hostAddr = htonl(0x7f000001);
2659 fprintf(stderr, "host %s not found in host table.\n",
2664 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2667 hostAddr = 0; /* means don't set host */
2668 setp = 0; /* aren't setting host */
2671 /* now do operation */
2672 blob.in_size = sizeof(afs_int32);
2673 blob.out_size = sizeof(afs_int32);
2674 blob.in = (char *)&hostAddr;
2675 blob.out = (char *)&hostAddr;
2676 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2682 printf("%s: new monitor host set.\n", pn);
2684 /* now decode old address */
2685 if (hostAddr == 0xffffffff) {
2686 printf("Cache monitoring is currently disabled.\n");
2688 tp = hostutil_GetNameByINet(hostAddr);
2689 printf("Using host %s for monitor services.\n", tp);
2696 SysNameCmd(struct cmd_syndesc *as, void *arock)
2699 struct ViceIoctl blob;
2700 struct cmd_item *ti;
2701 char *input = space;
2704 ti = as->parms[0].items;
2707 blob.out_size = AFS_PIOCTL_MAXSIZE;
2708 blob.in_size = sizeof(afs_int32);
2709 input += sizeof(afs_int32);
2710 for (; ti; ti = ti->next) {
2712 blob.in_size += strlen(ti->data) + 1;
2713 if (blob.in_size > AFS_PIOCTL_MAXSIZE) {
2714 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2715 setp > 1 ? "s" : "");
2718 strcpy(input, ti->data);
2719 input += strlen(ti->data);
2722 memcpy(space, &setp, sizeof(afs_int32));
2723 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2729 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2733 memcpy(&setp, input, sizeof(afs_int32));
2734 input += sizeof(afs_int32);
2736 fprintf(stderr, "No sysname name value was found\n");
2739 printf("Current sysname%s is", setp > 1 ? " list" : "");
2740 for (; setp > 0; --setp) {
2741 printf(" \'%s\'", input);
2742 input += strlen(input) + 1;
2748 static char *exported_types[] = { "null", "nfs", "" };
2750 ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2753 struct ViceIoctl blob;
2754 struct cmd_item *ti;
2755 int export = 0, type = 0, mode = 0, exp = 0, exportcall, pwsync =
2756 0, smounts = 0, clipags = 0, pagcb = 0;
2758 ti = as->parms[0].items;
2759 if (strcmp(ti->data, "nfs") == 0)
2760 type = 0x71; /* NFS */
2763 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n",
2767 ti = as->parms[1].items;
2769 if (strcmp(ti->data, "on") == 0)
2771 else if (strcmp(ti->data, "off") == 0)
2774 fprintf(stderr, "Illegal argument %s\n", ti->data);
2779 if ((ti = as->parms[2].items)) { /* -noconvert */
2780 if (strcmp(ti->data, "on") == 0)
2782 else if (strcmp(ti->data, "off") == 0)
2785 fprintf(stderr, "Illegal argument %s\n", ti->data);
2789 if ((ti = as->parms[3].items)) { /* -uidcheck */
2790 if (strcmp(ti->data, "on") == 0)
2792 else if (strcmp(ti->data, "off") == 0)
2795 fprintf(stderr, "Illegal argument %s\n", ti->data);
2799 if ((ti = as->parms[4].items)) { /* -submounts */
2800 if (strcmp(ti->data, "on") == 0)
2802 else if (strcmp(ti->data, "off") == 0)
2805 fprintf(stderr, "Illegal argument %s\n", ti->data);
2809 if ((ti = as->parms[5].items)) { /* -clipags */
2810 if (strcmp(ti->data, "on") == 0)
2812 else if (strcmp(ti->data, "off") == 0)
2815 fprintf(stderr, "Illegal argument %s\n", ti->data);
2819 if ((ti = as->parms[6].items)) { /* -pagcb */
2820 if (strcmp(ti->data, "on") == 0)
2822 else if (strcmp(ti->data, "off") == 0)
2825 fprintf(stderr, "Illegal argument %s\n", ti->data);
2830 (type << 24) | (pagcb << 10) | (clipags << 8) |
2831 (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2834 blob.in = (char *)&exportcall;
2835 blob.in_size = sizeof(afs_int32);
2836 blob.out = (char *)&exportcall;
2837 blob.out_size = sizeof(afs_int32);
2838 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2840 if (errno == ENODEV) {
2842 "Sorry, the %s-exporter type is currently not supported on this AFS client\n",
2843 exported_types[type]);
2850 if (exportcall & 1) {
2851 printf("'%s' translator is enabled with the following options:\n",
2852 exported_types[type]);
2853 printf("\tRunning in %s mode\n",
2854 (exportcall & 2 ? "strict unix" :
2855 "convert owner mode bits to world/other"));
2856 printf("\tRunning in %s mode\n",
2857 (exportcall & 4 ? "strict 'passwd sync'" :
2858 "no 'passwd sync'"));
2860 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
2861 "Only mounts to /afs allowed"));
2863 (exportcall & 16 ? "Client-assigned PAG's are used" :
2864 "Client-assigned PAG's are not used"));
2867 "Callbacks are made to get creds from new clients" :
2868 "Callbacks are not made to get creds from new clients"));
2870 printf("'%s' translator is disabled\n", exported_types[type]);
2877 GetCellCmd(struct cmd_syndesc *as, void *arock)
2880 struct ViceIoctl blob;
2881 struct afsconf_cell info;
2882 struct cmd_item *ti;
2889 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2890 for (ti = as->parms[0].items; ti; ti = ti->next) {
2892 blob.out_size = sizeof(args);
2893 blob.out = (caddr_t) & args;
2894 code = GetCellName(ti->data, &info);
2899 blob.in_size = 1 + strlen(info.name);
2900 blob.in = info.name;
2901 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2903 if (errno == ENOENT)
2904 fprintf(stderr, "%s: the cell named '%s' does not exist\n",
2907 Die(errno, info.name);
2911 printf("Cell %s status: ", info.name);
2917 printf("no setuid allowed");
2919 printf("setuid allowed");
2921 printf(", using old VLDB");
2928 SetCellCmd(struct cmd_syndesc *as, void *arock)
2931 struct ViceIoctl blob;
2932 struct afsconf_cell info;
2933 struct cmd_item *ti;
2941 /* Check arguments. */
2942 if (as->parms[1].items && as->parms[2].items) {
2943 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2947 /* figure stuff to set */
2951 if (!as->parms[1].items)
2952 args.stat |= 2; /* default to -nosuid */
2954 /* set stat for all listed cells */
2955 for (ti = as->parms[0].items; ti; ti = ti->next) {
2957 code = GetCellName(ti->data, &info);
2962 strcpy(args.cname, info.name);
2963 blob.in_size = sizeof(args);
2964 blob.in = (caddr_t) & args;
2966 blob.out = (caddr_t) 0;
2967 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2969 Die(errno, info.name); /* XXX added cell name to Die() call */
2977 GetCellName(char *cellName, struct afsconf_cell *info)
2979 struct afsconf_dir *tdir;
2982 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2985 "Could not process files in configuration directory (%s).\n",
2986 AFSDIR_CLIENT_ETC_DIRPATH);
2990 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2992 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2993 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
3002 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3006 code = ugen_ClientInit(noAuthFlag, (char *) AFSDIR_CLIENT_ETC_DIRPATH,
3007 info->name, 0, &uclient,
3008 NULL, pn, rxkad_clear,
3009 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3010 0, 0, USER_SERVICE_ID);
3015 static struct ViceIoctl gblob;
3016 static int debug = 0;
3018 * here follow some routines in suport of the setserverprefs and
3019 * getserverprefs commands. They are:
3020 * SetPrefCmd "top-level" routine
3021 * addServer adds a server to the list of servers to be poked into the
3022 * kernel. Will poke the list into the kernel if it threatens
3024 * pokeServers pokes the existing list of servers and ranks into the kernel
3025 * GetPrefCmd reads the Cache Manager's current list of server ranks
3029 * returns -1 if error message printed,
3031 * errno value if error and no error message printed
3038 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
3039 if (code && (errno == EINVAL)) {
3040 struct setspref *ssp;
3041 ssp = (struct setspref *)gblob.in;
3042 if (!(ssp->flags & DBservers)) {
3043 gblob.in = (void *)&(ssp->servers[0]);
3044 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3045 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
3046 return code ? errno : 0;
3049 "This cache manager does not support VL server preferences.\n");
3053 return code ? errno : 0;
3057 * returns -1 if error message printed,
3059 * errno value if error and no error message printed
3062 addServer(char *name, afs_int32 rank)
3065 struct setspref *ssp;
3067 struct hostent *thostent;
3072 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3074 #define MAXUSHORT ((unsigned short) ~0)
3078 thostent = hostutil_GetHostByName(name);
3080 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3084 ssp = (struct setspref *)(gblob.in);
3086 for (t = 0; thostent->h_addr_list[t]; t++) {
3087 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3088 code = pokeServers();
3091 ssp->num_servers = 0;
3094 sp = (struct spref *)(gblob.in + gblob.in_size);
3095 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3096 sizeof(afs_uint32));
3097 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3098 gblob.in_size += sizeof(struct spref);
3102 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3103 name, sp->rank, (long unsigned int) sp->server.s_addr);
3111 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3115 struct cmd_item *ti;
3118 struct setspref *ssp;
3119 int error = 0; /* -1 means error message printed,
3120 * >0 means errno value for unprinted message */
3122 ssp = (struct setspref *)space;
3124 ssp->num_servers = 0;
3125 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3128 gblob.out_size = AFS_PIOCTL_MAXSIZE;
3132 fprintf(stderr, "Permission denied: requires root access.\n");
3136 ti = as->parms[2].items; /* -file */
3139 fprintf(stderr, "opening file %s\n", ti->data);
3140 if (!(infd = fopen(ti->data, "r"))) {
3144 while (fscanf(infd, "%79s%ld", name, (long int *)&rank) != EOF) {
3145 code = addServer(name, (unsigned short)rank);
3152 ti = as->parms[3].items; /* -stdin */
3154 while (scanf("%79s%ld", name, (long int *)&rank) != EOF) {
3155 code = addServer(name, (unsigned short)rank);
3161 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3166 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3170 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3174 code = pokeServers();
3178 printf("now working on vlservers, code=%d\n", code);
3180 ssp = (struct setspref *)space;
3181 ssp->flags = DBservers;
3182 ssp->num_servers = 0;
3183 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3186 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3191 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3195 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3200 if (as->parms[1].items) {
3202 printf("now poking vlservers\n");
3203 code = pokeServers();
3211 return error ? 1 : 0;
3217 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3220 struct cmd_item *ti;
3221 char *name, tbuffer[20];
3226 struct ViceIoctl blob;
3227 struct sprefrequest *in;
3228 struct sprefinfo *out;
3231 ti = as->parms[0].items; /* -file */
3234 fprintf(stderr, "opening file %s\n", ti->data);
3235 if (!(outfd = freopen(ti->data, "w", stdout))) {
3241 ti = as->parms[1].items; /* -numeric */
3243 ti = as->parms[2].items; /* -vlservers */
3244 vlservers |= (ti ? DBservers : 0);
3245 /* ti = as->parms[3].items; -cell */
3247 in = (struct sprefrequest *)space;
3251 blob.in_size = sizeof(struct sprefrequest);
3252 blob.in = (char *)in;
3254 blob.out_size = AFS_PIOCTL_MAXSIZE;
3257 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3258 in->flags = vlservers;
3261 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3263 if ((errno != E2BIG) || (2 * blob.out_size > 0x7FFF)) {
3264 perror("getserverprefs pioctl");
3268 if (blob.out == space)
3269 blob.out = malloc(blob.out_size);
3271 blob.out = realloc(blob.out, blob.out_size);
3273 } while (code != 0);
3275 out = (struct sprefinfo *)blob.out;
3277 for (i = 0; i < out->num_servers; i++) {
3279 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3281 addr = ntohl(out->servers[i].server.s_addr);
3282 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3283 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3286 printf("%-50s %5u\n", name, out->servers[i].rank);
3289 in->offset = out->next_offset;
3290 } while (out->next_offset > 0);
3292 if (blob.out != space)
3299 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
3302 struct ViceIoctl blob;
3303 struct cmd_item *ti;
3304 struct sbstruct tsb, tsb2;
3310 tsb.sb_thisfile = -1;
3311 ti = as->parms[0].items; /* -kbytes */
3313 if (!as->parms[1].items) {
3314 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3318 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3319 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3320 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3326 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3327 ti = as->parms[2].items; /* -allfiles */
3329 allfiles = strtol(ti->data, &t, 10) * 1024;
3330 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3331 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3337 /* -verbose or -file only or no options */
3338 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3339 || (!as->parms[0].items && !as->parms[1].items
3340 && !as->parms[2].items))
3343 blob.in = (char *)&tsb;
3344 blob.in_size = sizeof(struct sbstruct);
3346 /* once per -file */
3347 for (ti = as->parms[1].items; ti; ti = ti->next) {
3348 /* Do this solely to see if the file is there */
3351 blob.out_size = AFS_PIOCTL_MAXSIZE;
3352 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3354 Die(errno, ti->data);
3359 memset(&tsb2, 0, sizeof(tsb2));
3360 blob.out = (char *)&tsb2;
3361 blob.out_size = sizeof(struct sbstruct);
3362 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
3364 Die(errno, ti->data);
3369 if (verbose && (blob.out_size == sizeof(tsb2))) {
3370 if (tsb2.sb_thisfile == -1) {
3371 fprintf(stdout, "Will store %s according to default.\n",
3375 "Will store up to %d kbytes of %s asynchronously.\n",
3376 (tsb2.sb_thisfile / 1024), ti->data);
3381 /* If no files - make at least one pioctl call, or
3382 * set the allfiles default if we need to.
3384 if (!as->parms[1].items || (allfiles != -1)) {
3385 tsb.sb_default = allfiles;
3386 memset(&tsb2, 0, sizeof(tsb2));
3387 blob.out = (char *)&tsb2;
3388 blob.out_size = sizeof(struct sbstruct);
3389 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
3391 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3396 /* Having no arguments also reports the default store asynchrony */
3397 if (!error && verbose && (blob.out_size == sizeof(tsb2))) {
3398 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3399 (tsb2.sb_default / 1024));
3407 SetCryptCmd(struct cmd_syndesc *as, void *arock)
3409 afs_int32 code = 0, flag;
3410 struct ViceIoctl blob;
3413 tp = as->parms[0].items->data;
3414 if (strcmp(tp, "on") == 0)
3416 else if (strcmp(tp, "off") == 0)
3419 fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3423 blob.in = (char *)&flag;
3424 blob.in_size = sizeof(flag);
3426 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3434 GetCryptCmd(struct cmd_syndesc *as, void *arock)
3436 afs_int32 code = 0, flag;
3437 struct ViceIoctl blob;
3442 blob.out_size = sizeof(flag);
3445 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3451 memcpy(&flag, tp, sizeof(afs_int32));
3452 printf("Security level is currently ");
3454 printf("crypt (data security).\n");
3461 static char *modenames[] = {
3464 "readonly", /* Not currently supported */
3465 "fetchonly", /* Not currently supported */
3466 "partial", /* Not currently supported */
3470 static char *policynames[] = {
3473 "closer", /* Not currently supported. */
3474 "manual", /* Not currently supported. */
3479 DisconCmd(struct cmd_syndesc *as, void *arock)
3481 struct cmd_item *ti;
3484 int modelen, policylen;
3485 afs_int32 mode, policy, code, unixuid = 0;
3486 struct ViceIoctl blob;
3491 space[0] = space[1] = space[2] = space[3] = 0;
3493 ti = as->parms[0].items;
3495 modename = ti->data;
3496 modelen = strlen(modename);
3497 for (mode = 0; modenames[mode] != NULL; mode++)
3498 if (!strncasecmp(modename, modenames[mode], modelen))
3500 if (modenames[mode] == NULL)
3501 printf("Unknown discon mode \"%s\"\n", modename);
3503 space[0] = mode + 1;
3506 ti = as->parms[1].items;
3508 policyname = ti->data;
3509 policylen = strlen(policyname);
3510 for (policy = 0; policynames[policy] != NULL; policy++)
3511 if (!strncasecmp(policyname, policynames[policy], policylen))
3513 if (policynames[policy] == NULL)
3514 printf("Unknown discon mode \"%s\"\n", policyname);
3516 space[1] = policy + 1;
3520 if (as->parms[2].items) {
3522 printf("force on\n");
3525 ti = as->parms[3].items;
3527 code = util_GetInt32(ti->data, &unixuid);
3529 fprintf(stderr, "%s: bad integer specified for uid.\n", pn);
3537 blob.in_size = 4 * sizeof(afs_int32);
3539 blob.out_size = sizeof(mode);
3541 code = pioctl(0, VIOC_DISCON, &blob, 1);
3545 memcpy(&mode, space, sizeof mode);
3546 if (mode < sizeof modenames / sizeof (char *))
3547 printf("Discon mode is now \"%s\"\n", modenames[mode]);
3549 printf("Unknown discon mode %d\n", mode);
3555 #include "AFS_component_version_number.c"
3558 main(int argc, char **argv)
3561 struct cmd_syndesc *ts;
3563 #ifdef AFS_AIX32_ENV
3565 * The following signal action for AIX is necessary so that in case of a
3566 * crash (i.e. core is generated) we can include the user's data section
3567 * in the core dump. Unfortunately, by default, only a partial core is
3568 * generated which, in many cases, isn't too useful.
3570 struct sigaction nsa;
3572 sigemptyset(&nsa.sa_mask);
3573 nsa.sa_handler = SIG_DFL;
3574 nsa.sa_flags = SA_FULLDUMP;
3575 sigaction(SIGSEGV, &nsa, NULL);
3578 /* try to find volume location information */
3579 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
3580 "get client network interface addresses");
3581 cmd_CreateAlias(ts, "gc");
3583 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
3584 "set client network interface addresses");
3585 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3586 "client network interfaces");
3587 cmd_CreateAlias(ts, "sc");
3589 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL,
3590 "set server ranks");
3591 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3592 "fileserver names and ranks");
3593 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3594 "VL server names and ranks");
3595 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3596 "input from named file");
3597 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3598 cmd_CreateAlias(ts, "sp");
3600 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL,
3601 "get server ranks");
3602 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3603 "output to named file");
3604 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3605 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3606 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3607 cmd_CreateAlias(ts, "gp");
3609 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
3610 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3611 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3612 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3613 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL,
3614 "apply to negative rights");
3615 parm_setacl_id = ts->nParms;
3616 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL,
3617 "initial directory acl (DFS only)");
3618 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL,
3619 "initial file acl (DFS only)");
3620 cmd_CreateAlias(ts, "sa");
3622 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL,
3623 "list access control list");
3624 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3625 parm_listacl_id = ts->nParms;
3626 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3627 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3628 cmd_AddParm(ts, "-cmd", CMD_FLAG, CMD_OPTIONAL, "output as 'fs setacl' command");
3629 cmd_CreateAlias(ts, "la");
3631 ts = cmd_CreateSyntax("getcalleraccess", GetCallerAccess, NULL,
3632 "list callers access");
3633 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3634 cmd_CreateAlias(ts, "gca");
3636 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL,
3637 "clean up access control list");
3638 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3640 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL,
3641 "copy access control list");
3642 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0,
3643 "source directory (or DFS file)");
3644 cmd_AddParm(ts, "-todir", CMD_LIST, 0,
3645 "destination directory (or DFS file)");
3646 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3647 "first clear dest access list");
3648 parm_copyacl_id = ts->nParms;
3649 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3650 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3652 cmd_CreateAlias(ts, "ca");
3654 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
3655 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3656 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
3657 "flush mount symlink from cache");
3658 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3660 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
3661 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3662 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL,
3663 "disk space quota in 1K units");
3665 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL,
3666 "disk space guaranteed");
3667 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3669 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL,
3671 cmd_CreateAlias(ts, "sv");
3673 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL,
3674 "control Cache Manager messages");
3675 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL,
3676 "[user|console|all|none]");
3678 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
3679 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3680 cmd_CreateAlias(ts, "lv");
3681 cmd_CreateAlias(ts, "listvol");
3683 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
3684 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3685 cmd_AddParm(ts, "-human", CMD_FLAG, CMD_OPTIONAL, "human-readable listing");
3686 cmd_CreateAlias(ts, "lq");
3688 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL,
3689 "show server disk space usage");
3690 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3691 cmd_AddParm(ts, "-human", CMD_FLAG, CMD_OPTIONAL, "human-readable listing");
3692 cmd_CreateAlias(ts, "df");
3694 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
3695 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3697 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
3698 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3700 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
3701 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3702 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3703 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3704 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3705 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3706 "don't check name with VLDB");
3708 #if defined(AFS_CACHE_BYPASS)
3709 ts = cmd_CreateSyntax("bypassthreshold", BypassThresholdCmd, 0,
3710 "get/set cache bypass file size threshold");
3711 cmd_AddParm(ts, "-size", CMD_SINGLE, CMD_OPTIONAL, "file size");
3718 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3722 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
3723 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3725 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL,
3726 "check local cell's servers");
3727 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3728 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3729 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3730 "just list, don't check");
3731 cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL,
3732 "seconds between probes");
3734 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL,
3735 "check volumeID/name mappings");
3736 cmd_CreateAlias(ts, "checkbackups");
3739 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL,
3741 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3742 "size in 1K byte blocks (0 => reset)");
3743 cmd_CreateAlias(ts, "cachesize");
3745 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL,
3746 "reset size back to boot value");
3748 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL,
3749 "get cache usage info");
3750 cmd_AddParm(ts, "-files", CMD_FLAG, CMD_OPTIONAL, "Show cach files used as well");
3751 cmd_AddParm(ts, "-excessive", CMD_FLAG, CMD_OPTIONAL, "excessively verbose cache stats");
3753 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL,
3754 "list configured cells");
3755 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3757 ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, NULL,
3758 "list configured cell aliases");
3760 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
3761 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3762 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3764 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3766 cmd_CreateAlias(ts, "sq");
3768 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
3769 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3770 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3771 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL,
3772 "linked cell name");
3774 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
3775 "configure new cell alias");
3776 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
3777 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
3779 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3781 * Turn this on only if you wish to be able to talk to a server which is listening
3782 * on alternative ports. This is not intended for general use and may not be
3783 * supported in the cache manager. It is not a way to run two servers at the
3784 * same host, since the cache manager cannot properly distinguish those two hosts.
3786 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL,
3787 "cell's fileserver port");
3788 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL,
3789 "cell's vldb server port");
3792 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
3793 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3795 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
3796 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3798 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
3801 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, NULL, "obsolete (listed primary cell)");
3804 /* set cache monitor host address */
3805 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, (char *)CMD_HIDDEN);
3806 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL,
3807 "host name or 'off'");
3808 cmd_CreateAlias(ts, "mariner");
3810 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
3811 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3813 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
3814 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3815 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3816 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL,
3817 "disallow setuid programs");
3819 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL,
3820 "flush all data in volume");
3821 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3823 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL,
3824 "get/set sysname (i.e. @sys) value");
3825 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3827 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL,
3828 "enable/disable translators to AFS");
3829 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3830 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL,
3831 "start/stop translator (on | off)");
3832 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL,
3833 "convert from afs to unix mode (on | off)");
3834 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL,
3835 "run on strict 'uid check' mode (on | off)");
3836 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
3837 "allow nfs mounts to subdirs of /afs/.. (on | off)");
3838 cmd_AddParm(ts, "-clipags", CMD_SINGLE, CMD_OPTIONAL,
3839 "enable use of client-assigned PAG's (on | off)");
3840 cmd_AddParm(ts, "-pagcb", CMD_SINGLE, CMD_OPTIONAL,
3841 "enable callbacks to get creds from new clients (on | off)");
3844 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
3845 "store to server after file close");
3846 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL,
3847 "asynchrony for specified names");
3848 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3849 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL,
3850 "new default (KB)");
3851 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3852 cmd_CreateAlias(ts, "sb");
3854 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL,
3855 "set cache manager encryption flag");
3856 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3858 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL,
3859 "get cache manager encryption flag");
3861 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
3862 "Manage per process RX statistics");
3863 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3864 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3865 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3867 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
3868 "Manage per peer RX statistics");
3869 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3870 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3871 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3873 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
3874 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
3876 /* try to find volume location information */
3877 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL,
3878 "get fid for file(s)");
3879 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3881 ts = cmd_CreateSyntax("discon", DisconCmd, NULL,
3882 "disconnection mode");
3883 cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_REQUIRED, "offline | online");
3884 cmd_AddParm(ts, "-policy", CMD_SINGLE, CMD_OPTIONAL, "client | server");
3885 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Force reconnection, despite any synchronization issues.");
3886 cmd_AddParm(ts, "-uid", CMD_SINGLE, CMD_OPTIONAL, "Numeric UID of user whose tokens to use at reconnect.");
3888 ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, NULL, "nuke credentials for NFS client");
3889 cmd_AddParm(ts, "-addr", CMD_SINGLE, 0, "host name or address");
3891 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
3892 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_REQUIRED, "generate a new UUID");
3894 ts = cmd_CreateSyntax("precache", PreCacheCmd, 0,
3895 "set precache size");
3896 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3897 "size in 1K byte blocks (0 => disable)");
3899 code = cmd_Dispatch(argc, argv);
3907 Die(int errnum, char *filename)
3913 "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3916 fprintf(stderr, "%s: Invalid argument.\n", pn);
3920 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3922 fprintf(stderr, "%s: no such file returned\n", pn);
3926 "%s: You can not change a backup or readonly volume\n", pn);
3932 "%s: You don't have the required access rights on '%s'\n",
3936 "%s: You do not have the required rights to do this operation\n",
3941 fprintf(stderr, "%s:'%s'", pn, filename);
3943 fprintf(stderr, "%s", pn);
3944 fprintf(stderr, ": %s\n", afs_error_message(errnum));
3949 /* get clients interface addresses */
3951 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3954 struct ViceIoctl blob;
3955 struct sprefrequest *in;
3956 struct sprefinfo *out;
3958 in = (struct sprefrequest *)space;
3962 blob.in_size = sizeof(struct sprefrequest);
3963 blob.in = (char *)in;
3965 blob.out_size = AFS_PIOCTL_MAXSIZE;
3968 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3969 /* returns addr in network byte order */
3970 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3972 perror("getClientInterfaceAddr pioctl");
3978 out = (struct sprefinfo *)blob.out;
3979 for (i = 0; i < out->num_servers; i++) {
3982 addr = ntohl(out->servers[i].server.s_addr);
3983 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3984 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3985 printf("%-50s\n", tbuffer);
3987 in->offset = out->next_offset;
3989 } while (out->next_offset > 0);
3995 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3997 afs_int32 code, addr;
3998 struct cmd_item *ti;
3999 struct ViceIoctl blob;
4000 struct setspref *ssp;
4001 int sizeUsed = 0, i, flag;
4002 afs_uint32 existingAddr[1024]; /* existing addresses on this host */
4006 ssp = (struct setspref *)space;
4007 ssp->num_servers = 0;
4010 blob.out_size = AFS_PIOCTL_MAXSIZE;
4013 fprintf(stderr, "Permission denied: requires root access.\n");
4017 /* extract all existing interface addresses */
4018 existNu = rx_getAllAddr(existingAddr, 1024);
4022 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
4023 for (ti = as->parms[0].items; ti; ti = ti->next) {
4024 if (sizeUsed >= sizeof(space)) {
4025 fprintf(stderr, "No more space\n");
4028 addr = extractAddr(ti->data, 20); /* network order */
4029 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
4030 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
4035 /* see if it is an address that really exists */
4036 for (flag = 0, i = 0; i < existNu; i++)
4037 if (existingAddr[i] == addr) {
4041 if (!flag) { /* this is an nonexistent address */
4042 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
4046 /* copy all specified addr into ioctl buffer */
4047 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
4048 printf("Adding 0x%08x\n", addr);
4050 sizeUsed += sizeof(struct spref);
4052 if (ssp->num_servers < 1) {
4053 fprintf(stderr, "No addresses specified\n");
4056 blob.in_size = sizeUsed - sizeof(struct spref);
4058 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
4068 FlushMountCmd(struct cmd_syndesc *as, void *arock)
4071 struct ViceIoctl blob;
4072 struct cmd_item *ti;
4073 char orig_name[1024]; /*Original name, may be modified */
4074 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
4075 char parent_dir[1024]; /*Parent directory of true name */
4076 char *last_component; /*Last component of true name */
4077 struct stat statbuff; /*Buffer for status info */
4078 int link_chars_read; /*Num chars read in readlink() */
4079 int thru_symlink; /*Did we get to a mount point via a symlink? */
4082 for (ti = as->parms[0].items; ti; ti = ti->next) {
4085 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
4088 if (lstat(orig_name, &statbuff) < 0) {
4089 /* if lstat fails, we should still try the pioctl, since it
4090 * may work (for example, lstat will fail, but pioctl will
4091 * work if the volume of offline (returning ENODEV). */
4092 statbuff.st_mode = S_IFDIR; /* lie like pros */
4096 * The lstat succeeded. If the given file is a symlink, substitute
4097 * the file name with the link name.
4099 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
4102 * Read name of resolved file.
4104 link_chars_read = readlink(orig_name, true_name, 1024);
4105 if (link_chars_read <= 0) {
4107 "%s: Can't read target name for '%s' symbolic link!\n",
4114 * Add a trailing null to what was read, bump the length.
4116 true_name[link_chars_read++] = 0;
4119 * If the symlink is an absolute pathname, we're fine. Otherwise, we
4120 * have to create a full pathname using the original name and the
4121 * relative symlink name. Find the rightmost slash in the original
4122 * name (we know there is one) and splice in the symlink value.
4124 if (true_name[0] != '/') {
4125 last_component = (char *)strrchr(orig_name, '/');
4126 strcpy(++last_component, true_name);
4127 strcpy(true_name, orig_name);
4130 strcpy(true_name, orig_name);
4133 * Find rightmost slash, if any.
4135 last_component = (char *)strrchr(true_name, '/');
4136 if (last_component == (char *)true_name) {
4137 strcpy(parent_dir, "/");
4140 else if (last_component != (char *)NULL) {
4142 * Found it. Designate everything before it as the parent directory,
4143 * everything after it as the final component.
4145 strncpy(parent_dir, true_name, last_component - true_name);
4146 parent_dir[last_component - true_name] = 0;
4147 last_component++; /*Skip the slash */
4150 * No slash appears in the given file name. Set parent_dir to the current
4151 * directory, and the last component as the given name.
4153 strcpy(parent_dir, ".");
4154 last_component = true_name;
4157 if (strcmp(last_component, ".") == 0
4158 || strcmp(last_component, "..") == 0) {
4160 "%s: you may not use '.' or '..' as the last component\n",
4162 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
4168 blob.in = last_component;
4169 blob.in_size = strlen(last_component) + 1;
4171 memset(space, 0, AFS_PIOCTL_MAXSIZE);
4173 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4176 if (errno == EINVAL) {
4177 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4179 Die(errno, (ti->data ? ti->data : parent_dir));
4188 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4191 afs_int32 flags = 0;
4192 struct ViceIoctl blob;
4194 if (as->parms[0].items) { /* -enable */
4195 flags |= AFSCALL_RXSTATS_ENABLE;
4197 if (as->parms[1].items) { /* -disable */
4198 flags |= AFSCALL_RXSTATS_DISABLE;
4200 if (as->parms[2].items) { /* -clear */
4201 flags |= AFSCALL_RXSTATS_CLEAR;
4204 fprintf(stderr, "You must specify at least one argument\n");
4208 blob.in = (char *)&flags;
4209 blob.in_size = sizeof(afs_int32);
4212 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4222 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4225 afs_int32 flags = 0;
4226 struct ViceIoctl blob;
4228 if (as->parms[0].items) { /* -enable */
4229 flags |= AFSCALL_RXSTATS_ENABLE;
4231 if (as->parms[1].items) { /* -disable */
4232 flags |= AFSCALL_RXSTATS_DISABLE;
4234 if (as->parms[2].items) { /* -clear */
4235 flags |= AFSCALL_RXSTATS_CLEAR;
4238 fprintf(stderr, "You must specify at least one argument\n");
4242 blob.in = (char *)&flags;
4243 blob.in_size = sizeof(afs_int32);
4246 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4256 GetFidCmd(struct cmd_syndesc *as, void *arock)
4258 struct ViceIoctl blob;
4259 struct cmd_item *ti;
4263 char cell[MAXCELLCHARS];
4265 SetDotDefault(&as->parms[0].items);
4266 for (ti = as->parms[0].items; ti; ti = ti->next) {
4267 struct VenusFid vfid;
4269 blob.out_size = sizeof(struct VenusFid);
4270 blob.out = (char *) &vfid;
4273 code = pioctl(ti->data, VIOCGETFID, &blob, 1);
4275 Die(errno,ti->data);
4280 code = GetCell(ti->data, cell);
4282 if (errno == ENOENT)
4283 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
4285 Die(errno, ti->data);
4290 printf("File %s (%u.%u.%u) located in cell %s\n",
4291 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,