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