/src/util-linux/libblkid/src/superblocks/nvidia_raid.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2008 Karel Zak <kzak@redhat.com> |
3 | | * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org> |
4 | | * |
5 | | * Inspired by libvolume_id by |
6 | | * Kay Sievers <kay.sievers@vrfy.org> |
7 | | * |
8 | | * This file may be redistributed under the terms of the |
9 | | * GNU Lesser General Public License. |
10 | | */ |
11 | | #include <stdio.h> |
12 | | #include <stdlib.h> |
13 | | #include <unistd.h> |
14 | | #include <string.h> |
15 | | #include <stdint.h> |
16 | | |
17 | | #include "superblocks.h" |
18 | | |
19 | | struct nv_metadata { |
20 | | uint8_t vendor[8]; |
21 | | uint32_t size; |
22 | | uint32_t chksum; |
23 | | uint16_t version; |
24 | | } __attribute__((packed)); |
25 | | |
26 | 0 | #define NVIDIA_SIGNATURE "NVIDIA " |
27 | 0 | #define NVIDIA_SUPERBLOCK_SIZE 120 |
28 | | |
29 | | |
30 | | static int nvraid_verify_checksum(blkid_probe pr, const struct nv_metadata *nv) |
31 | 0 | { |
32 | 0 | uint32_t csum = le32_to_cpu(nv->chksum); |
33 | 0 | for (size_t i = 0; i < le32_to_cpu(nv->size); i++) |
34 | 0 | csum += le32_to_cpu(((uint32_t *) nv)[i]); |
35 | 0 | return blkid_probe_verify_csum(pr, csum, le32_to_cpu(nv->chksum)); |
36 | 0 | } |
37 | | |
38 | | static int probe_nvraid(blkid_probe pr, |
39 | | const struct blkid_idmag *mag __attribute__((__unused__))) |
40 | 3 | { |
41 | 3 | uint64_t off; |
42 | 3 | struct nv_metadata *nv; |
43 | | |
44 | 3 | if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr)) |
45 | 3 | return 1; |
46 | | |
47 | 0 | off = ((pr->size / 0x200) - 2) * 0x200; |
48 | 0 | nv = (struct nv_metadata *) |
49 | 0 | blkid_probe_get_buffer(pr, |
50 | 0 | off, |
51 | 0 | NVIDIA_SUPERBLOCK_SIZE); |
52 | 0 | if (!nv) |
53 | 0 | return errno ? -errno : 1; |
54 | | |
55 | 0 | if (memcmp(nv->vendor, NVIDIA_SIGNATURE, sizeof(NVIDIA_SIGNATURE)-1) != 0) |
56 | 0 | return 1; |
57 | 0 | if (le32_to_cpu(nv->size) * 4 != NVIDIA_SUPERBLOCK_SIZE) |
58 | 0 | return 1; |
59 | 0 | if (!nvraid_verify_checksum(pr, nv)) |
60 | 0 | return 1; |
61 | 0 | if (blkid_probe_sprintf_version(pr, "%u", le16_to_cpu(nv->version)) != 0) |
62 | 0 | return 1; |
63 | 0 | if (blkid_probe_set_magic(pr, off, sizeof(nv->vendor), |
64 | 0 | (unsigned char *) nv->vendor)) |
65 | 0 | return 1; |
66 | 0 | return 0; |
67 | 0 | } |
68 | | |
69 | | const struct blkid_idinfo nvraid_idinfo = { |
70 | | .name = "nvidia_raid_member", |
71 | | .usage = BLKID_USAGE_RAID, |
72 | | .minsz = 0x10000, |
73 | | .probefunc = probe_nvraid, |
74 | | .magics = BLKID_NONE_MAGIC |
75 | | }; |
76 | | |
77 | | |