| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <stdio.h> |
| 4 |
|
| 5 |
#include "alloc-util.h" |
| 6 |
#include "analyze.h" |
| 7 |
#include "analyze-smbios11.h" |
| 8 |
#include "escape.h" |
| 9 |
#include "glyph-util.h" |
| 10 |
#include "log.h" |
| 11 |
#include "smbios11.h" |
| 12 |
|
| 13 |
int verb_smbios11(int argc, char *argv[], uintptr_t _data, void *userdata) { |
| 14 |
unsigned n = 0; |
| 15 |
int r; |
| 16 |
|
| 17 |
for (unsigned i = 0;; i++) { |
| 18 |
_cleanup_free_ char *data = NULL; |
| 19 |
bool written = false; |
| 20 |
size_t size; |
| 21 |
|
| 22 |
r = read_smbios11_field(i, SIZE_MAX, &data, &size); |
| 23 |
if (r == -ENOENT) /* Reached the end */ |
| 24 |
break; |
| 25 |
if (r < 0) |
| 26 |
return log_error_errno(r, "Failed to read SMBIOS Type #11 string %u: %m", i); |
| 27 |
bool incomplete = r == 0; |
| 28 |
|
| 29 |
size_t left, skip; |
| 30 |
const char *p; |
| 31 |
for (p = data, left = size; left > 0; p += skip, left -= skip) { |
| 32 |
const char *nul; |
| 33 |
|
| 34 |
nul = memchr(p, 0, left); |
| 35 |
if (nul) |
| 36 |
skip = (nul - p) + 1; |
| 37 |
else { |
| 38 |
nul = p + left; |
| 39 |
skip = left; |
| 40 |
} |
| 41 |
|
| 42 |
if (nul - p == 0) /* Skip empty strings */ |
| 43 |
continue; |
| 44 |
|
| 45 |
_cleanup_free_ char *escaped = NULL; |
| 46 |
escaped = cescape_length(p, nul - p); |
| 47 |
if (!escaped) |
| 48 |
return log_oom(); |
| 49 |
|
| 50 |
if (written) |
| 51 |
fputc('\n', stdout); |
| 52 |
|
| 53 |
fputs(escaped, stdout); |
| 54 |
written = true; |
| 55 |
n++; |
| 56 |
} |
| 57 |
|
| 58 |
if (written) { |
| 59 |
if (incomplete) |
| 60 |
fputs(glyph(GLYPH_ELLIPSIS), stdout); |
| 61 |
|
| 62 |
fputc('\n', stdout); |
| 63 |
} |
| 64 |
|
| 65 |
if (i == UINT_MAX) /* Prevent overflow */ |
| 66 |
break; |
| 67 |
} |
| 68 |
|
| 69 |
if (!arg_quiet) { |
| 70 |
if (n == 0) |
| 71 |
log_info("No SMBIOS Type #11 strings passed."); |
| 72 |
else |
| 73 |
log_info("\n%u SMBIOS Type #11 strings passed.", n); |
| 74 |
} |
| 75 |
|
| 76 |
return EXIT_SUCCESS; |
| 77 |
} |