+
+ (* Alternate version of print_stats which writes to a CSV file.
+ * We ignore the human-readable option because we assume that
+ * the data will be post-processed by something.
+ *)
+ let print_stats_csv dom ?disk ?partno dev fs =
+ let name = printable_name dom ?disk ?partno dev in
+
+ let row =
+ if fs.fs_is_swap then
+ (* Swap partition. *)
+ [ Int64.to_string (fs.fs_block_size *^ fs.fs_blocks_total /^ 1024L);
+ ""; "" ]
+ else (
+ (* Ordinary filesystem. *)
+ if not !inodes then ( (* Block display. *)
+ (* 'df' doesn't count the restricted blocks. *)
+ let blocks_total = fs.fs_blocks_total -^ fs.fs_blocks_reserved in
+ let blocks_avail = fs.fs_blocks_avail -^ fs.fs_blocks_reserved in
+ let blocks_avail = if blocks_avail < 0L then 0L else blocks_avail in
+
+ [ Int64.to_string (blocks_total *^ fs.fs_block_size /^ 1024L);
+ Int64.to_string (fs.fs_blocks_used *^ fs.fs_block_size /^ 1024L);
+ Int64.to_string (blocks_avail *^ fs.fs_block_size /^ 1024L) ]
+ ) else ( (* Inodes display. *)
+ [ Int64.to_string fs.fs_inodes_total;
+ Int64.to_string fs.fs_inodes_used;
+ Int64.to_string fs.fs_inodes_avail ]
+ )
+ ) in
+
+ let row = name :: row @ [fs.fs_name] in
+ csv_write row
+ in
+
+ iter_over_filesystems doms
+ (if not !csv_mode then print_stats else print_stats_csv)