diff options
author | Alexander Motin <mav@FreeBSD.org> | 2011-07-21 19:39:40 +0000 |
---|---|---|
committer | Alexander Motin <mav@FreeBSD.org> | 2011-07-21 19:39:40 +0000 |
commit | 23454425b752913f512fd6af02103a4beb62aa7a (patch) | |
tree | b737a7fda4d361765c857a6df5a240fa2c5261c3 /usr.sbin | |
parent | c03b5ad6a9202f3fbb8cc741af72bb49b4b6c599 (diff) | |
download | src-23454425b752913f512fd6af02103a4beb62aa7a.tar.gz src-23454425b752913f512fd6af02103a4beb62aa7a.zip |
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)
Notes
Notes:
svn path=/head/; revision=224250
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/diskinfo/diskinfo.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/usr.sbin/diskinfo/diskinfo.c b/usr.sbin/diskinfo/diskinfo.c index 168a9098262b..554b09e9c2d1 100644 --- a/usr.sbin/diskinfo/diskinfo.c +++ b/usr.sbin/diskinfo/diskinfo.c @@ -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; |