On Friday, 14 July 2017 15:39:21 CEST Richard W.M. Jones wrote:
+(* All device mapper devices are called /dev/mapper/ldm_vol_*. XXX
We
+ * could tighten this up in future if ldmtool had a way to read these
+ * names back after they have been created.
+ *)
+let list_ldm_volumes () =
+ (* If /dev/mapper doesn't exist at all, don't give an error. *)
+ if not (is_directory "/dev/mapper") then
+ []
+ else (
+ let dir = Sys.readdir "/dev/mapper" in
+ let dir = Array.to_list dir in
+ let dir =
+ List.filter (fun d -> String.is_prefix d "ldm_vol_") dir in
+ let dir = List.map ((^) "/dev/mapper/") dir in
+ List.sort compare dir
+ )
+
+(* Same as above but /dev/mapper/ldm_part_*. *)
+let list_ldm_partitions () =
+ (* If /dev/mapper doesn't exist at all, don't give an error. *)
+ if not (is_directory "/dev/mapper") then
+ []
+ else (
+ let dir = Sys.readdir "/dev/mapper" in
+ let dir = Array.to_list dir in
+ let dir =
+ List.filter (fun d -> String.is_prefix d "ldm_part_") dir in
+ let dir = List.map ((^) "/dev/mapper/") dir in
+ List.sort compare dir
+ )
IMHO most of their code can be shared, like done in the C
implementations -- something like the following (untested):
let get_devices prefix =
(* If /dev/mapper doesn't exist at all, don't give an error. *)
if not (is_directory "/dev/mapper") then
[]
else (
let dir = Sys.readdir "/dev/mapper" in
let dir = Array.to_list dir in
let dir =
List.filter (fun d -> String.is_prefix d prefix) dir in
let dir = List.map ((^) "/dev/mapper/") dir in
List.sort compare dir
)
let list_ldm_volumes () =
get_devices "ldm_vol_"
let list_ldm_partitions () =
get_devices "ldm_part_"
--
Pino Toscano