133f422fbb213bd8869c9a9445e01e3e91e3d603
[openafs.git] / src / venus / test / getinitparams.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 /* Get CM initialization parameters. */
11 #include <afsconfig.h>
12
13
14 #include <afs/param.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <netinet/in.h>
18 #include <afs/vice.h>
19 #include <afs/venus.h>
20 #include <afs/cmd.h>
21 #include <fcntl.h>
22 #include <unistd.h>
23 #ifdef AFS_AIX41_ENV
24 #include <signal.h>
25 #endif
26
27 /*
28  * if -file <path> is given, fetch initialization parameters via ioctl()
29  * on that file
30  *
31  * otherwise, fetch initialization paramters via lpioctl()
32  */
33
34
35
36 int
37 GetInitParamsCmd(struct cmd_syndesc *as, void *arock)
38 {
39     struct cm_initparams cm_initParams;
40     struct ViceIoctl blob;
41     int code;
42     char *file = 0;
43     int fd = 0;
44
45     if (as->parms[0].items) {
46         file = as->parms[0].items->data;
47     }
48
49     if (file) {
50         printf("ioctl test\n");
51         fd = open(file, O_RDONLY, 0);
52         if (fd < 0) {
53             perror("open");
54             exit(1);
55         }
56     } else {
57         printf("lpioctl test\n");
58     }
59
60     blob.in = (char *)0;
61     blob.in_size = 0;
62     blob.out = (char *)&cm_initParams;
63     blob.out_size = sizeof(struct cm_initparams);
64
65     if (file) {
66         code = ioctl(fd, VIOC_GETINITPARAMS, &blob);
67         if (code < 0) {
68             perror("ioctl: Error getting CM initialization parameters");
69             exit(1);
70         }
71         close(fd);
72     } else {
73         code = lpioctl(NULL, VIOC_GETINITPARAMS, &blob, 0);
74         if (code) {
75             perror("lpioctl: Error getting CM initialization parameters");
76             exit(1);
77         }
78     }
79
80     printf("cm_initparams version: %d\n", cm_initParams.cmi_version);
81     printf("Chunk Files: %d\n", cm_initParams.cmi_nChunkFiles);
82     printf("Stat Caches: %d\n", cm_initParams.cmi_nStatCaches);
83     printf("Data Caches: %d\n", cm_initParams.cmi_nDataCaches);
84     printf("Volume Caches: %d\n", cm_initParams.cmi_nVolumeCaches);
85     printf("First Chunk Size: %d\n", cm_initParams.cmi_firstChunkSize);
86     printf("Other Chunk Size: %d\n", cm_initParams.cmi_otherChunkSize);
87     printf("Initial Cache Size: %dK\n", cm_initParams.cmi_cacheSize);
88     printf("CM Sets Time: %c\n", cm_initParams.cmi_setTime ? 'Y' : 'N');
89     printf("Disk Based Cache: %c\n", cm_initParams.cmi_memCache ? 'N' : 'Y');
90
91     exit(0);
92 }
93
94 int
95 main(int ac, char **av)
96 {
97     int code;
98     struct cmd_syndesc *ts;
99
100 #ifdef  AFS_AIX32_ENV
101     /*
102      * The following signal action for AIX is necessary so that in case of a 
103      * crash (i.e. core is generated) we can include the user's data section 
104      * in the core dump. Unfortunately, by default, only a partial core is
105      * generated which, in many cases, isn't too useful.
106      */
107     struct sigaction nsa;
108
109     sigemptyset(&nsa.sa_mask);
110     nsa.sa_handler = SIG_DFL;
111     nsa.sa_flags = SA_FULLDUMP;
112     sigaction(SIGSEGV, &nsa, NULL);
113 #endif
114
115     ts = cmd_CreateSyntax(NULL, GetInitParamsCmd, NULL,
116                           "Get CM initialization parameters");
117
118     cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "filename in AFS");
119     code = cmd_Dispatch(ac, av);
120     exit(code);
121 }