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