struct drive * find_drive_by_devname(char *name) { int driveno; char *devpath; struct drive *drivep = NULL; if (ioctl(superdev, VINUM_GETCONFIG, &vinum_conf) < 0) { perror("Can't get vinum config"); return NULL; } devpath = getdevpath(name, 0); for (driveno = 0; driveno < vinum_conf.drives_allocated; driveno++) { get_drive_info(&drive, driveno); if (drive.state == drive_unallocated) continue; if (strcmp(drive.devicename, name) == 0) { drivep = &drive; break; } if (strcmp(drive.devicename, devpath) == 0) { drivep = &drive; break; } } free(devpath); return (drivep); }
/* * Find the object "name". Return object type at type, * and the index as the return value. * If not found, return -1 and invalid_object. */ int find_object(const char *name, enum objecttype *type) { int object; if (ioctl(superdev, VINUM_GETCONFIG, &vinum_conf) < 0) { perror("Can't get vinum config"); *type = invalid_object; return -1; } /* Search the drive table */ for (object = 0; object < vinum_conf.drives_allocated; object++) { get_drive_info(&drive, object); if (strcmp(name, drive.label.name) == 0) { *type = drive_object; return object; } } /* Search the subdisk table */ for (object = 0; object < vinum_conf.subdisks_allocated; object++) { get_sd_info(&sd, object); if (strcmp(name, sd.name) == 0) { *type = sd_object; return object; } } /* Search the plex table */ for (object = 0; object < vinum_conf.plexes_allocated; object++) { get_plex_info(&plex, object); if (strcmp(name, plex.name) == 0) { *type = plex_object; return object; } } /* Search the volume table */ for (object = 0; object < vinum_conf.volumes_allocated; object++) { get_volume_info(&vol, object); if (strcmp(name, vol.name) == 0) { *type = volume_object; return object; } } /* Didn't find the name: invalid */ *type = invalid_object; return -1; }
static int getDriveInfo(int biosdev, struct driveInfo *dip) { static struct driveInfo cached_di; int cc; // Real BIOS devices are 8-bit, so anything above that is for internal use. // Don't cache ramdisk drive info since it doesn't require several BIOS // calls and is thus not worth it. if (biosdev >= 0x100) { #if RAMDISK_SUPPORT if (p_get_ramdisk_info != NULL) { cc = (*p_get_ramdisk_info)(biosdev, dip); } else { cc = -1; } #else cc = -1; #endif if (cc < 0) { dip->valid = 0; return -1; } else { return 0; } } if (!cached_di.valid || biosdev != cached_di.biosdev) { cc = get_drive_info(biosdev, &cached_di); if (cc < 0) { cached_di.valid = 0; _DISK_DEBUG_DUMP(("get_drive_info returned error\n")); return (-1); // BIOS call error } } bcopy(&cached_di, dip, sizeof(cached_di)); return 0; }
static int getDriveInfo( int biosdev, struct driveInfo *dip ) { static struct driveInfo cached_di; int cc; if ( !cached_di.valid || biosdev != cached_di.biosdev ) { cc = get_drive_info(biosdev, &cached_di); if (cc < 0) { cached_di.valid = 0; return (-1); // BIOS call error } } bcopy(&cached_di, dip, sizeof(cached_di)); return 0; }
/* * Create the device nodes for vinum objects * * XXX - Obsolete, vinum kernel module now creates is own devices. */ void make_devices(void) { #if 0 int volno; int plexno; int sdno; int driveno; #endif if (hist) { timestamp(); fprintf(hist, "*** Created devices ***\n"); } #if 0 system("rm -rf " VINUM_DIR); /* remove the old directories */ system("mkdir -p " VINUM_DIR "/drive " /* and make them again */ VINUM_DIR "/plex " VINUM_DIR "/sd " VINUM_DIR "/vol"); if (mknod(VINUM_SUPERDEV_NAME, S_IRUSR | S_IWUSR | S_IFCHR, /* user only */ makedev(VINUM_CDEV_MAJOR, VINUM_SUPERDEV)) < 0) fprintf(stderr, "Can't create %s: %s\n", VINUM_SUPERDEV_NAME, strerror(errno)); if (mknod(VINUM_WRONGSUPERDEV_NAME, S_IRUSR | S_IWUSR | S_IFCHR, /* user only */ makedev(VINUM_CDEV_MAJOR, VINUM_WRONGSUPERDEV)) < 0) fprintf(stderr, "Can't create %s: %s\n", VINUM_WRONGSUPERDEV_NAME, strerror(errno)); superdev = open(VINUM_SUPERDEV_NAME, O_RDWR); /* open the super device */ if (mknod(VINUM_DAEMON_DEV_NAME, /* daemon super device */ S_IRUSR | S_IWUSR | S_IFCHR, /* user only */ makedev(VINUM_CDEV_MAJOR, VINUM_DAEMON_DEV)) < 0) fprintf(stderr, "Can't create %s: %s\n", VINUM_DAEMON_DEV_NAME, strerror(errno)); #endif if (ioctl(superdev, VINUM_GETCONFIG, &vinum_conf) < 0) { perror("Can't get vinum config"); return; } #if 0 for (volno = 0; volno < vinum_conf.volumes_allocated; volno++) make_vol_dev(volno, 0); for (plexno = 0; plexno < vinum_conf.plexes_allocated; plexno++) make_plex_dev(plexno, 0); for (sdno = 0; sdno < vinum_conf.subdisks_allocated; sdno++) make_sd_dev(sdno); /* Drives. Do this later (both logical and physical names) XXX */ for (driveno = 0; driveno < vinum_conf.drives_allocated; driveno++) { char filename[PATH_MAX]; /* for forming file names */ get_drive_info(&drive, driveno); if (drive.state > drive_referenced) { sprintf(filename, "ln -s %s " VINUM_DIR "/drive/%s", drive.devicename, drive.label.name); system(filename); } } #endif }