~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to libblkid/src/superblocks/ocfs.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 1999, 2001 by Andries Brouwer
 
3
 * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
 
4
 * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
 
5
 *
 
6
 * This file may be redistributed under the terms of the
 
7
 * GNU Lesser General Public License.
 
8
 */
 
9
#include <stdio.h>
 
10
#include <stdlib.h>
 
11
#include <unistd.h>
 
12
#include <string.h>
 
13
#include <stdint.h>
 
14
 
 
15
#include "superblocks.h"
 
16
 
 
17
struct ocfs_volume_header {
 
18
        unsigned char   minor_version[4];
 
19
        unsigned char   major_version[4];
 
20
        unsigned char   signature[128];
 
21
        char            mount[128];
 
22
        unsigned char   mount_len[2];
 
23
} __attribute__((packed));
 
24
 
 
25
struct ocfs_volume_label {
 
26
        unsigned char   disk_lock[48];
 
27
        char            label[64];
 
28
        unsigned char   label_len[2];
 
29
        unsigned char   vol_id[16];
 
30
        unsigned char   vol_id_len[2];
 
31
} __attribute__((packed));
 
32
 
 
33
#define ocfsmajor(o) ( (uint32_t) o.major_version[0] \
 
34
                   + (((uint32_t) o.major_version[1]) << 8) \
 
35
                   + (((uint32_t) o.major_version[2]) << 16) \
 
36
                   + (((uint32_t) o.major_version[3]) << 24))
 
37
 
 
38
#define ocfsminor(o) ( (uint32_t) o.minor_version[0] \
 
39
                   + (((uint32_t) o.minor_version[1]) << 8) \
 
40
                   + (((uint32_t) o.minor_version[2]) << 16) \
 
41
                   + (((uint32_t) o.minor_version[3]) << 24))
 
42
 
 
43
#define ocfslabellen(o) ((uint32_t)o.label_len[0] + (((uint32_t) o.label_len[1]) << 8))
 
44
#define ocfsmountlen(o) ((uint32_t)o.mount_len[0] + (((uint32_t) o.mount_len[1]) << 8))
 
45
 
 
46
struct ocfs2_super_block {
 
47
        uint8_t         i_signature[8];
 
48
        uint32_t        i_generation;
 
49
        int16_t         i_suballoc_slot;
 
50
        uint16_t        i_suballoc_bit;
 
51
        uint32_t        i_reserved0;
 
52
        uint32_t        i_clusters;
 
53
        uint32_t        i_uid;
 
54
        uint32_t        i_gid;
 
55
        uint64_t        i_size;
 
56
        uint16_t        i_mode;
 
57
        uint16_t        i_links_count;
 
58
        uint32_t        i_flags;
 
59
        uint64_t        i_atime;
 
60
        uint64_t        i_ctime;
 
61
        uint64_t        i_mtime;
 
62
        uint64_t        i_dtime;
 
63
        uint64_t        i_blkno;
 
64
        uint64_t        i_last_eb_blk;
 
65
        uint32_t        i_fs_generation;
 
66
        uint32_t        i_atime_nsec;
 
67
        uint32_t        i_ctime_nsec;
 
68
        uint32_t        i_mtime_nsec;
 
69
        uint64_t        i_reserved1[9];
 
70
        uint64_t        i_pad1;
 
71
        uint16_t        s_major_rev_level;
 
72
        uint16_t        s_minor_rev_level;
 
73
        uint16_t        s_mnt_count;
 
74
        int16_t         s_max_mnt_count;
 
75
        uint16_t        s_state;
 
76
        uint16_t        s_errors;
 
77
        uint32_t        s_checkinterval;
 
78
        uint64_t        s_lastcheck;
 
79
        uint32_t        s_creator_os;
 
80
        uint32_t        s_feature_compat;
 
81
        uint32_t        s_feature_incompat;
 
82
        uint32_t        s_feature_ro_compat;
 
83
        uint64_t        s_root_blkno;
 
84
        uint64_t        s_system_dir_blkno;
 
85
        uint32_t        s_blocksize_bits;
 
86
        uint32_t        s_clustersize_bits;
 
87
        uint16_t        s_max_slots;
 
88
        uint16_t        s_reserved1;
 
89
        uint32_t        s_reserved2;
 
90
        uint64_t        s_first_cluster_group;
 
91
        uint8_t         s_label[64];
 
92
        uint8_t         s_uuid[16];
 
93
} __attribute__((packed));
 
94
 
 
95
struct oracle_asm_disk_label {
 
96
        char dummy[32];
 
97
        char dl_tag[8];
 
98
        char dl_id[24];
 
99
} __attribute__((packed));
 
100
 
 
101
static int probe_ocfs(blkid_probe pr, const struct blkid_idmag *mag)
 
