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.
21 struct ufs_super_block {
44 uint32_t fs_maxcontig;
46 uint32_t fs_fragshift;
55 uint32_t fs_npsect_state;
56 uint32_t fs_interleave;
57 uint32_t fs_trackskew;
84 uint32_t fs_maxcluster;
86 uint16_t fs_opostbl[16][8];
90 uint8_t fs_volname[32];
95 uint32_t fs_contigdirs;
97 uint32_t fs_maxcluster;
101 int64_t fs_sparecon64[17];
102 int64_t fs_sblockloc;
103 struct ufs2_csum_total {
108 uint64_t cs_numclusters;
109 uint64_t cs_spare[3];
118 int64_t fs_pendingblocks;
119 int32_t fs_pendinginodes;
120 } __attribute__((packed)) fs_u2;
124 int32_t fs_sparecon[53];
126 int32_t fs_sparecon2[1];
128 uint32_t fs_qbmask[2];
129 uint32_t fs_qfmask[2];
132 int32_t fs_sparecon[53];
134 int32_t fs_sparecon2[1];
136 uint32_t fs_qbmask[2];
137 uint32_t fs_qfmask[2];
140 int32_t fs_sparecon[50];
141 int32_t fs_contigsumsize;
142 int32_t fs_maxsymlinklen;
144 uint32_t fs_maxfilesize[2];
145 uint32_t fs_qbmask[2];
146 uint32_t fs_qfmask[2];
150 int32_t fs_postblformat;
152 int32_t fs_postbloff;
156 } __attribute__((packed));
158 #define UFS_MAGIC 0x00011954
159 #define UFS2_MAGIC 0x19540119
160 #define UFS_MAGIC_FEA 0x00195612
161 #define UFS_MAGIC_LFN 0x00095014
162 #define UFS_MAGIC_SEC 0x00612195
163 #define UFS_MAGIC_4GB 0x05231994
165 static int probe_ufs(blkid_probe pr, const struct blkid_idmag *mag)
167 int offsets[] = { 0, 8, 64, 256 };
169 UFS2_MAGIC, UFS_MAGIC, UFS_MAGIC_FEA, UFS_MAGIC_LFN,
170 UFS_MAGIC_SEC, UFS_MAGIC_4GB
174 struct ufs_super_block *ufs;
176 for (i = 0; i < ARRAY_SIZE(offsets); i++) {
177 uint32_t magLE, magBE;
180 ufs = (struct ufs_super_block *)
181 blkid_probe_get_buffer(pr,
183 sizeof(struct ufs_super_block));
187 magBE = be32_to_cpu(ufs->fs_magic);
188 magLE = le32_to_cpu(ufs->fs_magic);
190 for (y = 0; y < ARRAY_SIZE(mags); y++) {
191 if (magLE == mags[y] || magBE == mags[y]) {
201 if (magic == UFS2_MAGIC) {
202 blkid_probe_set_version(pr, "2");
203 blkid_probe_set_label(pr, ufs->fs_u11.fs_u2.fs_volname,
204 sizeof(ufs->fs_u11.fs_u2.fs_volname));
206 blkid_probe_set_version(pr, "1");
212 * According to libvolume_id the UFS superblock could be on four positions.
213 * The original libblkid has checked one position (.kboff=8) only.
215 * We know four UFS magic strings and UFS could be both little-endian and
216 * big-endian. ... so we have:
218 * 4 position * 4 string * 2 version = 32 magic strings
220 * It seems simpler to check for these string in probing function that hardcode
221 * all in the .magic array.
223 const struct blkid_idinfo ufs_idinfo =
226 .usage = BLKID_USAGE_FILESYSTEM,
227 .probefunc = probe_ufs,
228 .magics = BLKID_NONE_MAGIC