2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #include "libvolume_id.h"
32 #include "libvolume_id-private.h"
34 struct ufs_super_block {
57 uint32_t fs_maxcontig;
59 uint32_t fs_fragshift;
68 uint32_t fs_npsect_state;
69 uint32_t fs_interleave;
70 uint32_t fs_trackskew;
97 uint32_t fs_maxcluster;
99 uint16_t fs_opostbl[16][8];
102 int8_t fs_fsmnt[468];
103 uint8_t fs_volname[32];
107 uint32_t fs_ocsp[28];
108 uint32_t fs_contigdirs;
110 uint32_t fs_maxcluster;
114 int64_t fs_sparecon64[17];
115 int64_t fs_sblockloc;
116 struct ufs2_csum_total {
121 uint64_t cs_numclusters;
122 uint64_t cs_spare[3];
131 int64_t fs_pendingblocks;
132 int32_t fs_pendinginodes;
137 int32_t fs_sparecon[53];
139 int32_t fs_sparecon2[1];
141 uint32_t fs_qbmask[2];
142 uint32_t fs_qfmask[2];
145 int32_t fs_sparecon[53];
147 int32_t fs_sparecon2[1];
149 uint32_t fs_qbmask[2];
150 uint32_t fs_qfmask[2];
153 int32_t fs_sparecon[50];
154 int32_t fs_contigsumsize;
155 int32_t fs_maxsymlinklen;
157 uint32_t fs_maxfilesize[2];
158 uint32_t fs_qbmask[2];
159 uint32_t fs_qfmask[2];
163 int32_t fs_postblformat;
165 int32_t fs_postbloff;
171 #define UFS_MAGIC 0x00011954
172 #define UFS2_MAGIC 0x19540119
173 #define UFS_MAGIC_FEA 0x00195612
174 #define UFS_MAGIC_LFN 0x00095014
176 int volume_id_probe_ufs(struct volume_id *id, uint64_t off, uint64_t size)
180 struct ufs_super_block *ufs;
181 int offsets[] = {0, 8, 64, 256, -1};
183 info("probing at offset 0x%" PRIx64 "\n", off);
185 for (i = 0; offsets[i] >= 0; i++) {
186 ufs = (struct ufs_super_block *) volume_id_get_buffer(id, off + (offsets[i] * 0x400), 0x800);
190 dbg("offset 0x%x\n", offsets[i] * 0x400);
191 magic = be32_to_cpu(ufs->fs_magic);
192 if ((magic == UFS_MAGIC) ||
193 (magic == UFS2_MAGIC) ||
194 (magic == UFS_MAGIC_FEA) ||
195 (magic == UFS_MAGIC_LFN)) {
196 dbg("magic 0x%08x(be)\n", magic);
199 magic = le32_to_cpu(ufs->fs_magic);
200 if ((magic == UFS_MAGIC) ||
201 (magic == UFS2_MAGIC) ||
202 (magic == UFS_MAGIC_FEA) ||
203 (magic == UFS_MAGIC_LFN)) {
204 dbg("magic 0x%08x(le)\n", magic);
211 volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
215 strcpy(id->type_version, "1");
218 strcpy(id->type_version, "2");
219 volume_id_set_label_raw(id, ufs->fs_u11.fs_u2.fs_volname, 32);
220 volume_id_set_label_string(id, ufs->fs_u11.fs_u2.fs_volname, 32);