Blame SOURCES/0098-mllib-Add-Common_utils.is_partition-function.patch

e76f14
From 53ea0055668938fc7b77431d54f36f9daa6da03f Mon Sep 17 00:00:00 2001
e76f14
From: "Richard W.M. Jones" <rjones@redhat.com>
e76f14
Date: Thu, 2 Jun 2016 15:10:04 +0100
e76f14
Subject: [PATCH] mllib: Add Common_utils.is_partition function.
e76f14
e76f14
Returns true if the device is a host partition.
e76f14
e76f14
The only tedious bit of this patch is that now Common_utils depends on
e76f14
Dev_t so we have to add extra objects every time something links with
e76f14
Common_utils.
e76f14
e76f14
(cherry picked from commit df7a33768eab2381b958ede2c8a40bc9cbc87928)
e76f14
---
e76f14
 builder/Makefile.am    |  2 ++
e76f14
 customize/Makefile.am  |  2 ++
e76f14
 dib/Makefile.am        |  2 ++
e76f14
 get-kernel/Makefile.am |  2 ++
e76f14
 mllib/common_utils.ml  | 13 +++++++++++++
e76f14
 mllib/common_utils.mli |  4 ++++
e76f14
 resize/Makefile.am     |  2 ++
e76f14
 sparsify/Makefile.am   |  2 ++
e76f14
 sysprep/Makefile.am    |  2 ++
e76f14
 v2v/Makefile.am        |  5 +++++
e76f14
 10 files changed, 36 insertions(+)
e76f14
e76f14
diff --git a/builder/Makefile.am b/builder/Makefile.am
e76f14
index f31aef9..54aa10b 100644
e76f14
--- a/builder/Makefile.am
e76f14
+++ b/builder/Makefile.am
e76f14
@@ -89,6 +89,7 @@ SOURCES_ML = \
e76f14
 	builder.ml
e76f14
 
e76f14
 SOURCES_C = \
e76f14
+	../mllib/dev_t-c.c \
e76f14
 	../mllib/fsync-c.c \
e76f14
 	../mllib/uri-c.c \
e76f14
 	../mllib/mkdtemp-c.c \
e76f14
@@ -134,6 +135,7 @@ BOBJECTS = \
e76f14
 	$(top_builddir)/mllib/libdir.cmo \
e76f14
 	$(top_builddir)/mllib/guestfs_config.cmo \
e76f14
 	$(top_builddir)/mllib/common_gettext.cmo \
e76f14
+	$(top_builddir)/mllib/dev_t.cmo \
e76f14
 	$(top_builddir)/mllib/common_utils.cmo \
e76f14
 	$(top_builddir)/mllib/fsync.cmo \
e76f14
 	$(top_builddir)/mllib/planner.cmo \
e76f14
diff --git a/customize/Makefile.am b/customize/Makefile.am
e76f14
index 033816c..661917a 100644
e76f14
--- a/customize/Makefile.am
e76f14
+++ b/customize/Makefile.am
e76f14
@@ -69,6 +69,7 @@ SOURCES_C = \
e76f14
 	../fish/uri.c \
e76f14
 	../fish/file-edit.c \
e76f14
 	../fish/file-edit.h \
e76f14
+	../mllib/dev_t-c.c \
e76f14
 	../mllib/uri-c.c \
e76f14
 	crypt-c.c \
e76f14
 	perl_edit-c.c
e76f14
@@ -93,6 +94,7 @@ virt_customize_CFLAGS = \
e76f14
 BOBJECTS = \
e76f14
 	$(top_builddir)/mllib/guestfs_config.cmo \
e76f14
 	$(top_builddir)/mllib/common_gettext.cmo \
e76f14
+	$(top_builddir)/mllib/dev_t.cmo \
e76f14
 	$(top_builddir)/mllib/common_utils.cmo \
e76f14
 	$(top_builddir)/mllib/regedit.cmo \
e76f14
 	$(top_builddir)/mllib/URI.cmo \
e76f14
diff --git a/dib/Makefile.am b/dib/Makefile.am
e76f14
index b969677..d1674a9 100644
e76f14
--- a/dib/Makefile.am
e76f14
+++ b/dib/Makefile.am
e76f14
@@ -33,6 +33,7 @@ SOURCES_ML = \
e76f14
 	dib.ml
e76f14
 
e76f14
 SOURCES_C = \
e76f14
+	../mllib/dev_t-c.c \
e76f14
 	../mllib/mkdtemp-c.c
e76f14
 
e76f14
 bin_PROGRAMS =
e76f14
@@ -57,6 +58,7 @@ BOBJECTS = \
e76f14
 	$(top_builddir)/mllib/libdir.cmo \
e76f14
 	$(top_builddir)/mllib/guestfs_config.cmo \
e76f14
 	$(top_builddir)/mllib/common_gettext.cmo \
