libblkid: const qualifier cleanup

* 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>
This commit is contained in:
Karel Zak 2018-07-20 15:03:01 +02:00
parent 34708190d1
commit 47afae0caa
12 changed files with 57 additions and 55 deletions

View 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;

View 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)

View 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));

View 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);

View 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);
}

View 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);

View 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,

View 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);
}

View 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);

View 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)

View 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;

View 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);