/* Helper function to set a drive to a given state. */ static int drive_set_state(char *drive, U8 Action, U8 State, const char *name) { CONFIG_PAGE_RAID_PHYS_DISK_0 *info; struct mpt_drive_list *list; U8 PhysDiskNum; int error, fd; fd = mpt_open(mpt_unit); if (fd < 0) { error = errno; warn("mpt_open"); return (error); } list = mpt_pd_list(fd); if (list == NULL) { close(fd); return (errno); } if (mpt_lookup_drive(list, drive, &PhysDiskNum) < 0) { error = errno; warn("Failed to find drive %s", drive); close(fd); return (error); } mpt_free_pd_list(list); /* Get the info for this drive. */ info = mpt_pd_info(fd, PhysDiskNum, NULL); if (info == NULL) { error = errno; warn("Failed to fetch info for drive %u", PhysDiskNum); close(fd); return (error); } /* Try to change the state. */ if (info->PhysDiskStatus.State == State) { warnx("Drive %u is already in the desired state", PhysDiskNum); free(info); close(fd); return (EINVAL); } error = mpt_raid_action(fd, Action, 0, 0, PhysDiskNum, 0, NULL, 0, NULL, NULL, 0, NULL, NULL, 0); if (error) { warnc(error, "Failed to set drive %u to %s", PhysDiskNum, name); free(info); close(fd); return (error); } free(info); close(fd); return (0); }
static int show_drives(int ac, char **av) { struct mpt_drive_list *list; struct mpt_standalone_disk *sdisks; int error, fd, i, len, nsdisks, state_len; if (ac != 1) { warnx("show drives: extra arguments"); return (EINVAL); } fd = mpt_open(mpt_unit); if (fd < 0) { error = errno; warn("mpt_open"); return (error); } /* Get the drive list. */ list = mpt_pd_list(fd); if (list == NULL) { error = errno; warn("Failed to get drive list"); return (error); } /* Fetch the list of standalone disks for this controller. */ state_len = 0; if (mpt_fetch_disks(fd, &nsdisks, &sdisks) != 0) { nsdisks = 0; sdisks = NULL; } if (nsdisks != 0) state_len = strlen(STANDALONE_STATE); /* Walk the drive list to determine width of state column. */ for (i = 0; i < list->ndrives; i++) { len = strlen(mpt_pdstate(list->drives[i])); if (len > state_len) state_len = len; } /* List the drives. */ printf("mpt%d Physical Drives:\n", mpt_unit); for (i = 0; i < list->ndrives; i++) { printf("%4u ", list->drives[i]->PhysDiskNum); print_pd(list->drives[i], state_len, 1); printf("\n"); } mpt_free_pd_list(list); for (i = 0; i < nsdisks; i++) { printf("%4s ", sdisks[i].devname); print_standalone(&sdisks[i], state_len, 1); printf("\n"); } free(sdisks); close(fd); return (0); }