1 (* Memory info for virtual domains.
2 (C) Copyright 2008 Richard W.M. Jones, Red Hat Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 open Virt_mem_gettext.Gettext
27 virt-uname - uname command for virtual machines
30 virt-uname [-options] [domains]
33 virt-uname prints the uname information such as OS version,
34 architecture and node name for virtual machines running under
37 let _, images = Virt_mem.start usage
40 (* Print new_utsname structure from bitstring. *)
41 let print_new_utsname name bs =
42 (* Truncate an OCaml string at the first ASCII NUL character, ie. as
43 * if it were a C string.
47 let i = String.index str '\000' in
53 | { sysname : 65*8 : string;
54 nodename : 65*8 : string;
55 release : 65*8 : string;
56 version : 65*8 : string;
57 machine : 65*8 : string;
58 domainname : 65*8 : string } ->
59 printf "%s: %s %s %s %s %s %s\n"
61 (truncate sysname) (truncate nodename) (truncate release)
62 (truncate version) (truncate machine) (truncate domainname)
64 eprintf (f_"%s: unexpected system_utsname in kernel image\n")
69 fun (name, arch, mem, lookup_ksym) ->
70 (* In Linux 2.6.25, the symbol is init_uts_ns.
71 * http://lxr.linux.no/linux/init/version.c
74 let addr = lookup_ksym "init_uts_ns" in
76 let bs = Bitmatch.bitstring_of_string (get_bytes mem addr (65*6+4)) in
78 | { _ : 32 : int; (* the kref, atomic_t, always 32 bits *)
79 new_utsname : -1 : bitstring } ->
80 print_new_utsname name new_utsname
82 eprintf (f_"%s: unexpected init_uts_ns in kernel image\n")
86 (* In Linux 2.6.9, the symbol is system_utsname.
87 * http://lxr.linux.no/linux-bk+v2.6.9/include/linux/utsname.h#L24
90 let addr = lookup_ksym "system_utsname" in
93 Bitmatch.bitstring_of_string (get_bytes mem addr (65*6)) in
94 print_new_utsname name bs
97 eprintf (f_"%s: could not find utsname in kernel image\n") name