X-Git-Url: http://git.annexia.org/?p=virt-top.git;a=blobdiff_plain;f=virt-df%2Fvirt_df_lvm2.ml;h=4247dc3e0a6d79da9e5b84536d7bc984bfa2f222;hp=a79ec7f58247d3890a6bd1d1c18643cc914850b9;hb=0019c13c600d34f12778e849246711bb20ba4ee2;hpb=748302caa93af2c412bcd30dad5787a5a24e9af5 diff --git a/virt-df/virt_df_lvm2.ml b/virt-df/virt_df_lvm2.ml index a79ec7f..4247dc3 100644 --- a/virt-df/virt_df_lvm2.ml +++ b/virt-df/virt_df_lvm2.ml @@ -24,9 +24,33 @@ open Printf open Virt_df_gettext.Gettext open Virt_df -let probe_lvm2 (dev : device) = - raise Not_found +let sector_size = 512 +let sector_size64 = 512L + +let pv_label_offset = sector_size64 + +let rec probe_pv dev = + try ignore (read_pv_label dev); true + with _ -> false + +and read_pv_label dev = + (* Load the second sector. *) + let bits = dev#read_bitstring pv_label_offset sector_size in + + bitmatch bits with + | labelone : 8*8 : bitstring; (* "LABELONE" *) + padding : 16*8 : bitstring; + lvm2_ver : 8*8 : bitstring; (* "LVM2 001" *) + uuid : 32*8 : bitstring (* UUID *) + when Bitmatch.string_of_bitstring labelone = "LABELONE" && + Bitmatch.string_of_bitstring lvm2_ver = "LVM2 001" -> + uuid + | _ -> + invalid_arg (sprintf "read_pv_label: %s: not an LVM2 physical volume" + dev#name) + +let list_lvs devs = [] (* Register with main code. *) let () = - filesystem_type_register "LVM2" probe_lvm2 + lvm_type_register "LVM2" probe_pv list_lvs