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