size_t len, unsigned char *magic)
__attribute__((nonnull));
+extern int blkid_probe_verify_csum(blkid_probe pr, uint64_t csum, uint64_t expected)
+ __attribute__((nonnull));
+
extern void blkid_unparse_uuid(const unsigned char *uuid, char *str, size_t len)
__attribute__((nonnull));
extern int blkid_uuid_is_empty(const unsigned char *buf, size_t len);
return pr->cur_chain;
}
+static const char *blkid_probe_get_probername(blkid_probe pr)
+{
+ struct blkid_chain *chn = blkid_probe_get_chain(pr);
+
+ if (chn && chn->idx >= 0 && chn->idx < chn->driver->nidinfos)
+ return chn->driver->idinfos[chn->idx]->name;
+
+ return NULL;
+}
+
void *blkid_probe_get_binary_data(blkid_probe pr, struct blkid_chain *chn)
{
int rc, org_prob_flags;
return rc;
}
+int blkid_probe_verify_csum(blkid_probe pr, uint64_t csum, uint64_t expected)
+{
+ if (csum != expected) {
+ DBG(LOWPROBE, blkid_debug(
+ "incorrect checksum for type %s,"
+ " got %jX, expected %jX",
+ blkid_probe_get_probername(pr),
+ csum, expected));
+ return 0;
+ }
+
+ return 1;
+}
+
/**
* blkid_probe_get_devno:
* @pr: probe
if (le64_to_cpu(label->sector_xl) != (unsigned) sector)
return 1;
- if (lvm2_calc_crc(&label->offset_xl, LVM2_LABEL_SIZE -
- ((char *) &label->offset_xl - (char *) label)) !=
- le32_to_cpu(label->crc_xl)) {
- DBG(PROBE, blkid_debug("LVM2: label checksum incorrect at sector %d",
- sector));
+ if (!blkid_probe_verify_csum(
+ pr, lvm2_calc_crc(
+ &label->offset_xl, LVM2_LABEL_SIZE -
+ ((char *) &label->offset_xl - (char *) label)),
+ le32_to_cpu(label->crc_xl)))
return 1;
- }
format_lvm_uuid(uuid, (char *) label->pv_uuid);
blkid_probe_sprintf_uuid(pr, label->pv_uuid, sizeof(label->pv_uuid),
crc = crc32(crc, sum, 4);
crc = crc32(crc, (unsigned char *)sb + sumoff + 4, bytes - sumoff - 4);
- if (crc != le32_to_cpu(sb->s_sum))
- return -1;
+ if (!blkid_probe_verify_csum(pr, crc, le32_to_cpu(sb->s_sum)))
+ return 1;
if (strlen(sb->s_volume_name))
blkid_probe_set_label(pr, (unsigned char *) sb->s_volume_name,
#define SILICON_MAGIC 0x2F000000
-static int checksum(struct silicon_metadata *sil)
+static uint16_t silraid_checksum(struct silicon_metadata *sil)
{
int sum = 0;
unsigned short count = offsetof(struct silicon_metadata, checksum1) / 2;
sum += le16_to_cpu(x);
}
- return (-sum & 0xFFFF) == le16_to_cpu(sil->checksum1);
+ return (-sum & 0xFFFF);
}
static int probe_silraid(blkid_probe pr,
return 1;
if (sil->disk_number >= 8)
return 1;
- if (!checksum(sil)) {
- DBG(LOWPROBE, blkid_debug("silicon raid: incorrect checksum"));
+ if (!blkid_probe_verify_csum(pr, silraid_checksum(sil), le16_to_cpu(sil->checksum1)))
return 1;
- }
if (blkid_probe_sprintf_version(pr, "%u.%u",
le16_to_cpu(sil->major_ver),
while (i--)
cs += ((uint8_t*) v)[i];
- return cs == v->checksum;
+ return cs;
}
static int probe_viaraid(blkid_probe pr,
return 1;
if (v->version_number > 2)
return 1;
- if (!via_checksum(v))
+ if (!blkid_probe_verify_csum(pr, via_checksum(v), v->checksum))
return 1;
if (blkid_probe_sprintf_version(pr, "%u", v->version_number) != 0)