2
* Copyright (C) 2008 Karel Zak <kzak@redhat.com>
4
* Inspired by libvolume_id by
5
* Kay Sievers <kay.sievers@vrfy.org>
7
* This file may be redistributed under the terms of the
8
* GNU Lesser General Public License.
20
#include "superblocks.h"
22
struct ufs_super_block {
45
uint32_t fs_maxcontig;
47
uint32_t fs_fragshift;
56
uint32_t fs_npsect_state;
57
uint32_t fs_interleave;
58
uint32_t fs_trackskew;
85
uint32_t fs_maxcluster;
87
uint16_t fs_opostbl[16][8];
91
uint8_t fs_volname[32];
96
uint32_t fs_contigdirs;
98
uint32_t fs_maxcluster;
102
int64_t fs_sparecon64[17];
103
int64_t fs_sblockloc;
104
struct ufs2_csum_total {
109
uint64_t cs_numclusters;
110
uint64_t cs_spare[3];
119
int64_t fs_pendingblocks;
120
int32_t fs_pendinginodes;
121
} __attribute__((packed)) fs_u2;
125
int32_t fs_sparecon[53];
127
int32_t fs_sparecon2[1];
129
uint32_t fs_qbmask[2];
130
uint32_t fs_qfmask[2];
133
int32_t fs_sparecon[53];
135
int32_t fs_sparecon2[1];
137
uint32_t fs_qbmask[2];
138
uint32_t fs_qfmask[2];
141
int32_t fs_sparecon[50];
142
int32_t fs_contigsumsize;
143
int32_t fs_maxsymlinklen;
145
uint32_t fs_maxfilesize[2];
146
uint32_t fs_qbmask[2];
147
uint32_t fs_qfmask[2];
151
int32_t fs_postblformat;
153
int32_t fs_postbloff;
157
} __attribute__((packed));
159
#define UFS_MAGIC 0x00011954
160
#define UFS2_MAGIC 0x19540119
161
#define UFS_MAGIC_FEA 0x00195612
162
#define UFS_MAGIC_LFN 0x00095014
163
#define UFS_MAGIC_SEC 0x00612195
164
#define UFS_MAGIC_4GB 0x05231994
166
static int probe_ufs(blkid_probe pr, const struct blkid_idmag *mag)
168
int offsets[] = { 0, 8, 64, 256 };
170
UFS2_MAGIC, UFS_MAGIC, UFS_MAGIC_FEA, UFS_MAGIC_LFN,
171
UFS_MAGIC_SEC, UFS_MAGIC_4GB
175
struct ufs_super_block *ufs;
177
for (i = 0; i < ARRAY_SIZE(offsets); i++) {
178
uint32_t magLE, magBE;
181
ufs = (struct ufs_super_block *)
182
blkid_probe_get_buffer(pr,
184
sizeof(struct ufs_super_block));
188
magBE = be32_to_cpu(ufs->fs_magic);
189
magLE = le32_to_cpu(ufs->fs_magic);
191
for (y = 0; y < ARRAY_SIZE(mags); y++) {
192
if (magLE == mags[y] || magBE == mags[y]) {
202
if (magic == UFS2_MAGIC) {
203
blkid_probe_set_version(pr, "2");
204
blkid_probe_set_label(pr, ufs->fs_u11.fs_u2.fs_volname,
205
sizeof(ufs->fs_u11.fs_u2.fs_volname));
207
blkid_probe_set_version(pr, "1");
209
if (blkid_probe_set_magic(pr,
210
(offsets[i] * 1024) +
211
offsetof(struct ufs_super_block, fs_magic),
212
sizeof(ufs->fs_magic),
213
(unsigned char *) &ufs->fs_magic))
220
* According to libvolume_id the UFS superblock could be on four positions.
221
* The original libblkid has checked one position (.kboff=8) only.
223
* We know four UFS magic strings and UFS could be both little-endian and
224
* big-endian. ... so we have:
226
* 4 position * 4 string * 2 version = 32 magic strings
228
* It seems simpler to check for these string in probing function that hardcode
229
* all in the .magic array.
231
const struct blkid_idinfo ufs_idinfo =
234
.usage = BLKID_USAGE_FILESYSTEM,
235
.probefunc = probe_ufs,
236
.magics = BLKID_NONE_MAGIC