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

📄 dtgen.c

📁 Linux磁盘测试的源代码,测试磁盘的读写性能
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************** *									    * *			  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:	dtgen.c * Author:	Robin T. Miller * Date:	September 8, 1993 * * Description: *	Generic test functions for the 'dt' program. * * Modification History: * * February 27th, 2004 by Robin Miller. *      In open_file() pre-format error string for Hazard printing. * * 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. * * September 27th, 2003 by Robin Miller. *      Added support for AIX. * * February 21st, 2002 by Robin Miller. *	Fix regression introduced by January 29th, 2002 update! * When AIO is specified the base buffer is not setup, only the * data buffer, so referencing this NULL pointer dumped core. * * January 29th, 2002 by Robin Miller. *	If compare is disabled, initialize the data buffer to be written. * This is important to honor the user specified pattern, and to avoid * problems writing data to tapes in compressed mode (user may wish to * specify a non-repeating data pattern).  In retrospect, it may not * be a good idea to use !compare to disable buffer initialization, * but changing this now will break too many folks :-) * * February 24th, 2001 by Robin Miller. *	Add conditionalization for QNX RTP (Neutrino). * * February 6th, 2001 by Robin Miller. *	Handle multiple slices to the same output file, by ensuring the * file disposition is set to "keep".  Otherwise, the first completing * process deletes the in-use file, which is generally not desriable. * * avoid unexpected failures.  This *is* permitted for input files. * * January 29th, 2001 by Robin Miller. *	Added validity checks to ensure transfer counts are modulo the * device size, to avoid unexpected failures. * * January 25th, 2001 by Robin Miller. *	Added validate options function for checking options after the * device information has been setup (i.e., device size, etc). * * January 15th, 2001 by Robin Miller. *	Add error checks to seek_file() and skip_file() calls. *	If reopen failures occur, don't terminate, return the error. * * January 14th, 2001 by Robin Miller. *	Added support for multiple volumes option. * * January 12th, 2001 by Robin Miller. *	When reading multiple tape files, issue a forward space file * mark command between tape files.  For systems which don't support * tape operations, we'll use continue to use the read_eof() method. * * December 30th, 2000 by Robin Miller. *	Make changes to build using MKS/NuTCracker product. * * November 8th, 2000 by Robin Miller. *	Add check for ignoring device close failures.  In this case, * the error is displayed as a warning instead of a failure. * * July 14th, 2000 by Robin Miller. *	In flush_file(), control sync'ing of data using fsync flag. * * May 8th, 2000 by Robin Miller. *	Honor the di_closing flag, to avoid a race condition with the * close function being called (again) while still closing, from the * terminate() routine called by the runtime= alarm, or signals. * [ damn, fixed this in 1994, broke it during recent re-write :-) ] * * April 18th, 2000 by Robin Miller. *	Added messages for open/close failures doing EEI reset tests. *	Modified calls to report_error() to ensure error count bumped. * * March 28th, 2000 by Robin Miller. *	Modified calls to file position functions which now accept a * device information parameter. * * February 19th, 2000 by Robin Miller. *	When EEI resets are enabled, retry open/reopen failures attempts. *	Also, if we're processing EEI resets, don't fail on close(). * * February 17th, 2000 by Robin Miller. *	Adding better support for multi-volume tape testing. * * January 22nd, 2000 by Robin Miller. *	Added support for Cygwin tape devices for Windows/NT. * * August 2, 1999 by Robin Miller. *	Don't do fsync() to tape devices to avoid errors on Linux. * * May 27, 1999 by Robin Miller. *	Adding support for micro-second delays. * * February 26, 1999 by Robin Miller. *	Adjust the file count AFTER writing a file mark, so our tape * repositioning code will work if the Reset occurs during the WFM. * * December 21, 1998 by Robin Miller. *	Updates necessary to match my tape API changes. *	Save device/file open flags in device info struct. * * December 17, 1998 by Robin Miller. *	For DUNIX tape devices, clear persistent EEI data after opens. * * 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). * * April 7, 1998 by Robin Miller. *	Fix problem with attempting reopen of stdin/stdout. * * 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. * * December 9, 1995 by Robin Miller. *	Allow writing tape file marks on QNX Operating System. * * September 23, 1994 by Robin Miller. *	Make changes necessary to build on QNX 4.21 release.  This *	required changing O_DSYNCH to O_DSYNC, and O_FSYNCH to O_SYNC. * * May 19, 1994 by Robin Miller. *	Altered logic in close_file() & reopen_file() functions to set *	the file descriptor to NoFd prior to calling close() to actually *	perform the close operation.  This avoids a problem where if the *	user types Ctrl/C while the close is in progress, the signal handler *	gets invoked immediately after the system call, the fd doesn't *	get marked closed, and our termination code then attempts to *	close an already closed file descriptor and reports the error: *		"dt: 'close' - Bad file number" */#include "dt.h"#if defined(_QNX_SOURCE)#  include <fcntl.h>#else /* !defined(_QNX_SOURCE) */#  include <sys/file.h>#endif /* defined(_QNX_SOURCE) *//* * Declare the generic (default) test functions. */struct dtfuncs generic_funcs = {    /*	tf_open,		tf_close,		tf_initialize,	  */	open_file,		close_file,		initialize,    /*  tf_start_test,		tf_end_test,				  */	init_file,		nofunc,    /*	tf_read_file,		tf_read_data,		tf_cancel_reads,  */	read_file,		read_data,		nofunc,    /*	tf_write_file,		tf_write_data,		tf_cancel_writes, */	write_file,		write_data,		nofunc,    /*	tf_flush_data,		tf_verify_data,		tf_reopen_file,   */	flush_file,		verify_data,		reopen_file,    /*	tf_startup,		tf_cleanup,		tf_validate_opts  */	nofunc,			nofunc,			validate_opts};#if defined(MUNSA)dlm_status_t gen_stat;#endif /* defined(MUNSA) *//************************************************************************ *									* * open_file() - Open an input/output file for read/write.		* *									* * Description:								* *	This function does the default (generic) open processing.	* *									* * Inputs:	dip = The device information pointer.			* *		oflags = The device/file open flags.			* *									* * Return Value:							* *		Returns 0 / -1 = SUCCESS / FAILURE.			* *									* ************************************************************************/intopen_file (struct dinfo *dip, int oflags){    char *file = dip->di_dname;    int status = SUCCESS;#if defined(EEI)    int open_retries = EEI_OPEN_RETRIES;#endif    if ( (strlen(file) == 1) && (*file == '-') ) {	if (debug_flag) {	    Printf ("Dup'ing standard %s...\n",		(dip->di_ftype == INPUT_FILE) ? "input" : "output");	}	if (dip->di_ftype == INPUT_FILE) {	    stdin_flag = TRUE;	    dip->di_fd = dup (fileno(stdin));	} else {	    ofp = efp; 		/* Redirect output to stderr. */	    stdout_flag = TRUE;	    dip->di_fd = dup (fileno(stdout));	    verify_flag = FALSE;	}	if (dip->di_fd < 0) {	    Fprintf ("dup -> ");	    report_error (file, TRUE);	    status = FAILURE;	}    } else {#if defined(__WIN32__)	oflags |= O_BINARY;#endif /* defined(__WIN32__) */#if defined(EEI)retry:#endif	if (debug_flag) {	    Printf (		"Attempting to open %s file '%s', open flags = %#o (%#x)...\n",		(dip->di_ftype == INPUT_FILE) ? "input" : "output",							file, oflags, oflags);	}	dip->di_oflags = oflags;	if (dip->di_ftype == INPUT_FILE) {	    dip->di_fd = open (file, oflags);	} else {	    dip->di_fd = open (file, oflags, 0666);	}	if (dip->di_fd < 0) {            char fmt[STRING_BUFFER_SIZE];#if defined(EEI)	    if ( (errno == EIO) && eei_resets &&		 (dip->di_dtype &&		  (dip->di_dtype->dt_dtype == DT_TAPE)) ) {		if (--open_retries) {		    if (verbose_flag) {			Printf("Warning, ignoring open error and retrying...\n");		    }		    goto retry;		}	    }#endif /* defined(EEI) */	    (void)sprintf(fmt, "open -> %s", file);	    report_error (fmt, TRUE);	    status = FAILURE;	}    }    end_of_file = FALSE;    dip->di_end_of_file = FALSE;    dip->di_end_of_media = FALSE;    dip->di_end_of_logical = FALSE;    if ( (status != FAILURE) && debug_flag) {	Printf ("%s file '%s' successfully opened, fd = %d\n",		(dip->di_ftype == INPUT_FILE) ? "Input" : "Output",						file, dip->di_fd);    }    return (status);}/************************************************************************ *									* * close_file() - Close an open file descriptor.			* *									* * Description:								* *	This function does the default (generic) close processing.	* *									* * Inputs:	dip = The device information pointer.			* *									* * Return Value:							* *		Returns 0 / -1 = SUCCESS / FAILURE.			* *									* ************************************************************************/intclose_file (struct dinfo *dip){    char *file = dip->di_dname;    int status = SUCCESS;    if (dip->di_closing || (dip->di_fd == NoFd)) {	return (status);		/* Closing or not open. */    }    dip->di_closing = TRUE;    if (cdelay_count) {			/* Optional close delay	*/	mySleep (cdelay_count);    }    if (debug_flag) {	Printf ("Closing file '%s', fd = %d...\n", file, dip->di_fd);    }    if ((status = close (dip->di_fd)) == FAILURE) {	if (cerrors_flag) {	    report_error ("close", TRUE);	} else if (verbose_flag) {	    status = SUCCESS;	    Printf("Warning, close failed, errno = %d - %s\n",					errno, strerror(errno));	    Printf("Warning, ignoring close failure and continuing...\n");	}#if defined(EEI)	if ( (errno == EIO) && eei_resets &&	     (dip->di_dtype->dt_dtype == DT_TAPE) ) {	    if (dip->di_proc_eei) {		if (verbose_flag) {		    Printf("Warning, ignoring close failure and continuing...\n");		}		error_count--;		status = SUCCESS;	    }	    /* No retries, we're already closed! */	}#endif /* defined(EEI) */    }    dip->di_fd = NoFd;    dip->di_closing = FALSE;    return (status);}/************************************************************************ *									* * reopen_file() - Close and reopen file descriptor.			* *									* * Inputs:	dip = The device information pointer.			* *		oflags = The device/file open flags.			* *									* * Return Value:							* *		Returns 0 / -1 = SUCCESS / FAILURE.			* *									* ************************************************************************/intreopen_file (struct dinfo *dip, int oflags){    struct dtfuncs *dtf = dip->di_funcs;    char *file = dip->di_dname;    int status = SUCCESS;#if defined(EEI)    int open_retries = EEI_OPEN_RETRIES;#endif    /*     * For stdin or stdout, do not attempt close/open.     */    if ( (strlen(file) == 1) && (*file == '-') ) return (status);    /*     * For tape, we must close & reopen to get to BOT,     * an lseek() won't do the trick.     */    if (dip->di_fd != NoFd) {		/* If not already closed... */	status = (*dtf->tf_close)(dip);    }    if (edelay_count) {			/* Optional end delay. 	*/	mySleep (edelay_count);    }    end_of_file = FALSE;    dip->di_end_of_file = FALSE;    dip->di_end_of_media = FALSE;    dip->di_end_of_logical = FALSE;#if defined(__WIN32__)    oflags |= O_BINARY;#endif /* defined(__WIN32__) */#if defined(EEI)retry:#endif    if (debug_flag) {	Printf ("Attempting to reopen file '%s', open flags = %#o (%#x)...\n",							file, oflags, oflags);    }    dip->di_oflags = oflags;    if ( (dip->di_fd = open (file, oflags)) == FAILURE) {#if defined(EEI)	if ( (dip->di_dtype->dt_dtype == DT_TAPE) &&	     (errno == EIO) && eei_resets) {	    if (--open_retries) {		if (verbose_flag) {		    Printf("Warning, ignoring open error and retrying...\n");		}		goto retry;	    }	}#endif /* defined(EEI) */	report_error ("reopen", TRUE);	return (FAILURE);    }    if (debug_flag) {	Printf ("File '%s' successfully reopened, fd = %d\n",

⌨️ 快捷键说明

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