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