102
{
 
103
        unsigned char *buf;
 
104
        struct ocfs_volume_header ovh;
 
105
        struct ocfs_volume_label ovl;
 
106
        uint32_t maj, min;
 
107
 
 
108
        /* header */
 
109
        buf = blkid_probe_get_buffer(pr, mag->kboff << 10,
 
110
                        sizeof(struct ocfs_volume_header));
 
111
        if (!buf)
 
112
                return -1;
 
113
        memcpy(&ovh, buf, sizeof(ovh));
 
114
 
 
115
        /* label */
 
116
        buf = blkid_probe_get_buffer(pr, (mag->kboff << 10) + 512,
 
117
                        sizeof(struct ocfs_volume_label));
 
118
        if (!buf)
 
119
                return -1;
 
120
        memcpy(&ovl, buf, sizeof(ovl));
 
121
 
 
122
        maj = ocfsmajor(ovh);
 
123
        min = ocfsminor(ovh);
 
124
 
 
125
        if (maj == 1)
 
126
                blkid_probe_set_value(pr, "SEC_TYPE",
 
127
                                (unsigned char *) "ocfs1", sizeof("ocfs1"));
 
128
        else if (maj >= 9)
 
129
                blkid_probe_set_value(pr, "SEC_TYPE",
 
130
                                (unsigned char *) "ntocfs", sizeof("ntocfs"));
 
131
 
 
132
        blkid_probe_set_label(pr, (unsigned char *) ovl.label,
 
133
                                ocfslabellen(ovl));
 
134
        blkid_probe_set_value(pr, "MOUNT", (unsigned char *) ovh.mount,
 
135
                                ocfsmountlen(ovh));
 
136
        blkid_probe_set_uuid(pr, ovl.vol_id);
 
137
        blkid_probe_sprintf_version(pr, "%u.%u", maj, min);
 
138
        return 0;
 
139
}
 
140
 
 
141
static int probe_ocfs2(blkid_probe pr, const struct blkid_idmag *mag)
 
142
{
 
143
        struct ocfs2_super_block *osb;
 
144
 
 
145
        osb = blkid_probe_get_sb(pr, mag, struct ocfs2_super_block);
 
146
        if (!osb)
 
147
                return -1;
 
148
 
 
149
        blkid_probe_set_label(pr, (unsigned char *) osb->s_label, sizeof(osb->s_label));
 
150
        blkid_probe_set_uuid(pr, osb->s_uuid);
 
151
 
 
152
        blkid_probe_sprintf_version(pr, "%u.%u",
 
153
                le16_to_cpu(osb->s_major_rev_level),
 
154
                le16_to_cpu(osb->s_minor_rev_level));
 
155
 
 
156
        return 0;
 
157
}
 
158
 
 
159
static int probe_oracleasm(blkid_probe pr, const struct blkid_idmag *mag)
 
160
{
 
161
        struct oracle_asm_disk_label *dl;
 
162
 
 
163
        dl = blkid_probe_get_sb(pr, mag, struct oracle_asm_disk_label);
 
164
        if (!dl)
 
165
                return -1;
 
166
 
 
167
        blkid_probe_set_label(pr, (unsigned char *) dl->dl_id, sizeof(dl->dl_id));
 
168
        return 0;
 
169
}
 
170
 
 
171
 
 
172
const struct blkid_idinfo ocfs_idinfo =
 
173
{
 
174
        .name           = "ocfs",
 
175
        .usage          = BLKID_USAGE_FILESYSTEM,
 
176
        .probefunc      = probe_ocfs,
 
177
        .minsz          = 108 * 1024 * 1024,
 
178
        .magics         =
 
179
        {
 
180
                { .magic = "OracleCFS", .len = 9, .kboff = 8 },
 
181
                { NULL }
 
182
        }
 
183
};
 
184
 
 
185
const struct blkid_idinfo ocfs2_idinfo =
 
186
{
 
187
        .name           = "ocfs2",
 
188
        .usage          = BLKID_USAGE_FILESYSTEM,
 
189
        .probefunc      = probe_ocfs2,
 
190
        .minsz          = 108 * 1024 * 1024,
 
191
        .magics         =
 
192
        {
 
193
                { .magic = "OCFSV2", .len = 6, .kboff = 1 },
 
194
                { .magic = "OCFSV2", .len = 6, .kboff = 2 },
 
195
                { .magic = "OCFSV2", .len = 6, .kboff = 4 },
 
196
                { .magic = "OCFSV2", .len = 6, .kboff = 8 },
 
197
                { NULL }
 
198
        }
 
199
};
 
200
 
 
201
/* Oracle ASM (Automatic Storage Management) */
 
202
const struct blkid_idinfo oracleasm_idinfo =
 
203
{
 
204
        .name           = "oracleasm",
 
205
        .usage          = BLKID_USAGE_FILESYSTEM,
 
206
        .probefunc      = probe_oracleasm,
 
207
        .magics         =
 
208
        {
 
209
                { .magic = "ORCLDISK", .len = 8, .sboff = 32 },
 
210
                { NULL }
 
211
        }
 
212
};
 
213