]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: const qualifier cleanup
authorKarel Zak <kzak@redhat.com>
Fri, 20 Jul 2018 13:03:01 +0000 (15:03 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 20 Jul 2018 13:05:32 +0000 (15:05 +0200)
* use "const" in functions where we don't modify arguments

* use "const" when cast from const buffer to any struct (superblock etc.)

Signed-off-by: Karel Zak <kzak@redhat.com>
12 files changed:
include/pt-sun.h
libblkid/src/blkidP.h
libblkid/src/partitions/partitions.c
libblkid/src/probe.c
libblkid/src/superblocks/bitlocker.c
libblkid/src/superblocks/minix.c
libblkid/src/superblocks/stratis.c
libblkid/src/superblocks/superblocks.c
libblkid/src/superblocks/superblocks.h
libblkid/src/superblocks/vfat.c
libblkid/src/superblocks/zfs.c
libblkid/src/topology/dm.c

index e6a4ed13ff1849ef7f9eb8bb9e53a680fcd1115f..8bb5d950ec0fffa7a4ce5fd006f9f34a997bbac0 100644 (file)
@@ -78,10 +78,10 @@ struct sun_disklabel {
 
 static inline uint16_t sun_pt_checksum(const struct sun_disklabel *label)
 {
-       uint16_t *ptr = ((uint16_t *) (label + 1)) - 1;
+       const uint16_t *ptr = ((const uint16_t *) (label + 1)) - 1;
        uint16_t sum;
 
-       for (sum = 0; ptr >= ((uint16_t *) label);)
+       for (sum = 0; ptr >= ((const uint16_t *) label);)
                sum ^= *ptr--;
 
        return sum;
index 22c9856312c1594d19dde8349f5dafce946672a1..2d272f856f543e9914586e24026aadc345fc5e18 100644 (file)
@@ -484,10 +484,10 @@ extern void *blkid_probe_get_binary_data(blkid_probe pr, struct blkid_chain *chn
 extern struct blkid_prval *blkid_probe_new_val(void)
                        __attribute__((warn_unused_result));
 extern int blkid_probe_set_value(blkid_probe pr, const char *name,
-                               unsigned char *data, size_t len)
+                               const unsigned char *data, size_t len)
                        __attribute__((nonnull));
 extern int blkid_probe_value_set_data(struct blkid_prval *v,
-                               unsigned char *data, size_t len)
+                               const unsigned char *data, size_t len)
                        __attribute__((nonnull));
 
 extern int blkid_probe_vsprintf_value(blkid_probe pr, const char *name,
@@ -500,7 +500,7 @@ extern int blkid_probe_sprintf_value(blkid_probe pr, const char *name,
                        __attribute__ ((__format__ (__printf__, 3, 4)));
 
 extern int blkid_probe_set_magic(blkid_probe pr, uint64_t offset,
-                               size_t len, unsigned char *magic)
+                               size_t len, const unsigned char *magic)
                        __attribute__((nonnull));
 
 extern int blkid_probe_verify_csum(blkid_probe pr, uint64_t csum, uint64_t expected)
index f60f3c6535c8d128d41189da20dad10c9f627792..4138904d44ed0f459bfb8513cf4fd5e1e1499a65 100644 (file)
@@ -557,7 +557,7 @@ static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id,
                }
                if (rc == BLKID_PROBE_OK && mag && chn && !chn->binary)
                        rc = blkid_probe_set_magic(pr, off, mag->len,
-                                       (unsigned char *) mag->magic);
+                                       (const unsigned char *) mag->magic);
 
                DBG(LOWPROBE, ul_debug("%s: <--- (rc = %d)", id->name, rc));
        }
