2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
18 #include <afs/afs_consts.h>
19 #include <afs/afs_args.h>
22 #include <afs/venus.h>
23 #include <afs/com_err.h>
24 #include <afs/afs_consts.h>
28 #include "afs/prs_fs.h"
29 #include <afs/afsint.h>
30 #include <afs/cellconfig.h>
33 #include <rx/rx_globals.h>
34 #include <afs/vldbint.h>
35 #include <afs/volser.h>
36 #include <afs/vlserver.h>
38 #include <afs/com_err.h>
39 #include <afs/ptclient.h>
40 #include <afs/ptuser.h>
41 #include <afs/afsutil.h>
42 #include <afs/sys_prototypes.h>
45 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
46 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
48 static char space[AFS_PIOCTL_MAXSIZE];
49 static char tspace[1024];
50 static struct ubik_client *uclient;
52 static int GetClientAddrsCmd(struct cmd_syndesc *, void *);
53 static int SetClientAddrsCmd(struct cmd_syndesc *, void *);
54 static int FlushMountCmd(struct cmd_syndesc *, void *);
55 static int RxStatProcCmd(struct cmd_syndesc *, void *);
56 static int RxStatPeerCmd(struct cmd_syndesc *, void *);
57 static int GetFidCmd(struct cmd_syndesc *, void *);
58 static int UuidCmd(struct cmd_syndesc *, void *);
60 static char pn[] = "fs";
61 static int rxInitDone = 0;
65 static void ZapList(struct AclEntry *);
66 static int PruneList(struct AclEntry **, int);
67 static int CleanAcl(struct Acl *, char *);
68 static int SetVolCmd(struct cmd_syndesc *as, void *arock);
69 static int GetCellName(char *, struct afsconf_cell *);
70 static void Die(int, char *);
73 * Character to use between name and rights in printed representation for
76 #define DFS_SEPARATOR ' '
78 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
81 int dfs; /* Originally true if a dfs acl; now also the type
82 * of the acl (1, 2, or 3, corresponding to object,
83 * initial dir, or initial object). */
84 sec_rgy_name_t cell; /* DFS cell name */
87 struct AclEntry *pluslist;
88 struct AclEntry *minuslist;
92 struct AclEntry *next;
98 afs_int32 callerAccess;
105 ZapAcl(struct Acl *acl)
109 ZapList(acl->pluslist);
110 ZapList(acl->minuslist);
115 foldcmp(char *a, char *b)
121 if (t >= 'A' && t <= 'Z')
123 if (u >= 'A' && u <= 'Z')
133 * Mods for the AFS/DFS protocol translator.
135 * DFS rights. It's ugly to put these definitions here, but they
136 * *cannot* change, because they're part of the wire protocol.
137 * In any event, the protocol translator will guarantee these
138 * assignments for AFS cache managers.
140 #define DFS_READ 0x01
141 #define DFS_WRITE 0x02
142 #define DFS_EXECUTE 0x04
143 #define DFS_CONTROL 0x08
144 #define DFS_INSERT 0x10
145 #define DFS_DELETE 0x20
147 /* the application definable ones (backwards from AFS) */
148 #define DFS_USR0 0x80000000 /* "A" bit */
149 #define DFS_USR1 0x40000000 /* "B" bit */
150 #define DFS_USR2 0x20000000 /* "C" bit */
151 #define DFS_USR3 0x10000000 /* "D" bit */
152 #define DFS_USR4 0x08000000 /* "E" bit */
153 #define DFS_USR5 0x04000000 /* "F" bit */
154 #define DFS_USR6 0x02000000 /* "G" bit */
155 #define DFS_USR7 0x01000000 /* "H" bit */
156 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
157 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
160 * Offset of -id switch in command structure for various commands.
161 * The -if switch is the next switch always.
163 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
166 * Determine whether either the -id or -if switches are present, and
167 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
169 /* int id; Offset of -id switch; -if is next switch */
171 getidf(struct cmd_syndesc *as, int id)
175 if (as->parms[id].items) {
178 if (as->parms[id + 1].items) {
183 "%s: you may specify either -id or -if, but not both switches\n",
191 PRights(afs_int32 arights, int dfs)
194 if (arights & PRSFS_READ)
196 if (arights & PRSFS_LOOKUP)
198 if (arights & PRSFS_INSERT)
200 if (arights & PRSFS_DELETE)
202 if (arights & PRSFS_WRITE)
204 if (arights & PRSFS_LOCK)
206 if (arights & PRSFS_ADMINISTER)
208 if (arights & PRSFS_USR0)
210 if (arights & PRSFS_USR1)
212 if (arights & PRSFS_USR2)
214 if (arights & PRSFS_USR3)
216 if (arights & PRSFS_USR4)
218 if (arights & PRSFS_USR5)
220 if (arights & PRSFS_USR6)
222 if (arights & PRSFS_USR7)
225 if (arights & DFS_READ)
229 if (arights & DFS_WRITE)
233 if (arights & DFS_EXECUTE)
237 if (arights & DFS_CONTROL)
241 if (arights & DFS_INSERT)
245 if (arights & DFS_DELETE)
249 if (arights & (DFS_USRALL))
251 if (arights & DFS_USR0)
253 if (arights & DFS_USR1)
255 if (arights & DFS_USR2)
257 if (arights & DFS_USR3)
259 if (arights & DFS_USR4)
261 if (arights & DFS_USR5)
263 if (arights & DFS_USR6)
265 if (arights & DFS_USR7)
271 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
275 struct ViceIoctl blob;
279 blob.out_size = AFS_PIOCTL_MAXSIZE;
282 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
284 if ((errno == EINVAL) || (errno == ENOENT))
290 /* return a static pointer to a buffer */
295 strlcpy(tspace, apath, sizeof(tspace));
296 tp = strrchr(tspace, '/');
297 if (tp == (char *)tspace)
299 else if (tp == NULL) {
307 /* added relative add resp. delete */
308 /* (so old add really means to set) */
309 enum rtype { add, destroy, deny, reladd, reldel };
312 Convert(char *arights, int dfs, enum rtype *rtypep)
316 char *tcp; /* to walk through the rights string */
318 *rtypep = add; /* add rights, by default */
320 /* analyze last character of string */
321 tcp = arights + strlen(arights);
322 if ( tcp-- > arights ) { /* assure non-empty string */
324 *rtypep = reladd; /* '+' indicates more rights */
325 else if ( *tcp == '-' )
326 *rtypep = reldel; /* '-' indicates less rights */
327 else if ( *tcp == '=' )
328 *rtypep = add; /* '=' also allows old behaviour */
330 tcp++; /* back to original null byte */
331 *tcp = '\0'; /* do not disturb old strcmp-s */
335 if (!strcmp(arights, "null")) {
339 if (!strcmp(arights, "read"))
340 return DFS_READ | DFS_EXECUTE;
341 if (!strcmp(arights, "write"))
342 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
344 if (!strcmp(arights, "all"))
345 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
346 DFS_WRITE | DFS_CONTROL;
348 if (!strcmp(arights, "read"))
349 return PRSFS_READ | PRSFS_LOOKUP;
350 if (!strcmp(arights, "write"))
351 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
352 PRSFS_WRITE | PRSFS_LOCK;
353 if (!strcmp(arights, "mail"))
354 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
355 if (!strcmp(arights, "all"))
356 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
357 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
359 if (!strcmp(arights, "none")) {
360 *rtypep = destroy; /* Remove entire entry */
365 while ((tc = *tcp++ )) {
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 = malloc(sizeof(struct cmd_item));
464 ti->next = (struct cmd_item *)0;
465 ti->data = malloc(2);
467 strcpy(ti->data, ".");
472 ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights,
475 struct AclEntry *tlist;
476 tlist = (plus ? al->pluslist : al->minuslist);
477 tlist = FindList(tlist, aname);
479 /* Found the item already in the list.
480 * modify rights in case of reladd and reladd only,
481 * use standard - add, ie. set - otherwise
483 if ( artypep == NULL )
484 tlist->rights = arights;
485 else if ( *artypep == reladd )
486 tlist->rights |= arights;
487 else if ( *artypep == reldel )
488 tlist->rights &= ~arights;
490 tlist->rights = arights;
493 al->nplus -= PruneList(&al->pluslist, al->dfs);
495 al->nminus -= PruneList(&al->minuslist, al->dfs);
498 if ( artypep != NULL && *artypep == reldel )
499 return; /* can't reduce non-existing rights */
501 /* Otherwise we make a new item and plug in the new data. */
502 tlist = malloc(sizeof(struct AclEntry));
504 strcpy(tlist->name, aname);
505 tlist->rights = arights;
507 tlist->next = al->pluslist;
508 al->pluslist = tlist;
510 if (arights == 0 || arights == -1)
511 al->nplus -= PruneList(&al->pluslist, al->dfs);
513 tlist->next = al->minuslist;
514 al->minuslist = tlist;
517 al->nminus -= PruneList(&al->minuslist, al->dfs);
522 ZapList(struct AclEntry *alist)
524 struct AclEntry *tp, *np;
525 for (tp = alist; tp; tp = np) {
532 PruneList(struct AclEntry **ae, int dfs)
534 struct AclEntry **lp;
535 struct AclEntry *te, *ne;
539 for (te = *ae; te; te = ne) {
540 if ((!dfs && te->rights == 0) || te->rights == -1) {
556 while (*astr != '\n')
563 * Create an empty acl, taking into account whether the acl pointed
564 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
565 * can recover from problems caused by bogus ACL's (in that case, always
566 * assume that the acl is AFS: for DFS, the user can always resort to
567 * acl_edit, but for AFS there may be no other way out).
575 tp = malloc(sizeof(struct Acl));
577 tp->nplus = tp->nminus = 0;
578 tp->pluslist = tp->minuslist = 0;
580 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
587 int nplus, nminus, i, trights;
589 struct AclEntry *first, *last, *tl;
592 ta = malloc(sizeof(struct Acl));
595 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
596 astr = SkipLine(astr);
597 sscanf(astr, "%d", &ta->nminus);
598 astr = SkipLine(astr);
605 for (i = 0; i < nplus; i++) {
606 sscanf(astr, "%100s %d", tname, &trights);
607 astr = SkipLine(astr);
608 tl = malloc(sizeof(struct AclEntry));
612 strcpy(tl->name, tname);
613 tl->rights = trights;
619 ta->pluslist = first;
623 for (i = 0; i < nminus; i++) {
624 sscanf(astr, "%100s %d", tname, &trights);
625 astr = SkipLine(astr);
626 tl = malloc(sizeof(struct AclEntry));
630 strcpy(tl->name, tname);
631 tl->rights = trights;
637 ta->minuslist = first;
643 PrintStatus(VolumeStatus * status, char *name, char *offmsg)
645 printf("Volume status for vid = %u named %s\n", status->Vid, name);
647 printf("Current offline message is %s\n", offmsg);
648 printf("Current disk quota is ");
649 if (status->MaxQuota != 0)
650 printf("%d\n", status->MaxQuota);
652 printf("unlimited\n");
653 printf("Current blocks used are %d\n", status->BlocksInUse);
654 printf("The partition has %d blocks available out of %d\n\n",
655 status->PartBlocksAvail, status->PartMaxBlocks);
659 static const char power_letter[] = {
668 HumanPrintSpace(afs_int32 int_space)
671 int exponent_max = sizeof(power_letter) - 1;
672 float space = int_space;
674 while (space >= 1024 && exponent < exponent_max) {
678 printf("%9.1f%c", space, power_letter[exponent]);
682 QuickPrintStatus(VolumeStatus * status, char *name, int human)
684 double QuotaUsed = 0.0;
685 double PartUsed = 0.0;
687 printf("%-25.25s", name);
689 if (status->MaxQuota != 0) {
692 HumanPrintSpace(status->MaxQuota);
694 HumanPrintSpace(status->BlocksInUse);
697 printf(" %10d %10d", status->MaxQuota, status->BlocksInUse);
699 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
701 printf(" no limit ");
703 HumanPrintSpace(status->BlocksInUse);
705 printf("%10d", status->BlocksInUse);
707 if (QuotaUsed > 90.0) {
708 printf("%5.0f%%<<", QuotaUsed);
711 printf("%5.0f%% ", QuotaUsed);
714 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
716 if (PartUsed > 97.0) {
717 printf("%9.0f%%<<", PartUsed);
720 printf("%9.0f%% ", PartUsed);
722 printf(" <<WARNING\n");
729 QuickPrintSpace(VolumeStatus * status, char *name, int human)
731 double PartUsed = 0.0;
733 printf("%-25.25s", name);
736 HumanPrintSpace(status->PartMaxBlocks);
737 HumanPrintSpace(status->PartMaxBlocks - status->PartBlocksAvail);
738 HumanPrintSpace(status->PartBlocksAvail);
741 printf("%10d%10d%10d", status->PartMaxBlocks,
742 status->PartMaxBlocks - status->PartBlocksAvail,
743 status->PartBlocksAvail);
747 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
749 if (PartUsed > 90.0) {
750 printf(" %4.0f%%<<", PartUsed);
753 printf(" %4.0f%% ", PartUsed);
755 printf(" <<WARNING\n");
762 AclToString(struct Acl *acl)
764 static char mydata[AFS_PIOCTL_MAXSIZE];
765 char tstring[AFS_PIOCTL_MAXSIZE];
770 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
773 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
774 for (tp = acl->pluslist; tp; tp = tp->next) {
775 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
776 strcat(mydata, tstring);
778 for (tp = acl->minuslist; tp; tp = tp->next) {
779 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
780 strcat(mydata, tstring);
786 SetACLCmd(struct cmd_syndesc *as, void *arock)
789 struct ViceIoctl blob;
791 struct cmd_item *ti, *ui;
795 int idf = getidf(as, parm_setacl_id);
798 if (as->parms[2].items)
802 plusp = !(as->parms[3].items);
803 for (ti = as->parms[0].items; ti; ti = ti->next) {
804 blob.out_size = AFS_PIOCTL_MAXSIZE;
806 blob.in = blob.out = space;
807 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
809 Die(errno, ti->data);
816 ta = ParseAcl(space);
817 if (!plusp && ta->dfs) {
819 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
821 "(you may specify \"null\" to revoke all rights, however)\n");
829 ta = EmptyAcl(space);
831 ta = ParseAcl(space);
832 CleanAcl(ta, ti->data);
833 for (ui = as->parms[1].items; ui; ui = ui->next->next) {
837 "%s: Missing second half of user/access pair.\n", pn);
841 rights = Convert(ui->next->data, ta->dfs, &rtype);
842 if (rtype == destroy && !ta->dfs) {
843 struct AclEntry *tlist;
845 tlist = (plusp ? ta->pluslist : ta->minuslist);
846 if (!FindList(tlist, ui->data))
849 if (rtype == deny && !ta->dfs)
851 if (rtype == destroy && ta->dfs)
853 ChangeList(ta, plusp, ui->data, rights, &rtype);
855 blob.in = AclToString(ta);
857 blob.in_size = 1 + strlen(blob.in);
858 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
860 if (errno == EINVAL) {
862 static char *fsenv = 0;
864 fsenv = (char *)getenv("FS_EXPERT");
867 "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n",
871 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
872 "\nPossible reasons for this include:\n\n",
873 " -You may have specified an inappropriate combination of rights.\n",
874 " For example, some DFS-supported filesystems may not allow you to\n",
875 " drop the \"c\" right from \"user_obj\".\n\n",
876 " -A mask_obj may be required (it is likely required by the underlying\n",
877 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
878 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
879 " does not automatically create or update the mask_obj. Try setting\n",
880 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
881 " users or groups. You can do this with a single command, such as\n",
882 " \"fs sa mask_obj all user:somename read\"\n\n",
883 " -A specified user or group may not exist.\n\n",
884 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
885 " This is probably not allowed by the underlying file system.\n\n",
886 " -If you add a user or group to a DFS ACL, remember that it must be\n",
887 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
888 " may be local requirements on the format of the user or group name.\n",
889 " Check with your cell administrator.\n\n",
890 " -Or numerous other possibilities. It would be great if we could be more\n",
891 " precise about the actual problem, but for various reasons, this is\n",
892 " impractical via this interface. If you can't figure it out, you\n",
893 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
894 " whatever is provided). You may get better results. Good luck!\n\n",
895 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
899 "%s: Invalid argument, possible reasons include:\n",
901 fprintf(stderr, "\t-File not in AFS\n");
903 "\t-Too many users on access control list\n");
905 "\t-Tried to add non-existent user to access control list\n");
908 Die(errno, ti->data);
920 CopyACLCmd(struct cmd_syndesc *as, void *arock)
923 struct ViceIoctl blob;
924 struct Acl *fa, *ta = 0;
928 int idf = getidf(as, parm_copyacl_id);
931 if (as->parms[2].items)
935 blob.out_size = AFS_PIOCTL_MAXSIZE;
937 blob.in = blob.out = space;
938 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
940 Die(errno, as->parms[0].items->data);
943 fa = ParseAcl(space);
944 CleanAcl(fa, as->parms[0].items->data);
945 for (ti = as->parms[1].items; ti; ti = ti->next) {
946 blob.out_size = AFS_PIOCTL_MAXSIZE;
948 blob.in = blob.out = space;
949 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
951 Die(errno, ti->data);
959 ta = EmptyAcl(space);
961 ta = ParseAcl(space);
962 CleanAcl(ta, ti->data);
963 if (ta->dfs != fa->dfs) {
965 "%s: incompatible file system types: acl not copied to %s; aborted\n",
971 if (!clear && strcmp(ta->cell, fa->cell) != 0) {
973 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
978 strcpy(ta->cell, fa->cell);
980 /* NULL rtype for standard handling */
981 for (tp = fa->pluslist; tp; tp = tp->next)
982 ChangeList(ta, 1, tp->name, tp->rights, NULL);
983 for (tp = fa->minuslist; tp; tp = tp->next)
984 ChangeList(ta, 0, tp->name, tp->rights, NULL);
985 blob.in = AclToString(ta);
987 blob.in_size = 1 + strlen(blob.in);
988 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
990 if (errno == EINVAL) {
992 "%s: Invalid argument, possible reasons include:\n",
994 fprintf(stderr, "\t-File not in AFS\n");
996 Die(errno, ti->data);
1007 /* pioctl() call to get the cellname of a pathname */
1009 GetCell(char *fname, char *cellname)
1012 struct ViceIoctl blob;
1015 blob.out_size = MAXCELLCHARS;
1016 blob.out = cellname;
1018 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1019 return code ? errno : 0;
1022 /* Check if a username is valid: If it contains only digits (or a
1023 * negative sign), then it might be bad. We then query the ptserver
1027 BadName(char *aname, char *fname)
1029 afs_int32 tc, code, id;
1031 char cell[MAXCELLCHARS];
1033 for (nm = aname; (tc = *nm); nm++) {
1034 /* all must be '-' or digit to be bad */
1035 if (tc != '-' && (tc < '0' || tc > '9'))
1039 /* Go to the PRDB and see if this all number username is valid */
1040 code = GetCell(fname, cell);
1044 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
1045 code = pr_SNameToId(aname, &id);
1048 /* 1=>Not-valid; 0=>Valid */
1049 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1053 /* clean up an access control list of its bad entries; return 1 if we made
1054 any changes to the list, and 0 otherwise */
1056 CleanAcl(struct Acl *aa, char *fname)
1058 struct AclEntry *te, **le, *ne;
1061 /* Don't correct DFS ACL's for now */
1065 /* prune out bad entries */
1066 changes = 0; /* count deleted entries */
1068 for (te = aa->pluslist; te; te = ne) {
1070 if (BadName(te->name, fname)) {
1080 le = &aa->minuslist;
1081 for (te = aa->minuslist; te; te = ne) {
1083 if (BadName(te->name, fname)) {
1097 /* clean up an acl to not have bogus entries */
1099 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1103 struct ViceIoctl blob;
1105 struct cmd_item *ti;
1106 struct AclEntry *te;
1109 SetDotDefault(&as->parms[0].items);
1110 for (ti = as->parms[0].items; ti; ti = ti->next) {
1111 blob.out_size = AFS_PIOCTL_MAXSIZE;
1114 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1116 Die(errno, ti->data);
1123 ta = ParseAcl(space);
1126 "%s: cleanacl is not supported for DFS access lists.\n",
1132 changes = CleanAcl(ta, ti->data);
1135 /* now set the acl */
1136 blob.in = AclToString(ta);
1137 blob.in_size = strlen(blob.in) + 1;
1139 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1141 if (errno == EINVAL) {
1143 "%s: Invalid argument, possible reasons include\n",
1145 fprintf(stderr, "%s: File not in vice or\n", pn);
1147 "%s: Too many users on access control list or\n",
1150 Die(errno, ti->data);
1156 /* now list the updated acl */
1157 printf("Access list for %s is now\n", ti->data);
1158 if (ta->nplus > 0) {
1160 printf("Normal rights:\n");
1161 for (te = ta->pluslist; te; te = te->next) {
1162 printf(" %s ", te->name);
1163 PRights(te->rights, ta->dfs);
1167 if (ta->nminus > 0) {
1168 printf("Negative rights:\n");
1169 for (te = ta->minuslist; te; te = te->next) {
1170 printf(" %s ", te->name);
1171 PRights(te->rights, ta->dfs);
1178 printf("Access list for %s is fine.\n", ti->data);
1186 ListACLCmd(struct cmd_syndesc *as, void *arock)
1190 struct ViceIoctl blob;
1191 struct AclEntry *te;
1192 struct cmd_item *ti;
1193 int idf = getidf(as, parm_listacl_id);
1196 SetDotDefault(&as->parms[0].items);
1197 for (ti = as->parms[0].items; ti; ti = ti->next) {
1198 blob.out_size = AFS_PIOCTL_MAXSIZE;
1200 blob.in = blob.out = space;
1201 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1203 Die(errno, ti->data);
1207 ta = ParseAcl(space);
1208 if (as->parms[3].items) { /* -cmd */
1209 printf("fs setacl -dir %s -acl ", ti->data);
1210 if (ta->nplus > 0) {
1211 for (te = ta->pluslist; te; te = te->next) {
1212 printf(" %s ", te->name);
1213 PRights(te->rights, ta->dfs);
1217 if (ta->nminus > 0) {
1218 printf("fs setacl -dir %s -acl ", ti->data);
1219 for (te = ta->minuslist; te; te = te->next) {
1220 printf(" %s ", te->name);
1221 PRights(te->rights, ta->dfs);
1223 printf(" -negative\n");
1228 printf("Access list for %s is\n", ti->data);
1231 printf("DFS access list for %s is\n", ti->data);
1234 printf("DFS initial directory access list of %s is\n", ti->data);
1237 printf("DFS initial file access list of %s is\n", ti->data);
1241 printf(" Default cell = %s\n", ta->cell);
1243 if (ta->nplus > 0) {
1245 printf("Normal rights:\n");
1246 for (te = ta->pluslist; te; te = te->next) {
1247 printf(" %s ", te->name);
1248 PRights(te->rights, ta->dfs);
1252 if (ta->nminus > 0) {
1253 printf("Negative rights:\n");
1254 for (te = ta->minuslist; te; te = te->next) {
1255 printf(" %s ", te->name);
1256 PRights(te->rights, ta->dfs);
1269 GetCallerAccess(struct cmd_syndesc *as, void *arock)
1271 struct cmd_item *ti;
1274 SetDotDefault(&as->parms[0].items);
1275 for (ti = as->parms[0].items; ti; ti = ti->next) {
1277 struct ViceIoctl blob;
1278 struct vcxstat2 stat;
1279 blob.out_size = sizeof(struct vcxstat2);
1281 blob.out = (void *)&stat;
1282 code = pioctl(ti->data, VIOC_GETVCXSTATUS2, &blob, 1);
1284 Die(errno, ti->data);
1288 printf("Callers access to %s is ", ti->data);
1289 PRights(stat.callerAccess, 0);
1296 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1299 struct ViceIoctl blob;
1300 struct cmd_item *ti;
1303 SetDotDefault(&as->parms[0].items);
1304 for (ti = as->parms[0].items; ti; ti = ti->next) {
1305 blob.in_size = blob.out_size = 0;
1306 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1308 fprintf(stderr, "Error flushing volume ");
1318 FlushAllVolumesCmd(struct cmd_syndesc *as, void *arock)
1321 struct ViceIoctl blob;
1325 blob.out_size = AFS_PIOCTL_MAXSIZE;
1328 code = pioctl(NULL, VIOC_FLUSHALL, &blob, 0);
1330 fprintf(stderr, "Error flushing all volumes\n");
1337 * The Windows version of UuidCmd displays the UUID.
1338 * When the UNIX version is updated to do the same
1339 * be sure to replace the CMD_REQUIRED flag with
1340 * CMD_OPTIONAL in the cmd_AddParam(-generate) call
1343 UuidCmd(struct cmd_syndesc *as, void *arock)
1346 struct ViceIoctl blob;
1351 if (as->parms[0].items) {
1353 fprintf (stderr, "Permission denied: requires root access.\n");
1357 /* generate new UUID */
1358 code = pioctl(0, VIOC_NEWUUID, &blob, 1);
1365 printf("New uuid generated.\n");
1367 /* This will never execute */
1368 printf("Please add the '-generate' option to generate a new UUID.\n");
1373 #if defined(AFS_CACHE_BYPASS)
1375 * Set cache-bypass threshold. Files larger than this size will not be cached.
1376 * With a threshold of 0, the cache is always bypassed. With a threshold of -1,
1377 * cache bypass is disabled.
1381 BypassThresholdCmd(struct cmd_syndesc *as, void *arock)
1384 struct ViceIoctl blob;
1385 afs_int32 threshold_i, threshold_o;
1388 /* if new threshold supplied, then set and confirm, else,
1389 * get current threshold and print
1392 if(as->parms[0].items) {
1395 tp = as->parms[0].items->data;
1398 if (!strcmp(tp,"-1")) {
1402 for(ix = 0; ix < len; ++ix) {
1403 if(!isdigit(tp[0])) {
1409 fprintf(stderr, "fs bypassthreshold -size: %s must be an integer between -1 and 2^31\n", tp);
1412 threshold_i = atoi(tp);
1413 if(ix > 9 && threshold_i < 2147483647)
1414 threshold_i = 2147483647;
1416 blob.in = (char *) &threshold_i;
1417 blob.in_size = sizeof(threshold_i);
1423 blob.out = (char *) &threshold_o;
1424 blob.out_size = sizeof(threshold_o);
1425 code = pioctl(0, VIOC_SETBYPASS_THRESH, &blob, 1);
1430 printf("Cache bypass threshold %d", threshold_o);
1431 if(threshold_o == -1)
1432 printf(" (disabled)");
1442 FlushCmd(struct cmd_syndesc *as, void *arock)
1445 struct ViceIoctl blob;
1446 struct cmd_item *ti;
1449 for (ti = as->parms[0].items; ti; ti = ti->next) {
1450 blob.in_size = blob.out_size = 0;
1451 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1453 if (errno == EMFILE) {
1454 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1457 fprintf(stderr, "%s: Error flushing file ", pn);
1467 /* all this command does is repackage its args and call SetVolCmd */
1469 SetQuotaCmd(struct cmd_syndesc *as, void *arock)
1471 struct cmd_syndesc ts;
1473 /* copy useful stuff from our command slot; we may later have to reorder */
1474 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1475 return SetVolCmd(&ts, arock);
1479 SetVolCmd(struct cmd_syndesc *as, void *arock)
1482 struct ViceIoctl blob;
1483 struct cmd_item *ti;
1484 struct VolumeStatus *status;
1485 char *offmsg, *input;
1488 SetDotDefault(&as->parms[0].items);
1489 for (ti = as->parms[0].items; ti; ti = ti->next) {
1491 blob.out_size = AFS_PIOCTL_MAXSIZE;
1492 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1495 status = (VolumeStatus *) space;
1496 status->MinQuota = status->MaxQuota = -1;
1498 if (as->parms[1].items) {
1499 code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota);
1501 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1506 if (as->parms[2].items)
1507 offmsg = as->parms[2].items->data;
1508 input = (char *)status + sizeof(*status);
1509 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1511 if (strlen(offmsg) >= VMSGSIZE) {
1513 "%s: message must be shorter than %d characters\n",
1518 strcpy(input, offmsg);
1519 blob.in_size += strlen(offmsg);
1520 input += strlen(offmsg) + 1;
1523 *(input++) = '\0'; /* Pad for old style volume "motd" */
1524 code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1);
1526 Die(errno, ti->data);
1534 * Why is VenusFid declared in the kernel-only section of afs.h,
1535 * if it's the exported interface of the cache manager?
1543 ExamineCmd(struct cmd_syndesc *as, void *arock)
1546 struct ViceIoctl blob;
1547 struct cmd_item *ti;
1548 struct VolumeStatus *status;
1549 char *name, *offmsg;
1552 SetDotDefault(&as->parms[0].items);
1553 for (ti = as->parms[0].items; ti; ti = ti->next) {
1554 struct VenusFid vfid;
1557 blob.out_size = AFS_PIOCTL_MAXSIZE;
1560 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1562 Die(errno, ti->data);
1566 status = (VolumeStatus *) space;
1567 name = (char *)status + sizeof(*status);
1568 offmsg = name + strlen(name) + 1;
1570 blob.out_size = sizeof(struct VenusFid);
1571 blob.out = (char *) &vfid;
1572 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1573 printf("File %s (%u.%u.%u) contained in volume %u\n",
1574 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1578 PrintStatus(status, name, offmsg);
1584 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1587 struct ViceIoctl blob;
1588 struct cmd_item *ti;
1589 struct VolumeStatus *status;
1594 if (as->parms[1].items)
1597 printf("%-25s%-11s%-11s%-7s%-11s\n", "Volume Name", " Quota",
1598 " Used", " %Used", " Partition");
1599 SetDotDefault(&as->parms[0].items);
1600 for (ti = as->parms[0].items; ti; ti = ti->next) {
1602 blob.out_size = AFS_PIOCTL_MAXSIZE;
1605 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1607 Die(errno, ti->data);
1611 status = (VolumeStatus *) space;
1612 name = (char *)status + sizeof(*status);
1613 QuickPrintStatus(status, name, human);
1619 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1622 struct ViceIoctl blob;
1623 struct cmd_item *ti;
1629 SetDotDefault(&as->parms[0].items);
1630 for (ti = as->parms[0].items; ti; ti = ti->next) {
1632 blob.out_size = AFS_PIOCTL_MAXSIZE;
1635 memset(space, 0, sizeof(space));
1636 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1638 Die(errno, ti->data);
1642 hosts = (afs_int32 *) space;
1643 printf("File %s is on host%s ", ti->data,
1644 (hosts[0] && !hosts[1]) ? "" : "s");
1645 for (j = 0; j < AFS_MAXHOSTS; j++) {
1648 tp = hostutil_GetNameByINet(hosts[j]);
1658 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1661 struct ViceIoctl blob;
1662 struct cmd_item *ti;
1664 struct VolumeStatus *status;
1668 if (as->parms[1].items)
1671 printf("%-25s%10s%10s%10s%6s\n", "Volume Name",
1672 human ? "total" : "kbytes", "used", "avail", "%used");
1673 SetDotDefault(&as->parms[0].items);
1674 for (ti = as->parms[0].items; ti; ti = ti->next) {
1676 blob.out_size = AFS_PIOCTL_MAXSIZE;
1679 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1681 Die(errno, ti->data);
1685 status = (VolumeStatus *) space;
1686 name = (char *)status + sizeof(*status);
1687 QuickPrintSpace(status, name, human);
1693 QuotaCmd(struct cmd_syndesc *as, void *arock)
1696 struct ViceIoctl blob;
1697 struct cmd_item *ti;
1699 struct VolumeStatus *status;
1702 SetDotDefault(&as->parms[0].items);
1703 for (ti = as->parms[0].items; ti; ti = ti->next) {
1705 blob.out_size = AFS_PIOCTL_MAXSIZE;
1708 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1710 Die(errno, ti->data);
1714 status = (VolumeStatus *) space;
1715 if (status->MaxQuota)
1717 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
1720 printf("%2.0f%% of quota used.\n", quotaPct);
1726 GetLastComponent(const char *data, char **outdir, char **outbase,
1729 char orig_name[1024]; /*Original name, may be modified */
1730 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
1732 struct stat statbuff; /*Buffer for status info */
1733 int link_chars_read; /*Num chars read in readlink() */
1734 char *dirname = NULL;
1735 char *basename = NULL;
1743 snprintf(orig_name, sizeof(orig_name), "%s%s",
1744 (data[0] == '/') ? "" : "./", data);
1746 if (lstat(orig_name, &statbuff) < 0) {
1747 /* if lstat fails, we should still try the pioctl, since it
1748 * may work (for example, lstat will fail, but pioctl will
1749 * work if the volume of offline (returning ENODEV). */
1750 statbuff.st_mode = S_IFDIR; /* lie like pros */
1754 * The lstat succeeded. If the given file is a symlink, substitute
1755 * the file name with the link name.
1757 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1761 /* Read name of resolved file */
1762 link_chars_read = readlink(orig_name, true_name, 1024);
1763 if (link_chars_read <= 0) {
1765 "%s: Can't read target name for '%s' symbolic link!\n",
1770 /* Add a trailing null to what was read, bump the length. */
1771 true_name[link_chars_read++] = 0;
1774 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1775 * have to create a full pathname using the original name and the
1776 * relative symlink name. Find the rightmost slash in the original
1777 * name (we know there is one) and splice in the symlink value.
1779 if (true_name[0] != '/') {
1780 lastSlash = strrchr(orig_name, '/');
1781 strcpy(++lastSlash, true_name);
1782 strcpy(true_name, orig_name);
1785 strcpy(true_name, orig_name);
1788 /* Find rightmost slash, if any. */
1789 lastSlash = strrchr(true_name, '/');
1790 if (lastSlash == true_name) {
1791 dirname = strdup("/");
1792 basename = strdup(lastSlash+1);
1793 } else if (lastSlash != NULL) {
1795 * Found it. Designate everything before it as the parent directory,
1796 * everything after it as the final component.
1799 dirname = strdup(true_name);
1800 basename = strdup(lastSlash+1);
1803 * No slash appears in the given file name. Set parent_dir to the current
1804 * directory, and the last component as the given name.
1806 dirname = strdup(".");
1807 basename = strdup(true_name);
1810 if (strcmp(basename, ".") == 0
1811 || strcmp(basename, "..") == 0) {
1813 "%s: you may not use '.' or '..' as the last component\n", pn);
1814 fprintf(stderr, "%s: of a name in this fs command.\n", pn);
1819 *outbase = basename;
1833 ListMountCmd(struct cmd_syndesc *as, void *arock)
1836 struct ViceIoctl blob;
1837 struct cmd_item *ti;
1838 char *last_component;
1840 int thru_symlink = 0;
1843 for (ti = as->parms[0].items; ti; ti = ti->next) {
1844 if (GetLastComponent(ti->data, &parent_dir,
1845 &last_component, &thru_symlink) != 0) {
1850 blob.in = last_component;
1851 blob.in_size = strlen(last_component) + 1;
1852 blob.out_size = AFS_PIOCTL_MAXSIZE;
1854 memset(space, 0, AFS_PIOCTL_MAXSIZE);
1856 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1857 free(last_component);
1860 printf("'%s' is a %smount point for volume '%s'\n", ti->data,
1861 (thru_symlink ? "symbolic link, leading to a " : ""),
1864 if (errno == EINVAL) {
1865 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
1867 Die(errno, (ti->data ? ti->data : parent_dir));
1877 MakeMountCmd(struct cmd_syndesc *as, void *arock)
1880 char *cellName, *volName, *tmpName;
1881 struct afsconf_cell info;
1882 struct vldbentry vldbEntry;
1883 struct ViceIoctl blob;
1884 struct afsconf_dir *dir;
1890 if (as->parms[5].items && !as->parms[2].items) {
1891 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1896 if (as->parms[2].items) /* cell name specified */
1897 cellName = as->parms[2].items->data;
1900 volName = as->parms[1].items->data;
1902 if (strlen(volName) >= 64) {
1904 "%s: volume name too long (length must be < 64 characters)\n",
1909 /* Check for a cellname in the volume specification, and complain
1910 * if it doesn't match what was specified with -cell */
1911 if ((tmpName = strchr(volName, ':'))) {
1914 if (strcasecmp(cellName, volName)) {
1915 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1920 volName = ++tmpName;
1923 if (!InAFS(Parent(as->parms[0].items->data))) {
1925 "%s: mount points must be created within the AFS file system\n",
1932 blob.out_size = AFS_PIOCTL_MAXSIZE;
1935 pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME,
1939 dir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
1942 "Could not process files in configuration directory (%s).\n",
1943 AFSDIR_CLIENT_ETC_DIRPATH);
1947 code = afsconf_GetCellInfo(dir, cellName ? cellName : space,
1948 AFSCONF_VLDBSERVICE, &info);
1951 "%s: cell %s not in %s\n", pn, cellName ? cellName : space,
1952 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
1956 if (!(as->parms[4].items)) {
1957 /* not fast, check which cell the mountpoint is being created in */
1958 code = ugen_ClientInitCell(dir, &info,
1959 AFSCONF_SECOPTS_FALLBACK_NULL |
1960 AFSCONF_SECOPTS_NOAUTH,
1961 &uclient, VLDB_MAXSERVERS,
1962 AFSCONF_VLDBSERVICE, 50);
1965 /* make the check. Don't complain if there are problems with init */
1967 ubik_VL_GetEntryByNameO(uclient, 0, volName,
1969 if (code == VL_NOENT) {
1971 "%s: warning, volume %s does not exist in cell %s.\n",
1972 pn, volName, cellName ? cellName : space);
1977 if (as->parms[3].items) /* if -rw specified */
1982 /* cellular mount point, prepend cell prefix */
1983 strcat(space, info.name);
1986 strcat(space, volName); /* append volume name */
1987 strcat(space, "."); /* stupid convention; these end with a period */
1988 code = symlink(space, as->parms[0].items->data);
1990 Die(errno, as->parms[0].items->data);
1997 * Delete AFS mount points. Variables are used as follows:
1998 * tbuffer: Set to point to the null-terminated directory name of the mount point
1999 * (or ``.'' if none is provided)
2000 * tp: Set to point to the actual name of the mount point to nuke.
2003 RemoveMountCmd(struct cmd_syndesc *as, void *arock)
2006 struct ViceIoctl blob;
2007 struct cmd_item *ti;
2009 char lsbuffer[1024];
2013 for (ti = as->parms[0].items; ti; ti = ti->next) {
2015 tp = (char *)strrchr(ti->data, '/');
2017 strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */
2019 tp++; /* skip the slash */
2021 strcpy(tbuffer, ".");
2025 blob.in_size = strlen(tp) + 1;
2026 blob.out = lsbuffer;
2027 blob.out_size = sizeof(lsbuffer);
2028 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 1);
2030 if (errno == EINVAL) {
2031 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
2034 Die(errno, ti->data);
2037 continue; /* don't bother trying */
2041 blob.in_size = strlen(tp) + 1;
2042 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 1);
2044 Die(errno, ti->data);
2055 CheckServersCmd(struct cmd_syndesc *as, void *arock)
2058 struct ViceIoctl blob;
2062 struct afsconf_cell info;
2063 struct chservinfo checkserv;
2065 memset(&checkserv, 0, sizeof(struct chservinfo));
2066 blob.in_size = sizeof(struct chservinfo);
2067 blob.in = (caddr_t) & checkserv;
2069 blob.out_size = AFS_PIOCTL_MAXSIZE;
2071 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2073 /* prepare flags for checkservers command */
2074 temp = 2; /* default to checking local cell only */
2075 if (as->parms[2].items)
2076 temp |= 1; /* set fast flag */
2077 if (as->parms[1].items)
2078 temp &= ~2; /* turn off local cell check */
2080 checkserv.magic = 0x12345678; /* XXX */
2081 checkserv.tflags = temp;
2083 /* now copy in optional cell name, if specified */
2084 if (as->parms[0].items) {
2085 code = GetCellName(as->parms[0].items->data, &info);
2089 strcpy(checkserv.tbuffer, info.name);
2090 checkserv.tsize = strlen(info.name) + 1;
2092 strcpy(checkserv.tbuffer, "\0");
2093 checkserv.tsize = 0;
2096 if (as->parms[3].items) {
2097 checkserv.tinterval = atol(as->parms[3].items->data);
2100 if (checkserv.tinterval < 0) {
2102 ("Warning: The negative -interval is ignored; treated as an inquiry\n");
2103 checkserv.tinterval = 0;
2104 } else if (checkserv.tinterval > 600) {
2106 ("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2107 checkserv.tinterval = 600; /* 10 min max interval */
2110 checkserv.tinterval = -1; /* don't change current interval */
2113 code = pioctl(0, VIOCCKSERV, &blob, 1);
2115 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2116 printf("Must be root to change -interval\n");
2122 memcpy(&temp, space, sizeof(afs_int32));
2123 if (checkserv.tinterval >= 0) {
2124 if (checkserv.tinterval > 0)
2126 ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2127 checkserv.tinterval, temp);
2129 printf("The current down server probe interval is %d secs\n",
2134 printf("All servers are running.\n");
2137 ("These servers unavailable due to network or server problems: ");
2139 memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32));
2142 tp = hostutil_GetNameByINet(temp);
2152 MessagesCmd(struct cmd_syndesc *as, void *arock)
2155 struct ViceIoctl blob;
2156 struct gaginfo gagflags;
2157 struct cmd_item *show;
2159 memset(&gagflags, 0, sizeof(struct gaginfo));
2160 blob.in_size = sizeof(struct gaginfo);
2161 blob.in = (caddr_t) & gagflags;
2162 blob.out_size = AFS_PIOCTL_MAXSIZE;
2164 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2166 if ((show = as->parms[0].items)) {
2167 if (!strcasecmp(show->data, "user"))
2168 gagflags.showflags |= GAGUSER;
2169 else if (!strcasecmp(show->data, "console"))
2170 gagflags.showflags |= GAGCONSOLE;
2171 else if (!strcasecmp(show->data, "all"))
2172 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2173 else if (!strcasecmp(show->data, "none"))
2177 "unrecognized flag %s: must be in {user,console,all,none}\n",
2186 code = pioctl(0, VIOC_GAG, &blob, 1);
2196 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2199 struct ViceIoctl blob;
2203 code = pioctl(0, VIOCCKBACK, &blob, 1);
2209 printf("All volumeID/name mappings checked.\n");
2214 PreCacheCmd(struct cmd_syndesc *as, void *arock)
2217 struct ViceIoctl blob;
2220 if (!as->parms[0].items && !as->parms[1].items) {
2221 fprintf(stderr, "%s: syntax error in precache cmd.\n", pn);
2224 if (as->parms[0].items) {
2225 code = util_GetInt32(as->parms[0].items->data, &temp);
2227 fprintf(stderr, "%s: bad integer specified for precache size.\n",
2233 blob.in = (char *)&temp;
2234 blob.in_size = sizeof(afs_int32);
2236 code = pioctl(0, VIOCPRECACHE, &blob, 1);
2242 printf("New precache size set.\n");
2247 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2250 struct ViceIoctl blob;
2253 if (!as->parms[0].items && !as->parms[1].items) {
2254 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
2257 if (as->parms[0].items) {
2258 code = util_GetHumanInt32(as->parms[0].items->data, &temp);
2260 fprintf(stderr, "%s: bad integer specified for cache size.\n",
2266 blob.in = (char *)&temp;
2267 blob.in_size = sizeof(afs_int32);
2269 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2271 if (errno == EROFS) {
2273 ("'fs setcache' not allowed on memory cache based cache managers.\n");
2280 printf("New cache size set.\n");
2284 #define MAXGCSIZE 16
2286 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2288 afs_int32 code, filesUsed;
2289 struct ViceIoctl blob;
2290 afs_int32 parms[MAXGCSIZE];
2291 double percentFiles, percentBlocks;
2292 afs_int32 flags = 0;
2294 if (as->parms[0].items){ /* -files */
2296 } else if (as->parms[1].items){ /* -excessive */
2302 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
2304 blob.in = (char *)&flags;
2305 blob.in_size = sizeof(afs_int32);
2306 } else { /* be backward compatible */
2310 blob.out_size = sizeof(parms);
2311 blob.out = (char *)parms;
2312 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2319 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2320 parms[1], parms[0]);
2321 if (parms[1] > parms[0])
2322 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2326 percentBlocks = ((double)parms[1]/parms[0]) * 100;
2327 printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n",
2328 percentBlocks, parms[1], parms[0]);
2333 filesUsed = parms[2] - parms[3];
2334 percentFiles = ((double)filesUsed/parms[2]) * 100;
2335 printf(" %5.0f%% of the cache files (%d of %d files)\n",
2336 percentFiles, filesUsed, parms[2]);
2338 printf(" afs_cacheFiles: %10d\n", parms[2]);
2339 printf(" IFFree: %10d\n", parms[3]);
2340 printf(" IFEverUsed: %10d\n", parms[4]);
2341 printf(" IFDataMod: %10d\n", parms[5]);
2342 printf(" IFDirtyPages: %10d\n", parms[6]);
2343 printf(" IFAnyPages: %10d\n", parms[7]);
2344 printf(" IFDiscarded: %10d\n", parms[8]);
2345 printf(" DCentries: %10d\n", parms[9]);
2346 printf(" 0k- 4K: %10d\n", parms[10]);
2347 printf(" 4k- 16k: %10d\n", parms[11]);
2348 printf(" 16k- 64k: %10d\n", parms[12]);
2349 printf(" 64k- 256k: %10d\n", parms[13]);
2350 printf(" 256k- 1M: %10d\n", parms[14]);
2351 printf(" >=1M: %10d\n", parms[15]);
2354 if (percentBlocks > 90)
2355 printf("[cache size usage over 90%%, consider increasing cache size]\n");
2356 if (percentFiles > 90)
2357 printf("[cache file usage over 90%%, consider increasing '-files' argument to afsd]\n");
2363 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2368 struct ViceIoctl blob;
2371 resolve = !(as->parms[0].items); /* -numeric */
2375 memcpy(tp, &i, sizeof(afs_int32));
2376 blob.out_size = AFS_PIOCTL_MAXSIZE;
2377 blob.in_size = sizeof(afs_int32);
2380 code = pioctl(0, VIOCGETCELL, &blob, 1);
2383 break; /* done with the list */
2388 printf("Cell %s on hosts", tp + AFS_MAXCELLHOSTS * sizeof(afs_int32));
2389 for (j = 0; j < AFS_MAXCELLHOSTS; j++) {
2391 char *name, tbuffer[20];
2393 memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32));
2398 name = hostutil_GetNameByINet(addr);
2401 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2402 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2405 printf(" %s", name);
2413 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2416 char *tp, *aliasName, *realName;
2417 struct ViceIoctl blob;
2421 memcpy(tp, &i, sizeof(afs_int32));
2422 blob.out_size = AFS_PIOCTL_MAXSIZE;
2423 blob.in_size = sizeof(afs_int32);
2426 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2429 break; /* done with the list */
2435 tp += strlen(aliasName) + 1;
2437 printf("Alias %s for cell %s\n", aliasName, realName);
2443 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2446 struct ViceIoctl blob;
2447 struct cmd_item *ti;
2449 struct hostent *thp;
2451 ti = as->parms[0].items;
2453 thp = hostutil_GetHostByName(ti->data);
2455 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2458 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2460 hostAddr = 0; /* means don't set host */
2463 /* now do operation */
2464 blob.in_size = sizeof(afs_int32);
2465 blob.out_size = sizeof(afs_int32);
2466 blob.in = (char *) &hostAddr;
2467 blob.out = (char *) &hostAddr;
2469 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2478 NukeNFSCredsCmd(struct cmd_syndesc *as, void *arock)
2481 struct ViceIoctl blob;
2482 struct cmd_item *ti;
2484 struct hostent *thp;
2486 ti = as->parms[0].items;
2487 thp = hostutil_GetHostByName(ti->data);
2489 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2492 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2494 /* now do operation */
2495 blob.in_size = sizeof(afs_int32);
2496 blob.out_size = sizeof(afs_int32);
2497 blob.in = (char *) &hostAddr;
2498 blob.out = (char *) &hostAddr;
2500 code = pioctl(0, VIOC_NFS_NUKE_CREDS, &blob, 1);
2509 NewCellCmd(struct cmd_syndesc *as, void *arock)
2511 afs_int32 code, linkedstate = 0, size = 0, *lp;
2512 struct ViceIoctl blob;
2513 struct cmd_item *ti;
2514 char *tp, *cellname = 0;
2515 struct hostent *thp;
2516 afs_int32 fsport = 0, vlport = 0;
2517 afs_int32 scount; /* Number of servers to pass in pioctl call */
2520 * With the NEWCELL pioctl call, 3.4 clients take an array of
2521 * AFS_MAXHOSTS (13) servers while 3.5 clients take an array of
2522 * AFS_MAXCELLHOSTS (8) servers. To determine which we are talking to,
2523 * do a GETCELL pioctl and pass it a magic number. If an array of
2524 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
2525 * If we get back EDOM, there are no cells in the kernel yet,
2526 * and we'll assume a 3.5 client.
2529 lp = (afs_int32 *) tp;
2530 *lp++ = 0; /* first cell entry */
2531 *lp = 0x12345678; /* magic */
2532 blob.out_size = AFS_PIOCTL_MAXSIZE;
2533 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
2536 code = pioctl(0, VIOCGETCELL, &blob, 1);
2537 if (code < 0 && errno != EDOM) {
2541 if (code < 1 && errno == EDOM) {
2542 scount = AFS_MAXHOSTS;
2545 cellname = tp + AFS_MAXCELLHOSTS * sizeof(afs_int32);
2546 scount = ((cellname[0] != '\0') ? AFS_MAXCELLHOSTS : AFS_MAXHOSTS);
2549 /* Now setup and do the NEWCELL pioctl call */
2550 memset(space, 0, (scount + 1) * sizeof(afs_int32));
2552 lp = (afs_int32 *) tp;
2554 tp += sizeof(afs_int32);
2555 for (ti = as->parms[1].items; ti; ti = ti->next) {
2556 thp = hostutil_GetHostByName(ti->data);
2559 "%s: Host %s not found in host table, skipping it.\n", pn,
2562 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2563 tp += sizeof(afs_int32);
2566 if (as->parms[2].items) {
2568 * Link the cell, for the purposes of volume location, to the specified
2571 cellname = as->parms[2].items->data;
2574 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2575 if (as->parms[3].items) {
2576 code = util_GetInt32(as->parms[3].items->data, &vlport);
2579 "%s: bad integer specified for the fileserver port.\n",
2584 if (as->parms[4].items) {
2585 code = util_GetInt32(as->parms[4].items->data, &fsport);
2588 "%s: bad integer specified for the vldb server port.\n",
2594 tp = (char *)(space + (scount + 1) * sizeof(afs_int32));
2595 lp = (afs_int32 *) tp;
2599 strcpy(space + ((scount + 4) * sizeof(afs_int32)),
2600 as->parms[0].items->data);
2601 size = ((scount + 4) * sizeof(afs_int32))
2602 + strlen(as->parms[0].items->data)
2603 + 1 /* for null */ ;
2604 tp = (char *)(space + size);
2606 strcpy(tp, cellname);
2607 size += strlen(cellname) + 1;
2609 blob.in_size = size;
2612 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2621 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2624 struct ViceIoctl blob;
2626 char *aliasName, *realName;
2628 /* Now setup and do the NEWCELL pioctl call */
2629 aliasName = as->parms[0].items->data;
2630 realName = as->parms[1].items->data;
2632 strcpy(tp, aliasName);
2633 tp += strlen(aliasName) + 1;
2634 strcpy(tp, realName);
2635 tp += strlen(realName) + 1;
2637 blob.in_size = tp - space;
2641 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2643 if (errno == EEXIST) {
2645 "%s: cell name `%s' in use by an existing cell.\n", pn,
2656 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2659 struct cmd_item *ti;
2661 char cell[MAXCELLCHARS];
2663 SetDotDefault(&as->parms[0].items);
2664 for (ti = as->parms[0].items; ti; ti = ti->next) {
2665 code = GetCell(ti->data, cell);
2667 if (errno == ENOENT)
2668 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
2670 Die(errno, ti->data);
2675 printf("File %s lives in cell '%s'\n", ti->data, cell);
2681 WSCellCmd(struct cmd_syndesc *as, void *arock)
2684 struct ViceIoctl blob;
2688 blob.out_size = AFS_PIOCTL_MAXSIZE;
2691 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2697 printf("This workstation belongs to cell '%s'\n", space);
2702 static PrimaryCellCmd(as)
2703 struct cmd_syndesc *as;
2705 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2711 MonitorCmd(struct cmd_syndesc *as, void *arock)
2714 struct ViceIoctl blob;
2715 struct cmd_item *ti;
2717 struct hostent *thp;
2721 ti = as->parms[0].items;
2725 if (!strcmp(ti->data, "off"))
2726 hostAddr = 0xffffffff;
2728 thp = hostutil_GetHostByName(ti->data);
2730 if (!strcmp(ti->data, "localhost")) {
2732 "localhost not in host table, assuming 127.0.0.1\n");
2733 hostAddr = htonl(0x7f000001);
2735 fprintf(stderr, "host %s not found in host table.\n",
2740 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2743 hostAddr = 0; /* means don't set host */
2744 setp = 0; /* aren't setting host */
2747 /* now do operation */
2748 blob.in_size = sizeof(afs_int32);
2749 blob.out_size = sizeof(afs_int32);
2750 blob.in = (char *)&hostAddr;
2751 blob.out = (char *)&hostAddr;
2752 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2758 printf("%s: new monitor host set.\n", pn);
2760 /* now decode old address */
2761 if (hostAddr == 0xffffffff) {
2762 printf("Cache monitoring is currently disabled.\n");
2764 tp = hostutil_GetNameByINet(hostAddr);
2765 printf("Using host %s for monitor services.\n", tp);
2772 SysNameCmd(struct cmd_syndesc *as, void *arock)
2775 struct ViceIoctl blob;
2776 struct cmd_item *ti;
2777 char *input = space;
2780 ti = as->parms[0].items;
2783 blob.out_size = AFS_PIOCTL_MAXSIZE;
2784 blob.in_size = sizeof(afs_int32);
2785 input += sizeof(afs_int32);
2786 for (; ti; ti = ti->next) {
2788 blob.in_size += strlen(ti->data) + 1;
2789 if (blob.in_size > AFS_PIOCTL_MAXSIZE) {
2790 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2791 setp > 1 ? "s" : "");
2794 strcpy(input, ti->data);
2795 input += strlen(ti->data);
2798 memcpy(space, &setp, sizeof(afs_int32));
2799 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2805 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2809 memcpy(&setp, input, sizeof(afs_int32));
2810 input += sizeof(afs_int32);
2812 fprintf(stderr, "No sysname name value was found\n");
2815 printf("Current sysname%s is", setp > 1 ? " list" : "");
2816 for (; setp > 0; --setp) {
2817 printf(" \'%s\'", input);
2818 input += strlen(input) + 1;
2824 static char *exported_types[] = { "null", "nfs", "" };
2826 ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2829 struct ViceIoctl blob;
2830 struct cmd_item *ti;
2831 int export = 0, type = 0, mode = 0, exportcall, pwsync =
2832 0, smounts = 0, clipags = 0, pagcb = 0;
2834 ti = as->parms[0].items;
2835 if (strcmp(ti->data, "nfs") == 0)
2836 type = 0x71; /* NFS */
2839 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n",
2843 ti = as->parms[1].items;
2845 if (strcmp(ti->data, "on") == 0)
2847 else if (strcmp(ti->data, "off") == 0)
2850 fprintf(stderr, "Illegal argument %s\n", ti->data);
2854 if ((ti = as->parms[2].items)) { /* -noconvert */
2855 if (strcmp(ti->data, "on") == 0)
2857 else if (strcmp(ti->data, "off") == 0)
2860 fprintf(stderr, "Illegal argument %s\n", ti->data);
2864 if ((ti = as->parms[3].items)) { /* -uidcheck */
2865 if (strcmp(ti->data, "on") == 0)
2867 else if (strcmp(ti->data, "off") == 0)
2870 fprintf(stderr, "Illegal argument %s\n", ti->data);
2874 if ((ti = as->parms[4].items)) { /* -submounts */
2875 if (strcmp(ti->data, "on") == 0)
2877 else if (strcmp(ti->data, "off") == 0)
2880 fprintf(stderr, "Illegal argument %s\n", ti->data);
2884 if ((ti = as->parms[5].items)) { /* -clipags */
2885 if (strcmp(ti->data, "on") == 0)
2887 else if (strcmp(ti->data, "off") == 0)
2890 fprintf(stderr, "Illegal argument %s\n", ti->data);
2894 if ((ti = as->parms[6].items)) { /* -pagcb */
2895 if (strcmp(ti->data, "on") == 0)
2897 else if (strcmp(ti->data, "off") == 0)
2900 fprintf(stderr, "Illegal argument %s\n", ti->data);
2905 (type << 24) | (pagcb << 10) | (clipags << 8) |
2906 (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2909 blob.in = (char *)&exportcall;
2910 blob.in_size = sizeof(afs_int32);
2911 blob.out = (char *)&exportcall;
2912 blob.out_size = sizeof(afs_int32);
2913 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2915 if (errno == ENODEV) {
2917 "Sorry, the %s-exporter type is currently not supported on this AFS client\n",
2918 exported_types[type]);
2925 if (exportcall & 1) {
2926 printf("'%s' translator is enabled with the following options:\n",
2927 exported_types[type]);
2928 printf("\tRunning in %s mode\n",
2929 (exportcall & 2 ? "strict unix" :
2930 "convert owner mode bits to world/other"));
2931 printf("\tRunning in %s mode\n",
2932 (exportcall & 4 ? "strict 'passwd sync'" :
2933 "no 'passwd sync'"));
2935 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
2936 "Only mounts to /afs allowed"));
2938 (exportcall & 16 ? "Client-assigned PAG's are used" :
2939 "Client-assigned PAG's are not used"));
2942 "Callbacks are made to get creds from new clients" :
2943 "Callbacks are not made to get creds from new clients"));
2945 printf("'%s' translator is disabled\n", exported_types[type]);
2952 GetCellCmd(struct cmd_syndesc *as, void *arock)
2955 struct ViceIoctl blob;
2956 struct afsconf_cell info;
2957 struct cmd_item *ti;
2964 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2965 for (ti = as->parms[0].items; ti; ti = ti->next) {
2967 blob.out_size = sizeof(args);
2968 blob.out = (caddr_t) & args;
2969 code = GetCellName(ti->data, &info);
2974 blob.in_size = 1 + strlen(info.name);
2975 blob.in = info.name;
2976 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2978 if (errno == ENOENT)
2979 fprintf(stderr, "%s: the cell named '%s' does not exist\n",
2982 Die(errno, info.name);
2986 printf("Cell %s status: ", info.name);
2992 printf("no setuid allowed");
2994 printf("setuid allowed");
2996 printf(", using old VLDB");
3003 SetCellCmd(struct cmd_syndesc *as, void *arock)
3006 struct ViceIoctl blob;
3007 struct afsconf_cell info;
3008 struct cmd_item *ti;
3016 /* Check arguments. */
3017 if (as->parms[1].items && as->parms[2].items) {
3018 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
3022 /* figure stuff to set */
3026 if (!as->parms[1].items)
3027 args.stat |= 2; /* default to -nosuid */
3029 /* set stat for all listed cells */
3030 for (ti = as->parms[0].items; ti; ti = ti->next) {
3032 code = GetCellName(ti->data, &info);
3037 strcpy(args.cname, info.name);
3038 blob.in_size = sizeof(args);
3039 blob.in = (caddr_t) & args;
3041 blob.out = (caddr_t) 0;
3042 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
3044 Die(errno, info.name); /* XXX added cell name to Die() call */
3052 GetCellName(char *cellName, struct afsconf_cell *info)
3054 struct afsconf_dir *tdir;
3057 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
3060 "Could not process files in configuration directory (%s).\n",
3061 AFSDIR_CLIENT_ETC_DIRPATH);
3065 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
3067 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
3068 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
3075 static struct ViceIoctl gblob;
3076 static int debug = 0;
3078 * here follow some routines in support of the setserverprefs and
3079 * getserverprefs commands. They are:
3080 * SetPrefCmd "top-level" routine
3081 * addServer adds a server to the list of servers to be poked into the
3082 * kernel. Will poke the list into the kernel if it threatens
3084 * pokeServers pokes the existing list of servers and ranks into the kernel
3085 * GetPrefCmd reads the Cache Manager's current list of server ranks
3089 * returns -1 if error message printed,
3091 * errno value if error and no error message printed
3098 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
3099 if (code && (errno == EINVAL)) {
3100 struct setspref *ssp;
3101 ssp = (struct setspref *)gblob.in;
3102 if (!(ssp->flags & DBservers)) {
3103 gblob.in = (void *)&(ssp->servers[0]);
3104 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3105 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
3106 return code ? errno : 0;
3109 "This cache manager does not support VL server preferences.\n");
3113 return code ? errno : 0;
3117 * returns -1 if error message printed,
3119 * errno value if error and no error message printed
3122 addServer(char *name, afs_int32 rank)
3125 struct setspref *ssp;
3127 struct hostent *thostent;
3132 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3134 #define MAXUSHORT ((unsigned short) ~0)
3138 thostent = hostutil_GetHostByName(name);
3140 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3144 ssp = (struct setspref *)(gblob.in);
3146 for (t = 0; thostent->h_addr_list[t]; t++) {
3147 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3148 code = pokeServers();
3151 ssp->num_servers = 0;
3154 sp = (struct spref *)(gblob.in + gblob.in_size);
3155 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3156 sizeof(afs_uint32));
3157 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3158 gblob.in_size += sizeof(struct spref);
3162 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3163 name, sp->rank, (long unsigned int) sp->server.s_addr);
3171 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3175 struct cmd_item *ti;
3178 struct setspref *ssp;
3179 int error = 0; /* -1 means error message printed,
3180 * >0 means errno value for unprinted message */
3182 ssp = (struct setspref *)space;
3184 ssp->num_servers = 0;
3185 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3188 gblob.out_size = AFS_PIOCTL_MAXSIZE;
3192 fprintf(stderr, "Permission denied: requires root access.\n");
3196 ti = as->parms[2].items; /* -file */
3199 fprintf(stderr, "opening file %s\n", ti->data);
3200 if (!(infd = fopen(ti->data, "r"))) {
3204 while (fscanf(infd, "%79s%d", name, &rank) != EOF) {
3205 code = addServer(name, (unsigned short)rank);
3212 ti = as->parms[3].items; /* -stdin */
3214 while (scanf("%79s%d", name, &rank) != EOF) {
3215 code = addServer(name, (unsigned short)rank);
3221 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3226 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3230 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3234 code = pokeServers();
3238 printf("now working on vlservers, code=%d\n", code);
3240 ssp = (struct setspref *)space;
3241 ssp->flags = DBservers;
3242 ssp->num_servers = 0;
3243 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3246 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3251 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3255 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3260 if (as->parms[1].items) {
3262 printf("now poking vlservers\n");
3263 code = pokeServers();
3271 return error ? 1 : 0;
3277 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3280 struct cmd_item *ti;
3281 char *name, tbuffer[20];
3286 struct ViceIoctl blob;
3287 struct sprefrequest *in;
3288 struct sprefinfo *out;
3291 ti = as->parms[0].items; /* -file */
3294 fprintf(stderr, "opening file %s\n", ti->data);
3295 if (!(outfd = freopen(ti->data, "w", stdout))) {
3301 ti = as->parms[1].items; /* -numeric */
3303 ti = as->parms[2].items; /* -vlservers */
3304 vlservers |= (ti ? DBservers : 0);
3305 /* ti = as->parms[3].items; -cell */
3307 in = (struct sprefrequest *)space;
3311 blob.in_size = sizeof(struct sprefrequest);
3312 blob.in = (char *)in;
3314 blob.out_size = AFS_PIOCTL_MAXSIZE;
3317 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3318 in->flags = vlservers;
3321 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3323 if ((errno != E2BIG) || (2 * blob.out_size > 0x7FFF)) {
3324 perror("getserverprefs pioctl");
3328 if (blob.out == space)
3329 blob.out = malloc(blob.out_size);
3331 blob.out = realloc(blob.out, blob.out_size);
3333 } while (code != 0);
3335 out = (struct sprefinfo *)blob.out;
3337 for (i = 0; i < out->num_servers; i++) {
3339 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3341 addr = ntohl(out->servers[i].server.s_addr);
3342 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3343 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3346 printf("%-50s %5u\n", name, out->servers[i].rank);
3349 in->offset = out->next_offset;
3350 } while (out->next_offset > 0);
3352 if (blob.out != space)
3359 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
3362 struct ViceIoctl blob;
3363 struct cmd_item *ti;
3364 struct sbstruct tsb, tsb2;
3369 int async_default = -1;
3371 tsb.sb_thisfile = -1;
3372 ti = as->parms[0].items; /* -kbytes */
3374 if (!as->parms[1].items) {
3375 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3379 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3380 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3381 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3387 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3388 ti = as->parms[2].items; /* -allfiles */
3390 allfiles = strtol(ti->data, &t, 10) * 1024;
3391 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3392 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3398 /* -verbose or -file only or no options */
3399 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3400 || (!as->parms[0].items && !as->parms[1].items
3401 && !as->parms[2].items))
3404 blob.in = (char *)&tsb;
3405 blob.in_size = sizeof(struct sbstruct);
3407 /* once per -file */
3408 for (ti = as->parms[1].items; ti; ti = ti->next) {
3409 /* Do this solely to see if the file is there */
3412 blob.out_size = AFS_PIOCTL_MAXSIZE;
3413 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3415 Die(errno, ti->data);
3420 memset(&tsb2, 0, sizeof(tsb2));
3421 blob.out = (char *)&tsb2;
3422 blob.out_size = sizeof(struct sbstruct);
3423 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
3425 Die(errno, ti->data);
3430 if (blob.out_size == sizeof(tsb2)) {
3431 async_default = tsb2.sb_default;
3434 if (tsb2.sb_thisfile == -1) {
3435 fprintf(stdout, "Will store %s according to default.\n",
3439 "Will store up to %d kbytes of %s asynchronously.\n",
3440 (tsb2.sb_thisfile / 1024), ti->data);
3446 /* If no files - make at least one pioctl call, or
3447 * set the allfiles default if we need to.
3449 if (async_default < 0 || (allfiles != -1)) {
3450 tsb.sb_default = allfiles;
3451 memset(&tsb2, 0, sizeof(tsb2));
3452 blob.out = (char *)&tsb2;
3453 blob.out_size = sizeof(struct sbstruct);
3454 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
3456 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3459 } else if (blob.out_size == sizeof(tsb2)) {
3460 async_default = tsb2.sb_default;
3464 /* Having no arguments also reports the default store asynchrony */
3465 if (async_default >= 0 && verbose) {
3466 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3467 (async_default / 1024));
3475 SetCryptCmd(struct cmd_syndesc *as, void *arock)
3477 afs_int32 code = 0, flag;
3478 struct ViceIoctl blob;
3481 tp = as->parms[0].items->data;
3482 if (strcmp(tp, "on") == 0)
3484 else if (strcmp(tp, "off") == 0)
3487 fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3491 blob.in = (char *)&flag;
3492 blob.in_size = sizeof(flag);
3494 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3502 GetCryptCmd(struct cmd_syndesc *as, void *arock)
3504 afs_int32 code = 0, flag;
3505 struct ViceIoctl blob;
3510 blob.out_size = sizeof(flag);
3513 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3519 memcpy(&flag, tp, sizeof(afs_int32));
3520 printf("Security level is currently ");
3522 printf("crypt (data security).\n");
3529 static char *modenames[] = {
3532 "readonly", /* Not currently supported */
3533 "fetchonly", /* Not currently supported */
3534 "partial", /* Not currently supported */
3538 static char *policynames[] = {
3541 "closer", /* Not currently supported. */
3542 "manual", /* Not currently supported. */
3547 DisconCmd(struct cmd_syndesc *as, void *arock)
3549 struct cmd_item *ti;
3552 int modelen, policylen;
3553 afs_int32 mode, policy, code, unixuid = 0;
3554 struct ViceIoctl blob;
3559 space[0] = space[1] = space[2] = space[3] = 0;
3561 ti = as->parms[0].items;
3563 modename = ti->data;
3564 modelen = strlen(modename);
3565 for (mode = 0; modenames[mode] != NULL; mode++)
3566 if (!strncasecmp(modename, modenames[mode], modelen))
3568 if (modenames[mode] == NULL)
3569 printf("Unknown discon mode \"%s\"\n", modename);
3571 space[0] = mode + 1;
3574 ti = as->parms[1].items;
3576 policyname = ti->data;
3577 policylen = strlen(policyname);
3578 for (policy = 0; policynames[policy] != NULL; policy++)
3579 if (!strncasecmp(policyname, policynames[policy], policylen))
3581 if (policynames[policy] == NULL)
3582 printf("Unknown discon mode \"%s\"\n", policyname);
3584 space[1] = policy + 1;
3588 if (as->parms[2].items) {
3590 printf("force on\n");
3593 ti = as->parms[3].items;
3595 code = util_GetInt32(ti->data, &unixuid);
3597 fprintf(stderr, "%s: bad integer specified for uid.\n", pn);
3605 blob.in_size = 4 * sizeof(afs_int32);
3607 blob.out_size = sizeof(mode);
3609 code = pioctl(0, VIOC_DISCON, &blob, 1);
3613 memcpy(&mode, space, sizeof mode);
3614 if (mode < sizeof modenames / sizeof (char *))
3615 printf("Discon mode is now \"%s\"\n", modenames[mode]);
3617 printf("Unknown discon mode %d\n", mode);
3623 #include "AFS_component_version_number.c"
3626 main(int argc, char **argv)
3629 struct cmd_syndesc *ts;
3631 #ifdef AFS_AIX32_ENV
3633 * The following signal action for AIX is necessary so that in case of a
3634 * crash (i.e. core is generated) we can include the user's data section
3635 * in the core dump. Unfortunately, by default, only a partial core is
3636 * generated which, in many cases, isn't too useful.
3638 struct sigaction nsa;
3640 sigemptyset(&nsa.sa_mask);
3641 nsa.sa_handler = SIG_DFL;
3642 nsa.sa_flags = SA_FULLDUMP;
3643 sigaction(SIGSEGV, &nsa, NULL);
3646 /* try to find volume location information */
3647 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
3648 "get client network interface addresses");
3649 cmd_CreateAlias(ts, "gc");
3651 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
3652 "set client network interface addresses");
3653 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3654 "client network interfaces");
3655 cmd_CreateAlias(ts, "sc");
3657 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL,
3658 "set server ranks");
3659 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3660 "fileserver names and ranks");
3661 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3662 "VL server names and ranks");
3663 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3664 "input from named file");
3665 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3666 cmd_CreateAlias(ts, "sp");
3668 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL,
3669 "get server ranks");
3670 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3671 "output to named file");
3672 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3673 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3674 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3675 cmd_CreateAlias(ts, "gp");
3677 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
3678 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3679 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3680 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3681 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL,
3682 "apply to negative rights");
3683 parm_setacl_id = ts->nParms;
3684 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL,
3685 "initial directory acl (DFS only)");
3686 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL,
3687 "initial file acl (DFS only)");
3688 cmd_CreateAlias(ts, "sa");
3690 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL,
3691 "list access control list");
3692 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3693 parm_listacl_id = ts->nParms;
3694 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3695 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3696 cmd_AddParm(ts, "-cmd", CMD_FLAG, CMD_OPTIONAL, "output as 'fs setacl' command");
3697 cmd_CreateAlias(ts, "la");
3699 ts = cmd_CreateSyntax("getcalleraccess", GetCallerAccess, NULL,
3700 "list callers access");
3701 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3702 cmd_CreateAlias(ts, "gca");
3704 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL,
3705 "clean up access control list");
3706 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3708 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL,
3709 "copy access control list");
3710 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0,
3711 "source directory (or DFS file)");
3712 cmd_AddParm(ts, "-todir", CMD_LIST, 0,
3713 "destination directory (or DFS file)");
3714 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3715 "first clear dest access list");
3716 parm_copyacl_id = ts->nParms;
3717 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3718 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3720 cmd_CreateAlias(ts, "ca");
3722 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
3723 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3724 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
3725 "flush mount symlink from cache");
3726 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3728 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
3729 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3730 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL,
3731 "disk space quota in 1K units");
3733 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL,
3734 "disk space guaranteed");
3735 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3737 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL,
3739 cmd_CreateAlias(ts, "sv");
3741 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL,
3742 "control Cache Manager messages");
3743 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL,
3744 "[user|console|all|none]");
3746 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
3747 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3748 cmd_CreateAlias(ts, "lv");
3749 cmd_CreateAlias(ts, "listvol");
3751 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
3752 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3753 cmd_AddParm(ts, "-human", CMD_FLAG, CMD_OPTIONAL, "human-readable listing");
3754 cmd_CreateAlias(ts, "lq");
3756 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL,
3757 "show server disk space usage");
3758 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3759 cmd_AddParm(ts, "-human", CMD_FLAG, CMD_OPTIONAL, "human-readable listing");
3760 cmd_CreateAlias(ts, "df");
3762 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
3763 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3765 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
3766 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3768 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
3769 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3770 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3771 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3772 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3773 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3774 "don't check name with VLDB");
3776 #if defined(AFS_CACHE_BYPASS)
3777 ts = cmd_CreateSyntax("bypassthreshold", BypassThresholdCmd, 0,
3778 "get/set cache bypass file size threshold");
3779 cmd_AddParm(ts, "-size", CMD_SINGLE, CMD_OPTIONAL, "file size");
3786 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3790 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
3791 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3793 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL,
3794 "check local cell's servers");
3795 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3796 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3797 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3798 "just list, don't check");
3799 cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL,
3800 "seconds between probes");
3802 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL,
3803 "check volumeID/name mappings");
3804 cmd_CreateAlias(ts, "checkbackups");
3807 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL,
3809 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3810 "size in 1K byte blocks (0 => reset)");
3811 cmd_CreateAlias(ts, "cachesize");
3813 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL,
3814 "reset size back to boot value");
3816 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL,
3817 "get cache usage info");
3818 cmd_AddParm(ts, "-files", CMD_FLAG, CMD_OPTIONAL, "Show cach files used as well");
3819 cmd_AddParm(ts, "-excessive", CMD_FLAG, CMD_OPTIONAL, "excessively verbose cache stats");
3821 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL,
3822 "list configured cells");
3823 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3825 ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, NULL,
3826 "list configured cell aliases");
3828 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
3829 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3830 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3832 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3834 cmd_CreateAlias(ts, "sq");
3836 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
3837 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3838 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3839 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL,
3840 "linked cell name");
3842 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
3843 "configure new cell alias");
3844 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
3845 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
3847 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3849 * Turn this on only if you wish to be able to talk to a server which is listening
3850 * on alternative ports. This is not intended for general use and may not be
3851 * supported in the cache manager. It is not a way to run two servers at the
3852 * same host, since the cache manager cannot properly distinguish those two hosts.
3854 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL,
3855 "cell's fileserver port");
3856 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL,
3857 "cell's vldb server port");
3860 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
3861 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3863 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
3864 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3866 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
3869 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, NULL, "obsolete (listed primary cell)");
3872 /* set cache monitor host address */
3873 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, (char *)CMD_HIDDEN);
3874 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL,
3875 "host name or 'off'");
3876 cmd_CreateAlias(ts, "mariner");
3878 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
3879 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3881 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
3882 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3883 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3884 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL,
3885 "disallow setuid programs");
3887 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL,
3888 "flush all data in volume");
3889 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3891 cmd_CreateSyntax("flushall", FlushAllVolumesCmd, NULL, "flush all data from the cache");
3893 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL,
3894 "get/set sysname (i.e. @sys) value");
3895 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3897 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL,
3898 "enable/disable translators to AFS");
3899 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3900 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL,
3901 "start/stop translator (on | off)");
3902 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL,
3903 "convert from afs to unix mode (on | off)");
3904 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL,
3905 "run on strict 'uid check' mode (on | off)");
3906 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
3907 "allow nfs mounts to subdirs of /afs/.. (on | off)");
3908 cmd_AddParm(ts, "-clipags", CMD_SINGLE, CMD_OPTIONAL,
3909 "enable use of client-assigned PAG's (on | off)");
3910 cmd_AddParm(ts, "-pagcb", CMD_SINGLE, CMD_OPTIONAL,
3911 "enable callbacks to get creds from new clients (on | off)");
3914 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
3915 "store to server after file close");
3916 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL,
3917 "asynchrony for specified names");
3918 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3919 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL,
3920 "new default (KB)");
3921 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3922 cmd_CreateAlias(ts, "sb");
3924 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL,
3925 "set cache manager encryption flag");
3926 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3928 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL,
3929 "get cache manager encryption flag");
3931 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
3932 "Manage per process RX statistics");
3933 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3934 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3935 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3937 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
3938 "Manage per peer RX statistics");
3939 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3940 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3941 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3943 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
3944 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
3946 /* try to find volume location information */
3947 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL,
3948 "get fid for file(s)");
3949 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3951 ts = cmd_CreateSyntax("discon", DisconCmd, NULL,
3952 "disconnection mode");
3953 cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_REQUIRED, "offline | online");
3954 cmd_AddParm(ts, "-policy", CMD_SINGLE, CMD_OPTIONAL, "client | server");
3955 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Force reconnection, despite any synchronization issues.");
3956 cmd_AddParm(ts, "-uid", CMD_SINGLE, CMD_OPTIONAL, "Numeric UID of user whose tokens to use at reconnect.");
3958 ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, NULL, "nuke credentials for NFS client");
3959 cmd_AddParm(ts, "-addr", CMD_SINGLE, 0, "host name or address");
3961 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
3962 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_REQUIRED, "generate a new UUID");
3964 ts = cmd_CreateSyntax("precache", PreCacheCmd, 0,
3965 "set precache size");
3966 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3967 "size in 1K byte blocks (0 => disable)");
3969 code = cmd_Dispatch(argc, argv);
3977 Die(int errnum, char *filename)
3983 "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3986 fprintf(stderr, "%s: Invalid argument.\n", pn);
3990 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3992 fprintf(stderr, "%s: no such file returned\n", pn);
3996 "%s: You can not change a backup or readonly volume\n", pn);
4002 "%s: You don't have the required access rights on '%s'\n",
4006 "%s: You do not have the required rights to do this operation\n",
4011 fprintf(stderr, "%s:'%s'", pn, filename);
4013 fprintf(stderr, "%s", pn);
4014 fprintf(stderr, ": %s\n", afs_error_message(errnum));
4019 /* get clients interface addresses */
4021 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4024 struct ViceIoctl blob;
4025 struct sprefrequest *in;
4026 struct sprefinfo *out;
4028 in = (struct sprefrequest *)space;
4032 blob.in_size = sizeof(struct sprefrequest);
4033 blob.in = (char *)in;
4035 blob.out_size = AFS_PIOCTL_MAXSIZE;
4038 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
4039 /* returns addr in network byte order */
4040 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
4042 perror("getClientInterfaceAddr pioctl");
4048 out = (struct sprefinfo *)blob.out;
4049 for (i = 0; i < out->num_servers; i++) {
4052 addr = ntohl(out->servers[i].server.s_addr);
4053 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
4054 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
4055 printf("%-50s\n", tbuffer);
4057 in->offset = out->next_offset;
4059 } while (out->next_offset > 0);
4065 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4067 afs_int32 code, addr;
4068 struct cmd_item *ti;
4069 struct ViceIoctl blob;
4070 struct setspref *ssp;
4071 int sizeUsed = 0, i, flag;
4072 afs_uint32 existingAddr[1024]; /* existing addresses on this host */
4076 ssp = (struct setspref *)space;
4077 ssp->num_servers = 0;
4080 blob.out_size = AFS_PIOCTL_MAXSIZE;
4083 fprintf(stderr, "Permission denied: requires root access.\n");
4087 /* extract all existing interface addresses */
4088 existNu = rx_getAllAddr(existingAddr, 1024);
4092 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
4093 for (ti = as->parms[0].items; ti; ti = ti->next) {
4094 if (sizeUsed >= sizeof(space)) {
4095 fprintf(stderr, "No more space\n");
4098 addr = extractAddr(ti->data, 20); /* network order */
4099 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
4100 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
4105 /* see if it is an address that really exists */
4106 for (flag = 0, i = 0; i < existNu; i++)
4107 if (existingAddr[i] == addr) {
4111 if (!flag) { /* this is an nonexistent address */
4112 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
4116 /* copy all specified addr into ioctl buffer */
4117 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
4118 printf("Adding 0x%08x\n", addr);
4120 sizeUsed += sizeof(struct spref);
4122 if (ssp->num_servers < 1) {
4123 fprintf(stderr, "No addresses specified\n");
4126 blob.in_size = sizeUsed - sizeof(struct spref);
4128 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
4138 FlushMountCmd(struct cmd_syndesc *as, void *arock)
4141 struct ViceIoctl blob;
4142 struct cmd_item *ti;
4143 char *last_component;
4147 for (ti = as->parms[0].items; ti; ti = ti->next) {
4148 if (GetLastComponent(ti->data, &parent_dir,
4149 &last_component, NULL) != 0) {
4154 blob.in = last_component;
4155 blob.in_size = strlen(last_component) + 1;
4158 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4160 free(last_component);
4163 if (errno == EINVAL) {
4164 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4166 Die(errno, (ti->data ? ti->data : parent_dir));
4176 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4179 afs_int32 flags = 0;
4180 struct ViceIoctl blob;
4182 if (as->parms[0].items) { /* -enable */
4183 flags |= AFSCALL_RXSTATS_ENABLE;
4185 if (as->parms[1].items) { /* -disable */
4186 flags |= AFSCALL_RXSTATS_DISABLE;
4188 if (as->parms[2].items) { /* -clear */
4189 flags |= AFSCALL_RXSTATS_CLEAR;
4192 fprintf(stderr, "You must specify at least one argument\n");
4196 blob.in = (char *)&flags;
4197 blob.in_size = sizeof(afs_int32);
4200 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4210 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4213 afs_int32 flags = 0;
4214 struct ViceIoctl blob;
4216 if (as->parms[0].items) { /* -enable */
4217 flags |= AFSCALL_RXSTATS_ENABLE;
4219 if (as->parms[1].items) { /* -disable */
4220 flags |= AFSCALL_RXSTATS_DISABLE;
4222 if (as->parms[2].items) { /* -clear */
4223 flags |= AFSCALL_RXSTATS_CLEAR;
4226 fprintf(stderr, "You must specify at least one argument\n");
4230 blob.in = (char *)&flags;
4231 blob.in_size = sizeof(afs_int32);
4234 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4244 GetFidCmd(struct cmd_syndesc *as, void *arock)
4246 struct ViceIoctl blob;
4247 struct cmd_item *ti;
4251 char cell[MAXCELLCHARS];
4253 SetDotDefault(&as->parms[0].items);
4254 for (ti = as->parms[0].items; ti; ti = ti->next) {
4255 struct VenusFid vfid;
4257 blob.out_size = sizeof(struct VenusFid);
4258 blob.out = (char *) &vfid;
4261 code = pioctl(ti->data, VIOCGETFID, &blob, 1);
4263 Die(errno,ti->data);
4268 code = GetCell(ti->data, cell);
4270 if (errno == ENOENT)
4271 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
4273 Die(errno, ti->data);
4278 printf("File %s (%u.%u.%u) located in cell %s\n",
4279 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,