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