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
36 #include "volume_id.h"
41 struct ufs_super_block {
64 uint32_t fs_maxcontig;
66 uint32_t fs_fragshift;
75 uint32_t fs_npsect_state;
76 uint32_t fs_interleave;
77 uint32_t fs_trackskew;
94 } __attribute__((__packed__)) fs_cstotal;
101 int8_t fs_fsmnt[512];
104 uint32_t fs_maxcluster;
106 uint16_t fs_opostbl[16][8];
107 } __attribute__((__packed__)) fs_u1;
109 int8_t fs_fsmnt[468];
110 uint8_t fs_volname[32];
114 uint32_t fs_ocsp[28];
115 uint32_t fs_contigdirs;
117 uint32_t fs_maxcluster;
121 int64_t fs_sparecon64[17];
122 int64_t fs_sblockloc;
123 struct ufs2_csum_total {
128 uint64_t cs_numclusters;
129 uint64_t cs_spare[3];
130 } __attribute__((__packed__)) fs_cstotal;
134 } __attribute__((__packed__)) fs_time;
138 int64_t fs_pendingblocks;
139 int32_t fs_pendinginodes;
140 } __attribute__((__packed__)) fs_u2;
144 int32_t fs_sparecon[53];
146 int32_t fs_sparecon2[1];
148 uint32_t fs_qbmask[2];
149 uint32_t fs_qfmask[2];
150 } __attribute__((__packed__)) fs_sun;
152 int32_t fs_sparecon[53];
154 int32_t fs_sparecon2[1];
156 uint32_t fs_qbmask[2];
157 uint32_t fs_qfmask[2];
158 } __attribute__((__packed__)) fs_sunx86;
160 int32_t fs_sparecon[50];
161 int32_t fs_contigsumsize;
162 int32_t fs_maxsymlinklen;
164 uint32_t fs_maxfilesize[2];
165 uint32_t fs_qbmask[2];
166 uint32_t fs_qfmask[2];
168 } __attribute__((__packed__)) fs_44;
170 int32_t fs_postblformat;
172 int32_t fs_postbloff;
176 } __attribute__((__packed__));
178 #define UFS_MAGIC 0x00011954
179 #define UFS2_MAGIC 0x19540119
180 #define UFS_MAGIC_FEA 0x00195612
181 #define UFS_MAGIC_LFN 0x00095014
183 int volume_id_probe_ufs(struct volume_id *id, uint64_t off)
187 struct ufs_super_block *ufs;
188 int offsets[] = {0, 8, 64, 256, -1};
190 dbg("probing at offset 0x%llx", (unsigned long long) off);
192 for (i = 0; offsets[i] >= 0; i++) {
193 ufs = (struct ufs_super_block *) volume_id_get_buffer(id, off + (offsets[i] * 0x400), 0x800);
197 dbg("offset 0x%x", offsets[i] * 0x400);
198 magic = be32_to_cpu(ufs->fs_magic);
199 if ((magic == UFS_MAGIC) ||
200 (magic == UFS2_MAGIC) ||
201 (magic == UFS_MAGIC_FEA) ||
202 (magic == UFS_MAGIC_LFN)) {
203 dbg("magic 0x%08x(be)", magic);
206 magic = le32_to_cpu(ufs->fs_magic);
207 if ((magic == UFS_MAGIC) ||
208 (magic == UFS2_MAGIC) ||
209 (magic == UFS_MAGIC_FEA) ||
210 (magic == UFS_MAGIC_LFN)) {
211 dbg("magic 0x%08x(le)", magic);
218 volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);