X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=diskzip%2Fdiskzip.ml;h=75fffc60f7de64344b4408d2671f7040e670ba74;hb=10ae94c252bfc3e744407115274fd3d92957d026;hp=b4a0a5ab2f41673bcd3a7d638b6b3f7c5aa3aaf7;hpb=bfbfdf2b0e5139de2f770346a08e0e844c219830;p=virt-df.git diff --git a/diskzip/diskzip.ml b/diskzip/diskzip.ml index b4a0a5a..75fffc6 100644 --- a/diskzip/diskzip.ml +++ b/diskzip/diskzip.ml @@ -20,7 +20,9 @@ open Unix open Printf +open Int63.Operators open Diskzip_gettext.Gettext +module Bitmap = Diskzip_bitmap type output = File of string | Dir of string type extcompress = BZip2 | GZip | External of string @@ -29,16 +31,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 +150,34 @@ 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 + + (* Create ownership bitmap for each disk. *) + 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. *) + + if !Diskimage.debug then + eprintf "Creating bitmap for %s (%s sectors) ...\n%!" + disk#name (Int63.to_string nr_blocks); + + (* Create an empty bitmap, one bit per sector. *) + let bitmap = Bitmap.create nr_blocks in + + (* Get the lookup function for this disk. *) + let lookup = Diskimage.get_owners_lookup machine ownership disk in + + (* Lookup each sector. *) + Bitmap.iter_set ( + fun blk _ -> + let owners = lookup blk in + false + ) bitmap + ) machine.Diskimage.m_disks; + (* Redirect output through external pipe if asked. *) (match extcompress with | None -> ()