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