2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "volume_id_internal.h"
23 struct ufs_super_block {
46 uint32_t fs_maxcontig;
48 uint32_t fs_fragshift;
57 uint32_t fs_npsect_state;
58 uint32_t fs_interleave;
59 uint32_t fs_trackskew;
76 } __attribute__((__packed__)) fs_cstotal;
86 uint32_t fs_maxcluster;
88 uint16_t fs_opostbl[16][8];
89 } __attribute__((__packed__)) fs_u1;
92 uint8_t fs_volname[32];
97 uint32_t fs_contigdirs;
99 uint32_t fs_maxcluster;
103 int64_t fs_sparecon64[17];
104 int64_t fs_sblockloc;
105 struct ufs2_csum_total {
110 uint64_t cs_numclusters;
111 uint64_t cs_spare[3];
112 } __attribute__((__packed__)) fs_cstotal;
116 } __attribute__((__packed__)) fs_time;
120 int64_t fs_pendingblocks;
121 int32_t fs_pendinginodes;
122 } __attribute__((__packed__)) fs_u2;
126 int32_t fs_sparecon[53];
128 int32_t fs_sparecon2[1];
130 uint32_t fs_qbmask[2];
131 uint32_t fs_qfmask[2];
132 } __attribute__((__packed__)) fs_sun;
134 int32_t fs_sparecon[53];
136 int32_t fs_sparecon2[1];
138 uint32_t fs_qbmask[2];
139 uint32_t fs_qfmask[2];
140 } __attribute__((__packed__)) fs_sunx86;
142 int32_t fs_sparecon[50];
143 int32_t fs_contigsumsize;
144 int32_t fs_maxsymlinklen;
146 uint32_t fs_maxfilesize[2];
147 uint32_t fs_qbmask[2];
148 uint32_t fs_qfmask[2];
150 } __attribute__((__packed__)) fs_44;
152 int32_t fs_postblformat;
154 int32_t fs_postbloff;
158 } __attribute__((__packed__));
160 #define UFS_MAGIC 0x00011954
161 #define UFS2_MAGIC 0x19540119
162 #define UFS_MAGIC_FEA 0x00195612
163 #define UFS_MAGIC_LFN 0x00095014
165 int volume_id_probe_ufs(struct volume_id *id, uint64_t off)
167 static const short offsets[] = { 0, 8, 64, 256 };
171 struct ufs_super_block *ufs;
173 dbg("probing at offset 0x%llx", (unsigned long long) off);
175 for (i = 0; i < ARRAY_SIZE(offsets); i++) {
176 ufs = volume_id_get_buffer(id, off + (offsets[i] * 0x400), 0x800);
180 dbg("offset 0x%x", offsets[i] * 0x400);
181 magic = ufs->fs_magic;
182 if ((magic == cpu_to_be32(UFS_MAGIC))
183 || (magic == cpu_to_be32(UFS2_MAGIC))
184 || (magic == cpu_to_be32(UFS_MAGIC_FEA))
185 || (magic == cpu_to_be32(UFS_MAGIC_LFN))
187 dbg("magic 0x%08x(be)", magic);
190 if ((magic == cpu_to_le32(UFS_MAGIC))
191 || (magic == cpu_to_le32(UFS2_MAGIC))
192 || (magic == cpu_to_le32(UFS_MAGIC_FEA))
193 || (magic == cpu_to_le32(UFS_MAGIC_LFN))
195 dbg("magic 0x%08x(le)", magic);
202 // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);