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>
16 #include <afs/afs_args.h>
18 #include <sys/ioctl.h>
19 #include <sys/socket.h>
23 #include <netinet/in.h>
27 #include <afs/venus.h>
28 #include <afs/com_err.h>
43 #include "afs/prs_fs.h"
44 #include <afs/afsint.h>
46 #include <afs/cellconfig.h>
49 #include <rx/rx_globals.h>
50 #include <afs/vldbint.h>
51 #include <afs/volser.h>
52 #include <afs/vlserver.h>
54 #include <afs/afsutil.h>
57 #include <afs/ptclient.h>
62 #define MAXCELLHOSTS 8
65 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
66 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
68 static char space[MAXSIZE];
69 static char tspace[1024];
70 static struct ubik_client *uclient;
72 static int GetClientAddrsCmd(), SetClientAddrsCmd(), FlushMountCmd();
73 static int RxStatProcCmd(), RxStatPeerCmd(), GetFidCmd();
75 extern char *hostutil_GetNameByINet();
76 extern struct hostent *hostutil_GetHostByName();
79 extern struct cmd_syndesc *cmd_CreateSyntax();
80 static char pn[] = "fs";
81 static int rxInitDone = 0;
83 static void ZapList();
84 static int PruneList();
92 * Character to use between name and rights in printed representation for
95 #define DFS_SEPARATOR ' '
97 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
100 int dfs; /* Originally true if a dfs acl; now also the type
101 * of the acl (1, 2, or 3, corresponding to object,
102 * initial dir, or initial object). */
103 sec_rgy_name_t cell; /* DFS cell name */
106 struct AclEntry *pluslist;
107 struct AclEntry *minuslist;
111 struct AclEntry *next;
117 afs_int32 callerAccess;
129 ZapList(acl->pluslist);
130 ZapList(acl->minuslist);
143 if (t >= 'A' && t <= 'Z')
145 if (u >= 'A' && u <= 'Z')
155 * Mods for the AFS/DFS protocol translator.
157 * DFS rights. It's ugly to put these definitions here, but they
158 * *cannot* change, because they're part of the wire protocol.
159 * In any event, the protocol translator will guarantee these
160 * assignments for AFS cache managers.
162 #define DFS_READ 0x01
163 #define DFS_WRITE 0x02
164 #define DFS_EXECUTE 0x04
165 #define DFS_CONTROL 0x08
166 #define DFS_INSERT 0x10
167 #define DFS_DELETE 0x20
169 /* the application definable ones (backwards from AFS) */
170 #define DFS_USR0 0x80000000 /* "A" bit */
171 #define DFS_USR1 0x40000000 /* "B" bit */
172 #define DFS_USR2 0x20000000 /* "C" bit */
173 #define DFS_USR3 0x10000000 /* "D" bit */
174 #define DFS_USR4 0x08000000 /* "E" bit */
175 #define DFS_USR5 0x04000000 /* "F" bit */
176 #define DFS_USR6 0x02000000 /* "G" bit */
177 #define DFS_USR7 0x01000000 /* "H" bit */
178 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
179 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
182 * Offset of -id switch in command structure for various commands.
183 * The -if switch is the next switch always.
185 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
188 * Determine whether either the -id or -if switches are present, and
189 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
191 /* int id; Offset of -id switch; -if is next switch */
193 getidf(struct cmd_syndesc *as, int id)
197 if (as->parms[id].items) {
200 if (as->parms[id + 1].items) {
205 "%s: you may specify either -id or -if, but not both switches\n",
213 PRights(afs_int32 arights, int dfs)
216 if (arights & PRSFS_READ)
218 if (arights & PRSFS_LOOKUP)
220 if (arights & PRSFS_INSERT)
222 if (arights & PRSFS_DELETE)
224 if (arights & PRSFS_WRITE)
226 if (arights & PRSFS_LOCK)
228 if (arights & PRSFS_ADMINISTER)
230 if (arights & PRSFS_USR0)
232 if (arights & PRSFS_USR1)
234 if (arights & PRSFS_USR2)
236 if (arights & PRSFS_USR3)
238 if (arights & PRSFS_USR4)
240 if (arights & PRSFS_USR5)
242 if (arights & PRSFS_USR6)
244 if (arights & PRSFS_USR7)
247 if (arights & DFS_READ)
251 if (arights & DFS_WRITE)
255 if (arights & DFS_EXECUTE)
259 if (arights & DFS_CONTROL)
263 if (arights & DFS_INSERT)
267 if (arights & DFS_DELETE)
271 if (arights & (DFS_USRALL))
273 if (arights & DFS_USR0)
275 if (arights & DFS_USR1)
277 if (arights & DFS_USR2)
279 if (arights & DFS_USR3)
281 if (arights & DFS_USR4)
283 if (arights & DFS_USR5)
285 if (arights & DFS_USR6)
287 if (arights & DFS_USR7)
292 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
296 struct ViceIoctl blob;
300 blob.out_size = MAXSIZE;
303 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
305 if ((errno == EINVAL) || (errno == ENOENT))
311 /* return a static pointer to a buffer */
316 strcpy(tspace, apath);
317 tp = strrchr(tspace, '/');
325 enum rtype { add, destroy, deny };
328 Convert(char *arights, int dfs, enum rtype *rtypep)
334 *rtypep = add; /* add rights, by default */
337 if (!strcmp(arights, "null")) {
341 if (!strcmp(arights, "read"))
342 return DFS_READ | DFS_EXECUTE;
343 if (!strcmp(arights, "write"))
344 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
346 if (!strcmp(arights, "all"))
347 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
348 DFS_WRITE | DFS_CONTROL;
350 if (!strcmp(arights, "read"))
351 return PRSFS_READ | PRSFS_LOOKUP;
352 if (!strcmp(arights, "write"))
353 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
354 PRSFS_WRITE | PRSFS_LOCK;
355 if (!strcmp(arights, "mail"))
356 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
357 if (!strcmp(arights, "all"))
358 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
359 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
361 if (!strcmp(arights, "none")) {
362 *rtypep = destroy; /* Remove entire entry */
365 len = strlen(arights);
367 for (i = 0; i < len; i++) {
401 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
409 mode |= PRSFS_LOOKUP;
411 mode |= PRSFS_INSERT;
413 mode |= PRSFS_DELETE;
419 mode |= PRSFS_ADMINISTER;
437 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
446 static struct AclEntry *
447 FindList(struct AclEntry *alist, char *aname)
450 if (!foldcmp(alist->name, aname))
457 /* if no parm specified in a particular slot, set parm to be "." instead */
459 SetDotDefault(struct cmd_item **aitemp)
463 return; /* already has value */
464 /* otherwise, allocate an item representing "." */
465 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
467 ti->next = (struct cmd_item *)0;
468 ti->data = (char *)malloc(2);
470 strcpy(ti->data, ".");
475 ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
477 struct AclEntry *tlist;
478 tlist = (plus ? al->pluslist : al->minuslist);
479 tlist = FindList(tlist, aname);
481 /* Found the item already in the list. */
482 tlist->rights = arights;
484 al->nplus -= PruneList(&al->pluslist, al->dfs);
486 al->nminus -= PruneList(&al->minuslist, al->dfs);
489 /* Otherwise we make a new item and plug in the new data. */
490 tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry));
492 strcpy(tlist->name, aname);
493 tlist->rights = arights;
495 tlist->next = al->pluslist;
496 al->pluslist = tlist;
498 if (arights == 0 || arights == -1)
499 al->nplus -= PruneList(&al->pluslist, al->dfs);
501 tlist->next = al->minuslist;
502 al->minuslist = tlist;
505 al->nminus -= PruneList(&al->minuslist, al->dfs);
510 ZapList(struct AclEntry *alist)
512 struct AclEntry *tp, *np;
513 for (tp = alist; tp; tp = np) {
520 PruneList(struct AclEntry **ae, int dfs)
522 struct AclEntry **lp;
523 struct AclEntry *te, *ne;
527 for (te = *ae; te; te = ne) {
528 if ((!dfs && te->rights == 0) || te->rights == -1) {
544 while (*astr != '\n')
551 * Create an empty acl, taking into account whether the acl pointed
552 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
553 * can recover from problems caused by bogus ACL's (in that case, always
554 * assume that the acl is AFS: for DFS, the user can always resort to
555 * acl_edit, but for AFS there may be no other way out).
563 tp = (struct Acl *)malloc(sizeof(struct Acl));
565 tp->nplus = tp->nminus = 0;
566 tp->pluslist = tp->minuslist = 0;
568 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
575 int nplus, nminus, i, trights;
577 struct AclEntry *first, *last, *tl;
580 ta = (struct Acl *)malloc(sizeof(struct Acl));
583 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
584 astr = SkipLine(astr);
585 sscanf(astr, "%d", &ta->nminus);
586 astr = SkipLine(astr);
593 for (i = 0; i < nplus; i++) {
594 sscanf(astr, "%100s %d", tname, &trights);
595 astr = SkipLine(astr);
596 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
600 strcpy(tl->name, tname);
601 tl->rights = trights;
607 ta->pluslist = first;
611 for (i = 0; i < nminus; i++) {
612 sscanf(astr, "%100s %d", tname, &trights);
613 astr = SkipLine(astr);
614 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
618 strcpy(tl->name, tname);
619 tl->rights = trights;
625 ta->minuslist = first;
631 PrintStatus(VolumeStatus * status, char *name, char *offmsg)
633 printf("Volume status for vid = %u named %s\n", status->Vid, name);
635 printf("Current offline message is %s\n", offmsg);
636 printf("Current disk quota is ");
637 if (status->MaxQuota != 0)
638 printf("%d\n", status->MaxQuota);
640 printf("unlimited\n");
641 printf("Current blocks used are %d\n", status->BlocksInUse);
642 printf("The partition has %d blocks available out of %d\n\n",
643 status->PartBlocksAvail, status->PartMaxBlocks);
648 QuickPrintStatus(VolumeStatus * status, char *name)
650 double QuotaUsed = 0.0;
651 double PartUsed = 0.0;
653 printf("%-25.25s", name);
655 if (status->MaxQuota != 0) {
656 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
658 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
660 printf(" no limit%10d", status->BlocksInUse);
662 if (QuotaUsed > 90.0) {
663 printf("%5.0f%%<<", QuotaUsed);
666 printf("%5.0f%% ", QuotaUsed);
669 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
671 if (PartUsed > 97.0) {
672 printf("%9.0f%%<<", PartUsed);
675 printf("%9.0f%% ", PartUsed);
677 printf(" <<WARNING\n");
684 QuickPrintSpace(VolumeStatus * status, char *name)
686 double PartUsed = 0.0;
688 printf("%-25.25s", name);
690 printf("%10d%10d%10d", status->PartMaxBlocks,
691 status->PartMaxBlocks - status->PartBlocksAvail,
692 status->PartBlocksAvail);
696 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
698 if (PartUsed > 90.0) {
699 printf(" %4.0f%%<<", PartUsed);
702 printf(" %4.0f%% ", PartUsed);
704 printf(" <<WARNING\n");
711 AclToString(struct Acl *acl)
713 static char mydata[MAXSIZE];
714 char tstring[MAXSIZE];
719 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
722 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
723 for (tp = acl->pluslist; tp; tp = tp->next) {
724 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
725 strcat(mydata, tstring);
727 for (tp = acl->minuslist; tp; tp = tp->next) {
728 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
729 strcat(mydata, tstring);
735 SetACLCmd(struct cmd_syndesc *as, char *arock)
738 struct ViceIoctl blob;
740 struct cmd_item *ti, *ui;
744 int idf = getidf(as, parm_setacl_id);
747 if (as->parms[2].items)
751 plusp = !(as->parms[3].items);
752 for (ti = as->parms[0].items; ti; ti = ti->next) {
753 blob.out_size = MAXSIZE;
755 blob.in = blob.out = space;
756 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
758 Die(errno, ti->data);
765 ta = ParseAcl(space);
766 if (!plusp && ta->dfs) {
768 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
770 "(you may specify \"null\" to revoke all rights, however)\n");
778 ta = EmptyAcl(space);
780 ta = ParseAcl(space);
781 CleanAcl(ta, ti->data);
782 for (ui = as->parms[1].items; ui; ui = ui->next->next) {
786 "%s: Missing second half of user/access pair.\n", pn);
790 rights = Convert(ui->next->data, ta->dfs, &rtype);
791 if (rtype == destroy && !ta->dfs) {
792 struct AclEntry *tlist;
794 tlist = (plusp ? ta->pluslist : ta->minuslist);
795 if (!FindList(tlist, ui->data))
798 if (rtype == deny && !ta->dfs)
800 if (rtype == destroy && ta->dfs)
802 ChangeList(ta, plusp, ui->data, rights);
804 blob.in = AclToString(ta);
806 blob.in_size = 1 + strlen(blob.in);
807 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
809 if (errno == EINVAL) {
811 static char *fsenv = 0;
813 fsenv = (char *)getenv("FS_EXPERT");
816 "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n",
820 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
821 "\nPossible reasons for this include:\n\n",
822 " -You may have specified an inappropriate combination of rights.\n",
823 " For example, some DFS-supported filesystems may not allow you to\n",
824 " drop the \"c\" right from \"user_obj\".\n\n",
825 " -A mask_obj may be required (it is likely required by the underlying\n",
826 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
827 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
828 " does not automatically create or update the mask_obj. Try setting\n",
829 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
830 " users or groups. You can do this with a single command, such as\n",
831 " \"fs sa mask_obj all user:somename read\"\n\n",
832 " -A specified user or group may not exist.\n\n",
833 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
834 " This is probably not allowed by the underlying file system.\n\n",
835 " -If you add a user or group to a DFS ACL, remember that it must be\n",
836 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
837 " may be local requirements on the format of the user or group name.\n",
838 " Check with your cell administrator.\n\n",
839 " -Or numerous other possibilities. It would be great if we could be more\n",
840 " precise about the actual problem, but for various reasons, this is\n",
841 " impractical via this interface. If you can't figure it out, you\n",
842 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
843 " whatever is provided). You may get better results. Good luck!\n\n",
844 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
848 "%s: Invalid argument, possible reasons include:\n",
850 fprintf(stderr, "\t-File not in AFS\n");
852 "\t-Too many users on access control list\n");
854 "\t-Tried to add non-existent user to access control list\n");
857 Die(errno, ti->data);
869 CopyACLCmd(struct cmd_syndesc *as, char *arock)
872 struct ViceIoctl blob;
873 struct Acl *fa, *ta = 0;
875 struct cmd_item *ti, *ui;
879 int idf = getidf(as, parm_copyacl_id);
882 if (as->parms[2].items)
886 blob.out_size = MAXSIZE;
888 blob.in = blob.out = space;
889 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
891 Die(errno, as->parms[0].items->data);
894 fa = ParseAcl(space);
895 CleanAcl(fa, as->parms[0].items->data);
896 for (ti = as->parms[1].items; ti; ti = ti->next) {
897 blob.out_size = MAXSIZE;
899 blob.in = blob.out = space;
900 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
902 Die(errno, ti->data);
910 ta = EmptyAcl(space);
912 ta = ParseAcl(space);
913 CleanAcl(ta, ti->data);
914 if (ta->dfs != fa->dfs) {
916 "%s: incompatible file system types: acl not copied to %s; aborted\n",
922 if (!clear && strcmp(ta->cell, fa->cell) != 0) {
924 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
929 strcpy(ta->cell, fa->cell);
931 for (tp = fa->pluslist; tp; tp = tp->next)
932 ChangeList(ta, 1, tp->name, tp->rights);
933 for (tp = fa->minuslist; tp; tp = tp->next)
934 ChangeList(ta, 0, tp->name, tp->rights);
935 blob.in = AclToString(ta);
937 blob.in_size = 1 + strlen(blob.in);
938 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
940 if (errno == EINVAL) {
942 "%s: Invalid argument, possible reasons include:\n",
944 fprintf(stderr, "\t-File not in AFS\n");
946 Die(errno, ti->data);
957 /* pioctl() call to get the cellname of a pathname */
959 GetCell(char *fname, char *cellname)
962 struct ViceIoctl blob;
965 blob.out_size = MAXCELLCHARS;
968 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
969 return code ? errno : 0;
972 /* Check if a username is valid: If it contains only digits (or a
973 * negative sign), then it might be bad. We then query the ptserver
977 BadName(char *aname, char *fname)
979 afs_int32 tc, code, id;
981 char cell[MAXCELLCHARS];
983 for (nm = aname; tc = *nm; nm++) {
984 /* all must be '-' or digit to be bad */
985 if (tc != '-' && (tc < '0' || tc > '9'))
989 /* Go to the PRDB and see if this all number username is valid */
990 code = GetCell(fname, cell);
994 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
995 code = pr_SNameToId(aname, &id);
998 /* 1=>Not-valid; 0=>Valid */
999 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1003 /* clean up an access control list of its bad entries; return 1 if we made
1004 any changes to the list, and 0 otherwise */
1006 CleanAcl(struct Acl *aa, char *fname)
1008 struct AclEntry *te, **le, *ne;
1011 /* Don't correct DFS ACL's for now */
1015 /* prune out bad entries */
1016 changes = 0; /* count deleted entries */
1018 for (te = aa->pluslist; te; te = ne) {
1020 if (BadName(te->name, fname)) {
1030 le = &aa->minuslist;
1031 for (te = aa->minuslist; te; te = ne) {
1033 if (BadName(te->name, fname)) {
1047 /* clean up an acl to not have bogus entries */
1049 CleanACLCmd(struct cmd_syndesc *as, char *arock)
1053 struct ViceIoctl blob;
1055 struct cmd_item *ti;
1056 struct AclEntry *te;
1059 SetDotDefault(&as->parms[0].items);
1060 for (ti = as->parms[0].items; ti; ti = ti->next) {
1061 blob.out_size = MAXSIZE;
1064 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1066 Die(errno, ti->data);
1073 ta = ParseAcl(space);
1076 "%s: cleanacl is not supported for DFS access lists.\n",
1082 changes = CleanAcl(ta, ti->data);
1085 /* now set the acl */
1086 blob.in = AclToString(ta);
1087 blob.in_size = strlen(blob.in) + 1;
1089 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1091 if (errno == EINVAL) {
1093 "%s: Invalid argument, possible reasons include\n",
1095 fprintf(stderr, "%s: File not in vice or\n", pn);
1097 "%s: Too many users on access control list or\n",
1100 Die(errno, ti->data);
1106 /* now list the updated acl */
1107 printf("Access list for %s is now\n", ti->data);
1108 if (ta->nplus > 0) {
1110 printf("Normal rights:\n");
1111 for (te = ta->pluslist; te; te = te->next) {
1112 printf(" %s ", te->name);
1113 PRights(te->rights, ta->dfs);
1117 if (ta->nminus > 0) {
1118 printf("Negative rights:\n");
1119 for (te = ta->minuslist; te; te = te->next) {
1120 printf(" %s ", te->name);
1121 PRights(te->rights, ta->dfs);
1128 printf("Access list for %s is fine.\n", ti->data);
1136 ListACLCmd(struct cmd_syndesc *as, char *arock)
1140 struct ViceIoctl blob;
1141 struct AclEntry *te;
1142 struct cmd_item *ti;
1143 int idf = getidf(as, parm_listacl_id);
1146 SetDotDefault(&as->parms[0].items);
1147 for (ti = as->parms[0].items; ti; ti = ti->next) {
1148 blob.out_size = MAXSIZE;
1150 blob.in = blob.out = space;
1151 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1153 Die(errno, ti->data);
1157 ta = ParseAcl(space);
1160 printf("Access list for %s is\n", ti->data);
1163 printf("DFS access list for %s is\n", ti->data);
1166 printf("DFS initial directory access list of %s is\n", ti->data);
1169 printf("DFS initial file access list of %s is\n", ti->data);
1173 printf(" Default cell = %s\n", ta->cell);
1175 if (ta->nplus > 0) {
1177 printf("Normal rights:\n");
1178 for (te = ta->pluslist; te; te = te->next) {
1179 printf(" %s ", te->name);
1180 PRights(te->rights, ta->dfs);
1184 if (ta->nminus > 0) {
1185 printf("Negative rights:\n");
1186 for (te = ta->minuslist; te; te = te->next) {
1187 printf(" %s ", te->name);
1188 PRights(te->rights, ta->dfs);
1200 GetCallerAccess(struct cmd_syndesc *as, char *arock)
1202 struct cmd_item *ti;
1205 SetDotDefault(&as->parms[0].items);
1206 for (ti = as->parms[0].items; ti; ti = ti->next) {
1208 struct ViceIoctl blob;
1209 struct vcxstat2 stat;
1210 blob.out_size = sizeof(struct vcxstat2);
1212 blob.out = (void *)&stat;
1213 code = pioctl(ti->data, VIOC_GETVCXSTATUS2, &blob, 1);
1215 Die(errno, ti->data);
1219 printf("Callers access to %s is ", ti->data);
1220 PRights(stat.callerAccess, 0);
1227 FlushVolumeCmd(struct cmd_syndesc *as, char *arock)
1230 struct ViceIoctl blob;
1231 struct cmd_item *ti;
1234 SetDotDefault(&as->parms[0].items);
1235 for (ti = as->parms[0].items; ti; ti = ti->next) {
1236 blob.in_size = blob.out_size = 0;
1237 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1239 fprintf(stderr, "Error flushing volume ");
1249 FlushCmd(struct cmd_syndesc *as, char *arock)
1252 struct ViceIoctl blob;
1253 struct cmd_item *ti;
1256 for (ti = as->parms[0].items; ti; ti = ti->next) {
1257 blob.in_size = blob.out_size = 0;
1258 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1260 if (errno == EMFILE) {
1261 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1264 fprintf(stderr, "%s: Error flushing file ", pn);
1274 /* all this command does is repackage its args and call SetVolCmd */
1276 SetQuotaCmd(struct cmd_syndesc *as, char *arock)
1278 struct cmd_syndesc ts;
1280 /* copy useful stuff from our command slot; we may later have to reorder */
1281 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1282 return SetVolCmd(&ts);
1286 SetVolCmd(struct cmd_syndesc *as, char *arock)
1289 struct ViceIoctl blob;
1290 struct cmd_item *ti;
1291 struct VolumeStatus *status;
1292 char *offmsg, *input;
1295 SetDotDefault(&as->parms[0].items);
1296 for (ti = as->parms[0].items; ti; ti = ti->next) {
1298 blob.out_size = MAXSIZE;
1299 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1302 status = (VolumeStatus *) space;
1303 status->MinQuota = status->MaxQuota = -1;
1305 if (as->parms[1].items) {
1306 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1308 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1313 if (as->parms[2].items)
1314 offmsg = as->parms[2].items->data;
1315 input = (char *)status + sizeof(*status);
1316 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1318 if (strlen(offmsg) >= VMSGSIZE) {
1320 "%s: message must be shorter than %d characters\n",
1325 strcpy(input, offmsg);
1326 blob.in_size += strlen(offmsg);
1327 input += strlen(offmsg) + 1;
1330 *(input++) = '\0'; /* Pad for old style volume "motd" */
1331 code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1);
1333 Die(errno, ti->data);
1341 * Why is VenusFid declared in the kernel-only section of afs.h,
1342 * if it's the exported interface of the cache manager?
1350 ExamineCmd(struct cmd_syndesc *as, char *arock)
1353 struct ViceIoctl blob;
1354 struct cmd_item *ti;
1355 struct VolumeStatus *status;
1356 char *name, *offmsg;
1359 SetDotDefault(&as->parms[0].items);
1360 for (ti = as->parms[0].items; ti; ti = ti->next) {
1361 struct VenusFid vfid;
1364 blob.out_size = MAXSIZE;
1367 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1369 Die(errno, ti->data);
1373 status = (VolumeStatus *) space;
1374 name = (char *)status + sizeof(*status);
1375 offmsg = name + strlen(name) + 1;
1377 blob.out_size = sizeof(struct VenusFid);
1378 blob.out = (char *) &vfid;
1379 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1380 printf("File %s (%u.%u.%u) contained in volume %u\n",
1381 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1385 PrintStatus(status, name, offmsg);
1391 ListQuotaCmd(struct cmd_syndesc *as, char *arock)
1394 struct ViceIoctl blob;
1395 struct cmd_item *ti;
1396 struct VolumeStatus *status;
1400 printf("%-25s%-10s%-10s%-7s%-11s\n", "Volume Name", " Quota",
1401 " Used", " %Used", " Partition");
1402 SetDotDefault(&as->parms[0].items);
1403 for (ti = as->parms[0].items; ti; ti = ti->next) {
1405 blob.out_size = MAXSIZE;
1408 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1410 Die(errno, ti->data);
1414 status = (VolumeStatus *) space;
1415 name = (char *)status + sizeof(*status);
1416 QuickPrintStatus(status, name);
1422 WhereIsCmd(struct cmd_syndesc *as, char *arock)
1425 struct ViceIoctl blob;
1426 struct cmd_item *ti;
1432 SetDotDefault(&as->parms[0].items);
1433 for (ti = as->parms[0].items; ti; ti = ti->next) {
1435 blob.out_size = MAXSIZE;
1438 memset(space, 0, sizeof(space));
1439 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1441 Die(errno, ti->data);
1445 hosts = (afs_int32 *) space;
1446 printf("File %s is on host%s ", ti->data,
1447 (hosts[0] && !hosts[1]) ? "" : "s");
1448 for (j = 0; j < MAXHOSTS; j++) {
1451 tp = hostutil_GetNameByINet(hosts[j]);
1461 DiskFreeCmd(struct cmd_syndesc *as, char *arock)
1464 struct ViceIoctl blob;
1465 struct cmd_item *ti;
1467 struct VolumeStatus *status;
1470 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1471 " used", " avail", " %used");
1472 SetDotDefault(&as->parms[0].items);
1473 for (ti = as->parms[0].items; ti; ti = ti->next) {
1475 blob.out_size = MAXSIZE;
1478 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1480 Die(errno, ti->data);
1484 status = (VolumeStatus *) space;
1485 name = (char *)status + sizeof(*status);
1486 QuickPrintSpace(status, name);
1492 QuotaCmd(struct cmd_syndesc *as, char *arock)
1495 struct ViceIoctl blob;
1496 struct cmd_item *ti;
1498 struct VolumeStatus *status;
1501 SetDotDefault(&as->parms[0].items);
1502 for (ti = as->parms[0].items; ti; ti = ti->next) {
1504 blob.out_size = MAXSIZE;
1507 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1509 Die(errno, ti->data);
1513 status = (VolumeStatus *) space;
1514 if (status->MaxQuota)
1516 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
1519 printf("%2.0f%% of quota used.\n", quotaPct);
1525 ListMountCmd(struct cmd_syndesc *as, char *arock)
1528 struct ViceIoctl blob;
1529 struct cmd_item *ti;
1530 char orig_name[1024]; /*Original name, may be modified */
1531 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
1532 char parent_dir[1024]; /*Parent directory of true name */
1533 char *last_component; /*Last component of true name */
1534 struct stat statbuff; /*Buffer for status info */
1535 int link_chars_read; /*Num chars read in readlink() */
1536 int thru_symlink; /*Did we get to a mount point via a symlink? */
1539 for (ti = as->parms[0].items; ti; ti = ti->next) {
1542 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
1545 if (lstat(orig_name, &statbuff) < 0) {
1546 /* if lstat fails, we should still try the pioctl, since it
1547 * may work (for example, lstat will fail, but pioctl will
1548 * work if the volume of offline (returning ENODEV). */
1549 statbuff.st_mode = S_IFDIR; /* lie like pros */
1553 * The lstat succeeded. If the given file is a symlink, substitute
1554 * the file name with the link name.
1556 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1559 * Read name of resolved file.
1561 link_chars_read = readlink(orig_name, true_name, 1024);
1562 if (link_chars_read <= 0) {
1564 "%s: Can't read target name for '%s' symbolic link!\n",
1571 * Add a trailing null to what was read, bump the length.
1573 true_name[link_chars_read++] = 0;
1576 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1577 * have to create a full pathname using the original name and the
1578 * relative symlink name. Find the rightmost slash in the original
1579 * name (we know there is one) and splice in the symlink value.
1581 if (true_name[0] != '/') {
1582 last_component = (char *)strrchr(orig_name, '/');
1583 strcpy(++last_component, true_name);
1584 strcpy(true_name, orig_name);
1587 strcpy(true_name, orig_name);
1590 * Find rightmost slash, if any.
1592 last_component = (char *)strrchr(true_name, '/');
1593 if (last_component) {
1595 * Found it. Designate everything before it as the parent directory,
1596 * everything after it as the final component.
1598 strncpy(parent_dir, true_name, last_component - true_name);
1599 parent_dir[last_component - true_name] = 0;
1600 last_component++; /*Skip the slash */
1603 * No slash appears in the given file name. Set parent_dir to the current
1604 * directory, and the last component as the given name.
1606 strcpy(parent_dir, ".");
1607 last_component = true_name;
1610 if (strcmp(last_component, ".") == 0
1611 || strcmp(last_component, "..") == 0) {
1613 "%s: you may not use '.' or '..' as the last component\n",
1615 fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n",
1621 blob.in = last_component;
1622 blob.in_size = strlen(last_component) + 1;
1623 blob.out_size = MAXSIZE;
1625 memset(space, 0, MAXSIZE);
1627 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1630 printf("'%s' is a %smount point for volume '%s'\n", ti->data,
1631 (thru_symlink ? "symbolic link, leading to a " : ""),
1634 if (errno == EINVAL) {
1635 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
1637 Die(errno, (ti->data ? ti->data : parent_dir));
1646 MakeMountCmd(struct cmd_syndesc *as, char *arock)
1649 char *cellName, *volName, *tmpName;
1650 struct afsconf_cell info;
1651 struct vldbentry vldbEntry;
1652 struct ViceIoctl blob;
1658 if (as->parms[5].items && !as->parms[2].items) {
1659 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1664 if (as->parms[2].items) /* cell name specified */
1665 cellName = as->parms[2].items->data;
1668 volName = as->parms[1].items->data;
1670 if (strlen(volName) >= 64) {
1672 "%s: volume name too long (length must be < 64 characters)\n",
1677 /* Check for a cellname in the volume specification, and complain
1678 * if it doesn't match what was specified with -cell */
1679 if (tmpName = strchr(volName, ':')) {
1682 if (strcasecmp(cellName, volName)) {
1683 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1688 volName = ++tmpName;
1691 if (!InAFS(Parent(as->parms[0].items->data))) {
1693 "%s: mount points must be created within the AFS file system\n",
1700 blob.out_size = MAXSIZE;
1703 pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME,
1707 code = GetCellName(cellName ? cellName : space, &info);
1711 if (!(as->parms[4].items)) {
1712 /* not fast, check which cell the mountpoint is being created in */
1713 /* not fast, check name with VLDB */
1714 code = VLDBInit(1, &info);
1716 /* make the check. Don't complain if there are problems with init */
1718 ubik_VL_GetEntryByNameO(uclient, 0, volName,
1720 if (code == VL_NOENT) {
1722 "%s: warning, volume %s does not exist in cell %s.\n",
1723 pn, volName, cellName ? cellName : space);
1728 if (as->parms[3].items) /* if -rw specified */
1733 /* cellular mount point, prepend cell prefix */
1734 strcat(space, info.name);
1737 strcat(space, volName); /* append volume name */
1738 strcat(space, "."); /* stupid convention; these end with a period */
1739 code = symlink(space, as->parms[0].items->data);
1741 Die(errno, as->parms[0].items->data);
1748 * Delete AFS mount points. Variables are used as follows:
1749 * tbuffer: Set to point to the null-terminated directory name of the mount point
1750 * (or ``.'' if none is provided)
1751 * tp: Set to point to the actual name of the mount point to nuke.
1754 RemoveMountCmd(struct cmd_syndesc *as, char *arock)
1757 struct ViceIoctl blob;
1758 struct cmd_item *ti;
1760 char lsbuffer[1024];
1764 for (ti = as->parms[0].items; ti; ti = ti->next) {
1766 tp = (char *)strrchr(ti->data, '/');
1768 strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */
1770 tp++; /* skip the slash */
1772 strcpy(tbuffer, ".");
1776 blob.in_size = strlen(tp) + 1;
1777 blob.out = lsbuffer;
1778 blob.out_size = sizeof(lsbuffer);
1779 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1781 if (errno == EINVAL) {
1782 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
1785 Die(errno, ti->data);
1788 continue; /* don't bother trying */
1792 blob.in_size = strlen(tp) + 1;
1793 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1795 Die(errno, ti->data);
1806 CheckServersCmd(struct cmd_syndesc *as, char *arock)
1809 struct ViceIoctl blob;
1815 struct afsconf_cell info;
1816 struct chservinfo checkserv;
1818 memset(&checkserv, 0, sizeof(struct chservinfo));
1819 blob.in_size = sizeof(struct chservinfo);
1820 blob.in = (caddr_t) & checkserv;
1822 blob.out_size = MAXSIZE;
1824 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1826 /* prepare flags for checkservers command */
1827 temp = 2; /* default to checking local cell only */
1828 if (as->parms[2].items)
1829 temp |= 1; /* set fast flag */
1830 if (as->parms[1].items)
1831 temp &= ~2; /* turn off local cell check */
1833 checkserv.magic = 0x12345678; /* XXX */
1834 checkserv.tflags = temp;
1836 /* now copy in optional cell name, if specified */
1837 if (as->parms[0].items) {
1838 code = GetCellName(as->parms[0].items->data, &info);
1842 strcpy(checkserv.tbuffer, info.name);
1843 checkserv.tsize = strlen(info.name) + 1;
1845 strcpy(checkserv.tbuffer, "\0");
1846 checkserv.tsize = 0;
1849 if (as->parms[3].items) {
1850 checkserv.tinterval = atol(as->parms[3].items->data);
1853 if (checkserv.tinterval < 0) {
1855 ("Warning: The negative -interval is ignored; treated as an inquiry\n");
1856 checkserv.tinterval = 0;
1857 } else if (checkserv.tinterval > 600) {
1859 ("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1860 checkserv.tinterval = 600; /* 10 min max interval */
1863 checkserv.tinterval = -1; /* don't change current interval */
1866 code = pioctl(0, VIOCCKSERV, &blob, 1);
1868 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1869 printf("Must be root to change -interval\n");
1875 memcpy(&temp, space, sizeof(afs_int32));
1876 if (checkserv.tinterval >= 0) {
1877 if (checkserv.tinterval > 0)
1879 ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1880 checkserv.tinterval, temp);
1882 printf("The current down server probe interval is %d secs\n",
1887 printf("All servers are running.\n");
1890 ("These servers unavailable due to network or server problems: ");
1892 memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32));
1895 tp = hostutil_GetNameByINet(temp);
1905 MessagesCmd(struct cmd_syndesc *as, char *arock)
1908 struct ViceIoctl blob;
1911 struct gaginfo gagflags;
1912 struct cmd_item *show;
1914 memset(&gagflags, 0, sizeof(struct gaginfo));
1915 blob.in_size = sizeof(struct gaginfo);
1916 blob.in = (caddr_t) & gagflags;
1917 blob.out_size = MAXSIZE;
1919 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1921 if (show = as->parms[0].items) {
1922 if (!strcasecmp(show->data, "user"))
1923 gagflags.showflags |= GAGUSER;
1924 else if (!strcasecmp(show->data, "console"))
1925 gagflags.showflags |= GAGCONSOLE;
1926 else if (!strcasecmp(show->data, "all"))
1927 gagflags.showflags |= GAGCONSOLE | GAGUSER;
1928 else if (!strcasecmp(show->data, "none"))
1932 "unrecognized flag %s: must be in {user,console,all,none}\n",
1941 code = pioctl(0, VIOC_GAG, &blob, 1);
1951 CheckVolumesCmd(struct cmd_syndesc *as, char *arock)
1954 struct ViceIoctl blob;
1958 code = pioctl(0, VIOCCKBACK, &blob, 1);
1964 printf("All volumeID/name mappings checked.\n");
1969 SetCacheSizeCmd(struct cmd_syndesc *as, char *arock)
1972 struct ViceIoctl blob;
1975 if (!as->parms[0].items && !as->parms[1].items) {
1976 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
1979 if (as->parms[0].items) {
1980 code = util_GetInt32(as->parms[0].items->data, &temp);
1982 fprintf(stderr, "%s: bad integer specified for cache size.\n",
1988 blob.in = (char *)&temp;
1989 blob.in_size = sizeof(afs_int32);
1991 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
1993 if (errno == EROFS) {
1995 ("'fs setcache' not allowed on memory cache based cache managers.\n");
2002 printf("New cache size set.\n");
2006 #define MAXGCSIZE 16
2008 GetCacheParmsCmd(struct cmd_syndesc *as, char *arock)
2010 afs_int32 code, filesUsed;
2011 struct ViceIoctl blob;
2012 afs_int32 parms[MAXGCSIZE];
2013 double percentFiles, percentBlocks;
2014 afs_int32 flags = 0;
2016 if (as->parms[0].items){ /* -files */
2018 } else if (as->parms[1].items){ /* -excessive */
2024 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
2026 blob.in = (char *)&flags;
2027 blob.in_size = sizeof(afs_int32);
2028 } else { /* be backward compatible */
2032 blob.out_size = sizeof(parms);
2033 blob.out = (char *)parms;
2034 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2041 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2042 parms[1], parms[0]);
2043 if (parms[1] > parms[0])
2044 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2048 percentBlocks = ((double)parms[1]/parms[0]) * 100;
2049 printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n",
2050 percentBlocks, parms[1], parms[0]);
2055 filesUsed = parms[2] - parms[3];
2056 percentFiles = ((double)filesUsed/parms[2]) * 100;
2057 printf(" %5.0f%% of the cache files (%d of %d files)\n",
2058 percentFiles, filesUsed, parms[2]);
2060 printf(" afs_cacheFiles: %10d\n", parms[2]);
2061 printf(" IFFree: %10d\n", parms[3]);
2062 printf(" IFEverUsed: %10d\n", parms[4]);
2063 printf(" IFDataMod: %10d\n", parms[5]);
2064 printf(" IFDirtyPages: %10d\n", parms[6]);
2065 printf(" IFAnyPages: %10d\n", parms[7]);
2066 printf(" IFDiscarded: %10d\n", parms[8]);
2067 printf(" DCentries: %10d\n", parms[9]);
2068 printf(" 0k- 4K: %10d\n", parms[10]);
2069 printf(" 4k- 16k: %10d\n", parms[11]);
2070 printf(" 16k- 64k: %10d\n", parms[12]);
2071 printf(" 64k- 256k: %10d\n", parms[13]);
2072 printf(" 256k- 1M: %10d\n", parms[14]);
2073 printf(" >=1M: %10d\n", parms[15]);
2076 if (percentBlocks > 90)
2077 printf("[cache size usage over 90%, consider increasing cache size]\n");
2078 if (percentFiles > 90)
2079 printf("[cache file usage over 90%, consider increasing '-files' argument to afsd]\n");
2085 ListCellsCmd(struct cmd_syndesc *as, char *arock)
2091 struct ViceIoctl blob;
2094 resolve = !(as->parms[0].items); /* -numeric */
2098 memcpy(tp, &i, sizeof(afs_int32));
2099 blob.out_size = MAXSIZE;
2100 blob.in_size = sizeof(afs_int32);
2103 code = pioctl(0, VIOCGETCELL, &blob, 1);
2106 break; /* done with the list */
2111 printf("Cell %s on hosts", tp + MAXCELLHOSTS * sizeof(afs_int32));
2112 for (j = 0; j < MAXCELLHOSTS; j++) {
2114 char *name, tbuffer[20];
2116 memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32));
2121 name = hostutil_GetNameByINet(addr);
2124 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2125 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2128 printf(" %s", name);
2136 ListAliasesCmd(struct cmd_syndesc *as, char *arock)
2139 char *tp, *aliasName, *realName;
2140 struct ViceIoctl blob;
2144 memcpy(tp, &i, sizeof(afs_int32));
2145 blob.out_size = MAXSIZE;
2146 blob.in_size = sizeof(afs_int32);
2149 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2152 break; /* done with the list */
2158 tp += strlen(aliasName) + 1;
2160 printf("Alias %s for cell %s\n", aliasName, realName);
2166 CallBackRxConnCmd(struct cmd_syndesc *as, char *arock)
2169 struct ViceIoctl blob;
2170 struct cmd_item *ti;
2172 struct hostent *thp;
2176 ti = as->parms[0].items;
2179 thp = hostutil_GetHostByName(ti->data);
2181 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2184 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2186 hostAddr = 0; /* means don't set host */
2187 setp = 0; /* aren't setting host */
2190 /* now do operation */
2191 blob.in_size = sizeof(afs_int32);
2192 blob.out_size = sizeof(afs_int32);
2193 blob.in = (char *) &hostAddr;
2194 blob.out = (char *) &hostAddr;
2196 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2205 NukeNFSCredsCmd(struct cmd_syndesc *as, char *arock)
2208 struct ViceIoctl blob;
2209 struct cmd_item *ti;
2211 struct hostent *thp;
2213 ti = as->parms[0].items;
2214 thp = hostutil_GetHostByName(ti->data);
2216 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2219 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2221 /* now do operation */
2222 blob.in_size = sizeof(afs_int32);
2223 blob.out_size = sizeof(afs_int32);
2224 blob.in = (char *) &hostAddr;
2225 blob.out = (char *) &hostAddr;
2227 code = pioctl(0, VIOC_NFS_NUKE_CREDS, &blob, 1);
2236 NewCellCmd(struct cmd_syndesc *as, char *arock)
2238 afs_int32 code, linkedstate = 0, size = 0, *lp;
2239 struct ViceIoctl blob;
2240 struct cmd_item *ti;
2241 char *tp, *cellname = 0;
2242 struct hostent *thp;
2243 afs_int32 fsport = 0, vlport = 0;
2244 afs_int32 magic, scount; /* Number of servers to pass in pioctl call */
2247 * With the NEWCELL pioctl call, 3.4 clients take an array of
2248 * MAXHOSTS (13) servers while 3.5 clients take an array of
2249 * MAXCELLHOSTS (8) servers. To determine which we are talking to,
2250 * do a GETCELL pioctl and pass it a magic number. If an array of
2251 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
2252 * If we get back EDOM, there are no cells in the kernel yet,
2253 * and we'll assume a 3.5 client.
2256 lp = (afs_int32 *) tp;
2257 *lp++ = 0; /* first cell entry */
2258 *lp = 0x12345678; /* magic */
2259 blob.out_size = MAXSIZE;
2260 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
2263 code = pioctl(0, VIOCGETCELL, &blob, 1);
2264 if (code < 0 && errno != EDOM) {
2268 if (code < 1 && errno == EDOM) {
2272 cellname = tp + MAXCELLHOSTS * sizeof(afs_int32);
2273 scount = ((cellname[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2276 /* Now setup and do the NEWCELL pioctl call */
2277 memset(space, 0, (scount + 1) * sizeof(afs_int32));
2279 lp = (afs_int32 *) tp;
2281 tp += sizeof(afs_int32);
2282 for (ti = as->parms[1].items; ti; ti = ti->next) {
2283 thp = hostutil_GetHostByName(ti->data);
2286 "%s: Host %s not found in host table, skipping it.\n", pn,
2289 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2290 tp += sizeof(afs_int32);
2293 if (as->parms[2].items) {
2295 * Link the cell, for the purposes of volume location, to the specified
2298 cellname = as->parms[2].items->data;
2301 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2302 if (as->parms[3].items) {
2303 code = util_GetInt32(as->parms[3].items->data, &vlport);
2306 "%s: bad integer specified for the fileserver port.\n",
2311 if (as->parms[4].items) {
2312 code = util_GetInt32(as->parms[4].items->data, &fsport);
2315 "%s: bad integer specified for the vldb server port.\n",
2321 tp = (char *)(space + (scount + 1) * sizeof(afs_int32));
2322 lp = (afs_int32 *) tp;
2326 strcpy(space + ((scount + 4) * sizeof(afs_int32)),
2327 as->parms[0].items->data);
2328 size = ((scount + 4) * sizeof(afs_int32))
2329 + strlen(as->parms[0].items->data)
2330 + 1 /* for null */ ;
2331 tp = (char *)(space + size);
2333 strcpy(tp, cellname);
2334 size += strlen(cellname) + 1;
2336 blob.in_size = size;
2339 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2348 NewAliasCmd(struct cmd_syndesc *as, char *arock)
2351 struct ViceIoctl blob;
2353 char *aliasName, *realName;
2355 /* Now setup and do the NEWCELL pioctl call */
2356 aliasName = as->parms[0].items->data;
2357 realName = as->parms[1].items->data;
2359 strcpy(tp, aliasName);
2360 tp += strlen(aliasName) + 1;
2361 strcpy(tp, realName);
2362 tp += strlen(realName) + 1;
2364 blob.in_size = tp - space;
2368 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2370 if (errno == EEXIST) {
2372 "%s: cell name `%s' in use by an existing cell.\n", pn,
2383 WhichCellCmd(struct cmd_syndesc *as, char *arock)
2386 struct cmd_item *ti;
2388 char cell[MAXCELLCHARS];
2390 SetDotDefault(&as->parms[0].items);
2391 for (ti = as->parms[0].items; ti; ti = ti->next) {
2392 code = GetCell(ti->data, cell);
2394 if (errno == ENOENT)
2395 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
2397 Die(errno, ti->data);
2402 printf("File %s lives in cell '%s'\n", ti->data, cell);
2408 WSCellCmd(struct cmd_syndesc *as, char *arock)
2411 struct ViceIoctl blob;
2415 blob.out_size = MAXSIZE;
2418 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2424 printf("This workstation belongs to cell '%s'\n", space);
2429 static PrimaryCellCmd(as)
2430 struct cmd_syndesc *as;
2432 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2438 MonitorCmd(struct cmd_syndesc *as, char *arock)
2441 struct ViceIoctl blob;
2442 struct cmd_item *ti;
2444 struct hostent *thp;
2448 ti = as->parms[0].items;
2452 if (!strcmp(ti->data, "off"))
2453 hostAddr = 0xffffffff;
2455 thp = hostutil_GetHostByName(ti->data);
2457 if (!strcmp(ti->data, "localhost")) {
2459 "localhost not in host table, assuming 127.0.0.1\n");
2460 hostAddr = htonl(0x7f000001);
2462 fprintf(stderr, "host %s not found in host table.\n",
2467 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2470 hostAddr = 0; /* means don't set host */
2471 setp = 0; /* aren't setting host */
2474 /* now do operation */
2475 blob.in_size = sizeof(afs_int32);
2476 blob.out_size = sizeof(afs_int32);
2477 blob.in = (char *)&hostAddr;
2478 blob.out = (char *)&hostAddr;
2479 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2485 printf("%s: new monitor host set.\n", pn);
2487 /* now decode old address */
2488 if (hostAddr == 0xffffffff) {
2489 printf("Cache monitoring is currently disabled.\n");
2491 tp = hostutil_GetNameByINet(hostAddr);
2492 printf("Using host %s for monitor services.\n", tp);
2499 SysNameCmd(struct cmd_syndesc *as, char *arock)
2502 struct ViceIoctl blob;
2503 struct cmd_item *ti;
2504 char *input = space;
2507 ti = as->parms[0].items;
2510 blob.out_size = MAXSIZE;
2511 blob.in_size = sizeof(afs_int32);
2512 input += sizeof(afs_int32);
2513 for (; ti; ti = ti->next) {
2515 blob.in_size += strlen(ti->data) + 1;
2516 if (blob.in_size > MAXSIZE) {
2517 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2518 setp > 1 ? "s" : "");
2521 strcpy(input, ti->data);
2522 input += strlen(ti->data);
2525 memcpy(space, &setp, sizeof(afs_int32));
2526 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2532 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2536 memcpy(&setp, input, sizeof(afs_int32));
2537 input += sizeof(afs_int32);
2539 fprintf(stderr, "No sysname name value was found\n");
2542 printf("Current sysname%s is", setp > 1 ? " list" : "");
2543 for (; setp > 0; --setp) {
2544 printf(" \'%s\'", input);
2545 input += strlen(input) + 1;
2551 static char *exported_types[] = { "null", "nfs", "" };
2553 ExportAfsCmd(struct cmd_syndesc *as, char *arock)
2556 struct ViceIoctl blob;
2557 struct cmd_item *ti;
2558 int export = 0, type = 0, mode = 0, exp = 0, exportcall, pwsync =
2559 0, smounts = 0, clipags = 0, pagcb = 0;
2561 ti = as->parms[0].items;
2562 if (strcmp(ti->data, "nfs") == 0)
2563 type = 0x71; /* NFS */
2566 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n",
2570 ti = as->parms[1].items;
2572 if (strcmp(ti->data, "on") == 0)
2574 else if (strcmp(ti->data, "off") == 0)
2577 fprintf(stderr, "Illegal argument %s\n", ti->data);
2582 if (ti = as->parms[2].items) { /* -noconvert */
2583 if (strcmp(ti->data, "on") == 0)
2585 else if (strcmp(ti->data, "off") == 0)
2588 fprintf(stderr, "Illegal argument %s\n", ti->data);
2592 if (ti = as->parms[3].items) { /* -uidcheck */
2593 if (strcmp(ti->data, "on") == 0)
2595 else if (strcmp(ti->data, "off") == 0)
2598 fprintf(stderr, "Illegal argument %s\n", ti->data);
2602 if (ti = as->parms[4].items) { /* -submounts */
2603 if (strcmp(ti->data, "on") == 0)
2605 else if (strcmp(ti->data, "off") == 0)
2608 fprintf(stderr, "Illegal argument %s\n", ti->data);
2612 if (ti = as->parms[5].items) { /* -clipags */
2613 if (strcmp(ti->data, "on") == 0)
2615 else if (strcmp(ti->data, "off") == 0)
2618 fprintf(stderr, "Illegal argument %s\n", ti->data);
2622 if (ti = as->parms[6].items) { /* -pagcb */
2623 if (strcmp(ti->data, "on") == 0)
2625 else if (strcmp(ti->data, "off") == 0)
2628 fprintf(stderr, "Illegal argument %s\n", ti->data);
2633 (type << 24) | (pagcb << 10) | (clipags << 8) |
2634 (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2637 blob.in = (char *)&exportcall;
2638 blob.in_size = sizeof(afs_int32);
2639 blob.out = (char *)&exportcall;
2640 blob.out_size = sizeof(afs_int32);
2641 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2643 if (errno == ENODEV) {
2645 "Sorry, the %s-exporter type is currently not supported on this AFS client\n",
2646 exported_types[type]);
2653 if (exportcall & 1) {
2654 printf("'%s' translator is enabled with the following options:\n",
2655 exported_types[type]);
2656 printf("\tRunning in %s mode\n",
2657 (exportcall & 2 ? "strict unix" :
2658 "convert owner mode bits to world/other"));
2659 printf("\tRunning in %s mode\n",
2660 (exportcall & 4 ? "strict 'passwd sync'" :
2661 "no 'passwd sync'"));
2663 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
2664 "Only mounts to /afs allowed"));
2666 (exportcall & 16 ? "Client-assigned PAG's are used" :
2667 "Client-assigned PAG's are not used"));
2670 "Callbacks are made to get creds from new clients" :
2671 "Callbacks are not made to get creds from new clients"));
2673 printf("'%s' translator is disabled\n", exported_types[type]);
2680 GetCellCmd(struct cmd_syndesc *as, char *arock)
2683 struct ViceIoctl blob;
2684 struct afsconf_cell info;
2685 struct cmd_item *ti;
2692 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2693 for (ti = as->parms[0].items; ti; ti = ti->next) {
2695 blob.out_size = sizeof(args);
2696 blob.out = (caddr_t) & args;
2697 code = GetCellName(ti->data, &info);
2702 blob.in_size = 1 + strlen(info.name);
2703 blob.in = info.name;
2704 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2706 if (errno == ENOENT)
2707 fprintf(stderr, "%s: the cell named '%s' does not exist\n",
2710 Die(errno, info.name);
2714 printf("Cell %s status: ", info.name);
2720 printf("no setuid allowed");
2722 printf("setuid allowed");
2724 printf(", using old VLDB");
2731 SetCellCmd(struct cmd_syndesc *as, char *arock)
2734 struct ViceIoctl blob;
2735 struct afsconf_cell info;
2736 struct cmd_item *ti;
2744 /* Check arguments. */
2745 if (as->parms[1].items && as->parms[2].items) {
2746 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2750 /* figure stuff to set */
2754 if (!as->parms[1].items)
2755 args.stat |= 2; /* default to -nosuid */
2757 /* set stat for all listed cells */
2758 for (ti = as->parms[0].items; ti; ti = ti->next) {
2760 code = GetCellName(ti->data, &info);
2765 strcpy(args.cname, info.name);
2766 blob.in_size = sizeof(args);
2767 blob.in = (caddr_t) & args;
2769 blob.out = (caddr_t) 0;
2770 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2772 Die(errno, info.name); /* XXX added cell name to Die() call */
2780 GetCellName(char *cellName, struct afsconf_cell *info)
2782 struct afsconf_dir *tdir;
2785 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2788 "Could not process files in configuration directory (%s).\n",
2789 AFSDIR_CLIENT_ETC_DIRPATH);
2793 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2795 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2796 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
2805 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
2809 code = ugen_ClientInit(noAuthFlag, AFSDIR_CLIENT_ETC_DIRPATH,
2810 info->name, 0, &uclient,
2811 NULL, pn, rxkad_clear,
2812 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
2813 0, 0, USER_SERVICE_ID);
2818 static struct ViceIoctl gblob;
2819 static int debug = 0;
2821 * here follow some routines in suport of the setserverprefs and
2822 * getserverprefs commands. They are:
2823 * SetPrefCmd "top-level" routine
2824 * addServer adds a server to the list of servers to be poked into the
2825 * kernel. Will poke the list into the kernel if it threatens
2827 * pokeServers pokes the existing list of servers and ranks into the kernel
2828 * GetPrefCmd reads the Cache Manager's current list of server ranks
2832 * returns -1 if error message printed,
2834 * errno value if error and no error message printed
2841 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2842 if (code && (errno == EINVAL)) {
2843 struct setspref *ssp;
2844 ssp = (struct setspref *)gblob.in;
2845 if (!(ssp->flags & DBservers)) {
2846 gblob.in = (void *)&(ssp->servers[0]);
2847 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
2848 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
2849 return code ? errno : 0;
2852 "This cache manager does not support VL server preferences.\n");
2856 return code ? errno : 0;
2860 * returns -1 if error message printed,
2862 * errno value if error and no error message printed
2865 addServer(char *name, afs_int32 rank)
2868 struct setspref *ssp;
2870 struct hostent *thostent;
2876 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
2878 #define MAXUSHORT ((unsigned short) ~0)
2882 thostent = hostutil_GetHostByName(name);
2884 fprintf(stderr, "%s: couldn't resolve name.\n", name);
2888 ssp = (struct setspref *)(gblob.in);
2890 for (t = 0; thostent->h_addr_list[t]; t++) {
2891 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
2892 code = pokeServers();
2895 ssp->num_servers = 0;
2898 sp = (struct spref *)(gblob.in + gblob.in_size);
2899 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
2900 sizeof(afs_uint32));
2901 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
2902 gblob.in_size += sizeof(struct spref);
2906 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
2907 name, sp->rank, sp->server.s_addr);
2915 SetPrefCmd(struct cmd_syndesc *as, char *arock)
2919 struct cmd_item *ti;
2922 struct setspref *ssp;
2923 int error = 0; /* -1 means error message printed,
2924 * >0 means errno value for unprinted message */
2926 ssp = (struct setspref *)space;
2928 ssp->num_servers = 0;
2929 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
2932 gblob.out_size = MAXSIZE;
2936 fprintf(stderr, "Permission denied: requires root access.\n");
2940 ti = as->parms[2].items; /* -file */
2943 fprintf(stderr, "opening file %s\n", ti->data);
2944 if (!(infd = fopen(ti->data, "r"))) {
2948 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
2949 code = addServer(name, (unsigned short)rank);
2956 ti = as->parms[3].items; /* -stdin */
2958 while (scanf("%79s%ld", name, &rank) != EOF) {
2959 code = addServer(name, (unsigned short)rank);
2965 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
2970 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
2974 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
2978 code = pokeServers();
2982 printf("now working on vlservers, code=%d\n", code);
2984 ssp = (struct setspref *)space;
2985 ssp->flags = DBservers;
2986 ssp->num_servers = 0;
2987 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
2990 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
2995 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
2999 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3004 if (as->parms[1].items) {
3006 printf("now poking vlservers\n");
3007 code = pokeServers();
3015 return error ? 1 : 0;
3021 GetPrefCmd(struct cmd_syndesc *as, char *arock)
3024 struct cmd_item *ti;
3025 char *name, tbuffer[20];
3026 afs_int32 rank, addr;
3030 struct ViceIoctl blob;
3031 struct sprefrequest *in;
3032 struct sprefinfo *out;
3035 ti = as->parms[0].items; /* -file */
3038 fprintf(stderr, "opening file %s\n", ti->data);
3039 if (!(outfd = freopen(ti->data, "w", stdout))) {
3045 ti = as->parms[1].items; /* -numeric */
3047 ti = as->parms[2].items; /* -vlservers */
3048 vlservers |= (ti ? DBservers : 0);
3049 /* ti = as->parms[3].items; -cell */
3051 in = (struct sprefrequest *)space;
3055 blob.in_size = sizeof(struct sprefrequest);
3056 blob.in = (char *)in;
3058 blob.out_size = MAXSIZE;
3061 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3062 in->flags = vlservers;
3064 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3066 perror("getserverprefs pioctl");
3070 out = (struct sprefinfo *)blob.out;
3072 for (i = 0; i < out->num_servers; i++) {
3074 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3076 addr = ntohl(out->servers[i].server.s_addr);
3077 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3078 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3081 printf("%-50s %5u\n", name, out->servers[i].rank);
3084 in->offset = out->next_offset;
3085 } while (out->next_offset > 0);
3091 StoreBehindCmd(struct cmd_syndesc *as, char *arock)
3094 struct ViceIoctl blob;
3095 struct cmd_item *ti;
3096 struct sbstruct tsb, tsb2;
3102 tsb.sb_thisfile = -1;
3103 ti = as->parms[0].items; /* -kbytes */
3105 if (!as->parms[1].items) {
3106 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3110 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3111 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3112 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3118 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3119 ti = as->parms[2].items; /* -allfiles */
3121 allfiles = strtol(ti->data, &t, 10) * 1024;
3122 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3123 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3129 /* -verbose or -file only or no options */
3130 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3131 || (!as->parms[0].items && !as->parms[1].items
3132 && !as->parms[2].items))
3135 blob.in = (char *)&tsb;
3136 blob.out = (char *)&tsb2;
3137 blob.in_size = blob.out_size = sizeof(struct sbstruct);
3138 memset(&tsb2, 0, sizeof(tsb2));
3140 /* once per -file */
3141 for (ti = as->parms[1].items; ti; ti = ti->next) {
3142 /* Do this solely to see if the file is there */
3143 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3145 Die(errno, ti->data);
3150 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
3152 Die(errno, ti->data);
3157 if (verbose && (blob.out_size == sizeof(tsb2))) {
3158 if (tsb2.sb_thisfile == -1) {
3159 fprintf(stdout, "Will store %s according to default.\n",
3163 "Will store up to %d kbytes of %s asynchronously.\n",
3164 (tsb2.sb_thisfile / 1024), ti->data);
3169 /* If no files - make at least one pioctl call, or
3170 * set the allfiles default if we need to.
3172 if (!as->parms[1].items || (allfiles != -1)) {
3173 tsb.sb_default = allfiles;
3174 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
3176 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3181 /* Having no arguments also reports the default store asynchrony */
3182 if (verbose && (blob.out_size == sizeof(tsb2))) {
3183 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3184 (tsb2.sb_default / 1024));
3192 SetCryptCmd(struct cmd_syndesc *as, char *arock)
3194 afs_int32 code = 0, flag;
3195 struct ViceIoctl blob;
3198 tp = as->parms[0].items->data;
3199 if (strcmp(tp, "on") == 0)
3201 else if (strcmp(tp, "off") == 0)
3204 fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3208 blob.in = (char *)&flag;
3209 blob.in_size = sizeof(flag);
3211 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3219 GetCryptCmd(struct cmd_syndesc *as, char *arock)
3221 afs_int32 code = 0, flag;
3222 struct ViceIoctl blob;
3227 blob.out_size = sizeof(flag);
3230 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3236 memcpy(&flag, tp, sizeof(afs_int32));
3237 printf("Security level is currently ");
3239 printf("crypt (data security).\n");
3246 #ifdef AFS_DISCON_ENV
3247 static char *modenames[] = {
3257 DisconCmd(struct cmd_syndesc *as, char *arock)
3259 struct cmd_item *ti;
3262 afs_int32 mode, code;
3263 struct ViceIoctl blob;
3268 ti = as->parms[0].items;
3270 modename = ti->data;
3271 modelen = strlen(modename);
3272 for (mode = 0; modenames[mode] != NULL; mode++)
3273 if (!strncasecmp(modename, modenames[mode], modelen))
3275 if (modenames[mode] == NULL)
3276 printf("Unknown discon mode \"%s\"\n", modename);
3278 memcpy(space, &mode, sizeof mode);
3280 blob.in_size = sizeof mode;
3284 blob.out_size = sizeof(mode);
3286 code = pioctl(0, VIOC_DISCON, &blob, 1);
3290 memcpy(&mode, space, sizeof mode);
3291 if (mode < sizeof modenames / sizeof (char *))
3292 printf("Discon mode is now \"%s\"\n", modenames[mode]);
3294 printf("Unknown discon mode %d\n", mode);
3301 #include "AFS_component_version_number.c"
3304 main(int argc, char **argv)
3307 struct cmd_syndesc *ts;
3309 #ifdef AFS_AIX32_ENV
3311 * The following signal action for AIX is necessary so that in case of a
3312 * crash (i.e. core is generated) we can include the user's data section
3313 * in the core dump. Unfortunately, by default, only a partial core is
3314 * generated which, in many cases, isn't too useful.
3316 struct sigaction nsa;
3318 sigemptyset(&nsa.sa_mask);
3319 nsa.sa_handler = SIG_DFL;
3320 nsa.sa_flags = SA_FULLDUMP;
3321 sigaction(SIGSEGV, &nsa, NULL);
3324 /* try to find volume location information */
3325 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, 0,
3326 "get client network interface addresses");
3327 cmd_CreateAlias(ts, "gc");
3329 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, 0,
3330 "set client network interface addresses");
3331 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3332 "client network interfaces");
3333 cmd_CreateAlias(ts, "sc");
3335 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0,
3336 "set server ranks");
3337 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3338 "fileserver names and ranks");
3339 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3340 "VL server names and ranks");
3341 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3342 "input from named file");
3343 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3344 cmd_CreateAlias(ts, "sp");
3346 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0,
3347 "get server ranks");
3348 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3349 "output to named file");
3350 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3351 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3352 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3353 cmd_CreateAlias(ts, "gp");
3355 ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list");
3356 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3357 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3358 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3359 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL,
3360 "apply to negative rights");
3361 parm_setacl_id = ts->nParms;
3362 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL,
3363 "initial directory acl (DFS only)");
3364 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL,
3365 "initial file acl (DFS only)");
3366 cmd_CreateAlias(ts, "sa");
3368 ts = cmd_CreateSyntax("listacl", ListACLCmd, 0,
3369 "list access control list");
3370 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3371 parm_listacl_id = ts->nParms;
3372 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3373 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3374 cmd_CreateAlias(ts, "la");
3376 ts = cmd_CreateSyntax("getcalleraccess", GetCallerAccess, 0,
3377 "list callers access");
3378 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3379 cmd_CreateAlias(ts, "gca");
3381 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0,
3382 "clean up access control list");
3383 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3385 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0,
3386 "copy access control list");
3387 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0,
3388 "source directory (or DFS file)");
3389 cmd_AddParm(ts, "-todir", CMD_LIST, 0,
3390 "destination directory (or DFS file)");
3391 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3392 "first clear dest access list");
3393 parm_copyacl_id = ts->nParms;
3394 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3395 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3397 cmd_CreateAlias(ts, "ca");
3399 ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache");
3400 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3401 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, 0,
3402 "flush mount symlink from cache");
3403 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3405 ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status");
3406 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3407 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL,
3408 "disk space quota in 1K units");
3410 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL,
3411 "disk space guaranteed");
3412 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3414 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL,
3416 cmd_CreateAlias(ts, "sv");
3418 ts = cmd_CreateSyntax("messages", MessagesCmd, 0,
3419 "control Cache Manager messages");
3420 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL,
3421 "[user|console|all|none]");
3423 ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display file/volume status");
3424 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3425 cmd_CreateAlias(ts, "lv");
3426 cmd_CreateAlias(ts, "listvol");
3428 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota");
3429 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3430 cmd_CreateAlias(ts, "lq");
3432 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0,
3433 "show server disk space usage");
3434 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3435 cmd_CreateAlias(ts, "df");
3437 ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage");
3438 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3440 ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point");
3441 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3443 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point");
3444 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3445 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3446 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3447 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3448 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3449 "don't check name with VLDB");
3455 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3459 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point");
3460 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3462 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0,
3463 "check local cell's servers");
3464 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3465 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3466 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3467 "just list, don't check");
3468 cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL,
3469 "seconds between probes");
3471 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, 0,
3472 "check volumeID/name mappings");
3473 cmd_CreateAlias(ts, "checkbackups");
3476 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0,
3478 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3479 "size in 1K byte blocks (0 => reset)");
3480 cmd_CreateAlias(ts, "cachesize");
3482 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL,
3483 "reset size back to boot value");
3485 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0,
3486 "get cache usage info");
3487 cmd_AddParm(ts, "-files", CMD_FLAG, CMD_OPTIONAL, "Show cach files used as well");
3488 cmd_AddParm(ts, "-excessive", CMD_FLAG, CMD_OPTIONAL, "excessively verbose cache stats");
3490 ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0,
3491 "list configured cells");
3492 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3494 ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, 0,
3495 "list configured cell aliases");
3497 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota");
3498 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3499 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3501 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3503 cmd_CreateAlias(ts, "sq");
3505 ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell");
3506 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3507 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3508 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL,
3509 "linked cell name");
3511 ts = cmd_CreateSyntax("newalias", NewAliasCmd, 0,
3512 "configure new cell alias");
3513 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
3514 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
3516 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3518 * Turn this on only if you wish to be able to talk to a server which is listening
3519 * on alternative ports. This is not intended for general use and may not be
3520 * supported in the cache manager. It is not a way to run two servers at the
3521 * same host, since the cache manager cannot properly distinguish those two hosts.
3523 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL,
3524 "cell's fileserver port");
3525 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL,
3526 "cell's vldb server port");
3529 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell");
3530 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3532 ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location");
3533 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3535 ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell");
3538 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
3541 /* set cache monitor host address */
3542 ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, (char *)CMD_HIDDEN);
3543 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL,
3544 "host name or 'off'");
3545 cmd_CreateAlias(ts, "mariner");
3547 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status");
3548 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3550 ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status");
3551 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3552 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3553 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL,
3554 "disallow setuid programs");
3556 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0,
3557 "flush all data in volume");
3558 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3560 ts = cmd_CreateSyntax("sysname", SysNameCmd, 0,
3561 "get/set sysname (i.e. @sys) value");
3562 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3564 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0,
3565 "enable/disable translators to AFS");
3566 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3567 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL,
3568 "start/stop translator (on | off)");
3569 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL,
3570 "convert from afs to unix mode (on | off)");
3571 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL,
3572 "run on strict 'uid check' mode (on | off)");
3573 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
3574 "allow nfs mounts to subdirs of /afs/.. (on | off)");
3575 cmd_AddParm(ts, "-clipags", CMD_SINGLE, CMD_OPTIONAL,
3576 "enable use of client-assigned PAG's (on | off)");
3577 cmd_AddParm(ts, "-pagcb", CMD_SINGLE, CMD_OPTIONAL,
3578 "enable callbacks to get creds from new clients (on | off)");
3581 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0,
3582 "store to server after file close");
3583 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL,
3584 "asynchrony for specified names");
3585 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3586 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL,
3587 "new default (KB)");
3588 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3589 cmd_CreateAlias(ts, "sb");
3591 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0,
3592 "set cache manager encryption flag");
3593 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3595 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0,
3596 "get cache manager encryption flag");
3598 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, 0,
3599 "Manage per process RX statistics");
3600 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3601 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3602 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3604 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, 0,
3605 "Manage per peer RX statistics");
3606 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3607 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3608 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3610 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, 0, "configure callback connection address");
3611 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
3613 /* try to find volume location information */
3614 ts = cmd_CreateSyntax("getfid", GetFidCmd, 0,
3615 "get fid for file(s)");
3616 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3618 #ifdef AFS_DISCON_ENV
3619 ts = cmd_CreateSyntax("discon", DisconCmd, 0,
3620 "disconnection mode");
3621 cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_OPTIONAL, "nat | full");
3624 ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, 0, "nuke credentials for NFS client");
3625 cmd_AddParm(ts, "-addr", CMD_SINGLE, 0, "host name or address");
3627 code = cmd_Dispatch(argc, argv);
3635 Die(int errnum, char *filename)
3641 "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3644 fprintf(stderr, "%s: Invalid argument.\n", pn);
3648 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3650 fprintf(stderr, "%s: no such file returned\n", pn);
3654 "%s: You can not change a backup or readonly volume\n", pn);
3660 "%s: You don't have the required access rights on '%s'\n",
3664 "%s: You do not have the required rights to do this operation\n",
3669 fprintf(stderr, "%s:'%s'", pn, filename);
3671 fprintf(stderr, "%s", pn);
3672 fprintf(stderr, ": %s\n", error_message(errnum));
3677 /* get clients interface addresses */
3679 GetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
3682 struct cmd_item *ti;
3684 struct ViceIoctl blob;
3685 struct sprefrequest *in;
3686 struct sprefinfo *out;
3688 in = (struct sprefrequest *)space;
3692 blob.in_size = sizeof(struct sprefrequest);
3693 blob.in = (char *)in;
3695 blob.out_size = MAXSIZE;
3698 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3699 /* returns addr in network byte order */
3700 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3702 perror("getClientInterfaceAddr pioctl");
3708 out = (struct sprefinfo *)blob.out;
3709 for (i = 0; i < out->num_servers; i++) {
3712 addr = ntohl(out->servers[i].server.s_addr);
3713 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3714 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3715 printf("%-50s\n", tbuffer);
3717 in->offset = out->next_offset;
3719 } while (out->next_offset > 0);
3725 SetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
3727 afs_int32 code, addr;
3728 struct cmd_item *ti;
3730 struct ViceIoctl blob;
3731 struct setspref *ssp;
3732 int sizeUsed = 0, i, flag;
3733 afs_int32 existingAddr[1024]; /* existing addresses on this host */
3737 ssp = (struct setspref *)space;
3738 ssp->num_servers = 0;
3741 blob.out_size = MAXSIZE;
3744 fprintf(stderr, "Permission denied: requires root access.\n");
3748 /* extract all existing interface addresses */
3749 existNu = rx_getAllAddr(existingAddr, 1024);
3753 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
3754 for (ti = as->parms[0].items; ti; ti = ti->next) {
3755 if (sizeUsed >= sizeof(space)) {
3756 fprintf(stderr, "No more space\n");
3759 addr = extractAddr(ti->data, 20); /* network order */
3760 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
3761 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
3766 /* see if it is an address that really exists */
3767 for (flag = 0, i = 0; i < existNu; i++)
3768 if (existingAddr[i] == addr) {
3772 if (!flag) { /* this is an nonexistent address */
3773 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
3777 /* copy all specified addr into ioctl buffer */
3778 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
3779 printf("Adding 0x%08x\n", addr);
3781 sizeUsed += sizeof(struct spref);
3783 if (ssp->num_servers < 1) {
3784 fprintf(stderr, "No addresses specified\n");
3787 blob.in_size = sizeUsed - sizeof(struct spref);
3789 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
3799 FlushMountCmd(struct cmd_syndesc *as, char *arock)
3802 struct ViceIoctl blob;
3803 struct cmd_item *ti;
3804 char orig_name[1024]; /*Original name, may be modified */
3805 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
3806 char parent_dir[1024]; /*Parent directory of true name */
3807 char *last_component; /*Last component of true name */
3808 struct stat statbuff; /*Buffer for status info */
3809 int link_chars_read; /*Num chars read in readlink() */
3810 int thru_symlink; /*Did we get to a mount point via a symlink? */
3813 for (ti = as->parms[0].items; ti; ti = ti->next) {
3816 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
3819 if (lstat(orig_name, &statbuff) < 0) {
3820 /* if lstat fails, we should still try the pioctl, since it
3821 * may work (for example, lstat will fail, but pioctl will
3822 * work if the volume of offline (returning ENODEV). */
3823 statbuff.st_mode = S_IFDIR; /* lie like pros */
3827 * The lstat succeeded. If the given file is a symlink, substitute
3828 * the file name with the link name.
3830 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
3833 * Read name of resolved file.
3835 link_chars_read = readlink(orig_name, true_name, 1024);
3836 if (link_chars_read <= 0) {
3838 "%s: Can't read target name for '%s' symbolic link!\n",
3845 * Add a trailing null to what was read, bump the length.
3847 true_name[link_chars_read++] = 0;
3850 * If the symlink is an absolute pathname, we're fine. Otherwise, we
3851 * have to create a full pathname using the original name and the
3852 * relative symlink name. Find the rightmost slash in the original
3853 * name (we know there is one) and splice in the symlink value.
3855 if (true_name[0] != '/') {
3856 last_component = (char *)strrchr(orig_name, '/');
3857 strcpy(++last_component, true_name);
3858 strcpy(true_name, orig_name);
3861 strcpy(true_name, orig_name);
3864 * Find rightmost slash, if any.
3866 last_component = (char *)strrchr(true_name, '/');
3867 if (last_component) {
3869 * Found it. Designate everything before it as the parent directory,
3870 * everything after it as the final component.
3872 strncpy(parent_dir, true_name, last_component - true_name);
3873 parent_dir[last_component - true_name] = 0;
3874 last_component++; /*Skip the slash */
3877 * No slash appears in the given file name. Set parent_dir to the current
3878 * directory, and the last component as the given name.
3880 strcpy(parent_dir, ".");
3881 last_component = true_name;
3884 if (strcmp(last_component, ".") == 0
3885 || strcmp(last_component, "..") == 0) {
3887 "%s: you may not use '.' or '..' as the last component\n",
3889 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
3895 blob.in = last_component;
3896 blob.in_size = strlen(last_component) + 1;
3898 memset(space, 0, MAXSIZE);
3900 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
3903 if (errno == EINVAL) {
3904 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
3906 Die(errno, (ti->data ? ti->data : parent_dir));
3915 RxStatProcCmd(struct cmd_syndesc *as, char *arock)
3918 afs_int32 flags = 0;
3919 struct ViceIoctl blob;
3920 struct cmd_item *ti;
3922 if (as->parms[0].items) { /* -enable */
3923 flags |= AFSCALL_RXSTATS_ENABLE;
3925 if (as->parms[1].items) { /* -disable */
3926 flags |= AFSCALL_RXSTATS_DISABLE;
3928 if (as->parms[2].items) { /* -clear */
3929 flags |= AFSCALL_RXSTATS_CLEAR;
3932 fprintf(stderr, "You must specify at least one argument\n");
3936 blob.in = (char *)&flags;
3937 blob.in_size = sizeof(afs_int32);
3940 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
3950 RxStatPeerCmd(struct cmd_syndesc *as, char *arock)
3953 afs_int32 flags = 0;
3954 struct ViceIoctl blob;
3955 struct cmd_item *ti;
3957 if (as->parms[0].items) { /* -enable */
3958 flags |= AFSCALL_RXSTATS_ENABLE;
3960 if (as->parms[1].items) { /* -disable */
3961 flags |= AFSCALL_RXSTATS_DISABLE;
3963 if (as->parms[2].items) { /* -clear */
3964 flags |= AFSCALL_RXSTATS_CLEAR;
3967 fprintf(stderr, "You must specify at least one argument\n");
3971 blob.in = (char *)&flags;
3972 blob.in_size = sizeof(afs_int32);
3975 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
3985 GetFidCmd(struct cmd_syndesc *as, char *arock)
3987 struct ViceIoctl blob;
3988 struct cmd_item *ti;
3989 for (ti = as->parms[0].items; ti; ti = ti->next) {
3990 struct VenusFid vfid;
3992 blob.out_size = sizeof(struct VenusFid);
3993 blob.out = (char *) &vfid;
3996 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
3997 printf("File %s (%u.%u.%u) contained in volume %u\n",
3998 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,