📄 dtutil.c
字号:
/**************************************************************************** * * * 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: dtutil.c * Author: Robin T. Miller * * Description: * Utility routines for generic data test program. */#include "dt.h"#include <ctype.h>#include <fcntl.h>#include <math.h>#include <netdb.h> /* for MAXHOSTNAMELEN */#include <string.h>#include <stdarg.h>#include <sys/stat.h>#include <sys/param.h>#if defined(sun)# define strtoul strtol#endif /* defined(sun) */#if defined(ultrix)extern void *valloc(size_t size);#endif /* defined(ultrix) *//* * Modification History: * * March 30th, 2004 by Robin Miller. * Improve lseek error messages (should they should fail). * * March 24th, 2004 by Robin Miller. * Update code in do_random() where the random data limit * (rdata_limit) was being truncated to an unsigned long, which * is 32-bits many systems. This causes large capacity disks, * such as 36GB (0x900000000), to be truncated to zero which * causes a divide by zero ("Arithmetic exception" on HP-UX). * Also increase the size of the random number (randum) to * 64-bits (on 32-bit systems), so larger seeks are possible. * * February 23, 2004 by Robin Miller. * Reverse the buffer and prefix pattern bytes being dumped * in verify_prefix(), so they properly reflect the expected versus * found bytes. Otherwise, the information is misleading. * * November 25th, 2003 by Robin Miller. * When formatting the prefix string, if we're doing random * I/O, round the prefix string up to sizeof(u_int32), so partial * patterns (non-modulo our 4 byte pattern) do not get used, which * causes false data compare failures. * Note: Failures still occur if random I/O is used with pattern * files containing non-repeating data pattern bytes! * * November 20th, 2003 by Robin Miller. * Broken verify data function up for better performance. * Update prefix string logic to write the string in every * logical block (lbdata_size). This had to be done or else random * I/O with prefix strings failed! It also give better coverage. * * 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. * * October 8th, 2003 by Robin Miller. * On AIX, accept ENXIO for I/O's pass EOF. * * September 27th, 2003 by Robin Miller. * Added support for AIX. * * March 20th, 2003 by Robin Miller. * Added FmtPrefix() to format the prefix string. * * March 18th, 2003 by Robin Miller. * Optimize code and loops using USE_PATTERN_BUFFER define. * * March 15th, 2003 by Robin Miller. * Added support for data pattern prefix strings. * * March 4th, 2003 by Robin Miller. * Add support for broken EOF SunOS release. This means writes * at EOF return a count of zero, but there is no errno value to key * off like POSIX specifies. * * November 21st, 2002 by Robin Miller. * On HP-UX, accept ENXIO for I/O's pass EOF. * * November 14th, 2002 by Robin Miller. * Add support for 32-bit HP-UX compilation. * * October 10th, 2002 by Robin Miller. * Display correct erroring byte during data compare errors, * when using a 32-bit hex data pattern. * * February 1st, 2002 by Robin Miller. * Make porting changes necessary for Solaris 8. * * January 29th, by Robin Miller. * Minor tweak to clarify correct versus incorrect data dumped. * * June 25th, 2001 by Robin Miller. * Report mt status for all errors, not just EIO errors. Also, * report mt status on unexpected EOF/EOM when no data transferred. * Note: Reporting mt and EEI status is only done for Tru64 Unix. * * February 24th, 2001 by Robin Miller. * Add conditionalization for QNX RTP (Neutrino). * * January 24th, 2001 by Robin Miller. * Add support for variable I/O requests sizes. * Conditionalize some functions to allow INLINE macros. * Modifications to allow IOT test pattern to honor the lba * size variable, rather than hardcoding IOT to 512 byte sectors. * * January 15th, 2001 by Robin Miller. * Don't terminate() on failures, return error to caller. * Note: seek functions still call terminate()... more work! * * January 2nd, 2001 by Robin Miller. * Make changes to build using MKS/NuTCracker product. * * October 4th, 2000 by Robin Miller. * Update is_Eof() to accept ENXIO for AIO reads @ EOM on * SCO UnixWare systems. All other systems return ENOSPC or zero. * * April 25th, 2000 by Robin Miller. * Added an expect flag to dump_buffer to help with formatting. * * April 18th, 2000 by Robin Miller. * Modified calls to report_error() to ensure error count bumped. * * March 28th, 2000 by Robin Miller. * Modified file position functions to accept device information * parameter, so necessary debug could be added to these funcitons. * Also, only scale the random position upwards by the device size * every other record, so low blocks gets utilized more often. * Note: These changes degrade random I/O performance slightly. * [ All debug needs ripped out to obtain better performance, ] * * February 17th, 2000 by Robin Miller. * Adding better support for multi-volume tape testing. Mainly, * make it work with writing multiple tape files, rather than one file. * * February 16th, 2000 by Robin Miller. * Set exit_status to FAILURE in RecordError() function. This * is necessary to catch any error being logged, since test functions * no longer call terminate() with FAILURE status. * * January 22nd, 2000 by Robin Miller. * Add check for Cygwin device names for Windows/NT. * * January 4th, 2000 by Robin Miller. * Major cleanup in verify_data(). Now reports IOT block number. * Added verify_buffers() and verify_lbdata() functions for raw. * * December 31st, 1999 by Robin Miller. * Modify do_random() to ensure rlimit is not exceeded when the lower * file position is factored in, to stay within desired lba range. * * December 30th, 1999 by Robin Miller. * Modify do_random() to take into consideration the transfer size, * to ensure the requested random I/O data limit is not exceeded. * Added get_lba() function to return the current logical block address. * * November 11th, 1999 by Robin Miller. * Add LogDiagMsg() to log diagnostic information to event logger. * * November 10th, 1999 by Robin Miller. * Update make_lbdata() & winit_lbdata() so if the IOT test pattern is * selected, and the device block size is NOT 512 bytes, we force 1 block. * Note: This only affects Tru64 Unix, since we obtain the real sector size. * * November 9th, 1999 by Robin Miller. * Remove use of '%p' in dump_buffer(), since it's use is inconsistent. * With Cygnus Solutions, '%p' displays a leading '0x', other OS's don't! * * August 26th, 1999 by Robin Miller. * Report an error for ENOSPC, if no data has been transferred. * Previously, this error was only reported for tape devices. * * 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. * * July 7th, 1999 by Robin Miller. * Modify CvtStrtoValue() to check for recursive calls which return * zero (0) for '/' and '%', which cause a divide by zero fault/core dump. * * June 28, 1999 by Robin Miller. * For 32-bit systems, added CvtStrtoLarge() function to * permit double or long long values, since u_long is too small. * * May 27, 1999 by Robin Miller. * Added support for micro-second delays. * * April 8, 1999 by Robin Miller. * Added format_ltime() to format table() sysinfo times. * * January 7, 1999 by Robin Miller. * Removed fflush() in Fprintf() function which caused intermixed * output when multiple processes were running (i.e., serial line testing). * * December 21, 1998 by Robin Miller. * - update Malloc() to clear allocated memory. * - for DUNIX, updates to handle resets for tapes. * * December 16, 1998 by Robin Miller. * Merge in changes made by George Bittner: * - modify do_random(), use random value as a block number * instead of a byte offset, for testing larger disks/files. * - ensure the random offset is within starting file position * and the end of the disk/partition. * * November 19, 1998, by Robin Miller. * Fix problem where wrong lbdata lba was returned for offset 0. * This required updates to make_lbdata() and winit_lbdata() functions. * [ sorry folks, major brain burp!!! ] * * November 16, 1998 by Robin Miller. * For AIO, report the relative block from saved AIO control block. * * 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 26, 1998 by Robin Miller. * Add functions make_lbdata() and winit_lbdata() which handle * using both random I/O and lbdata options. The file offset seeked * to is used as the starting lbdata address. * * April 28, 1998 by Robin Miller. * For WIN32/NT, or in O_BINARY into open flags to force binary * mode (the default is text mode). * * May 16, 1997 by Robin Miller. * Modified macro used in ReportDeviceInfo() which rounded block * up, causing the erroring block to be off by one, when data * compare errors were not at the beginning of a block. Also, * report the block offset (byte within block) when non-modulo. * * May 14, 1997 by Robin Miller. * If we encounter a ENOSPC error and no data has been transferred, * flag this as an error. This normally indicates a zero length * partition or the user may have seek'ed past eom or eop. * * March 27, 1997 by Ali Eghlima. * Fix call to report_error() to reflect "unlink" failed. * * March 7, 1997 by Robin Miller. * In ReportDeviceInfo(), when we're doing a copy/verify * operation, allow output device to be a different offset. * * February 28, 1996 by Robin Miller. * Modified ReportDeviceInfo() so we seek past disk errors. * This action allows testing to continue with "errors=n". * * February 21, 1996 by Robin Miller. * Added do_random() function for random I/O to disks. * * December 19, 1995 by Robin Miller. * Conditionalize for Linux Operating System. * * Novemeber 18, 1995 by Robin Miller. * Removing unaligned data access (ade) test code (code cleanup). * * November 11, 1995 by Robin Miller. * Fix bug with verifying pad bytes. Basically, the previous logic, * while valid for short reads, was incorrect when the pad bytes did * *not* start on a modulo sizeof(int) boundary. This caused variable * length reads with small increment values to report an (invalid) * pad byte data compare error. NOTE: Only occurred w/pattern file. * * July 22, 1995 by Robin Miller. * Finally, correctly dump data buffers with context (yes, I made * sure I tested min/max limits via fault insertion this time). * * July 15, 1995 by Robin Miller. * Add is_Eof() to handle end of media (ENOSPC), and cleanup code. * * July 7, 1995 by Robin Miller. * Correctly dump the pattern buffer on data compare errors. * When reporting a compare error, also display the byte count. * This latter information is useful for variable length records. * * July 6, 1995 by Robin Miller. * Changed a number of fprintf's to Fprintf so the child PID gets * reported during error processing (how did I miss this stuff?). * * September 23, 1994 by Robin Miller. * Make changes necessary to build on QNX 4.21 release. * * January 20, 1994 by Robin Miller. * When checking the pad bytes, don't do the entire buffer since very * large buffers (e.g. 100m) may have been specified using min, max, * and incr options which cause excessive paging and poor performance. * * October 28, 1993 by Robin Miller. * For multiple processes, display the PID to differentiate output. * * September 15, 1993 by Robin Miller. * Limit pattern buffer dumping to size of pattern buffer. * * September 17, 1993 by Robin Miller. * Added RecordWarning() function to reporting record number and * time stamp on warning errors (useful for debugging purposes). * More limiting of data & pattern buffer dumping (less bytes). * * September 3, 1993 by Robin Miller. * Allow "inf" or "INF" keywords to set maximum counts. * * September 2, 1993 by Robin Miller. * Added device specific information. * * September 1, 1993 by Robin Miller. * Report proper record number during errors (add partial records). * Limit data dumped when data verify errors occur (short records). * * August 27, 1993 by Robin MIller. * Added support for DEC OSF/1 POSIX Asynchronous I/O (AIO). * * August 17, 1993 by Robin Miller. * Added function RecordError() to record when an error occurs, * and added function Ctime() to append date/time string to the * log buffer. * * August 10, 1993 by Robin Miller. * Added verify_padbuf() function to check pad buffer bytes after * read operations to ensure they weren't overwritten. * * August 4, 1993 by Robin Miller. * Added various printing functions to simplify error reporting. * * September 11, 1992 by Robin Miller. * Added additional debug information when reopening a device. * * September 5, 1992 by Robin Miller. * Initial port to QNX 4.1 Operating System. * * May 22, 1992 by Robin Miller. * Control / force kernel address data exception via flag. * * March 11, 1992 by Robin Miller. * Changes necessary for port to 64-bit Alpha architecture. * * October 16, 1990 by Robin Miller. * Added myalloc() memory allocation function to allocate and * align the buffer address using the alignment value. * * October 9, 1990 by Robin Miller. * Use variable hz instead of HZ define for clock ticks per second * so user can specify different value via "hz=ticks" option. * * August 21, 1990 by Robin Miller. * Changed exit status so scripts can detect and handle errors * based on the exit code. If not success, fatal error, or end * of file/tape, the exit code is the error number (errno). * * August 21, 1990 by Robin Miller. * Added function dump_buffer() to dump buffer in hex bytes. * * August 8, 1990 by Robin Miller. * Added functions seek_file() and skip_records(). Modified seek * file function to avoid lseek() system call overhead (see code). * * Changed malloc() to valloc() to align buffer on page boundry. * On some archetectures, this results on better performance to * raw devices since the DMA is done directly to the users' buffer. * * April 11, 1990 by Robin Miller. * Added function mmap_file() to memory map a file. Added munmap() * syscall to reopen_file() which gets called for multiple passes. * This allows us to time the mmap() as well as the munmap() code. * * March 21, 1990 by Robin Miller. * Added function delete_file() which checks for a regular file * and then unlinks it. * *//* * Forward References: */size_t copy_prefix(u_char *buffer, size_t bcount);int verify_prefix(struct dinfo *dip, u_char *buffer, size_t bcount, size_t *pcount);static int verify_data_normal( struct dinfo *dip, u_char *buffer, size_t bcount, u_int32 pattern);static int verify_data_prefix( struct dinfo *dip, u_char *buffer, size_t bcount, u_int32 pattern );static int verify_data_with_lba(struct dinfo *dip, u_char *buffer, size_t bcount, u_int32 pattern, u_int32 *lba );static size_t CalculateDumpSize(size_t size);static int dopad_verify ( struct dinfo *dip, u_char *buffer, size_t offset, u_int32 pattern, size_t pbytes, size_t pindex, bool inverted );int vSprintf(char *bufptr, const char *msg, va_list ap);#if 0static char *pad_str = "Pad";#endifstatic char *data_str = "Data";static char *pattern_str = "Pattern";static char *prefix_str = "Prefix";static char *verify_str = "Verify";static char *compare_error_str = "Data compare error at byte";static char *bad_conversion_str = "Warning: unexpected conversion size of %d bytes.";/************************************************************************ * * * delete_file() - Delete the specified file. * * * * This function ensures the file specified is a regular * * file before doing an unlink() to delete the file. * * * * Inputs: dip = The device information pointer. * * * * Outputs: Returns SUCCESS/FAILURE = File Delete/Not Deleted. * * * ************************************************************************/intdelete_file (struct dinfo *dip){ int status; if (debug_flag) { Printf("Deleting file '%s'...\n", dip->di_dname); } if ( (status = unlink(dip->di_dname)) == FAILURE) { report_error ("unlink", TRUE); } return (status);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -