X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=lib%2Fdiskimage_linux_swap.ml;h=22b8d5eaf7adc87503784fda91ad2ca66338f1f3;hb=5318d6037135dbb8f53074d8003af769132d72bd;hp=b8c49e61e4a243fb2d41d4c5a64433e64c863646;hpb=091ddc2dd90ad9985aca308657d8120781defc11;p=virt-df.git diff --git a/lib/diskimage_linux_swap.ml b/lib/diskimage_linux_swap.ml index b8c49e6..22b8d5e 100644 --- a/lib/diskimage_linux_swap.ml +++ b/lib/diskimage_linux_swap.ml @@ -20,27 +20,26 @@ Support for Linux swap partitions. *) -open Diskimage_utils +open Diskimage_impl open Int63.Operators -let plugin_id = "linux_swap" +let id = "linux_swap" let blocksize = ~^4096 (* XXX *) -let probe dev = +let rec probe dev = (* Load the "superblock" (ie. first 0x1000 bytes). *) let bits = dev#read_bitstring ~^0 ~^0x1000 in bitmatch bits with | { - (* Actually this isn't just padding. *) - padding : 8*0x1000 - 10*8 : bitstring; + _ : 8*0x1000 - 10*8 : bitstring; ("SWAP-SPACE"|"SWAPSPACE2") : 80 : string } -> let fs_dev = new blocksize_overlay blocksize dev in { - fs_plugin_id = plugin_id; + fs_cb = callbacks (); fs_dev = fs_dev; fs_blocksize = blocksize; @@ -59,3 +58,20 @@ let probe dev = | { _ } -> raise Not_found (* Not Linux swapspace. *) + +(* Linux swap space is always 'free', apart from the superblock. + * Compare diskimage_linux_swsuspend.ml + *) +and offset_is_free _ offset = offset >= blocksize + +and callbacks = + let i = ref 0 in + fun () -> { + fs_cb_uq = (incr i; !i); + fs_cb_name = id; + fs_cb_printable_name = "Linux swap"; + fs_cb_offset_is_free = offset_is_free; + } + +(* Register the plugin. *) +let () = register_plugin ~filesystem:probe id