+ invalid_arg
+ (sprintf "LVM2: read_pv_label: %s: not an LVM2 physical volume" dev#name)
+
+and read_metadata dev offset32 len32 =
+ if debug then
+ eprintf "metadata: offset 0x%lx len %ld bytes\n" offset32 len32;
+
+ (* Check the offset and length are sensible. *)
+ let offset64 =
+ if offset32 <= Int32.max_int then Int64.of_int32 offset32
+ else invalid_arg "LVM2: read_metadata: metadata offset too large" in
+ let len64 =
+ if len32 <= 2_147_483_647_l then Int64.of_int32 len32
+ else invalid_arg "LVM2: read_metadata: metadata length too large" in
+
+ if offset64 <= 0x1200L || offset64 >= dev#size
+ || len64 <= 0L || offset64 +^ len64 >= dev#size then
+ invalid_arg "LVM2: read_metadata: bad metadata offset or length";
+
+ (* If it is outside the disk boundaries, this will throw an exception,
+ * otherwise it will read and return the metadata string.
+ *)
+ dev#read offset64 (Int64.to_int len64)