From: Jan Kiszka <[email protected]>

This is also touching our external API but in a harmless,
backward-compatible way.

Signed-off-by: Jan Kiszka <[email protected]>
---
 env/env_api.c                        | 14 +++++++-------
 env/env_api_fat.c                    | 14 +++++++-------
 env/env_config_file.c                |  4 ++--
 env/env_config_partitions.c          | 10 +++++-----
 env/env_disk_utils.c                 |  6 +++---
 env/uservars.c                       | 14 +++++++-------
 include/ebgenv.h                     | 12 ++++++------
 include/env_api.h                    | 10 +++++-----
 include/env_config_file.h            |  4 ++--
 include/env_disk_utils.h             |  2 +-
 include/test-interface.h             |  4 ++--
 include/uservars.h                   | 10 +++++-----
 tools/tests/test_probe_config_file.c |  6 +++---
 13 files changed, 55 insertions(+), 55 deletions(-)

diff --git a/env/env_api.c b/env/env_api.c
index 0890771..ce6abbd 100644
--- a/env/env_api.c
+++ b/env/env_api.c
@@ -107,7 +107,7 @@ int ebg_env_create_new(ebgenv_t *e)
                return EIO;
        }
 
-       BG_ENVDATA *latest_data = ((BGENV *)latest_env)->data;
+       const BG_ENVDATA *latest_data = ((BGENV *)latest_env)->data;
 
        if (latest_data->in_progress != 1) {
                e->bgenv = (void *)bgenv_create_new();
@@ -140,27 +140,27 @@ int ebg_env_open_current(ebgenv_t *e)
        return e->bgenv == NULL ? EIO : 0;
 }
 
-int ebg_env_get(ebgenv_t *e, char *key, char *buffer)
+int ebg_env_get(ebgenv_t *e, const char *key, char *buffer)
 {
        return bgenv_get((BGENV *)e->bgenv, key, NULL, buffer,
                         ENV_STRING_LENGTH);
 }
 
-int ebg_env_get_ex(ebgenv_t *e, char *key, uint64_t *usertype, uint8_t *buffer,
-                  uint32_t maxlen)
+int ebg_env_get_ex(ebgenv_t *e, const char *key, uint64_t *usertype,
+                  uint8_t *buffer, uint32_t maxlen)
 {
        return bgenv_get((BGENV *)e->bgenv, key, usertype, buffer, maxlen);
 }
 
-int ebg_env_set(ebgenv_t *e, char *key, char *value)
+int ebg_env_set(ebgenv_t *e, const char *key, const char *value)
 {
        return bgenv_set((BGENV *)e->bgenv, key, USERVAR_TYPE_DEFAULT |
                         USERVAR_TYPE_STRING_ASCII, value,
                         strlen(value) + 1);
 }
 
-int ebg_env_set_ex(ebgenv_t *e, char *key, uint64_t usertype, uint8_t *value,
-                  uint32_t datalen)
+int ebg_env_set_ex(ebgenv_t *e, const char *key, uint64_t usertype,
+                  const uint8_t *value, uint32_t datalen)
 {
        return bgenv_set((BGENV *)e->bgenv, key, usertype, value, datalen);
 }
diff --git a/env/env_api_fat.c b/env/env_api_fat.c
index 6bca88d..7c84dc6 100644
--- a/env/env_api_fat.c
+++ b/env/env_api_fat.c
@@ -22,7 +22,7 @@
 
 extern ebgenv_opts_t ebgenv_opts;
 
