From owner-svn-src-user@FreeBSD.ORG Sun Aug 15 14:11:59 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4B5C0106566B; Sun, 15 Aug 2010 14:11:59 +0000 (UTC) (envelope-from des@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 3B0188FC1C; Sun, 15 Aug 2010 14:11:59 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o7FEBxGU062498; Sun, 15 Aug 2010 14:11:59 GMT (envelope-from des@svn.freebsd.org) Received: (from des@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o7FEBxBW062496; Sun, 15 Aug 2010 14:11:59 GMT (envelope-from des@svn.freebsd.org) Message-Id: <201008151411.o7FEBxBW062496@svn.freebsd.org> From: Dag-Erling Smorgrav Date: Sun, 15 Aug 2010 14:11:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r211334 - user/des/phybs X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Aug 2010 14:11:59 -0000 Author: des Date: Sun Aug 15 14:11:58 2010 New Revision: 211334 URL: http://svn.freebsd.org/changeset/base/211334 Log: Instead of a hardcoding the block size, ask the device; default to 512 bytes for regular files. Adjust all other default values accordingly. Modified: user/des/phybs/phybs.c Modified: user/des/phybs/phybs.c ============================================================================== --- user/des/phybs/phybs.c Sun Aug 15 13:25:18 2010 (r211333) +++ user/des/phybs/phybs.c Sun Aug 15 14:11:58 2010 (r211334) @@ -27,7 +27,10 @@ * $FreeBSD$ */ +#include +#include #include +#include #include #include @@ -38,14 +41,15 @@ #include #include -#define BSIZE 512 +static const char *device; -static unsigned int minsize = 1024; -static unsigned int maxsize = 8192; -static unsigned int total = (128 * 1024 * 1024); +static unsigned int bsize; +static unsigned int minsize; +static unsigned int maxsize; +static unsigned int total; -static int opt_r = 0; -static int opt_w = 1; +static int opt_r; +static int opt_w; static int tty = 0; static char progress[] = " [----------------]" @@ -112,7 +116,7 @@ usage(void) } static unsigned int -poweroftwo(char opt, const char *valstr, unsigned int min, unsigned int max) +poweroftwo(char opt, const char *valstr) { uint64_t val; @@ -124,7 +128,7 @@ poweroftwo(char opt, const char *valstr, fprintf(stderr, "-%c: not a power of two\n", opt); usage(); } - if (val < min || (max != 0 && val > max) || val > UINT_MAX) { + if (val == 0 || val > UINT_MAX) { fprintf(stderr, "-%c: out of range\n", opt); usage(); } @@ -134,22 +138,25 @@ poweroftwo(char opt, const char *valstr, int main(int argc, char *argv[]) { - char *device; + struct stat st; int fd, opt; tty = isatty(STDOUT_FILENO); - while ((opt = getopt(argc, argv, "h:l:rw")) != -1) + while ((opt = getopt(argc, argv, "h:l:rt:w")) != -1) switch (opt) { case 'h': - maxsize = poweroftwo(opt, optarg, minsize, 0); + maxsize = poweroftwo(opt, optarg); break; case 'l': - minsize = poweroftwo(opt, optarg, BSIZE, maxsize); + minsize = poweroftwo(opt, optarg); break; case 'r': opt_r = 1; break; + case 't': + total = poweroftwo(opt, optarg); + break; case 'w': opt_w = 1; break; @@ -160,24 +167,51 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if (!opt_r && !opt_w) - opt_r = opt_w = 1; - if (argc != 1) usage(); device = argv[0]; + if (!opt_r && !opt_w) + errx(1, "must specify -r and / or -w"); + if ((fd = open(device, opt_w ? O_RDWR : O_RDONLY)) == -1) err(1, "open(%s)", device); + + if (fstat(fd, &st) != 0) + err(1, "stat(%s)", device); + bsize = 512; + if (S_ISCHR(st.st_mode) && ioctl(fd, DIOCGSECTORSIZE, &bsize) == -1) + err(1, "ioctl(%s, DIOCGSECTORSIZE)", device); + + if (minsize == 0) + minsize = bsize * 2; + if (minsize % bsize != 0) + errx(1, "minsize (%u) is not a multiple of block size (%u)", + minsize, bsize); + + if (maxsize == 0) + maxsize = minsize * 8; + if (maxsize % minsize != 0) + errx(1, "maxsize (%u) is not a multiple of minsize (%u)", + maxsize, minsize); + + if (total == 0) + total = 128 * 1024 * 1024; + if (total % maxsize != 0) + errx(1, "total (%u) is not a multiple of maxsize (%u)", + total, maxsize); + printf("%8s%8s%8s%8s%12s%8s%8s\n", "count", "size", "offset", "step", "msec", "tps", "kBps"); + for (size_t size = minsize; size <= maxsize; size *= 2) { printf("\n"); scan(fd, size, 0, size * 4, total / size); - for (off_t offset = BSIZE; offset < (off_t)size; offset *= 2) + for (off_t offset = bsize; offset < (off_t)size; offset *= 2) scan(fd, size, offset, size * 4, total / size); } + close(fd); exit(0); }