e76f14
+	$(top_builddir)/mllib/dev_t.cmo \
e76f14
 	$(top_builddir)/mllib/common_utils.cmo \
e76f14
 	$(top_builddir)/mllib/mkdtemp.cmo \
e76f14
 	$(SOURCES_ML:.ml=.cmo)
e76f14
diff --git a/get-kernel/Makefile.am b/get-kernel/Makefile.am
e76f14
index da94ece..9d8fc61 100644
e76f14
--- a/get-kernel/Makefile.am
e76f14
+++ b/get-kernel/Makefile.am
e76f14
@@ -27,6 +27,7 @@ SOURCES_ML = \
e76f14
 	get_kernel.ml
e76f14
 
e76f14
 SOURCES_C = \
e76f14
+	../mllib/dev_t-c.c \
e76f14
 	../mllib/uri-c.c \
e76f14
 	../fish/uri.c
e76f14
 
e76f14
@@ -56,6 +57,7 @@ BOBJECTS = \
e76f14
 	$(top_builddir)/mllib/libdir.cmo \
e76f14
 	$(top_builddir)/mllib/guestfs_config.cmo \
e76f14
 	$(top_builddir)/mllib/common_gettext.cmo \
e76f14
+	$(top_builddir)/mllib/dev_t.cmo \
e76f14
 	$(top_builddir)/mllib/common_utils.cmo \
e76f14
 	$(top_builddir)/mllib/URI.cmo \
e76f14
 	$(SOURCES_ML:.ml=.cmo)
e76f14
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
e76f14
index 2ba8f9a..c29dfa0 100644
e76f14
--- a/mllib/common_utils.ml
e76f14
+++ b/mllib/common_utils.ml
e76f14
@@ -819,6 +819,19 @@ let is_char_device file =
e76f14
   try (Unix.stat file).Unix.st_kind = Unix.S_CHR
e76f14
   with Unix.Unix_error _ -> false
e76f14
 
