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,
167
const struct blkid_idmag *mag __attribute__((__unused__)))
169
int offsets[] = { 0, 8, 64, 256 };
171
UFS2_MAGIC, UFS_MAGIC, UFS_MAGIC_FEA, UFS_MAGIC_LFN,
172
UFS_MAGIC_SEC, UFS_MAGIC_4GB
176
struct ufs_super_block *ufs;
178
for (i = 0; i < ARRAY_SIZE(offsets); i++) {
179
uint32_t magLE, magBE;
182
ufs = (struct ufs_super_block *)
183
blkid_probe_get_buffer(pr,
185
sizeof(struct ufs_super_block));
189
magBE = be32_to_cpu(ufs->fs_magic);
190
magLE = le32_to_cpu(ufs->fs_magic);
192
for (y = 0; y < ARRAY_SIZE(mags); y++) {
193
if (magLE == mags[y] || magBE == mags[y]) {
203
if (magic == UFS2_MAGIC) {
204
blkid_probe_set_version(pr, "2");
205
blkid_probe_set_label(pr, ufs->fs_u11.fs_u2.fs_volname,
206
sizeof(ufs->fs_u11.fs_u2.fs_volname));
208
blkid_probe_set_version(pr, "1");
210
if (blkid_probe_set_magic(pr,
211
(offsets[i] * 1024) +
212
offsetof(struct ufs_super_block, fs_magic),
213
sizeof(ufs->fs_magic),
214
(unsigned char *) &ufs->fs_magic))
221
* According to libvolume_id the UFS superblock could be on four positions.
222
* The original libblkid has checked one position (.kboff=8) only.
224
* We know four UFS magic strings and UFS could be both little-endian and
225
* big-endian. ... so we have:
227
* 4 position * 4 string * 2 version = 32 magic strings
229
* It seems simpler to check for these string in probing function that hardcode
230
* all in the .magic array.
232
const struct blkid_idinfo ufs_idinfo =
235
.usage = BLKID_USAGE_FILESYSTEM,
236
.probefunc = probe_ufs,
237
.magics = BLKID_NONE_MAGIC