When using libdisk functions with files, not real or partfs(8) disks, chs fields in the Disk structure are not filled. Later on, partitiongeometry() will try to calculate the cylinders with disk->c = disk->secs / (disk->h*disk->s) which may result in a division by zero. This patch just checks for empty chs. .