blob: 5db8ec260e8c590ec3f0b2df5e1938f9b9471e55 [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001/*
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
19struct nv_metadata {
20 uint8_t vendor[8];
21 uint32_t size;
22 uint32_t chksum;
23 uint16_t version;
24} __attribute__((packed));
25
26#define NVIDIA_SIGNATURE "NVIDIA"
27
28static int probe_nvraid(blkid_probe pr,
29 const struct blkid_idmag *mag __attribute__((__unused__)))
30{
31 uint64_t off;
32 struct nv_metadata *nv;
33
34 if (pr->size < 0x10000)
bigbiff7b4c7a62015-01-01 19:44:14 -050035 return 1;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050036 if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr))
bigbiff7b4c7a62015-01-01 19:44:14 -050037 return 1;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050038
39 off = ((pr->size / 0x200) - 2) * 0x200;
40 nv = (struct nv_metadata *)
41 blkid_probe_get_buffer(pr,
42 off,
43 sizeof(struct nv_metadata));
44 if (!nv)
bigbiff7b4c7a62015-01-01 19:44:14 -050045 return errno ? -errno : 1;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050046
47 if (memcmp(nv->vendor, NVIDIA_SIGNATURE, sizeof(NVIDIA_SIGNATURE)-1) != 0)
bigbiff7b4c7a62015-01-01 19:44:14 -050048 return 1;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050049 if (blkid_probe_sprintf_version(pr, "%u", le16_to_cpu(nv->version)) != 0)
bigbiff7b4c7a62015-01-01 19:44:14 -050050 return 1;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050051 if (blkid_probe_set_magic(pr, off, sizeof(nv->vendor),
52 (unsigned char *) nv->vendor))
bigbiff7b4c7a62015-01-01 19:44:14 -050053 return 1;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050054 return 0;
55}
56
57const struct blkid_idinfo nvraid_idinfo = {
58 .name = "nvidia_raid_member",
59 .usage = BLKID_USAGE_RAID,
60 .probefunc = probe_nvraid,
61 .magics = BLKID_NONE_MAGIC
62};
63
64