Sanity check media size and sector counts to ensure that we don't

produce negative sector numbers in the testing algorithm.

CID: 1198994
This commit is contained in:
Warner Losh 2018-01-06 12:34:03 +00:00
parent 917fa2a3e9
commit 1723a6e523
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=327617

View file

@ -407,9 +407,14 @@ speeddisk(int fd, off_t mediasize, u_int sectorsize)
int bulk, i;
off_t b0, b1, sectorcount, step;
/*
* Drives smaller than 1MB produce negative sector numbers,
* as do 2048 or fewer sectors.
*/
sectorcount = mediasize / sectorsize;
if (sectorcount <= 0)
return; /* Can't test devices with no sectors */
if (mediasize < 1024 * 1024 || sectorcount < 2048)
return;
step = 1ULL << (flsll(sectorcount / (4 * 200)) - 1);
if (step > 16384)