@@ -620,7 +620,7 @@ static int partitions_probe(blkid_probe pr, struct blkid_chain *chn)
                         * functions.
                         */
                        blkid_probe_set_value(pr, "PTTYPE",
-                                               (unsigned char *) name,
+                                               (const unsigned char *) name,
                                                strlen(name) + 1);
 
                DBG(LOWPROBE, ul_debug("<-- leaving probing loop (type=%s) [PARTS idx=%d]",
@@ -755,24 +755,24 @@ static int blkid_partitions_probe_partition(blkid_probe pr)
                        v = blkid_parttable_get_type(tab);
                        if (v)
                                blkid_probe_set_value(pr, "PART_ENTRY_SCHEME",
-                                       (unsigned char *) v, strlen(v) + 1);
+                                       (const unsigned char *) v, strlen(v) + 1);
                }
 
                v = blkid_partition_get_name(par);
                if (v)
                        blkid_probe_set_value(pr, "PART_ENTRY_NAME",
-                               (unsigned char *) v, strlen(v) + 1);
+                               (const unsigned char *) v, strlen(v) + 1);
 
                v = blkid_partition_get_uuid(par);
                if (v)
                        blkid_probe_set_value(pr, "PART_ENTRY_UUID",
-                               (unsigned char *) v, strlen(v) + 1);
+                               (const unsigned char *) v, strlen(v) + 1);
 
                /* type */
                v = blkid_partition_get_type_string(par);
                if (v)
                        blkid_probe_set_value(pr, "PART_ENTRY_TYPE",
-                               (unsigned char *) v, strlen(v) + 1);
+                               (const unsigned char *) v, strlen(v) + 1);
                else
                        blkid_probe_sprintf_value(pr, "PART_ENTRY_TYPE",
                                "0x%x", blkid_partition_get_type(par));
