]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: constify cached disk data
authorThomas Weißschuh <thomas@t-8ch.de>
Thu, 18 May 2023 20:37:10 +0000 (22:37 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Thu, 18 May 2023 22:00:34 +0000 (00:00 +0200)
The data returned from blkid_probe_get_buffer() and friends may or may
not be cached between different calls.
If one copy is modified this may not be visible in other copies.

This issue can be avoided by making any modification illegal.

See also #2165

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
31 files changed:
include/pt-mbr.h
libblkid/src/blkidP.h
libblkid/src/partitions/bsd.c
libblkid/src/partitions/dos.c
libblkid/src/partitions/gpt.c
libblkid/src/partitions/mac.c
libblkid/src/partitions/minix.c
libblkid/src/partitions/ultrix.c
libblkid/src/probe.c
libblkid/src/superblocks/bcache.c
libblkid/src/superblocks/befs.c
libblkid/src/superblocks/cramfs.c
libblkid/src/superblocks/ddf_raid.c
libblkid/src/superblocks/erofs.c
libblkid/src/superblocks/exfat.c
libblkid/src/superblocks/f2fs.c
libblkid/src/superblocks/hfs.c
libblkid/src/superblocks/iso9660.c
libblkid/src/superblocks/linux_raid.c
libblkid/src/superblocks/lvm.c
libblkid/src/superblocks/minix.c
libblkid/src/superblocks/ntfs.c
libblkid/src/superblocks/ocfs.c
libblkid/src/superblocks/romfs.c
libblkid/src/superblocks/stratis.c
libblkid/src/superblocks/swap.c
libblkid/src/superblocks/vfat.c
libblkid/src/superblocks/vmfs.c
libblkid/src/superblocks/xfs.c
libblkid/src/superblocks/zfs.c
libfdisk/src/dos.c

index 93a6def6a6cb57bac1f60633c8f81458d9beed5b..81b2aee80e7f6cdf4569f79c377ed425530d3dca 100644 (file)
@@ -19,7 +19,7 @@ struct dos_partition {
 #define MBR_PT_OFFSET          0x1be
 #define MBR_PT_BOOTBITS_SIZE   440
 
-static inline struct dos_partition *mbr_get_partition(unsigned char *mbr, int i)
+static inline struct dos_partition *mbr_get_partition(const unsigned char *mbr, int i)
 {
        return (struct dos_partition *)
                (mbr + MBR_PT_OFFSET + (i * sizeof(struct dos_partition)));
@@ -42,7 +42,7 @@ static inline void __dos_store_4le(unsigned char *p, unsigned int val)
        p[3] = ((val >> 24) & 0xff);
 }
 
-static inline unsigned int dos_partition_get_start(struct dos_partition *p)
+static inline unsigned int dos_partition_get_start(const struct dos_partition *p)
 {
        return __dos_assemble_4le(&(p->start_sect[0]));
 }
@@ -52,7 +52,7 @@ static inline void dos_partition_set_start(struct dos_partition *p, unsigned int
        __dos_store_4le(p->start_sect, n);
 }
 
-static inline unsigned int dos_partition_get_size(struct dos_partition *p)
+static inline unsigned int dos_partition_get_size(const struct dos_partition *p)
 {
        return __dos_assemble_4le(&(p->nr_sects[0]));
 }
index 007cc357b12dc96a5265093810e7817ac359dc87..088a8a4c94b67c2053313c5793d963483814f14d 100644 (file)
@@ -412,12 +412,12 @@ extern int blkdid_probe_is_opal_locked(blkid_probe pr)
                        __attribute__((nonnull))
                        __attribute__((warn_unused_result));
 
-extern unsigned char *blkid_probe_get_buffer(blkid_probe pr,
+extern const unsigned char *blkid_probe_get_buffer(blkid_probe pr,
                                 uint64_t off, uint64_t len)
                        __attribute__((nonnull))
                        __attribute__((warn_unused_result));
 
-extern unsigned char *blkid_probe_get_sector(blkid_probe pr, unsigned int sector)
+extern const unsigned char *blkid_probe_get_sector(blkid_probe pr, unsigned int sector)
                        __attribute__((nonnull))
                        __attribute__((warn_unused_result));
 
@@ -434,7 +434,7 @@ extern int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo *id,
                        __attribute__((nonnull(1)));
 
 /* returns superblock according to 'struct blkid_idmag' */
-extern unsigned char *blkid_probe_get_sb_buffer(blkid_probe pr, const struct blkid_idmag *mag, size_t size);
+extern const unsigned char *blkid_probe_get_sb_buffer(blkid_probe pr, const struct blkid_idmag *mag, size_t size);
 #define blkid_probe_get_sb(_pr, _mag, type) \
                        ((type *) blkid_probe_get_sb_buffer((_pr), _mag, sizeof(type)))
 
index ba120195ea08bc9a1aa988de02aa5fdeb797e7ce..20dab6b3e3359342becdc220dc1713acc033110f 100644 (file)
@@ -47,7 +47,7 @@ static int probe_bsd_pt(blkid_probe pr, const struct blkid_idmag *mag)
        blkid_partition parent;
        blkid_partlist ls;
        int i, nparts = BSD_MAXPARTITIONS;
-       unsigned char *data;
+       const unsigned char *data;
        int rc = BLKID_PROBE_NONE;
        uint32_t abs_offset = 0;
 
index 5c7718c3e221db9aa32f165e60a2a91363708e35..d5a8aa3ae03a140fbd82d6b2f8c22377e68fe91f 100644 (file)
@@ -34,7 +34,7 @@ static const struct dos_subtypes {
        { MBR_MINIX_PARTITION, &minix_pt_idinfo }
 };
 
-static inline int is_extended(struct dos_partition *p)
+static inline int is_extended(const struct dos_partition *p)
 {
        return (p->sys_ind == MBR_DOS_EXTENDED_PARTITION ||
                p->sys_ind == MBR_W95_EXTENDED_PARTITION ||
@@ -46,7 +46,7 @@ static int parse_dos_extended(blkid_probe pr, blkid_parttable tab,
 {
        blkid_partlist ls = blkid_probe_get_partlist(pr);
        uint32_t cur_start = ex_start, cur_size = ex_size;
-       unsigned char *data;
+       const unsigned char *data;
        int ct_nodata = 0;      /* count ext.partitions without data partitions */
        int i;
 
@@ -57,7 +57,7 @@ static int parse_dos_extended(blkid_probe pr, blkid_parttable tab,
        }
 
        while (1) {
-               struct dos_partition *p, *p0;
+               const struct dos_partition *p, *p0;
                uint32_t start = 0, size;
 
                if (++ct_nodata > 100)
@@ -156,9 +156,9 @@ static inline int is_lvm(blkid_probe pr)
        return (v && v->data && strcmp((char *) v->data, "LVM2_member") == 0);
 }
 
-static inline int is_empty_mbr(unsigned char *mbr)
+static inline int is_empty_mbr(const unsigned char *mbr)
 {
-       struct dos_partition *p = mbr_get_partition(mbr, 0);
+       const struct dos_partition *p = mbr_get_partition(mbr, 0);
        int i, nparts = 0;
 
        for (i = 0; i < 4; i++) {
@@ -177,8 +177,8 @@ static int probe_dos_pt(blkid_probe pr,
        int ssf;
        blkid_parttable tab = NULL;
        blkid_partlist ls;
-       struct dos_partition *p0, *p;
-       unsigned char *data;
+       const struct dos_partition *p0, *p;
+       const unsigned char *data;
        uint32_t start, size, id;
        char idstr[UUID_STR_LEN];
 
index 89e7bb679b9d2245b6746df45f749a9186f57aa9..473bf5c0e21b7fcd7d3429c131317a917f2ac2fb 100644 (file)
@@ -109,7 +109,7 @@ static inline uint32_t count_crc32(const unsigned char *buf, size_t len,
        return (ul_crc32_exclude_offset(~0L, buf, len, exclude_off, exclude_len) ^ ~0L);
 }
 
-static inline unsigned char *get_lba_buffer(blkid_probe pr,
+static inline const unsigned char *get_lba_buffer(blkid_probe pr,
                                        uint64_t lba, size_t bytes)
 {
        return blkid_probe_get_buffer(pr,
@@ -161,8 +161,8 @@ static int last_lba(blkid_probe pr, uint64_t *lba)
 static int is_pmbr_valid(blkid_probe pr, int *has)
 {
        int flags = blkid_partitions_get_flags(pr);
-       unsigned char *data;
-       struct dos_partition *p;
+       const unsigned char *data;
+       const struct dos_partition *p;
        int i;
 
        if (has)
index 75a558b0a3d52893057b52afc97964731e859f6c..36ce74ed3fbb070309865ab954410207dea7a109 100644 (file)
@@ -56,7 +56,7 @@ struct mac_driver_desc {
        /* there is more stuff after this that we don't need */
 } __attribute__((packed));
 
-static inline unsigned char *get_mac_block(
+static inline const unsigned char *get_mac_block(
                                        blkid_probe pr,
                                        uint16_t block_size,
                                        uint32_t num)
index 43c9d9af10e5f3c95b2a2053640466b7d5661e18..dee7df95b95e9d1d53338fb5da7b44f57e54e6fc 100644 (file)
 static int probe_minix_pt(blkid_probe pr,
                const struct blkid_idmag *mag __attribute__((__unused__)))
 {
-       struct dos_partition *p;
+       const struct dos_partition *p;
        blkid_parttable tab = NULL;
        blkid_partition parent;
        blkid_partlist ls;
-       unsigned char *data;
+       const unsigned char *data;
        int i;
 
        data = blkid_probe_get_sector(pr, 0);
index 9c060be1df4a8c39038fece88f0b609c8482d519..a85712fad52e991e4607aece144ee8d72bd757b2 100644 (file)
@@ -37,8 +37,8 @@ struct ultrix_disklabel {
 static int probe_ultrix_pt(blkid_probe pr,
                const struct blkid_idmag *mag __attribute__((__unused__)))
 {
-       unsigned char *data;
-       struct ultrix_disklabel *l;
+       const unsigned char *data;
+       const struct ultrix_disklabel *l;
        blkid_parttable tab = NULL;
        blkid_partlist ls;
        int i;
@@ -50,7 +50,7 @@ static int probe_ultrix_pt(blkid_probe pr,
                goto nothing;
        }
 
-       l = (struct ultrix_disklabel *) (data + ULTRIX_OFFSET);
+       l = (const struct ultrix_disklabel *) (data + ULTRIX_OFFSET);
 
        if (l->pt_magic != ULTRIX_MAGIC || l->pt_valid != 1)
                goto nothing;
index b4299493fb344e2f6f659f0e671a51bfca793267..fdad0c2661549166a1b30cc08086b29c69552b7c 100644 (file)
@@ -669,7 +669,7 @@ static int hide_buffer(blkid_probe pr, uint64_t off, uint64_t len)
  * Note that @off is offset within probing area, the probing area is defined by
  * pr->off and pr->size.
  */
-unsigned char *blkid_probe_get_buffer(blkid_probe pr, uint64_t off, uint64_t len)
+const unsigned char *blkid_probe_get_buffer(blkid_probe pr, uint64_t off, uint64_t len)
 {
        struct blkid_bufinfo *bf = NULL;
        uint64_t real_off = pr->off + off;
@@ -1136,7 +1136,7 @@ int blkid_probe_set_dimension(blkid_probe pr, uint64_t off, uint64_t size)
        return 0;
 }
 
-unsigned char *blkid_probe_get_sb_buffer(blkid_probe pr, const struct blkid_idmag *mag, size_t size)
+const unsigned char *blkid_probe_get_sb_buffer(blkid_probe pr, const struct blkid_idmag *mag, size_t size)
 {
        uint64_t hint_offset;
 
@@ -1164,7 +1164,7 @@ int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo *id,
 
        /* try to detect by magic string */
        while(mag && mag->magic) {
-               unsigned char *buf;
+               const unsigned char *buf;
                uint64_t kboff;
                uint64_t hint_offset;
 
@@ -1690,7 +1690,7 @@ done:
 }
 
 /* same sa blkid_probe_get_buffer() but works with 512-sectors */
-unsigned char *blkid_probe_get_sector(blkid_probe pr, unsigned int sector)
+const unsigned char *blkid_probe_get_sector(blkid_probe pr, unsigned int sector)
 {
        return blkid_probe_get_buffer(pr, ((uint64_t) sector) << 9, 0x200);
 }
index 7e8d78db533fdca7a72553ee14d06af596deac1c..c8ac52425e10641c63ee06437b09d7b981df9148 100644 (file)
@@ -118,7 +118,7 @@ struct bcachefs_super_block {
 static int bcache_verify_checksum(blkid_probe pr, const struct blkid_idmag *mag,
                const struct bcache_super_block *bcs)
 {
-       unsigned char *csummed = blkid_probe_get_sb_buffer(pr, mag, BCACHE_SB_CSUMMED_END);
+       const unsigned char *csummed = blkid_probe_get_sb_buffer(pr, mag, BCACHE_SB_CSUMMED_END);
        uint64_t csum = ul_crc64_we(csummed + BCACHE_SB_CSUMMED_START,
                        BCACHE_SB_CSUMMED_END - BCACHE_SB_CSUMMED_START);
        return blkid_probe_verify_csum(pr, csum, le64_to_cpu(bcs->csum));
@@ -168,7 +168,7 @@ static void probe_bcachefs_sb_members(blkid_probe pr,
        blkid_probe_set_fssize(pr, sectors * BCACHEFS_SECTOR_SIZE);
 }
 
-static int is_within_range(void *start, uint64_t size, void *end)
+static int is_within_range(const void *start, uint64_t size, const void *end)
 {
        ptrdiff_t diff;
 
@@ -180,9 +180,9 @@ static int is_within_range(void *start, uint64_t size, void *end)
 }
 
 static void probe_bcachefs_sb_fields(blkid_probe pr, const struct bcachefs_super_block *bcs,
-                                    unsigned char *sb_start, unsigned char *sb_end)
+                                    const unsigned char *sb_start, const unsigned char *sb_end)
 {
-       unsigned char *field_addr = sb_start + BCACHEFS_SB_FIELDS_OFF;
+       const unsigned char *field_addr = sb_start + BCACHEFS_SB_FIELDS_OFF;
 
        while (1) {
                struct bcachefs_sb_field *field = (struct bcachefs_sb_field *) field_addr;
@@ -212,10 +212,10 @@ static void probe_bcachefs_sb_fields(blkid_probe pr, const struct bcachefs_super
 }
 
 static int bcachefs_validate_checksum(blkid_probe pr, const struct bcachefs_super_block *bcs,
-                                     unsigned char *sb, unsigned char *sb_end)
+                                     const unsigned char *sb, const unsigned char *sb_end)
 {
        uint8_t checksum_type = be64_to_cpu(bcs->flags[0]) >> 58;
-       unsigned char *checksummed_data_start = sb + sizeof(bcs->csum);
+       const unsigned char *checksummed_data_start = sb + sizeof(bcs->csum);
        size_t checksummed_data_size = sb_end - checksummed_data_start;
 
        switch (checksum_type) {
@@ -242,7 +242,7 @@ static int bcachefs_validate_checksum(blkid_probe pr, const struct bcachefs_supe
 static int probe_bcachefs(blkid_probe pr, const struct blkid_idmag *mag)
 {
        struct bcachefs_super_block *bcs;
-       unsigned char *sb, *sb_end;
+       const unsigned char *sb, *sb_end;
        uint64_t sb_size, blocksize;
 
        bcs = blkid_probe_get_sb(pr, mag, struct bcachefs_super_block);
index 5112d44f49aa07ae0229a88dfd525fe211f7fb67..d501eb105d4b3dafc6a5992467917b10605e2fba 100644 (file)
@@ -122,7 +122,7 @@ struct bplustree_node {
        char            name[0];
 } __attribute__((packed));
 
-static unsigned char *get_block_run(blkid_probe pr, const struct befs_super_block *bs,
+static const unsigned char *get_block_run(blkid_probe pr, const struct befs_super_block *bs,
                                        const struct block_run *br, int fs_le)
 {
        return blkid_probe_get_buffer(pr,
@@ -135,7 +135,7 @@ static unsigned char *get_block_run(blkid_probe pr, const struct befs_super_bloc
                                        << FS32_TO_CPU(bs->block_shift, fs_le));
 }
 
-static unsigned char *get_custom_block_run(blkid_probe pr,
+static const unsigned char *get_custom_block_run(blkid_probe pr,
                                const struct befs_super_block *bs,
                                const struct block_run *br,
                                int64_t offset, uint32_t length, int fs_le)
@@ -154,7 +154,7 @@ static unsigned char *get_custom_block_run(blkid_probe pr,
                        length);
 }
 
-static unsigned char *get_tree_node(blkid_probe pr, const struct befs_super_block *bs,
+static const unsigned char *get_tree_node(blkid_probe pr, const struct befs_super_block *bs,
                                const struct data_stream *ds,
                                int64_t start, uint32_t length, int fs_le)
 {
index 2a87acdaa1a95950e7aa25e706416064c064ce9e..81aa377c485575581d97b181f0cb044d5b5c19f2 100644 (file)
@@ -55,7 +55,7 @@ static int cramfs_verify_csum(blkid_probe pr, const struct blkid_idmag *mag,
                struct cramfs_super *cs, int le)
 {
        uint32_t crc, expected, csummed_size;
-       unsigned char *csummed;
+       const unsigned char *csummed;
 
        expected = cfs32_to_cpu(le, cs->info.crc);
        csummed_size = cfs32_to_cpu(le, cs->size);
@@ -67,9 +67,10 @@ static int cramfs_verify_csum(blkid_probe pr, const struct blkid_idmag *mag,
        csummed = blkid_probe_get_sb_buffer(pr, mag, csummed_size);
        if (!csummed)
                return 0;
-       memset(csummed + offsetof(struct cramfs_super, info.crc), 0, sizeof(uint32_t));
 
-       crc = ~ul_crc32(~0LL, csummed, csummed_size);
+       crc = ~ul_crc32_exclude_offset(~0LL, csummed, csummed_size,
+                       offsetof(struct cramfs_super, info.crc),
+                       sizeof_member(struct cramfs_super, info.crc));
 
        return blkid_probe_verify_csum(pr, crc, expected);
 }
index 0b82e73eb69ae4789ead8fd24efb00b8d2946623..66b49396ac15f56bd4d48d23915b3093a7615058 100644 (file)
@@ -106,7 +106,7 @@ static int probe_ddf(blkid_probe pr,
 
        if (lba > 0) {
                /* check primary header */
-               unsigned char *buf;
+               const unsigned char *buf;
 
                buf = blkid_probe_get_buffer(pr,
                                        lba << 9, sizeof(ddf->signature));
index 14d272efef633d5035d281f0d1392d5b4c234b3e..672cd7fdc020eb1767d6248955cf3c5950b77b83 100644 (file)
@@ -46,7 +46,7 @@ static int erofs_verify_checksum(blkid_probe pr, const struct blkid_idmag *mag,
 {
        uint32_t expected, csum;
        size_t csummed_size;
-       unsigned char *csummed;
+       const unsigned char *csummed;
 
        if (!(le32_to_cpu(sb->feature_compat) & EROFS_FEATURE_SB_CSUM))
                return 1;
index 3703404874d7caa4ed1ef4f2344ec302fea918d6..554868f4f842fe1f9b695db4cb6e80fc21f20582 100644 (file)
@@ -119,7 +119,7 @@ static struct exfat_entry_label *find_label(blkid_probe pr,
 }
 
 /* From https://docs.microsoft.com/en-us/windows/win32/fileio/exfat-specification#34-main-and-backup-boot-checksum-sub-regions */
-static uint32_t exfat_boot_checksum(unsigned char *sectors,
+static uint32_t exfat_boot_checksum(const unsigned char *sectors,
                                    size_t sector_size)
 {
        uint32_t n_bytes = sector_size * 11;
@@ -141,7 +141,7 @@ static int exfat_validate_checksum(blkid_probe pr,
 {
        size_t sector_size = BLOCK_SIZE(sb);
        /* 11 sectors will be checksummed, the 12th contains the expected */
-       unsigned char *data = blkid_probe_get_buffer(pr, 0, sector_size * 12);
+       const unsigned char *data = blkid_probe_get_buffer(pr, 0, sector_size * 12);
        if (!data)
                return 0;
 
index 980111ef37b2021f06e42fc647dff296117527b2..5ee3442fc895022d8a87b23d08e540eb405047fd 100644 (file)
@@ -67,14 +67,14 @@ static int f2fs_validate_checksum(blkid_probe pr, size_t sb_off,
        if (csum_off + sizeof(uint32_t) > 4096)
                return 0;
 
-       unsigned char *csum_data = blkid_probe_get_buffer(pr,
+       const unsigned char *csum_data = blkid_probe_get_buffer(pr,
                        sb_off + csum_off, sizeof(uint32_t));
        if (!csum_data)
                return 0;
 
        uint32_t expected = le32_to_cpu(*(uint32_t *) csum_data);
 
-       unsigned char *csummed = blkid_probe_get_buffer(pr, sb_off, csum_off);
+       const unsigned char *csummed = blkid_probe_get_buffer(pr, sb_off, csum_off);
        if (!csummed)
                return 0;
 
index 68cb30edbbe14840e7226d78bf02b1ffd177fc48..184c98e0d9d2617f87b880b4709be69bf366f339 100644 (file)
@@ -183,11 +183,11 @@ static int probe_hfs(blkid_probe pr, const struct blkid_idmag *mag)
 static int probe_hfsplus(blkid_probe pr, const struct blkid_idmag *mag)
 {
        struct hfsplus_extent extents[HFSPLUS_EXTENT_COUNT];
-       struct hfsplus_bnode_descriptor *descr;
-       struct hfsplus_bheader_record *bnode;
-       struct hfsplus_catalog_key *key;
-       struct hfsplus_vol_header *hfsplus;
-       struct hfs_mdb *sbd;
+       const struct hfsplus_bnode_descriptor *descr;
+       const struct hfsplus_bheader_record *bnode;
+       const struct hfsplus_catalog_key *key;
+       const struct hfsplus_vol_header *hfsplus;
+       const struct hfs_mdb *sbd;
        unsigned int alloc_block_size;
        unsigned int alloc_first_block;
        unsigned int embed_first_block;
@@ -203,7 +203,7 @@ static int probe_hfsplus(blkid_probe pr, const struct blkid_idmag *mag)
        unsigned int leaf_block;
        int ext;
        uint64_t leaf_off;
-       unsigned char *buf;
+       const unsigned char *buf;
 
        sbd = blkid_probe_get_sb(pr, mag, struct hfs_mdb);
        if (!sbd)
@@ -225,7 +225,7 @@ static int probe_hfsplus(blkid_probe pr, const struct blkid_idmag *mag)
                buf = blkid_probe_get_buffer(pr,
                                off + (mag->kboff * 1024),
                                sizeof(struct hfsplus_vol_header));
-               hfsplus = (struct hfsplus_vol_header *) buf;
+               hfsplus = (const struct hfsplus_vol_header *) buf;
 
        } else
                hfsplus = blkid_probe_get_sb(pr, mag,
index 536704b4ebf437d086c5f31e17d708a3dcc196b0..dbed1628c06f5a96e1040bf1ffe9cab97d341f70 100644 (file)
@@ -232,7 +232,7 @@ static int probe_iso9660(blkid_probe pr, const struct blkid_idmag *mag)
                return probe_iso9660_hsfs(pr, mag);
 
        for (i = 0, off += ISO_SUPERBLOCK_OFFSET; i < ISO_VD_MAX && (!boot || !pvd || !joliet); i++, off += ISO_SECTOR_SIZE) {
-               unsigned char *desc =
+               const unsigned char *desc =
                        blkid_probe_get_buffer(pr,
                                        off,
                                        max(sizeof(struct boot_record),
index 360cd4eb3491559da6d18ff6c34d05a165332198..156b0bf488609f0bf96019ae99bfe519241df367 100644 (file)
@@ -187,15 +187,14 @@ static int raid1_verify_csum(blkid_probe pr, off_t off,
 {
        size_t csummed_size = sizeof(struct mdp1_super_block)
                + le32_to_cpu(mdp1->max_dev) * sizeof(mdp1->dev_roles[0]);
-       unsigned char *csummed = blkid_probe_get_buffer(pr, off, csummed_size);
+       const unsigned char *csummed = blkid_probe_get_buffer(pr, off, csummed_size);
        if (!csummed)
                return 1;
 
-       memset(csummed + offsetof(struct mdp1_super_block, sb_csum), 0,
-                       sizeof(mdp1->sb_csum));
-
        uint64_t csum = 0;
 
+       csum -= le32_to_cpu(*(uint32_t *) (csummed + offsetof(struct mdp1_super_block, sb_csum)));
+
        while (csummed_size >= 4) {
                csum += le32_to_cpu(*(uint32_t *) csummed);
                csummed_size -= 4;
index eea74d65763ad5368643565b1ddf4aa124212c9e..71ca132021f649a7ccf4e97c6a44213ea292d4de 100644 (file)
@@ -76,7 +76,7 @@ static int probe_lvm2(blkid_probe pr, const struct blkid_idmag *mag)
        int sector = mag->kboff << 1;
        struct lvm2_pv_label_header *label;
        char uuid[LVM2_ID_LEN + 7];
-       unsigned char *buf;
+       const unsigned char *buf;
 
        buf = blkid_probe_get_buffer(pr,
                        mag->kboff << 10,
index c68ade9c9309d8acdb9a91e2e764066d795337a0..dba299d235e74c4bc966f99a9fbfdf6cd575766b 100644 (file)
@@ -74,7 +74,7 @@ static int get_minix_version(const unsigned char *data, int *other_endian)
 static int probe_minix(blkid_probe pr,
                const struct blkid_idmag *mag __attribute__((__unused__)))
 {
-       unsigned char *ext;
+       const unsigned char *ext;
        const unsigned char *data;
        int version = 0, swabme = 0;
        unsigned long zones, ninodes, imaps, zmaps;
index 8309ea8ca92182f0255cc7a37e3c05edaef2038e..d0dbb60fa254d0c001b4a65030f0d5b9979fe7bf 100644 (file)
@@ -80,13 +80,13 @@ struct file_attribute {
 
 static int __probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag, int save_info)
 {
-       struct ntfs_super_block *ns;
-       struct master_file_table_record *mft;
+       const struct ntfs_super_block *ns;
+       const struct master_file_table_record *mft;
 
        uint32_t sectors_per_cluster, mft_record_size;
        uint16_t sector_size;
        uint64_t nr_clusters, off, attr_off;
-       unsigned char *buf_mft;
+       const unsigned char *buf_mft;
 
        ns = blkid_probe_get_sb(pr, mag, struct ntfs_super_block);
        if (!ns)
index e213d66b4472eeeb7c3389ef9bcf92f35101be21..14f74d3916e8d7db593d08996f0f579a12a49b6d 100644 (file)
@@ -100,7 +100,7 @@ struct oracle_asm_disk_label {
 
 static int probe_ocfs(blkid_probe pr, const struct blkid_idmag *mag)
 {
-       unsigned char *buf;
+       const unsigned char *buf;
        struct ocfs_volume_header ovh;
        struct ocfs_volume_label ovl;
        uint32_t maj, min;
index 456cbfb7d619c7eda8ff7c90237640743a9748fe..805e8fc1ed851829e48923513c4aecbd9ff9c1ca 100644 (file)
@@ -29,7 +29,7 @@ static int romfs_verify_csum(blkid_probe pr, const struct blkid_idmag *mag,
 {
        uint32_t csummed_size = min((uint32_t) 512,
                        be32_to_cpu(ros->ros_full_size));
-       unsigned char *csummed;
+       const unsigned char *csummed;
        uint32_t csum;
 
        if (csummed_size % sizeof(uint32_t) != 0)
index fe4a452774b6aba2d6f4e2ed76777c8b79008bb5..4cd94c087f1845af7b6c89059e1851a3856a9f2e 100644 (file)
@@ -49,7 +49,7 @@ const char STRATIS_MAGIC[] = "!Stra0tis\x86\xff\x02^\x41rh";
 #define MAGIC_OFFSET_COPY_1 (FIRST_COPY_OFFSET + _MAGIC_OFFSET)
 #define MAGIC_OFFSET_COPY_2 (SECOND_COPY_OFFSET + _MAGIC_OFFSET)
 
-static int stratis_valid_sb(uint8_t *p)
+static int stratis_valid_sb(const uint8_t *p)
 {
        const struct stratis_sb *stratis = (const struct stratis_sb *)p;
        uint32_t crc = 0;
@@ -83,7 +83,7 @@ static int probe_stratis(blkid_probe pr,
                const struct blkid_idmag *mag __attribute__((__unused__)))
 {
        const struct stratis_sb *stratis = NULL;
-       uint8_t *buf = blkid_probe_get_buffer(pr, 0, SB_AREA_SIZE);
+       const uint8_t *buf = blkid_probe_get_buffer(pr, 0, SB_AREA_SIZE);
        unsigned char uuid[STRATIS_UUID_STR_LEN];
 
        if (!buf)
index 67224bc634b441ad50b304e354b702462dd59c9b..c7fbec3088750235db3bbf15cef906be3917da66 100644 (file)
@@ -91,7 +91,7 @@ static int swap_set_info(blkid_probe pr, const struct blkid_idmag *mag,
 
 static int probe_swap(blkid_probe pr, const struct blkid_idmag *mag)
 {
-       unsigned char *buf;
+       const unsigned char *buf;
 
        if (!mag)
                return 1;
index 6d3b09171e1f8001bc4ad92cd60c780a8d36a066..dacf5afd544f0e0b92b24badb77282dea77908c5 100644 (file)
@@ -351,7 +351,7 @@ static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag)
                        version = "FAT16";
 
        } else if (vs->vs_fat32_length) {
-               unsigned char *buf;
+               const unsigned char *buf;
                uint16_t fsinfo_sect;
                int maxloop = 100;
 
index fac87abe5dbdaefd54c0fc9668e6bd890c915284..ff96136c82c7a02d668dc78710e764bda6df88e1 100644 (file)
@@ -49,7 +49,7 @@ static int probe_vmfs_fs(blkid_probe pr, const struct blkid_idmag *mag)
 static int probe_vmfs_volume(blkid_probe pr, const struct blkid_idmag *mag)
 {
        struct vmfs_volume_info *header;
-       unsigned char *lvm_uuid;
+       const unsigned char *lvm_uuid;
 
        header = blkid_probe_get_sb(pr, mag, struct vmfs_volume_info);
        if (header == NULL)
index f0e099e57e9b8cb5dd9fa72e7d591b4eaa136a80..a592469fd91bcdc4fe90162e819e59c2a9bd05f1 100644 (file)
@@ -206,7 +206,7 @@ static int xfs_verify_sb(struct xfs_super_block *ondisk, blkid_probe pr,
 
        if ((sbp->sb_versionnum & 0x0f) == 5) {
                uint32_t expected, crc;
-               unsigned char *csummed;
+               const unsigned char *csummed;
 
                if (!(sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT))
                        return 0;
@@ -331,7 +331,7 @@ static int probe_xfs_log(blkid_probe pr,
 {
        int i;
        struct xlog_rec_header *rhead;
-       unsigned char *buf;
+       const unsigned char *buf;
 
        buf = blkid_probe_get_buffer(pr, 0, 256*1024);
        if (!buf)
index 1fcc38409fc67a8312eb5f2a93452cef82de01f0..008a200828c050f6946215a06b14ce23c904e804 100644 (file)
@@ -71,13 +71,13 @@ struct nvlist {
        struct nvpair   nvl_nvpair;
 };
 
-static void zfs_process_value(blkid_probe pr, char *name, size_t namelen,
-                            void *value, size_t max_value_size, unsigned directory_level)
+static void zfs_process_value(blkid_probe pr, const char *name, size_t namelen,
+                            const void *value, size_t max_value_size, unsigned directory_level)
 {
        if (strncmp(name, "name", namelen) == 0 &&
            sizeof(struct nvstring) <= max_value_size &&
            !directory_level) {
-               struct nvstring *nvs = value;
+               const struct nvstring *nvs = value;
                uint32_t nvs_type = be32_to_cpu(nvs->nvs_type);
                uint32_t nvs_strlen = be32_to_cpu(nvs->nvs_strlen);
 
@@ -92,7 +92,7 @@ static void zfs_process_value(blkid_probe pr, char *name, size_t namelen,
        } else if (strncmp(name, "guid", namelen) == 0 &&
                   sizeof(struct nvuint64) <= max_value_size &&
                   !directory_level) {
-               struct nvuint64 *nvu = value;
+               const struct nvuint64 *nvu = value;
                uint32_t nvu_type = be32_to_cpu(nvu->nvu_type);
                uint64_t nvu_value;
 
@@ -110,7 +110,7 @@ static void zfs_process_value(blkid_probe pr, char *name, size_t namelen,
        } else if (strncmp(name, "pool_guid", namelen) == 0 &&
                   sizeof(struct nvuint64) <= max_value_size &&
                   !directory_level) {
-               struct nvuint64 *nvu = value;
+               const struct nvuint64 *nvu = value;
                uint32_t nvu_type = be32_to_cpu(nvu->nvu_type);
                uint64_t nvu_value;
 
@@ -128,7 +128,7 @@ static void zfs_process_value(blkid_probe pr, char *name, size_t namelen,
                                         "%"PRIu64, nvu_value);
        } else if (strncmp(name, "ashift", namelen) == 0 &&
                   sizeof(struct nvuint64) <= max_value_size) {
-               struct nvuint64 *nvu = value;
+               const struct nvuint64 *nvu = value;
                uint32_t nvu_type = be32_to_cpu(nvu->nvu_type);
                uint64_t nvu_value;
 
@@ -147,9 +147,9 @@ static void zfs_process_value(blkid_probe pr, char *name, size_t namelen,
 
 static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
 {
-       unsigned char *p;
-       struct nvlist *nvl;
-       struct nvpair *nvp;
+       const unsigned char *p;
+       const struct nvlist *nvl;
+       const struct nvpair *nvp;
        size_t left = 4096;
        unsigned directory_level = 0;
 
@@ -166,16 +166,16 @@ static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
        DBG(LOWPROBE, ul_debug("zfs_extract: nvlist offset %jd",
                               (intmax_t)offset));
 
-       nvl = (struct nvlist *) p;
+       nvl = (const struct nvlist *) p;
        nvp = &nvl->nvl_nvpair;
-       left -= (unsigned char *)nvp - p; /* Already used up 12 bytes */
+       left -= (const unsigned char *)nvp - p; /* Already used up 12 bytes */
 
        while (left > sizeof(*nvp)) {
                uint32_t nvp_size = be32_to_cpu(nvp->nvp_size);
                uint32_t nvp_namelen = be32_to_cpu(nvp->nvp_namelen);
                uint64_t namesize = ((uint64_t)nvp_namelen + 3) & ~3;
                size_t max_value_size;
-               void *value;
+               const void *value;
 
                if (!nvp->nvp_size) {
                        if (!directory_level)
@@ -201,7 +201,7 @@ static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
                value = nvp->nvp_name + namesize;
 
                if (sizeof(struct nvdirectory) <= max_value_size) {
-                       struct nvdirectory *nvu = value;
+                       const struct nvdirectory *nvu = value;
                        if (be32_to_cpu(nvu->nvd_type) == DATA_TYPE_DIRECTORY) {
                                nvp_size = sizeof(*nvp) + namesize + sizeof(*nvu);
                                directory_level++;
@@ -259,7 +259,7 @@ static int probe_zfs(blkid_probe pr,
        struct zfs_uberblock *ub = NULL;
        loff_t offset = 0, ub_offset = 0;
        int label_no, found = 0, found_in_label;
-       void *label;
+       const void *label;
        loff_t blk_align = (pr->size % (256 * 1024ULL));
 
        DBG(PROBE, ul_debug("probe_zfs"));
index 7970ae139b40095cbee02000fee318461d395bb5..1d17943b89a567902a86bee7623f55c975dd2a30 100644 (file)
@@ -792,7 +792,7 @@ static void get_partition_table_geometry(struct fdisk_context *cxt,
        unsigned char *bufp = cxt->firstsector;
        struct { unsigned int c, h, o, v; } t[8];
        unsigned int n1, n2, n3, n4, n5, n6;
-       struct dos_partition *p;
+       const struct dos_partition *p;
        unsigned int c, h, s, l;
        unsigned int hh, ss;
        unsigned int sects;