The function takes one argument - device path (e.g. /dev/sda) and returns true if device
contains partition(s) or false otherwise. The function look in /sys/block/<device>/
for entries starting with <device>, eg. /sys/block/sda/sda1.
---
daemon/devsparts.ml | 14 ++++++++++++++
daemon/devsparts.mli | 1 +
2 files changed, 15 insertions(+)
diff --git a/daemon/devsparts.ml b/daemon/devsparts.ml
index 54108bb..60ac11a 100644
--- a/daemon/devsparts.ml
+++ b/daemon/devsparts.ml
@@ -71,6 +71,20 @@ let list_devices () =
map_block_devices ~return_md:false ((^) "/dev/") in
sort_device_names devices
+let is_partitioned_device device =
+ assert (String.is_prefix device "/dev/");
+ assert (not (String.is_prefix device "/dev/mapper/"));
+ let device = String.sub device 5 (String.length device - 5) in
+
+ (* Open the device's directory under /sys/block *)
+ let parts = Sys.readdir ("/sys/block/" ^ device) in
+ let parts = Array.to_list parts in
+
+ (* Look in /sys/block/<device>/ for entries starting with
+ * <device>, eg. /sys/block/sda/sda1.
+ *)
+ List.exists (fun part -> String.is_prefix part device) parts
+
let rec list_partitions () =
let partitions = map_block_devices ~return_md:true add_partitions in
let partitions = List.flatten partitions in
diff --git a/daemon/devsparts.mli b/daemon/devsparts.mli
index 7b669c2..d3224a1 100644
--- a/daemon/devsparts.mli
+++ b/daemon/devsparts.mli
@@ -21,5 +21,6 @@ val list_partitions : unit -> string list
val part_to_dev : string -> string
val part_to_partnum : string -> int
val is_whole_device : string -> bool
+val is_partitioned_device : string -> bool
val nr_devices : unit -> int
val device_index : string -> int
--
2.9.5