Esempio n. 1
0
int
Get_Next_HR_Disk (void)
{
    char string[100];
    int fd, result;
    int index;
    int max_disks;
    time_t now;

    HRD_index++;
    (void*) time( &now );
    while ( HRD_type_index < HR_number_disk_types ) {
	max_disks = disk_device_last[    HRD_type_index ] -
		    disk_device_id[      HRD_type_index ] +1;

	while ( HRD_index < max_disks ) {
	    index = (HRD_type_index << HRDISK_TYPE_SHIFT) + HRD_index;

			/*
			 * Check to see whether this device
			 *   has been probed for 'recently'
			 *   and skip if so.
			 * This has a *major* impact on run
			 *   times (by a factor of 10!)
			 */
	    if (( HRD_history[ index ] != 0 ) &&
		(( now - HRD_history[ index ]) < 60 ))
	    {
			HRD_index++;
			continue;
	    }

		/* Construct the device name in "string" */
	    sprintf(string, disk_device_strings[ HRD_type_index ], 
			    disk_device_id[      HRD_type_index ] + HRD_index,
			    disk_device_full[    HRD_type_index ] );

	    DEBUGMSGTL(("host/hr_disk", "Get_Next_HR_Disk: %s (%d/%d)\n",
                        string, HRD_type_index, HRD_index ));
	
	    fd = open( string, O_RDONLY  );
	    if (fd != -1 ) {
		result = Query_Disk( fd );
		close(fd);
		if ( result != -1 ) {
		    HRD_history[ index ] = 0;
		    return ((HRDEV_DISK << HRDEV_TYPE_SHIFT) + index );
		}
	    }
	    HRD_history[ index ] = now;
	    HRD_index++;
	}
	HRD_type_index++;
	HRD_index = 0;
    }
    HRD_index = -1;
    return -1;
}
Esempio n. 2
0
int
Get_Next_HR_Disk(void)
{
    char            string[1024];
    int             fd, result;
    int             iindex;
    int             max_disks;
    time_t          now;

    HRD_index++;
    (void *) time(&now);
    DEBUGMSGTL(("host/hr_disk", "Next_Disk type %d of %d\n",
                HRD_type_index, HR_number_disk_types));
    while (HRD_type_index < HR_number_disk_types) {
        max_disks = disk_devices[HRD_type_index].disk_device_last -
            disk_devices[HRD_type_index].disk_device_first + 1;
        DEBUGMSGTL(("host/hr_disk", "Next_Disk max %d of type %d\n",
                    max_disks, HRD_type_index));

        while (HRD_index < max_disks) {
            iindex = (HRD_type_index << HRDISK_TYPE_SHIFT) + HRD_index;

            /*
             * Check to see whether this device
             *   has been probed for 'recently'
             *   and skip if so.
             * This has a *major* impact on run
             *   times (by a factor of 10!)
             */
            if ((HRD_history[iindex] > 0) &&
                ((now - HRD_history[iindex]) < 60)) {
                HRD_index++;
                continue;
            }

            /*
             * Construct the full device name in "string" 
             */
            if (disk_devices[HRD_type_index].disk_controller != -1) {
                snprintf(string, sizeof(string),
                        disk_devices[HRD_type_index].disk_devfull_string,
                        disk_devices[HRD_type_index].disk_controller,
                        disk_devices[HRD_type_index].disk_device_first +
                        HRD_index);
            } else {
                snprintf(string, sizeof(string),
                        disk_devices[HRD_type_index].disk_devfull_string,
                        disk_devices[HRD_type_index].disk_device_first +
                        HRD_index);
            }
            string[ sizeof(string)-1 ] = 0;

            DEBUGMSGTL(("host/hr_disk", "Get_Next_HR_Disk: %s (%d/%d)\n",
                        string, HRD_type_index, HRD_index));

            if (HRD_history[iindex] == -1) {
                /*
                 * check whether this device is in the "ignoredisk" list in
                 * the config file. if yes this device will be marked as
                 * invalid for the future, i.e. it won't ever be checked
                 * again.
                 */
                if (match_disk_config(string)) {
                    /*
                     * device name matches entry in ignoredisk list 
                     */
                    DEBUGMSGTL(("host/hr_disk",
                                "Get_Next_HR_Disk: %s ignored\n", string));
                    HRD_history[iindex] = LONG_MAX;
                    HRD_index++;
                    continue;
                }
            }

            /*
             * use O_NDELAY to avoid CDROM spin-up and media detection
             * * (too slow) --okir 
             */
            /*
             * at least with HP-UX 11.0 this doesn't seem to work properly
             * * when accessing an empty CDROM device --jsf 
             */
#ifdef O_NDELAY                 /* I'm sure everything has it, but just in case...  --Wes */
            fd = open(string, O_RDONLY | O_NDELAY);
#else
            fd = open(string, O_RDONLY);
#endif
            if (fd != -1) {
                result = Query_Disk(fd, string);
                close(fd);
                if (result != -1) {
                    HRD_history[iindex] = 0;
                    return ((HRDEV_DISK << HRDEV_TYPE_SHIFT) + iindex);
                }
            }
            HRD_history[iindex] = now;
            HRD_index++;
        }
        HRD_type_index++;
        HRD_index = 0;
    }
    HRD_index = -1;
    return -1;
}