Coverage Report

Created: 2025-11-07 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/util-linux/libblkid/src/superblocks/highpoint_raid.c
Line
Count
Source
1
/*
2
 * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
3
 *
4
 * Inspired by libvolume_id by
5
 *     Kay Sievers <kay.sievers@vrfy.org>
6
 *
7
 * This file may be redistributed under the terms of the
8
 * GNU Lesser General Public License.
9
 */
10
#include <stdio.h>
11
#include <stdlib.h>
12
#include <unistd.h>
13
#include <string.h>
14
#include <stdint.h>
15
16
#include "superblocks.h"
17
18
struct hpt45x_metadata {
19
  uint32_t  magic;
20
};
21
22
12.3k
#define HPT45X_MAGIC_OK     0x5a7816f3
23
6.17k
#define HPT45X_MAGIC_BAD    0x5a7816fd
24
25
static int probe_highpoint45x(blkid_probe pr,
26
    const struct blkid_idmag *mag __attribute__((__unused__)))
27
6.17k
{
28
6.17k
  struct hpt45x_metadata *hpt;
29
6.17k
  uint64_t off;
30
6.17k
  uint32_t magic;
31
32
6.17k
  if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr))
33
0
    return 1;
34
35
6.17k
  off = ((pr->size / 0x200) - 11) * 0x200;
36
6.17k
  hpt = (struct hpt45x_metadata *)
37
6.17k
      blkid_probe_get_buffer(pr,
38
6.17k
          off,
39
6.17k
          sizeof(struct hpt45x_metadata));
40
6.17k
  if (!hpt)
41
0
    return errno ? -errno : 1;
42
6.17k
  magic = le32_to_cpu(hpt->magic);
43
6.17k
  if (magic != HPT45X_MAGIC_OK && magic != HPT45X_MAGIC_BAD)
44
6.17k
    return 1;
45
0
  if (blkid_probe_set_magic(pr, off, sizeof(hpt->magic),
46
0
        (unsigned char *) &hpt->magic))
47
0
    return 1;
48
0
  return 0;
49
0
}
50
51
static int probe_highpoint37x(blkid_probe pr,
52
    const struct blkid_idmag *mag __attribute__((__unused__)))
53
5
{
54
5
  if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr))
55
0
    return 1;
56
5
  return 0;
57
5
}
58
59
60
const struct blkid_idinfo highpoint45x_idinfo = {
61
  .name   = "hpt45x_raid_member",
62
  .usage    = BLKID_USAGE_RAID,
63
  .minsz    = 0x10000,
64
  .probefunc  = probe_highpoint45x,
65
  .magics   = BLKID_NONE_MAGIC
66
};
67
68
const struct blkid_idinfo highpoint37x_idinfo = {
69
  .name   = "hpt37x_raid_member",
70
  .usage    = BLKID_USAGE_RAID,
71
  .probefunc  = probe_highpoint37x,
72
  .magics   = {
73
    /*
74
     * Superblock offset:                     4608 bytes  (9 sectors)
75
     * Magic string offset within superblock:   32 bytes
76
     *
77
     * kboff = (4608 + 32) / 1024
78
     * sboff = (4608 + 32) % kboff
79
     */
80
    { .magic = "\xf0\x16\x78\x5a", .len = 4, .kboff = 4, .sboff = 544 },
81
    { .magic = "\xfd\x16\x78\x5a", .len = 4, .kboff = 4, .sboff = 544 },
82
    { NULL }
83
  }
84
};
85
86