btrfs-progs: fix floating point exception for btrfs-calc-size

Current code exit with floating point exception on a blank fs:
 # btrfs-calc-size -b /dev/sda6
 Calculating size of root tree
         Total size: 16384
                 Inline data: 0
         Total seeks: 0
                 Forward seeks: 0
                 Backward seeks: 0
 Floating point exception

This patch add a condition check for above case.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Zhao Lei 2015-10-29 17:31:43 +08:00 committed by David Sterba
parent 835821f36a
commit 0b69dfa410

View File

@ -372,8 +372,8 @@ out_print:
printf("\tTotal seeks: %Lu\n", stat.total_seeks);
printf("\t\tForward seeks: %Lu\n", stat.forward_seeks);
printf("\t\tBackward seeks: %Lu\n", stat.backward_seeks);
printf("\t\tAvg seek len: %Lu\n", stat.total_seek_len /
stat.total_seeks);
printf("\t\tAvg seek len: %llu\n", stat.total_seeks ?
stat.total_seek_len / stat.total_seeks : 0);
print_seek_histogram(&stat);
printf("\tTotal clusters: %Lu\n", stat.total_clusters);
printf("\t\tAvg cluster size: %Lu\n", stat.total_cluster_size /