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

📄 dtinfo.c

📁 Linux磁盘测试的源代码,测试磁盘的读写性能
💻 C
📖 第 1 页 / 共 3 页
字号:
	    case SCSI_DIRECT_ACCESS:	    case SCSI_WORM:	    case SCSI_CDROM:	    case SCSI_MO:		dip->di_dtype = setup_device_type("disk");		break;	    case SCSI_SEQUENTIAL_ACCESS:		dip->di_dtype = setup_device_type("tape");		break;	    default:		break;	}    }    if (temp_fd) (void)close(fd);    return;}#endif /* defined(HP_UX) */#if defined(__linux__)/* Ugly stuff to avoid conflict with Linux BLOCK_SIZE definition. */#undef BLOCK_SIZE#include <linux/fs.h>#undef BLOCK_SIZE#define BLOCK_SIZE 512voidos_system_device_info (struct dinfo *dip){    int fd = dip->di_fd;    bool temp_fd = FALSE;    unsigned long nr_sects;    int sect_size;    if (fd == NoFd) {	temp_fd = TRUE;	if ( (fd = open (dip->di_dname, (O_RDONLY | O_NDELAY))) < 0) {	    return;	}    }    /*     * Try to obtain the sector size.     */    if (ioctl (fd, BLKSSZGET, &sect_size) == SUCCESS) {        dip->di_dsize = sect_size;        if (debug_flag) {            Printf("BLKSSZGET Sector Size: %d bytes\n", sect_size);        }    }    /*     * If this IOCTL succeeds, we will assume it's a disk device.     *     * Note: The size returned is for the partition (thank-you!).     */    if (ioctl (fd, BLKGETSIZE, &nr_sects) == SUCCESS) {        if (!dip->di_dsize) dip->di_dsize = BLOCK_SIZE;        /*	 * Only setup capacity for random I/O, since we want to test	 * end of file conditions on sequential reads and writes.	 */	if (dip->di_random_io || num_slices) {	    if ( !max_capacity && !user_capacity ) {		max_capacity = TRUE;		dip->di_capacity = nr_sects;		user_capacity = (dip->di_capacity * (large_t)dip->di_dsize);		if (debug_flag) {		    Printf("BLKGETSIZE Capacity: " LUF " blocks (%u byte blocks).\n",					dip->di_capacity, dip->di_dsize);		}	    }        }    }    if (temp_fd) (void)close(fd);    return;}#endif /* defined(__linux__) *//* * Note: This function called after the device is opened! */voidsystem_device_info (struct dinfo *dip){    if (dip->di_dtype == NULL) {	struct stat sb;	/*	 * For regular files, set the fsync flag to flush writes.	 * Note: This handles processing of *new* output files.	 */	if ( (fstat (dip->di_fd, &sb) == SUCCESS) &&	     ( S_ISREG(sb.st_mode) ) ) {	    SetupRegularFile (dip, &sb);	} else {	    dip->di_dtype = setup_device_type("unknown");	}    }    if (fsync_flag == UNINITIALIZED) { fsync_flag = FALSE; }    return;}/************************************************************************ *									* * setup_device_info() - Setup Initial Device Information.		* *									* * Description:								* *	This function allocates a device information entry, and does	* * the initial setup of certain information based on known options.	* * This function is meant to be called prior to opening the device so	* * test specific functions are known for initial processing.		* *									* * Inputs:	dname = The device name.				* *									* * Return Value:							* *		Returns pointer to device information entry.		* *									* ************************************************************************/struct dinfo *setup_device_info (char *dname, struct dtype *dtp){    struct dinfo *dip;    struct stat sb;    dip = (struct dinfo *) Malloc (sizeof(*dip));    dip->di_fd = NoFd;    dip->di_dname = dname;    dip->di_funcs = &generic_funcs;    if ( (io_dir == REVERSE) || (io_type == RANDOM_IO) ) {	dip->di_random_io = TRUE;    }#if defined(AIO)    if (aio_flag) {	dip->di_funcs = &aio_funcs;    }#endif /* defined(AIO) */#if defined(MMAP)    if (mmap_flag) {	dip->di_funcs = &mmap_funcs;	dtp = setup_device_type("mmap");    }#endif /* defined(MMAP) */#if defined(ultrix) || defined(DEC) || defined(HP_UX) || defined(__linux__)    /*     * Must do this early on, to set device type and size.     */    if (dtp == NULL) {	os_system_device_info (dip);	dtp = dip->di_dtype;    }#endif /* defined(ultrix) || defined(DEC) || defined(HP_UX) || defined(__linux__) */    /*     * If user specified a device type, don't override it.     */    if (dtp == NULL) {	/*	 * Determine test functions based on device name.	 */	if ( (EQL (dname, DEV_PREFIX, DEV_LEN))   ||	     (EQL (dname, ADEV_PREFIX, ADEV_LEN)) ||	     (EQL (dname, NDEV_PREFIX, NDEV_LEN)) ) {	    char *dentry;	    if (EQL (dname, DEV_PREFIX, DEV_LEN)) {		dentry = (dname + DEV_LEN);	    } else if (EQL (dname, ADEV_PREFIX, ADEV_LEN)) {		dentry = (dname + ADEV_LEN);	    } else {		dentry = (dname + NDEV_LEN);	    }#if defined(__CYGWIN__)	/*	 * Map //./ or \\.\ to /dev/ prefix for Cygnus raw mounts.	 */	{   if (NEL (dname, DEV_PREFIX, DEV_LEN)) {		char *cygnus_dname = Malloc(strlen(dname)+1);		(void)strcpy(cygnus_dname, DEV_PREFIX);		(void)strcat(cygnus_dname, dentry);		dip->di_dname = cygnus_dname;	    }	}#endif /* defined(__CYGWIN__) */	    if ( (ttyport_flag == TRUE) ||		 (EQL (dentry, TTY_NAME, TTY_LEN)) ||		 (EQL (dentry, CONSOLE_NAME, CONSOLE_LEN)) ) {		dtp = setup_device_type("terminal");	    } else if ( (EQL (dentry, TAPE_NAME, sizeof(TAPE_NAME)-1)) ||			(EQL (dentry, NTAPE_NAME, sizeof(NTAPE_NAME)-1)) ) {		dtp = setup_device_type("tape");	    } else if ( (EQL (dentry, DISK_NAME, sizeof(DISK_NAME)-1)) ||			(EQL (dentry, RDISK_NAME, sizeof(RDISK_NAME)-1)) ) {		dtp = setup_device_type("disk");	    } else if ( (EQL (dentry, CDROM_NAME, sizeof(CDROM_NAME)-1)) ||			(EQL (dentry, RCDROM_NAME, sizeof(RCDROM_NAME)-1)) ) {		dtp = setup_device_type("disk");	    }#if defined(__MSDOS__) || defined(__WIN32__) || defined(_NT_SOURCE)	    if ( (dtp == NULL) && (IsDriveLetter (dentry)) ) {		dtp = setup_device_type("block");	    }#endif /* defined(__MSDOS__) || defined(__WIN32__) || defined(_NT_SOURCE) */	}#if defined(FIFO)	if ( (dtp == NULL) &&	     (stat (dname, &sb) == SUCCESS) ) {	    if ( S_ISFIFO(sb.st_mode) ) {		verify_flag = FALSE;		dip->di_funcs = &fifo_funcs;		dtp = setup_device_type("fifo");	    }	}#endif /* defined(FIFO) */	if ( (dtp == NULL) &&	     (strlen(dname) == 1) && (*dname == '-') ) {	    dtp = setup_device_type("pipe");	}	if ( (dtp == NULL) &&	     (stat (dname, &sb) == SUCCESS)) {	    if ( S_ISBLK(sb.st_mode) ) {		dtp = setup_device_type("block");		if (fsync_flag == UNINITIALIZED) {		     fsync_flag = TRUE;		}	    } else if ( S_ISCHR(sb.st_mode) ) {		/*		 * Character devices are NOT treated as disks!		 */#if defined(ultrix) || defined(DEC)		if (SetupDiskAttributes(dip, dip->di_fd) != SUCCESS)#endif		    dtp = setup_device_type("character");	    }	}    } /* if (dtp == NULL) */    /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */    /* End of device type setup.  Special setup follows. */    /* - - - - - - - - - - - - - - - - - - - - - - - - - */    /*     * Do special setup for certain device types.     */    if (dip->di_dtype = dtp) {#if defined(TTY)	if (dtp->dt_dtype == DT_TERMINAL) {	    ttyport_flag = TRUE;		/* this should go away... */	    dip->di_funcs = &tty_funcs;	} else #endif /* defined(TTY) */            if ( (dtp->dt_dtype == DT_BLOCK) ||		    (dtp->dt_dtype == DT_DISK)  || dip->di_random_io ) {	    dip->di_random_access = TRUE;	}	setup_device_defaults (dip);    }    /*     * If the device size isn't set, then set it to our default.     *     * Note: This size is used for finding disk capacity, random I/O,     *	 variable requests, and reporting failing relative block.     */    if ( !dip->di_dsize ) {	if (!device_size) {	    device_size = BLOCK_SIZE;	}	dip->di_dsize = device_size;    }    /*     * Note: This handles *existing* input/output files.     */    if (stat (dname, &sb) == SUCCESS) {	if ( S_ISREG(sb.st_mode) ) {	    SetupRegularFile (dip, &sb);	    if ( (dispose_mode == DELETE_FILE) && keep_existing && !num_procs) {		dispose_mode = KEEP_FILE;	/* Keep existing files! */	    }	}#if defined(_QNX_SOURCE)	else if ( S_ISBLK(sb.st_mode) ) {	    user_capacity = ((large_t)sb.st_size * (large_t)dip->di_dsize);	}#endif /* defined(_QNX_SOURCE) */    }    return (dip);}static voidSetupRegularFile (struct dinfo *dip, struct stat *sbp){    /*     * If random I/O was selected, and a data or record limit was     * not specified (i.e. runtime=n), then setup the file size.     * This is necessary to limit random I/O within file size, or     * for newly created files setup capacity based on data limit.     */    if ( (dip->di_random_io || num_slices) &&	 (rdata_limit == (large_t)0) && !user_capacity) {	if (sbp->st_size) {	    user_capacity = (large_t) sbp->st_size;	} else if (data_limit != INFINITY) {	    user_capacity = data_limit;	}    }    if (fsync_flag == UNINITIALIZED) {	fsync_flag = TRUE;	/* Only has meaning when writing. */    }    dip->di_random_access = TRUE;    dip->di_dtype = setup_device_type("regular");    setup_device_defaults (dip);}#if defined(__MSDOS__) || defined(__WIN32__) || defined(_NT_SOURCE)static boolIsDriveLetter(char *bufptr){    /* Check for drive letters "[a-zA-Z]:" */    if ((strlen(bufptr) == 2) && (bufptr[1] == ':') &&	((bufptr[0] >= 'a') && (bufptr[0] <= 'z') ||	 (bufptr[0] >= 'A') && (bufptr[0] <= 'Z'))) {	return (TRUE);    }    return (FALSE);}#endif /* defined(__MSDOS__) || defined(__WIN32__) || defined(_NT_SOURCE) */

⌨️ 快捷键说明

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