2016-05-17 22:45:27 +00:00
|
|
|
/*
|
|
|
|
* virfirmware.c: Definition of firmware object and supporting functions
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "viralloc.h"
|
|
|
|
#include "virerror.h"
|
|
|
|
#include "virfirmware.h"
|
|
|
|
#include "virlog.h"
|
|
|
|
#include "virstring.h"
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
|
|
|
VIR_LOG_INIT("util.firmware");
|
|
|
|
|
|
|
|
|
2019-08-05 09:38:06 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virFirmwareFree(virFirmware *firmware)
|
2016-05-17 22:45:27 +00:00
|
|
|
{
|
|
|
|
if (!firmware)
|
|
|
|
return;
|
|
|
|
|
2021-02-03 19:32:34 +00:00
|
|
|
g_free(firmware->name);
|
|
|
|
g_free(firmware->nvram);
|
|
|
|
g_free(firmware);
|
2016-05-17 22:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virFirmwareFreeList(virFirmware **firmwares, size_t nfirmwares)
|
2016-05-17 22:45:27 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < nfirmwares; i++)
|
|
|
|
virFirmwareFree(firmwares[i]);
|
|
|
|
|
2021-02-03 19:32:34 +00:00
|
|
|
g_free(firmwares);
|
2016-05-17 22:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virFirmwareParse(const char *str, virFirmware *firmware)
|
2016-05-17 22:45:27 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
2021-11-01 09:34:10 +00:00
|
|
|
g_auto(GStrv) token = NULL;
|
2016-05-17 22:45:27 +00:00
|
|
|
|
2021-02-05 17:35:07 +00:00
|
|
|
if (!(token = g_strsplit(str, ":", 0)))
|
2016-05-17 22:45:27 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (token[0]) {
|
|
|
|
virSkipSpaces((const char **) &token[0]);
|
|
|
|
if (token[1])
|
|
|
|
virSkipSpaces((const char **) &token[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Exactly two tokens are expected */
|
|
|
|
if (!token[0] || !token[1] || token[2] ||
|
|
|
|
STREQ(token[0], "") || STREQ(token[1], "")) {
|
|
|
|
virReportError(VIR_ERR_CONF_SYNTAX,
|
|
|
|
_("Invalid nvram format: '%s'"),
|
|
|
|
str);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2019-10-20 11:49:46 +00:00
|
|
|
firmware->name = g_strdup(token[0]);
|
|
|
|
firmware->nvram = g_strdup(token[1]);
|
2016-05-17 22:45:27 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
virFirmwareParseList(const char *list,
|
2021-03-11 07:16:13 +00:00
|
|
|
virFirmware ***firmwares,
|
2016-05-17 22:45:27 +00:00
|
|
|
size_t *nfirmwares)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
2021-11-01 09:34:10 +00:00
|
|
|
g_auto(GStrv) token = NULL;
|
2016-05-17 22:45:27 +00:00
|
|
|
size_t i, j;
|
|
|
|
|
2021-02-05 17:35:07 +00:00
|
|
|
if (!(token = g_strsplit(list, ":", 0)))
|
2016-05-17 22:45:27 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; token[i]; i += 2) {
|
|
|
|
if (!token[i] || !token[i + 1] ||
|
|
|
|
STREQ(token[i], "") || STREQ(token[i + 1], "")) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Invalid --with-loader-nvram list: %s"),
|
|
|
|
list);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i) {
|
2021-03-11 07:16:13 +00:00
|
|
|
*firmwares = g_new0(virFirmware *, i / 2);
|
2016-05-17 22:45:27 +00:00
|
|
|
*nfirmwares = i / 2;
|
|
|
|
|
|
|
|
for (j = 0; j < i / 2; j++) {
|
2021-03-11 07:16:13 +00:00
|
|
|
virFirmware **fws = *firmwares;
|
2016-05-17 22:45:27 +00:00
|
|
|
|
2020-10-05 17:12:37 +00:00
|
|
|
fws[j] = g_new0(virFirmware, 1);
|
2019-10-20 11:49:46 +00:00
|
|
|
fws[j]->name = g_strdup(token[2 * j]);
|
|
|
|
fws[j]->nvram = g_strdup(token[2 * j + 1]);
|
2016-05-17 22:45:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
return ret;
|
|
|
|
}
|