chiark / gitweb /
0f5ff80cfb98ae7e47ff96a23ca8ed2fd0580621
[elogind.git] / extras / volume_id / lib / oracleasm.c
1 /*
2  * volume_id - reads filesystem label and uuid
3  *
4  * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
5  *
6  *      This program is free software; you can redistribute it and/or modify it
7  *      under the terms of the GNU General Public License as published by the
8  *      Free Software Foundation version 2 of the License.
9  */
10
11 #ifndef _GNU_SOURCE
12 #define _GNU_SOURCE 1
13 #endif
14
15 #ifdef HAVE_CONFIG_H
16 #  include <config.h>
17 #endif
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <errno.h>
24 #include <ctype.h>
25
26 #include "libvolume_id.h"
27 #include "util.h"
28
29 struct oracleasm_super_block {
30         uint8_t tag[8];
31         uint8_t id[24];
32 } PACKED;
33
34 #define ASM_SB_OFF                      0x20
35 #define ASM_MAGIC                       "ORCLDISK"
36
37 /*
38  * Detect Oracle Automatic Storage Management (ASM).
39  * It can do mirroring, but don't consider it RAID in the sense
40  * that an ext3 filesystem could live inside.  Thus, mark it 'other'.
41  * There also is a magic word 'ORCLCLRD'; like blkid(8), we ignore that.
42  */
43 int volume_id_probe_oracleasm(struct volume_id *id, uint64_t off, uint64_t size)
44 {
45         const uint8_t *buf;
46         struct oracleasm_super_block *oracleasm;
47
48         info("probing at offset 0x%llx\n", (unsigned long long) off);
49
50         buf = volume_id_get_buffer(id, off + ASM_SB_OFF, 0x800);
51         if (buf == NULL)
52                 return -1;
53
54         oracleasm = (struct oracleasm_super_block *) buf;
55
56         if (memcmp(oracleasm->tag, ASM_MAGIC, 8) != 0)
57                 return -1;
58
59         volume_id_set_usage(id, VOLUME_ID_OTHER);
60         volume_id_set_label_raw(id, oracleasm->id, 24);
61         volume_id_set_label_string(id, oracleasm->id, 24);
62         id->type = "oracleasm";
63
64         return 0;
65 }