chiark / gitweb /
9ea00e20cc9af40b658cb450335cf870ab1b0995
[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 "libvolume_id-private.h"
28 #include "util.h"
29
30 struct oracleasm_super_block {
31         uint8_t tag[8];
32         uint8_t id[24];
33 } PACKED;
34
35 #define ASM_SB_OFF                      0x20
36 #define ASM_MAGIC                       "ORCLDISK"
37
38 /*
39  * Detect Oracle Automatic Storage Management (ASM).
40  * It can do mirroring, but don't consider it RAID in the sense
41  * that an ext3 filesystem could live inside.  Thus, mark it 'other'.
42  * There also is a magic word 'ORCLCLRD'; like blkid(8), we ignore that.
43  */
44 int volume_id_probe_oracleasm(struct volume_id *id, uint64_t off, uint64_t size)
45 {
46         const uint8_t *buf;
47         struct oracleasm_super_block *oracleasm;
48
49         info("probing at offset 0x%llx\n", (unsigned long long) off);
50
51         buf = volume_id_get_buffer(id, off + ASM_SB_OFF, 0x800);
52         if (buf == NULL)
53                 return -1;
54
55         oracleasm = (struct oracleasm_super_block *) buf;
56
57         if (memcmp(oracleasm->tag, ASM_MAGIC, 8) != 0)
58                 return -1;
59
60         volume_id_set_usage(id, VOLUME_ID_OTHER);
61         volume_id_set_label_raw(id, oracleasm->id, 24);
62         volume_id_set_label_string(id, oracleasm->id, 24);
63         id->type = "oracleasm";
64
65         return 0;
66 }