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