Convert everything to use int63 type throughout.
[virt-df.git] / virt-df / virt_df_main.ml
index cd51c88..4572099 100644 (file)
@@ -23,19 +23,11 @@ open ExtList
 module C = Libvirt.Connect
 module D = Libvirt.Domain
 
+open Int63.Operators
+
 open Virt_df_gettext.Gettext
 open Virt_df
 
-let ( +* ) = Int32.add
-let ( -* ) = Int32.sub
-let ( ** ) = Int32.mul
-let ( /* ) = Int32.div
-
-let ( +^ ) = Int64.add
-let ( -^ ) = Int64.sub
-let ( *^ ) = Int64.mul
-let ( /^ ) = Int64.div
-
 let () =
   (* Command line argument parsing. *)
   let set_uri = function "" -> uri := None | u -> uri := Some u in
@@ -275,12 +267,12 @@ OPTIONS" in
       csv_write [ "Filesystem"; total; used; avail; "Type" ] in
 
   let printable_size bytes =
-    if bytes < 1024L *^ 1024L then
-      sprintf "%Ld bytes" bytes
-    else if bytes < 1024L *^ 1024L *^ 1024L then
-      sprintf "%.1f MiB" (Int64.to_float (bytes /^ 1024L) /. 1024.)
+    if bytes < ~^1024 *^ ~^1024 then
+      sprintf "%s bytes" (Int63.to_string bytes)
+    else if bytes < ~^1024 *^ ~^1024 *^ ~^1024 then
+      sprintf "%.1f MiB" (Int63.to_float (bytes /^ ~^1024) /. 1024.)
     else
-      sprintf "%.1f GiB" (Int64.to_float (bytes /^ 1024L /^ 1024L) /. 1024.)
+      sprintf "%.1f GiB" (Int63.to_float (bytes /^ ~^1024 /^ ~^1024) /. 1024.)
   in
 
   (* HOF to iterate over filesystems. *)
@@ -295,7 +287,7 @@ OPTIONS" in
        List.iter (
          function
          | ({ Diskimage.d_content = `Filesystem fs; d_dev = dev } as disk) ->
-             f dom ~disk dev fs
+             f dom ~disk (dev :> Diskimage.device) fs
          | ({ Diskimage.d_content = `Partitions partitions } as disk) ->
              List.iteri (
                fun i ->
@@ -338,8 +330,8 @@ OPTIONS" in
     printf "%-32s " name;
 
     let {
-      Diskimage.fs_name = fs_name;
-      fs_block_size = fs_block_size;
+      Diskimage.fs_plugin_id = fs_plugin_id;
+      fs_blocksize = fs_blocksize;
       fs_blocks_total = fs_blocks_total;
       fs_is_swap = fs_is_swap;
       fs_blocks_reserved = fs_blocks_reserved;
@@ -351,38 +343,44 @@ OPTIONS" in
       fs_inodes_used = fs_inodes_used
     } = fs in
 
+    let fs_name = Diskimage.name_of_filesystem fs_plugin_id in
+
     if fs_is_swap then (
       (* Swap partition. *)
       if not !human then
-       printf "%10Ld                       %s\n"
-         (fs_block_size *^ fs_blocks_total /^ 1024L) fs_name
+       printf "%10s                       %s\n"
+         (Int63.to_string (fs_blocksize *^ fs_blocks_total /^ ~^1024))
+         fs_name
       else
        printf "%10s                       %s\n"
-         (printable_size (fs_block_size *^ fs_blocks_total)) fs_name
+         (printable_size (fs_blocksize *^ fs_blocks_total))
+         fs_name
     ) else (
       (* Ordinary filesystem. *)
       if not !inodes then (            (* Block display. *)
        (* 'df' doesn't count the restricted blocks. *)
        let blocks_total = fs_blocks_total -^ fs_blocks_reserved in
        let blocks_avail = fs_blocks_avail -^ fs_blocks_reserved in
-       let blocks_avail = if blocks_avail < 0L then 0L else blocks_avail in
+       let blocks_avail = if blocks_avail < ~^0 then ~^0 else blocks_avail in
 
        if not !human then (            (* Display 1K blocks. *)
-         printf "%10Ld %10Ld %10Ld %s\n"
-           (blocks_total *^ fs_block_size /^ 1024L)
-           (fs_blocks_used *^ fs_block_size /^ 1024L)
-           (blocks_avail *^ fs_block_size /^ 1024L)
+         printf "%10s %10s %10s %s\n"
+           (Int63.to_string (blocks_total *^ fs_blocksize /^ ~^1024))
+           (Int63.to_string (fs_blocks_used *^ fs_blocksize /^ ~^1024))
+           (Int63.to_string (blocks_avail *^ fs_blocksize /^ ~^1024))
            fs_name
        ) else (                        (* Human-readable blocks. *)
          printf "%10s %10s %10s %s\n"
-           (printable_size (blocks_total *^ fs_block_size))
-           (printable_size (fs_blocks_used *^ fs_block_size))
-           (printable_size (blocks_avail *^ fs_block_size))
+           (printable_size (blocks_total *^ fs_blocksize))
+           (printable_size (fs_blocks_used *^ fs_blocksize))
+           (printable_size (blocks_avail *^ fs_blocksize))
            fs_name
        )
       ) else (                         (* Inodes display. *)
-       printf "%10Ld %10Ld %10Ld %s\n"
-         fs_inodes_total fs_inodes_used fs_inodes_avail
+       printf "%10s %10s %10s %s\n"
+         (Int63.to_string fs_inodes_total)
+         (Int63.to_string fs_inodes_used)
+         (Int63.to_string fs_inodes_avail)
          fs_name
       )
     )
@@ -396,8 +394,8 @@ OPTIONS" in
     let name = printable_name machine ?disk ?partno dev in
 
     let {
-      Diskimage.fs_name = fs_name;
-      fs_block_size = fs_block_size;
+      Diskimage.fs_plugin_id = fs_plugin_id;
+      fs_blocksize = fs_blocksize;
       fs_blocks_total = fs_blocks_total;
       fs_is_swap = fs_is_swap;
       fs_blocks_reserved = fs_blocks_reserved;
@@ -409,26 +407,28 @@ OPTIONS" in
       fs_inodes_used = fs_inodes_used
     } = fs in
 
+    let fs_name = Diskimage.name_of_filesystem fs_plugin_id in
+
     let row =
       if fs_is_swap then
        (* Swap partition. *)
-       [ Int64.to_string (fs_block_size *^ fs_blocks_total /^ 1024L);
+       [ Int63.to_string (fs_blocksize *^ fs_blocks_total /^ ~^1024);
          ""; "" ]
       else (
        (* Ordinary filesystem. *)
-       if not !inodes then (           (* Block display. *)
+       if not !inodes then (           (* 1K block display. *)
          (* 'df' doesn't count the restricted blocks. *)
          let blocks_total = fs_blocks_total -^ fs_blocks_reserved in
          let blocks_avail = fs_blocks_avail -^ fs_blocks_reserved in
-         let blocks_avail = if blocks_avail < 0L then 0L else blocks_avail in
+         let blocks_avail = if blocks_avail < ~^0 then ~^0 else blocks_avail in
 
-         [ Int64.to_string (blocks_total *^ fs_block_size /^ 1024L);
-           Int64.to_string (fs_blocks_used *^ fs_block_size /^ 1024L);
-           Int64.to_string (blocks_avail *^ fs_block_size /^ 1024L) ]
+         [ Int63.to_string (blocks_total *^ fs_blocksize /^ ~^1024);
+           Int63.to_string (fs_blocks_used *^ fs_blocksize /^ ~^1024);
+           Int63.to_string (blocks_avail *^ fs_blocksize /^ ~^1024) ]
        ) else (                        (* Inodes display. *)
-         [ Int64.to_string fs_inodes_total;
-           Int64.to_string fs_inodes_used;
-           Int64.to_string fs_inodes_avail ]
+         [ Int63.to_string fs_inodes_total;
+           Int63.to_string fs_inodes_used;
+           Int63.to_string fs_inodes_avail ]
        )
       ) in