Updated MANIFEST
[virt-df.git] / lib / diskimage_linux_swsuspend.ml
index c1eeac8..171661c 100644 (file)
@@ -3,44 +3,44 @@
    (C) Copyright 2007 Richard W.M. Jones, Red Hat Inc.
    http://libvirt.org/
 
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version,
+   with the OCaml linking exception described in ../COPYING.LIB.
 
-   This program is distributed in the hope that it will be useful,
+   This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 
    Support for Linux software suspend partitions.
 *)
 
-open Diskimage_utils
+open Diskimage_impl
 
 open Int63.Operators
 
-let plugin_id = "linux_swsuspend"
+let id = "linux_swsuspend"
 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;
       ("S1SUSPEND"|"S2SUSPEND") : 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;
@@ -63,9 +63,16 @@ let probe dev =
 (* Linux software suspend image is never free.
  * Compare diskimage_linux_swap.ml
  *)
-let offset_is_free _ _ = false
-
-let callbacks = {
-  fs_cb_probe = probe;
-  fs_cb_offset_is_free = offset_is_free;
-}
+and offset_is_free _ _ = false
+
+and callbacks =
+  let i = ref 0 in
+  fun () -> {
+    fs_cb_uq = (incr i; !i);
+    fs_cb_name = id;
+    fs_cb_printable_name = "Linux s/w suspend";
+    fs_cb_offset_is_free = offset_is_free;
+  }
+
+(* Register the plugin. *)
+let () = register_plugin ~filesystem:probe id