mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-13 14:40:22 +00:00
Fix diskinfo -t
operation for disks smaller then 8GB or bigger then 2TB.
Tested to work with 1.44MB floppy, 4GB USB stick and 4TB disk array. Approved by: re (kib)
This commit is contained in:
parent
c03b5ad6a9
commit
23454425b7
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=224250
@ -32,6 +32,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
@ -171,7 +172,7 @@ static char sector[65536];
|
||||
static char mega[1024 * 1024];
|
||||
|
||||
static void
|
||||
rdsect(int fd, u_int blockno, u_int sectorsize)
|
||||
rdsect(int fd, off_t blockno, u_int sectorsize)
|
||||
{
|
||||
int error;
|
||||
|
||||
@ -232,21 +233,27 @@ TR(double count)
|
||||
static void
|
||||
speeddisk(int fd, off_t mediasize, u_int sectorsize)
|
||||
{
|
||||
int i;
|
||||
uint b0, b1, sectorcount;
|
||||
int bulk, i;
|
||||
off_t b0, b1, sectorcount, step;
|
||||
|
||||
sectorcount = mediasize / sectorsize;
|
||||
step = 1ULL << (flsll(sectorcount / (4 * 200)) - 1);
|
||||
if (step > 16384)
|
||||
step = 16384;
|
||||
bulk = mediasize / (1024 * 1024);
|
||||
if (bulk > 100)
|
||||
bulk = 100;
|
||||
|
||||
printf("Seek times:\n");
|
||||
printf("\tFull stroke:\t");
|
||||
b0 = 0;
|
||||
b1 = sectorcount - 1 - 16384;
|
||||
b1 = sectorcount - step;
|
||||
T0();
|
||||
for (i = 0; i < 125; i++) {
|
||||
rdsect(fd, b0, sectorsize);
|
||||
b0 += 16384;
|
||||
b0 += step;
|
||||
rdsect(fd, b1, sectorsize);
|
||||
b1 -= 16384;
|
||||
b1 -= step;
|
||||
}
|
||||
TN(250);
|
||||
|
||||
@ -256,9 +263,9 @@ speeddisk(int fd, off_t mediasize, u_int sectorsize)
|
||||
T0();
|
||||
for (i = 0; i < 125; i++) {
|
||||
rdsect(fd, b0, sectorsize);
|
||||
b0 += 16384;
|
||||
b0 += step;
|
||||
rdsect(fd, b1, sectorsize);
|
||||
b1 += 16384;
|
||||
b1 += step;
|
||||
}
|
||||
TN(250);
|
||||
printf("\tQuarter stroke:\t");
|
||||
@ -267,9 +274,9 @@ speeddisk(int fd, off_t mediasize, u_int sectorsize)
|
||||
T0();
|
||||
for (i = 0; i < 250; i++) {
|
||||
rdsect(fd, b0, sectorsize);
|
||||
b0 += 16384;
|
||||
b0 += step;
|
||||
rdsect(fd, b1, sectorsize);
|
||||
b1 += 16384;
|
||||
b1 += step;
|
||||
}
|
||||
TN(500);
|
||||
|
||||
@ -278,7 +285,7 @@ speeddisk(int fd, off_t mediasize, u_int sectorsize)
|
||||
T0();
|
||||
for (i = 0; i < 400; i++) {
|
||||
rdsect(fd, b0, sectorsize);
|
||||
b0 += 16384;
|
||||
b0 += step;
|
||||
}
|
||||
TN(400);
|
||||
|
||||
@ -287,7 +294,7 @@ speeddisk(int fd, off_t mediasize, u_int sectorsize)
|
||||
T0();
|
||||
for (i = 0; i < 400; i++) {
|
||||
rdsect(fd, b0, sectorsize);
|
||||
b0 -= 16384;
|
||||
b0 -= step;
|
||||
}
|
||||
TN(400);
|
||||
|
||||
@ -301,7 +308,7 @@ speeddisk(int fd, off_t mediasize, u_int sectorsize)
|
||||
TN(2048);
|
||||
|
||||
printf("\tSeq inner:\t");
|
||||
b0 = sectorcount - 2048 - 1;
|
||||
b0 = sectorcount - 2048;
|
||||
T0();
|
||||
for (i = 0; i < 2048; i++) {
|
||||
rdsect(fd, b0, sectorsize);
|
||||
@ -313,28 +320,28 @@ speeddisk(int fd, off_t mediasize, u_int sectorsize)
|
||||
printf("\toutside: ");
|
||||
rdsect(fd, 0, sectorsize);
|
||||
T0();
|
||||
for (i = 0; i < 100; i++) {
|
||||
for (i = 0; i < bulk; i++) {
|
||||
rdmega(fd);
|
||||
}
|
||||
TR(100 * 1024);
|
||||
TR(bulk * 1024);
|
||||
|
||||
printf("\tmiddle: ");
|
||||
b0 = sectorcount / 2;
|
||||
b0 = sectorcount / 2 - bulk * (1024*1024 / sectorsize) / 2 - 1;
|
||||
rdsect(fd, b0, sectorsize);
|
||||
T0();
|
||||
for (i = 0; i < 100; i++) {
|
||||
for (i = 0; i < bulk; i++) {
|
||||
rdmega(fd);
|
||||
}
|
||||
TR(100 * 1024);
|
||||
TR(bulk * 1024);
|
||||
|
||||
printf("\tinside: ");
|
||||
b0 = sectorcount - 100 * (1024*1024 / sectorsize) - 1;;
|
||||
b0 = sectorcount - bulk * (1024*1024 / sectorsize) - 1;;
|
||||
rdsect(fd, b0, sectorsize);
|
||||
T0();
|
||||
for (i = 0; i < 100; i++) {
|
||||
for (i = 0; i < bulk; i++) {
|
||||
rdmega(fd);
|
||||
}
|
||||
TR(100 * 1024);
|
||||
TR(bulk * 1024);
|
||||
|
||||
printf("\n");
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user