This is essentially a line-for-line translation of the C inspection
code.
---
daemon/Makefile.am | 8 +
daemon/inspect.ml| 396 +
daemon/inspect.mli | 41 +++
daemon/inspect_fs.ml | 363 +++
daemon/inspect_fs.mli| 23 ++
daemon/inspect_fs_unix.ml| 745 +++
daemon/inspect_fs_unix.mli | 44 +++
daemon/inspect_fs_unix_fstab.ml | 533
daemon/inspect_fs_unix_fstab.mli | 34 ++
9 files changed, 2187 insertions(+)
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 51737e511..f035add2b 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -252,6 +252,10 @@ SOURCES_MLI = \
file.mli \
filearch.mli \
findfs.mli \
+ inspect.mli \
+ inspect_fs.mli \
+ inspect_fs_unix.mli \
+ inspect_fs_unix_fstab.mli \
inspect_types.mli \
inspect_utils.mli \
is.mli \
@@ -291,6 +295,10 @@ SOURCES_ML = \
realpath.ml \
inspect_types.ml \
inspect_utils.ml \
+ inspect_fs_unix_fstab.ml \
+ inspect_fs_unix.ml \
+ inspect_fs.ml \
+ inspect.ml \
callbacks.ml \
daemon.ml
diff --git a/daemon/inspect.ml b/daemon/inspect.ml
new file mode 100644
index 0..0f5bcfc10
--- /dev/null
+++ b/daemon/inspect.ml
@@ -0,0 +1,396 @@
+(* guestfs-inspection
+ * Copyright (C) 2009-2017 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+open Printf
+
+open Std_utils
+
+open Utils
+open Mountable
+open Inspect_types
+
+let re_primary_partition = PCRE.compile "^/dev/(?:h|s|v)d.[1234]$"
+
+let rec inspect_os () =
+ Mount.umount_all ();
+
+ (* Iterate over all detected filesystems. Inspect each one in turn. *)
+ let fses = Listfs.list_filesystems () in
+
+ let fses =
+filter_map (
+ fun (mountable, vfs_type) ->
+Inspect_fs.check_for_filesystem_on mountable vfs_type
+ ) fses in
+ if verbose () then (
+eprintf "inspect_os: fses:\n";
+List.iter (fun fs -> eprintf "%s" (string_of_fs fs)) fses;
+flush stderr
+ );
+
+ (* The OS inspection information for CoreOS are gathered by inspecting
+ * multiple filesystems. Gather all the inspected information in the
+ * inspect_fs struct of the root filesystem.
+ *)
+ let fses = collect_coreos_inspection_info fses in
+
+ (* Check if the same filesystem was listed twice as root in fses.
+ * This may happen for the *BSD root partition where an MBR partition
+ * is a shadow of the real root partition probably /dev/sda5
+ *)
+ let fses = check_for_duplicated_bsd_root fses in
+
+ (* For Linux guests with a separate /usr filesystem, merge some of the
+ * inspected information in that partition to the inspect_fs struct
+ * of the root filesystem.
+ *)
+ let fses = collect_linux_inspection_info fses in
+
+ (* Save what we found in a global variable. *)
+ Inspect_types.inspect_fses := fses;
+
+ (* At this point we have, in the handle, a list of all filesystems
+ * found and data about each one. Now we assemble the list of
+ * filesystems which are root devices.
+ *
+ * Fall through to inspect_get_roots to do that.
+ *)
+ inspect_get_roots ()
+
+(* Traverse through the filesystem list and find out if it contains
+ * the [/] and [/usr] filesystems of a CoreOS image. If this is the
+ * case, sum up all the collected information on the root fs.
+ *)
+and collect_coreos_inspection_info fses =
+ (* Split the list into CoreOS root(s), CoreOS usr(s), and
+ * everything else.
+ *)
+ let rec loop roots usrs others = function
+| [] -> roots, usrs, others
+| ({ role = RoleRoot { distro = Some DISTRO_COREOS } } as r) :: rest ->
+ loop (r::roots) usrs others rest
+| ({ role = RoleUsr { distro = Some DISTRO_COREOS } } as u) :: rest ->
+ loop roots (u::usrs) others rest
+| o :: rest ->
+ loop roots usrs (o::others) rest
+ in
+ let roots, usrs, others = loop [] [] [] fses in
+
+ match roots with
+ (* If there are no CoreOS roots, then there's nothing to do. *)
+ | [] -> fses
+ (* If there are more than one CoreOS roots, we cannot inspect the guest. *)
+ | _::_::_ -> failwith "multiple CoreOS root filesyste