-EBGENVKEY bgenv_str2enum(char *key)
+EBGENVKEY bgenv_str2enum(const char *key)
 {
        if (strcmp(key, "kernelfile") == 0) {
                return EBGENV_KERNELFILE;
@@ -124,7 +124,7 @@ bool read_env(CONFIG_PART *part, BG_ENVDATA *env)
        return validate_envdata(env);
 }
 
-bool write_env(CONFIG_PART *part, BG_ENVDATA *env)
+bool write_env(CONFIG_PART *part, const BG_ENVDATA *env)
 {
        if (!part) {
                return false;
@@ -265,7 +265,7 @@ bool bgenv_write(BGENV *env)
        return true;
 }
 
-BG_ENVDATA *bgenv_read(BGENV *env)
+BG_ENVDATA *bgenv_read(const BGENV *env)
 {
        if (!env) {
                return NULL;
@@ -314,7 +314,7 @@ static int bgenv_get_string(char *buffer, uint64_t *type, 
void *data,
        return 0;
 }
 
-int bgenv_get(BGENV *env, char *key, uint64_t *type, void *data,
+int bgenv_get(BGENV *env, const char *key, uint64_t *type, void *data,
              uint32_t maxlen)
 {
        EBGENVKEY e;
@@ -372,7 +372,7 @@ int bgenv_get(BGENV *env, char *key, uint64_t *type, void 
*data,
        }
 }
 
-static long bgenv_convert_to_long(char *value)
+static long bgenv_convert_to_long(const char *value)
 {
        long val;
        char *p;
@@ -389,12 +389,12 @@ static long bgenv_convert_to_long(char *value)
        return val;
 }
 
-int bgenv_set(BGENV *env, char *key, uint64_t type, void *data,
+int bgenv_set(BGENV *env, const char *key, uint64_t type, const void *data,
              uint32_t datalen)
 {
        EBGENVKEY e;
        int val;
-       char *value = (char *)data;
+       const char *value = (const char *)data;
 
        if (!key || !data || datalen == 0) {
                return -EINVAL;
diff --git a/env/env_config_file.c b/env/env_config_file.c
index a19678e..b0cf043 100644
--- a/env/env_config_file.c
+++ b/env/env_config_file.c
@@ -18,13 +18,13 @@
 #include "env_disk_utils.h"
 #include "env_config_file.h"
 
-FILE *open_config_file(char *configfilepath, char *mode)
+FILE *open_config_file(const char *configfilepath, const char *mode)
 {
        VERBOSE(stdout, "Probing config file at %s.\n", configfilepath);
        return fopen(configfilepath, mode);
 }
 
-FILE *open_config_file_from_part(CONFIG_PART *cfgpart, char *mode)
+FILE *open_config_file_from_part(const CONFIG_PART *cfgpart, const char *mode)
 {
        char *configfilepath;
 
diff --git a/env/env_config_partitions.c b/env/env_config_partitions.c
index 0ef5a55..862c2bf 100644
--- a/env/env_config_partitions.c
+++ b/env/env_config_partitions.c
@@ -74,7 +74,7 @@ static char *get_rootdev_from_efi(void)
        }
        VERBOSE(stdout, "resolved ESP to %s\n", devpath);
        // get disk name from path
-       char *partition = strrchr(devpath, '/') + 1;
+       const char *partition = strrchr(devpath, '/') + 1;
 
        // resolve parent device. As the ESP must be a primary partition, the
        // parent is the block device.
@@ -84,7 +84,7 @@ static char *get_rootdev_from_efi(void)
 
        // resolve to e.g. /sys/devices/pci0000:00/0000:00:1f.2/<...>/block/sda
        char *blockpath = realpath(buffer.aschar, NULL);
-       char *_blockdev = strrchr(blockpath, '/') + 1;
+       const char *_blockdev = strrchr(blockpath, '/') + 1;
        char *blockdev = strdup(_blockdev);
        free(blockpath);
        return blockdev;
@@ -92,7 +92,7 @@ static char *get_rootdev_from_efi(void)
 
 bool probe_config_partitions(CONFIG_PART *cfgpart, bool search_all_devices)
 {
-       PedDevice *dev = NULL;
+       const PedDevice *dev = NULL;
        char devpath[4096];
        char *rootdev = NULL;
        int count = 0;
@@ -115,11 +115,11 @@ bool probe_config_partitions(CONFIG_PART *cfgpart, bool 
search_all_devices)
 
        while ((dev = ped_device_get_next(dev))) {
                printf_debug("Device: %s\n", dev->model);
-               PedDisk *pd = ped_disk_new(dev);
+               const PedDisk *pd = ped_disk_new(dev);
                if (!pd) {
                        continue;
                }
-               PedPartition *part = pd->part_list;
+               const PedPartition *part = pd->part_list;
                while (part) {
                        if (part->fs_type != FS_TYPE_FAT12 &&
                            part->fs_type != FS_TYPE_FAT16 &&
diff --git a/env/env_disk_utils.c b/env/env_disk_utils.c
index 289174f..bcf9f80 100644
--- a/env/env_disk_utils.c
+++ b/env/env_disk_utils.c
@@ -20,10 +20,10 @@
 
 const char *tmp_mnt_dir = "/tmp/mnt-XXXXXX";
 
-char *get_mountpoint(char *devpath)
+char *get_mountpoint(const char *devpath)
 {
+       const struct mntent *part;
        char *mntpoint = NULL;
-       struct mntent *part;
        FILE *mtab;
 
        mtab = setmntent("/proc/mounts", "r");
@@ -46,7 +46,7 @@ char *get_mountpoint(char *devpath)
 bool mount_partition(CONFIG_PART *cfgpart)
 {
        char tmpdir_template[256];
-       char *mountpoint;
+       const char *mountpoint;
        (void)snprintf(tmpdir_template, 256, "%s", tmp_mnt_dir);
        if (!cfgpart) {
                return false;
diff --git a/env/uservars.c b/env/uservars.c
index 23c6350..145ed5d 100644
--- a/env/uservars.c
+++ b/env/uservars.c
@@ -153,8 +153,8 @@ static uint8_t *bgenv_uservar_realloc(uint8_t *udata, 
uint32_t new_rsize,
        return udata + ENV_MEM_USERVARS - spaceleft;
 }
 
-static void bgenv_serialize_uservar(uint8_t *p, char *key, uint64_t type,
-                                   void *data, uint32_t record_size)
+static void bgenv_serialize_uservar(uint8_t *p, const char *key, uint64_t type,
+                                   const void *data, uint32_t record_size)
 {
        uint32_t payload_size, data_size;
 
@@ -176,8 +176,8 @@ static void bgenv_serialize_uservar(uint8_t *p, char *key, 
uint64_t type,
        memcpy(p, data, data_size);
 }
 
-int bgenv_get_uservar(uint8_t *udata, char *key, uint64_t *type, void *data,
-                     uint32_t maxlen)
+int bgenv_get_uservar(uint8_t *udata, const char *key, uint64_t *type,
+                     void *data, uint32_t maxlen)
 {
        uint8_t *uservar, *value;
        char *lkey;
@@ -205,8 +205,8 @@ int bgenv_get_uservar(uint8_t *udata, char *key, uint64_t 
*type, void *data,
        return 0;
 }
 
-int bgenv_set_uservar(uint8_t *udata, char *key, uint64_t type, void *data,
-                     uint32_t datalen)
+int bgenv_set_uservar(uint8_t *udata, const char *key, uint64_t type,
+                     const void *data, uint32_t datalen)
 {
        uint32_t total_size;
        uint8_t *p;
@@ -238,7 +238,7 @@ int bgenv_set_uservar(uint8_t *udata, char *key, uint64_t 
type, void *data,
        return 0;
 }
 
-uint8_t *bgenv_find_uservar(uint8_t *udata, char *key)
+uint8_t *bgenv_find_uservar(uint8_t *udata, const char *key)
 {
        char *varkey;
 
diff --git a/include/ebgenv.h b/include/ebgenv.h
index 60ba81c..7a8dfec 100644
--- a/include/ebgenv.h
+++ b/include/ebgenv.h
@@ -96,7 +96,7 @@ int ebg_env_open_current(ebgenv_t *e);
  *          If buffer == NULL: needed buffer size, 0 if variable
  *                             is not found.
  */
-int ebg_env_get(ebgenv_t *e, char *key, char* buffer);
+int ebg_env_get(ebgenv_t *e, const char *key, char* buffer);
 
 /** @brief Store new content into variable
  *  @param e A pointer to an ebgenv_t context.
@@ -105,7 +105,7 @@ int ebg_env_get(ebgenv_t *e, char *key, char* buffer);
  *  @return 0 on success, -errno on failure. If buffer is NULL,
  *         the required buffer size is returned.
  */
-int ebg_env_set(ebgenv_t *e, char *key, char *value);
+int ebg_env_set(ebgenv_t *e, const char *key, const char *value);
 
 /** @brief Store new content into variable
  *  @param e A pointer to an ebgenv_t context.
@@ -115,8 +115,8 @@ int ebg_env_set(ebgenv_t *e, char *key, char *value);
  *  @param datalen length of the data to be stored into the variable
  *  @return 0 on success, -errno on failure
  */
-int ebg_env_set_ex(ebgenv_t *e, char *key, uint64_t datatype, uint8_t *value,
-                  uint32_t datalen);
+int ebg_env_set_ex(ebgenv_t *e, const char *key, uint64_t datatype,
+                  const uint8_t *value, uint32_t datalen);
 
 /** @brief Get content of user variable
  *  @param e A pointer to an ebgenv_t context.
@@ -126,8 +126,8 @@ int ebg_env_set_ex(ebgenv_t *e, char *key, uint64_t 
datatype, uint8_t *value,
  *  @param maxlen size of provided buffer
  *  @return 0 on success, -errno on failure
  */
-int ebg_env_get_ex(ebgenv_t *e, char *key, uint64_t *datatype, uint8_t *buffer,
-                  uint32_t maxlen);
+int ebg_env_get_ex(ebgenv_t *e, const char *key, uint64_t *datatype,
+                  uint8_t *buffer, uint32_t maxlen);
 
 /** @brief Get available space for user variables
  *  @param e A pointer to an ebgenv_t context.
diff --git a/include/env_api.h b/include/env_api.h
index 99fd0ae..24b2414 100644
--- a/include/env_api.h
+++ b/include/env_api.h
@@ -86,14 +86,14 @@ extern BGENV *bgenv_open_by_index(uint32_t index);
 extern BGENV *bgenv_open_oldest(void);
 extern BGENV *bgenv_open_latest(void);
 extern bool bgenv_write(BGENV *env);
-extern BG_ENVDATA *bgenv_read(BGENV *env);
+extern BG_ENVDATA *bgenv_read(const BGENV *env);
 extern void bgenv_close(BGENV *env);
 
 extern BGENV *bgenv_create_new(void);
-extern int bgenv_get(BGENV *env, char *key, uint64_t *type, void *data,
+extern int bgenv_get(BGENV *env, const char *key, uint64_t *type, void *data,
                     uint32_t maxlen);
-extern int bgenv_set(BGENV *env, char *key, uint64_t type, void *data,
-                    uint32_t datalen);
-extern uint8_t *bgenv_find_uservar(uint8_t *userdata, char *key);
+extern int bgenv_set(BGENV *env, const char *key, uint64_t type,
+                    const void *data, uint32_t datalen);
+extern uint8_t *bgenv_find_uservar(uint8_t *userdata, const char *key);
 
 extern bool validate_envdata(BG_ENVDATA *data);
diff --git a/include/env_config_file.h b/include/env_config_file.h
index 059ce0f..a95b395 100644
--- a/include/env_config_file.h
+++ b/include/env_config_file.h
@@ -16,6 +16,6 @@
 #include <stdio.h>
 #include "env_api.h"
 
-FILE *open_config_file_from_part(CONFIG_PART *cfgpart, char *mode);
-FILE *open_config_file(char *configfilepath, char *mode);
+FILE *open_config_file_from_part(const CONFIG_PART *cfgpart, const char *mode);
+FILE *open_config_file(const char *configfilepath, const char *mode);
 bool probe_config_file(CONFIG_PART *cfgpart);
diff --git a/include/env_disk_utils.h b/include/env_disk_utils.h
index ab338e2..cec93c1 100644
--- a/include/env_disk_utils.h
+++ b/include/env_disk_utils.h
@@ -17,6 +17,6 @@
 #include <stdbool.h>
 #include "env_api.h"
 
-char *get_mountpoint(char *devpath);
+char *get_mountpoint(const char *devpath);
 bool mount_partition(CONFIG_PART *cfgpart);
 void unmount_partition(CONFIG_PART *cfgpart);
diff --git a/include/test-interface.h b/include/test-interface.h
index df62618..7658c6d 100644
--- a/include/test-interface.h
+++ b/include/test-interface.h
@@ -17,6 +17,6 @@
 #include "env_api.h"
 
 bool read_env(CONFIG_PART *part, BG_ENVDATA *env);
-bool write_env(CONFIG_PART *part, BG_ENVDATA *env);
+bool write_env(CONFIG_PART *part, const BG_ENVDATA *env);
 
-EBGENVKEY bgenv_str2enum(char *key);
+EBGENVKEY bgenv_str2enum(const char *key);
diff --git a/include/uservars.h b/include/uservars.h
index 9adef9d..6623996 100644
--- a/include/uservars.h
+++ b/include/uservars.h
@@ -21,12 +21,12 @@ void bgenv_map_uservar(uint8_t *udata, char **key, uint64_t 
*type,
                       uint8_t **val, uint32_t *record_size,
                       uint32_t *data_size);
 
-int bgenv_get_uservar(uint8_t *udata, char *key, uint64_t *type, void *data,
-                     uint32_t maxlen);
-int bgenv_set_uservar(uint8_t *udata, char *key, uint64_t type, void *data,
-                     uint32_t datalen);
+int bgenv_get_uservar(uint8_t *udata, const char *key, uint64_t *type,
+                     void *data, uint32_t maxlen);
+int bgenv_set_uservar(uint8_t *udata, const char *key, uint64_t type,
+                     const void *data, uint32_t datalen);
 
-uint8_t *bgenv_find_uservar(uint8_t *udata, char *key);
+uint8_t *bgenv_find_uservar(uint8_t *udata, const char *key);
 uint8_t *bgenv_next_uservar(uint8_t *udata);
 
 void bgenv_del_uservar(uint8_t *udata, uint8_t *var);
diff --git a/tools/tests/test_probe_config_file.c 
b/tools/tests/test_probe_config_file.c
index ba179b6..cb3e065 100644
--- a/tools/tests/test_probe_config_file.c
+++ b/tools/tests/test_probe_config_file.c
@@ -29,7 +29,7 @@ DEFINE_FFF_GLOBALS;
 
 Suite *ebg_test_suite(void);
 
-char *get_mountpoint_custom_fake(char *devpath);
+char *get_mountpoint_custom_fake(const char *devpath);
 void delete_temp_files(void);
 
 bool __wrap_probe_config_file(CONFIG_PART *);
@@ -45,7 +45,7 @@ struct fake_env_file_path {
 };
 STAILQ_HEAD(stailhead, fake_env_file_path) head = 
STAILQ_HEAD_INITIALIZER(head);
 
-char *get_mountpoint_custom_fake(char *devpath)
+char *get_mountpoint_custom_fake(const char *devpath)
 {
        char *buff = NULL;
        char *tempdir = NULL;
@@ -134,7 +134,7 @@ void delete_temp_files(void)
 
 FAKE_VOID_FUNC(ped_device_probe_all, char *);
 FAKE_VALUE_FUNC(PedDevice *, ped_device_get_next, const PedDevice *);
-FAKE_VALUE_FUNC(char *, get_mountpoint, char *);
+FAKE_VALUE_FUNC(char *, get_mountpoint, const char *);
 
 START_TEST(env_api_fat_test_probe_config_file)
 {
-- 
2.43.0

-- 
You received this message because you are subscribed to the Google Groups "EFI 
Boot Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/efibootguard-dev/206ad1f3c41cc6f7ee59f5e211426cd796e3306d.1747253700.git.jan.kiszka%40siemens.com.

Reply via email to