let unmarshal_uint16 ?(bigendian=false) (s, offset) =
let offsets = if bigendian then [|1;0|] else [|0;1|] in
- let (<<) a b = a lsl b
- and (||) a b = a lor b in
+ let (<!<) a b = a lsl b
+ and (|!|) a b = a lor b in
let a = int_of_char (s.[offset + offsets.(0)])
and b = int_of_char (s.[offset + offsets.(1)]) in
- (a << 0) || (b << 8), (s, offset + 2)
+ (a <!< 0) |!| (b <!< 8), (s, offset + 2)
let unmarshal_uint32 ?(bigendian=false) (s, offset) =
let offsets = if bigendian then [|3;2;1;0|] else [|0;1;2;3|] in
- let (<<) a b = Int32.shift_left a b
- and (||) a b = Int32.logor a b in
+ let (<!<) a b = Int32.shift_left a b
+ and (|!|) a b = Int32.logor a b in
let a = Int32.of_int (int_of_char (s.[offset + offsets.(0)]))
and b = Int32.of_int (int_of_char (s.[offset + offsets.(1)]))
and c = Int32.of_int (int_of_char (s.[offset + offsets.(2)]))
and d = Int32.of_int (int_of_char (s.[offset + offsets.(3)])) in
- (a << 0) || (b << 8) || (c << 16) || (d << 24), (s, offset + 4)
+ (a <!< 0) |!| (b <!< 8) |!| (c <!< 16) |!| (d <!< 24), (s, offset + 4)
let unmarshal_uint64 ?(bigendian=false) (s, offset) =
let offsets = if bigendian then [|7;6;5;4;3;2;1;0|] else [|0;1;2;3;4;5;6;7|] in
- let (<<) a b = Int64.shift_left a b
- and (||) a b = Int64.logor a b in
+ let (<!<) a b = Int64.shift_left a b
+ and (|!|) a b = Int64.logor a b in
let a = Int64.of_int (int_of_char (s.[offset + offsets.(0)]))
and b = Int64.of_int (int_of_char (s.[offset + offsets.(1)]))
and c = Int64.of_int (int_of_char (s.[offset + offsets.(2)]))
and f = Int64.of_int (int_of_char (s.[offset + offsets.(5)]))
and g = Int64.of_int (int_of_char (s.[offset + offsets.(6)]))
and h = Int64.of_int (int_of_char (s.[offset + offsets.(7)])) in
- (a << 0) || (b << 8) || (c << 16) || (d << 24)
- || (e << 32) || (f << 40) || (g << 48) || h << (56), (s, offset + 8)
+ (a <!< 0) |!| (b <!< 8) |!| (c <!< 16) |!| (d <!< 24)
+ |!| (e <!< 32) |!| (f <!< 40) |!| (g <!< 48) |!| (h <!< 56), (s, offset + 8)
let unmarshal_string len (s,offset) =
String.sub s offset len, (s, offset + len)
let marshal_int16 (s,offset) ?(bigendian=false) x =
let offsets = if bigendian then [|1;0|] else [|0;1|] in
- let (>>) a b = a lsr b
+ let (>!>) a b = a lsr b
and (&&) a b = a land b in
- let a = (x >> 0) && 0xff
- and b = (x >> 8) && 0xff in
+ let a = (x >!> 0) && 0xff
+ and b = (x >!> 8) && 0xff in
s.[offset+offsets.(0)] <- char_of_int a;
s.[offset+offsets.(1)] <- char_of_int b;
(s,offset+2)
let marshal_int32 (s,offset) ?(bigendian=false) x =
let offsets = if bigendian then [|3;2;1;0|] else [|0;1;2;3|] in
- let (>>) a b = Int32.shift_right_logical a b
+ let (>!>) a b = Int32.shift_right_logical a b
and (&&) a b = Int32.logand a b in
- let a = (x >> 0) && 0xffl
- and b = (x >> 8) && 0xffl
- and c = (x >> 16) && 0xffl
- and d = (x >> 24) && 0xffl in
+ let a = (x >!> 0) && 0xffl
+ and b = (x >!> 8) && 0xffl
+ and c = (x >!> 16) && 0xffl
+ and d = (x >!> 24) && 0xffl in
s.[offset+offsets.(0)] <- char_of_int (Int32.to_int a);
s.[offset+offsets.(1)] <- char_of_int (Int32.to_int b);
s.[offset+offsets.(2)] <- char_of_int (Int32.to_int c);
let marshal_int64 (s,offset) ?(bigendian=false) x =
let offsets = if bigendian then [|7;6;5;4;3;2;1;0|] else [|0;1;2;3;4;5;6;7|] in
- let (>>) a b = Int64.shift_right_logical a b
+ let (>!>) a b = Int64.shift_right_logical a b
and (&&) a b = Int64.logand a b in
- let a = (x >> 0) && 0xffL
- and b = (x >> 8) && 0xffL
- and c = (x >> 16) && 0xffL
- and d = (x >> 24) && 0xffL
- and e = (x >> 32) && 0xffL
- and f = (x >> 40) && 0xffL
- and g = (x >> 48) && 0xffL
- and h = (x >> 56) && 0xffL in
+ let a = (x >!> 0) && 0xffL
+ and b = (x >!> 8) && 0xffL
+ and c = (x >!> 16) && 0xffL
+ and d = (x >!> 24) && 0xffL
+ and e = (x >!> 32) && 0xffL
+ and f = (x >!> 40) && 0xffL
+ and g = (x >!> 48) && 0xffL
+ and h = (x >!> 56) && 0xffL in
s.[offset+offsets.(0)] <- char_of_int (Int64.to_int a);
s.[offset+offsets.(1)] <- char_of_int (Int64.to_int b);
s.[offset+offsets.(2)] <- char_of_int (Int64.to_int c);
ty : string (* 8 bytes, equal to "LVM2 001" - Constants.label_type*)
}
- type disk_locn = {
+ and disk_locn = {
dl_offset : int64;
dl_size : int64;
}
- type pv_header = {
+ and pv_header = {
pvh_id : string; (* 32 bytes, 'uuid' *)
pvh_device_size : int64;
pvh_extents: disk_locn list;
pvh_metadata_areas: disk_locn list;
}
- type t = {
+ and t = {
device : string;
label_header : label_header;
pv_header : pv_header;
- }
+ } with rpc
let unmarshal_header b0 =
let id,b = unmarshal_string 8 b0 in
pvh_extents=disk_areas;
pvh_metadata_areas=disk_areas2},b
+ let pvh_to_ascii pvh =
+ let disk_area_list_to_ascii l =
+ (String.concat "," (List.map (fun da -> Printf.sprintf "{offset=%Ld,size=%Ld}" da.dl_offset da.dl_size) l)) in
+ Printf.sprintf "pvh_id: %s\npvh_device_size: %Ld\npvh_areas1: %s\npvh_areas2: %s\n"
+ pvh.pvh_id pvh.pvh_device_size
+ (disk_area_list_to_ascii pvh.pvh_extents)
+ (disk_area_list_to_ascii pvh.pvh_metadata_areas)
+
let write_label_and_pv_header l =
let label = l.label_header in
let pvh = l.pv_header in
let header = marshal_string header label.ty in
assert(snd header = 32);
-
+
+ Debug.debug (Printf.sprintf "write_label_and_pv_header:\nPV header:\n%s" (pvh_to_ascii pvh));
+
(* PV header *)
let header = marshal_string header (Lvm_uuid.remove_hyphens pvh.pvh_id) in
let header = marshal_int64 header pvh.pvh_device_size in
Unix.close fd
- let pvh_to_ascii pvh =
- let disk_area_list_to_ascii l =
- (String.concat "," (List.map (fun da -> Printf.sprintf "{offset=%Ld,size=%Ld}" da.dl_offset da.dl_size) l)) in
- Printf.sprintf "pvh_id: %s\npvh_device_size: %Ld\npvh_areas1: %s\npvh_areas2: %s\n"
- pvh.pvh_id pvh.pvh_device_size
- (disk_area_list_to_ascii pvh.pvh_extents)
- (disk_area_list_to_ascii pvh.pvh_metadata_areas)
-
let get_metadata_locations label =
label.pv_header.pvh_metadata_areas
end
module MDAHeader = struct
+ let mda_header_size = Constants.sector_size
+
type mda_raw_locn = {
mrl_offset: int64;
mrl_size: int64;
mrl_filler: int32;
}
- let mda_header_size = Constants.sector_size
-
- type mda_header = {
+ and mda_header = {
mdah_checksum : int32;
mdah_magic : string;
mdah_version : int32;
mdah_start: int64;
mdah_size: int64;
mdah_raw_locns : mda_raw_locn list;
- }
+ } with rpc
let unmarshal_mda_header device location =
let offset,fd =
type status =
| Allocatable
-type physical_volume = {
+and physical_volume = {
name : string;
id : string;
dev : string;
pe_count : int64;
label : Label.t; (* The one label for this PV *)
mda_headers : MDAHeader.mda_header list;
-}
+} with rpc
let status_to_string s =
match s with
(** Find the metadata area on a device and return the text of the metadata *)
let find_metadata device =
let label = Label.find device in
- (* Printf.printf "Label found: \n%s\nPV header found:\n%s\n"
- (Pv.Label.label_to_ascii label) (Pv.Label.pvh_to_ascii pvh); *)
+ Debug.debug (Printf.sprintf "Label found: \n%s\n"
+ (Label.to_ascii label));
let mda_locs = Label.get_metadata_locations label in
let mdahs = List.map (MDAHeader.unmarshal_mda_header device) mda_locs in
let mdt = MDAHeader.read_md device (List.hd mdahs) 0 in