/* Print all parameters with descriptions. If force_all!=0, prints even * parameters that specify the NO_PRINT_ALL flag. * * Returns 0 if success, non-zero if error. */ int PrintAllParams(int force_all) { const Param* p; int retval = 0; char buf[VB_MAX_STRING_PROPERTY]; const char* value; for (p = sys_param_list; p->name; p++) { if (0 == force_all && (p->flags & NO_PRINT_ALL)) continue; if (p->flags & IS_STRING) { value = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); } else { int v = VbGetSystemPropertyInt(p->name); if (v == -1) value = NULL; else { snprintf(buf, sizeof(buf), p->format ? p->format : "%d", v); value = buf; } } printf("%-22s = %-30s # %s\n", p->name, (value ? value : "(error)"), p->desc); } return retval; }
/* Return true if the FWID starts with the specified string. */ int FwidStartsWith(const char *start) { char fwid[VB_MAX_STRING_PROPERTY]; if (!VbGetSystemPropertyString("fwid", fwid, sizeof(fwid))) return 0; return 0 == strncmp(fwid, start, strlen(start)); }
/* Print the specified parameter. * * Returns 0 if success, non-zero if error. */ int PrintParam(const Param* p) { if (p->flags & IS_STRING) { char buf[VB_MAX_STRING_PROPERTY]; const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); if (!v) return 1; printf("%s", v); } else { int v = VbGetSystemPropertyInt(p->name); if (v == -1) return 1; printf(p->format ? p->format : "%d", v); } return 0; }
/* Compares the parameter with the expected value. * * Returns 0 if success (match), non-zero if error (mismatch). */ int CheckParam(const Param* p, char* expect) { if (p->flags & IS_STRING) { char buf[VB_MAX_STRING_PROPERTY]; const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); if (!v || 0 != strcmp(v, expect)) return 1; } else { char* e; int i = (int)strtol(expect, &e, 0); int v = VbGetSystemPropertyInt(p->name); if (!*expect || (e && *e)) return 1; if (v == -1 || i != v) return 1; } return 0; }