📄 dtinfo.c
字号:
# include <io/common/devgetinfo.h>#endif /* defined(DEC) */voidos_system_device_info (struct dinfo *dip){ struct devget devget, *devgp = NULL; device_info_t devinfo, *devip = NULL; int fd = dip->di_fd; bool temp_fd = FALSE; short category; int i, status; if (fd == NoFd) { temp_fd = TRUE; if ( (fd = open (dip->di_dname, (O_RDONLY | O_NDELAY))) < 0) { return; } } /* * Attempt to obtain the device information. */ bzero ((char *) &devinfo, sizeof(devinfo)); if (ioctl (fd, DEVGETINFO, (char *) &devinfo) == SUCCESS) { devip = &devinfo; category = devip->v1.category; if ( NEL (devip->v1.device, DEV_UNKNOWN, DEV_STRING_SIZE) ) { dip->di_device = Malloc(DEV_STRING_SIZE + 1); (void) strncpy (dip->di_device, devip->v1.device, DEV_STRING_SIZE); } else if ( NEL (devip->v1.dev_name, DEV_UNKNOWN, DEV_STRING_SIZE) ) { dip->di_device = Malloc(DEV_STRING_SIZE + 1); (void) strncpy (dip->di_device, devip->v1.dev_name, DEV_STRING_SIZE); } if (dip->di_device) { /* * In Steel, device names have trailing spaces. grrr! */ for (i = (DEV_STRING_SIZE); i--; ) { if ( isspace(dip->di_device[i]) ) { dip->di_device[i] = '\0'; } else { break; } } } } else { /* Try the old DEVIOCGET IOCTL... */ (void) bzero ((char *) &devget, sizeof(devget)); if (ioctl (fd, DEVIOCGET, (char *) &devget) < 0) { if (temp_fd) (void)close(fd); return; } devgp = &devget; category = devgp->category; if ( NEL (devgp->device, DEV_UNKNOWN, DEV_SIZE) ) { dip->di_device = Malloc(DEV_SIZE + 1); (void) strncpy (dip->di_device, devgp->device, DEV_SIZE); } else if ( NEL (devgp->dev_name, DEV_UNKNOWN, DEV_SIZE) ) { dip->di_device = Malloc(DEV_SIZE + 1); (void) strncpy (dip->di_device, devgp->dev_name, DEV_SIZE); } if (dip->di_device) { /* * In Steel, device names have trailing spaces. grrr! */ for (i = (DEV_SIZE); i--; ) { if ( isspace(dip->di_device[i]) ) { dip->di_device[i] = '\0'; } else { break; } } } } /* * Setup the device type based on the category. */ switch (category) { case DEV_TAPE: /* Tape category. */ dip->di_dtype = setup_device_type("tape");#if defined(EEI) dip->di_mt = Malloc(sizeof(*dip->di_mt)); if (eei_flag) clear_eei_status(fd, TRUE); dip->di_eei_sleep = EEI_SLEEP; dip->di_eei_retries = EEI_RETRIES;#endif /* defined(EEI) */ break; case DEV_DISK: { /* Disk category. */ /* * If using partition 'c', setup to use the whole capacity. * * Note: Only setup maximum capacity for random I/O, or else * we will inhibit End of Media (EOM) testing. */ if (dip->di_random_io || num_slices) { if (dip->di_dname[strlen(dip->di_dname)-1] == 'c') { if ( !max_capacity && !user_capacity ) { max_capacity = TRUE; } } } /**************************************************************** * Attempt to get disk attributes using DEVGETINFO first, since * * for SCSI disks we get more information, which we plan to use * * one day, and we also get the real block (sector) size. * ****************************************************************/ if (devip && (devip->version == VERSION_1) ) { v1_disk_dev_info_t *diskinfo; diskinfo = &devip->v1.devinfo.disk; dip->di_dsize = diskinfo->blocksz; if (!device_size) device_size = dip->di_dsize; /* * NOTE: capacity is whole disk, not the open partition, * so we don't use it unless selected by the user. */ if (max_capacity) { dip->di_capacity = diskinfo->capacity; user_capacity = (dip->di_capacity * (large_t)dip->di_dsize); if (debug_flag) { Printf("DEVGETINFO Capacity: " LUF " blocks.\n", dip->di_capacity); } } if (dip->di_dsize && !user_lbsize && !lbdata_size) { lbdata_size = dip->di_dsize; } } else { (void)SetupDiskAttributes(dip, fd); } dip->di_dtype = setup_device_type("disk"); /* * TODO: Need to read disklabel to pickup partition sizes, * and to check for mounted file systems. More work! */ break; } case DEV_TERMINAL: /* Terminal category. */ dip->di_dtype = setup_device_type("terminal"); break; case DEV_PRINTER: /* Printer category. */ dip->di_dtype = setup_device_type("printer"); break; case DEV_SPECIAL: /* Special category. */ /* * On Tru64 Unix, LSM volumes are really disks! */ if (SetupDiskAttributes(dip, fd) != SUCCESS) { dip->di_dtype = setup_device_type("special"); } break; default: break; } if (temp_fd) (void)close(fd); return;}/* * SetupDiskAttributes() - Setup Disk Attributes using DEVGETGEOM. * * Description: * This function is used for disk devices which don't support * the newer DEVGETINFO IOCTL, like LSM devices. * * Inputs: * dip = The device information pointer. * fd = The file descriptor (NoFd == Not open). * * Outputs: * Returns 0 or -1 for Success/Failure. */static intSetupDiskAttributes (struct dinfo *dip, int fd){ int status; bool temp_fd = FALSE; DEVGEOMST devgeom; if (fd == NoFd) { temp_fd = TRUE; if ( (fd = open (dip->di_dname, O_RDONLY)) < 0) { return (FAILURE); } } /* * If using partition 'c', setup to use the whole capacity. * * Note: Only setup maximum capacity for random I/O, or else * we will inhibit End of Media (EOM) testing. */ if (dip->di_random_io || num_slices) { if ( (dip->di_device && EQ(dip->di_device,"LSM")) || (dip->di_dname[strlen(dip->di_dname)-1] == 'c') ) { if ( !max_capacity && !user_capacity ) { max_capacity = TRUE; } } } /* * Attempt to obtain the disk geometry. Works for LSM, etc. * * NOTE: DEVGETGEOM *fails* on read-only devices (shit!). */ bzero ((char *) &devgeom, sizeof(devgeom)); if ((status = ioctl (fd, DEVGETGEOM, (char *) &devgeom)) == SUCCESS) { dip->di_dsize = devgeom.geom_info.sector_size; if (!device_size) device_size = dip->di_dsize; /* * NOTE: dev_size is whole disk, not the open partition, * so we don't use it unless selected by the user. */ if (max_capacity) { dip->di_capacity = devgeom.geom_info.dev_size; user_capacity = (dip->di_capacity * (large_t)dip->di_dsize); if (debug_flag) { Printf("DEVGETGEOM Capacity: " LUF " blocks.\n", dip->di_capacity); } } if (dip->di_dsize && !user_lbsize && !lbdata_size) { lbdata_size = dip->di_dsize; } dip->di_dtype = setup_device_type("disk"); } /* * TODO: Need to read disklabel to pickup partition sizes, * and to check for mounted file systems. More work! */ if (temp_fd) (void)close(fd); return (status);}#endif /* defined(ultrix) || defined(DEC) */#if defined(HP_UX)#include <sys/diskio.h>#include <sys/scsi.h>voidos_system_device_info (struct dinfo *dip){ disk_describe_type disk_type, *disktp = &disk_type; union inquiry_data inquiry; int fd = dip->di_fd; bool temp_fd = FALSE; short category; int i; if (fd == NoFd) { temp_fd = TRUE; if ( (fd = open (dip->di_dname, (O_RDONLY | O_NDELAY))) < 0) { return; } } /* * Attempt to obtain the device information. */ bzero ((char *) disktp, sizeof(*disktp)); if (ioctl (fd, DIOC_DESCRIBE, disktp) == SUCCESS) { if (disktp->dev_type != UNKNOWN_DEV_TYPE) { size_t size = sizeof(disktp->model_num); dip->di_device = Malloc(size + 1); (void) strncpy (dip->di_device, disktp->model_num, size); /* * Strip trailing spaces from the device name. */ for (i = size; i--; ) { if ( isspace(dip->di_device[i]) ) { dip->di_device[i] = '\0'; } else { break; } } dip->di_dsize = disktp->lgblksz; /* * 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 = (disktp->maxsva + 1); user_capacity = (dip->di_capacity * (large_t)dip->di_dsize); if (debug_flag) { Printf("DIOC_DESCRIBE Capacity: " LUF " blocks (%u byte blocks).\n", dip->di_capacity, dip->di_dsize); } } } } switch (disktp->dev_type) { case CDROM_DEV_TYPE: /* CDROM device */ case DISK_DEV_TYPE: /* Disk device */ case WORM_DEV_TYPE: /* Write once read many optical device */ case MO_DEV_TYPE: /* Magneto Optical device */ dip->di_dtype = setup_device_type("disk"); break; case CTD_DEV_TYPE: /* Cartridge tape device */ dip->di_dtype = setup_device_type("tape"); break; default: break; } } else if (ioctl (fd, SIOC_INQUIRY, &inquiry) == SUCCESS) { struct inquiry_2 *inq = (struct inquiry_2 *)&inquiry; size_t size = sizeof(inq->product_id); if (debug_flag) { Printf("SIOC_INQUIRY device type %u\n", inq->dev_type); } dip->di_device = Malloc(size + 1); (void) strncpy (dip->di_device, inq->product_id, size); for (i = size; i--; ) { if ( isspace(dip->di_device[i]) ) { dip->di_device[i] = '\0'; } else { break; } } switch (inq->dev_type) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -