svn commit: r224492 - stable/7/usr.sbin/diskinfo
Alexander Motin
mav at FreeBSD.org
Fri Jul 29 10:51:57 UTC 2011
Author: mav
Date: Fri Jul 29 10:51:56 2011
New Revision: 224492
URL: http://svn.freebsd.org/changeset/base/224492
Log:
MFC r224250:
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.
Modified:
stable/7/usr.sbin/diskinfo/diskinfo.c
Directory Properties:
stable/7/usr.sbin/diskinfo/ (props changed)
Modified: stable/7/usr.sbin/diskinfo/diskinfo.c
==============================================================================
--- stable/7/usr.sbin/diskinfo/diskinfo.c Fri Jul 29 10:02:03 2011 (r224491)
+++ stable/7/usr.sbin/diskinfo/diskinfo.c Fri Jul 29 10:51:56 2011 (r224492)
@@ -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>
@@ -161,7 +162,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;
@@ -222,21 +223,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);
@@ -246,9 +253,9 @@ speeddisk(int fd, off_t mediasize, u_int
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");
@@ -257,9 +264,9 @@ speeddisk(int fd, off_t mediasize, u_int
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);
@@ -268,7 +275,7 @@ speeddisk(int fd, off_t mediasize, u_int
T0();
for (i = 0; i < 400; i++) {
rdsect(fd, b0, sectorsize);
- b0 += 16384;
+ b0 += step;
}
TN(400);
@@ -277,7 +284,7 @@ speeddisk(int fd, off_t mediasize, u_int
T0();
for (i = 0; i < 400; i++) {
rdsect(fd, b0, sectorsize);
- b0 -= 16384;
+ b0 -= step;
}
TN(400);
@@ -291,7 +298,7 @@ speeddisk(int fd, off_t mediasize, u_int
TN(2048);
printf("\tSeq inner:\t");
- b0 = sectorcount - 2048 - 1;
+ b0 = sectorcount - 2048;
T0();
for (i = 0; i < 2048; i++) {
rdsect(fd, b0, sectorsize);
@@ -303,28 +310,28 @@ speeddisk(int fd, off_t mediasize, u_int
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;
More information about the svn-src-stable
mailing list