📄 dtinfo.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: dtinfo.c * Author: Robin T. Miller * Date: September 8, 1993 * * Description: * Setup device and/or system information for 'dt' program. */#include "dt.h"#if !defined(_QNX_SOURCE)# if !defined(sun)# include <sys/ioctl.h># endif /* !defined(sun) */#endif /* !defined(_QNX_SOURCE) */#include <sys/stat.h>/* * Modification History: * * March 30th, 2004 by Robin Miller. * Add os_system_device_info() for Linux to try to obtain the * sector size and partition capacity. If this can be obtained for * random I/O, then do_random() can be avoided, which is a good thing * since it's broken in 2.4 kernels (can't lseek past end of partition). * * February 27th, 2003 by Robin Miller. * A little more tweaking of the fsync() flag... only enable * fsync for block or regular file, not for character (raw) disks. * * December 5th, 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. * * June 9th, 2003 by Robin Miller. * Fix problem setting fsync_flag when dtype=disk/block/regular * is specified (should do fsync() after writes, but it is *not*). * * March 13th, 2003 by Robin Miller. * Add support for DIOC_DESCRIBE IOCTL to determine device type, * capacity, and block size. * * March 16th, 2002 by Robin Miller. * In dec_system_device_info() open device with O_NDELAY, incase * this is a tape device, we don't want a looong delay during the open. * * October 4th, 2001 by Robin Miller. * Fix problem with idtype/odtype options were being overridden by * dec_system_device_info(). Assume the user is right :-) * * August 31st, 2001 by Robin Miller. * Add casts to values being used to calculate user capacity, which * is in bytes (64 bits), to ensure 32-bit truncation does not occur. * * June 2nd, 2001 by Robin Miller. * After setting up a "regular" device type, ensure the device * defaults also get setup. Was not setting min/max/incr defaults. * * April 13th, 2001 by Robin Miller. * Removed old PTOS conditionalization (Tru64 Unix V4.0+ only now). * If supported, use DEVGETINFO instead of DEVIOCGET for longer * device names, and more information. If max_capacity, set by the user * or random I/O and partition 'c' selected, set max capacity returned * from the device driver. For random I/O, prevents lseek/read logic. * * April 12th, 2001 by Robin Miller. * Delay setting device defaults, until later in setup_device_info(). * When random I/O is selected, setup device values for a disk device. * * April 11th, 2001 by Robin Miller. * For Tru64 Unix, if the user specified a device type, don't ovrride * it by calling dec_system_device_info(). If the user selected random I/O * options, enable random access mode. Hey, the worse that can happen is * they'll get an lseek() error! This handles special disk devices (LSM). * * February 6th, 2001 by Robin Miller. * For Cygnus, map //./ and \\.\ directory prefixes to /dev. This * is how physical (raw) devices *must* be mounted to work properly. * If physical devices aren't mounted, Unix style EOM isn't emulated! * Ensure same processing is performed on existing files and newly * created files. This includes setting the fsync flag appropriately, * and setting up the user capacity for random I/O as necessary. * * February 1st, 2001 by Robin Miller. * Make changes to allow multiple slices to an existing file. * * January 28th, 2001 by Robin Miller. * Allow dec_system_device_info() to be called prior to the file * being opened. We need device info early on for new slices option. * * January 25th, 2001 by Robin Miller. * Flag disk devices, via di_random_access boolean flag. This * includes regular files, so seek and report functions work on them. * * January 24th, 2001 by Robin Miller. * Setup the default device block size from device_size variable, * so the user can override this using the "dsize=value" option. Also, * various functions no longer have to check for this field being zero, * so perhaps this will help performance too. * * January 2nd, 2001 by Robin Miller. * Make changes to build using MKS/NuTCracker product. * * August 22nd, 2000 by Robin Miller. * Update setup_device_defaults() to better set incr and min values, * since this function may get called twice on Tru64 Unix systems. * * July 14th, 2000 by Robin Miller. * Added logic to set file sync flag, if a block device or regular * file is used. Tapes, FIFO's, and other devices do NOT like fsync()! * * April 2nd, 2000 by Robin Miller. * Only set the random data limit when stat'ing the file, * if it's a regular file, since the st_size might not be bytes. * On QNX, st_size is the drive capacity, so setup user_capacity * to avoid seek/read algorithm in FindCapacity() for random I/O. * * August 1, 1999 by Robin Miller. * Do a better job in setup_device_defaults() setting up the * defaults for min and increment counts. For disks, this value * needs to be modulo the block size, since most disk drivers do * not permit non-modulo requests (Tru64 UNIX CAM is exception). * * December 21, 1998 by Robin Miller. * - for DUNIX, allocate mtget structure for tapes. * - changes for Malloc(), which now clears memory. * * December 19, 1998 by Robin Miller. * For Steel DUNIX, strip trailing spaces from device names. * * 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). * * April 29, 1998 by Robin Miller. * Add support for an alternate device directory. * * October 31, 1993 by Robin Miller. * Enhance device type setup and honor user specified device type. * * October 29, 1993 by Robin Miller. * Added more checks in setup_device_type() to determine detect * selection of terminal devices (e.g., console device). * * September 15, 1993 by Robin Miller. * Added stat() of file specified to check for FIFO's and set the * device type appropriately so other checks could be done prior * to opening the device (O_NONBLOCK needs set before open()). * *//* * Forward References: */static void setup_device_defaults(struct dinfo *dip);static void SetupRegularFile(struct dinfo *dip, struct stat *sbp);#if defined(__MSDOS__) || defined(__WIN32__) || defined(_NT_SOURCE)static bool IsDriveLetter(char *bufptr);#endif /* defined(__MSDOS__) || defined(__WIN32__) || defined(_NT_SOURCE) */#if defined(ultrix) || defined(DEC)static int SetupDiskAttributes(struct dinfo *dip, int fd);#endif /* defined(ultrix) || defined(DEC) *//************************************************************************ * * * setup_device_type() - Setup the device type. * * * * Description: * * This function sets up the specific device type to be tested. * * Since each operating system has a different method of identifying * * devices, so this table lookup allows the user to specify the device * * type. Of course, this could be used to force errors. * * * * Inputs: str = Pointer to device type string. * * * * Return Value: * * Returns pointer to device type table entry or NULL. * * * ************************************************************************/struct dtype dtype_table[] = { { "audio", DT_AUDIO }, { "block", DT_BLOCK }, { "character", DT_CHARACTER }, { "comm", DT_COMM }, { "disk", DT_DISK }, { "graphics", DT_GRAPHICS }, { "memory", DT_MEMORY }, { "mmap", DT_MMAP }, { "mouse", DT_MOUSE }, { "network", DT_NETWORK }, { "fifo", DT_FIFO }, { "pipe", DT_PIPE }, { "printer", DT_PRINTER }, { "processor", DT_PROCESSOR }, { "regular", DT_REGULAR }, { "socket", DT_SOCKET }, { "special", DT_SPECIAL }, { "streams", DT_STREAMS }, { "tape", DT_TAPE }, { "terminal", DT_TERMINAL }, { "unknown", DT_UNKNOWN }};int num_dtypes = sizeof(dtype_table) / sizeof(dtype_table[0]);struct dtype *setup_device_type (char *str){ int i; struct dtype *dtp; for (dtp = dtype_table, i = 0; i < num_dtypes; i++, dtp++) { if (strcmp(str, dtp->dt_type) == 0) { return (dtp); } } fprintf (efp, "Device type '%s' is invalid, valid entrys are:\n", str); for (dtp = dtype_table, i = 0; i < num_dtypes; i++, dtp++) { if ( (i % 4) == 0) fprintf (efp, "\n"); fprintf (efp, " %-12s", dtp->dt_type); } fprintf (efp, "\n"); return ((struct dtype *) 0);}/************************************************************************ * * * setup_device_defaults() - Setup the device defaults. * * * * Description: * * This function sets up the specific device type defaults, for * * test parameters which were not specified. * * * * Inputs: dip = The device information pointer. * * * * Return Value: * * Returns pointer to device type table entry or NULL. * * * * Note: This function may get called twice! On Tru64 Unix, after we * * open the device, the initial device type may get overridden. * * * ************************************************************************/static voidsetup_device_defaults (struct dinfo *dip){ struct dtype *dtp = dip->di_dtype; if ( (dtp->dt_dtype == DT_BLOCK) || (dtp->dt_dtype == DT_DISK) || (dtp->dt_dtype == DT_REGULAR) || dip->di_random_io ) { /* * Real device size should already been obtained. */ if (!device_size) device_size = BLOCK_SIZE; if (!lbdata_size) lbdata_size = device_size; if (max_size && !user_min) min_size = device_size; if (min_size && !user_incr) incr_count = device_size; /* Ensure min and incr values are non-zero! */ if (max_size && !min_size) min_size = device_size; if (min_size && !incr_count) incr_count = device_size; if (dip->di_random_io) { if (!random_align) random_align = device_size; } if (fsync_flag == UNINITIALIZED) { if ( (dtp->dt_dtype == DT_BLOCK) || (dtp->dt_dtype == DT_REGULAR) ) { fsync_flag = TRUE; } else if ( (dtp->dt_dtype == DT_DISK) ) /* * Devices identified as DT_DISK should be the * raw (character) device. Since some OS's, * such as AIX don't like fsync() to disks, * we'll disable it since it really only has * meaning to block or regular (FS) files. */ fsync_flag = FALSE; } } else { if (!device_size) device_size = 1; if (max_size && !user_min) min_size = 1; if (min_size && !user_incr) incr_count = 1; /* Ensure min and incr values are non-zero! */ if (max_size && !min_size) min_size = 1; if (min_size && !incr_count) incr_count = 1; } return;}/************************************************************************ * * * os_system_device_info() - Get OS System Device Information. * * * * Description: * * This function attempts to obtain device information necessary * * for device specific testing, by using system dependent syscalls. * * Note: This function is called _after_ the device/file is opened. * * * * Inputs: dip = The device information pointer. * * * * Return Value: * * None. * * * ************************************************************************/#if defined(ultrix) || defined(DEC)#include <sys/devio.h>#include <sys/ioctl.h>#if defined(DEC)# include <sys/ioctl_compat.h>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -