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>
14 #include <afs/afs_args.h>
16 #include <sys/ioctl.h>
17 #include <sys/socket.h>
21 #include <netinet/in.h>
25 #include <afs/venus.h>
26 #include <afs/com_err.h>
35 #include "afs/prs_fs.h"
36 #include <afs/afsint.h>
37 #include <afs/cellconfig.h>
40 #include <rx/rx_globals.h>
41 #include <afs/vldbint.h>
42 #include <afs/volser.h>
43 #include <afs/vlserver.h>
45 #include <afs/afsutil.h>
46 #include <afs/com_err.h>
49 #include <afs/ptclient.h>
50 #include <afs/ptuser.h>
51 #include <afs/afsutil.h>
52 #include <afs/sys_prototypes.h>
56 #define MAXCELLHOSTS 8
59 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
60 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
62 static char space[MAXSIZE];
63 static char tspace[1024];
64 static struct ubik_client *uclient;
66 static int GetClientAddrsCmd(struct cmd_syndesc *, void *);
67 static int SetClientAddrsCmd(struct cmd_syndesc *, void *);
68 static int FlushMountCmd(struct cmd_syndesc *, void *);
69 static int RxStatProcCmd(struct cmd_syndesc *, void *);
70 static int RxStatPeerCmd(struct cmd_syndesc *, void *);
71 static int GetFidCmd(struct cmd_syndesc *, void *);
72 static int UuidCmd(struct cmd_syndesc *, void *);
74 static char pn[] = "fs";
75 static int rxInitDone = 0;
79 static void ZapList(struct AclEntry *);
80 static int PruneList(struct AclEntry **, int);
81 static int CleanAcl(struct Acl *, char *);
82 static int SetVolCmd(struct cmd_syndesc *as, void *arock);
83 static int GetCellName(char *, struct afsconf_cell *);
84 static int VLDBInit(int, struct afsconf_cell *);
85 static void Die(int, char *);
88 * Character to use between name and rights in printed representation for
91 #define DFS_SEPARATOR ' '
93 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
96 int dfs; /* Originally true if a dfs acl; now also the type
97 * of the acl (1, 2, or 3, corresponding to object,
98 * initial dir, or initial object). */
99 sec_rgy_name_t cell; /* DFS cell name */
102 struct AclEntry *pluslist;
103 struct AclEntry *minuslist;
107 struct AclEntry *next;
113 afs_int32 callerAccess;
120 ZapAcl(struct Acl *acl)
124 ZapList(acl->pluslist);
125 ZapList(acl->minuslist);
130 foldcmp(char *a, char *b)
136 if (t >= 'A' && t <= 'Z')
138 if (u >= 'A' && u <= 'Z')
148 * Mods for the AFS/DFS protocol translator.
150 * DFS rights. It's ugly to put these definitions here, but they
151 * *cannot* change, because they're part of the wire protocol.
152 * In any event, the protocol translator will guarantee these
153 * assignments for AFS cache managers.
155 #define DFS_READ 0x01
156 #define DFS_WRITE 0x02
157 #define DFS_EXECUTE 0x04
158 #define DFS_CONTROL 0x08
159 #define DFS_INSERT 0x10
160 #define DFS_DELETE 0x20
162 /* the application definable ones (backwards from AFS) */
163 #define DFS_USR0 0x80000000 /* "A" bit */
164 #define DFS_USR1 0x40000000 /* "B" bit */
165 #define DFS_USR2 0x20000000 /* "C" bit */
166 #define DFS_USR3 0x10000000 /* "D" bit */
167 #define DFS_USR4 0x08000000 /* "E" bit */
168 #define DFS_USR5 0x04000000 /* "F" bit */
169 #define DFS_USR6 0x02000000 /* "G" bit */
170 #define DFS_USR7 0x01000000 /* "H" bit */
171 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
172 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
175 * Offset of -id switch in command structure for various commands.
176 * The -if switch is the next switch always.
178 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
181 * Determine whether either the -id or -if switches are present, and
182 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
184 /* int id; Offset of -id switch; -if is next switch */
186 getidf(struct cmd_syndesc *as, int id)
190 if (as->parms[id].items) {
193 if (as->parms[id + 1].items) {
198 "%s: you may specify either -id or -if, but not both switches\n",
206 PRights(afs_int32 arights, int dfs)
209 if (arights & PRSFS_READ)
211 if (arights & PRSFS_LOOKUP)
213 if (arights & PRSFS_INSERT)
215 if (arights & PRSFS_DELETE)
217 if (arights & PRSFS_WRITE)
219 if (arights & PRSFS_LOCK)
221 if (arights & PRSFS_ADMINISTER)
223 if (arights & PRSFS_USR0)
225 if (arights & PRSFS_USR1)
227 if (arights & PRSFS_USR2)
229 if (arights & PRSFS_USR3)
231 if (arights & PRSFS_USR4)
233 if (arights & PRSFS_USR5)
235 if (arights & PRSFS_USR6)
237 if (arights & PRSFS_USR7)
240 if (arights & DFS_READ)
244 if (arights & DFS_WRITE)
248 if (arights & DFS_EXECUTE)
252 if (arights & DFS_CONTROL)
256 if (arights & DFS_INSERT)
260 if (arights & DFS_DELETE)
264 if (arights & (DFS_USRALL))
266 if (arights & DFS_USR0)
268 if (arights & DFS_USR1)
270 if (arights & DFS_USR2)
272 if (arights & DFS_USR3)
274 if (arights & DFS_USR4)
276 if (arights & DFS_USR5)
278 if (arights & DFS_USR6)
280 if (arights & DFS_USR7)
286 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
290 struct ViceIoctl blob;
294 blob.out_size = MAXSIZE;
297 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
299 if ((errno == EINVAL) || (errno == ENOENT))
305 /* return a static pointer to a buffer */
310 strlcpy(tspace, apath, sizeof(tspace));
311 tp = strrchr(tspace, '/');
312 if (tp == (char *)tspace)
314 else if (tp == (char *)NULL) {
322 enum rtype { add, destroy, deny };
325 Convert(char *arights, int dfs, enum rtype *rtypep)
331 *rtypep = add; /* add rights, by default */
334 if (!strcmp(arights, "null")) {
338 if (!strcmp(arights, "read"))
339 return DFS_READ | DFS_EXECUTE;
340 if (!strcmp(arights, "write"))
341 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
343 if (!strcmp(arights, "all"))
344 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
345 DFS_WRITE | DFS_CONTROL;
347 if (!strcmp(arights, "read"))
348 return PRSFS_READ | PRSFS_LOOKUP;
349 if (!strcmp(arights, "write"))
350 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
351 PRSFS_WRITE | PRSFS_LOCK;
352 if (!strcmp(arights, "mail"))
353 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
354 if (!strcmp(arights, "all"))
355 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
356 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
358 if (!strcmp(arights, "none")) {
359 *rtypep = destroy; /* Remove entire entry */
362 len = strlen(arights);
364 for (i = 0; i < len; i++) {
398 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
406 mode |= PRSFS_LOOKUP;
408 mode |= PRSFS_INSERT;
410 mode |= PRSFS_DELETE;
416 mode |= PRSFS_ADMINISTER;
434 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
443 static struct AclEntry *
444 FindList(struct AclEntry *alist, char *aname)
447 if (!foldcmp(alist->name, aname))
454 /* if no parm specified in a particular slot, set parm to be "." instead */
456 SetDotDefault(struct cmd_item **aitemp)
460 return; /* already has value */
461 /* otherwise, allocate an item representing "." */
462 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
464 ti->next = (struct cmd_item *)0;
465 ti->data = (char *)malloc(2);
467 strcpy(ti->data, ".");
472 ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
474 struct AclEntry *tlist;
475 tlist = (plus ? al->pluslist : al->minuslist);
476 tlist = FindList(tlist, aname);
478 /* Found the item already in the list. */
479 tlist->rights = arights;
481 al->nplus -= PruneList(&al->pluslist, al->dfs);
483 al->nminus -= PruneList(&al->minuslist, al->dfs);
486 /* Otherwise we make a new item and plug in the new data. */
487 tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry));
489 strcpy(tlist->name, aname);
490 tlist->rights = arights;
492 tlist->next = al->pluslist;
493 al->pluslist = tlist;
495 if (arights == 0 || arights == -1)
496 al->nplus -= PruneList(&al->pluslist, al->dfs);
498 tlist->next = al->minuslist;
499 al->minuslist = tlist;
502 al->nminus -= PruneList(&al->minuslist, al->dfs);
507 ZapList(struct AclEntry *alist)
509 struct AclEntry *tp, *np;
510 for (tp = alist; tp; tp = np) {
517 PruneList(struct AclEntry **ae, int dfs)
519 struct AclEntry **lp;
520 struct AclEntry *te, *ne;
524 for (te = *ae; te; te = ne) {
525 if ((!dfs && te->rights == 0) || te->rights == -1) {
541 while (*astr != '\n')
548 * Create an empty acl, taking into account whether the acl pointed
549 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
550 * can recover from problems caused by bogus ACL's (in that case, always
551 * assume that the acl is AFS: for DFS, the user can always resort to
552 * acl_edit, but for AFS there may be no other way out).
560 tp = (struct Acl *)malloc(sizeof(struct Acl));
562 tp->nplus = tp->nminus = 0;
563 tp->pluslist = tp->minuslist = 0;
565 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
572 int nplus, nminus, i, trights;
574 struct AclEntry *first, *last, *tl;
577 ta = (struct Acl *)malloc(sizeof(struct Acl));
580 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
581 astr = SkipLine(astr);
582 sscanf(astr, "%d", &ta->nminus);
583 astr = SkipLine(astr);
590 for (i = 0; i < nplus; i++) {
591 sscanf(astr, "%100s %d", tname, &trights);
592 astr = SkipLine(astr);
593 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
597 strcpy(tl->name, tname);
598 tl->rights = trights;
604 ta->pluslist = first;
608 for (i = 0; i < nminus; i++) {
609 sscanf(astr, "%100s %d", tname, &trights);
610 astr = SkipLine(astr);
611 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
615 strcpy(tl->name, tname);
616 tl->rights = trights;
622 ta->minuslist = first;
628 PrintStatus(VolumeStatus * status, char *name, char *offmsg)
630 printf("Volume status for vid = %u named %s\n", status->Vid, name);
632 printf("Current offline message is %s\n", offmsg);
633 printf("Current disk quota is ");
634 if (status->MaxQuota != 0)
635 printf("%d\n", status->MaxQuota);
637 printf("unlimited\n");
638 printf("Current blocks used are %d\n", status->BlocksInUse);
639 printf("The partition has %d blocks available out of %d\n\n",
640 status->PartBlocksAvail, status->PartMaxBlocks);
645 QuickPrintStatus(VolumeStatus * status, char *name)
647 double QuotaUsed = 0.0;
648 double PartUsed = 0.0;
650 printf("%-25.25s", name);
652 if (status->MaxQuota != 0) {
653 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
655 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
657 printf(" no limit%10d", status->BlocksInUse);
659 if (QuotaUsed > 90.0) {
660 printf("%5.0f%%<<", QuotaUsed);
663 printf("%5.0f%% ", QuotaUsed);
666 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
668 if (PartUsed > 97.0) {
669 printf("%9.0f%%<<", PartUsed);
672 printf("%9.0f%% ", PartUsed);
674 printf(" <<WARNING\n");
681 QuickPrintSpace(VolumeStatus * status, char *name)
683 double PartUsed = 0.0;
685 printf("%-25.25s", name);
687 printf("%10d%10d%10d", status->PartMaxBlocks,
688 status->PartMaxBlocks - status->PartBlocksAvail,
689 status->PartBlocksAvail);
693 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
695 if (PartUsed > 90.0) {
696 printf(" %4.0f%%<<", PartUsed);
699 printf(" %4.0f%% ", PartUsed);
701 printf(" <<WARNING\n");
708 AclToString(struct Acl *acl)
710 static char mydata[MAXSIZE];
711 char tstring[MAXSIZE];
716 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
719 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
720 for (tp = acl->pluslist; tp; tp = tp->next) {
721 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
722 strcat(mydata, tstring);
724 for (tp = acl->minuslist; tp; tp = tp->next) {
725 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
726 strcat(mydata, tstring);
732 SetACLCmd(struct cmd_syndesc *as, void *arock)
735 struct ViceIoctl blob;
737 struct cmd_item *ti, *ui;
741 int idf = getidf(as, parm_setacl_id);
744 if (as->parms[2].items)
748 plusp = !(as->parms[3].items);
749 for (ti = as->parms[0].items; ti; ti = ti->next) {
750 blob.out_size = MAXSIZE;
752 blob.in = blob.out = space;
753 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
755 Die(errno, ti->data);
762 ta = ParseAcl(space);
763 if (!plusp && ta->dfs) {
765 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
767 "(you may specify \"null\" to revoke all rights, however)\n");
775 ta = EmptyAcl(space);
777 ta = ParseAcl(space);
778 CleanAcl(ta, ti->data);
779 for (ui = as->parms[1].items; ui; ui = ui->next->next) {
783 "%s: Missing second half of user/access pair.\n", pn);
787 rights = Convert(ui->next->data, ta->dfs, &rtype);
788 if (rtype == destroy && !ta->dfs) {
789 struct AclEntry *tlist;
791 tlist = (plusp ? ta->pluslist : ta->minuslist);
792 if (!FindList(tlist, ui->data))
795 if (rtype == deny && !ta->dfs)
797 if (rtype == destroy && ta->dfs)
799 ChangeList(ta, plusp, ui->data, rights);
801 blob.in = AclToString(ta);
803 blob.in_size = 1 + strlen(blob.in);
804 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
806 if (errno == EINVAL) {
808 static char *fsenv = 0;
810 fsenv = (char *)getenv("FS_EXPERT");
813 "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n",
817 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
818 "\nPossible reasons for this include:\n\n",
819 " -You may have specified an inappropriate combination of rights.\n",
820 " For example, some DFS-supported filesystems may not allow you to\n",
821 " drop the \"c\" right from \"user_obj\".\n\n",
822 " -A mask_obj may be required (it is likely required by the underlying\n",
823 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
824 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
825 " does not automatically create or update the mask_obj. Try setting\n",
826 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
827 " users or groups. You can do this with a single command, such as\n",
828 " \"fs sa mask_obj all user:somename read\"\n\n",
829 " -A specified user or group may not exist.\n\n",
830 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
831 " This is probably not allowed by the underlying file system.\n\n",
832 " -If you add a user or group to a DFS ACL, remember that it must be\n",
833 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
834 " may be local requirements on the format of the user or group name.\n",
835 " Check with your cell administrator.\n\n",
836 " -Or numerous other possibilities. It would be great if we could be more\n",
837 " precise about the actual problem, but for various reasons, this is\n",
838 " impractical via this interface. If you can't figure it out, you\n",
839 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
840 " whatever is provided). You may get better results. Good luck!\n\n",
841 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
845 "%s: Invalid argument, possible reasons include:\n",
847 fprintf(stderr, "\t-File not in AFS\n");
849 "\t-Too many users on access control list\n");
851 "\t-Tried to add non-existent user to access control list\n");
854 Die(errno, ti->data);
866 CopyACLCmd(struct cmd_syndesc *as, void *arock)
869 struct ViceIoctl blob;
870 struct Acl *fa, *ta = 0;
874 int idf = getidf(as, parm_copyacl_id);
877 if (as->parms[2].items)
881 blob.out_size = MAXSIZE;
883 blob.in = blob.out = space;
884 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
886 Die(errno, as->parms[0].items->data);
889 fa = ParseAcl(space);
890 CleanAcl(fa, as->parms[0].items->data);
891 for (ti = as->parms[1].items; ti; ti = ti->next) {
892 blob.out_size = MAXSIZE;
894 blob.in = blob.out = space;
895 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
897 Die(errno, ti->data);
905 ta = EmptyAcl(space);
907 ta = ParseAcl(space);
908 CleanAcl(ta, ti->data);
909 if (ta->dfs != fa->dfs) {
911 "%s: incompatible file system types: acl not copied to %s; aborted\n",
917 if (!clear && strcmp(ta->cell, fa->cell) != 0) {
919 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
924 strcpy(ta->cell, fa->cell);
926 for (tp = fa->pluslist; tp; tp = tp->next)
927 ChangeList(ta, 1, tp->name, tp->rights);
928 for (tp = fa->minuslist; tp; tp = tp->next)
929 ChangeList(ta, 0, tp->name, tp->rights);
930 blob.in = AclToString(ta);
932 blob.in_size = 1 + strlen(blob.in);
933 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
935 if (errno == EINVAL) {
937 "%s: Invalid argument, possible reasons include:\n",
939 fprintf(stderr, "\t-File not in AFS\n");
941 Die(errno, ti->data);
952 /* pioctl() call to get the cellname of a pathname */
954 GetCell(char *fname, char *cellname)
957 struct ViceIoctl blob;
960 blob.out_size = MAXCELLCHARS;
963 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
964 return code ? errno : 0;
967 /* Check if a username is valid: If it contains only digits (or a
968 * negative sign), then it might be bad. We then query the ptserver
972 BadName(char *aname, char *fname)
974 afs_int32 tc, code, id;
976 char cell[MAXCELLCHARS];
978 for (nm = aname; (tc = *nm); nm++) {
979 /* all must be '-' or digit to be bad */
980 if (tc != '-' && (tc < '0' || tc > '9'))
984 /* Go to the PRDB and see if this all number username is valid */
985 code = GetCell(fname, cell);
989 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
990 code = pr_SNameToId(aname, &id);
993 /* 1=>Not-valid; 0=>Valid */
994 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
998 /* clean up an access control list of its bad entries; return 1 if we made
999 any changes to the list, and 0 otherwise */
1001 CleanAcl(struct Acl *aa, char *fname)
1003 struct AclEntry *te, **le, *ne;
1006 /* Don't correct DFS ACL's for now */
1010 /* prune out bad entries */
1011 changes = 0; /* count deleted entries */
1013 for (te = aa->pluslist; te; te = ne) {
1015 if (BadName(te->name, fname)) {
1025 le = &aa->minuslist;
1026 for (te = aa->minuslist; te; te = ne) {
1028 if (BadName(te->name, fname)) {
1042 /* clean up an acl to not have bogus entries */
1044 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1048 struct ViceIoctl blob;
1050 struct cmd_item *ti;
1051 struct AclEntry *te;
1054 SetDotDefault(&as->parms[0].items);
1055 for (ti = as->parms[0].items; ti; ti = ti->next) {
1056 blob.out_size = MAXSIZE;
1059 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1061 Die(errno, ti->data);
1068 ta = ParseAcl(space);
1071 "%s: cleanacl is not supported for DFS access lists.\n",
1077 changes = CleanAcl(ta, ti->data);
1080 /* now set the acl */
1081 blob.in = AclToString(ta);
1082 blob.in_size = strlen(blob.in) + 1;
1084 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1086 if (errno == EINVAL) {
1088 "%s: Invalid argument, possible reasons include\n",
1090 fprintf(stderr, "%s: File not in vice or\n", pn);
1092 "%s: Too many users on access control list or\n",
1095 Die(errno, ti->data);
1101 /* now list the updated acl */
1102 printf("Access list for %s is now\n", ti->data);
1103 if (ta->nplus > 0) {
1105 printf("Normal rights:\n");
1106 for (te = ta->pluslist; te; te = te->next) {
1107 printf(" %s ", te->name);
1108 PRights(te->rights, ta->dfs);
1112 if (ta->nminus > 0) {
1113 printf("Negative rights:\n");
1114 for (te = ta->minuslist; te; te = te->next) {
1115 printf(" %s ", te->name);
1116 PRights(te->rights, ta->dfs);
1123 printf("Access list for %s is fine.\n", ti->data);
1131 ListACLCmd(struct cmd_syndesc *as, void *arock)
1135 struct ViceIoctl blob;
1136 struct AclEntry *te;
1137 struct cmd_item *ti;
1138 int idf = getidf(as, parm_listacl_id);
1141 SetDotDefault(&as->parms[0].items);
1142 for (ti = as->parms[0].items; ti; ti = ti->next) {
1143 blob.out_size = MAXSIZE;
1145 blob.in = blob.out = space;
1146 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1148 Die(errno, ti->data);
1152 ta = ParseAcl(space);
1155 printf("Access list for %s is\n", ti->data);
1158 printf("DFS access list for %s is\n", ti->data);
1161 printf("DFS initial directory access list of %s is\n", ti->data);
1164 printf("DFS initial file access list of %s is\n", ti->data);
1168 printf(" Default cell = %s\n", ta->cell);
1170 if (ta->nplus > 0) {
1172 printf("Normal rights:\n");
1173 for (te = ta->pluslist; te; te = te->next) {
1174 printf(" %s ", te->name);
1175 PRights(te->rights, ta->dfs);
1179 if (ta->nminus > 0) {
1180 printf("Negative rights:\n");
1181 for (te = ta->minuslist; te; te = te->next) {
1182 printf(" %s ", te->name);
1183 PRights(te->rights, ta->dfs);
1195 GetCallerAccess(struct cmd_syndesc *as, void *arock)
1197 struct cmd_item *ti;
1200 SetDotDefault(&as->parms[0].items);
1201 for (ti = as->parms[0].items; ti; ti = ti->next) {
1203 struct ViceIoctl blob;
1204 struct vcxstat2 stat;
1205 blob.out_size = sizeof(struct vcxstat2);
1207 blob.out = (void *)&stat;
1208 code = pioctl(ti->data, VIOC_GETVCXSTATUS2, &blob, 1);
1210 Die(errno, ti->data);
1214 printf("Callers access to %s is ", ti->data);
1215 PRights(stat.callerAccess, 0);
1222 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1225 struct ViceIoctl blob;
1226 struct cmd_item *ti;
1229 SetDotDefault(&as->parms[0].items);
1230 for (ti = as->parms[0].items; ti; ti = ti->next) {
1231 blob.in_size = blob.out_size = 0;
1232 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1234 fprintf(stderr, "Error flushing volume ");
1244 * The Windows version of UuidCmd displays the UUID.
1245 * When the UNIX version is updated to do the same
1246 * be sure to replace the CMD_REQUIRED flag with
1247 * CMD_OPTIONAL in the cmd_AddParam(-generate) call
1250 UuidCmd(struct cmd_syndesc *as, void *arock)
1253 struct ViceIoctl blob;
1258 if (as->parms[0].items) {
1260 fprintf (stderr, "Permission denied: requires root access.\n");
1264 /* generate new UUID */
1265 code = pioctl(0, VIOC_NEWUUID, &blob, 1);
1272 printf("New uuid generated.\n");
1274 /* This will never execute */
1275 printf("Please add the '-generate' option to generate a new UUID.\n");
1280 #if defined(AFS_CACHE_BYPASS)
1282 * Set cache-bypass threshold. Files larger than this size will not be cached.
1283 * With a threshold of 0, the cache is always bypassed. With a threshold of -1,
1284 * cache bypass is disabled.
1288 BypassThresholdCmd(struct cmd_syndesc *as, char *arock)
1292 struct ViceIoctl blob;
1293 afs_int32 threshold_i, threshold_o;
1296 /* if new threshold supplied, then set and confirm, else,
1297 * get current threshold and print
1300 if(as->parms[0].items) {
1303 tp = as->parms[0].items->data;
1306 for(ix = 0; ix < len; ++ix) {
1307 if(!isdigit(tp[0])) {
1313 fprintf(stderr, "fs bypassthreshold -size: %s must be an undecorated digit string.\n", tp);
1316 threshold_i = atoi(tp);
1317 if(ix > 9 && threshold_i < 2147483647)
1318 threshold_i = 2147483647;
1319 blob.in = (char *) &threshold_i;
1320 blob.in_size = sizeof(threshold_i);
1326 blob.out = (char *) &threshold_o;
1327 blob.out_size = sizeof(threshold_o);
1328 code = pioctl(0, VIOC_SETBYPASS_THRESH, &blob, 1);
1333 printf("Cache bypass threshold %d", threshold_o);
1334 if(threshold_o == -1)
1335 printf(" (disabled)");
1345 FlushCmd(struct cmd_syndesc *as, void *arock)
1348 struct ViceIoctl blob;
1349 struct cmd_item *ti;
1352 for (ti = as->parms[0].items; ti; ti = ti->next) {
1353 blob.in_size = blob.out_size = 0;
1354 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1356 if (errno == EMFILE) {
1357 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1360 fprintf(stderr, "%s: Error flushing file ", pn);
1370 /* all this command does is repackage its args and call SetVolCmd */
1372 SetQuotaCmd(struct cmd_syndesc *as, void *arock)
1374 struct cmd_syndesc ts;
1376 /* copy useful stuff from our command slot; we may later have to reorder */
1377 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1378 return SetVolCmd(&ts, arock);
1382 SetVolCmd(struct cmd_syndesc *as, void *arock)
1385 struct ViceIoctl blob;
1386 struct cmd_item *ti;
1387 struct VolumeStatus *status;
1388 char *offmsg, *input;
1391 SetDotDefault(&as->parms[0].items);
1392 for (ti = as->parms[0].items; ti; ti = ti->next) {
1394 blob.out_size = MAXSIZE;
1395 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1398 status = (VolumeStatus *) space;
1399 status->MinQuota = status->MaxQuota = -1;
1401 if (as->parms[1].items) {
1402 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1404 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1409 if (as->parms[2].items)
1410 offmsg = as->parms[2].items->data;
1411 input = (char *)status + sizeof(*status);
1412 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1414 if (strlen(offmsg) >= VMSGSIZE) {
1416 "%s: message must be shorter than %d characters\n",
1421 strcpy(input, offmsg);
1422 blob.in_size += strlen(offmsg);
1423 input += strlen(offmsg) + 1;
1426 *(input++) = '\0'; /* Pad for old style volume "motd" */
1427 code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1);
1429 Die(errno, ti->data);
1437 * Why is VenusFid declared in the kernel-only section of afs.h,
1438 * if it's the exported interface of the cache manager?
1446 ExamineCmd(struct cmd_syndesc *as, void *arock)
1449 struct ViceIoctl blob;
1450 struct cmd_item *ti;
1451 struct VolumeStatus *status;
1452 char *name, *offmsg;
1455 SetDotDefault(&as->parms[0].items);
1456 for (ti = as->parms[0].items; ti; ti = ti->next) {
1457 struct VenusFid vfid;
1460 blob.out_size = MAXSIZE;
1463 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1465 Die(errno, ti->data);
1469 status = (VolumeStatus *) space;
1470 name = (char *)status + sizeof(*status);
1471 offmsg = name + strlen(name) + 1;
1473 blob.out_size = sizeof(struct VenusFid);
1474 blob.out = (char *) &vfid;
1475 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1476 printf("File %s (%u.%u.%u) contained in volume %u\n",
1477 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1481 PrintStatus(status, name, offmsg);
1487 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1490 struct ViceIoctl blob;
1491 struct cmd_item *ti;
1492 struct VolumeStatus *status;
1496 printf("%-25s%-10s%-10s%-7s%-11s\n", "Volume Name", " Quota",
1497 " Used", " %Used", " Partition");
1498 SetDotDefault(&as->parms[0].items);
1499 for (ti = as->parms[0].items; ti; ti = ti->next) {
1501 blob.out_size = MAXSIZE;
1504 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1506 Die(errno, ti->data);
1510 status = (VolumeStatus *) space;
1511 name = (char *)status + sizeof(*status);
1512 QuickPrintStatus(status, name);
1518 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1521 struct ViceIoctl blob;
1522 struct cmd_item *ti;
1528 SetDotDefault(&as->parms[0].items);
1529 for (ti = as->parms[0].items; ti; ti = ti->next) {
1531 blob.out_size = MAXSIZE;
1534 memset(space, 0, sizeof(space));
1535 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1537 Die(errno, ti->data);
1541 hosts = (afs_int32 *) space;
1542 printf("File %s is on host%s ", ti->data,
1543 (hosts[0] && !hosts[1]) ? "" : "s");
1544 for (j = 0; j < MAXHOSTS; j++) {
1547 tp = hostutil_GetNameByINet(hosts[j]);
1557 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1560 struct ViceIoctl blob;
1561 struct cmd_item *ti;
1563 struct VolumeStatus *status;
1566 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1567 " used", " avail", " %used");
1568 SetDotDefault(&as->parms[0].items);
1569 for (ti = as->parms[0].items; ti; ti = ti->next) {
1571 blob.out_size = MAXSIZE;
1574 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1576 Die(errno, ti->data);
1580 status = (VolumeStatus *) space;
1581 name = (char *)status + sizeof(*status);
1582 QuickPrintSpace(status, name);
1588 QuotaCmd(struct cmd_syndesc *as, void *arock)
1591 struct ViceIoctl blob;
1592 struct cmd_item *ti;
1594 struct VolumeStatus *status;
1597 SetDotDefault(&as->parms[0].items);
1598 for (ti = as->parms[0].items; ti; ti = ti->next) {
1600 blob.out_size = MAXSIZE;
1603 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1605 Die(errno, ti->data);
1609 status = (VolumeStatus *) space;
1610 if (status->MaxQuota)
1612 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
1615 printf("%2.0f%% of quota used.\n", quotaPct);
1621 ListMountCmd(struct cmd_syndesc *as, void *arock)
1624 struct ViceIoctl blob;
1625 struct cmd_item *ti;
1626 char orig_name[1024]; /*Original name, may be modified */
1627 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
1628 char parent_dir[1024]; /*Parent directory of true name */
1629 char *last_component; /*Last component of true name */
1630 struct stat statbuff; /*Buffer for status info */
1631 int link_chars_read; /*Num chars read in readlink() */
1632 int thru_symlink; /*Did we get to a mount point via a symlink? */
1635 for (ti = as->parms[0].items; ti; ti = ti->next) {
1638 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
1641 if (lstat(orig_name, &statbuff) < 0) {
1642 /* if lstat fails, we should still try the pioctl, since it
1643 * may work (for example, lstat will fail, but pioctl will
1644 * work if the volume of offline (returning ENODEV). */
1645 statbuff.st_mode = S_IFDIR; /* lie like pros */
1649 * The lstat succeeded. If the given file is a symlink, substitute
1650 * the file name with the link name.
1652 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1655 * Read name of resolved file.
1657 link_chars_read = readlink(orig_name, true_name, 1024);
1658 if (link_chars_read <= 0) {
1660 "%s: Can't read target name for '%s' symbolic link!\n",
1667 * Add a trailing null to what was read, bump the length.
1669 true_name[link_chars_read++] = 0;
1672 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1673 * have to create a full pathname using the original name and the
1674 * relative symlink name. Find the rightmost slash in the original
1675 * name (we know there is one) and splice in the symlink value.
1677 if (true_name[0] != '/') {
1678 last_component = (char *)strrchr(orig_name, '/');
1679 strcpy(++last_component, true_name);
1680 strcpy(true_name, orig_name);
1683 strcpy(true_name, orig_name);
1686 * Find rightmost slash, if any.
1688 last_component = (char *)strrchr(true_name, '/');
1689 if (last_component == (char *)true_name) {
1690 strcpy(parent_dir, "/");
1693 else if (last_component != (char *)NULL) {
1695 * Found it. Designate everything before it as the parent directory,
1696 * everything after it as the final component.
1698 strncpy(parent_dir, true_name, last_component - true_name);
1699 parent_dir[last_component - true_name] = 0;
1700 last_component++; /*Skip the slash */
1703 * No slash appears in the given file name. Set parent_dir to the current
1704 * directory, and the last component as the given name.
1706 strcpy(parent_dir, ".");
1707 last_component = true_name;
1710 if (strcmp(last_component, ".") == 0
1711 || strcmp(last_component, "..") == 0) {
1713 "%s: you may not use '.' or '..' as the last component\n",
1715 fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n",
1721 blob.in = last_component;
1722 blob.in_size = strlen(last_component) + 1;
1723 blob.out_size = MAXSIZE;
1725 memset(space, 0, MAXSIZE);
1727 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1730 printf("'%s' is a %smount point for volume '%s'\n", ti->data,
1731 (thru_symlink ? "symbolic link, leading to a " : ""),
1734 if (errno == EINVAL) {
1735 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
1737 Die(errno, (ti->data ? ti->data : parent_dir));
1746 MakeMountCmd(struct cmd_syndesc *as, void *arock)
1749 char *cellName, *volName, *tmpName;
1750 struct afsconf_cell info;
1751 struct vldbentry vldbEntry;
1752 struct ViceIoctl blob;
1758 if (as->parms[5].items && !as->parms[2].items) {
1759 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1764 if (as->parms[2].items) /* cell name specified */
1765 cellName = as->parms[2].items->data;
1768 volName = as->parms[1].items->data;
1770 if (strlen(volName) >= 64) {
1772 "%s: volume name too long (length must be < 64 characters)\n",
1777 /* Check for a cellname in the volume specification, and complain
1778 * if it doesn't match what was specified with -cell */
1779 if ((tmpName = strchr(volName, ':'))) {
1782 if (strcasecmp(cellName, volName)) {
1783 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1788 volName = ++tmpName;
1791 if (!InAFS(Parent(as->parms[0].items->data))) {
1793 "%s: mount points must be created within the AFS file system\n",
1800 blob.out_size = MAXSIZE;
1803 pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME,
1807 code = GetCellName(cellName ? cellName : space, &info);
1811 if (!(as->parms[4].items)) {
1812 /* not fast, check which cell the mountpoint is being created in */
1813 /* not fast, check name with VLDB */
1814 code = VLDBInit(1, &info);
1816 /* make the check. Don't complain if there are problems with init */
1818 ubik_VL_GetEntryByNameO(uclient, 0, volName,
1820 if (code == VL_NOENT) {
1822 "%s: warning, volume %s does not exist in cell %s.\n",
1823 pn, volName, cellName ? cellName : space);
1828 if (as->parms[3].items) /* if -rw specified */
1833 /* cellular mount point, prepend cell prefix */
1834 strcat(space, info.name);
1837 strcat(space, volName); /* append volume name */
1838 strcat(space, "."); /* stupid convention; these end with a period */
1839 code = symlink(space, as->parms[0].items->data);
1841 Die(errno, as->parms[0].items->data);
1848 * Delete AFS mount points. Variables are used as follows:
1849 * tbuffer: Set to point to the null-terminated directory name of the mount point
1850 * (or ``.'' if none is provided)
1851 * tp: Set to point to the actual name of the mount point to nuke.
1854 RemoveMountCmd(struct cmd_syndesc *as, void *arock)
1857 struct ViceIoctl blob;
1858 struct cmd_item *ti;
1860 char lsbuffer[1024];
1864 for (ti = as->parms[0].items; ti; ti = ti->next) {
1866 tp = (char *)strrchr(ti->data, '/');
1868 strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */
1870 tp++; /* skip the slash */
1872 strcpy(tbuffer, ".");
1876 blob.in_size = strlen(tp) + 1;
1877 blob.out = lsbuffer;
1878 blob.out_size = sizeof(lsbuffer);
1879 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1881 if (errno == EINVAL) {
1882 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
1885 Die(errno, ti->data);
1888 continue; /* don't bother trying */
1892 blob.in_size = strlen(tp) + 1;
1893 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1895 Die(errno, ti->data);
1906 CheckServersCmd(struct cmd_syndesc *as, void *arock)
1909 struct ViceIoctl blob;
1913 struct afsconf_cell info;
1914 struct chservinfo checkserv;
1916 memset(&checkserv, 0, sizeof(struct chservinfo));
1917 blob.in_size = sizeof(struct chservinfo);
1918 blob.in = (caddr_t) & checkserv;
1920 blob.out_size = MAXSIZE;
1922 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1924 /* prepare flags for checkservers command */
1925 temp = 2; /* default to checking local cell only */
1926 if (as->parms[2].items)
1927 temp |= 1; /* set fast flag */
1928 if (as->parms[1].items)
1929 temp &= ~2; /* turn off local cell check */
1931 checkserv.magic = 0x12345678; /* XXX */
1932 checkserv.tflags = temp;
1934 /* now copy in optional cell name, if specified */
1935 if (as->parms[0].items) {
1936 code = GetCellName(as->parms[0].items->data, &info);
1940 strcpy(checkserv.tbuffer, info.name);
1941 checkserv.tsize = strlen(info.name) + 1;
1943 strcpy(checkserv.tbuffer, "\0");
1944 checkserv.tsize = 0;
1947 if (as->parms[3].items) {
1948 checkserv.tinterval = atol(as->parms[3].items->data);
1951 if (checkserv.tinterval < 0) {
1953 ("Warning: The negative -interval is ignored; treated as an inquiry\n");
1954 checkserv.tinterval = 0;
1955 } else if (checkserv.tinterval > 600) {
1957 ("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1958 checkserv.tinterval = 600; /* 10 min max interval */
1961 checkserv.tinterval = -1; /* don't change current interval */
1964 code = pioctl(0, VIOCCKSERV, &blob, 1);
1966 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1967 printf("Must be root to change -interval\n");
1973 memcpy(&temp, space, sizeof(afs_int32));
1974 if (checkserv.tinterval >= 0) {
1975 if (checkserv.tinterval > 0)
1977 ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1978 checkserv.tinterval, temp);
1980 printf("The current down server probe interval is %d secs\n",
1985 printf("All servers are running.\n");
1988 ("These servers unavailable due to network or server problems: ");
1990 memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32));
1993 tp = hostutil_GetNameByINet(temp);
2003 MessagesCmd(struct cmd_syndesc *as, void *arock)
2006 struct ViceIoctl blob;
2007 struct gaginfo gagflags;
2008 struct cmd_item *show;
2010 memset(&gagflags, 0, sizeof(struct gaginfo));
2011 blob.in_size = sizeof(struct gaginfo);
2012 blob.in = (caddr_t) & gagflags;
2013 blob.out_size = MAXSIZE;
2015 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2017 if ((show = as->parms[0].items)) {
2018 if (!strcasecmp(show->data, "user"))
2019 gagflags.showflags |= GAGUSER;
2020 else if (!strcasecmp(show->data, "console"))
2021 gagflags.showflags |= GAGCONSOLE;
2022 else if (!strcasecmp(show->data, "all"))
2023 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2024 else if (!strcasecmp(show->data, "none"))
2028 "unrecognized flag %s: must be in {user,console,all,none}\n",
2037 code = pioctl(0, VIOC_GAG, &blob, 1);
2047 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2050 struct ViceIoctl blob;
2054 code = pioctl(0, VIOCCKBACK, &blob, 1);
2060 printf("All volumeID/name mappings checked.\n");
2065 PreCacheCmd(struct cmd_syndesc *as, void *arock)
2068 struct ViceIoctl blob;
2071 if (!as->parms[0].items && !as->parms[1].items) {
2072 fprintf(stderr, "%s: syntax error in precache cmd.\n", pn);
2075 if (as->parms[0].items) {
2076 code = util_GetInt32(as->parms[0].items->data, &temp);
2078 fprintf(stderr, "%s: bad integer specified for precache size.\n",
2084 blob.in = (char *)&temp;
2085 blob.in_size = sizeof(afs_int32);
2087 code = pioctl(0, VIOCPRECACHE, &blob, 1);
2093 printf("New precache size set.\n");
2098 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2101 struct ViceIoctl blob;
2104 if (!as->parms[0].items && !as->parms[1].items) {
2105 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
2108 if (as->parms[0].items) {
2109 code = util_GetInt32(as->parms[0].items->data, &temp);
2111 fprintf(stderr, "%s: bad integer specified for cache size.\n",
2117 blob.in = (char *)&temp;
2118 blob.in_size = sizeof(afs_int32);
2120 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2122 if (errno == EROFS) {
2124 ("'fs setcache' not allowed on memory cache based cache managers.\n");
2131 printf("New cache size set.\n");
2135 #define MAXGCSIZE 16
2137 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2139 afs_int32 code, filesUsed;
2140 struct ViceIoctl blob;
2141 afs_int32 parms[MAXGCSIZE];
2142 double percentFiles, percentBlocks;
2143 afs_int32 flags = 0;
2145 if (as->parms[0].items){ /* -files */
2147 } else if (as->parms[1].items){ /* -excessive */
2153 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
2155 blob.in = (char *)&flags;
2156 blob.in_size = sizeof(afs_int32);
2157 } else { /* be backward compatible */
2161 blob.out_size = sizeof(parms);
2162 blob.out = (char *)parms;
2163 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2170 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2171 parms[1], parms[0]);
2172 if (parms[1] > parms[0])
2173 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2177 percentBlocks = ((double)parms[1]/parms[0]) * 100;
2178 printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n",
2179 percentBlocks, parms[1], parms[0]);
2184 filesUsed = parms[2] - parms[3];
2185 percentFiles = ((double)filesUsed/parms[2]) * 100;
2186 printf(" %5.0f%% of the cache files (%d of %d files)\n",
2187 percentFiles, filesUsed, parms[2]);
2189 printf(" afs_cacheFiles: %10d\n", parms[2]);
2190 printf(" IFFree: %10d\n", parms[3]);
2191 printf(" IFEverUsed: %10d\n", parms[4]);
2192 printf(" IFDataMod: %10d\n", parms[5]);
2193 printf(" IFDirtyPages: %10d\n", parms[6]);
2194 printf(" IFAnyPages: %10d\n", parms[7]);
2195 printf(" IFDiscarded: %10d\n", parms[8]);
2196 printf(" DCentries: %10d\n", parms[9]);
2197 printf(" 0k- 4K: %10d\n", parms[10]);
2198 printf(" 4k- 16k: %10d\n", parms[11]);
2199 printf(" 16k- 64k: %10d\n", parms[12]);
2200 printf(" 64k- 256k: %10d\n", parms[13]);
2201 printf(" 256k- 1M: %10d\n", parms[14]);
2202 printf(" >=1M: %10d\n", parms[15]);
2205 if (percentBlocks > 90)
2206 printf("[cache size usage over 90%%, consider increasing cache size]\n");
2207 if (percentFiles > 90)
2208 printf("[cache file usage over 90%%, consider increasing '-files' argument to afsd]\n");
2214 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2219 struct ViceIoctl blob;
2222 resolve = !(as->parms[0].items); /* -numeric */
2226 memcpy(tp, &i, sizeof(afs_int32));
2227 blob.out_size = MAXSIZE;
2228 blob.in_size = sizeof(afs_int32);
2231 code = pioctl(0, VIOCGETCELL, &blob, 1);
2234 break; /* done with the list */
2239 printf("Cell %s on hosts", tp + MAXCELLHOSTS * sizeof(afs_int32));
2240 for (j = 0; j < MAXCELLHOSTS; j++) {
2242 char *name, tbuffer[20];
2244 memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32));
2249 name = hostutil_GetNameByINet(addr);
2252 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2253 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2256 printf(" %s", name);
2264 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2267 char *tp, *aliasName, *realName;
2268 struct ViceIoctl blob;
2272 memcpy(tp, &i, sizeof(afs_int32));
2273 blob.out_size = MAXSIZE;
2274 blob.in_size = sizeof(afs_int32);
2277 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2280 break; /* done with the list */
2286 tp += strlen(aliasName) + 1;
2288 printf("Alias %s for cell %s\n", aliasName, realName);
2294 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2297 struct ViceIoctl blob;
2298 struct cmd_item *ti;
2300 struct hostent *thp;
2303 ti = as->parms[0].items;
2306 thp = hostutil_GetHostByName(ti->data);
2308 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2311 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2313 hostAddr = 0; /* means don't set host */
2314 setp = 0; /* aren't setting host */
2317 /* now do operation */
2318 blob.in_size = sizeof(afs_int32);
2319 blob.out_size = sizeof(afs_int32);
2320 blob.in = (char *) &hostAddr;
2321 blob.out = (char *) &hostAddr;
2323 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2332 NukeNFSCredsCmd(struct cmd_syndesc *as, void *arock)
2335 struct ViceIoctl blob;
2336 struct cmd_item *ti;
2338 struct hostent *thp;
2340 ti = as->parms[0].items;
2341 thp = hostutil_GetHostByName(ti->data);
2343 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2346 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2348 /* now do operation */
2349 blob.in_size = sizeof(afs_int32);
2350 blob.out_size = sizeof(afs_int32);
2351 blob.in = (char *) &hostAddr;
2352 blob.out = (char *) &hostAddr;
2354 code = pioctl(0, VIOC_NFS_NUKE_CREDS, &blob, 1);
2363 NewCellCmd(struct cmd_syndesc *as, void *arock)
2365 afs_int32 code, linkedstate = 0, size = 0, *lp;
2366 struct ViceIoctl blob;
2367 struct cmd_item *ti;
2368 char *tp, *cellname = 0;
2369 struct hostent *thp;
2370 afs_int32 fsport = 0, vlport = 0;
2371 afs_int32 scount; /* Number of servers to pass in pioctl call */
2374 * With the NEWCELL pioctl call, 3.4 clients take an array of
2375 * MAXHOSTS (13) servers while 3.5 clients take an array of
2376 * MAXCELLHOSTS (8) servers. To determine which we are talking to,
2377 * do a GETCELL pioctl and pass it a magic number. If an array of
2378 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
2379 * If we get back EDOM, there are no cells in the kernel yet,
2380 * and we'll assume a 3.5 client.
2383 lp = (afs_int32 *) tp;
2384 *lp++ = 0; /* first cell entry */
2385 *lp = 0x12345678; /* magic */
2386 blob.out_size = MAXSIZE;
2387 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
2390 code = pioctl(0, VIOCGETCELL, &blob, 1);
2391 if (code < 0 && errno != EDOM) {
2395 if (code < 1 && errno == EDOM) {
2399 cellname = tp + MAXCELLHOSTS * sizeof(afs_int32);
2400 scount = ((cellname[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2403 /* Now setup and do the NEWCELL pioctl call */
2404 memset(space, 0, (scount + 1) * sizeof(afs_int32));
2406 lp = (afs_int32 *) tp;
2408 tp += sizeof(afs_int32);
2409 for (ti = as->parms[1].items; ti; ti = ti->next) {
2410 thp = hostutil_GetHostByName(ti->data);
2413 "%s: Host %s not found in host table, skipping it.\n", pn,
2416 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2417 tp += sizeof(afs_int32);
2420 if (as->parms[2].items) {
2422 * Link the cell, for the purposes of volume location, to the specified
2425 cellname = as->parms[2].items->data;
2428 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2429 if (as->parms[3].items) {
2430 code = util_GetInt32(as->parms[3].items->data, &vlport);
2433 "%s: bad integer specified for the fileserver port.\n",
2438 if (as->parms[4].items) {
2439 code = util_GetInt32(as->parms[4].items->data, &fsport);
2442 "%s: bad integer specified for the vldb server port.\n",
2448 tp = (char *)(space + (scount + 1) * sizeof(afs_int32));
2449 lp = (afs_int32 *) tp;
2453 strcpy(space + ((scount + 4) * sizeof(afs_int32)),
2454 as->parms[0].items->data);
2455 size = ((scount + 4) * sizeof(afs_int32))
2456 + strlen(as->parms[0].items->data)
2457 + 1 /* for null */ ;
2458 tp = (char *)(space + size);
2460 strcpy(tp, cellname);
2461 size += strlen(cellname) + 1;
2463 blob.in_size = size;
2466 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2475 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2478 struct ViceIoctl blob;
2480 char *aliasName, *realName;
2482 /* Now setup and do the NEWCELL pioctl call */
2483 aliasName = as->parms[0].items->data;
2484 realName = as->parms[1].items->data;
2486 strcpy(tp, aliasName);
2487 tp += strlen(aliasName) + 1;
2488 strcpy(tp, realName);
2489 tp += strlen(realName) + 1;
2491 blob.in_size = tp - space;
2495 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2497 if (errno == EEXIST) {
2499 "%s: cell name `%s' in use by an existing cell.\n", pn,
2510 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2513 struct cmd_item *ti;
2515 char cell[MAXCELLCHARS];
2517 SetDotDefault(&as->parms[0].items);
2518 for (ti = as->parms[0].items; ti; ti = ti->next) {
2519 code = GetCell(ti->data, cell);
2521 if (errno == ENOENT)
2522 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
2524 Die(errno, ti->data);
2529 printf("File %s lives in cell '%s'\n", ti->data, cell);
2535 WSCellCmd(struct cmd_syndesc *as, void *arock)
2538 struct ViceIoctl blob;
2542 blob.out_size = MAXSIZE;
2545 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2551 printf("This workstation belongs to cell '%s'\n", space);
2556 static PrimaryCellCmd(as)
2557 struct cmd_syndesc *as;
2559 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2565 MonitorCmd(struct cmd_syndesc *as, void *arock)
2568 struct ViceIoctl blob;
2569 struct cmd_item *ti;
2571 struct hostent *thp;
2575 ti = as->parms[0].items;
2579 if (!strcmp(ti->data, "off"))
2580 hostAddr = 0xffffffff;
2582 thp = hostutil_GetHostByName(ti->data);
2584 if (!strcmp(ti->data, "localhost")) {
2586 "localhost not in host table, assuming 127.0.0.1\n");
2587 hostAddr = htonl(0x7f000001);
2589 fprintf(stderr, "host %s not found in host table.\n",
2594 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2597 hostAddr = 0; /* means don't set host */
2598 setp = 0; /* aren't setting host */
2601 /* now do operation */
2602 blob.in_size = sizeof(afs_int32);
2603 blob.out_size = sizeof(afs_int32);
2604 blob.in = (char *)&hostAddr;
2605 blob.out = (char *)&hostAddr;
2606 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2612 printf("%s: new monitor host set.\n", pn);
2614 /* now decode old address */
2615 if (hostAddr == 0xffffffff) {
2616 printf("Cache monitoring is currently disabled.\n");
2618 tp = hostutil_GetNameByINet(hostAddr);
2619 printf("Using host %s for monitor services.\n", tp);
2626 SysNameCmd(struct cmd_syndesc *as, void *arock)
2629 struct ViceIoctl blob;
2630 struct cmd_item *ti;
2631 char *input = space;
2634 ti = as->parms[0].items;
2637 blob.out_size = MAXSIZE;
2638 blob.in_size = sizeof(afs_int32);
2639 input += sizeof(afs_int32);
2640 for (; ti; ti = ti->next) {
2642 blob.in_size += strlen(ti->data) + 1;
2643 if (blob.in_size > MAXSIZE) {
2644 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2645 setp > 1 ? "s" : "");
2648 strcpy(input, ti->data);
2649 input += strlen(ti->data);
2652 memcpy(space, &setp, sizeof(afs_int32));
2653 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2659 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2663 memcpy(&setp, input, sizeof(afs_int32));
2664 input += sizeof(afs_int32);
2666 fprintf(stderr, "No sysname name value was found\n");
2669 printf("Current sysname%s is", setp > 1 ? " list" : "");
2670 for (; setp > 0; --setp) {
2671 printf(" \'%s\'", input);
2672 input += strlen(input) + 1;
2678 static char *exported_types[] = { "null", "nfs", "" };
2680 ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2683 struct ViceIoctl blob;
2684 struct cmd_item *ti;
2685 int export = 0, type = 0, mode = 0, exp = 0, exportcall, pwsync =
2686 0, smounts = 0, clipags = 0, pagcb = 0;
2688 ti = as->parms[0].items;
2689 if (strcmp(ti->data, "nfs") == 0)
2690 type = 0x71; /* NFS */
2693 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n",
2697 ti = as->parms[1].items;
2699 if (strcmp(ti->data, "on") == 0)
2701 else if (strcmp(ti->data, "off") == 0)
2704 fprintf(stderr, "Illegal argument %s\n", ti->data);
2709 if ((ti = as->parms[2].items)) { /* -noconvert */
2710 if (strcmp(ti->data, "on") == 0)
2712 else if (strcmp(ti->data, "off") == 0)
2715 fprintf(stderr, "Illegal argument %s\n", ti->data);
2719 if ((ti = as->parms[3].items)) { /* -uidcheck */
2720 if (strcmp(ti->data, "on") == 0)
2722 else if (strcmp(ti->data, "off") == 0)
2725 fprintf(stderr, "Illegal argument %s\n", ti->data);
2729 if ((ti = as->parms[4].items)) { /* -submounts */
2730 if (strcmp(ti->data, "on") == 0)
2732 else if (strcmp(ti->data, "off") == 0)
2735 fprintf(stderr, "Illegal argument %s\n", ti->data);
2739 if ((ti = as->parms[5].items)) { /* -clipags */
2740 if (strcmp(ti->data, "on") == 0)
2742 else if (strcmp(ti->data, "off") == 0)
2745 fprintf(stderr, "Illegal argument %s\n", ti->data);
2749 if ((ti = as->parms[6].items)) { /* -pagcb */
2750 if (strcmp(ti->data, "on") == 0)
2752 else if (strcmp(ti->data, "off") == 0)
2755 fprintf(stderr, "Illegal argument %s\n", ti->data);
2760 (type << 24) | (pagcb << 10) | (clipags << 8) |
2761 (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2764 blob.in = (char *)&exportcall;
2765 blob.in_size = sizeof(afs_int32);
2766 blob.out = (char *)&exportcall;
2767 blob.out_size = sizeof(afs_int32);
2768 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2770 if (errno == ENODEV) {
2772 "Sorry, the %s-exporter type is currently not supported on this AFS client\n",
2773 exported_types[type]);
2780 if (exportcall & 1) {
2781 printf("'%s' translator is enabled with the following options:\n",
2782 exported_types[type]);
2783 printf("\tRunning in %s mode\n",
2784 (exportcall & 2 ? "strict unix" :
2785 "convert owner mode bits to world/other"));
2786 printf("\tRunning in %s mode\n",
2787 (exportcall & 4 ? "strict 'passwd sync'" :
2788 "no 'passwd sync'"));
2790 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
2791 "Only mounts to /afs allowed"));
2793 (exportcall & 16 ? "Client-assigned PAG's are used" :
2794 "Client-assigned PAG's are not used"));
2797 "Callbacks are made to get creds from new clients" :
2798 "Callbacks are not made to get creds from new clients"));
2800 printf("'%s' translator is disabled\n", exported_types[type]);
2807 GetCellCmd(struct cmd_syndesc *as, void *arock)
2810 struct ViceIoctl blob;
2811 struct afsconf_cell info;
2812 struct cmd_item *ti;
2819 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2820 for (ti = as->parms[0].items; ti; ti = ti->next) {
2822 blob.out_size = sizeof(args);
2823 blob.out = (caddr_t) & args;
2824 code = GetCellName(ti->data, &info);
2829 blob.in_size = 1 + strlen(info.name);
2830 blob.in = info.name;
2831 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2833 if (errno == ENOENT)
2834 fprintf(stderr, "%s: the cell named '%s' does not exist\n",
2837 Die(errno, info.name);
2841 printf("Cell %s status: ", info.name);
2847 printf("no setuid allowed");
2849 printf("setuid allowed");
2851 printf(", using old VLDB");
2858 SetCellCmd(struct cmd_syndesc *as, void *arock)
2861 struct ViceIoctl blob;
2862 struct afsconf_cell info;
2863 struct cmd_item *ti;
2871 /* Check arguments. */
2872 if (as->parms[1].items && as->parms[2].items) {
2873 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2877 /* figure stuff to set */
2881 if (!as->parms[1].items)
2882 args.stat |= 2; /* default to -nosuid */
2884 /* set stat for all listed cells */
2885 for (ti = as->parms[0].items; ti; ti = ti->next) {
2887 code = GetCellName(ti->data, &info);
2892 strcpy(args.cname, info.name);
2893 blob.in_size = sizeof(args);
2894 blob.in = (caddr_t) & args;
2896 blob.out = (caddr_t) 0;
2897 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2899 Die(errno, info.name); /* XXX added cell name to Die() call */
2907 GetCellName(char *cellName, struct afsconf_cell *info)
2909 struct afsconf_dir *tdir;
2912 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2915 "Could not process files in configuration directory (%s).\n",
2916 AFSDIR_CLIENT_ETC_DIRPATH);
2920 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2922 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2923 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
2932 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
2936 code = ugen_ClientInit(noAuthFlag, AFSDIR_CLIENT_ETC_DIRPATH,
2937 info->name, 0, &uclient,
2938 NULL, pn, rxkad_clear,
2939 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
2940 0, 0, USER_SERVICE_ID);
2945 static struct ViceIoctl gblob;
2946 static int debug = 0;
2948 * here follow some routines in suport of the setserverprefs and
2949 * getserverprefs commands. They are:
2950 * SetPrefCmd "top-level" routine
2951 * addServer adds a server to the list of servers to be poked into the
2952 * kernel. Will poke the list into the kernel if it threatens
2954 * pokeServers pokes the existing list of servers and ranks into the kernel
2955 * GetPrefCmd reads the Cache Manager's current list of server ranks
2959 * returns -1 if error message printed,
2961 * errno value if error and no error message printed
2968 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2969 if (code && (errno == EINVAL)) {
2970 struct setspref *ssp;
2971 ssp = (struct setspref *)gblob.in;
2972 if (!(ssp->flags & DBservers)) {
2973 gblob.in = (void *)&(ssp->servers[0]);
2974 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
2975 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
2976 return code ? errno : 0;
2979 "This cache manager does not support VL server preferences.\n");
2983 return code ? errno : 0;
2987 * returns -1 if error message printed,
2989 * errno value if error and no error message printed
2992 addServer(char *name, afs_int32 rank)
2995 struct setspref *ssp;
2997 struct hostent *thostent;
3002 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3004 #define MAXUSHORT ((unsigned short) ~0)
3008 thostent = hostutil_GetHostByName(name);
3010 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3014 ssp = (struct setspref *)(gblob.in);
3016 for (t = 0; thostent->h_addr_list[t]; t++) {
3017 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3018 code = pokeServers();
3021 ssp->num_servers = 0;
3024 sp = (struct spref *)(gblob.in + gblob.in_size);
3025 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3026 sizeof(afs_uint32));
3027 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3028 gblob.in_size += sizeof(struct spref);
3032 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3033 name, sp->rank, (long unsigned int) sp->server.s_addr);
3041 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3045 struct cmd_item *ti;
3048 struct setspref *ssp;
3049 int error = 0; /* -1 means error message printed,
3050 * >0 means errno value for unprinted message */
3052 ssp = (struct setspref *)space;
3054 ssp->num_servers = 0;
3055 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3058 gblob.out_size = MAXSIZE;
3062 fprintf(stderr, "Permission denied: requires root access.\n");
3066 ti = as->parms[2].items; /* -file */
3069 fprintf(stderr, "opening file %s\n", ti->data);
3070 if (!(infd = fopen(ti->data, "r"))) {
3074 while (fscanf(infd, "%79s%ld", name, (long int *)&rank) != EOF) {
3075 code = addServer(name, (unsigned short)rank);
3082 ti = as->parms[3].items; /* -stdin */
3084 while (scanf("%79s%ld", name, (long int *)&rank) != EOF) {
3085 code = addServer(name, (unsigned short)rank);
3091 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3096 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3100 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3104 code = pokeServers();
3108 printf("now working on vlservers, code=%d\n", code);
3110 ssp = (struct setspref *)space;
3111 ssp->flags = DBservers;
3112 ssp->num_servers = 0;
3113 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3116 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3121 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3125 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3130 if (as->parms[1].items) {
3132 printf("now poking vlservers\n");
3133 code = pokeServers();
3141 return error ? 1 : 0;
3147 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3150 struct cmd_item *ti;
3151 char *name, tbuffer[20];
3156 struct ViceIoctl blob;
3157 struct sprefrequest *in;
3158 struct sprefinfo *out;
3161 ti = as->parms[0].items; /* -file */
3164 fprintf(stderr, "opening file %s\n", ti->data);
3165 if (!(outfd = freopen(ti->data, "w", stdout))) {
3171 ti = as->parms[1].items; /* -numeric */
3173 ti = as->parms[2].items; /* -vlservers */
3174 vlservers |= (ti ? DBservers : 0);
3175 /* ti = as->parms[3].items; -cell */
3177 in = (struct sprefrequest *)space;
3181 blob.in_size = sizeof(struct sprefrequest);
3182 blob.in = (char *)in;
3184 blob.out_size = MAXSIZE;
3187 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3188 in->flags = vlservers;
3190 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3192 perror("getserverprefs pioctl");
3196 out = (struct sprefinfo *)blob.out;
3198 for (i = 0; i < out->num_servers; i++) {
3200 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3202 addr = ntohl(out->servers[i].server.s_addr);
3203 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3204 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3207 printf("%-50s %5u\n", name, out->servers[i].rank);
3210 in->offset = out->next_offset;
3211 } while (out->next_offset > 0);
3217 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
3220 struct ViceIoctl blob;
3221 struct cmd_item *ti;
3222 struct sbstruct tsb, tsb2;
3228 tsb.sb_thisfile = -1;
3229 ti = as->parms[0].items; /* -kbytes */
3231 if (!as->parms[1].items) {
3232 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3236 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3237 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3238 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3244 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3245 ti = as->parms[2].items; /* -allfiles */
3247 allfiles = strtol(ti->data, &t, 10) * 1024;
3248 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3249 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3255 /* -verbose or -file only or no options */
3256 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3257 || (!as->parms[0].items && !as->parms[1].items
3258 && !as->parms[2].items))
3261 blob.in = (char *)&tsb;
3262 blob.out = (char *)&tsb2;
3263 blob.in_size = blob.out_size = sizeof(struct sbstruct);
3264 memset(&tsb2, 0, sizeof(tsb2));
3266 /* once per -file */
3267 for (ti = as->parms[1].items; ti; ti = ti->next) {
3268 /* Do this solely to see if the file is there */
3269 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3271 Die(errno, ti->data);
3276 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
3278 Die(errno, ti->data);
3283 if (verbose && (blob.out_size == sizeof(tsb2))) {
3284 if (tsb2.sb_thisfile == -1) {
3285 fprintf(stdout, "Will store %s according to default.\n",
3289 "Will store up to %d kbytes of %s asynchronously.\n",
3290 (tsb2.sb_thisfile / 1024), ti->data);
3295 /* If no files - make at least one pioctl call, or
3296 * set the allfiles default if we need to.
3298 if (!as->parms[1].items || (allfiles != -1)) {
3299 tsb.sb_default = allfiles;
3300 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
3302 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3307 /* Having no arguments also reports the default store asynchrony */
3308 if (verbose && (blob.out_size == sizeof(tsb2))) {
3309 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3310 (tsb2.sb_default / 1024));
3318 SetCryptCmd(struct cmd_syndesc *as, void *arock)
3320 afs_int32 code = 0, flag;
3321 struct ViceIoctl blob;
3324 tp = as->parms[0].items->data;
3325 if (strcmp(tp, "on") == 0)
3327 else if (strcmp(tp, "off") == 0)
3330 fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3334 blob.in = (char *)&flag;
3335 blob.in_size = sizeof(flag);
3337 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3345 GetCryptCmd(struct cmd_syndesc *as, void *arock)
3347 afs_int32 code = 0, flag;
3348 struct ViceIoctl blob;
3353 blob.out_size = sizeof(flag);
3356 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3362 memcpy(&flag, tp, sizeof(afs_int32));
3363 printf("Security level is currently ");
3365 printf("crypt (data security).\n");
3372 #ifdef AFS_DISCON_ENV
3373 static char *modenames[] = {
3376 "readonly", /* Not currently supported */
3377 "fetchonly", /* Not currently supported */
3378 "partial", /* Not currently supported */
3382 static char *policynames[] = {
3385 "closer", /* Not currently supported. */
3386 "manual", /* Not currently supported. */
3391 DisconCmd(struct cmd_syndesc *as, void *arock)
3393 struct cmd_item *ti;
3396 int modelen, policylen;
3397 afs_int32 mode, policy, code;
3398 struct ViceIoctl blob;
3403 space[0] = space[1] = space[2] = 0;
3405 ti = as->parms[0].items;
3407 modename = ti->data;
3408 modelen = strlen(modename);
3409 for (mode = 0; modenames[mode] != NULL; mode++)
3410 if (!strncasecmp(modename, modenames[mode], modelen))
3412 if (modenames[mode] == NULL)
3413 printf("Unknown discon mode \"%s\"\n", modename);
3415 space[0] = mode + 1;
3418 ti = as->parms[1].items;
3420 policyname = ti->data;
3421 policylen = strlen(policyname);
3422 for (policy = 0; policynames[policy] != NULL; policy++)
3423 if (!strncasecmp(policyname, policynames[policy], policylen))
3425 if (policynames[policy] == NULL)
3426 printf("Unknown discon mode \"%s\"\n", policyname);
3428 space[1] = policy + 1;
3432 if (as->parms[2].items) {
3434 printf("force on\n");
3438 blob.in_size = 3 * sizeof(afs_int32);
3440 blob.out_size = sizeof(mode);
3442 code = pioctl(0, VIOC_DISCON, &blob, 1);
3446 memcpy(&mode, space, sizeof mode);
3447 if (mode < sizeof modenames / sizeof (char *))
3448 printf("Discon mode is now \"%s\"\n", modenames[mode]);
3450 printf("Unknown discon mode %d\n", mode);
3457 #include "AFS_component_version_number.c"
3460 main(int argc, char **argv)
3463 struct cmd_syndesc *ts;
3465 #ifdef AFS_AIX32_ENV
3467 * The following signal action for AIX is necessary so that in case of a
3468 * crash (i.e. core is generated) we can include the user's data section
3469 * in the core dump. Unfortunately, by default, only a partial core is
3470 * generated which, in many cases, isn't too useful.
3472 struct sigaction nsa;
3474 sigemptyset(&nsa.sa_mask);
3475 nsa.sa_handler = SIG_DFL;
3476 nsa.sa_flags = SA_FULLDUMP;
3477 sigaction(SIGSEGV, &nsa, NULL);
3480 /* try to find volume location information */
3481 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
3482 "get client network interface addresses");
3483 cmd_CreateAlias(ts, "gc");
3485 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
3486 "set client network interface addresses");
3487 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3488 "client network interfaces");
3489 cmd_CreateAlias(ts, "sc");
3491 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL,
3492 "set server ranks");
3493 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3494 "fileserver names and ranks");
3495 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3496 "VL server names and ranks");
3497 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3498 "input from named file");
3499 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3500 cmd_CreateAlias(ts, "sp");
3502 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL,
3503 "get server ranks");
3504 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3505 "output to named file");
3506 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3507 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3508 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3509 cmd_CreateAlias(ts, "gp");
3511 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
3512 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3513 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3514 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3515 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL,
3516 "apply to negative rights");
3517 parm_setacl_id = ts->nParms;
3518 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL,
3519 "initial directory acl (DFS only)");
3520 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL,
3521 "initial file acl (DFS only)");
3522 cmd_CreateAlias(ts, "sa");
3524 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL,
3525 "list access control list");
3526 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3527 parm_listacl_id = ts->nParms;
3528 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3529 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3530 cmd_CreateAlias(ts, "la");
3532 ts = cmd_CreateSyntax("getcalleraccess", GetCallerAccess, NULL,
3533 "list callers access");
3534 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3535 cmd_CreateAlias(ts, "gca");
3537 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL,
3538 "clean up access control list");
3539 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3541 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL,
3542 "copy access control list");
3543 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0,
3544 "source directory (or DFS file)");
3545 cmd_AddParm(ts, "-todir", CMD_LIST, 0,
3546 "destination directory (or DFS file)");
3547 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3548 "first clear dest access list");
3549 parm_copyacl_id = ts->nParms;
3550 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3551 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3553 cmd_CreateAlias(ts, "ca");
3555 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
3556 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3557 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
3558 "flush mount symlink from cache");
3559 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3561 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
3562 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3563 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL,
3564 "disk space quota in 1K units");
3566 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL,
3567 "disk space guaranteed");
3568 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3570 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL,
3572 cmd_CreateAlias(ts, "sv");
3574 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL,
3575 "control Cache Manager messages");
3576 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL,
3577 "[user|console|all|none]");
3579 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
3580 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3581 cmd_CreateAlias(ts, "lv");
3582 cmd_CreateAlias(ts, "listvol");
3584 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
3585 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3586 cmd_CreateAlias(ts, "lq");
3588 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL,
3589 "show server disk space usage");
3590 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3591 cmd_CreateAlias(ts, "df");
3593 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
3594 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3596 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
3597 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3599 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
3600 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3601 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3602 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3603 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3604 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3605 "don't check name with VLDB");
3607 #if defined(AFS_CACHE_BYPASS)
3608 ts = cmd_CreateSyntax("bypassthreshold", BypassThresholdCmd, 0,
3609 "get/set cache bypass file size threshold");
3610 cmd_AddParm(ts, "-size", CMD_SINGLE, CMD_OPTIONAL, "file size");
3617 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3621 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
3622 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3624 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL,
3625 "check local cell's servers");
3626 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3627 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3628 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3629 "just list, don't check");
3630 cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL,
3631 "seconds between probes");
3633 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL,
3634 "check volumeID/name mappings");
3635 cmd_CreateAlias(ts, "checkbackups");
3638 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL,
3640 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3641 "size in 1K byte blocks (0 => reset)");
3642 cmd_CreateAlias(ts, "cachesize");
3644 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL,
3645 "reset size back to boot value");
3647 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL,
3648 "get cache usage info");
3649 cmd_AddParm(ts, "-files", CMD_FLAG, CMD_OPTIONAL, "Show cach files used as well");
3650 cmd_AddParm(ts, "-excessive", CMD_FLAG, CMD_OPTIONAL, "excessively verbose cache stats");
3652 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL,
3653 "list configured cells");
3654 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3656 ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, NULL,
3657 "list configured cell aliases");
3659 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
3660 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3661 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3663 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3665 cmd_CreateAlias(ts, "sq");
3667 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
3668 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3669 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3670 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL,
3671 "linked cell name");
3673 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
3674 "configure new cell alias");
3675 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
3676 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
3678 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3680 * Turn this on only if you wish to be able to talk to a server which is listening
3681 * on alternative ports. This is not intended for general use and may not be
3682 * supported in the cache manager. It is not a way to run two servers at the
3683 * same host, since the cache manager cannot properly distinguish those two hosts.
3685 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL,
3686 "cell's fileserver port");
3687 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL,
3688 "cell's vldb server port");
3691 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
3692 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3694 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
3695 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3697 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
3700 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, NULL, "obsolete (listed primary cell)");
3703 /* set cache monitor host address */
3704 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, (char *)CMD_HIDDEN);
3705 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL,
3706 "host name or 'off'");
3707 cmd_CreateAlias(ts, "mariner");
3709 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
3710 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3712 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
3713 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3714 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3715 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL,
3716 "disallow setuid programs");
3718 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL,
3719 "flush all data in volume");
3720 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3722 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL,
3723 "get/set sysname (i.e. @sys) value");
3724 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3726 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL,
3727 "enable/disable translators to AFS");
3728 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3729 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL,
3730 "start/stop translator (on | off)");
3731 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL,
3732 "convert from afs to unix mode (on | off)");
3733 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL,
3734 "run on strict 'uid check' mode (on | off)");
3735 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
3736 "allow nfs mounts to subdirs of /afs/.. (on | off)");
3737 cmd_AddParm(ts, "-clipags", CMD_SINGLE, CMD_OPTIONAL,
3738 "enable use of client-assigned PAG's (on | off)");
3739 cmd_AddParm(ts, "-pagcb", CMD_SINGLE, CMD_OPTIONAL,
3740 "enable callbacks to get creds from new clients (on | off)");
3743 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
3744 "store to server after file close");
3745 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL,
3746 "asynchrony for specified names");
3747 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3748 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL,
3749 "new default (KB)");
3750 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3751 cmd_CreateAlias(ts, "sb");
3753 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL,
3754 "set cache manager encryption flag");
3755 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3757 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL,
3758 "get cache manager encryption flag");
3760 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
3761 "Manage per process RX statistics");
3762 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3763 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3764 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3766 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
3767 "Manage per peer RX statistics");
3768 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3769 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3770 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3772 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
3773 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
3775 /* try to find volume location information */
3776 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL,
3777 "get fid for file(s)");
3778 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3780 #ifdef AFS_DISCON_ENV
3781 ts = cmd_CreateSyntax("discon", DisconCmd, NULL,
3782 "disconnection mode");
3783 cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_REQUIRED, "offline | online");
3784 cmd_AddParm(ts, "-policy", CMD_SINGLE, CMD_OPTIONAL, "client | server");
3785 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Force reconnection, despite any synchronization issues.");
3788 ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, NULL, "nuke credentials for NFS client");
3789 cmd_AddParm(ts, "-addr", CMD_SINGLE, 0, "host name or address");
3791 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
3792 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_REQUIRED, "generate a new UUID");
3794 ts = cmd_CreateSyntax("precache", PreCacheCmd, 0,
3795 "set precache size");
3796 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3797 "size in 1K byte blocks (0 => disable)");
3799 code = cmd_Dispatch(argc, argv);
3807 Die(int errnum, char *filename)
3813 "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3816 fprintf(stderr, "%s: Invalid argument.\n", pn);
3820 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3822 fprintf(stderr, "%s: no such file returned\n", pn);
3826 "%s: You can not change a backup or readonly volume\n", pn);
3832 "%s: You don't have the required access rights on '%s'\n",
3836 "%s: You do not have the required rights to do this operation\n",
3841 fprintf(stderr, "%s:'%s'", pn, filename);
3843 fprintf(stderr, "%s", pn);
3844 fprintf(stderr, ": %s\n", afs_error_message(errnum));
3849 /* get clients interface addresses */
3851 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3854 struct ViceIoctl blob;
3855 struct sprefrequest *in;
3856 struct sprefinfo *out;
3858 in = (struct sprefrequest *)space;
3862 blob.in_size = sizeof(struct sprefrequest);
3863 blob.in = (char *)in;
3865 blob.out_size = MAXSIZE;
3868 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3869 /* returns addr in network byte order */
3870 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3872 perror("getClientInterfaceAddr pioctl");
3878 out = (struct sprefinfo *)blob.out;
3879 for (i = 0; i < out->num_servers; i++) {
3882 addr = ntohl(out->servers[i].server.s_addr);
3883 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3884 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3885 printf("%-50s\n", tbuffer);
3887 in->offset = out->next_offset;
3889 } while (out->next_offset > 0);
3895 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
3897 afs_int32 code, addr;
3898 struct cmd_item *ti;
3899 struct ViceIoctl blob;
3900 struct setspref *ssp;
3901 int sizeUsed = 0, i, flag;
3902 afs_uint32 existingAddr[1024]; /* existing addresses on this host */
3906 ssp = (struct setspref *)space;
3907 ssp->num_servers = 0;
3910 blob.out_size = MAXSIZE;
3913 fprintf(stderr, "Permission denied: requires root access.\n");
3917 /* extract all existing interface addresses */
3918 existNu = rx_getAllAddr(existingAddr, 1024);
3922 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
3923 for (ti = as->parms[0].items; ti; ti = ti->next) {
3924 if (sizeUsed >= sizeof(space)) {
3925 fprintf(stderr, "No more space\n");
3928 addr = extractAddr(ti->data, 20); /* network order */
3929 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
3930 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
3935 /* see if it is an address that really exists */
3936 for (flag = 0, i = 0; i < existNu; i++)
3937 if (existingAddr[i] == addr) {
3941 if (!flag) { /* this is an nonexistent address */
3942 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
3946 /* copy all specified addr into ioctl buffer */
3947 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
3948 printf("Adding 0x%08x\n", addr);
3950 sizeUsed += sizeof(struct spref);
3952 if (ssp->num_servers < 1) {
3953 fprintf(stderr, "No addresses specified\n");
3956 blob.in_size = sizeUsed - sizeof(struct spref);
3958 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
3968 FlushMountCmd(struct cmd_syndesc *as, void *arock)
3971 struct ViceIoctl blob;
3972 struct cmd_item *ti;
3973 char orig_name[1024]; /*Original name, may be modified */
3974 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
3975 char parent_dir[1024]; /*Parent directory of true name */
3976 char *last_component; /*Last component of true name */
3977 struct stat statbuff; /*Buffer for status info */
3978 int link_chars_read; /*Num chars read in readlink() */
3979 int thru_symlink; /*Did we get to a mount point via a symlink? */
3982 for (ti = as->parms[0].items; ti; ti = ti->next) {
3985 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
3988 if (lstat(orig_name, &statbuff) < 0) {
3989 /* if lstat fails, we should still try the pioctl, since it
3990 * may work (for example, lstat will fail, but pioctl will
3991 * work if the volume of offline (returning ENODEV). */
3992 statbuff.st_mode = S_IFDIR; /* lie like pros */
3996 * The lstat succeeded. If the given file is a symlink, substitute
3997 * the file name with the link name.
3999 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
4002 * Read name of resolved file.
4004 link_chars_read = readlink(orig_name, true_name, 1024);
4005 if (link_chars_read <= 0) {
4007 "%s: Can't read target name for '%s' symbolic link!\n",
4014 * Add a trailing null to what was read, bump the length.
4016 true_name[link_chars_read++] = 0;
4019 * If the symlink is an absolute pathname, we're fine. Otherwise, we
4020 * have to create a full pathname using the original name and the
4021 * relative symlink name. Find the rightmost slash in the original
4022 * name (we know there is one) and splice in the symlink value.
4024 if (true_name[0] != '/') {
4025 last_component = (char *)strrchr(orig_name, '/');
4026 strcpy(++last_component, true_name);
4027 strcpy(true_name, orig_name);
4030 strcpy(true_name, orig_name);
4033 * Find rightmost slash, if any.
4035 last_component = (char *)strrchr(true_name, '/');
4036 if (last_component == (char *)true_name) {
4037 strcpy(parent_dir, "/");
4040 else if (last_component != (char *)NULL) {
4042 * Found it. Designate everything before it as the parent directory,
4043 * everything after it as the final component.
4045 strncpy(parent_dir, true_name, last_component - true_name);
4046 parent_dir[last_component - true_name] = 0;
4047 last_component++; /*Skip the slash */
4050 * No slash appears in the given file name. Set parent_dir to the current
4051 * directory, and the last component as the given name.
4053 strcpy(parent_dir, ".");
4054 last_component = true_name;
4057 if (strcmp(last_component, ".") == 0
4058 || strcmp(last_component, "..") == 0) {
4060 "%s: you may not use '.' or '..' as the last component\n",
4062 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
4068 blob.in = last_component;
4069 blob.in_size = strlen(last_component) + 1;
4071 memset(space, 0, MAXSIZE);
4073 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4076 if (errno == EINVAL) {
4077 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4079 Die(errno, (ti->data ? ti->data : parent_dir));
4088 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4091 afs_int32 flags = 0;
4092 struct ViceIoctl blob;
4094 if (as->parms[0].items) { /* -enable */
4095 flags |= AFSCALL_RXSTATS_ENABLE;
4097 if (as->parms[1].items) { /* -disable */
4098 flags |= AFSCALL_RXSTATS_DISABLE;
4100 if (as->parms[2].items) { /* -clear */
4101 flags |= AFSCALL_RXSTATS_CLEAR;
4104 fprintf(stderr, "You must specify at least one argument\n");
4108 blob.in = (char *)&flags;
4109 blob.in_size = sizeof(afs_int32);
4112 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4122 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4125 afs_int32 flags = 0;
4126 struct ViceIoctl blob;
4128 if (as->parms[0].items) { /* -enable */
4129 flags |= AFSCALL_RXSTATS_ENABLE;
4131 if (as->parms[1].items) { /* -disable */
4132 flags |= AFSCALL_RXSTATS_DISABLE;
4134 if (as->parms[2].items) { /* -clear */
4135 flags |= AFSCALL_RXSTATS_CLEAR;
4138 fprintf(stderr, "You must specify at least one argument\n");
4142 blob.in = (char *)&flags;
4143 blob.in_size = sizeof(afs_int32);
4146 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4156 GetFidCmd(struct cmd_syndesc *as, void *arock)
4158 struct ViceIoctl blob;
4159 struct cmd_item *ti;
4160 for (ti = as->parms[0].items; ti; ti = ti->next) {
4161 struct VenusFid vfid;
4163 blob.out_size = sizeof(struct VenusFid);
4164 blob.out = (char *) &vfid;
4167 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
4168 printf("File %s (%u.%u.%u) contained in volume %u\n",
4169 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,