Sync usage with man page.
[netbsd-mini2440.git] / sys / compat / irix / irix_systeminfo.c
blobe3d19595ec32b4f9c333c61651306529fe048e4a
1 /* $NetBSD: irix_systeminfo.c,v 1.15 2007/12/20 23:02:51 dsl Exp $ */
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Emmanuel Dreyfus.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: irix_systeminfo.c,v 1.15 2007/12/20 23:02:51 dsl Exp $");
35 #include <sys/types.h>
36 #include <sys/signal.h>
37 #include <sys/param.h>
38 #include <sys/mount.h>
39 #include <sys/kernel.h>
40 #include <sys/proc.h>
41 #include <sys/systm.h>
42 #include <sys/sysctl.h>
43 #include <sys/syscallargs.h>
45 #include <compat/common/compat_util.h>
47 #include <compat/svr4/svr4_systeminfo.h>
48 #include <compat/svr4/svr4_types.h>
49 #include <compat/svr4/svr4_signal.h>
50 #include <compat/svr4/svr4_ucontext.h>
51 #include <compat/svr4/svr4_lwp.h>
52 #include <compat/svr4/svr4_syscallargs.h>
54 #include <compat/irix/irix_types.h>
55 #include <compat/irix/irix_signal.h>
56 #include <compat/irix/irix_sysctl.h>
57 #include <compat/irix/irix_syscallargs.h>
59 char irix_si_vendor[128] = "Silicon Graphics, Inc.";
60 char irix_si_os_provider[128] = "Silicon Graphics, Inc.";
61 char irix_si_os_name[128] = "IRIX";
62 char irix_si_hw_name[128] = "IP22"; /* XXX */
63 char irix_si_osrel_maj[128] = "6";
64 char irix_si_osrel_min[128] = "5";
65 char irix_si_osrel_patch[128] = "0";
66 char irix_si_processors[128] = "R5000 1.0"; /* XXX */
67 char irix_si_version[128] = "04131232";
69 #define BUF_SIZE 16
71 int
72 irix_sys_systeminfo(struct lwp *l, const struct irix_sys_systeminfo_args *uap, register_t *retval)
74 /* {
75 syscallarg(int) what;
76 syscallarg(char *) buf;
77 syscallarg(long) len;
78 } */
79 const char *str = NULL;
80 char strbuf[BUF_SIZE + 1];
81 int error = 0;
82 size_t len = 0;
83 char buf[256];
85 u_int rlen = SCARG(uap, len);
87 switch (SCARG(uap, what)) {
88 case SVR4_MIPS_SI_VENDOR:
89 str = irix_si_vendor;
90 break;
92 case SVR4_MIPS_SI_OS_PROVIDER:
93 str = irix_si_os_provider;
94 break;
96 case SVR4_MIPS_SI_OS_NAME:
97 str = irix_si_os_name;
98 break;
100 case SVR4_MIPS_SI_HW_NAME:
101 str = irix_si_hw_name;
102 break;
104 case SVR4_MIPS_SI_OSREL_MAJ:
105 str = irix_si_osrel_maj;
106 break;
108 case SVR4_MIPS_SI_OSREL_MIN:
109 str = irix_si_osrel_min;
110 break;
112 case SVR4_MIPS_SI_OSREL_PATCH:
113 str = irix_si_osrel_patch;
114 break;
116 case SVR4_MIPS_SI_PROCESSORS:
117 str = irix_si_processors;
118 break;
120 case SVR4_MIPS_SI_NUM_PROCESSORS:
121 case SVR4_MIPS_SI_AVAIL_PROCESSORS: {
122 snprintf(strbuf, BUF_SIZE, "%d", ncpu);
123 str = strbuf;
124 break;
127 case SVR4_SI_HW_SERIAL:
128 snprintf(strbuf, BUF_SIZE, "%d", (int32_t)hostid);
129 str = strbuf;
130 break;
132 case SVR4_MIPS_SI_HOSTID:
133 snprintf(strbuf, BUF_SIZE, "%08x", (int32_t)hostid);
134 str = strbuf;
135 break;
137 case SVR4_MIPS_SI_SERIAL: /* Unimplemented yet */
138 default:
139 return svr4_sys_systeminfo(l, (const void *)uap, retval);
140 break;
144 * This duplicates some code in
145 * svr4_sys_systeminfo().
146 * Ideally, it should be merged.
148 if (str) {
149 len = strlen(str) + 1;
150 if (len > rlen)
151 len = rlen;
153 if (SCARG(uap, buf)) {
154 error = copyout(str, SCARG(uap, buf), len);
155 if (error)
156 return error;
157 /* make sure we are NULL terminated */
158 buf[0] = '\0';
159 error = copyout(buf, &(SCARG(uap, buf)[len - 1]), 1);
161 else
162 error = 0;
165 *retval = len;
166 return error;