/* * Given pg2_path = /some/file.pg2, extract the needed VPD values from * /some/file.vpd. */ static int read_fake_vpd(const char *sg, const char *pg2_path, struct dev_vpd *vpd) { char *vpd_path, *dot; char *result; FILE *f; vpd_path = strdup(pg2_path); assert(vpd_path); dot = strrchr(vpd_path, '.'); assert(dot && !strcmp(dot, ".pg2")); strncpy(dot, ".vpd", VPD_PATHNAME_EXTN_MAXLEN - 1); dot[VPD_PATHNAME_EXTN_MAXLEN - 1] = '\0'; f = fopen(vpd_path, "r"); if (!f) { perror(vpd_path); free(vpd_path); return -1; } result = fgets_nonl(vpd->mtm, VPD_LENGTH, f); if (!result) goto missing_vpd; result = fgets_nonl(vpd->full_loc, LOCATION_LENGTH, f); if (!result) goto missing_vpd; result = fgets_nonl(vpd->sn, VPD_LENGTH, f); if (!result) goto missing_vpd; result = fgets_nonl(vpd->fru, VPD_LENGTH, f); if (!result) goto missing_vpd; fclose(f); free(vpd_path); /* Add sg device name */ strncpy(vpd->dev, sg, PATH_MAX - 1); trim_location_code(vpd); return 0; missing_vpd: fprintf(stderr, "%s lacks acceptable mtm, location code, serial number," " and FRU number.\n", vpd_path); fclose(f); free(vpd_path); return -1; }
/* * enclosure_maint_mode * @brief Check the state of SCSI enclosure * * Returns: * -1 on failure * 1 if sg is offline * 0 if sg is running */ static int enclosure_maint_mode(const char *sg) { char devsg[128], sgstate[128]; FILE *fp; snprintf(devsg, 128, "/sys/class/scsi_generic/%s/device/state", sg); fp = fopen(devsg, "r"); if (!fp) { perror(devsg); fprintf(stderr, "Unable to open enclosure " "state file : %s\n", devsg); return -1; } if (fgets_nonl(sgstate, 128, fp) == NULL) { fprintf(stderr, "Unable to read the state of " "enclosure device : %s\n", sg); fclose(fp); return -1; } /* Check device state */ if (!strcmp(sgstate, "offline")) { fprintf(stderr, "Enclosure \"%s\" is offline." " Cannot run diagnostics.\n", sg); fclose(fp); return 1; } fclose(fp); return 0; }
/* * Given pg2_path = /some/file.pg2, extract the needed VPD values from * /some/file.vpd. */ static int read_fake_vpd(struct dev_vpd *vpd, const char *pg2_path) { char *vpd_path, *dot; char *result; FILE *f; vpd_path = strdup(pg2_path); assert(vpd_path); dot = strrchr(vpd_path, '.'); assert(dot && !strcmp(dot, ".pg2")); strcpy(dot, ".vpd"); f = fopen(vpd_path, "r"); if (!f) { perror(vpd_path); free(vpd_path); return -1; } result = fgets_nonl(vpd->mtm, 128, f); if (!result) goto missing_vpd; result = fgets_nonl(vpd->full_loc, 128, f); if (!result) goto missing_vpd; result = fgets_nonl(vpd->sn, 128, f); if (!result) goto missing_vpd; result = fgets_nonl(vpd->fru, 128, f); if (!result) goto missing_vpd; fclose(f); free(vpd_path); trim_location_code(vpd); return 0; missing_vpd: fprintf(stderr, "%s lacks acceptable mtm, location code, serial number," " and FRU number.\n", vpd_path); fclose(f); free(vpd_path); return -1; }