e76f14
+let is_partition dev =
e76f14
+  try
e76f14
+    if not (is_block_device dev) then false
e76f14
+    else (
e76f14
+      let rdev = (Unix.stat dev).Unix.st_rdev in
e76f14
+      let major = Dev_t.major rdev in
e76f14
+      let minor = Dev_t.minor rdev in
e76f14
+      let path = sprintf "/sys/dev/block/%d:%d/partition" major minor in
e76f14
+      Unix.access path [F_OK];
e76f14
+      true
e76f14
+    )
e76f14
+  with Unix.Unix_error _ -> false
e76f14
+
e76f14
 (* Annoyingly Sys.is_directory throws an exception on failure
e76f14
  * (RHBZ#1022431).
e76f14
  *)
e76f14
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
e76f14
index ae89fd6..4cfe7d0 100644
e76f14
--- a/mllib/common_utils.mli
e76f14
+++ b/mllib/common_utils.mli
e76f14
@@ -327,6 +327,10 @@ val is_char_device : string -> bool
e76f14
 val is_directory : string -> bool
e76f14
 (** These don't throw exceptions, unlike the [Sys] functions. *)
e76f14
 
e76f14
+val is_partition : string -> bool
e76f14
+(** Return true if the host device [dev] is a partition.  If it's
e76f14
+    anything else, or missing, returns false. *)
e76f14
+
e76f14
 val absolute_path : string -> string
e76f14
 (** Convert any path to an absolute path. *)
e76f14
 
e76f14
diff --git a/resize/Makefile.am b/resize/Makefile.am
e76f14
index f4d1626..e9f48da 100644
e76f14
--- a/resize/Makefile.am
e76f14
+++ b/resize/Makefile.am
e76f14
@@ -30,6 +30,7 @@ SOURCES_ML = \
e76f14
 	resize.ml
e76f14
 
e76f14
 SOURCES_C = \
e76f14
+	../mllib/dev_t-c.c \
e76f14
 	../mllib/fsync-c.c \
e76f14
 	../fish/progress.c \
e76f14
 	../mllib/progress-c.c \
e76f14
@@ -58,6 +59,7 @@ BOBJECTS = \
e76f14
 	$(top_builddir)/mllib/URI.cmo \
e76f14
 	$(top_builddir)/mllib/guestfs_config.cmo \
e76f14
 	$(top_builddir)/mllib/common_gettext.cmo \
e76f14
+	$(top_builddir)/mllib/dev_t.cmo \
e76f14
 	$(top_builddir)/mllib/common_utils.cmo \
e76f14
 	$(SOURCES_ML:.ml=.cmo)
e76f14
 XOBJECTS = $(BOBJECTS:.cmo=.cmx)
e76f14
diff --git a/sparsify/Makefile.am b/sparsify/Makefile.am
e76f14
index 3da7a7a..9df3e1f 100644
e76f14
--- a/sparsify/Makefile.am
e76f14
+++ b/sparsify/Makefile.am
e76f14
@@ -37,6 +37,7 @@ SOURCES_ML = \
e76f14
 
e76f14
 SOURCES_C = \
e76f14
 	../fish/progress.c \
e76f14
+	../mllib/dev_t-c.c \
e76f14
 	../mllib/progress-c.c \
e76f14
 	statvfs-c.c
e76f14
 
e76f14
@@ -57,6 +58,7 @@ virt_sparsify_CFLAGS = \
e76f14
 BOBJECTS = \
e76f14
 	$(top_builddir)/mllib/guestfs_config.cmo \
e76f14
 	$(top_builddir)/mllib/common_gettext.cmo \
e76f14
+	$(top_builddir)/mllib/dev_t.cmo \
e76f14
 	$(top_builddir)/mllib/common_utils.cmo \
e76f14
 	$(top_builddir)/mllib/progress.cmo \
e76f14
 	$(SOURCES_ML:.ml=.cmo)
e76f14
diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
e76f14
index b890bca..e439a88 100644
e76f14
--- a/sysprep/Makefile.am
e76f14
+++ b/sysprep/Makefile.am
e76f14
@@ -80,6 +80,7 @@ SOURCES_ML = \
e76f14
 	main.ml
e76f14
 
e76f14
 SOURCES_C = \
e76f14
+	../mllib/dev_t-c.c \
e76f14
 	../mllib/uri-c.c \
e76f14
 	../mllib/mkdtemp-c.c \
e76f14
 	../customize/crypt-c.c \
e76f14
@@ -106,6 +107,7 @@ virt_sysprep_CFLAGS = \
e76f14
 BOBJECTS = \
e76f14
 	$(top_builddir)/mllib/guestfs_config.cmo \
e76f14
 	$(top_builddir)/mllib/common_gettext.cmo \
e76f14
+	$(top_builddir)/mllib/dev_t.cmo \
e76f14
 	$(top_builddir)/mllib/common_utils.cmo \
e76f14
 	$(top_builddir)/mllib/URI.cmo \
e76f14
 	$(top_builddir)/mllib/mkdtemp.cmo \
e76f14
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
e76f14
index 5d0ce95..5bffbfe 100644
e76f14
--- a/v2v/Makefile.am
e76f14
+++ b/v2v/Makefile.am
e76f14
@@ -113,6 +113,7 @@ SOURCES_ML = \
e76f14
 	v2v.ml
e76f14
 
e76f14
 SOURCES_C = \
e76f14
+	../mllib/dev_t-c.c \
e76f14
 	../mllib/mkdtemp-c.c \
e76f14
 	domainxml-c.c \
e76f14
 	changeuid-c.c \
e76f14
@@ -137,6 +138,7 @@ virt_v2v_CFLAGS = \
e76f14
 BOBJECTS = \
e76f14
 	$(top_builddir)/mllib/guestfs_config.cmo \
e76f14
 	$(top_builddir)/mllib/common_gettext.cmo \
e76f14
+	$(top_builddir)/mllib/dev_t.cmo \
e76f14
 	$(top_builddir)/mllib/common_utils.cmo \
e76f14
 	$(top_builddir)/mllib/regedit.cmo \
e76f14
 	$(top_builddir)/mllib/mkdtemp.cmo \
e76f14
@@ -187,6 +189,7 @@ virt_v2v_LINK = \
e76f14
 	  $(OBJECTS) -o $@
e76f14
 
e76f14
 virt_v2v_copy_to_local_SOURCES = \
e76f14
+	../mllib/dev_t-c.c \
e76f14
 	domainxml-c.c \
e76f14
 	utils-c.c \
e76f14
 	xml-c.c
e76f14
@@ -203,6 +206,7 @@ virt_v2v_copy_to_local_CFLAGS = \
e76f14
 COPY_TO_LOCAL_BOBJECTS = \
e76f14
 	$(top_builddir)/mllib/guestfs_config.cmo \
e76f14
 	$(top_builddir)/mllib/common_gettext.cmo \
e76f14
+	$(top_builddir)/mllib/dev_t.cmo \
e76f14
 	$(top_builddir)/mllib/common_utils.cmo \
e76f14
 	$(top_builddir)/mllib/JSON.cmo \
e76f14
 	$(top_builddir)/mllib/curl.cmo \
e76f14
@@ -361,6 +365,7 @@ endif
e76f14
 v2v_unit_tests_BOBJECTS = \
e76f14
 	$(top_builddir)/mllib/guestfs_config.cmo \
e76f14
 	$(top_builddir)/mllib/common_gettext.cmo \
e76f14
+	$(top_builddir)/mllib/dev_t.cmo \
e76f14
 	$(top_builddir)/mllib/common_utils.cmo \
e76f14
 	$(top_builddir)/mllib/regedit.cmo \
e76f14
 	stringMap.cmo \
e76f14
-- 
e76f14
1.8.3.1
e76f14