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>
42 #include "afs/prs_fs.h"
43 #include <afs/afsint.h>
45 #include <afs/cellconfig.h>
48 #include <rx/rx_globals.h>
49 #include <afs/vldbint.h>
50 #include <afs/volser.h>
51 #include <afs/vlserver.h>
53 #include <afs/afsutil.h>
56 #include <afs/ptclient.h>
61 #define MAXCELLHOSTS 8
64 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
65 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
67 static char space[MAXSIZE];
68 static char tspace[1024];
69 static struct ubik_client *uclient;
71 static int GetClientAddrsCmd(), SetClientAddrsCmd(), FlushMountCmd();
72 static int RxStatProcCmd(), RxStatPeerCmd();
74 extern char *hostutil_GetNameByINet();
75 extern struct hostent *hostutil_GetHostByName();
78 extern struct cmd_syndesc *cmd_CreateSyntax();
79 static char pn[] = "fs";
80 static int rxInitDone = 0;
82 static void ZapList();
83 static int PruneList();
91 * Character to use between name and rights in printed representation for
94 #define DFS_SEPARATOR ' '
96 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
99 int dfs; /* Originally true if a dfs acl; now also the type
100 * of the acl (1, 2, or 3, corresponding to object,
101 * initial dir, or initial object). */
102 sec_rgy_name_t cell; /* DFS cell name */
105 struct AclEntry *pluslist;
106 struct AclEntry *minuslist;
110 struct AclEntry *next;
121 ZapList(acl->pluslist);
122 ZapList(acl->minuslist);
135 if (t >= 'A' && t <= 'Z')
137 if (u >= 'A' && u <= 'Z')
147 * Mods for the AFS/DFS protocol translator.
149 * DFS rights. It's ugly to put these definitions here, but they
150 * *cannot* change, because they're part of the wire protocol.
151 * In any event, the protocol translator will guarantee these
152 * assignments for AFS cache managers.
154 #define DFS_READ 0x01
155 #define DFS_WRITE 0x02
156 #define DFS_EXECUTE 0x04
157 #define DFS_CONTROL 0x08
158 #define DFS_INSERT 0x10
159 #define DFS_DELETE 0x20
161 /* the application definable ones (backwards from AFS) */
162 #define DFS_USR0 0x80000000 /* "A" bit */
163 #define DFS_USR1 0x40000000 /* "B" bit */
164 #define DFS_USR2 0x20000000 /* "C" bit */
165 #define DFS_USR3 0x10000000 /* "D" bit */
166 #define DFS_USR4 0x08000000 /* "E" bit */
167 #define DFS_USR5 0x04000000 /* "F" bit */
168 #define DFS_USR6 0x02000000 /* "G" bit */
169 #define DFS_USR7 0x01000000 /* "H" bit */
170 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
171 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
174 * Offset of -id switch in command structure for various commands.
175 * The -if switch is the next switch always.
177 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
180 * Determine whether either the -id or -if switches are present, and
181 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
183 /* int id; Offset of -id switch; -if is next switch */
185 getidf(struct cmd_syndesc *as, int id)
189 if (as->parms[id].items) {
192 if (as->parms[id + 1].items) {
197 "%s: you may specify either -id or -if, but not both switches\n",
205 PRights(afs_int32 arights, int dfs)
208 if (arights & PRSFS_READ)
210 if (arights & PRSFS_LOOKUP)
212 if (arights & PRSFS_INSERT)
214 if (arights & PRSFS_DELETE)
216 if (arights & PRSFS_WRITE)
218 if (arights & PRSFS_LOCK)
220 if (arights & PRSFS_ADMINISTER)
222 if (arights & PRSFS_USR0)
224 if (arights & PRSFS_USR1)
226 if (arights & PRSFS_USR2)
228 if (arights & PRSFS_USR3)
230 if (arights & PRSFS_USR4)
232 if (arights & PRSFS_USR5)
234 if (arights & PRSFS_USR6)
236 if (arights & PRSFS_USR7)
239 if (arights & DFS_READ)
243 if (arights & DFS_WRITE)
247 if (arights & DFS_EXECUTE)
251 if (arights & DFS_CONTROL)
255 if (arights & DFS_INSERT)
259 if (arights & DFS_DELETE)
263 if (arights & (DFS_USRALL))
265 if (arights & DFS_USR0)
267 if (arights & DFS_USR1)
269 if (arights & DFS_USR2)
271 if (arights & DFS_USR3)
273 if (arights & DFS_USR4)
275 if (arights & DFS_USR5)
277 if (arights & DFS_USR6)
279 if (arights & DFS_USR7)
284 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
288 struct ViceIoctl blob;
292 blob.out_size = MAXSIZE;
295 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
297 if ((errno == EINVAL) || (errno == ENOENT))
303 /* return a static pointer to a buffer */
308 strcpy(tspace, apath);
309 tp = strrchr(tspace, '/');
317 enum rtype { add, destroy, deny };
320 Convert(char *arights, int dfs, enum rtype *rtypep)
326 *rtypep = add; /* add rights, by default */
329 if (!strcmp(arights, "null")) {
333 if (!strcmp(arights, "read"))
334 return DFS_READ | DFS_EXECUTE;
335 if (!strcmp(arights, "write"))
336 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
338 if (!strcmp(arights, "all"))
339 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
340 DFS_WRITE | DFS_CONTROL;
342 if (!strcmp(arights, "read"))
343 return PRSFS_READ | PRSFS_LOOKUP;
344 if (!strcmp(arights, "write"))
345 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
346 PRSFS_WRITE | PRSFS_LOCK;
347 if (!strcmp(arights, "mail"))
348 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
349 if (!strcmp(arights, "all"))
350 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
351 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
353 if (!strcmp(arights, "none")) {
354 *rtypep = destroy; /* Remove entire entry */
357 len = strlen(arights);
359 for (i = 0; i < len; i++) {
393 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
401 mode |= PRSFS_LOOKUP;
403 mode |= PRSFS_INSERT;
405 mode |= PRSFS_DELETE;
411 mode |= PRSFS_ADMINISTER;
429 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
438 static struct AclEntry *
439 FindList(struct AclEntry *alist, char *aname)
442 if (!foldcmp(alist->name, aname))
449 /* if no parm specified in a particular slot, set parm to be "." instead */
451 SetDotDefault(struct cmd_item **aitemp)
455 return; /* already has value */
456 /* otherwise, allocate an item representing "." */
457 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
459 ti->next = (struct cmd_item *)0;
460 ti->data = (char *)malloc(2);
462 strcpy(ti->data, ".");
467 ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
469 struct AclEntry *tlist;
470 tlist = (plus ? al->pluslist : al->minuslist);
471 tlist = FindList(tlist, aname);
473 /* Found the item already in the list. */
474 tlist->rights = arights;
476 al->nplus -= PruneList(&al->pluslist, al->dfs);
478 al->nminus -= PruneList(&al->minuslist, al->dfs);
481 /* Otherwise we make a new item and plug in the new data. */
482 tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry));
484 strcpy(tlist->name, aname);
485 tlist->rights = arights;
487 tlist->next = al->pluslist;
488 al->pluslist = tlist;
490 if (arights == 0 || arights == -1)
491 al->nplus -= PruneList(&al->pluslist, al->dfs);
493 tlist->next = al->minuslist;
494 al->minuslist = tlist;
497 al->nminus -= PruneList(&al->minuslist, al->dfs);
502 ZapList(struct AclEntry *alist)
504 struct AclEntry *tp, *np;
505 for (tp = alist; tp; tp = np) {
512 PruneList(struct AclEntry **ae, int dfs)
514 struct AclEntry **lp;
515 struct AclEntry *te, *ne;
519 for (te = *ae; te; te = ne) {
520 if ((!dfs && te->rights == 0) || te->rights == -1) {
536 while (*astr != '\n')
543 * Create an empty acl, taking into account whether the acl pointed
544 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
545 * can recover from problems caused by bogus ACL's (in that case, always
546 * assume that the acl is AFS: for DFS, the user can always resort to
547 * acl_edit, but for AFS there may be no other way out).
555 tp = (struct Acl *)malloc(sizeof(struct Acl));
557 tp->nplus = tp->nminus = 0;
558 tp->pluslist = tp->minuslist = 0;
560 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
567 int nplus, nminus, i, trights;
569 struct AclEntry *first, *last, *tl;
572 ta = (struct Acl *)malloc(sizeof(struct Acl));
575 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
576 astr = SkipLine(astr);
577 sscanf(astr, "%d", &ta->nminus);
578 astr = SkipLine(astr);
585 for (i = 0; i < nplus; i++) {
586 sscanf(astr, "%100s %d", tname, &trights);
587 astr = SkipLine(astr);
588 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
592 strcpy(tl->name, tname);
593 tl->rights = trights;
599 ta->pluslist = first;
603 for (i = 0; i < nminus; i++) {
604 sscanf(astr, "%100s %d", tname, &trights);
605 astr = SkipLine(astr);
606 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
610 strcpy(tl->name, tname);
611 tl->rights = trights;
617 ta->minuslist = first;
623 PrintStatus(VolumeStatus * status, char *name, char *offmsg)
625 printf("Volume status for vid = %u named %s\n", status->Vid, name);
627 printf("Current offline message is %s\n", offmsg);
628 printf("Current disk quota is ");
629 if (status->MaxQuota != 0)
630 printf("%d\n", status->MaxQuota);
632 printf("unlimited\n");
633 printf("Current blocks used are %d\n", status->BlocksInUse);
634 printf("The partition has %d blocks available out of %d\n\n",
635 status->PartBlocksAvail, status->PartMaxBlocks);
640 QuickPrintStatus(VolumeStatus * status, char *name)
642 double QuotaUsed = 0.0;
643 double PartUsed = 0.0;
645 printf("%-25.25s", name);
647 if (status->MaxQuota != 0) {
648 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
650 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
652 printf(" no limit%10d", status->BlocksInUse);
654 if (QuotaUsed > 90.0) {
655 printf("%5.0f%%<<", QuotaUsed);
658 printf("%5.0f%% ", QuotaUsed);
661 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
663 if (PartUsed > 97.0) {
664 printf("%9.0f%%<<", PartUsed);
667 printf("%9.0f%% ", PartUsed);
669 printf(" <<WARNING\n");
676 QuickPrintSpace(VolumeStatus * status, char *name)
678 double PartUsed = 0.0;
680 printf("%-25.25s", name);
682 printf("%10d%10d%10d", status->PartMaxBlocks,
683 status->PartMaxBlocks - status->PartBlocksAvail,
684 status->PartBlocksAvail);
688 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
690 if (PartUsed > 90.0) {
691 printf(" %4.0f%%<<", PartUsed);
694 printf(" %4.0f%% ", PartUsed);
696 printf(" <<WARNING\n");
703 AclToString(struct Acl *acl)
705 static char mydata[MAXSIZE];
706 char tstring[MAXSIZE];
711 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
714 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
715 for (tp = acl->pluslist; tp; tp = tp->next) {
716 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
717 strcat(mydata, tstring);
719 for (tp = acl->minuslist; tp; tp = tp->next) {
720 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
721 strcat(mydata, tstring);
727 SetACLCmd(struct cmd_syndesc *as)
730 struct ViceIoctl blob;
732 struct cmd_item *ti, *ui;
736 int idf = getidf(as, parm_setacl_id);
739 if (as->parms[2].items)
743 plusp = !(as->parms[3].items);
744 for (ti = as->parms[0].items; ti; ti = ti->next) {
745 blob.out_size = MAXSIZE;
747 blob.in = blob.out = space;
748 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
750 Die(errno, ti->data);
757 ta = ParseAcl(space);
758 if (!plusp && ta->dfs) {
760 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
762 "(you may specify \"null\" to revoke all rights, however)\n");
770 ta = EmptyAcl(space);
772 ta = ParseAcl(space);
773 CleanAcl(ta, ti->data);
774 for (ui = as->parms[1].items; ui; ui = ui->next->next) {
778 "%s: Missing second half of user/access pair.\n", pn);
782 rights = Convert(ui->next->data, ta->dfs, &rtype);
783 if (rtype == destroy && !ta->dfs) {
784 struct AclEntry *tlist;
786 tlist = (plusp ? ta->pluslist : ta->minuslist);
787 if (!FindList(tlist, ui->data))
790 if (rtype == deny && !ta->dfs)
792 if (rtype == destroy && ta->dfs)
794 ChangeList(ta, plusp, ui->data, rights);
796 blob.in = AclToString(ta);
798 blob.in_size = 1 + strlen(blob.in);
799 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
801 if (errno == EINVAL) {
803 static char *fsenv = 0;
805 fsenv = (char *)getenv("FS_EXPERT");
808 "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n",
812 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
813 "\nPossible reasons for this include:\n\n",
814 " -You may have specified an inappropriate combination of rights.\n",
815 " For example, some DFS-supported filesystems may not allow you to\n",
816 " drop the \"c\" right from \"user_obj\".\n\n",
817 " -A mask_obj may be required (it is likely required by the underlying\n",
818 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
819 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
820 " does not automatically create or update the mask_obj. Try setting\n",
821 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
822 " users or groups. You can do this with a single command, such as\n",
823 " \"fs sa mask_obj all user:somename read\"\n\n",
824 " -A specified user or group may not exist.\n\n",
825 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
826 " This is probably not allowed by the underlying file system.\n\n",
827 " -If you add a user or group to a DFS ACL, remember that it must be\n",
828 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
829 " may be local requirements on the format of the user or group name.\n",
830 " Check with your cell administrator.\n\n",
831 " -Or numerous other possibilities. It would be great if we could be more\n",
832 " precise about the actual problem, but for various reasons, this is\n",
833 " impractical via this interface. If you can't figure it out, you\n",
834 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
835 " whatever is provided). You may get better results. Good luck!\n\n",
836 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
840 "%s: Invalid argument, possible reasons include:\n",
842 fprintf(stderr, "\t-File not in AFS\n");
844 "\t-Too many users on access control list\n");
846 "\t-Tried to add non-existent user to access control list\n");
849 Die(errno, ti->data);
861 CopyACLCmd(struct cmd_syndesc *as)
864 struct ViceIoctl blob;
865 struct Acl *fa, *ta = 0;
867 struct cmd_item *ti, *ui;
871 int idf = getidf(as, parm_copyacl_id);
874 if (as->parms[2].items)
878 blob.out_size = MAXSIZE;
880 blob.in = blob.out = space;
881 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
883 Die(errno, as->parms[0].items->data);
886 fa = ParseAcl(space);
887 CleanAcl(fa, as->parms[0].items->data);
888 for (ti = as->parms[1].items; ti; ti = ti->next) {
889 blob.out_size = MAXSIZE;
891 blob.in = blob.out = space;
892 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
894 Die(errno, ti->data);
902 ta = EmptyAcl(space);
904 ta = ParseAcl(space);
905 CleanAcl(ta, ti->data);
906 if (ta->dfs != fa->dfs) {
908 "%s: incompatible file system types: acl not copied to %s; aborted\n",
914 if (!clear && strcmp(ta->cell, fa->cell) != 0) {
916 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
921 strcpy(ta->cell, fa->cell);
923 for (tp = fa->pluslist; tp; tp = tp->next)
924 ChangeList(ta, 1, tp->name, tp->rights);
925 for (tp = fa->minuslist; tp; tp = tp->next)
926 ChangeList(ta, 0, tp->name, tp->rights);
927 blob.in = AclToString(ta);
929 blob.in_size = 1 + strlen(blob.in);
930 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
932 if (errno == EINVAL) {
934 "%s: Invalid argument, possible reasons include:\n",
936 fprintf(stderr, "\t-File not in AFS\n");
938 Die(errno, ti->data);
949 /* pioctl() call to get the cellname of a pathname */
951 GetCell(char *fname, char *cellname)
954 struct ViceIoctl blob;
957 blob.out_size = MAXCELLCHARS;
960 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
961 return code ? errno : 0;
964 /* Check if a username is valid: If it contains only digits (or a
965 * negative sign), then it might be bad. We then query the ptserver
969 BadName(char *aname, char *fname)
971 afs_int32 tc, code, id;
973 char cell[MAXCELLCHARS];
975 for (nm = aname; tc = *nm; nm++) {
976 /* all must be '-' or digit to be bad */
977 if (tc != '-' && (tc < '0' || tc > '9'))
981 /* Go to the PRDB and see if this all number username is valid */
982 code = GetCell(fname, cell);
986 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
987 code = pr_SNameToId(aname, &id);
990 /* 1=>Not-valid; 0=>Valid */
991 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
995 /* clean up an access control list of its bad entries; return 1 if we made
996 any changes to the list, and 0 otherwise */
998 CleanAcl(struct Acl *aa, char *fname)
1000 struct AclEntry *te, **le, *ne;
1003 /* Don't correct DFS ACL's for now */
1007 /* prune out bad entries */
1008 changes = 0; /* count deleted entries */
1010 for (te = aa->pluslist; te; te = ne) {
1012 if (BadName(te->name, fname)) {
1022 le = &aa->minuslist;
1023 for (te = aa->minuslist; te; te = ne) {
1025 if (BadName(te->name, fname)) {
1039 /* clean up an acl to not have bogus entries */
1041 CleanACLCmd(struct cmd_syndesc *as)
1045 struct ViceIoctl blob;
1047 struct cmd_item *ti;
1048 struct AclEntry *te;
1051 SetDotDefault(&as->parms[0].items);
1052 for (ti = as->parms[0].items; ti; ti = ti->next) {
1053 blob.out_size = MAXSIZE;
1056 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1058 Die(errno, ti->data);
1065 ta = ParseAcl(space);
1068 "%s: cleanacl is not supported for DFS access lists.\n",
1074 changes = CleanAcl(ta, ti->data);
1077 /* now set the acl */
1078 blob.in = AclToString(ta);
1079 blob.in_size = strlen(blob.in) + 1;
1081 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1083 if (errno == EINVAL) {
1085 "%s: Invalid argument, possible reasons include\n",
1087 fprintf(stderr, "%s: File not in vice or\n", pn);
1089 "%s: Too many users on access control list or\n",
1092 Die(errno, ti->data);
1098 /* now list the updated acl */
1099 printf("Access list for %s is now\n", ti->data);
1100 if (ta->nplus > 0) {
1102 printf("Normal rights:\n");
1103 for (te = ta->pluslist; te; te = te->next) {
1104 printf(" %s ", te->name);
1105 PRights(te->rights, ta->dfs);
1109 if (ta->nminus > 0) {
1110 printf("Negative rights:\n");
1111 for (te = ta->minuslist; te; te = te->next) {
1112 printf(" %s ", te->name);
1113 PRights(te->rights, ta->dfs);
1120 printf("Access list for %s is fine.\n", ti->data);
1128 ListACLCmd(struct cmd_syndesc *as)
1132 struct ViceIoctl blob;
1133 struct AclEntry *te;
1134 struct cmd_item *ti;
1135 int idf = getidf(as, parm_listacl_id);
1138 SetDotDefault(&as->parms[0].items);
1139 for (ti = as->parms[0].items; ti; ti = ti->next) {
1140 blob.out_size = MAXSIZE;
1142 blob.in = blob.out = space;
1143 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1145 Die(errno, ti->data);
1149 ta = ParseAcl(space);
1152 printf("Access list for %s is\n", ti->data);
1155 printf("DFS access list for %s is\n", ti->data);
1158 printf("DFS initial directory access list of %s is\n", ti->data);
1161 printf("DFS initial file access list of %s is\n", ti->data);
1165 printf(" Default cell = %s\n", ta->cell);
1167 if (ta->nplus > 0) {
1169 printf("Normal rights:\n");
1170 for (te = ta->pluslist; te; te = te->next) {
1171 printf(" %s ", te->name);
1172 PRights(te->rights, ta->dfs);
1176 if (ta->nminus > 0) {
1177 printf("Negative rights:\n");
1178 for (te = ta->minuslist; te; te = te->next) {
1179 printf(" %s ", te->name);
1180 PRights(te->rights, ta->dfs);
1192 FlushVolumeCmd(struct cmd_syndesc *as)
1195 struct ViceIoctl blob;
1196 struct cmd_item *ti;
1199 SetDotDefault(&as->parms[0].items);
1200 for (ti = as->parms[0].items; ti; ti = ti->next) {
1201 blob.in_size = blob.out_size = 0;
1202 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1204 fprintf(stderr, "Error flushing volume ");
1214 FlushCmd(struct cmd_syndesc *as)
1217 struct ViceIoctl blob;
1218 struct cmd_item *ti;
1221 for (ti = as->parms[0].items; ti; ti = ti->next) {
1222 blob.in_size = blob.out_size = 0;
1223 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1225 if (errno == EMFILE) {
1226 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1229 fprintf(stderr, "%s: Error flushing file ", pn);
1239 /* all this command does is repackage its args and call SetVolCmd */
1241 SetQuotaCmd(struct cmd_syndesc *as)
1243 struct cmd_syndesc ts;
1245 /* copy useful stuff from our command slot; we may later have to reorder */
1246 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1247 return SetVolCmd(&ts);
1251 SetVolCmd(struct cmd_syndesc *as)
1254 struct ViceIoctl blob;
1255 struct cmd_item *ti;
1256 struct VolumeStatus *status;
1257 char *offmsg, *input;
1260 SetDotDefault(&as->parms[0].items);
1261 for (ti = as->parms[0].items; ti; ti = ti->next) {
1263 blob.out_size = MAXSIZE;
1264 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1267 status = (VolumeStatus *) space;
1268 status->MinQuota = status->MaxQuota = -1;
1270 if (as->parms[1].items) {
1271 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1273 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1278 if (as->parms[2].items)
1279 offmsg = as->parms[2].items->data;
1280 input = (char *)status + sizeof(*status);
1281 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1283 if (strlen(offmsg) >= VMSGSIZE) {
1285 "%s: message must be shorter than %d characters\n",
1290 strcpy(input, offmsg);
1291 blob.in_size += strlen(offmsg);
1292 input += strlen(offmsg) + 1;
1295 *(input++) = '\0'; /* Pad for old style volume "motd" */
1296 code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1);
1298 Die(errno, ti->data);
1306 ExamineCmd(struct cmd_syndesc *as)
1309 struct ViceIoctl blob;
1310 struct cmd_item *ti;
1311 struct VolumeStatus *status;
1312 char *name, *offmsg;
1315 SetDotDefault(&as->parms[0].items);
1316 for (ti = as->parms[0].items; ti; ti = ti->next) {
1318 blob.out_size = MAXSIZE;
1321 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1323 Die(errno, ti->data);
1327 status = (VolumeStatus *) space;
1328 name = (char *)status + sizeof(*status);
1329 offmsg = name + strlen(name) + 1;
1330 PrintStatus(status, name, offmsg);
1336 ListQuotaCmd(struct cmd_syndesc *as)
1339 struct ViceIoctl blob;
1340 struct cmd_item *ti;
1341 struct VolumeStatus *status;
1345 printf("%-25s%-10s%-10s%-7s%-11s\n", "Volume Name", " Quota",
1346 " Used", " %Used", " Partition");
1347 SetDotDefault(&as->parms[0].items);
1348 for (ti = as->parms[0].items; ti; ti = ti->next) {
1350 blob.out_size = MAXSIZE;
1353 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1355 Die(errno, ti->data);
1359 status = (VolumeStatus *) space;
1360 name = (char *)status + sizeof(*status);
1361 QuickPrintStatus(status, name);
1367 WhereIsCmd(struct cmd_syndesc *as)
1370 struct ViceIoctl blob;
1371 struct cmd_item *ti;
1377 SetDotDefault(&as->parms[0].items);
1378 for (ti = as->parms[0].items; ti; ti = ti->next) {
1380 blob.out_size = MAXSIZE;
1383 memset(space, 0, sizeof(space));
1384 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1386 Die(errno, ti->data);
1390 hosts = (afs_int32 *) space;
1391 printf("File %s is on host%s ", ti->data,
1392 (hosts[0] && !hosts[1]) ? "" : "s");
1393 for (j = 0; j < MAXHOSTS; j++) {
1396 tp = hostutil_GetNameByINet(hosts[j]);
1406 DiskFreeCmd(struct cmd_syndesc *as)
1409 struct ViceIoctl blob;
1410 struct cmd_item *ti;
1412 struct VolumeStatus *status;
1415 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1416 " used", " avail", " %used");
1417 SetDotDefault(&as->parms[0].items);
1418 for (ti = as->parms[0].items; ti; ti = ti->next) {
1420 blob.out_size = MAXSIZE;
1423 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1425 Die(errno, ti->data);
1429 status = (VolumeStatus *) space;
1430 name = (char *)status + sizeof(*status);
1431 QuickPrintSpace(status, name);
1437 QuotaCmd(struct cmd_syndesc *as)
1440 struct ViceIoctl blob;
1441 struct cmd_item *ti;
1443 struct VolumeStatus *status;
1446 SetDotDefault(&as->parms[0].items);
1447 for (ti = as->parms[0].items; ti; ti = ti->next) {
1449 blob.out_size = MAXSIZE;
1452 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1454 Die(errno, ti->data);
1458 status = (VolumeStatus *) space;
1459 if (status->MaxQuota)
1461 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
1464 printf("%2.0f%% of quota used.\n", quotaPct);
1470 ListMountCmd(struct cmd_syndesc *as)
1473 struct ViceIoctl blob;
1474 struct cmd_item *ti;
1475 char orig_name[1024]; /*Original name, may be modified */
1476 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
1477 char parent_dir[1024]; /*Parent directory of true name */
1478 char *last_component; /*Last component of true name */
1479 struct stat statbuff; /*Buffer for status info */
1480 int link_chars_read; /*Num chars read in readlink() */
1481 int thru_symlink; /*Did we get to a mount point via a symlink? */
1484 for (ti = as->parms[0].items; ti; ti = ti->next) {
1487 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
1490 if (lstat(orig_name, &statbuff) < 0) {
1491 /* if lstat fails, we should still try the pioctl, since it
1492 * may work (for example, lstat will fail, but pioctl will
1493 * work if the volume of offline (returning ENODEV). */
1494 statbuff.st_mode = S_IFDIR; /* lie like pros */
1498 * The lstat succeeded. If the given file is a symlink, substitute
1499 * the file name with the link name.
1501 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1504 * Read name of resolved file.
1506 link_chars_read = readlink(orig_name, true_name, 1024);
1507 if (link_chars_read <= 0) {
1509 "%s: Can't read target name for '%s' symbolic link!\n",
1516 * Add a trailing null to what was read, bump the length.
1518 true_name[link_chars_read++] = 0;
1521 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1522 * have to create a full pathname using the original name and the
1523 * relative symlink name. Find the rightmost slash in the original
1524 * name (we know there is one) and splice in the symlink value.
1526 if (true_name[0] != '/') {
1527 last_component = (char *)strrchr(orig_name, '/');
1528 strcpy(++last_component, true_name);
1529 strcpy(true_name, orig_name);
1532 strcpy(true_name, orig_name);
1535 * Find rightmost slash, if any.
1537 last_component = (char *)strrchr(true_name, '/');
1538 if (last_component) {
1540 * Found it. Designate everything before it as the parent directory,
1541 * everything after it as the final component.
1543 strncpy(parent_dir, true_name, last_component - true_name);
1544 parent_dir[last_component - true_name] = 0;
1545 last_component++; /*Skip the slash */
1548 * No slash appears in the given file name. Set parent_dir to the current
1549 * directory, and the last component as the given name.
1551 strcpy(parent_dir, ".");
1552 last_component = true_name;
1555 if (strcmp(last_component, ".") == 0
1556 || strcmp(last_component, "..") == 0) {
1558 "%s: you may not use '.' or '..' as the last component\n",
1560 fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n",
1566 blob.in = last_component;
1567 blob.in_size = strlen(last_component) + 1;
1568 blob.out_size = MAXSIZE;
1570 memset(space, 0, MAXSIZE);
1572 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1575 printf("'%s' is a %smount point for volume '%s'\n", ti->data,
1576 (thru_symlink ? "symbolic link, leading to a " : ""),
1579 if (errno == EINVAL) {
1580 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
1582 Die(errno, (ti->data ? ti->data : parent_dir));
1591 MakeMountCmd(struct cmd_syndesc *as)
1594 char *cellName, *volName, *tmpName;
1595 struct afsconf_cell info;
1596 struct vldbentry vldbEntry;
1597 struct ViceIoctl blob;
1603 if (as->parms[5].items && !as->parms[2].items) {
1604 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1609 if (as->parms[2].items) /* cell name specified */
1610 cellName = as->parms[2].items->data;
1613 volName = as->parms[1].items->data;
1615 if (strlen(volName) >= 64) {
1617 "%s: volume name too long (length must be < 64 characters)\n",
1622 /* Check for a cellname in the volume specification, and complain
1623 * if it doesn't match what was specified with -cell */
1624 if (tmpName = strchr(volName, ':')) {
1627 if (strcasecmp(cellName, volName)) {
1628 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1633 volName = ++tmpName;
1636 if (!InAFS(Parent(as->parms[0].items->data))) {
1638 "%s: mount points must be created within the AFS file system\n",
1645 blob.out_size = MAXSIZE;
1648 pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME,
1652 code = GetCellName(cellName ? cellName : space, &info);
1656 if (!(as->parms[4].items)) {
1657 /* not fast, check which cell the mountpoint is being created in */
1658 /* not fast, check name with VLDB */
1659 code = VLDBInit(1, &info);
1661 /* make the check. Don't complain if there are problems with init */
1663 ubik_Call(VL_GetEntryByNameO, uclient, 0, volName,
1665 if (code == VL_NOENT) {
1667 "%s: warning, volume %s does not exist in cell %s.\n",
1668 pn, volName, cellName ? cellName : space);
1673 if (as->parms[3].items) /* if -rw specified */
1678 /* cellular mount point, prepend cell prefix */
1679 strcat(space, info.name);
1682 strcat(space, volName); /* append volume name */
1683 strcat(space, "."); /* stupid convention; these end with a period */
1684 code = symlink(space, as->parms[0].items->data);
1686 Die(errno, as->parms[0].items->data);
1693 * Delete AFS mount points. Variables are used as follows:
1694 * tbuffer: Set to point to the null-terminated directory name of the mount point
1695 * (or ``.'' if none is provided)
1696 * tp: Set to point to the actual name of the mount point to nuke.
1699 RemoveMountCmd(struct cmd_syndesc *as)
1702 struct ViceIoctl blob;
1703 struct cmd_item *ti;
1705 char lsbuffer[1024];
1709 for (ti = as->parms[0].items; ti; ti = ti->next) {
1711 tp = (char *)strrchr(ti->data, '/');
1713 strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */
1715 tp++; /* skip the slash */
1717 strcpy(tbuffer, ".");
1721 blob.in_size = strlen(tp) + 1;
1722 blob.out = lsbuffer;
1723 blob.out_size = sizeof(lsbuffer);
1724 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1726 if (errno == EINVAL) {
1727 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
1730 Die(errno, ti->data);
1733 continue; /* don't bother trying */
1737 blob.in_size = strlen(tp) + 1;
1738 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1740 Die(errno, ti->data);
1751 CheckServersCmd(struct cmd_syndesc *as)
1754 struct ViceIoctl blob;
1760 struct afsconf_cell info;
1761 struct chservinfo checkserv;
1763 memset(&checkserv, 0, sizeof(struct chservinfo));
1764 blob.in_size = sizeof(struct chservinfo);
1765 blob.in = (caddr_t) & checkserv;
1767 blob.out_size = MAXSIZE;
1769 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1771 /* prepare flags for checkservers command */
1772 temp = 2; /* default to checking local cell only */
1773 if (as->parms[2].items)
1774 temp |= 1; /* set fast flag */
1775 if (as->parms[1].items)
1776 temp &= ~2; /* turn off local cell check */
1778 checkserv.magic = 0x12345678; /* XXX */
1779 checkserv.tflags = temp;
1781 /* now copy in optional cell name, if specified */
1782 if (as->parms[0].items) {
1783 code = GetCellName(as->parms[0].items->data, &info);
1787 strcpy(checkserv.tbuffer, info.name);
1788 checkserv.tsize = strlen(info.name) + 1;
1790 strcpy(checkserv.tbuffer, "\0");
1791 checkserv.tsize = 0;
1794 if (as->parms[3].items) {
1795 checkserv.tinterval = atol(as->parms[3].items->data);
1798 if (checkserv.tinterval < 0) {
1800 ("Warning: The negative -interval is ignored; treated as an inquiry\n");
1801 checkserv.tinterval = 0;
1802 } else if (checkserv.tinterval > 600) {
1804 ("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1805 checkserv.tinterval = 600; /* 10 min max interval */
1808 checkserv.tinterval = -1; /* don't change current interval */
1811 code = pioctl(0, VIOCCKSERV, &blob, 1);
1813 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1814 printf("Must be root to change -interval\n");
1820 memcpy(&temp, space, sizeof(afs_int32));
1821 if (checkserv.tinterval >= 0) {
1822 if (checkserv.tinterval > 0)
1824 ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1825 checkserv.tinterval, temp);
1827 printf("The current down server probe interval is %d secs\n",
1832 printf("All servers are running.\n");
1835 ("These servers unavailable due to network or server problems: ");
1837 memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32));
1840 tp = hostutil_GetNameByINet(temp);
1850 MessagesCmd(struct cmd_syndesc *as)
1853 struct ViceIoctl blob;
1856 struct gaginfo gagflags;
1857 struct cmd_item *show;
1859 memset(&gagflags, 0, sizeof(struct gaginfo));
1860 blob.in_size = sizeof(struct gaginfo);
1861 blob.in = (caddr_t) & gagflags;
1862 blob.out_size = MAXSIZE;
1864 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1866 if (show = as->parms[0].items) {
1867 if (!strcasecmp(show->data, "user"))
1868 gagflags.showflags |= GAGUSER;
1869 else if (!strcasecmp(show->data, "console"))
1870 gagflags.showflags |= GAGCONSOLE;
1871 else if (!strcasecmp(show->data, "all"))
1872 gagflags.showflags |= GAGCONSOLE | GAGUSER;
1873 else if (!strcasecmp(show->data, "none"))
1877 "unrecognized flag %s: must be in {user,console,all,none}\n",
1886 code = pioctl(0, VIOC_GAG, &blob, 1);
1896 CheckVolumesCmd(struct cmd_syndesc *as)
1899 struct ViceIoctl blob;
1903 code = pioctl(0, VIOCCKBACK, &blob, 1);
1909 printf("All volumeID/name mappings checked.\n");
1914 SetCacheSizeCmd(struct cmd_syndesc *as)
1917 struct ViceIoctl blob;
1920 if (!as->parms[0].items && !as->parms[1].items) {
1921 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
1924 if (as->parms[0].items) {
1925 code = util_GetInt32(as->parms[0].items->data, &temp);
1927 fprintf(stderr, "%s: bad integer specified for cache size.\n",
1933 blob.in = (char *)&temp;
1934 blob.in_size = sizeof(afs_int32);
1936 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
1938 if (errno == EROFS) {
1940 ("'fs setcache' not allowed on memory cache based cache managers.\n");
1947 printf("New cache size set.\n");
1951 #define MAXGCSIZE 16
1953 GetCacheParmsCmd(struct cmd_syndesc *as)
1956 struct ViceIoctl blob;
1957 afs_int32 parms[MAXGCSIZE];
1959 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
1962 blob.out_size = sizeof(parms);
1963 blob.out = (char *)parms;
1964 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
1969 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
1970 parms[1], parms[0]);
1971 if (parms[1] > parms[0])
1973 ("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
1978 ListCellsCmd(struct cmd_syndesc *as)
1984 struct ViceIoctl blob;
1987 resolve = !(as->parms[0].items); /* -numeric */
1991 memcpy(tp, &i, sizeof(afs_int32));
1992 blob.out_size = MAXSIZE;
1993 blob.in_size = sizeof(afs_int32);
1996 code = pioctl(0, VIOCGETCELL, &blob, 1);
1999 break; /* done with the list */
2004 printf("Cell %s on hosts", tp + MAXCELLHOSTS * sizeof(afs_int32));
2005 for (j = 0; j < MAXCELLHOSTS; j++) {
2007 char *name, tbuffer[20];
2009 memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32));
2014 name = hostutil_GetNameByINet(addr);
2017 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2018 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2021 printf(" %s", name);
2029 ListAliasesCmd(struct cmd_syndesc *as)
2032 char *tp, *aliasName, *realName;
2033 struct ViceIoctl blob;
2037 memcpy(tp, &i, sizeof(afs_int32));
2038 blob.out_size = MAXSIZE;
2039 blob.in_size = sizeof(afs_int32);
2042 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2045 break; /* done with the list */
2051 tp += strlen(aliasName) + 1;
2053 printf("Alias %s for cell %s\n", aliasName, realName);
2059 NewCellCmd(struct cmd_syndesc *as)
2061 afs_int32 code, linkedstate = 0, size = 0, *lp;
2062 struct ViceIoctl blob;
2063 struct cmd_item *ti;
2064 char *tp, *cellname = 0;
2065 struct hostent *thp;
2066 afs_int32 fsport = 0, vlport = 0;
2067 afs_int32 magic, scount; /* Number of servers to pass in pioctl call */
2070 * With the NEWCELL pioctl call, 3.4 clients take an array of
2071 * MAXHOSTS (13) servers while 3.5 clients take an array of
2072 * MAXCELLHOSTS (8) servers. To determine which we are talking to,
2073 * do a GETCELL pioctl and pass it a magic number. If an array of
2074 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
2075 * If we get back EDOM, there are no cells in the kernel yet,
2076 * and we'll assume a 3.5 client.
2079 lp = (afs_int32 *) tp;
2080 *lp++ = 0; /* first cell entry */
2081 *lp = 0x12345678; /* magic */
2082 blob.out_size = MAXSIZE;
2083 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
2086 code = pioctl(0, VIOCGETCELL, &blob, 1);
2087 if (code < 0 && errno != EDOM) {
2091 if (code < 1 && errno == EDOM) {
2095 cellname = tp + MAXCELLHOSTS * sizeof(afs_int32);
2096 scount = ((cellname[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2099 /* Now setup and do the NEWCELL pioctl call */
2100 memset(space, 0, (scount + 1) * sizeof(afs_int32));
2102 lp = (afs_int32 *) tp;
2104 tp += sizeof(afs_int32);
2105 for (ti = as->parms[1].items; ti; ti = ti->next) {
2106 thp = hostutil_GetHostByName(ti->data);
2109 "%s: Host %s not found in host table, skipping it.\n", pn,
2112 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2113 tp += sizeof(afs_int32);
2116 if (as->parms[2].items) {
2118 * Link the cell, for the purposes of volume location, to the specified
2121 cellname = as->parms[2].items->data;
2124 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2125 if (as->parms[3].items) {
2126 code = util_GetInt32(as->parms[3].items->data, &vlport);
2129 "%s: bad integer specified for the fileserver port.\n",
2134 if (as->parms[4].items) {
2135 code = util_GetInt32(as->parms[4].items->data, &fsport);
2138 "%s: bad integer specified for the vldb server port.\n",
2144 tp = (char *)(space + (scount + 1) * sizeof(afs_int32));
2145 lp = (afs_int32 *) tp;
2149 strcpy(space + ((scount + 4) * sizeof(afs_int32)),
2150 as->parms[0].items->data);
2151 size = ((scount + 4) * sizeof(afs_int32))
2152 + strlen(as->parms[0].items->data)
2153 + 1 /* for null */ ;
2154 tp = (char *)(space + size);
2156 strcpy(tp, cellname);
2157 size += strlen(cellname) + 1;
2159 blob.in_size = size;
2162 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2171 NewAliasCmd(struct cmd_syndesc *as)
2174 struct ViceIoctl blob;
2176 char *aliasName, *realName;
2178 /* Now setup and do the NEWCELL pioctl call */
2179 aliasName = as->parms[0].items->data;
2180 realName = as->parms[1].items->data;
2182 strcpy(tp, aliasName);
2183 tp += strlen(aliasName) + 1;
2184 strcpy(tp, realName);
2185 tp += strlen(realName) + 1;
2187 blob.in_size = tp - space;
2191 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2193 if (errno == EEXIST) {
2195 "%s: cell name `%s' in use by an existing cell.\n", pn,
2206 WhichCellCmd(struct cmd_syndesc *as)
2209 struct cmd_item *ti;
2211 char cell[MAXCELLCHARS];
2213 SetDotDefault(&as->parms[0].items);
2214 for (ti = as->parms[0].items; ti; ti = ti->next) {
2215 code = GetCell(ti->data, cell);
2217 if (errno == ENOENT)
2218 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
2220 Die(errno, ti->data);
2225 printf("File %s lives in cell '%s'\n", ti->data, cell);
2231 WSCellCmd(struct cmd_syndesc *as)
2234 struct ViceIoctl blob;
2238 blob.out_size = MAXSIZE;
2241 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2247 printf("This workstation belongs to cell '%s'\n", space);
2252 static PrimaryCellCmd(as)
2253 struct cmd_syndesc *as;
2255 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2261 MonitorCmd(struct cmd_syndesc *as)
2264 struct ViceIoctl blob;
2265 struct cmd_item *ti;
2267 struct hostent *thp;
2271 ti = as->parms[0].items;
2275 if (!strcmp(ti->data, "off"))
2276 hostAddr = 0xffffffff;
2278 thp = hostutil_GetHostByName(ti->data);
2280 if (!strcmp(ti->data, "localhost")) {
2282 "localhost not in host table, assuming 127.0.0.1\n");
2283 hostAddr = htonl(0x7f000001);
2285 fprintf(stderr, "host %s not found in host table.\n",
2290 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2293 hostAddr = 0; /* means don't set host */
2294 setp = 0; /* aren't setting host */
2297 /* now do operation */
2298 blob.in_size = sizeof(afs_int32);
2299 blob.out_size = sizeof(afs_int32);
2300 blob.in = (char *)&hostAddr;
2301 blob.out = (char *)&hostAddr;
2302 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2308 printf("%s: new monitor host set.\n", pn);
2310 /* now decode old address */
2311 if (hostAddr == 0xffffffff) {
2312 printf("Cache monitoring is currently disabled.\n");
2314 tp = hostutil_GetNameByINet(hostAddr);
2315 printf("Using host %s for monitor services.\n", tp);
2322 SysNameCmd(struct cmd_syndesc *as)
2325 struct ViceIoctl blob;
2326 struct cmd_item *ti;
2327 char *input = space;
2330 ti = as->parms[0].items;
2333 blob.out_size = MAXSIZE;
2334 blob.in_size = sizeof(afs_int32);
2335 input += sizeof(afs_int32);
2336 for (; ti; ti = ti->next) {
2338 blob.in_size += strlen(ti->data) + 1;
2339 if (blob.in_size > MAXSIZE) {
2340 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2341 setp > 1 ? "s" : "");
2344 strcpy(input, ti->data);
2345 input += strlen(ti->data);
2348 memcpy(space, &setp, sizeof(afs_int32));
2349 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2355 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2359 memcpy(&setp, input, sizeof(afs_int32));
2360 input += sizeof(afs_int32);
2362 fprintf(stderr, "No sysname name value was found\n");
2365 printf("Current sysname%s is", setp > 1 ? " list" : "");
2366 for (; setp > 0; --setp) {
2367 printf(" \'%s\'", input);
2368 input += strlen(input) + 1;
2374 static char *exported_types[] = { "null", "nfs", "" };
2376 ExportAfsCmd(struct cmd_syndesc *as)
2379 struct ViceIoctl blob;
2380 struct cmd_item *ti;
2381 int export = 0, type = 0, mode = 0, exp = 0, exportcall, pwsync =
2384 ti = as->parms[0].items;
2385 if (strcmp(ti->data, "nfs") == 0)
2386 type = 0x71; /* NFS */
2389 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n",
2393 ti = as->parms[1].items;
2395 if (strcmp(ti->data, "on") == 0)
2397 else if (strcmp(ti->data, "off") == 0)
2400 fprintf(stderr, "Illegal argument %s\n", ti->data);
2405 if (ti = as->parms[2].items) { /* -noconvert */
2406 if (strcmp(ti->data, "on") == 0)
2408 else if (strcmp(ti->data, "off") == 0)
2411 fprintf(stderr, "Illegal argument %s\n", ti->data);
2415 if (ti = as->parms[3].items) { /* -uidcheck */
2416 if (strcmp(ti->data, "on") == 0)
2418 else if (strcmp(ti->data, "off") == 0)
2421 fprintf(stderr, "Illegal argument %s\n", ti->data);
2425 if (ti = as->parms[4].items) { /* -submounts */
2426 if (strcmp(ti->data, "on") == 0)
2428 else if (strcmp(ti->data, "off") == 0)
2431 fprintf(stderr, "Illegal argument %s\n", ti->data);
2436 (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2439 blob.in = (char *)&exportcall;
2440 blob.in_size = sizeof(afs_int32);
2441 blob.out = (char *)&exportcall;
2442 blob.out_size = sizeof(afs_int32);
2443 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2445 if (errno == ENODEV) {
2447 "Sorry, the %s-exporter type is currently not supported on this AFS client\n",
2448 exported_types[type]);
2455 if (exportcall & 1) {
2456 printf("'%s' translator is enabled with the following options:\n",
2457 exported_types[type]);
2458 printf("\tRunning in %s mode\n",
2459 (exportcall & 2 ? "strict unix" :
2460 "convert owner mode bits to world/other"));
2461 printf("\tRunning in %s mode\n",
2462 (exportcall & 4 ? "strict 'passwd sync'" :
2463 "no 'passwd sync'"));
2465 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
2466 "Only mounts to /afs allowed"));
2468 printf("'%s' translator is disabled\n", exported_types[type]);
2475 GetCellCmd(struct cmd_syndesc *as)
2478 struct ViceIoctl blob;
2479 struct afsconf_cell info;
2480 struct cmd_item *ti;
2487 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2488 for (ti = as->parms[0].items; ti; ti = ti->next) {
2490 blob.out_size = sizeof(args);
2491 blob.out = (caddr_t) & args;
2492 code = GetCellName(ti->data, &info);
2497 blob.in_size = 1 + strlen(info.name);
2498 blob.in = info.name;
2499 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2501 if (errno == ENOENT)
2502 fprintf(stderr, "%s: the cell named '%s' does not exist\n",
2505 Die(errno, info.name);
2509 printf("Cell %s status: ", info.name);
2515 printf("no setuid allowed");
2517 printf("setuid allowed");
2519 printf(", using old VLDB");
2526 SetCellCmd(struct cmd_syndesc *as)
2529 struct ViceIoctl blob;
2530 struct afsconf_cell info;
2531 struct cmd_item *ti;
2539 /* Check arguments. */
2540 if (as->parms[1].items && as->parms[2].items) {
2541 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2545 /* figure stuff to set */
2549 if (!as->parms[1].items)
2550 args.stat |= 2; /* default to -nosuid */
2552 /* set stat for all listed cells */
2553 for (ti = as->parms[0].items; ti; ti = ti->next) {
2555 code = GetCellName(ti->data, &info);
2560 strcpy(args.cname, info.name);
2561 blob.in_size = sizeof(args);
2562 blob.in = (caddr_t) & args;
2564 blob.out = (caddr_t) 0;
2565 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2567 Die(errno, info.name); /* XXX added cell name to Die() call */
2575 GetCellName(char *cellName, struct afsconf_cell *info)
2577 struct afsconf_dir *tdir;
2580 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2583 "Could not process files in configuration directory (%s).\n",
2584 AFSDIR_CLIENT_ETC_DIRPATH);
2588 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2590 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2591 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
2600 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
2603 struct ktc_principal sname;
2604 struct ktc_token ttoken;
2606 struct rx_securityClass *sc;
2607 struct rx_connection *serverconns[VLDB_MAXSERVERS];
2612 fprintf(stderr, "%s: could not initialize rx.\n", pn);
2616 rx_SetRxDeadTime(50);
2617 if (!noAuthFlag) { /* we don't need tickets for null */
2618 strcpy(sname.cell, info->name);
2619 sname.instance[0] = 0;
2620 strcpy(sname.name, "afs");
2621 code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL);
2624 "%s: Could not get afs tokens, running unauthenticated.\n",
2629 if (ttoken.kvno >= 0 && ttoken.kvno <= 255)
2630 scIndex = 2; /* kerberos */
2632 fprintf(stderr, "%s: funny kvno (%d) in ticket, proceeding\n",
2638 scIndex = 0; /* don't authenticate */
2641 sc = rxnull_NewClientSecurityObject();
2647 sc = (struct rx_securityClass *)
2648 rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
2649 ttoken.kvno, ttoken.ticketLen,
2653 if (info->numServers > VLDB_MAXSERVERS) {
2654 fprintf(stderr, "%s: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n", pn,
2655 info->numServers, VLDB_MAXSERVERS);
2658 memset(serverconns, 0, sizeof(serverconns));
2659 for (i = 0; i < info->numServers; i++)
2661 rx_NewConnection(info->hostAddr[i].sin_addr.s_addr,
2662 info->hostAddr[i].sin_port, USER_SERVICE_ID, sc,
2665 code = ubik_ClientInit(serverconns, &uclient);
2668 fprintf(stderr, "%s: ubik client init failed.\n", pn);
2674 static struct ViceIoctl gblob;
2675 static int debug = 0;
2677 * here follow some routines in suport of the setserverprefs and
2678 * getserverprefs commands. They are:
2679 * SetPrefCmd "top-level" routine
2680 * addServer adds a server to the list of servers to be poked into the
2681 * kernel. Will poke the list into the kernel if it threatens
2683 * pokeServers pokes the existing list of servers and ranks into the kernel
2684 * GetPrefCmd reads the Cache Manager's current list of server ranks
2688 * returns -1 if error message printed,
2690 * errno value if error and no error message printed
2697 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2698 if (code && (errno == EINVAL)) {
2699 struct setspref *ssp;
2700 ssp = (struct setspref *)gblob.in;
2701 if (!(ssp->flags & DBservers)) {
2702 gblob.in = (void *)&(ssp->servers[0]);
2703 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
2704 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
2705 return code ? errno : 0;
2708 "This cache manager does not support VL server preferences.\n");
2712 return code ? errno : 0;
2716 * returns -1 if error message printed,
2718 * errno value if error and no error message printed
2721 addServer(char *name, afs_int32 rank)
2724 struct setspref *ssp;
2726 struct hostent *thostent;
2732 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
2734 #define MAXUSHORT ((unsigned short) ~0)
2738 thostent = hostutil_GetHostByName(name);
2740 fprintf(stderr, "%s: couldn't resolve name.\n", name);
2744 ssp = (struct setspref *)(gblob.in);
2746 for (t = 0; thostent->h_addr_list[t]; t++) {
2747 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
2748 code = pokeServers();
2751 ssp->num_servers = 0;
2754 sp = (struct spref *)(gblob.in + gblob.in_size);
2755 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
2756 sizeof(afs_uint32));
2757 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
2758 gblob.in_size += sizeof(struct spref);
2762 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
2763 name, sp->rank, sp->server.s_addr);
2771 SetPrefCmd(struct cmd_syndesc *as)
2775 struct cmd_item *ti;
2778 struct setspref *ssp;
2779 int error = 0; /* -1 means error message printed,
2780 * >0 means errno value for unprinted message */
2782 ssp = (struct setspref *)space;
2784 ssp->num_servers = 0;
2785 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
2788 gblob.out_size = MAXSIZE;
2792 fprintf(stderr, "Permission denied: requires root access.\n");
2796 ti = as->parms[2].items; /* -file */
2799 fprintf(stderr, "opening file %s\n", ti->data);
2800 if (!(infd = fopen(ti->data, "r"))) {
2804 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
2805 code = addServer(name, (unsigned short)rank);
2812 ti = as->parms[3].items; /* -stdin */
2814 while (scanf("%79s%ld", name, &rank) != EOF) {
2815 code = addServer(name, (unsigned short)rank);
2821 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
2826 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
2830 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
2834 code = pokeServers();
2838 printf("now working on vlservers, code=%d\n", code);
2840 ssp = (struct setspref *)space;
2841 ssp->flags = DBservers;
2842 ssp->num_servers = 0;
2843 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
2846 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
2851 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
2855 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
2860 if (as->parms[1].items) {
2862 printf("now poking vlservers\n");
2863 code = pokeServers();
2871 return error ? 1 : 0;
2877 GetPrefCmd(struct cmd_syndesc *as)
2880 struct cmd_item *ti;
2881 char *name, tbuffer[20];
2882 afs_int32 rank, addr;
2886 struct ViceIoctl blob;
2887 struct sprefrequest *in;
2888 struct sprefinfo *out;
2891 ti = as->parms[0].items; /* -file */
2894 fprintf(stderr, "opening file %s\n", ti->data);
2895 if (!(outfd = freopen(ti->data, "w", stdout))) {
2901 ti = as->parms[1].items; /* -numeric */
2903 ti = as->parms[2].items; /* -vlservers */
2904 vlservers |= (ti ? DBservers : 0);
2905 /* ti = as->parms[3].items; -cell */
2907 in = (struct sprefrequest *)space;
2911 blob.in_size = sizeof(struct sprefrequest);
2912 blob.in = (char *)in;
2914 blob.out_size = MAXSIZE;
2917 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
2918 in->flags = vlservers;
2920 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
2922 perror("getserverprefs pioctl");
2926 out = (struct sprefinfo *)blob.out;
2928 for (i = 0; i < out->num_servers; i++) {
2930 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
2932 addr = ntohl(out->servers[i].server.s_addr);
2933 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2934 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2937 printf("%-50s %5u\n", name, out->servers[i].rank);
2940 in->offset = out->next_offset;
2941 } while (out->next_offset > 0);
2947 StoreBehindCmd(struct cmd_syndesc *as)
2950 struct ViceIoctl blob;
2951 struct cmd_item *ti;
2952 struct sbstruct tsb, tsb2;
2958 tsb.sb_thisfile = -1;
2959 ti = as->parms[0].items; /* -kbytes */
2961 if (!as->parms[1].items) {
2962 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
2966 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
2967 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
2968 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
2974 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
2975 ti = as->parms[2].items; /* -allfiles */
2977 allfiles = strtol(ti->data, &t, 10) * 1024;
2978 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
2979 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
2985 /* -verbose or -file only or no options */
2986 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
2987 || (!as->parms[0].items && !as->parms[1].items
2988 && !as->parms[2].items))
2991 blob.in = (char *)&tsb;
2992 blob.out = (char *)&tsb2;
2993 blob.in_size = blob.out_size = sizeof(struct sbstruct);
2994 memset(&tsb2, 0, sizeof(tsb2));
2996 /* once per -file */
2997 for (ti = as->parms[1].items; ti; ti = ti->next) {
2998 /* Do this solely to see if the file is there */
2999 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3001 Die(errno, ti->data);
3006 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
3008 Die(errno, ti->data);
3013 if (verbose && (blob.out_size == sizeof(tsb2))) {
3014 if (tsb2.sb_thisfile == -1) {
3015 fprintf(stdout, "Will store %s according to default.\n",
3019 "Will store up to %d kbytes of %s asynchronously.\n",
3020 (tsb2.sb_thisfile / 1024), ti->data);
3025 /* If no files - make at least one pioctl call, or
3026 * set the allfiles default if we need to.
3028 if (!as->parms[1].items || (allfiles != -1)) {
3029 tsb.sb_default = allfiles;
3030 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
3032 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3037 /* Having no arguments also reports the default store asynchrony */
3038 if (verbose && (blob.out_size == sizeof(tsb2))) {
3039 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3040 (tsb2.sb_default / 1024));
3048 SetCryptCmd(struct cmd_syndesc *as)
3050 afs_int32 code = 0, flag;
3051 struct ViceIoctl blob;
3054 tp = as->parms[0].items->data;
3055 if (strcmp(tp, "on") == 0)
3057 else if (strcmp(tp, "off") == 0)
3060 fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3064 blob.in = (char *)&flag;
3065 blob.in_size = sizeof(flag);
3067 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3075 GetCryptCmd(struct cmd_syndesc *as)
3077 afs_int32 code = 0, flag;
3078 struct ViceIoctl blob;
3083 blob.out_size = sizeof(flag);
3086 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3092 memcpy(&flag, tp, sizeof(afs_int32));
3093 printf("Security level is currently ");
3095 printf("crypt (data security).\n");
3102 #include "AFS_component_version_number.c"
3105 main(int argc, char **argv)
3108 struct cmd_syndesc *ts;
3110 #ifdef AFS_AIX32_ENV
3112 * The following signal action for AIX is necessary so that in case of a
3113 * crash (i.e. core is generated) we can include the user's data section
3114 * in the core dump. Unfortunately, by default, only a partial core is
3115 * generated which, in many cases, isn't too useful.
3117 struct sigaction nsa;
3119 sigemptyset(&nsa.sa_mask);
3120 nsa.sa_handler = SIG_DFL;
3121 nsa.sa_flags = SA_FULLDUMP;
3122 sigaction(SIGSEGV, &nsa, NULL);
3125 /* try to find volume location information */
3126 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, 0,
3127 "get client network interface addresses");
3128 cmd_CreateAlias(ts, "gc");
3130 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, 0,
3131 "set client network interface addresses");
3132 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3133 "client network interfaces");
3134 cmd_CreateAlias(ts, "sc");
3136 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0,
3137 "set server ranks");
3138 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3139 "fileserver names and ranks");
3140 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3141 "VL server names and ranks");
3142 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3143 "input from named file");
3144 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3145 cmd_CreateAlias(ts, "sp");
3147 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0,
3148 "get server ranks");
3149 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3150 "output to named file");
3151 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3152 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3153 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3154 cmd_CreateAlias(ts, "gp");
3156 ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list");
3157 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3158 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3159 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3160 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL,
3161 "apply to negative rights");
3162 parm_setacl_id = ts->nParms;
3163 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL,
3164 "initial directory acl (DFS only)");
3165 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL,
3166 "initial file acl (DFS only)");
3167 cmd_CreateAlias(ts, "sa");
3169 ts = cmd_CreateSyntax("listacl", ListACLCmd, 0,
3170 "list access control list");
3171 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3172 parm_listacl_id = ts->nParms;
3173 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3174 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3175 cmd_CreateAlias(ts, "la");
3177 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0,
3178 "clean up access control list");
3179 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3181 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0,
3182 "copy access control list");
3183 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0,
3184 "source directory (or DFS file)");
3185 cmd_AddParm(ts, "-todir", CMD_LIST, 0,
3186 "destination directory (or DFS file)");
3187 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3188 "first clear dest access list");
3189 parm_copyacl_id = ts->nParms;
3190 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3191 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3193 cmd_CreateAlias(ts, "ca");
3195 ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache");
3196 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3197 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, 0,
3198 "flush mount symlink from cache");
3199 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3201 ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status");
3202 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3203 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL,
3204 "disk space quota in 1K units");
3206 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL,
3207 "disk space guaranteed");
3208 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3210 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL,
3212 cmd_CreateAlias(ts, "sv");
3214 ts = cmd_CreateSyntax("messages", MessagesCmd, 0,
3215 "control Cache Manager messages");
3216 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL,
3217 "[user|console|all|none]");
3219 ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display volume status");
3220 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3221 cmd_CreateAlias(ts, "lv");
3222 cmd_CreateAlias(ts, "listvol");
3224 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota");
3225 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3226 cmd_CreateAlias(ts, "lq");
3228 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0,
3229 "show server disk space usage");
3230 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3231 cmd_CreateAlias(ts, "df");
3233 ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage");
3234 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3236 ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point");
3237 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3239 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point");
3240 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3241 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3242 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3243 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3244 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3245 "don't check name with VLDB");
3251 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3255 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point");
3256 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3258 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0,
3259 "check local cell's servers");
3260 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3261 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3262 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3263 "just list, don't check");
3264 cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL,
3265 "seconds between probes");
3267 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, 0,
3268 "check volumeID/name mappings");
3269 cmd_CreateAlias(ts, "checkbackups");
3272 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0,
3274 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3275 "size in 1K byte blocks (0 => reset)");
3276 cmd_CreateAlias(ts, "cachesize");
3278 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL,
3279 "reset size back to boot value");
3281 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0,
3282 "get cache usage info");
3284 ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0,
3285 "list configured cells");
3286 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3288 ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, 0,
3289 "list configured cell aliases");
3291 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota");
3292 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3293 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3295 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3297 cmd_CreateAlias(ts, "sq");
3299 ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell");
3300 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3301 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3302 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL,
3303 "linked cell name");
3305 ts = cmd_CreateSyntax("newalias", NewAliasCmd, 0,
3306 "configure new cell alias");
3307 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
3308 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
3310 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3312 * Turn this on only if you wish to be able to talk to a server which is listening
3313 * on alternative ports. This is not intended for general use and may not be
3314 * supported in the cache manager. It is not a way to run two servers at the
3315 * same host, since the cache manager cannot properly distinguish those two hosts.
3317 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL,
3318 "cell's fileserver port");
3319 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL,
3320 "cell's vldb server port");
3323 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell");
3324 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3326 ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location");
3327 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3329 ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell");
3332 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
3335 /* set cache monitor host address */
3336 ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, (char *)CMD_HIDDEN);
3337 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL,
3338 "host name or 'off'");
3339 cmd_CreateAlias(ts, "mariner");
3341 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status");
3342 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3344 ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status");
3345 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3346 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3347 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL,
3348 "disallow setuid programs");
3350 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0,
3351 "flush all data in volume");
3352 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3354 ts = cmd_CreateSyntax("sysname", SysNameCmd, 0,
3355 "get/set sysname (i.e. @sys) value");
3356 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3358 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0,
3359 "enable/disable translators to AFS");
3360 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3361 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL,
3362 "start/stop translator (on | off)");
3363 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL,
3364 "convert from afs to unix mode (on | off)");
3365 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL,
3366 "run on strict 'uid check' mode (on | off)");
3367 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
3368 "allow nfs mounts to subdirs of /afs/.. (on | off)");
3371 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0,
3372 "store to server after file close");
3373 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL,
3374 "asynchrony for specified names");
3375 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3376 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL,
3377 "new default (KB)");
3378 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3379 cmd_CreateAlias(ts, "sb");
3381 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0,
3382 "set cache manager encryption flag");
3383 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3385 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0,
3386 "set cache manager encryption flag");
3388 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, 0,
3389 "Manage per process RX statistics");
3390 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3391 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3392 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3394 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, 0,
3395 "Manage per peer RX statistics");
3396 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3397 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3398 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3400 code = cmd_Dispatch(argc, argv);
3408 Die(int errnum, char *filename)
3414 "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3417 fprintf(stderr, "%s: Invalid argument.\n", pn);
3421 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3423 fprintf(stderr, "%s: no such file returned\n", pn);
3427 "%s: You can not change a backup or readonly volume\n", pn);
3433 "%s: You don't have the required access rights on '%s'\n",
3437 "%s: You do not have the required rights to do this operation\n",
3442 fprintf(stderr, "%s:'%s'", pn, filename);
3444 fprintf(stderr, "%s", pn);
3445 fprintf(stderr, ": %s\n", error_message(errnum));
3450 /* get clients interface addresses */
3452 GetClientAddrsCmd(struct cmd_syndesc *as)
3455 struct cmd_item *ti;
3457 struct ViceIoctl blob;
3458 struct sprefrequest *in;
3459 struct sprefinfo *out;
3461 in = (struct sprefrequest *)space;
3465 blob.in_size = sizeof(struct sprefrequest);
3466 blob.in = (char *)in;
3468 blob.out_size = MAXSIZE;
3471 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3472 /* returns addr in network byte order */
3473 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3475 perror("getClientInterfaceAddr pioctl");
3481 out = (struct sprefinfo *)blob.out;
3482 for (i = 0; i < out->num_servers; i++) {
3485 addr = ntohl(out->servers[i].server.s_addr);
3486 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3487 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3488 printf("%-50s\n", tbuffer);
3490 in->offset = out->next_offset;
3492 } while (out->next_offset > 0);
3498 SetClientAddrsCmd(struct cmd_syndesc *as)
3500 afs_int32 code, addr;
3501 struct cmd_item *ti;
3503 struct ViceIoctl blob;
3504 struct setspref *ssp;
3505 int sizeUsed = 0, i, flag;
3506 afs_int32 existingAddr[1024]; /* existing addresses on this host */
3510 ssp = (struct setspref *)space;
3511 ssp->num_servers = 0;
3514 blob.out_size = MAXSIZE;
3517 fprintf(stderr, "Permission denied: requires root access.\n");
3521 /* extract all existing interface addresses */
3522 existNu = rx_getAllAddr(existingAddr, 1024);
3526 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
3527 for (ti = as->parms[0].items; ti; ti = ti->next) {
3528 if (sizeUsed >= sizeof(space)) {
3529 fprintf(stderr, "No more space\n");
3532 addr = extractAddr(ti->data, 20); /* network order */
3533 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
3534 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
3539 /* see if it is an address that really exists */
3540 for (flag = 0, i = 0; i < existNu; i++)
3541 if (existingAddr[i] == addr) {
3545 if (!flag) { /* this is an nonexistent address */
3546 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
3550 /* copy all specified addr into ioctl buffer */
3551 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
3552 printf("Adding 0x%08x\n", addr);
3554 sizeUsed += sizeof(struct spref);
3556 if (ssp->num_servers < 1) {
3557 fprintf(stderr, "No addresses specified\n");
3560 blob.in_size = sizeUsed - sizeof(struct spref);
3562 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
3572 FlushMountCmd(struct cmd_syndesc *as)
3575 struct ViceIoctl blob;
3576 struct cmd_item *ti;
3577 char orig_name[1024]; /*Original name, may be modified */
3578 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
3579 char parent_dir[1024]; /*Parent directory of true name */
3580 char *last_component; /*Last component of true name */
3581 struct stat statbuff; /*Buffer for status info */
3582 int link_chars_read; /*Num chars read in readlink() */
3583 int thru_symlink; /*Did we get to a mount point via a symlink? */
3586 for (ti = as->parms[0].items; ti; ti = ti->next) {
3589 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
3592 if (lstat(orig_name, &statbuff) < 0) {
3593 /* if lstat fails, we should still try the pioctl, since it
3594 * may work (for example, lstat will fail, but pioctl will
3595 * work if the volume of offline (returning ENODEV). */
3596 statbuff.st_mode = S_IFDIR; /* lie like pros */
3600 * The lstat succeeded. If the given file is a symlink, substitute
3601 * the file name with the link name.
3603 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
3606 * Read name of resolved file.
3608 link_chars_read = readlink(orig_name, true_name, 1024);
3609 if (link_chars_read <= 0) {
3611 "%s: Can't read target name for '%s' symbolic link!\n",
3618 * Add a trailing null to what was read, bump the length.
3620 true_name[link_chars_read++] = 0;
3623 * If the symlink is an absolute pathname, we're fine. Otherwise, we
3624 * have to create a full pathname using the original name and the
3625 * relative symlink name. Find the rightmost slash in the original
3626 * name (we know there is one) and splice in the symlink value.
3628 if (true_name[0] != '/') {
3629 last_component = (char *)strrchr(orig_name, '/');
3630 strcpy(++last_component, true_name);
3631 strcpy(true_name, orig_name);
3634 strcpy(true_name, orig_name);
3637 * Find rightmost slash, if any.
3639 last_component = (char *)strrchr(true_name, '/');
3640 if (last_component) {
3642 * Found it. Designate everything before it as the parent directory,
3643 * everything after it as the final component.
3645 strncpy(parent_dir, true_name, last_component - true_name);
3646 parent_dir[last_component - true_name] = 0;
3647 last_component++; /*Skip the slash */
3650 * No slash appears in the given file name. Set parent_dir to the current
3651 * directory, and the last component as the given name.
3653 strcpy(parent_dir, ".");
3654 last_component = true_name;
3657 if (strcmp(last_component, ".") == 0
3658 || strcmp(last_component, "..") == 0) {
3660 "%s: you may not use '.' or '..' as the last component\n",
3662 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
3668 blob.in = last_component;
3669 blob.in_size = strlen(last_component) + 1;
3671 memset(space, 0, MAXSIZE);
3673 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
3676 if (errno == EINVAL) {
3677 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
3679 Die(errno, (ti->data ? ti->data : parent_dir));
3688 RxStatProcCmd(struct cmd_syndesc *as)
3691 afs_int32 flags = 0;
3692 struct ViceIoctl blob;
3693 struct cmd_item *ti;
3695 if (as->parms[0].items) { /* -enable */
3696 flags |= AFSCALL_RXSTATS_ENABLE;
3698 if (as->parms[1].items) { /* -disable */
3699 flags |= AFSCALL_RXSTATS_DISABLE;
3701 if (as->parms[2].items) { /* -clear */
3702 flags |= AFSCALL_RXSTATS_CLEAR;
3705 fprintf(stderr, "You must specify at least one argument\n");
3709 blob.in = (char *)&flags;
3710 blob.in_size = sizeof(afs_int32);
3713 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
3723 RxStatPeerCmd(struct cmd_syndesc *as)
3726 afs_int32 flags = 0;
3727 struct ViceIoctl blob;
3728 struct cmd_item *ti;
3730 if (as->parms[0].items) { /* -enable */
3731 flags |= AFSCALL_RXSTATS_ENABLE;
3733 if (as->parms[1].items) { /* -disable */
3734 flags |= AFSCALL_RXSTATS_DISABLE;
3736 if (as->parms[2].items) { /* -clear */
3737 flags |= AFSCALL_RXSTATS_CLEAR;
3740 fprintf(stderr, "You must specify at least one argument\n");
3744 blob.in = (char *)&flags;
3745 blob.in_size = sizeof(afs_int32);
3748 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);