Removed bitmap object - don't need to build a bitmap.
[virt-df.git] / diskzip / diskzip.ml
index b4a0a5a..8acabc4 100644 (file)
@@ -20,6 +20,7 @@
 open Unix
 open Printf
 
+open Int63.Operators
 open Diskzip_gettext.Gettext
 
 type output = File of string | Dir of string
@@ -29,16 +30,19 @@ let rec main () =
   (* Program name changes behaviour. *)
   let compressing =
     let name = Sys.argv.(0) in
-    let name = Filename.basename name in       (* just the executable name *)
-    let name = Filename.chop_extension name in (* remove .opt or .exe *)
+    let name = Filename.basename name in (* just the executable name *)
+    let name =                          (* remove .opt or .exe *)
+      try Filename.chop_extension name
+      with Invalid_argument("Filename.chop_extension") -> name in
     let name = String.lowercase name in
     match name with
     | "diskzcat" -> false
     | "diskzip" -> true
-    | name ->
+    | _ ->
        eprintf
          (f_"diskzip: unknown executable name '%s', assuming 'diskzip'\n")
-         name in
+         name;
+       true in
   let compressing = ref compressing in
 
   (* Command line argument parsing. *)
@@ -145,6 +149,9 @@ and go_compress extcompress images =
   (* Scan the images for filesystems. *)
   let machine = Diskimage.scan_machine machine in
 
+  (* Create ownership tables. *)
+  let ownership = Diskimage.create_ownership machine in
+
   (* Redirect output through external pipe if asked. *)
   (match extcompress with
    | None -> ()
@@ -166,7 +173,25 @@ and go_compress extcompress images =
         dup2 wfd stdout;
         close wfd
        )
-  )
+  );
+
+  (* Iterate over the disks. *)
+  List.iter (
+    fun { Diskimage.d_name = name; d_dev = disk } ->
+      let blocksize = disk#blocksize in
+      let size = disk#size in          (* Size in bytes. *)
+      let nr_blocks = size /^ blocksize in (* Number of disk sectors. *)
+
+      (* Get the lookup function for this disk. *)
+      let lookup = Diskimage.get_owners_lookup machine ownership disk in
+
+      (* Lookup each sector. *)
+      for blk = 0 to nr_blocks-1 do
+       ignore (lookup blk)
+      done
+  ) machine.Diskimage.m_disks;
+
+