⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dt.c

📁 Linux磁盘测试的源代码,测试磁盘的读写性能
💻 C
📖 第 1 页 / 共 5 页
字号:
/**************************************************************************** *									    * *			  COPYRIGHT (c) 1990 - 2004			    * *			   This Software Provided			    * *				     By					    * *			  Robin's Nest Software Inc.			    * *									    * * Permission to use, copy, modify, distribute and sell this software and   * * its documentation for any purpose and without fee is hereby granted,	    * * provided that the above copyright notice appear in all copies and that   * * both that copyright notice and this permission notice appear in the	    * * supporting documentation, and that the name of the author not be used    * * in advertising or publicity pertaining to distribution of the software   * * without specific, written prior permission.				    * *									    * * THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 	    * * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN	    * * NO EVENT SHALL HE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL   * * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR    * * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS  * * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF   * * THIS SOFTWARE.							    * *									    * ****************************************************************************//* * Module:	dt.c * Author:	Robin T. Miller * * Description: *	Main line code for generic data test program 'dt'. */#include "dt.h"#include <ctype.h>#include <fcntl.h>#include <math.h>#include <signal.h>#if !defined(_QNX_SOURCE)#  if !defined(sun)#    include <sys/ioctl.h>#  endif /* !defined(sun) */#  include <sys/file.h>#  include <sys/param.h>#  if defined(sun) || defined(_OSF_SOURCE)#    include <sys/mman.h>#  endif /* defined(sun) || defined(_OSF_SOURCE) */#endif /* !defined(_QNX_SOURCE) */#include <sys/wait.h>#if defined(DEC)#  include <sys/utsname.h>#endif /* defined(DEC) *//* * Modification History: * * February 27th, 2004 by Robin Miller. *       Switch ctime() to ctime_r() in preparation for threads. * * February 24th, 2004 by Robin Miller. *      Allow parsing of aios=0, to ease supporting of OS's which * don't support POSIX AIO.  Makes script writing a little simpler. * * December 6th, 2003 by Robin Miller. *      Conditionalize to exclude tty code. * * November 17th, 2003 by Robin Miller. *	Breakup output to stdout or stderr, rather than writing * all output to stderr.  If output file is stdout ('-') or a log * file is specified, then all output reverts to stderr. *	Parse AIO options, but then emit warning if not supported. * This allows portable scripts to be written without parameterizing * exlusion of AIO if a platform (OS) does not support it. * * October 31st, 2003 by Robin Miller. *	In terminate(), don't attempt flush if device or file is * not open when we receive the alarm signal. * * September 27th, 2003 by Robin Miller. *	Added support for AIX. * * June 9th, 2003 by Robin Miller. *	When terminating as result of alarm, flush output data if we * were writing a file.  Thanks to Hank Jakiela for reporting this. * * March 20th, 2003 by Robin Miller. *	Fix bug or'ing O_LARGEFILE into open flags (thanks Kris Corwin!). * * March 15th, 2003 by Robin Miller. *	Added "prefix=" option to support data pattern prefix string. * * March 14th, 2003 by Robin Miller. *	Added "slice=" option to support testing an individual slice. * * February 23rd, 2002 by Robin Miller. *      Make porting changes for HP-UX IA64. * * May 31st, 2001 by Robin Miller. *	Don't allow different data patterns with multiple processes, * unless writing to a regular file (each process has own filename). * * April 13th, 2001 by Robin Miller. *	Added "capacity=max" for Tru64 Unix, this will force using the * driver returned media capacity.  Prevents lseek/read algorithm when * using random I/O too!  Note:  Will inhibit disk driver EOM testing. * * February 24th, 2001 by Robin Miller. *	Add conditionalization for QNX RTP (Neutrino). * * February 21st, 2001 by Robin Miller. *	Disable EOF/EOM exit status by default.  This causes trouble for * normal testers.  Use "enable=eof" to reenable previous behaviour. * * February 6th, 2001 by Robin Miller. *	If input file and multiple slices, allow cycling through data * patterns, since the file is expected to have been written with unique * patterns in each slice region.  Minor update to deleting files too. * * February 3rd, 2001 by Robin Miller. *	Lift restriction of bs= or min= sizes being smaller than * sizeof(u_int32) for IOT pattern or lbdata option.  Although this * isn't *really* correct, enforcing this breaks numerious scripts. * Although smaller works, it's only by luck and the fact we have * pad bytes at EOB, which prvented data corruption in the past! * * January 28th, 2001 by Robin Miller. *	Added "slices=value" and "enable/disable=unique" options. * The slices option carves up a disk with each process exercising a * differnent range of blocks.  The unique pattern option sets up a * unique pattern for each process started for slices & regular files. * * January 26th, 2001 by Robin Miller. *	Added report_record() to the report record information. *	Added "iodir={forward,reverse}" option to all reverse I/O * to rotating media.  Add validation checks both before and after * a device is open (mostly random/reverse I/O checks). * * January 24th, 2001 by Robin Miller. *	Added "dsize=value" to set the device block size. *	Added "incr=var" option for variable request sizes. *	Removed some dead code (#if 0 stuff), to cleanup a bit. *	Updates to allow the IOT pattern to use non-modulo 512 byte * sizes.  The logic is: 1) user defined "lbs=value", 2) device block * size (Tru64 Unix), or 3) default to 512 byte block (original default). * This change was initiated by Windows/NT IOT disc using 2KB sector size. * * January 18th, 2001 by Robin Miller. *	When requesting multiple volumes, ensure the tape device gets * closed prior to retries, if the rewind operation fails.  Otherwise, * the next tape open fails with EBUSY (exclusive open device). * * January 14th, 2001 by Robin Miller. *	Added support for multiple volumes option. * * December 30th, 2000 by Robin Miller. *	Make changes to build using MKS/NuTCracker product. * * November 19th, 2000 by Robin Miller. *	Add missing enable/disable=fsync goto label statements. * * November 10th, 2000 by Robin Miller. *	Added sanity check to warn user about unpredictable results * when writing to a disk with multiple procs and multiple passes. * * November 8th, 2000 by Robin Miller. *	Added "disable=cerrors" to disable device close errors. * [ Note: This is really a workaround for the Linux tape driver. ] *	In HandleMultiVolume(), if closing the device fails, then * return that failure to abort the test.  With tapes, this means * flushing the buffered data or writing filemarks has failed. * * October 2nd, 2000 by Robin Miller. *	Enhanced report_error() to display errno value (same as Scu). * * August 22nd, 2000 by Robin Miller. *	Added boolean flags to track user set min, max, & incr values. * * July 14th, 2000 by Robin Miller. *	Added fsync_flag to control sync'ing data to disk files. * * May 8th, 2000 by Robin Miller. *	Adding parsing of "version" option, which is used to only * display the version string, dtversion() in file dtusage.c * * May 5th, 2000 by Robin Miller. *	Set proper exit code in terminate(), when exiting due to * an alarm, i.e., runtime= option.  Previously, the end of file * exit status was being ignored and we exited with failure status. * * April 25th, 2000 by Robin Miller. *	Fix problem of not breaking out of test loop if the error * limit has been reached on previous pass. * * March 28th, 2000 by Robin Miller. *	Modify "position=value" to accept a large numeric value, * otherwise we were limited to 32 bit value on non-64bit systems. * Do the same thing for "step=value" for 64-bit file offsets. * When using the "runtime=" option, when the alarm expires and * we call terminate() to exit, look at the exit_status variable * instead of error_count for errors, so we don't miss errors! * * March 27th, 2000 by Robin Miller. *   o	Fixed parsing of a couple flags, including "flags=direct". *   o	Added "capacity=value" option to set the drive capacity. * * March 20th, 2000 by Robin Miller. *	Don't allow a pass limit of zero.  This also avoids a * core dump when preparing statistics, since the active device * never got setup. * * March 2nd, 2000 by Robin Miller. *	In HandleMultiVolume(), reset the exit status to SUCCESS, * since this got set to END_OF_FILE earlier.  Failure to do this * means we exit with an END_OF_FILE (254) status (no good :-). * * February 17th, 2000 by Robin Miller. *	Adding better support for multi-volume tape testing. * * January 17th, 2000 by Robin Miller. *	In copy mode, is input file is stdin, don't do verify. *	Enable random I/O, for ralign, rlimit, or rseed options. * * January 14th, 2000 by Robin Miller. *	Don't delete the output file unless we're in test mode. * * January 6th, 2000 by Robin Miller. *	Added support for multi-volume media (lot's of changes). * * January 1st, 2000 by Robin Miller. *	Added read after write support, "enable=raw" option. * * December 31st, 1999 by Robin Miller. *	Added "rseed=" option, so user can specify the random seed. *	Modify reopen_file logic to use O_RDWR if skip_count exists. * * November 11th, 1999 by Robin Miller. *	Added logging of diagnostic information to event logger. * * November 10th. 1999 by Robin Miller. *	Fixed parsing of "dispose=delete". * * November 9th, 1999 by Robin Miller. *	Modify logic associated with making stderr stream buffered. * * August 26th, 1999 by Robin Miller. *	If during the write pass no data was transferred, don't do * the read pass since obviously this will result in a compare error. * * August 7th, 1999 by Robin Miller. *	Allow enabling open w/O_LARGEFILE via "flags=large", incase * _FILE_OFFSET_BITS=64 does _not_ enable this by default. * * July 22nd, 1999 by Robin Miller. *	Added support for IOT (DJ's) test pattern. *  * July 19th, 1999 by Robin Miller. *	Add flag to control log file header normally displayed. * * June 28, 1999 by Robin Miller. *	For 32-bit systems, change count and limit variables from * u_long to double, since u_long limits us to 4GB (too small). * * May 27, 1999 by Robin Miller. *	Merge in Goerge Bittner's changes for micro-second delays. *	Conditionalized all common/output file open flags. * * April 8, 1999 by Robin Miller. *	Merge in Jeff Detjen's changes for table()/sysinfo timing. * * April 7, 1999 by Robin Miller. *	On DEC systems, obtain tick/second via sysconf(_SC_CLK_TCK). * * December 21, 1998 by Robin Miller. *	Add pasing of "enable=resets", which enables tape repositioning * logic when bus/device resets are detected by DUNIX EEI status codes. * * December 19, 1998 by Robin Miller. *	- Disable setbuf() for stderr... screws up log files. *	- Write cmd line and version to log file for reference. * * December 16, 1998 by Robin Miller. *	Merge in changes made by George Bittner: *	- set random_seed using times() instead of time(0). *	- remove DLM_VALB, per Dan Christians' recommendation. * * October 29, 1998 by Robin Miller. *	Implement a random I/O data limit, instead of using the normal * data limit variable (not good to dual purpose this value). * * October 22, 1998 by Robin Miller. (Happy Birthday Mom!) *	When specifying a runtime, ensure we break out of the * passes loop if we exceed the error limit.  Previously, we'd * loop (possibly with error) for the duration of runtime :-) * * June 16, 1998 by Robin Miller. *	Add common open "flags={excl,ndelay,nonblock,rsync}". *	Add output (write) open "oflags={defer,dsync,trunc}". * * April 29, 1998 by Robin Miller. *	Add support for an alternate device directory. * * April 7, 1998 by Robin Miller. *	Setup the pattern as a pattern string, so non-modulo *	sizeof(pattern) read counts will data compare properly. * * March 20, 1998 by Robin Miller. *	When terminating, call close function before reporting stats, *	since in the case of AIO the I/O rundown updates statistics *	with outstanding requests, when we're aborted by a signal. * * May 14, 1997 by Robin Miller. *	In report_error(), set exit value to FAILURE instead of errno *	since this makes detecting errors easier in scripts. * * May 13, 1997 by Robin Miller. *	If a "skip=" count is specified with an output file "of=", *	open the file for R/W access since skips are accompished via *	read()'s of record size. * * March 27, 1997 by Ali Eghlima. *      Added cluster support, so more than one process or one system *      can access a resource. dlm are being used to synchronize all *      access. *  * March 7, 1997 by Robin Miller. *	If a copy or verify operation is selected, and a data limit *	is specified, then double the data limit to account for double *	the I/O's.  Previously, only half of the desired data limit was *	copied and/or verified. * * February 3, 1997 by Robin Miller. *	Check status from closing file descriptor, and if it's not *	SUCCESS, use this for the exit status.  For tapes, deferred *	writes and failure to write file marks occur at close time. * * March 30, 1996 by Robin Miller. *	When writing, now default to an infinite record limit, so *	writes stop when EOF is reached (disks and tapes only). * * February 29, 1996 by Robin Miller. *	Added callouts to setup data limit for disk random I/O. * * February 28, 1996 by Robin Miller. *	Added support for copying and verifying device/files. * * February 17, 1996 by Robin Miller. *	Add "enable=spad" option to control checking of pad bytes *	when long reads of short records is performed, since some *	controllers corrupt data bytes following the short record. *	[ NOTE:  At DEC, this action was deemed acceptable, since *	  the requester stated the driver could trash a larger buf. ] * * December 6, 1995 by Robin Miller. *	Add "ttymin=value" option to give user control over tty VMIN. * * November 19, 1995 by Robin Miller. *	When the device type is a disk, default min_size & incr_count to *	BLOCK_SIZE (512) instead of 1 (which is non-modulo for disks). * * November 18, 1995 by Robin Miller. *	Removing unaligned data access (ade) test code (code cleanup). * * July 24, 1995 by Robin Miller. *	Changed O_NDELAY to O_NONBLOCK which is defined by POSIX.  They are *	supposed to do the same thing, but they _do_ have different values. *	[ NOTE: This is only used for serial line modem testing. ] *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -