dt.h

来自「Linux磁盘测试的源代码,测试磁盘的读写性能」· C头文件 代码 · 共 1,265 行 · 第 1/3 页

H
1,265
字号
/**************************************************************************** *									    * *			  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.							    * *									    * ****************************************************************************//* * Modification History: * * September 27th, 2003 by Robin Miller. *      Added support for AIX. * * March 14th, 2003 by Robin Miller. *	Add declarations for slice and prefix variables. * * November 14th, 2002 by Robin Miller. *	Add support for 32-bit HP-UX compilation. * * February 23rd, 2002 by Robin Miller. *	Make porting changes for HP-UX IA64. * * February 1st, 2002 by Robin Miller. *	Make porting changes necessary for Solaris 8. * * August 31st, 2001 by Robin Miller. *	Increase size of di_capacity from 32 to 64 bits in preparation * for larger capacity volumes, esp. logical volumes on array controllers. * * January 24th, 2001 by Robin Miller. *	For Windows/NT, use /dev/[n]rmt instead of "tapeN" for tape * device names, since this is the name used when tapes are mounted * using the Cygnus toolkit. * * January 14th, 2001 by Robin Miller. *	Added support for multiple volumes option. * * January 11th, 2001 by Robin Miller. *	Modify conditionals so Windows tape devices are /dev/rmtN * and /dev/nrmtN (norewind)  which the latest Cygnus README states. * * December 30th, 2000 by Robin Miller. *	Make changes to build using MKS/NuTCracker product. * * April 17th, 2000 by Robin Miller. *	Added device path failure flag, to force re-open of tapes * on Wave4 clusters which forces alternate paths or servers to be * located by CAM or DRD. * * January 22nd, 2000 by Robin Miller. *	Added support for Cygwin tape devices for Windows/NT. * * August 6th, 1999 by Robin Miller. *      Better parameterizing of "long long" printf formatting. * * July 29, 1999 by Robin Miller. *	Merge in changes made to compile on FreeBSD. * * July 22nd, 1999 by Robin Miller. *	Added support for IOT (DJ's) test pattern. *  * May 27, 1999 by Robin Miller. *	Added support for micro-second delays. * * April 8, 1999 by Robin Miller. *	Merge in Jeff Detjen's changes for table()/sysinfo timing. * * December 21, 1998 by Robin Miller. *	For DUNIX, changes to handle tape resets. * * April 29, 1998 by Robin Miller. *	Add support for an alternate device directory, e.g. "/devices/", * as a prefix to physical device names.  Just checking for "/dev...", * described below, is too general and sure to get me into trouble. * * April 25, 1998 by Robin Miller. *	Change device prefix to account for "/dev" or "/devices" (steel), * since this knowledge is used to determine if a device should exist * (to avoid creating files in the /dev directory), as well as whether * the PID is appended during multiple process testing. * * February 28, 1996 by Robin Miller. *	Added support for copying and verifying device/files. * * December 19, 1995 by Robin Miller *      Conditionalize for Linux Operating System. * * September 23, 1994 by Robin Miller. *      Make changes necessary to build on QNX 4.21 release. * * September 5, 1992 by Robin Miller. *	Initial port to QNX 4.1 Operating System. */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <fcntl.h>#include <termios.h>#include <time.h> 				/* CLK_TCK defined here */#include <unistd.h>#include <math.h>#include <errno.h>#include <sys/types.h>#include <sys/times.h>#include <sys/stat.h>#if defined(__QNXNTO__)#include <unix.h>#endif/* * These are found in <tzfile.h> on Tru64 UNIX and Solaris. */#define SECS_PER_MIN	60#define MINS_PER_HOUR	60#define HOURS_PER_DAY	24#define SECS_PER_HOUR	(SECS_PER_MIN * MINS_PER_HOUR)#define SECS_PER_DAY	(SECS_PER_HOUR * HOURS_PER_DAY)#if defined(DEC)#  include <sys/table.h>#endif /* defined(DEC) */#if defined(EEI)#  include <sys/mtio.h>#endif /* defined(EEI) */#if defined(MUNSA)#  include <assert.h>#  include <sys/dlm.h>dlm_lock_mode_t    munsa_lock;#endif /* defined(MUNSA) */#if !defined(HZ)#  if defined(sun) || defined(__WIN32__) || defined(SCO) || defined(HP_UX)#    include <sys/param.h>#  endif /* defined(sun) */#  if defined(CLK_TCK) && !defined(HZ)#    define HZ		CLK_TCK#  else#    if !defined(HZ)#      define HZ		256#    endif /* !defined(HZ) */#    if !defined(CLK_TCK)#      define CLK_TCK	HZ#    endif /* !defined(CLK_TCK) */#  endif /* defined(CLK_TCK) */#endif /* !defined(HZ) */#if defined(DEC)#  define LOG_DIAG_INFO	1#endif /* defined(DEC) */#if defined(__alpha) || defined(__LP64__)#  define MACHINE_64BITS#endif /* defined(__alpha) *//* * Macro to calculate block count from byte count (rounds up). * [ these are usually found in sys/param.h on DUNIX ] */#if !defined(howmany)#  define howmany(x, y)   (((x)+((y)-1))/(y))#endif /* !defined(howmany) */#if !defined(roundup)#  define roundup(x, y)   ((((x)+((y)-1))/(y))*(y))#endif /* !defined(roundup) */#if !defined(rounddown)#  define rounddown(x,y)  (((x)/(y))*(y))#endif /* !defined(rounddown) *//* * Macros for fast min/max. */#if !defined(MIN)#  define MIN(a,b) (((a)<(b))?(a):(b))#endif /* !defined(MIN) */#if !defined(MAX)#  define MAX(a,b) (((a)>(b))?(a):(b))#endif /* if !defined(MAX) *//* * Macro to calculate the starting block of where error occured. *    ( 'x' = byte count or file offset, 'y' = block size ) */#define WhichBlock(x,y)		((x)/(y))#if defined(__CYGWIN__) && defined(__STRICT_ANSI__)int     _EXFUN(fileno, (FILE *));#endif/* * Large value for 32 or 64 bit systems. * * Note: Most systems are now defined quad_t or u_quad_t for *	 "long long" values, but I've chosen to avoid conflicts *	 by defining my own typedef's (for now :-).  The other *	 reason for my own definitions is to avoid the following: * *	 typedef struct  _quad { int val[2]; } quad; * *	 used by some systems that don't support "long long" :-) * */#if defined(MACHINE_64BITS)#define QuadIsLongtypedef unsigned long		large_t;typedef signed long		slarge_t;typedef volatile large_t	v_large;typedef volatile slarge_t	v_slarge;#define LUF	"%lu"#define LDF	"%ld"#define LXF	"%#lx"#define FUF	LUF#define FXF	LXF#elif defined(__GNUC__) && defined(_BSD_SOURCE) || defined(SCO) || defined(__QNXNTO__) || defined(SOLARIS) || defined(HP_UX) || defined(AIX) || defined(_NT_SOURCE)#define QuadIsLongLongtypedef unsigned long long int	large_t;typedef signed long long int	slarge_t;typedef volatile large_t	v_large;typedef volatile slarge_t	v_slarge;#if defined(__QNXNTO__) || defined(SOLARIS) || defined(HP_UX) || defined(AIX)#  define LUF   "%llu"#  define LDF   "%lld"#  define LXF   "%#llx"#elif defined(SCO)#  define LUF	"%Lu"#  define LDF	"%Ld"#  define LXF	"%#Lx"#else /* !defined(SCO) && !defined(__QNXNTO__) && !defined(HP_UX) && !defined(AIX) */#  define LUF	"%qu"#  define LDF	"%qd"#  define LXF	"%#qx"#endif /* defined(__QNXNTO__) */#if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)#  define FUF	LUF#  define FXF	LXF#else /* !defined(_FILE_OFFSET_BITS) || (_FILE_OFFSET_BITS != 64) */#  define FUF	"%lu"#  define FXF	"%#lx"#endif /* defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64) */#elif defined(__NUTC__)#define QuadIsLongLongtypedef u_quad_t		large_t;typedef quad_t			slarge_t;typedef volatile large_t	v_large;typedef volatile slarge_t	v_slarge;#define LUF	"%qu"#define LDF	"%qd"#define LXF	"%#qx"#define FUF	"%lu"#define FXF	"%#lx"#else /* !defined(MACHINE_64BITS) && !defined(__GNUC__) */#define QuadIsDoubletypedef double			large_t;typedef double			slarge_t;typedef volatile large_t	v_large;typedef volatile slarge_t	v_slarge;#define LUF	"%.0f"#define LDF	"%.0f"#define LXF	"%.0f"	/* ??? no hex ??? */#define FUF	"%lu"#define FXF	"%#lx"#endif /* defined(MACHINE_64BITS) *//* * Create some shorthands for volatile storage classes: */typedef	volatile char	v_char;typedef	volatile short	v_short;typedef	volatile int	v_int;typedef volatile long	v_long;#if !defined(DEC)/* These are defined in sys/types.h on DEC Alpha systems. */typedef	volatile unsigned char	vu_char;typedef	volatile unsigned short	vu_short;typedef	volatile unsigned int	vu_int;typedef volatile unsigned long	vu_long;#endif /* !defined(__alpha) */#define SUCCESS		0			/* Success status code. */#define FAILURE		-1			/* Failure status code. */#define WARNING		1			/* Warning status code.	*/#define TRUE		1			/* Boolean TRUE value.	*/#define FALSE		0			/* Boolean FALSE value.	*/#define UNINITIALIZED	255			/* Uninitialized flag.	*/#define NO_LBA		0xFFFFFFFF		/* No LBA vlaue.	*/#define BLOCK_SIZE		512		/* Bytes in block.	*/#define KBYTE_SIZE		1024		/* Kilobytes value.	*/#define MBYTE_SIZE		1048576L	/* Megabytes value.	*/#define GBYTE_SIZE		1073741824L	/* Gigabytes value.	*//* * These buffer sizes are mainly for allocating stack space * for pre-formatting strings to display.  Different sizes * to prevent wasting stack space (my preference). */#define SMALL_BUFFER_SIZE       32              /* Small buffer size.   */#define MEDIUM_BUFFER_SIZE      64              /* Medium buffer size.  */#define LARGE_BUFFER_SIZE       128             /* Large buffer size.   */#define STRING_BUFFER_SIZE	256		/* String buffer size.	*/#define MAX_PROCS	256			/* Maximum processes.	*/#define MAX_SLICES	256			/* Maximum slices.	*/#define USE_PATTERN_BUFFER			/* Use pattern buffer.	*/#undef INFINITY#if defined(MACHINE_64BITS)#  define MAX_SEEK	0x8000000000000000UL /* Maximum lseek() value.	*/#  define MAX_LONG	0x7fffffffffffffffL  /* Maximum positive long.	*/#  define MAX_ULONG	0xffffffffffffffffUL /* Maximum u_long value.	*/#  define INFINITY	MAX_ULONG	/* Maximum possible long value.	*/#  define DEFAULT_PATTERN 0x39c39c39U	/* Default data pattern.	*/#  define ASCII_PATTERN	  0x41424344U	/* Default ASCII data pattern.	*/#  define TBYTE_SIZE	1099511627776L		/* Terabytes value.	*/#else /* !defined(MACHINE_64BITS */#  define MAX_LONG	0x7fffffffL	/* Maximum positive long value.	*/#  define MAX_ULONG	0xffffffffUL	/* Maximum unsigned long value.	*/#  if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)#    define MAX_SEEK	0x8000000000000000ULL /* Maximum lseek() value. */#  else /* if !defined(_FILE_OFFSET_BITS) || (_FILE_OFFSET_BITS != 64) */#    define MAX_SEEK	0x80000000UL	/* Maximum lseek() value.	*/#  endif /* defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64) */#  if defined(QuadIsLongLong)#    if defined(__NUTC__)#      define MAX_ULONG_LONG 0xffffffffffffffffui64#      define INFINITY	 MAX_ULONG_LONG	/* Maximum possible large value */#      define TBYTE_SIZE 1099511627776i64       /* Terabytes value.	*/#    else #      define MAX_ULONG_LONG 0xffffffffffffffffULL#      define INFINITY	 MAX_ULONG_LONG	/* Maximum possible large value */#      define TBYTE_SIZE 1099511627776LL	/* Terabytes value.	*/#    endif /* defined(__NUTC__) */#  else /* assume QuadIsDouble */#    if defined(__WIN32__)       /* HUGE_VAL seems to be defined as 0.0, which is NFG! */#      define INFINITY  (double)0x10000000000000L /* Max large value???	*/#    else#      define INFINITY	HUGE_VAL	/* Maximum possible large value */#    endif#    define TBYTE_SIZE	((double)GBYTE_SIZE*1024) /* Terabytes value.	*/#  endif /* defined(QuadIsLongLong) */#  define DEFAULT_PATTERN 0x39c39c39UL	/* Default data pattern.	*/#  define ASCII_PATTERN	  0x41424344UL	/* Default ASCII data pattern.	*/#endif /* defined(MACHINE_64BITS) *//* * Shorthand macros for string compare functions: */#define EQ(x,y)		(strcmp(x,y)==0)	/* String EQ compare.	*/#define EQL(x,y,n)	(strncmp(x,y,n)==0)	/* Compare w/length.	*/#define NE(x,y)		(strcmp(x,y)!=0)	/* String NE compare.	*/#define NEL(x,y,n)	(strncmp(x,y,n)!=0)	/* Compare w/length.	*/#define EQS(x,y)	(strstr(x,y) != NULL)	/* Sub-string equal.	*/#define EQSC(x,y)	(strcasestr(x,y) != NULL) /* Case insensitive.	*/#define NES(x,y)	(strstr(x,y) == NULL)	/* Sub-string not equal	*/#define NESC(x,y)	(strcasestr(x,y) == NULL) /* Case insensitive.	*//* * Define some known device names (for automatic device recognition). */#define DEV_PREFIX	"/dev/"		/* Physical device name prefix.	*/#define DEV_LEN		5		/* Length of device name prefix.*//* * Alternate Device Directory: */#if defined(_NT_SOURCE)#  define ADEV_PREFIX	"//./"		/* Windows hidden device dir.	*/#  define ADEV_LEN	4		/* Length of device name prefix.*/#  define NDEV_PREFIX	"\\\\.\\"	/* Native Windows device dir.	*/#  define NDEV_LEN	4		/* That's for "\\.\" prefix.	*/#else /* !defined(_NT_SOURCE) */#  define ADEV_PREFIX	"/devices/"	/* Physical device name prefix.	*/#  define ADEV_LEN	9		/* Length of device name prefix.*/#  define NDEV_PREFIX	"/dev/"		/* Native device prefix (dup).	*/#  define NDEV_LEN	5		/* Native device prefix length.	*/#endif /* defined(_NT_SOURCE) */#define CONSOLE_NAME	"console"	/* The console device name.	*/#define CONSOLE_LEN	7		/* Length of console name.	*/#if defined(_QNX_SOURCE)#  define CDROM_NAME	"cd"		/* Start of CD-ROM device name.	*/#  define RCDROM_NAME	"cd"		/* Start of raw CD-ROM names.	*/#elif defined(sun) || defined(__linux__)/* Note: Don't know about Sun systems. */#  define CDROM_NAME	"cd"		/* Start of CD-ROM device name.	*/#  define RCDROM_NAME	"scd"		/* Start of raw CD-ROM names.	*//* NOTE: Linux (RedHat V6.0) currently has no raw CD-ROM names! */

⌨️ 快捷键说明

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