Do more guarding against zero divide traps for the geom subroutine.

This commit is contained in:
Matt Jacob 2006-04-18 21:53:39 +00:00
parent 2901a7b7d4
commit bae3cbf075
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=157854

View File

@ -373,7 +373,16 @@ cam_calc_geometry(struct ccb_calc_geometry *ccg, int extended)
{
uint32_t size_mb, secs_per_cylinder;
size_mb = ccg->volume_size / ((1024L * 1024L) / ccg->block_size);
if (ccg->block_size == 0) {
ccg->ccb_h.status = CAM_REQ_CMP_ERR;
return;
}
size_mb = (1024L * 1024L) / ccg->block_size;
if (size_mb == 0) {
ccg->ccb_h.status = CAM_REQ_CMP_ERR;
return;
}
size_mb = ccg->volume_size / size_mb;
if (size_mb > 1024 && extended) {
ccg->heads = 255;
ccg->secs_per_track = 63;
@ -382,6 +391,10 @@ cam_calc_geometry(struct ccb_calc_geometry *ccg, int extended)
ccg->secs_per_track = 32;
}
secs_per_cylinder = ccg->heads * ccg->secs_per_track;
if (secs_per_cylinder == 0) {
ccg->ccb_h.status = CAM_REQ_CMP_ERR;
return;
}
ccg->cylinders = ccg->volume_size / secs_per_cylinder;
ccg->ccb_h.status = CAM_REQ_CMP;
}