index 647ae416ab0685464873b5a09b00a9042e5c821a..081f8826eb763606e8c869448aeb3469ca41b9d5 100644 (file)
@@ -1468,7 +1468,7 @@ struct blkid_prval *blkid_probe_assign_value(blkid_probe pr, const char *name)
  * for binary data it's without terminator).
  */
 int blkid_probe_value_set_data(struct blkid_prval *v,
-               unsigned char *data, size_t len)
+               const unsigned char *data, size_t len)
 {
        v->data = calloc(1, len + 1);   /* always terminate by \0 */
 
@@ -1480,7 +1480,7 @@ int blkid_probe_value_set_data(struct blkid_prval *v,
 }
 
 int blkid_probe_set_value(blkid_probe pr, const char *name,
-               unsigned char *data, size_t len)
+               const unsigned char *data, size_t len)
 {
        struct blkid_prval *v;
 
@@ -1525,7 +1525,7 @@ int blkid_probe_sprintf_value(blkid_probe pr, const char *name,
 }
 
 int blkid_probe_set_magic(blkid_probe pr, uint64_t offset,
-                       size_t len, unsigned char *magic)
+                       size_t len, const unsigned char *magic)
 {
        int rc = 0;
        struct blkid_chain *chn = blkid_probe_get_chain(pr);
index 032839d7e4adadc8b1e38d5b42d6ea8a25127db3..111edf39bc64ac63feb28443b9a131e812fc91f2 100644 (file)
@@ -82,7 +82,7 @@ static int get_bitlocker_headers(blkid_probe pr,
 {
 
        const unsigned char *buf;
-       struct bde_fve_metadata *fve;
+       const struct bde_fve_metadata *fve;
        uint64_t off = 0;
        int kind;
 
@@ -102,10 +102,10 @@ static int get_bitlocker_headers(blkid_probe pr,
        /* Check BitLocker header */
        switch (kind) {
        case BDE_VERSION_WIN7:
-               off = le64_to_cpu(((struct bde_header_win7 *) buf)->fve_metadata_offset);
+               off = le64_to_cpu(((const struct bde_header_win7 *) buf)->fve_metadata_offset);
                break;
        case BDE_VERSION_TOGO:
-               off = le64_to_cpu(((struct bde_header_togo *) buf)->fve_metadata_offset);
+               off = le64_to_cpu(((const struct bde_header_togo *) buf)->fve_metadata_offset);
                break;
        case BDE_VERSION_VISTA:
                goto done;
@@ -123,7 +123,7 @@ static int get_bitlocker_headers(blkid_probe pr,
        if (!buf)
                return errno ? -errno : 1;
 
-       fve = (struct bde_fve_metadata *) buf;
+       fve = (const struct bde_fve_metadata *) buf;
        if (memcmp(fve->signature, BDE_MAGIC_FVE, sizeof(fve->signature)) != 0)
                goto nothing;
        if (buf_fve)
@@ -156,17 +156,17 @@ static int probe_bitlocker(blkid_probe pr,
                return rc;
 
        if (kind == BDE_VERSION_WIN7) {
-               struct bde_header_win7 *hdr = (struct bde_header_win7 *) buf_hdr;
+               const struct bde_header_win7 *hdr = (const struct bde_header_win7 *) buf_hdr;
 
                /* Unfortunately, it seems volume_serial is always zero */
                blkid_probe_sprintf_uuid(pr,
-                               (unsigned char *) &hdr->volume_serial,
+                               (const unsigned char *) &hdr->volume_serial,
                                sizeof(hdr->volume_serial),
                                "%016d", le32_to_cpu(hdr->volume_serial));
        }
 
        if (buf_fve) {
-               struct bde_fve_metadata *fve = (struct bde_fve_metadata *) buf_fve;
+               const struct bde_fve_metadata *fve = (const struct bde_fve_metadata *) buf_fve;
 
                blkid_probe_sprintf_version(pr, "%d", fve->version);
        }
index c47378d731fae43340039ea10a28cf40a63f4cac..d9771ba02f96258dc04eaa48ae74914fc24cc926 100644 (file)
@@ -18,8 +18,8 @@
 
 static int get_minix_version(const unsigned char *data, int *other_endian)
 {
-       struct minix_super_block *sb = (struct minix_super_block *) data;
-       struct minix3_super_block *sb3 = (struct minix3_super_block *) data;
+       const struct minix_super_block *sb = (const struct minix_super_block *) data;
+       const struct minix3_super_block *sb3 = (const struct minix3_super_block *) data;
        int version = 0;
        char *endian;
 
@@ -90,7 +90,7 @@ static int probe_minix(blkid_probe pr,
        switch (version) {
        case 1:
        case 2: {
-               struct minix_super_block *sb = (struct minix_super_block *) data;
+               const struct minix_super_block *sb = (const struct minix_super_block *) data;
 
                uint16_t state = minix_swab16(swabme, sb->s_state);
                if ((state & (MINIX_VALID_FS | MINIX_ERROR_FS)) != state)
@@ -106,7 +106,7 @@ static int probe_minix(blkid_probe pr,
                break;
        }
        case 3: {
-               struct minix3_super_block *sb = (struct minix3_super_block *) data;
+               const struct minix3_super_block *sb = (const struct minix3_super_block *) data;
 
                zones = minix_swab32(swabme, sb->s_zones);
                ninodes = minix_swab32(swabme, sb->s_ninodes);
index 96c7df9aa3c01143a0932ce7a0b416be854675b6..7fdee2b38c03be2acb886924ca18b002fe273c44 100644 (file)
@@ -76,10 +76,10 @@ static int probe_stratis(blkid_probe pr,
                                (buf + SECOND_COPY_OFFSET);
        }
 
-       blkid_probe_strncpy_uuid(pr, (unsigned char *)stratis->dev_uuid,
+       blkid_probe_strncpy_uuid(pr, stratis->dev_uuid,
                                        sizeof(stratis->dev_uuid));
        blkid_probe_set_value(pr, "POOL_UUID",
-                               (unsigned char *)stratis->pool_uuid,
+                               stratis->pool_uuid,
                                sizeof(stratis->pool_uuid));
 
        blkid_probe_sprintf_value(pr, "BLOCKDEV_SECTORS", "%" PRIu64,
index e95c1e626b95edf46873256faa1e5be12e299831..70d4c2697af2551555d46fd59da841ba784511c2 100644 (file)
@@ -417,7 +417,7 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)
                /* all checks passed */
                if (chn->flags & BLKID_SUBLKS_TYPE)
                        rc = blkid_probe_set_value(pr, "TYPE",
-                               (unsigned char *) id->name,
+                               (const unsigned char *) id->name,
                                strlen(id->name) + 1);
 
                if (!rc)
@@ -425,7 +425,7 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)
 
                if (!rc && mag)
                        rc = blkid_probe_set_magic(pr, off, mag->len,
-                                       (unsigned char *) mag->magic);
+                                       (const unsigned char *) mag->magic);
                if (rc) {
                        blkid_probe_chain_reset_values(pr, chn);
                        DBG(LOWPROBE, ul_debug("failed to set result -- ignore"));
@@ -531,7 +531,8 @@ int blkid_probe_set_version(blkid_probe pr, const char *version)
 
        if (chn->flags & BLKID_SUBLKS_VERSION)
                return blkid_probe_set_value(pr, "VERSION",
-                          (unsigned char *) version, strlen(version) + 1);
+                               (const unsigned char *) version,
+                               strlen(version) + 1);
        return 0;
 }
 
@@ -574,7 +575,7 @@ static int blkid_probe_set_usage(blkid_probe pr, int usage)
 }
 
 int blkid_probe_set_id_label(blkid_probe pr, const char *name,
-                            unsigned char *data, size_t len)
+                            const unsigned char *data, size_t len)
 {
        struct blkid_chain *chn = blkid_probe_get_chain(pr);
        struct blkid_prval *v;
@@ -603,7 +604,7 @@ int blkid_probe_set_id_label(blkid_probe pr, const char *name,
 }
 
 int blkid_probe_set_utf8_id_label(blkid_probe pr, const char *name,
-                            unsigned char *data, size_t len, int enc)
+                            const unsigned char *data, size_t len, int enc)
 {
        struct blkid_chain *chn = blkid_probe_get_chain(pr);
        struct blkid_prval *v;
@@ -633,7 +634,7 @@ int blkid_probe_set_utf8_id_label(blkid_probe pr, const char *name,
        return rc;
 }
 
-int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len)
+int blkid_probe_set_label(blkid_probe pr, const unsigned char *label, size_t len)
 {
        struct blkid_chain *chn = blkid_probe_get_chain(pr);
        struct blkid_prval *v;
@@ -661,7 +662,7 @@ int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len)
        return rc;
 }
 
-int blkid_probe_set_utf8label(blkid_probe pr, unsigned char *label,
+int blkid_probe_set_utf8label(blkid_probe pr, const unsigned char *label,
                                size_t len, int enc)
 {
        struct blkid_chain *chn = blkid_probe_get_chain(pr);
@@ -693,7 +694,7 @@ int blkid_probe_set_utf8label(blkid_probe pr, unsigned char *label,
        return rc;
 }
 
-int blkid_probe_sprintf_uuid(blkid_probe pr, unsigned char *uuid,
+int blkid_probe_sprintf_uuid(blkid_probe pr, const unsigned char *uuid,
                                size_t len, const char *fmt, ...)
 {
        struct blkid_chain *chn = blkid_probe_get_chain(pr);
@@ -718,7 +719,7 @@ int blkid_probe_sprintf_uuid(blkid_probe pr, unsigned char *uuid,
 }
 
 /* function to set UUIDs that are in superblocks stored as strings */
-int blkid_probe_strncpy_uuid(blkid_probe pr, unsigned char *str, size_t len)
+int blkid_probe_strncpy_uuid(blkid_probe pr, const unsigned char *str, size_t len)
 {
        struct blkid_chain *chn = blkid_probe_get_chain(pr);
        struct blkid_prval *v;
@@ -728,7 +729,7 @@ int blkid_probe_strncpy_uuid(blkid_probe pr, unsigned char *str, size_t len)
                return -EINVAL;
 
        if (!len)
-               len = strlen((char *) str);
+               len = strlen((const char *) str);
 
        if ((chn->flags & BLKID_SUBLKS_UUIDRAW) &&
            (rc = blkid_probe_set_value(pr, "UUID_RAW", str, len)) < 0)
@@ -753,7 +754,7 @@ int blkid_probe_strncpy_uuid(blkid_probe pr, unsigned char *str, size_t len)
 }
 
 /* default _set_uuid function to set DCE UUIDs */
-int blkid_probe_set_uuid_as(blkid_probe pr, unsigned char *uuid, const char *name)
+int blkid_probe_set_uuid_as(blkid_probe pr, const unsigned char *uuid, const char *name)
 {
        struct blkid_chain *chn = blkid_probe_get_chain(pr);
        struct blkid_prval *v;
@@ -791,7 +792,7 @@ int blkid_probe_set_uuid_as(blkid_probe pr, unsigned char *uuid, const char *nam
        return rc;
 }
 
-int blkid_probe_set_uuid(blkid_probe pr, unsigned char *uuid)
+int blkid_probe_set_uuid(blkid_probe pr, const unsigned char *uuid)
 {
        return blkid_probe_set_uuid_as(pr, uuid, NULL);
 }
index 85858b9fc52cb070e03321fc386033905c5a578a..11c16e4b4e0f000834e83c3ac5518c110f811778 100644 (file)
@@ -91,21 +91,21 @@ extern int blkid_probe_set_version(blkid_probe pr, const char *version);
 extern int blkid_probe_sprintf_version(blkid_probe pr, const char *fmt, ...)
                __attribute__ ((__format__ (__printf__, 2, 3)));
 
-extern int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len);
-extern int blkid_probe_set_utf8label(blkid_probe pr, unsigned char *label,
+extern int blkid_probe_set_label(blkid_probe pr, const unsigned char *label, size_t len);
+extern int blkid_probe_set_utf8label(blkid_probe pr, const unsigned char *label,
                 size_t len, int enc);
-extern int blkid_probe_sprintf_uuid(blkid_probe pr, unsigned char *uuid,
+extern int blkid_probe_sprintf_uuid(blkid_probe pr, const unsigned char *uuid,
                 size_t len, const char *fmt, ...)
                __attribute__ ((__format__ (__printf__, 4, 5)));
-extern int blkid_probe_strncpy_uuid(blkid_probe pr, unsigned char *str, size_t len);
+extern int blkid_probe_strncpy_uuid(blkid_probe pr, const unsigned char *str, size_t len);
 
-extern int blkid_probe_set_uuid(blkid_probe pr, unsigned char *uuid);
-extern int blkid_probe_set_uuid_as(blkid_probe pr, unsigned char *uuid, const char *name);
+extern int blkid_probe_set_uuid(blkid_probe pr, const unsigned char *uuid);
+extern int blkid_probe_set_uuid_as(blkid_probe pr, const unsigned char *uuid, const char *name);
 
 extern int blkid_probe_set_id_label(blkid_probe pr, const char *name,
-                            unsigned char *data, size_t len);
+                            const unsigned char *data, size_t len);
 extern int blkid_probe_set_utf8_id_label(blkid_probe pr, const char *name,
-                            unsigned char *data, size_t len, int enc);
+                            const unsigned char *data, size_t len, int enc);
 
 extern int blkid_probe_is_bitlocker(blkid_probe pr);
 
index f4628da4a5697291c03feca731f64053f8a6b95c..5061587ad806276cd66c78245d4cc3d4d47e64fa 100644 (file)
@@ -426,10 +426,10 @@ static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag)
        }
 
        if (boot_label && memcmp(boot_label, no_name, 11))
-               blkid_probe_set_id_label(pr, "LABEL_FATBOOT", (unsigned char *) boot_label, 11);
+               blkid_probe_set_id_label(pr, "LABEL_FATBOOT", boot_label, 11);
 
        if (vol_label)
-               blkid_probe_set_label(pr, (unsigned char *) vol_label, 11);
+               blkid_probe_set_label(pr, vol_label, 11);
 
        /* We can't just print them as %04X, because they are unaligned */
        if (vol_serno)
index ec3e1c5bf4fcb7adb70d244f62650f80c959a65d..1292b303be8520cbba4341c70cd0ce7e79a1c729 100644 (file)
@@ -186,12 +186,12 @@ static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
 static int find_uberblocks(const void *label, loff_t *ub_offset, int *swap_endian)
 {
        uint64_t swab_magic = swab64((uint64_t)UBERBLOCK_MAGIC);
-       struct zfs_uberblock *ub;
+       const struct zfs_uberblock *ub;
        int i, found = 0;
        loff_t offset = VDEV_LABEL_UBERBLOCK;
 
        for (i = 0; i < UBERBLOCKS_COUNT; i++, offset += UBERBLOCK_SIZE) {
-               ub = (struct zfs_uberblock *)((char *) label + offset);
+               ub = (const struct zfs_uberblock *)((const char *) label + offset);
 
                if (ub->ub_magic == UBERBLOCK_MAGIC) {
                        *ub_offset = offset;
index e061632cadd507d55dc6b540e36d34e53c3cb5c5..37fce6d6294a212bb5060ed38e6a5d0c1ac89738 100644 (file)
@@ -35,7 +35,7 @@ static int probe_dm_tp(blkid_probe pr,
                "/sbin/dmsetup"
        };
        int dmpipe[] = { -1, -1 }, stripes, stripesize;
-       char *cmd = NULL;
+       const char *cmd = NULL;
        FILE *stream = NULL;
        long long  offset, size;
        size_t i;
@@ -49,7 +49,7 @@ static int probe_dm_tp(blkid_probe pr,
        for (i = 0; i < ARRAY_SIZE(paths); i++) {
                struct stat sb;
                if (stat(paths[i], &sb) == 0) {
-                       cmd = (char *) paths[i];
+                       cmd = paths[i];
                        break;
                }
        }
@@ -64,7 +64,8 @@ static int probe_dm_tp(blkid_probe pr,
        switch (fork()) {
        case 0:
        {
-               char *dmargv[7], maj[16], min[16];
+               const char *dmargv[7];
+               char maj[16], min[16];
 
                /* Plumbing */
                close(dmpipe[0]);
@@ -89,7 +90,7 @@ static int probe_dm_tp(blkid_probe pr,
                dmargv[5] = min;
                dmargv[6] = NULL;
 
-               execv(dmargv[0], dmargv);
+               execv(dmargv[0], (char * const *) dmargv);
 
                DBG(LOWPROBE, ul_debug("Failed to execute %s: errno=%d", cmd, errno));
                exit(1);