94d83dc33372532b02076b68fca01d6d08cd6908
[openafs.git] / src / venus / twiddle.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12 #include <afs/stds.h>
13
14 #include <roken.h>
15
16 #include <rx/xdr.h>
17 #include <afs/com_err.h>
18 #include <afs/vice.h>
19 #include <afs/venus.h>
20 #undef VIRTUE
21 #undef VICE
22 #include "afs/prs_fs.h"
23 #include <afs/afsint.h>
24 #include <afs/cellconfig.h>
25 #include <afs/cmd.h>
26 #include <afs/com_err.h>
27 #include <afs/afs_consts.h>
28 #include <afs/sys_prototypes.h>
29
30 #define MAXINSIZE 1300          /* pioctl complains if data is larger than this */
31 #define VMSGSIZE 128            /* size of msg buf in volume hdr */
32
33 static void Die(int code, char *filename);
34
35 static char pn[] = "fs";
36 static int rxInitDone = 0;
37
38 static int
39 Twiddle(struct cmd_syndesc *as, void *arock)
40 {
41     afs_int32 code;
42     struct ViceIoctl blob;
43     struct cmd_item *ti;
44     struct rxparams rxp;
45     int tmp;
46
47     ti = as->parms[0].items;
48     if (ti && ti->data) {
49         tmp = atoi(ti->data);
50     } else
51         tmp = 0;
52     rxp.rx_initReceiveWindow = tmp;
53     ti = as->parms[1].items;
54     if (ti && ti->data) {
55         tmp = atoi(ti->data);
56     } else
57         tmp = 0;
58     rxp.rx_maxReceiveWindow = tmp;
59     ti = as->parms[2].items;
60     if (ti && ti->data) {
61         tmp = atoi(ti->data);
62     } else
63         tmp = 0;
64     rxp.rx_initSendWindow = tmp;
65     ti = as->parms[3].items;
66     if (ti && ti->data) {
67         tmp = atoi(ti->data);
68     } else
69         tmp = 0;
70     rxp.rx_maxSendWindow = tmp;
71     ti = as->parms[4].items;
72     if (ti && ti->data) {
73         tmp = atoi(ti->data);
74     } else
75         tmp = 0;
76     rxp.rxi_nSendFrags = tmp;
77     ti = as->parms[5].items;
78     if (ti && ti->data) {
79         tmp = atoi(ti->data);
80     } else
81         tmp = 0;
82     rxp.rxi_nRecvFrags = tmp;
83     ti = as->parms[6].items;
84     if (ti && ti->data) {
85         tmp = atoi(ti->data);
86     } else
87         tmp = 0;
88     rxp.rxi_OrphanFragSize = tmp;
89     ti = as->parms[7].items;
90     if (ti && ti->data) {
91         tmp = atoi(ti->data);
92     } else
93         tmp = 0;
94     rxp.rx_maxReceiveSize = tmp;
95     ti = as->parms[8].items;
96     if (ti && ti->data) {
97         tmp = atoi(ti->data);
98     } else
99         tmp = 0;
100     rxp.rx_MyMaxSendSize = tmp;
101
102     blob.in = (char *)&rxp;
103     blob.out = (char *)&rxp;
104     blob.in_size = sizeof(rxp);
105     blob.out_size = sizeof(rxp);
106     code = pioctl(0, VIOC_TWIDDLE, &blob, 1);
107
108     if (code) {
109         Die(code, 0);
110     }
111     return code;
112 }
113
114 #include "AFS_component_version_number.c"
115
116 int
117 main(int argc, char **argv)
118 {
119     afs_int32 code;
120     struct cmd_syndesc *ts;
121
122 #ifdef  AFS_AIX32_ENV
123     /*
124      * The following signal action for AIX is necessary so that in case of a
125      * crash (i.e. core is generated) we can include the user's data section
126      * in the core dump. Unfortunately, by default, only a partial core is
127      * generated which, in many cases, isn't too useful.
128      */
129     struct sigaction nsa;
130
131     sigemptyset(&nsa.sa_mask);
132     nsa.sa_handler = SIG_DFL;
133     nsa.sa_flags = SA_FULLDUMP;
134     sigaction(SIGSEGV, &nsa, NULL);
135 #endif
136     /* try to find volume location information */
137
138
139     ts = cmd_CreateSyntax(NULL, Twiddle, NULL, "adjust rx parms");
140     cmd_AddParm(ts, "-initReceiveWindow ", CMD_SINGLE, CMD_OPTIONAL, "16");
141     cmd_AddParm(ts, "-maxReceiveWindow ", CMD_SINGLE, CMD_OPTIONAL, "16");
142     cmd_AddParm(ts, "-initSendWindow ", CMD_SINGLE, CMD_OPTIONAL, "8");
143     cmd_AddParm(ts, "-maxSendWindow ", CMD_SINGLE, CMD_OPTIONAL, "16");
144     cmd_AddParm(ts, "-nSendFrags ", CMD_SINGLE, CMD_OPTIONAL, "4");
145     cmd_AddParm(ts, "-nRecvFrags ", CMD_SINGLE, CMD_OPTIONAL, "4");
146     cmd_AddParm(ts, "-OrphanFragSize ", CMD_SINGLE, CMD_OPTIONAL, "512");
147     cmd_AddParm(ts, "-maxReceiveSize ", CMD_SINGLE, CMD_OPTIONAL, "");
148     cmd_AddParm(ts, "-MyMaxSendSize ", CMD_SINGLE, CMD_OPTIONAL, "");
149
150     code = cmd_Dispatch(argc, argv);
151     if (rxInitDone)
152         rx_Finalize();
153
154     exit(code);
155 }
156
157 static void
158 Die(int code, char *filename)
159 {                               /*Die */
160
161     if (errno == EINVAL) {
162         if (filename)
163             fprintf(stderr,
164                     "%s: Invalid argument; it is possible that %s is not in AFS.\n",
165                     pn, filename);
166         else
167             fprintf(stderr, "%s: Invalid argument.\n", pn);
168     } else if (errno == ENOENT) {
169         if (filename)
170             fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
171         else
172             fprintf(stderr, "%s: no such file returned\n", pn);
173     } else if (errno == EROFS)
174         fprintf(stderr,
175                 "%s: You can not change a backup or readonly volume\n", pn);
176     else if (errno == EACCES || errno == EPERM) {
177         if (filename)
178             fprintf(stderr,
179                     "%s: You don't have the required access rights on '%s'\n",
180                     pn, filename);
181         else
182             fprintf(stderr,
183                     "%s: You do not have the required rights to do this operation\n",
184                     pn);
185     } else {
186         if (filename)
187             fprintf(stderr, "%s:'%s'", pn, filename);
188         else
189             fprintf(stderr, "%s", pn);
190         fprintf(stderr, ": %s\n", afs_error_message(errno));
191     }
192 }                               /*Die */