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